| The Gaudi Framework v29r1 (5cd95fa2)

- 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 "AIDA/IHistogram3D.h"
5 #include "Annotation.h"
6 #include "Axis.h"
7 #include "GaudiKernel/HistogramBase.h"
8 #include "TFile.h"
9 #include <memory>
10 #include <stdexcept>
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 {
24
35 template <typename INTERFACE, typename IMPLEMENTATION>
36 class GAUDI_API Generic3D : virtual public INTERFACE, virtual public HistogramBase
37 {
38 public:
39 typedef Generic3D<INTERFACE, IMPLEMENTATION> Base;
41 Generic3D() = default;
42
43 protected:
45 Generic3D( IMPLEMENTATION* p ) : m_rep( p ) {}
46
47 public:
49 ~Generic3D() override = default;
51 TObject* representation() const override { return m_rep.get(); }
53 void adoptRepresentation( TObject* rep ) override;
54
56 int dimension() const override { return 3; }
58 std::string title() const override { return m_annotation.value( "Title" ); }
60 bool setTitle( const std::string& title ) override;
62 std::string name() const { return m_annotation.value( "Name" ); }
64 bool setName( const std::string& newName );
66 AIDA::IAnnotation& annotation() override { return m_annotation; }
68 const AIDA::IAnnotation& annotation() const override { return m_annotation; }
69
71 int entries() const override;
73 int allEntries() const override;
75 double sumBinHeights() const override;
77 double sumAllBinHeights() const override;
79 double sumExtraBinHeights() const override { return sumAllBinHeights() - sumBinHeights(); }
81 double minBinHeight() const override;
83 double maxBinHeight() const override;
84
85 int rIndexX( int index ) const { return m_xAxis.rIndex( index ); }
86 int rIndexY( int index ) const { return m_yAxis.rIndex( index ); }
87 int rIndexZ( int index ) const { return m_zAxis.rIndex( index ); }
88
90 double binMeanX( int indexX, int, int ) const override
91 {
92 return m_rep->GetXaxis()->GetBinCenter( rIndexX( indexX ) );
93 }
95 double binMeanY( int, int indexY, int ) const override
96 {
97 return m_rep->GetYaxis()->GetBinCenter( rIndexY( indexY ) );
98 }
100 double binMeanZ( int, int, int indexZ ) const override
101 {
102 return m_rep->GetYaxis()->GetBinCenter( rIndexY( indexZ ) );
103 }
105 int binEntries( int indexX, int indexY, int indexZ ) const override
106 {
107 if ( binHeight( indexX, indexY, indexZ ) <= 0 ) return 0;
108 double xx = binHeight( indexX, indexY, indexZ ) / binError( indexX, indexY, indexZ );
109 return int( xx * xx + 0.5 );
110 }
112 int binEntriesX( int index ) const override
113 {
114 int n = 0;
115 for ( int i = -2; i < yAxis().bins(); ++i )
116 for ( int j = -2; j < zAxis().bins(); ++j ) n += binEntries( index, i, j );
117 return n;
118 }
120 int binEntriesY( int index ) const override
121 {
122 int n = 0;
123 for ( int i = -2; i < xAxis().bins(); ++i )
124 for ( int j = -2; j < zAxis().bins(); ++j ) n += binEntries( i, index, j );
125 return n;
126 }
127
129 int binEntriesZ( int index ) const override
130 {
131 int n = 0;
132 for ( int i = -2; i < xAxis().bins(); ++i )
133 for ( int j = -2; j < yAxis().bins(); ++j ) n += binEntries( i, j, index );
134 return n;
135 }
136
138 double binHeight( int indexX, int indexY, int indexZ ) const
139 {
140 return m_rep->GetBinContent( rIndexX( indexX ), rIndexY( indexY ), rIndexZ( indexZ ) );
141 }
142
144 double binHeightX( int index ) const override
145 {
146 double s = 0;
147 for ( int i = -2; i < yAxis().bins(); ++i )
148 for ( int j = -2; j < zAxis().bins(); ++j ) s += binHeight( index, i, j );
149 return s;
150 }
152 double binHeightY( int index ) const override
153 {
154 double s = 0;
155 for ( int i = -2; i < xAxis().bins(); ++i )
156 for ( int j = -2; j < zAxis().bins(); ++j ) s += binHeight( i, index, j );
157 return s;
158 }
160 double binHeightZ( int index ) const override
161 {
162 double s = 0;
163 for ( int i = -2; i < xAxis().bins(); ++i )
164 for ( int j = -2; j < yAxis().bins(); ++j ) s += binHeight( i, j, index );
165 return s;
166 }
168 double binError( int indexX, int indexY, int indexZ ) const override
169 {
170 return m_rep->GetBinError( rIndexX( indexX ), rIndexY( indexY ), rIndexZ( indexZ ) );
171 }
173 double meanX() const override { return m_rep->GetMean( 1 ); }
174
176 double meanY() const override { return m_rep->GetMean( 2 ); }
178 double meanZ() const override { return m_rep->GetMean( 3 ); }
180 double rmsX() const override { return m_rep->GetRMS( 1 ); }
182 double rmsY() const override { return m_rep->GetRMS( 2 ); }
184 double rmsZ() const override { return m_rep->GetRMS( 3 ); }
186 const AIDA::IAxis& xAxis() const override { return m_xAxis; }
188 const AIDA::IAxis& yAxis() const override { return m_yAxis; }
190 const AIDA::IAxis& zAxis() const override { return m_zAxis; }
192 int coordToIndexX( double coord ) const override { return xAxis().coordToIndex( coord ); }
194 int coordToIndexY( double coord ) const override { return yAxis().coordToIndex( coord ); }
196 int coordToIndexZ( double coord ) const override { return zAxis().coordToIndex( coord ); }
197
199 double equivalentBinEntries() const override;
202 bool scale( double scaleFactor ) override;
204 bool add( const INTERFACE& hist ) override
205 {
206 const Base* p = dynamic_cast<const Base*>( &hist );
207 if ( !p ) throw std::runtime_error( "Cannot add profile histograms of different implementations." );
208 m_rep->Add( p->m_rep.get() );
209 return true;
210 }
211
212 // overwrite extraentries
213 int extraEntries() const override
214 {
215 return binEntries( AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN ) +
216 binEntries( AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN ) +
217 binEntries( AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN ) +
218 binEntries( AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN ) +
219 binEntries( AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN ) +
220 binEntries( AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN ) +
221 binEntries( AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN );
222 }
224 std::ostream& print( std::ostream& s ) const override;
226 std::ostream& write( std::ostream& s ) const override;
228 int write( const char* file_name ) const override;
229
230 protected:
231 Gaudi::Axis m_xAxis;
232 Gaudi::Axis m_yAxis;
233 Gaudi::Axis m_zAxis;
235 mutable AIDA::Annotation m_annotation;
237 std::unique_ptr<IMPLEMENTATION> m_rep;
238 // class type
239 std::string m_classType;
240 // cache sumEntries (allEntries) when setting contents since Root can't compute by himself
241 int m_sumEntries = 0;
242 }; // end class IHistogram3D
243
244 template <class INTERFACE, class IMPLEMENTATION>
245 bool Generic3D<INTERFACE, IMPLEMENTATION>::setTitle( const std::string& title )
246 {
247 m_rep->SetTitle( title.c_str() );
248 if ( !annotation().addItem( "Title", title ) ) m_annotation.setValue( "Title", title );
249 if ( !annotation().addItem( "title", title ) ) annotation().setValue( "title", title );
250 return true;
251 }
252
253 template <class INTERFACE, class IMPLEMENTATION>
254 bool Generic3D<INTERFACE, IMPLEMENTATION>::setName( const std::string& newName )
255 {
256 m_rep->SetName( newName.c_str() );
257 m_annotation.setValue( "Name", newName );
258 return true;
259 }
260 template <class INTERFACE, class IMPLEMENTATION>
261 int Generic3D<INTERFACE, IMPLEMENTATION>::entries() const
262 {
263 return m_rep->GetEntries();
264 }
265
266 template <class INTERFACE, class IMPLEMENTATION>
267 int Generic3D<INTERFACE, IMPLEMENTATION>::allEntries() const
268 {
269 return int( m_rep->GetEntries() );
270 }
271
272 template <class INTERFACE, class IMPLEMENTATION>
273 double Generic3D<INTERFACE, IMPLEMENTATION>::minBinHeight() const
274 {
275 return m_rep->GetMinimum();
276 }
277
278 template <class INTERFACE, class IMPLEMENTATION>
279 double Generic3D<INTERFACE, IMPLEMENTATION>::maxBinHeight() const
280 {
281 return m_rep->GetMaximum();
282 }
283
284 template <class INTERFACE, class IMPLEMENTATION>
285 double Generic3D<INTERFACE, IMPLEMENTATION>::sumBinHeights() const
286 {
287 return m_rep->GetSumOfWeights();
288 }
289
290 template <class INTERFACE, class IMPLEMENTATION>
291 double Generic3D<INTERFACE, IMPLEMENTATION>::sumAllBinHeights() const
292 {
293 return m_rep->GetSum();
294 }
295
296 template <class INTERFACE, class IMPLEMENTATION>
297 double Generic3D<INTERFACE, IMPLEMENTATION>::equivalentBinEntries() const
298 {
299 if ( sumBinHeights() <= 0 ) return 0;
300 Stat_t stats[11]; // cover up to 3D...
301 m_rep->GetStats( stats );
302 return stats[0] * stats[0] / stats[1];
303 }
304
305 template <class INTERFACE, class IMPLEMENTATION>
306 bool Generic3D<INTERFACE, IMPLEMENTATION>::scale( double scaleFactor )
307 {
308 m_rep->Scale( scaleFactor );
309 return true;
310 }
311
312 template <class INTERFACE, class IMPLEMENTATION>
313 std::ostream& Generic3D<INTERFACE, IMPLEMENTATION>::print( std::ostream& s ) const
314 {
316 m_rep->Print( "all" );
317 return s;
318 }
319
321 template <class INTERFACE, class IMPLEMENTATION>
322 std::ostream& Generic3D<INTERFACE, IMPLEMENTATION>::write( std::ostream& s ) const
323 {
324 s << "\n3D Histogram Table: " << std::endl;
325 s << "BinX, BinY, BinZ, Height, Error " << std::endl;
326 for ( int i = 0; i < xAxis().bins(); ++i )
327 for ( int j = 0; j < yAxis().bins(); ++j )
328 for ( int k = 0; k < zAxis().bins(); ++k )
329 s << binMeanX( i, j, k ) << ", " << binMeanY( i, j, k ) << ", " << binMeanZ( i, j, k ) << ", "
330 << binHeight( i, j, k ) << ", " << binError( i, j, k ) << std::endl;
331 s << std::endl;
332 return s;
333 }
334
336 template <class INTERFACE, class IMPLEMENTATION>
337 int Generic3D<INTERFACE, IMPLEMENTATION>::write( const char* file_name ) const
338 {
339 TFile* f = TFile::Open( file_name, "RECREATE" );
340 Int_t nbytes = m_rep->Write();
341 f->Close();
342 return nbytes;
343 }
344 }
345
346 #ifdef __clang__
347 #pragma clang diagnostic pop
348 #elif defined( __GNUC__ ) && __GNUC__ >= 5
349 #pragma GCC diagnostic pop
350 #endif
351
352 #endif // GAUDIPI_GENERIC3D_H
Gaudi::Generic3D::rIndexZ
int rIndexZ(int index) const
Definition: Generic3D.h:87
Gaudi::Generic3D::rIndexX
int rIndexX(int index) const
Definition: Generic3D.h:85
Gaudi::Generic3D::annotation
AIDA::IAnnotation & annotation() override
Access annotation object.
Definition: Generic3D.h:66
Gaudi::Generic3D::m_xAxis
Gaudi::Axis m_xAxis
Definition: Generic3D.h:231
Gaudi::Generic3D::meanZ
double meanZ() const override
The mean of the IHistogram3D along the z axis.
Definition: Generic3D.h:178
Gaudi::Generic3D::annotation
const AIDA::IAnnotation & annotation() const override
Access annotation object (cons)
Definition: Generic3D.h:68
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:120
Gaudi::Generic3D::m_yAxis
Gaudi::Axis m_yAxis
Definition: Generic3D.h:232
Gaudi::Generic3D::maxBinHeight
double maxBinHeight() const override
Get the maximum height of the in-range bins.
Definition: Generic3D.h:279
Gaudi::Generic3D::entries
int entries() const override
Get the number or all the entries.
Definition: Generic3D.h:261
Gaudi::Generic3D::print
std::ostream & print(std::ostream &s) const override
Print (ASCII) the histogram into the output stream.
Definition: Generic3D.h:313
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:95
Gaudi::Generic3D::yAxis
const AIDA::IAxis & yAxis() const override
Get the y axis of the IHistogram3D.
Definition: Generic3D.h:188
Gaudi::Generic3D::zAxis
const AIDA::IAxis & zAxis() const override
Get the z axis of the IHistogram3D.
Definition: Generic3D.h:190
Gaudi::Generic3D::rmsZ
double rmsZ() const override
The RMS of the IHistogram3D along the z axis.
Definition: Generic3D.h:184
Gaudi::Generic3D::name
std::string name() const
object name
Definition: Generic3D.h:62
Gaudi::Generic3D::add
bool add(const INTERFACE &hist) override
Add to this Histogram3D the contents of another IHistogram3D.
Definition: Generic3D.h:204
Gaudi::Generic3D::sumAllBinHeights
double sumAllBinHeights() const override
Get the sum of all the bins heights (including underflow and overflow bin).
Definition: Generic3D.h:291
std::string
STL class.
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:228
Gaudi::Generic3D::Base
Generic3D< INTERFACE, IMPLEMENTATION > Base
Definition: Generic3D.h:39
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:105
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:285
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:152
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:160
AIDA::Annotation
Implementation of the AIDA IAnnotation interface class.
Definition: Annotation.h:17
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:306
Gaudi::Generic3D::setName
bool setName(const std::string &newName)
Sets the name of the object.
Definition: Generic3D.h:254
Gaudi::Generic3D::m_zAxis
Gaudi::Axis m_zAxis
Definition: Generic3D.h:233
Gaudi::Generic3D::setTitle
bool setTitle(const std::string &title) override
Set the title of the object.
Definition: Generic3D.h:245
Gaudi::Generic3D::rIndexY
int rIndexY(int index) const
Definition: Generic3D.h:86
Gaudi::Generic3D::representation
TObject * representation() const override
ROOT object implementation.
Definition: Generic3D.h:51
Gaudi::Generic3D::m_rep
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic3D.h:237
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:138
Gaudi::Generic3D::title
std::string title() const override
Get the title of the object.
Definition: Generic3D.h:58
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:273
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:112
Gaudi::HistogramBase
Common base class for all histograms Use is solely functional to minimize dynamic_casts inside Histog...
Definition: HistogramBase.h:23
std::unique_ptr< IMPLEMENTATION >
Gaudi::Generic3D::m_annotation
AIDA::Annotation m_annotation
Object annotations.
Definition: Generic3D.h:235
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:194
print
void print(string text)
Definition: mergesort.cpp:30
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:186
Gaudi::Generic3D::rmsY
double rmsY() const override
The RMS of the IHistogram3D along the y axis.
Definition: Generic3D.h:182
Gaudi::Generic3D::m_classType
std::string m_classType
Definition: Generic3D.h:239
GaudiPython.GaudiAlgs.write
write
Definition: GaudiAlgs.py:1259
gaudirun.s
string s
Definition: gaudirun.py:253
Gaudi::Generic3D::rmsX
double rmsX() const override
The RMS of the IHistogram3D along the x axis.
Definition: Generic3D.h:180
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:100
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:196
Gaudi::Generic3D::dimension
int dimension() const override
Get the Histogram&#39;s dimension.
Definition: Generic3D.h:56
Gaudi::Generic3D::meanY
double meanY() const override
The mean of the IHistogram3D along the y axis.
Definition: Generic3D.h:176
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:90
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:192
Gaudi::Generic3D::write
std::ostream & write(std::ostream &s) const override
Write (ASCII) the histogram table into the output stream.
Definition: Generic3D.h:322
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:110
Gaudi::Generic3D::extraEntries
int extraEntries() const override
Definition: Generic3D.h:213
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:297
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:267
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:144
Gaudi::Generic3D::binError
double binError(int indexX, int indexY, int indexZ) const override
The error of a given bin.
Definition: Generic3D.h:168
Gaudi::Generic3D::Generic3D
Generic3D(IMPLEMENTATION *p)
constructor
Definition: Generic3D.h:45
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:30
Gaudi::Generic3D::meanX
double meanX() const override
The mean of the IHistogram3D along the x axis.
Definition: Generic3D.h:173
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:129
Gaudi::Generic3D
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
Definition: Generic3D.h:36
Gaudi::Generic3D::sumExtraBinHeights
double sumExtraBinHeights() const override
Get the sum of the underflow and overflow bin height.
Definition: Generic3D.h:79