| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Generic3D.h
Go to the documentation of this file.
1 #ifndef GAUDISVC_GENERIC3D_H
2 #define GAUDISVC_GENERIC3D_H 1
3
4 #include "Axis.h"
5 #include "TFile.h"
6 #include "Annotation.h"
7 #include "GaudiKernel/HistogramBase.h"
8 #include "AIDA/IHistogram3D.h"
9 #include <stdexcept>
10 #include <memory>
11
12 // Hide warning message:
13 // warning: 'XYZ' overrides a member function but is not marked 'override'
14 #ifdef __clang__
15 #pragma clang diagnostic push
16 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
17 #elif defined(__GNUC__) && __GNUC__ >= 5
18 #pragma GCC diagnostic push
19 #pragma GCC diagnostic ignored "-Wsuggest-override"
20 #endif
21
22 namespace Gaudi {
23
34 template<typename INTERFACE, typename IMPLEMENTATION>
35 class GAUDI_API Generic3D : virtual public INTERFACE, virtual public HistogramBase {
36 public:
37 typedef Generic3D<INTERFACE,IMPLEMENTATION> Base;
39 Generic3D() = default;
40 protected:
42 Generic3D(IMPLEMENTATION* p) : m_rep(p) { }
43 public:
45 ~Generic3D() override = default;
47 TObject* representation() const override { return m_rep.get(); }
49 void adoptRepresentation(TObject* rep) override;
50
52 int dimension() const override { return 3; }
54 std::string title() const override { return m_annotation.value("Title");}
56 bool setTitle(const std::string & title) override;
58 std::string name() const { return m_annotation.value("Name"); }
60 bool setName( const std::string& newName);
62 AIDA::IAnnotation & annotation() override { return m_annotation; }
64 const AIDA::IAnnotation & annotation() const override { return m_annotation; }
65
67 int entries() const override;
69 int allEntries() const override;
71 double sumBinHeights() const override;
73 double sumAllBinHeights() const override;
75 double sumExtraBinHeights ( ) const override { return sumAllBinHeights()-sumBinHeights(); }
77 double minBinHeight() const override;
79 double maxBinHeight() const override;
80
81 int rIndexX(int index) const { return m_xAxis.rIndex(index);}
82 int rIndexY(int index) const { return m_yAxis.rIndex(index);}
83 int rIndexZ(int index) const { return m_zAxis.rIndex(index);}
84
86 double binMeanX(int indexX,int ,int ) const override
87 { return m_rep->GetXaxis()->GetBinCenter( rIndexX(indexX) ); }
89 double binMeanY(int,int indexY,int ) const override
90 { return m_rep->GetYaxis()->GetBinCenter( rIndexY(indexY) ); }
92 double binMeanZ(int ,int ,int indexZ) const override
93 { return m_rep->GetYaxis()->GetBinCenter( rIndexY(indexZ) ); }
95 int binEntries(int indexX,int indexY,int indexZ) const override {
96 if (binHeight(indexX, indexY, indexZ)<=0) return 0;
97 double xx = binHeight(indexX, indexY, indexZ)/binError(indexX, indexY, indexZ);
98 return int(xx*xx+0.5);
99 }
101 int binEntriesX(int index) const override {
102 int n = 0;
103 for (int i = -2; i < yAxis().bins(); ++i)
104 for (int j = -2; j < zAxis().bins(); ++j)
105 n += binEntries(index,i,j);
106 return n;
107
108 }
110 int binEntriesY(int index) const override {
111 int n = 0;
112 for (int i = -2; i < xAxis().bins(); ++i)
113 for (int j = -2; j < zAxis().bins(); ++j)
114 n += binEntries(i,index,j);
115 return n;
116 }
117
119 int binEntriesZ(int index) const override {
120 int n = 0;
121 for (int i = -2; i < xAxis().bins(); ++i)
122 for (int j = -2; j < yAxis().bins(); ++j)
123 n += binEntries(i,j,index);
124 return n;
125 }
126
128 double binHeight ( int indexX,int indexY,int indexZ ) const
129 { return m_rep->GetBinContent ( rIndexX(indexX), rIndexY(indexY), rIndexZ(indexZ) ); }
130
132 double binHeightX(int index) const override {
133 double s = 0;
134 for (int i = -2; i < yAxis().bins(); ++i)
135 for (int j = -2; j < zAxis().bins(); ++j)
136 s += binHeight(index,i,j);
137 return s;
138 }
140 double binHeightY(int index) const override {
141 double s = 0;
142 for (int i = -2; i < xAxis().bins(); ++i)
143 for (int j = -2; j < zAxis().bins(); ++j)
144 s += binHeight(i,index,j);
145 return s;
146 }
148 double binHeightZ(int index) const override {
149 double s = 0;
150 for (int i = -2; i < xAxis().bins(); ++i)
151 for (int j = -2; j < yAxis().bins(); ++j)
152 s += binHeight(i,j,index);
153 return s;
154 }
156 double binError ( int indexX,int indexY,int indexZ ) const override
157 { return m_rep->GetBinError ( rIndexX(indexX), rIndexY(indexY ), rIndexZ(indexZ ) ); }
159 double meanX ( ) const override { return m_rep->GetMean ( 1); }
160
162 double meanY ( ) const override { return m_rep->GetMean ( 2 ); }
164 double meanZ ( ) const override { return m_rep->GetMean ( 3 ); }
166 double rmsX ( ) const override { return m_rep->GetRMS( 1 ); }
168 double rmsY ( ) const override { return m_rep->GetRMS( 2 ); }
170 double rmsZ ( ) const override { return m_rep->GetRMS( 3 ); }
172 const AIDA::IAxis & xAxis ( ) const override { return m_xAxis; }
174 const AIDA::IAxis & yAxis ( ) const override { return m_yAxis; }
176 const AIDA::IAxis & zAxis ( ) const override { return m_zAxis; }
178 int coordToIndexX ( double coord ) const override { return xAxis().coordToIndex(coord);}
180 int coordToIndexY ( double coord ) const override { return yAxis().coordToIndex(coord);}
182 int coordToIndexZ ( double coord ) const override { return zAxis().coordToIndex(coord);}
183
185 double equivalentBinEntries ( ) const override;
187 bool scale( double scaleFactor ) override;
189 bool add ( const INTERFACE & hist ) override {
190 const Base* p = dynamic_cast<const Base*>(&hist);
191 if ( !p ) throw std::runtime_error("Cannot add profile histograms of different implementations.");
192 m_rep->Add(p->m_rep.get());
193 return true;
194 }
195
196 // overwrite extraentries
197 int extraEntries() const override {
198 return
199 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
200 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
201 binEntries(AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
202 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
203 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
204 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
205 binEntries(AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN);
206 }
208 std::ostream& print( std::ostream& s ) const override;
210 std::ostream& write( std::ostream& s ) const override;
212 int write( const char* file_name ) const override;
213
214 protected:
215 Gaudi::Axis m_xAxis;
216 Gaudi::Axis m_yAxis;
217 Gaudi::Axis m_zAxis;
219 mutable AIDA::Annotation m_annotation;
221 std::unique_ptr<IMPLEMENTATION> m_rep;
222 // class type
223 std::string m_classType;
224 // cache sumEntries (allEntries) when setting contents since Root can't compute by himself
225 int m_sumEntries = 0;
226 }; // end class IHistogram3D
227
228 template <class INTERFACE, class IMPLEMENTATION>
229 bool Generic3D<INTERFACE,IMPLEMENTATION>::setTitle(const std::string & title) {
230 m_rep->SetTitle(title.c_str());
231 if ( !annotation().addItem( "Title", title ) )
232 m_annotation.setValue( "Title" , title );
233 if ( !annotation().addItem( "title", title ) )
234 annotation().setValue( "title", title );
235 return true;
236 }
237
238 template <class INTERFACE, class IMPLEMENTATION>
239 bool Generic3D<INTERFACE,IMPLEMENTATION>::setName( const std::string& newName ) {
240 m_rep->SetName(newName.c_str());
241 m_annotation.setValue( "Name", newName );
242 return true;
243 }
244 template <class INTERFACE, class IMPLEMENTATION>
245 int Generic3D<INTERFACE,IMPLEMENTATION>::entries() const {
246 return m_rep->GetEntries();
247 }
248
249 template <class INTERFACE, class IMPLEMENTATION>
250 int Generic3D<INTERFACE,IMPLEMENTATION>::allEntries ( ) const {
251 return int(m_rep->GetEntries());
252 }
253
254 template <class INTERFACE, class IMPLEMENTATION>
255 double Generic3D<INTERFACE,IMPLEMENTATION>::minBinHeight() const {
256 return m_rep->GetMinimum();
257 }
258
259 template <class INTERFACE, class IMPLEMENTATION>
260 double Generic3D<INTERFACE,IMPLEMENTATION>::maxBinHeight() const {
261 return m_rep->GetMaximum();
262 }
263
264 template <class INTERFACE, class IMPLEMENTATION>
265 double Generic3D<INTERFACE,IMPLEMENTATION>::sumBinHeights () const {
266 return m_rep->GetSumOfWeights();
267 }
268
269 template <class INTERFACE, class IMPLEMENTATION>
270 double Generic3D<INTERFACE,IMPLEMENTATION>::sumAllBinHeights () const {
271 return m_rep->GetSum();
272 }
273
274 template <class INTERFACE, class IMPLEMENTATION>
275 double Generic3D<INTERFACE,IMPLEMENTATION>::equivalentBinEntries() const {
276 if (sumBinHeights() <= 0) return 0;
277 Stat_t stats[11]; // cover up to 3D...
278 m_rep->GetStats(stats);
279 return stats[0]*stats[0]/stats[1];
280 }
281
282 template <class INTERFACE, class IMPLEMENTATION>
283 bool Generic3D<INTERFACE,IMPLEMENTATION>::scale(double scaleFactor) {
284 m_rep->Scale ( scaleFactor );
285 return true;
286 }
287
288 template <class INTERFACE, class IMPLEMENTATION>
289 std::ostream& Generic3D<INTERFACE,IMPLEMENTATION>::print( std::ostream& s ) const
290 {
292 m_rep->Print("all");
293 return s;
294 }
295
296
298 template <class INTERFACE, class IMPLEMENTATION>
299 std::ostream& Generic3D<INTERFACE,IMPLEMENTATION>::write( std::ostream& s ) const
300 {
301 s << "\n3D Histogram Table: " << std::endl;
302 s << "BinX, BinY, BinZ, Height, Error " << std::endl;
303 for ( int i = 0; i < xAxis().bins(); ++i )
304 for ( int j = 0; j < yAxis().bins(); ++j )
305 for ( int k = 0; k < zAxis().bins(); ++k )
306 s << binMeanX( i, j, k ) << ", "
307 << binMeanY( i, j, k ) << ", "
308 << binMeanZ( i, j, k ) << ", "
309 << binHeight( i, j, k ) << ", "
310 << binError ( i, j, k ) << std::endl;
311 s << std::endl;
312 return s;
313 }
314
316 template <class INTERFACE, class IMPLEMENTATION>
317 int Generic3D<INTERFACE,IMPLEMENTATION>::write( const char* file_name ) const
318 {
319 TFile *f = TFile::Open(file_name,"RECREATE");
320 Int_t nbytes = m_rep->Write();
321 f->Close();
322 return nbytes;
323 }
324 }
325
326 #ifdef __clang__
327 #pragma clang diagnostic pop
328 #elif defined(__GNUC__) && __GNUC__ >= 5
329 #pragma GCC diagnostic pop
330 #endif
331
332 #endif // GAUDIPI_GENERIC3D_H
Gaudi::Generic3D::rIndexZ
int rIndexZ(int index) const
Definition: Generic3D.h:83
Gaudi::Generic3D::rIndexX
int rIndexX(int index) const
Definition: Generic3D.h:81
Gaudi::Generic3D::annotation
AIDA::IAnnotation & annotation() override
Access annotation object.
Definition: Generic3D.h:62
Gaudi::Generic3D::m_xAxis
Gaudi::Axis m_xAxis
Definition: Generic3D.h:215
Gaudi::Generic3D::meanZ
double meanZ() const override
The mean of the IHistogram3D along the z axis.
Definition: Generic3D.h:164
Gaudi::Generic3D::annotation
const AIDA::IAnnotation & annotation() const override
Access annotation object (cons)
Definition: Generic3D.h:64
Gaudi::Generic3D::binEntriesY
int binEntriesY(int index) const override
Sum of all the entries of the bins along a given y bin.
Definition: Generic3D.h:110
Gaudi::Generic3D::m_yAxis
Gaudi::Axis m_yAxis
Definition: Generic3D.h:216
Gaudi::Generic3D::maxBinHeight
double maxBinHeight() const override
Get the maximum height of the in-range bins.
Definition: Generic3D.h:260
Gaudi::Generic3D::entries
int entries() const override
Get the number or all the entries.
Definition: Generic3D.h:245
Gaudi::Generic3D::print
std::ostream & print(std::ostream &s) const override
Print (ASCII) the histogram into the output stream.
Definition: Generic3D.h:289
std::endl
T endl(T...args)
Gaudi::Generic3D::binMeanY
double binMeanY(int, int indexY, int) const override
The weighted mean along the y axis of a given bin.
Definition: Generic3D.h:89
Gaudi::Generic3D::yAxis
const AIDA::IAxis & yAxis() const override
Get the y axis of the IHistogram3D.
Definition: Generic3D.h:174
Gaudi::Generic3D::zAxis
const AIDA::IAxis & zAxis() const override
Get the z axis of the IHistogram3D.
Definition: Generic3D.h:176
Gaudi::Generic3D::rmsZ
double rmsZ() const override
The RMS of the IHistogram3D along the z axis.
Definition: Generic3D.h:170
Gaudi::Generic3D::name
std::string name() const
object name
Definition: Generic3D.h:58
Gaudi::Generic3D::add
bool add(const INTERFACE &hist) override
Add to this Histogram3D the contents of another IHistogram3D.
Definition: Generic3D.h:189
Gaudi::Generic3D::sumAllBinHeights
double sumAllBinHeights() const override
Get the sum of all the bins heights (including underflow and overflow bin).
Definition: Generic3D.h:270
std::string
STL class.
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:217
Gaudi::Generic3D::binEntries
int binEntries(int indexX, int indexY, int indexZ) const override
Number of entries in the corresponding bin (ie the number of times fill was calle d for this bin)...
Definition: Generic3D.h:95
HistogramBase.h
Axis.h
Gaudi::Generic3D::sumBinHeights
double sumBinHeights() const override
Get the sum of in range bin heights in the IProfile.
Definition: Generic3D.h:265
Gaudi::Generic3D::binHeightY
double binHeightY(int index) const override
Sum of all the heights of the bins along a given y bin.
Definition: Generic3D.h:140
std::runtime_error
STL class.
Gaudi::Generic3D::binHeightZ
double binHeightZ(int index) const override
Sum of all the heights of the bins along a given z bin.
Definition: Generic3D.h:148
AIDA::Annotation
Implementation of the AIDA IAnnotation interface class.
Definition: Annotation.h:16
Gaudi::Generic3D::scale
bool scale(double scaleFactor) override
Scale the weights and the errors of all the IHistogram&#39;s bins (in-range and out-of-range ones) by a g...
Definition: Generic3D.h:283
Gaudi::Generic3D::setName
bool setName(const std::string &newName)
Sets the name of the object.
Definition: Generic3D.h:239
Gaudi::Generic3D::m_zAxis
Gaudi::Axis m_zAxis
Definition: Generic3D.h:217
Gaudi::Generic3D::setTitle
bool setTitle(const std::string &title) override
Set the title of the object.
Definition: Generic3D.h:229
Gaudi::Generic3D::rIndexY
int rIndexY(int index) const
Definition: Generic3D.h:82
Gaudi::Generic3D::Base
Generic3D< INTERFACE, IMPLEMENTATION > Base
Definition: Generic3D.h:37
Gaudi::Generic3D::representation
TObject * representation() const override
ROOT object implementation.
Definition: Generic3D.h:47
Gaudi::Generic3D::m_rep
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic3D.h:221
Gaudi::Generic3D::binHeight
double binHeight(int indexX, int indexY, int indexZ) const
Total height of the corresponding bin (ie the sum of the weights in this bin).
Definition: Generic3D.h:128
Gaudi::Generic3D::title
std::string title() const override
Get the title of the object.
Definition: Generic3D.h:54
std::unique_ptr::get
T get(T...args)
Gaudi::Generic3D::minBinHeight
double minBinHeight() const override
Get the minimum height of the in-range bins.
Definition: Generic3D.h:255
Gaudi::Generic3D::binEntriesX
int binEntriesX(int index) const override
Sum of all the entries of the bins along a given x bin.
Definition: Generic3D.h:101
Gaudi::HistogramBase
Common base class for all histograms Use is solely functional to minimize dynamic_casts inside Histog...
Definition: HistogramBase.h:22
std::unique_ptr< IMPLEMENTATION >
Gaudi::Generic3D::m_annotation
AIDA::Annotation m_annotation
Object annotations.
Definition: Generic3D.h:219
Gaudi::Generic3D::coordToIndexY
int coordToIndexY(double coord) const override
Get the bin number corresponding to a given coordinate along the y axis.
Definition: Generic3D.h:180
print
void print(string text)
Definition: mergesort.cpp:33
std::string::c_str
T c_str(T...args)
Gaudi::Generic3D::xAxis
const AIDA::IAxis & xAxis() const override
Get the x axis of the IHistogram3D.
Definition: Generic3D.h:172
Gaudi::Generic3D::rmsY
double rmsY() const override
The RMS of the IHistogram3D along the y axis.
Definition: Generic3D.h:168
Gaudi::Generic3D::m_classType
std::string m_classType
Definition: Generic3D.h:223
GaudiPython.GaudiAlgs.write
write
Definition: GaudiAlgs.py:1144
gaudirun.s
string s
Definition: gaudirun.py:245
Gaudi::Generic3D::rmsX
double rmsX() const override
The RMS of the IHistogram3D along the x axis.
Definition: Generic3D.h:166
Gaudi::Generic3D::binMeanZ
double binMeanZ(int, int, int indexZ) const override
The weighted mean along the z axis of a given bin.
Definition: Generic3D.h:92
Gaudi::Generic3D::coordToIndexZ
int coordToIndexZ(double coord) const override
Get the bin number corresponding to a given coordinate along the z axis.
Definition: Generic3D.h:182
Gaudi::Generic3D::dimension
int dimension() const override
Get the Histogram&#39;s dimension.
Definition: Generic3D.h:52
Gaudi::Generic3D::meanY
double meanY() const override
The mean of the IHistogram3D along the y axis.
Definition: Generic3D.h:162
Gaudi::Generic3D::binMeanX
double binMeanX(int indexX, int, int) const override
The weighted mean along the x axis of a given bin.
Definition: Generic3D.h:86
Gaudi::Generic3D::coordToIndexX
int coordToIndexX(double coord) const override
Get the bin number corresponding to a given coordinate along the x axis.
Definition: Generic3D.h:178
Gaudi::Generic3D::write
std::ostream & write(std::ostream &s) const override
Write (ASCII) the histogram table into the output stream.
Definition: Generic3D.h:299
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:107
Gaudi::Generic3D::extraEntries
int extraEntries() const override
Definition: Generic3D.h:197
std::ostream
STL class.
Gaudi::Generic3D::equivalentBinEntries
double equivalentBinEntries() const override
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
Definition: Generic3D.h:275
Gaudi::Generic3D::allEntries
int allEntries() const override
Get the number or all the entries, both in range and underflow/overflow bins of the IProfile...
Definition: Generic3D.h:250
Gaudi::Generic3D::binHeightX
double binHeightX(int index) const override
Sum of all the heights of the bins along a given x bin.
Definition: Generic3D.h:132
Gaudi::Generic3D::binError
double binError(int indexX, int indexY, int indexZ) const override
The error of a given bin.
Definition: Generic3D.h:156
Gaudi::Generic3D::Generic3D
Generic3D(IMPLEMENTATION *p)
constructor
Definition: Generic3D.h:42
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
Gaudi::Axis
An IAxis represents a binned histogram axis.
Definition: Axis.h:29
Gaudi::Generic3D::meanX
double meanX() const override
The mean of the IHistogram3D along the x axis.
Definition: Generic3D.h:159
Annotation.h
Gaudi::Generic3D::binEntriesZ
int binEntriesZ(int index) const override
Sum of all the entries of the bins along a given z bin.
Definition: Generic3D.h:119
Gaudi::Generic3D
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
Definition: Generic3D.h:35
Gaudi::Generic3D::sumExtraBinHeights
double sumExtraBinHeights() const override
Get the sum of the underflow and overflow bin height.
Definition: Generic3D.h:75