| The Gaudi Framework v29r0 (ff2e7097)

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

- File List
- File Members

Generic2D.h
Go to the documentation of this file.
1 #ifndef GAUDISVC_GENERIC2D_H
2 #define GAUDISVC_GENERIC2D_H 1
3
4 #include "AIDA/IProfile2D.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 <class INTERFACE, class IMPLEMENTATION>
36 class GAUDI_API Generic2D : virtual public INTERFACE, virtual public HistogramBase
37 {
38 public:
39 typedef Generic2D<INTERFACE, IMPLEMENTATION> Base;
40
41 Generic2D() = default;
42
43 protected:
45 Generic2D( IMPLEMENTATION* p ) : m_rep( p ) {}
46
47 public:
49 ~Generic2D() override = default;
51 TObject* representation() const override { return m_rep.get(); }
53 void adoptRepresentation( TObject* rep ) override;
55 std::string title() const override { return m_annotation.value( "Title" ); }
57 bool setTitle( const std::string& title ) override;
59 std::string name() const { return m_annotation.value( "Name" ); }
61 bool setName( const std::string& newName );
63 AIDA::IAnnotation& annotation() override { return m_annotation; }
65 const AIDA::IAnnotation& annotation() const override { return m_annotation; }
66
68 const AIDA::IAxis& xAxis() const override { return m_xAxis; }
70 const AIDA::IAxis& yAxis() const override { return m_yAxis; }
72 virtual int rIndexX( int index ) const { return m_xAxis.rIndex( index ); }
74 virtual int rIndexY( int index ) const { return m_yAxis.rIndex( index ); }
75
77 int entries() const override;
79 int allEntries() const override;
81 int extraEntries() const override;
83 double sumBinHeights() const override;
85 double sumAllBinHeights() const override;
87 double sumExtraBinHeights() const override { return sumAllBinHeights() - sumBinHeights(); }
89 double minBinHeight() const override;
91 double maxBinHeight() const override;
92
94 double binMeanX( int indexX, int indexY ) const override;
96 double binMeanY( int indexX, int indexY ) const override;
98 int binEntries( int indexX, int indexY ) const override;
100 int binEntriesX( int indexX ) const override;
102 int binEntriesY( int indexY ) const override;
104 double binHeight( int indexX, int indexY ) const override;
106 double binHeightX( int indexX ) const override;
108 double binHeightY( int indexY ) const override;
110 double binError( int indexX, int indexY ) const override;
112 virtual double binRms( int indexX, int indexY ) const;
114 double meanX() const override;
116 double meanY() const override;
118 double rmsX() const override;
120 double rmsY() const override;
122 int coordToIndexX( double coordX ) const override;
124 int coordToIndexY( double coordY ) const override;
126 virtual double equivalentBinEntries() const;
129 virtual bool scale( double scaleFactor );
131 bool add( const INTERFACE& h ) override;
132 // overwrite reset
133 bool reset() override;
135 void* cast( const std::string& className ) const override;
137 const std::string& userLevelClassType() const { return m_classType; }
139 int dimension() const override { return 2; }
141 std::ostream& print( std::ostream& s ) const override;
143 std::ostream& write( std::ostream& s ) const override;
145 int write( const char* file_name ) const override;
146
147 protected:
149 Axis m_xAxis;
151 Axis m_yAxis;
153 mutable AIDA::Annotation m_annotation;
155 std::unique_ptr<IMPLEMENTATION> m_rep;
157 std::string m_classType;
159 int m_sumEntries = 0;
160 };
161
162 template <class INTERFACE, class IMPLEMENTATION>
163 bool Generic2D<INTERFACE, IMPLEMENTATION>::setTitle( const std::string& title )
164 {
165 m_rep->SetTitle( title.c_str() );
166 if ( !annotation().addItem( "Title", title ) ) m_annotation.setValue( "Title", title );
167 if ( !annotation().addItem( "title", title ) ) annotation().setValue( "title", title );
168 return true;
169 }
170
171 template <class INTERFACE, class IMPLEMENTATION>
172 bool Generic2D<INTERFACE, IMPLEMENTATION>::setName( const std::string& newName )
173 {
174 m_rep->SetName( newName.c_str() );
175 m_annotation.setValue( "Name", newName );
176 return true;
177 }
178
179 template <class INTERFACE, class IMPLEMENTATION>
180 int Generic2D<INTERFACE, IMPLEMENTATION>::entries() const
181 {
182 return m_rep->GetEntries();
183 }
184
185 template <class INTERFACE, class IMPLEMENTATION>
186 int Generic2D<INTERFACE, IMPLEMENTATION>::allEntries() const
187 {
188 return m_rep->GetEntries();
189 }
190
191 template <class INTERFACE, class IMPLEMENTATION>
192 double Generic2D<INTERFACE, IMPLEMENTATION>::minBinHeight() const
193 {
194 return m_rep->GetMinimum();
195 }
196
197 template <class INTERFACE, class IMPLEMENTATION>
198 double Generic2D<INTERFACE, IMPLEMENTATION>::maxBinHeight() const
199 {
200 return m_rep->GetMaximum();
201 }
202
203 template <class INTERFACE, class IMPLEMENTATION>
204 double Generic2D<INTERFACE, IMPLEMENTATION>::sumBinHeights() const
205 {
206 return m_rep->GetSumOfWeights();
207 }
208
209 template <class INTERFACE, class IMPLEMENTATION>
210 double Generic2D<INTERFACE, IMPLEMENTATION>::sumAllBinHeights() const
211 {
212 return m_rep->GetSum();
213 }
214
215 template <class INTERFACE, class IMPLEMENTATION>
216 double Generic2D<INTERFACE, IMPLEMENTATION>::binRms( int indexX, int indexY ) const
217 {
218 return m_rep->GetBinError( rIndexX( indexX ), rIndexY( indexY ) );
219 }
220
221 template <class INTERFACE, class IMPLEMENTATION>
222 double Generic2D<INTERFACE, IMPLEMENTATION>::binMeanX( int indexX, int ) const
223 {
224 return m_rep->GetXaxis()->GetBinCenter( rIndexX( indexX ) );
225 }
226
227 template <class INTERFACE, class IMPLEMENTATION>
228 double Generic2D<INTERFACE, IMPLEMENTATION>::binMeanY( int, int indexY ) const
229 {
230 return m_rep->GetYaxis()->GetBinCenter( rIndexY( indexY ) );
231 }
232
233 template <class INTERFACE, class IMPLEMENTATION>
234 int Generic2D<INTERFACE, IMPLEMENTATION>::binEntriesX( int index ) const
235 {
236 int n = 0;
237 for ( int iY = -2; iY < yAxis().bins(); ++iY ) n += binEntries( index, iY );
238 return n;
239 }
240
241 template <class INTERFACE, class IMPLEMENTATION>
242 int Generic2D<INTERFACE, IMPLEMENTATION>::binEntriesY( int index ) const
243 {
244 int n = 0;
245 for ( int iX = -2; iX < xAxis().bins(); ++iX ) n += binEntries( iX, index );
246 return n;
247 }
248
249 template <class INTERFACE, class IMPLEMENTATION>
250 double Generic2D<INTERFACE, IMPLEMENTATION>::binHeight( int indexX, int indexY ) const
251 {
252 return m_rep->GetBinContent( rIndexX( indexX ), rIndexY( indexY ) );
253 }
254
255 template <class INTERFACE, class IMPLEMENTATION>
256 double Generic2D<INTERFACE, IMPLEMENTATION>::binHeightX( int index ) const
257 {
258 double s = 0;
259 for ( int iY = -2; iY < yAxis().bins(); ++iY ) {
260 s += binHeight( index, iY );
261 }
262 return s;
263 }
264
265 template <class INTERFACE, class IMPLEMENTATION>
266 double Generic2D<INTERFACE, IMPLEMENTATION>::binHeightY( int index ) const
267 {
268 double s = 0;
269 for ( int iX = -2; iX < xAxis().bins(); ++iX ) s += binHeight( iX, index );
270 return s;
271 }
272
273 template <class INTERFACE, class IMPLEMENTATION>
274 double Generic2D<INTERFACE, IMPLEMENTATION>::binError( int indexX, int indexY ) const
275 {
276 return m_rep->GetBinError( rIndexX( indexX ), rIndexY( indexY ) );
277 }
278
279 template <class INTERFACE, class IMPLEMENTATION>
280 double Generic2D<INTERFACE, IMPLEMENTATION>::meanX() const
281 {
282 return m_rep->GetMean( 1 );
283 }
284
285 template <class INTERFACE, class IMPLEMENTATION>
286 double Generic2D<INTERFACE, IMPLEMENTATION>::meanY() const
287 {
288 return m_rep->GetMean( 2 );
289 }
290
291 template <class INTERFACE, class IMPLEMENTATION>
292 double Generic2D<INTERFACE, IMPLEMENTATION>::rmsX() const
293 {
294 return m_rep->GetRMS( 1 );
295 }
296
297 template <class INTERFACE, class IMPLEMENTATION>
298 double Generic2D<INTERFACE, IMPLEMENTATION>::rmsY() const
299 {
300 return m_rep->GetRMS( 2 );
301 }
302
303 template <class INTERFACE, class IMPLEMENTATION>
304 int Generic2D<INTERFACE, IMPLEMENTATION>::coordToIndexX( double coord ) const
305 {
306 return xAxis().coordToIndex( coord );
307 }
308
309 template <class INTERFACE, class IMPLEMENTATION>
310 int Generic2D<INTERFACE, IMPLEMENTATION>::coordToIndexY( double coord ) const
311 {
312 return yAxis().coordToIndex( coord );
313 }
314
315 template <class INTERFACE, class IMPLEMENTATION>
316 bool Generic2D<INTERFACE, IMPLEMENTATION>::add( const INTERFACE& hist )
317 {
318 const Base* p = dynamic_cast<const Base*>( &hist );
319 if ( !p ) throw std::runtime_error( "Cannot add profile histograms of different implementations." );
320 m_rep->Add( p->m_rep.get() );
321 return true;
322 }
323
324 template <class INTERFACE, class IMPLEMENTATION>
325 int Generic2D<INTERFACE, IMPLEMENTATION>::extraEntries() const
326 {
327 return binEntries( AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN ) +
328 binEntries( AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN ) +
329 binEntries( AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN ) +
330 binEntries( AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN );
331 }
332
333 template <class INTERFACE, class IMPLEMENTATION>
334 double Generic2D<INTERFACE, IMPLEMENTATION>::equivalentBinEntries() const
335 {
336 if ( sumBinHeights() <= 0 ) return 0;
337 Stat_t stats[11]; // cover up to 3D...
338 m_rep->GetStats( stats );
339 return stats[0] * stats[0] / stats[1];
340 }
341
342 template <class INTERFACE, class IMPLEMENTATION>
343 bool Generic2D<INTERFACE, IMPLEMENTATION>::scale( double scaleFactor )
344 {
345 m_rep->Scale( scaleFactor );
346 return true;
347 }
348
349 template <class INTERFACE, class IMPLEMENTATION>
350 bool Generic2D<INTERFACE, IMPLEMENTATION>::reset()
351 {
352 m_sumEntries = 0;
353 m_rep->Reset();
354 return true;
355 }
356
357 template <class INTERFACE, class IMPLEMENTATION>
358 std::ostream& Generic2D<INTERFACE, IMPLEMENTATION>::print( std::ostream& s ) const
359 {
361 m_rep->Print( "all" );
362 return s;
363 }
364
366 template <class INTERFACE, class IMPLEMENTATION>
367 std::ostream& Generic2D<INTERFACE, IMPLEMENTATION>::write( std::ostream& s ) const
368 {
369 s << std::endl << "2D Histogram Table: " << std::endl;
370 s << "BinX, BinY, Height, Error " << std::endl;
371 for ( int i = 0; i < xAxis().bins(); ++i ) {
372 for ( int j = 0; j < yAxis().bins(); ++j ) {
373 s << binMeanX( i, j ) << ", " << binMeanY( i, j ) << ", " << binHeight( i, j ) << ", " << binError( i, j )
374 << std::endl;
375 }
376 }
377 s << std::endl;
378 return s;
379 }
380
382 template <class INTERFACE, class IMPLEMENTATION>
383 int Generic2D<INTERFACE, IMPLEMENTATION>::write( const char* file_name ) const
384 {
385 TFile* f = TFile::Open( file_name, "RECREATE" );
386 Int_t nbytes = m_rep->Write();
387 f->Close();
388 return nbytes;
389 }
390 }
391
392 #ifdef __clang__
393 #pragma clang diagnostic pop
394 #elif defined( __GNUC__ ) && __GNUC__ >= 5
395 #pragma GCC diagnostic pop
396 #endif
397
398 #endif // GAUDIPI_GENERIC2D_H
Gaudi::Generic2D::coordToIndexX
int coordToIndexX(double coordX) const override
Convenience method, equivalent to xAxis().coordToIndex(coord).
Definition: Generic2D.h:304
Gaudi::Generic2D::equivalentBinEntries
virtual double equivalentBinEntries() const
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
Definition: Generic2D.h:334
Gaudi::Generic2D::rmsX
double rmsX() const override
Returns the rms of the profile as calculated on filling-time projected on the X axis.
Definition: Generic2D.h:292
Gaudi::Generic2D::extraEntries
int extraEntries() const override
Get the number of entries in the underflow and overflow bins.
Definition: Generic2D.h:325
Gaudi::Generic2D::dimension
int dimension() const override
Get the Histogram&#39;s dimension.
Definition: Generic2D.h:139
std::endl
T endl(T...args)
Gaudi::Generic2D::Generic2D
Generic2D(IMPLEMENTATION *p)
constructor
Definition: Generic2D.h:45
Gaudi::Generic2D::reset
bool reset() override
Definition: Generic2D.h:350
Gaudi::Generic2D::binMeanY
double binMeanY(int indexX, int indexY) const override
The weighted mean along y of a given bin.
Definition: Generic2D.h:228
Gaudi::Generic2D::scale
virtual bool scale(double scaleFactor)
Scale the weights and the errors of all the IHistogram&#39;s bins (in-range and out-of-range ones) by a g...
Definition: Generic2D.h:343
Gaudi::Generic2D::rmsY
double rmsY() const override
Returns the rms of the profile as calculated on filling-time projected on the Y axis.
Definition: Generic2D.h:298
Gaudi::Generic2D::maxBinHeight
double maxBinHeight() const override
Get the maximum height of the in-range bins.
Definition: Generic2D.h:198
Gaudi::Generic2D::name
std::string name() const
object name
Definition: Generic2D.h:59
Gaudi::Generic2D::setName
bool setName(const std::string &newName)
Set the name of the object.
Definition: Generic2D.h:172
std::string
STL class.
Gaudi::Generic2D::rIndexX
virtual int rIndexX(int index) const
operator methods
Definition: Generic2D.h:72
Gaudi::Generic2D::binEntriesX
int binEntriesX(int indexX) const override
Equivalent to projectionX().binEntries(indexX).
Definition: Generic2D.h:234
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:228
GaudiPython.Persistency.add
def add(instance)
Definition: Persistency.py:39
Gaudi::Generic2D::sumBinHeights
double sumBinHeights() const override
Get the sum of in range bin heights in the IProfile.
Definition: Generic2D.h:204
Gaudi::Generic2D::binHeightY
double binHeightY(int indexY) const override
Equivalent to projectionY().binHeight(indexY).
Definition: Generic2D.h:266
Gaudi::Generic2D::binHeightX
double binHeightX(int indexX) const override
Equivalent to projectionX().binHeight(indexX).
Definition: Generic2D.h:256
HistogramBase.h
Gaudi::Generic2D::m_classType
std::string m_classType
class type
Definition: Generic2D.h:157
Axis.h
HiveAlgSequencer.h
h
Definition: HiveAlgSequencer.py:24
Gaudi::Generic2D::m_xAxis
Axis m_xAxis
X axis member.
Definition: Generic2D.h:149
Gaudi::Generic2D::Base
Generic2D< INTERFACE, IMPLEMENTATION > Base
Definition: Generic2D.h:39
std::runtime_error
STL class.
Gaudi::Generic2D::allEntries
int allEntries() const override
Get the number or all the entries, both in range and underflow/overflow bins of the IProfile...
Definition: Generic2D.h:186
AIDA::Annotation
Implementation of the AIDA IAnnotation interface class.
Definition: Annotation.h:17
Gaudi::Generic2D::coordToIndexY
int coordToIndexY(double coordY) const override
Convenience method, equivalent to yAxis().coordToIndex(coord).
Definition: Generic2D.h:310
Gaudi::Generic2D::sumExtraBinHeights
double sumExtraBinHeights() const override
Get the sum of the underflow and overflow bin height.
Definition: Generic2D.h:87
Gaudi::Generic2D::print
std::ostream & print(std::ostream &s) const override
Print (ASCII) the histogram into the output stream.
Definition: Generic2D.h:358
std::unique_ptr::get
T get(T...args)
Gaudi::Generic2D::annotation
const AIDA::IAnnotation & annotation() const override
Access annotation object (cons)
Definition: Generic2D.h:65
Gaudi::Generic2D::userLevelClassType
const std::string & userLevelClassType() const
The AIDA user-level unterface leaf class type.
Definition: Generic2D.h:137
Gaudi::Generic2D::annotation
AIDA::IAnnotation & annotation() override
Access annotation object.
Definition: Generic2D.h:63
Gaudi::Generic2D::binError
double binError(int indexX, int indexY) const override
The error on this bin.
Definition: Generic2D.h:274
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::Generic2D::m_annotation
AIDA::Annotation m_annotation
Object annotations.
Definition: Generic2D.h:153
Gaudi::Generic2D::setTitle
bool setTitle(const std::string &title) override
Set the title of the object.
Definition: Generic2D.h:163
Gaudi::Generic2D::representation
TObject * representation() const override
ROOT object implementation.
Definition: Generic2D.h:51
Gaudi::Generic2D::meanX
double meanX() const override
Returns the mean of the profile, as calculated on filling-time projected on the X axis...
Definition: Generic2D.h:280
print
void print(string text)
Definition: mergesort.cpp:30
std::string::c_str
T c_str(T...args)
GaudiPython.GaudiAlgs.write
write
Definition: GaudiAlgs.py:1259
Gaudi::Generic2D::m_yAxis
Axis m_yAxis
Y axis member.
Definition: Generic2D.h:151
Gaudi::Generic2D::write
std::ostream & write(std::ostream &s) const override
Write (ASCII) the histogram table into the output stream.
Definition: Generic2D.h:367
gaudirun.s
string s
Definition: gaudirun.py:253
Gaudi::Generic2D::binMeanX
double binMeanX(int indexX, int indexY) const override
The weighted mean along x of a given bin.
Definition: Generic2D.h:222
Gaudi::Generic2D::sumAllBinHeights
double sumAllBinHeights() const override
Get the sum of all the bins heights (including underflow and overflow bin).
Definition: Generic2D.h:210
Gaudi::Generic2D::binRms
virtual double binRms(int indexX, int indexY) const
The spread (RMS) of this bin.
Definition: Generic2D.h:216
Gaudi::Generic2D::m_rep
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic2D.h:155
Gaudi::Generic2D::binEntriesY
int binEntriesY(int indexY) const override
Equivalent to projectionY().binEntries(indexY).
Definition: Generic2D.h:242
Gaudi::Generic2D::entries
int entries() const override
Get the number or all the entries.
Definition: Generic2D.h:180
Gaudi::Generic2D::rIndexY
virtual int rIndexY(int index) const
operator methods
Definition: Generic2D.h:74
Gaudi::Generic2D::meanY
double meanY() const override
Returns the mean of the profile, as calculated on filling-time projected on the Y axis...
Definition: Generic2D.h:286
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:110
Gaudi::Generic2D::title
std::string title() const override
Get the title of the object.
Definition: Generic2D.h:55
std::ostream
STL class.
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
Annotation.h
Gaudi::Generic2D::add
bool add(const INTERFACE &h) override
Modifies this profile by adding the contents of profile to it.
Definition: Generic2D.h:316
Gaudi::Generic2D::yAxis
const AIDA::IAxis & yAxis() const override
Return the Y axis.
Definition: Generic2D.h:70
Gaudi::Generic2D::minBinHeight
double minBinHeight() const override
Get the minimum height of the in-range bins.
Definition: Generic2D.h:192
Gaudi::Generic2D::xAxis
const AIDA::IAxis & xAxis() const override
Return the X axis.
Definition: Generic2D.h:68
Gaudi::Generic2D::binHeight
double binHeight(int indexX, int indexY) const override
Total height of the corresponding bin (ie the sum of the weights in this bin).
Definition: Generic2D.h:250
Gaudi::Generic2D
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
Definition: Generic2D.h:36