| The Gaudi Framework v32r1 (f65d50dc)

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