| The Gaudi Framework v27r1

- 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 #include "AIDA_visibility_hack.h"
5
6 #include "Axis.h"
7 #include "TFile.h"
8 #include "Annotation.h"
9 #include "GaudiKernel/HistogramBase.h"
10 #include "AIDA/IHistogram3D.h"
11 #include <stdexcept>
12 #include <memory>
13
14 #ifdef __clang__
15 #pragma clang diagnostic push
16 // Hide warning message:
17 // warning: 'XYZ' overrides a member function but is not marked 'override'
18 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
19 #endif
20
21 namespace Gaudi {
22
33 template<typename INTERFACE, typename IMPLEMENTATION>
34 class GAUDI_API Generic3D : virtual public INTERFACE, virtual public HistogramBase {
35 public:
36 typedef Generic3D<INTERFACE,IMPLEMENTATION> Base;
38 Generic3D() = default;
39 protected:
41 Generic3D(IMPLEMENTATION* p) : m_rep(p) { }
42 public:
44 ~Generic3D() override = default;
46 TObject* representation() const override { return m_rep.get(); }
48 void adoptRepresentation(TObject* rep) override;
49
51 int dimension() const override { return 3; }
53 std::string title() const override { return m_annotation.value("Title");}
55 bool setTitle(const std::string & title) override;
57 std::string name() const { return m_annotation.value("Name"); }
59 bool setName( const std::string& newName);
61 AIDA::IAnnotation & annotation() override { return m_annotation; }
63 const AIDA::IAnnotation & annotation() const override { return m_annotation; }
64
66 int entries() const override;
68 int allEntries() const override;
70 double sumBinHeights() const override;
72 double sumAllBinHeights() const override;
74 double sumExtraBinHeights ( ) const override { return sumAllBinHeights()-sumBinHeights(); }
76 double minBinHeight() const override;
78 double maxBinHeight() const override;
79
80 int rIndexX(int index) const { return m_xAxis.rIndex(index);}
81 int rIndexY(int index) const { return m_yAxis.rIndex(index);}
82 int rIndexZ(int index) const { return m_zAxis.rIndex(index);}
83
85 double binMeanX(int indexX,int ,int ) const override
86 { return m_rep->GetXaxis()->GetBinCenter( rIndexX(indexX) ); }
88 double binMeanY(int,int indexY,int ) const override
89 { return m_rep->GetYaxis()->GetBinCenter( rIndexY(indexY) ); }
91 double binMeanZ(int ,int ,int indexZ) const override
92 { return m_rep->GetYaxis()->GetBinCenter( rIndexY(indexZ) ); }
94 int binEntries(int indexX,int indexY,int indexZ) const override {
95 if (binHeight(indexX, indexY, indexZ)<=0) return 0;
96 double xx = binHeight(indexX, indexY, indexZ)/binError(indexX, indexY, indexZ);
97 return int(xx*xx+0.5);
98 }
100 int binEntriesX(int index) const override {
101 int n = 0;
102 for (int i = -2; i < yAxis().bins(); ++i)
103 for (int j = -2; j < zAxis().bins(); ++j)
104 n += binEntries(index,i,j);
105 return n;
106
107 }
109 int binEntriesY(int index) const override {
110 int n = 0;
111 for (int i = -2; i < xAxis().bins(); ++i)
112 for (int j = -2; j < zAxis().bins(); ++j)
113 n += binEntries(i,index,j);
114 return n;
115 }
116
118 int binEntriesZ(int index) const override {
119 int n = 0;
120 for (int i = -2; i < xAxis().bins(); ++i)
121 for (int j = -2; j < yAxis().bins(); ++j)
122 n += binEntries(i,j,index);
123 return n;
124 }
125
127 double binHeight ( int indexX,int indexY,int indexZ ) const
128 { return m_rep->GetBinContent ( rIndexX(indexX), rIndexY(indexY), rIndexZ(indexZ) ); }
129
131 double binHeightX(int index) const override {
132 double s = 0;
133 for (int i = -2; i < yAxis().bins(); ++i)
134 for (int j = -2; j < zAxis().bins(); ++j)
135 s += binHeight(index,i,j);
136 return s;
137 }
139 double binHeightY(int index) const override {
140 double s = 0;
141 for (int i = -2; i < xAxis().bins(); ++i)
142 for (int j = -2; j < zAxis().bins(); ++j)
143 s += binHeight(i,index,j);
144 return s;
145 }
147 double binHeightZ(int index) const override {
148 double s = 0;
149 for (int i = -2; i < xAxis().bins(); ++i)
150 for (int j = -2; j < yAxis().bins(); ++j)
151 s += binHeight(i,j,index);
152 return s;
153 }
155 double binError ( int indexX,int indexY,int indexZ ) const override
156 { return m_rep->GetBinError ( rIndexX(indexX), rIndexY(indexY ), rIndexZ(indexZ ) ); }
158 double meanX ( ) const override { return m_rep->GetMean ( 1); }
159
161 double meanY ( ) const override { return m_rep->GetMean ( 2 ); }
163 double meanZ ( ) const override { return m_rep->GetMean ( 3 ); }
165 double rmsX ( ) const override { return m_rep->GetRMS( 1 ); }
167 double rmsY ( ) const override { return m_rep->GetRMS( 2 ); }
169 double rmsZ ( ) const override { return m_rep->GetRMS( 3 ); }
171 const AIDA::IAxis & xAxis ( ) const override { return m_xAxis; }
173 const AIDA::IAxis & yAxis ( ) const override { return m_yAxis; }
175 const AIDA::IAxis & zAxis ( ) const override { return m_zAxis; }
177 int coordToIndexX ( double coord ) const override { return xAxis().coordToIndex(coord);}
179 int coordToIndexY ( double coord ) const override { return yAxis().coordToIndex(coord);}
181 int coordToIndexZ ( double coord ) const override { return zAxis().coordToIndex(coord);}
182
184 double equivalentBinEntries ( ) const override;
186 bool scale( double scaleFactor ) override;
188 bool add ( const INTERFACE & hist ) override {
189 const Base* p = dynamic_cast<const Base*>(&hist);
190 if ( !p ) throw std::runtime_error("Cannot add profile histograms of different implementations.");
191 m_rep->Add(p->m_rep.get());
192 return true;
193 }
194
195 // overwrite extraentries
196 int extraEntries() const override {
197 return
198 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
199 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
200 binEntries(AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
201 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
202 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
203 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
204 binEntries(AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN);
205 }
207 std::ostream& print( std::ostream& s ) const override;
209 std::ostream& write( std::ostream& s ) const override;
211 int write( const char* file_name ) const override;
212
213 protected:
214 Gaudi::Axis m_xAxis;
215 Gaudi::Axis m_yAxis;
216 Gaudi::Axis m_zAxis;
218 mutable AIDA::Annotation m_annotation;
220 std::unique_ptr<IMPLEMENTATION> m_rep;
221 // class type
222 std::string m_classType;
223 // cache sumEntries (allEntries) when setting contents since Root can't compute by himself
224 int m_sumEntries = 0;
225 }; // end class IHistogram3D
226
227 template <class INTERFACE, class IMPLEMENTATION>
228 bool Generic3D<INTERFACE,IMPLEMENTATION>::setTitle(const std::string & title) {
229 m_rep->SetTitle(title.c_str());
230 if ( !annotation().addItem( "Title", title ) )
231 m_annotation.setValue( "Title" , title );
232 if ( !annotation().addItem( "title", title ) )
233 annotation().setValue( "title", title );
234 return true;
235 }
236
237 template <class INTERFACE, class IMPLEMENTATION>
238 bool Generic3D<INTERFACE,IMPLEMENTATION>::setName( const std::string& newName ) {
239 m_rep->SetName(newName.c_str());
240 m_annotation.setValue( "Name", newName );
241 return true;
242 }
243 template <class INTERFACE, class IMPLEMENTATION>
244 int Generic3D<INTERFACE,IMPLEMENTATION>::entries() const {
245 return m_rep->GetEntries();
246 }
247
248 template <class INTERFACE, class IMPLEMENTATION>
249 int Generic3D<INTERFACE,IMPLEMENTATION>::allEntries ( ) const {
250 return int(m_rep->GetEntries());
251 }
252
253 template <class INTERFACE, class IMPLEMENTATION>
254 double Generic3D<INTERFACE,IMPLEMENTATION>::minBinHeight() const {
255 return m_rep->GetMinimum();
256 }
257
258 template <class INTERFACE, class IMPLEMENTATION>
259 double Generic3D<INTERFACE,IMPLEMENTATION>::maxBinHeight() const {
260 return m_rep->GetMaximum();
261 }
262
263 template <class INTERFACE, class IMPLEMENTATION>
264 double Generic3D<INTERFACE,IMPLEMENTATION>::sumBinHeights () const {
265 return m_rep->GetSumOfWeights();
266 }
267
268 template <class INTERFACE, class IMPLEMENTATION>
269 double Generic3D<INTERFACE,IMPLEMENTATION>::sumAllBinHeights () const {
270 return m_rep->GetSum();
271 }
272
273 template <class INTERFACE, class IMPLEMENTATION>
274 double Generic3D<INTERFACE,IMPLEMENTATION>::equivalentBinEntries() const {
275 if (sumBinHeights() <= 0) return 0;
276 Stat_t stats[11]; // cover up to 3D...
277 m_rep->GetStats(stats);
278 return stats[0]*stats[0]/stats[1];
279 }
280
281 template <class INTERFACE, class IMPLEMENTATION>
282 bool Generic3D<INTERFACE,IMPLEMENTATION>::scale(double scaleFactor) {
283 m_rep->Scale ( scaleFactor );
284 return true;
285 }
286
287 template <class INTERFACE, class IMPLEMENTATION>
288 std::ostream& Generic3D<INTERFACE,IMPLEMENTATION>::print( std::ostream& s ) const
289 {
291 m_rep->Print("all");
292 return s;
293 }
294
295
297 template <class INTERFACE, class IMPLEMENTATION>
298 std::ostream& Generic3D<INTERFACE,IMPLEMENTATION>::write( std::ostream& s ) const
299 {
300 s << "\n3D Histogram Table: " << std::endl;
301 s << "BinX, BinY, BinZ, Height, Error " << std::endl;
302 for ( int i = 0; i < xAxis().bins(); ++i )
303 for ( int j = 0; j < yAxis().bins(); ++j )
304 for ( int k = 0; k < zAxis().bins(); ++k )
305 s << binMeanX( i, j, k ) << ", "
306 << binMeanY( i, j, k ) << ", "
307 << binMeanZ( i, j, k ) << ", "
308 << binHeight( i, j, k ) << ", "
309 << binError ( i, j, k ) << std::endl;
310 s << std::endl;
311 return s;
312 }
313
315 template <class INTERFACE, class IMPLEMENTATION>
316 int Generic3D<INTERFACE,IMPLEMENTATION>::write( const char* file_name ) const
317 {
318 TFile *f = TFile::Open(file_name,"RECREATE");
319 Int_t nbytes = m_rep->Write();
320 f->Close();
321 return nbytes;
322 }
323 }
324
325 #ifdef __clang__
326 #pragma clang diagnostic pop
327 #endif
328
329 #endif // GAUDIPI_GENERIC3D_H
Gaudi::Generic3D::rIndexZ
int rIndexZ(int index) const
Definition: Generic3D.h:82
Gaudi::Generic3D::rIndexX
int rIndexX(int index) const
Definition: Generic3D.h:80
Gaudi::Generic3D::annotation
AIDA::IAnnotation & annotation() override
Access annotation object.
Definition: Generic3D.h:61
Gaudi::Generic3D::m_xAxis
Gaudi::Axis m_xAxis
Definition: Generic3D.h:214
Gaudi::Generic3D::m_yAxis
Gaudi::Axis m_yAxis
Definition: Generic3D.h:215
Gaudi::Generic3D::sumAllBinHeights
double sumAllBinHeights() const override
Get the sum of all the bins heights (including underflow and overflow bin).
Definition: Generic3D.h:269
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:179
AIDA_visibility_hack.h
Gaudi::Generic3D::xAxis
const AIDA::IAxis & xAxis() const override
Get the x axis of the IHistogram3D.
Definition: Generic3D.h:171
std::endl
T endl(T...args)
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:118
Gaudi::Generic3D::sumExtraBinHeights
double sumExtraBinHeights() const override
Get the sum of the underflow and overflow bin height.
Definition: Generic3D.h:74
Gaudi::Generic3D::representation
TObject * representation() const override
ROOT object implementation.
Definition: Generic3D.h:46
Gaudi::Generic3D::sumBinHeights
double sumBinHeights() const override
Get the sum of in range bin heights in the IProfile.
Definition: Generic3D.h:264
Gaudi::Generic3D::title
std::string title() const override
Get the title of the object.
Definition: Generic3D.h:53
GaudiPluginService.cpluginsvc.n
list n
Definition: cpluginsvc.py:217
Gaudi::Generic3D::name
std::string name() const
object name
Definition: Generic3D.h:57
Gaudi::Generic3D::add
bool add(const INTERFACE &hist) override
Add to this Histogram3D the contents of another IHistogram3D.
Definition: Generic3D.h:188
std::string
STL class.
Gaudi::Generic3D::entries
int entries() const override
Get the number or all the entries.
Definition: Generic3D.h:244
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:88
Gaudi::Generic3D::zAxis
const AIDA::IAxis & zAxis() const override
Get the z axis of the IHistogram3D.
Definition: Generic3D.h:175
Gaudi::Generic3D::maxBinHeight
double maxBinHeight() const override
Get the maximum height of the in-range bins.
Definition: Generic3D.h:259
HistogramBase.h
Gaudi::Generic3D::meanX
double meanX() const override
The mean of the IHistogram3D along the x axis.
Definition: Generic3D.h:158
Axis.h
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:109
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:85
std::runtime_error
STL class.
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:91
AIDA::Annotation
Implementation of the AIDA IAnnotation interface class.
Definition: Annotation.h:18
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:94
Gaudi::Generic3D::scale
bool scale(double scaleFactor) override
Scale the weights and the errors of all the IHistogram's bins (in-range and out-of-range ones) by a g...
Definition: Generic3D.h:282
Gaudi::Generic3D::setName
bool setName(const std::string &newName)
Sets the name of the object.
Definition: Generic3D.h:238
Gaudi::Generic3D::m_zAxis
Gaudi::Axis m_zAxis
Definition: Generic3D.h:216
Gaudi::Generic3D::setTitle
bool setTitle(const std::string &title) override
Set the title of the object.
Definition: Generic3D.h:228
Gaudi::Generic3D::rIndexY
int rIndexY(int index) const
Definition: Generic3D.h:81
Gaudi::Generic3D::Base
Generic3D< INTERFACE, IMPLEMENTATION > Base
Definition: Generic3D.h:36
Gaudi::Generic3D::m_rep
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic3D.h:220
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:127
Gaudi::Generic3D::dimension
int dimension() const override
Get the Histogram's dimension.
Definition: Generic3D.h:51
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:249
std::unique_ptr::get
T get(T...args)
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:147
Gaudi::Generic3D::rmsY
double rmsY() const override
The RMS of the IHistogram3D along the y axis.
Definition: Generic3D.h:167
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:139
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::coordToIndexX
int coordToIndexX(double coord) const override
Get the bin number corresponding to a given coordinate along the x axis.
Definition: Generic3D.h:177
Gaudi::Generic3D::m_annotation
AIDA::Annotation m_annotation
Object annotations.
Definition: Generic3D.h:218
Gaudi::Generic3D::annotation
const AIDA::IAnnotation & annotation() const override
Access annotation object (cons)
Definition: Generic3D.h:63
Gaudi::Generic3D::write
std::ostream & write(std::ostream &s) const override
Write (ASCII) the histogram table into the output stream.
Definition: Generic3D.h:298
print
void print(string text)
Definition: mergesort.cpp:33
std::string::c_str
T c_str(T...args)
Gaudi::Generic3D::m_classType
std::string m_classType
Definition: Generic3D.h:222
gaudirun.s
string s
Definition: gaudirun.py:245
Gaudi::Generic3D::minBinHeight
double minBinHeight() const override
Get the minimum height of the in-range bins.
Definition: Generic3D.h:254
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:181
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:100
Gaudi::Generic3D::print
std::ostream & print(std::ostream &s) const override
Print (ASCII) the histogram into the output stream.
Definition: Generic3D.h:288
Gaudi::Generic3D::rmsZ
double rmsZ() const override
The RMS of the IHistogram3D along the z axis.
Definition: Generic3D.h:169
Gaudi::Generic3D::binError
double binError(int indexX, int indexY, int indexZ) const override
The error of a given bin.
Definition: Generic3D.h:155
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:107
ana.i
list i
Definition: ana.py:128
std::ostream
STL class.
Gaudi::Generic3D::extraEntries
int extraEntries() const override
Definition: Generic3D.h:196
Gaudi::Generic3D::meanY
double meanY() const override
The mean of the IHistogram3D along the y axis.
Definition: Generic3D.h:161
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:131
Gaudi::Generic3D::Generic3D
Generic3D(IMPLEMENTATION *p)
constructor
Definition: Generic3D.h:41
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:31
Gaudi::Generic3D::rmsX
double rmsX() const override
The RMS of the IHistogram3D along the x axis.
Definition: Generic3D.h:165
Gaudi::Generic3D::meanZ
double meanZ() const override
The mean of the IHistogram3D along the z axis.
Definition: Generic3D.h:163
Annotation.h
Gaudi::Generic3D::equivalentBinEntries
double equivalentBinEntries() const override
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
Definition: Generic3D.h:274
Gaudi::Generic3D
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
Definition: Generic3D.h:34
Gaudi::Generic3D::yAxis
const AIDA::IAxis & yAxis() const override
Get the y axis of the IHistogram3D.
Definition: Generic3D.h:173