| The Gaudi Framework v27r1

- 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 #include "AIDA_visibility_hack.h"
5
6 #include <stdexcept>
7 #include <memory>
8 #include "AIDA/IProfile2D.h"
9 #include "GaudiKernel/HistogramBase.h"
10 #include "Annotation.h"
11 #include "Axis.h"
12 #include "TFile.h"
13
14
15 #ifdef __clang__
16 #pragma clang diagnostic push
17 // Hide warning message:
18 // warning: 'XYZ' overrides a member function but is not marked 'override'
19 #pragma clang diagnostic ignored "-Winconsistent-missing-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 protected:
42 Generic2D(IMPLEMENTATION* p) : m_rep(p) { }
43 public:
45 ~Generic2D() override = default;
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;
124 virtual bool scale( double scaleFactor );
126 bool add(const INTERFACE & h) override;
127 // overwrite reset
128 bool reset ( ) override;
130 void * cast(const std::string & className) const;
132 const std::string& userLevelClassType() const { return m_classType; }
134 int dimension() const override { return 2; }
136 std::ostream& print( std::ostream& s ) const override;
138 std::ostream& write( std::ostream& s ) const override;
140 int write( const char* file_name ) const override;
141
142 protected:
144 Axis m_xAxis;
146 Axis m_yAxis;
148 mutable AIDA::Annotation m_annotation;
150 std::unique_ptr<IMPLEMENTATION> m_rep;
152 std::string m_classType;
154 int m_sumEntries = 0;
155 };
156
157 template <class INTERFACE, class IMPLEMENTATION>
158 bool Generic2D<INTERFACE,IMPLEMENTATION>::setTitle(const std::string & title) {
159 m_rep->SetTitle(title.c_str());
160 if ( !annotation().addItem( "Title", title ) )
161 m_annotation.setValue( "Title" , title );
162 if ( !annotation().addItem( "title", title ) )
163 annotation().setValue( "title", title );
164 return true;
165 }
166
167 template <class INTERFACE, class IMPLEMENTATION>
168 bool Generic2D<INTERFACE,IMPLEMENTATION>::setName( const std::string& newName ) {
169 m_rep->SetName(newName.c_str());
170 m_annotation.setValue( "Name", newName );
171 return true;
172 }
173
174 template <class INTERFACE, class IMPLEMENTATION>
175 int Generic2D<INTERFACE,IMPLEMENTATION>::entries() const {
176 return m_rep->GetEntries();
177 }
178
179 template <class INTERFACE, class IMPLEMENTATION>
180 int Generic2D<INTERFACE,IMPLEMENTATION>::allEntries ( ) const {
181 return m_rep->GetEntries();
182 }
183
184 template <class INTERFACE, class IMPLEMENTATION>
185 double Generic2D<INTERFACE,IMPLEMENTATION>::minBinHeight() const {
186 return m_rep->GetMinimum();
187 }
188
189 template <class INTERFACE, class IMPLEMENTATION>
190 double Generic2D<INTERFACE,IMPLEMENTATION>::maxBinHeight() const {
191 return m_rep->GetMaximum();
192 }
193
194 template <class INTERFACE, class IMPLEMENTATION>
195 double Generic2D<INTERFACE,IMPLEMENTATION>::sumBinHeights () const {
196 return m_rep->GetSumOfWeights();
197 }
198
199 template <class INTERFACE, class IMPLEMENTATION>
200 double Generic2D<INTERFACE,IMPLEMENTATION>::sumAllBinHeights () const {
201 return m_rep->GetSum();
202 }
203
204 template <class INTERFACE, class IMPLEMENTATION>
205 double Generic2D<INTERFACE,IMPLEMENTATION>::binRms(int indexX,int indexY) const {
206 return m_rep->GetBinError ( rIndexX(indexX), rIndexY(indexY) );
207 }
208
209 template <class INTERFACE, class IMPLEMENTATION>
210 double Generic2D<INTERFACE,IMPLEMENTATION>::binMeanX(int indexX,int ) const {
211 return m_rep->GetXaxis()->GetBinCenter( rIndexX(indexX) );
212 }
213
214 template <class INTERFACE, class IMPLEMENTATION>
215 double Generic2D<INTERFACE,IMPLEMENTATION>::binMeanY(int,int indexY) const {
216 return m_rep->GetYaxis()->GetBinCenter( rIndexY(indexY) );
217 }
218
219 template <class INTERFACE, class IMPLEMENTATION>
220 int Generic2D<INTERFACE,IMPLEMENTATION>::binEntriesX(int index) const {
221 int n = 0;
222 for (int iY = -2; iY < yAxis().bins(); ++iY)
223 n += binEntries(index,iY);
224 return n;
225 }
226
227 template <class INTERFACE, class IMPLEMENTATION>
228 int Generic2D<INTERFACE,IMPLEMENTATION>::binEntriesY(int index) const {
229 int n = 0;
230 for (int iX = -2; iX < xAxis().bins(); ++iX)
231 n += binEntries(iX,index);
232 return n;
233 }
234
235 template <class INTERFACE, class IMPLEMENTATION>
236 double Generic2D<INTERFACE,IMPLEMENTATION>::binHeight ( int indexX,int indexY ) const {
237 return m_rep->GetBinContent ( rIndexX(indexX), rIndexY(indexY) );
238 }
239
240 template <class INTERFACE, class IMPLEMENTATION>
241 double Generic2D<INTERFACE,IMPLEMENTATION>::binHeightX(int index) const {
242 double s = 0;
243 for (int iY = -2; iY < yAxis().bins(); ++iY) {
244 s += binHeight(index,iY);
245 }
246 return s;
247 }
248
249 template <class INTERFACE, class IMPLEMENTATION>
250 double Generic2D<INTERFACE,IMPLEMENTATION>::binHeightY(int index) const {
251 double s = 0;
252 for (int iX = -2; iX < xAxis().bins(); ++iX)
253 s += binHeight(iX,index);
254 return s;
255 }
256
257 template <class INTERFACE, class IMPLEMENTATION>
258 double Generic2D<INTERFACE,IMPLEMENTATION>::binError(int indexX,int indexY) const {
259 return m_rep->GetBinError ( rIndexX(indexX), rIndexY(indexY ) );
260 }
261
262 template <class INTERFACE, class IMPLEMENTATION>
263 double Generic2D<INTERFACE,IMPLEMENTATION>::meanX() const {
264 return m_rep->GetMean(1);
265 }
266
267 template <class INTERFACE, class IMPLEMENTATION>
268 double Generic2D<INTERFACE,IMPLEMENTATION>::meanY() const {
269 return m_rep->GetMean(2);
270 }
271
272 template <class INTERFACE, class IMPLEMENTATION>
273 double Generic2D<INTERFACE,IMPLEMENTATION>::rmsX() const {
274 return m_rep->GetRMS(1);
275 }
276
277 template <class INTERFACE, class IMPLEMENTATION>
278 double Generic2D<INTERFACE,IMPLEMENTATION>::rmsY() const {
279 return m_rep->GetRMS(2);
280 }
281
282 template <class INTERFACE, class IMPLEMENTATION>
283 int Generic2D<INTERFACE,IMPLEMENTATION>::coordToIndexX ( double coord ) const {
284 return xAxis().coordToIndex(coord);
285 }
286
287 template <class INTERFACE, class IMPLEMENTATION>
288 int Generic2D<INTERFACE,IMPLEMENTATION>::coordToIndexY ( double coord ) const {
289 return yAxis().coordToIndex(coord);
290 }
291
292 template <class INTERFACE, class IMPLEMENTATION>
293 bool Generic2D<INTERFACE,IMPLEMENTATION>::add ( const INTERFACE & hist ) {
294 const Base* p = dynamic_cast<const Base*>(&hist);
295 if ( !p ) throw std::runtime_error("Cannot add profile histograms of different implementations.");
296 m_rep->Add(p->m_rep.get());
297 return true;
298 }
299
300 template <class INTERFACE, class IMPLEMENTATION>
301 int Generic2D<INTERFACE,IMPLEMENTATION>::extraEntries() const {
302 return
303 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
304 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
305 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
306 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN);
307 }
308
309 template <class INTERFACE, class IMPLEMENTATION>
310 double Generic2D<INTERFACE,IMPLEMENTATION>::equivalentBinEntries() const {
311 if (sumBinHeights() <= 0) return 0;
312 Stat_t stats[11]; // cover up to 3D...
313 m_rep->GetStats(stats);
314 return stats[0]*stats[0]/stats[1];
315 }
316
317 template <class INTERFACE, class IMPLEMENTATION>
318 bool Generic2D<INTERFACE,IMPLEMENTATION>::scale(double scaleFactor) {
319 m_rep->Scale ( scaleFactor );
320 return true;
321 }
322
323 template <class INTERFACE, class IMPLEMENTATION>
324 bool Generic2D<INTERFACE,IMPLEMENTATION>::reset ( ) {
325 m_sumEntries = 0;
326 m_rep->Reset ( );
327 return true;
328 }
329
330 template <class INTERFACE, class IMPLEMENTATION>
331 std::ostream& Generic2D<INTERFACE,IMPLEMENTATION>::print( std::ostream& s ) const
332 {
334 m_rep->Print("all");
335 return s;
336 }
337
339 template <class INTERFACE, class IMPLEMENTATION>
340 std::ostream& Generic2D<INTERFACE,IMPLEMENTATION>::write( std::ostream& s ) const
341 {
342 s << std::endl << "2D Histogram Table: " << std::endl;
343 s << "BinX, BinY, Height, Error " << std::endl;
344 for ( int i = 0; i < xAxis().bins(); ++i ) {
345 for ( int j = 0; j < yAxis().bins(); ++j ) {
346 s << binMeanX( i, j ) << ", "
347 << binMeanY( i, j ) << ", "
348 << binHeight( i, j ) << ", "
349 << binError ( i, j ) << std::endl;
350 }
351 }
352 s << std::endl;
353 return s;
354 }
355
357 template <class INTERFACE, class IMPLEMENTATION>
358 int Generic2D<INTERFACE,IMPLEMENTATION>::write( const char* file_name ) const
359 {
360 TFile *f = TFile::Open(file_name,"RECREATE");
361 Int_t nbytes = m_rep->Write();
362 f->Close();
363 return nbytes;
364 }
365 }
366
367 #ifdef __clang__
368 #pragma clang diagnostic pop
369 #endif
370
371 #endif // GAUDIPI_GENERIC2D_H
Gaudi::Generic2D::binHeightY
double binHeightY(int indexY) const override
Equivalent to projectionY().binHeight(indexY).
Definition: Generic2D.h:250
Gaudi::Generic2D::binMeanX
double binMeanX(int indexX, int indexY) const override
The weighted mean along x of a given bin.
Definition: Generic2D.h:210
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:134
Gaudi::Generic2D::equivalentBinEntries
virtual double equivalentBinEntries() const
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
Definition: Generic2D.h:310
Gaudi::Generic2D::coordToIndexY
int coordToIndexY(double coordY) const override
Convenience method, equivalent to yAxis().coordToIndex(coord).
Definition: Generic2D.h:288
Gaudi::Generic2D::Base
Generic2D< INTERFACE, IMPLEMENTATION > Base
Definition: Generic2D.h:37
Gaudi::Generic2D::annotation
const AIDA::IAnnotation & annotation() const override
Access annotation object (cons)
Definition: Generic2D.h:61
AIDA_visibility_hack.h
std::endl
T endl(T...args)
Gaudi::Generic2D::Generic2D
Generic2D(IMPLEMENTATION *p)
constructor
Definition: Generic2D.h:42
Gaudi::Generic2D::coordToIndexX
int coordToIndexX(double coordX) const override
Convenience method, equivalent to xAxis().coordToIndex(coord).
Definition: Generic2D.h:283
Gaudi::Generic2D::reset
bool reset() override
Definition: Generic2D.h:324
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:263
Gaudi::Generic2D::entries
int entries() const override
Get the number or all the entries.
Definition: Generic2D.h:175
Gaudi::Generic2D::binEntriesY
int binEntriesY(int indexY) const override
Equivalent to projectionY().binEntries(indexY).
Definition: Generic2D.h:228
Gaudi::Generic2D::minBinHeight
double minBinHeight() const override
Get the minimum height of the in-range bins.
Definition: Generic2D.h:185
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:318
GaudiPluginService.cpluginsvc.n
list n
Definition: cpluginsvc.py:217
Gaudi::Generic2D::name
std::string name() const
object name
Definition: Generic2D.h:55
Gaudi::Generic2D::setName
bool setName(const std::string &newName)
Set the name of the object.
Definition: Generic2D.h:168
std::string
STL class.
Gaudi::Generic2D::rIndexX
virtual int rIndexX(int index) const
operator methods
Definition: Generic2D.h:68
Gaudi::Generic2D::binHeightX
double binHeightX(int indexX) const override
Equivalent to projectionX().binHeight(indexX).
Definition: Generic2D.h:241
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:195
GaudiPython.Persistency.add
def add(instance)
Definition: Persistency.py:32
HistogramBase.h
Gaudi::Generic2D::m_classType
std::string m_classType
class type
Definition: Generic2D.h:152
Axis.h
Gaudi::Generic2D::m_xAxis
Axis m_xAxis
X axis member.
Definition: Generic2D.h:144
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:340
AIDA::Annotation
Implementation of the AIDA IAnnotation interface class.
Definition: Annotation.h:18
HiveAlgSequencer.h
tuple h
Definition: HiveAlgSequencer.py:24
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:180
Gaudi::Generic2D::userLevelClassType
const std::string & userLevelClassType() const
The AIDA user-level unterface leaf class type.
Definition: Generic2D.h:132
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:301
Gaudi::Generic2D::m_annotation
AIDA::Annotation m_annotation
Object annotations.
Definition: Generic2D.h:148
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:278
Gaudi::Generic2D::setTitle
bool setTitle(const std::string &title) override
Set the title of the object.
Definition: Generic2D.h:158
Gaudi::Generic2D::binError
double binError(int indexX, int indexY) const override
The error on this bin.
Definition: Generic2D.h:258
print
void print(string text)
Definition: mergesort.cpp:33
std::string::c_str
T c_str(T...args)
Gaudi::Generic2D::m_yAxis
Axis m_yAxis
Y axis member.
Definition: Generic2D.h:146
gaudirun.s
string s
Definition: gaudirun.py:245
Gaudi::Generic2D::binRms
virtual double binRms(int indexX, int indexY) const
The spread (RMS) of this bin.
Definition: Generic2D.h:205
Gaudi::Generic2D::m_rep
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic2D.h:150
Gaudi::Generic2D::binEntriesX
int binEntriesX(int indexX) const override
Equivalent to projectionX().binEntries(indexX).
Definition: Generic2D.h:220
Gaudi::Generic2D::rIndexY
virtual int rIndexY(int index) const
operator methods
Definition: Generic2D.h:70
Gaudi::Generic2D::maxBinHeight
double maxBinHeight() const override
Get the maximum height of the in-range bins.
Definition: Generic2D.h:190
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:268
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:107
ana.i
list i
Definition: ana.py:128
Gaudi::Generic2D::print
std::ostream & print(std::ostream &s) const override
Print (ASCII) the histogram into the output stream.
Definition: Generic2D.h:331
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:200
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:273
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::Generic2D::binMeanY
double binMeanY(int indexX, int indexY) const override
The weighted mean along y of a given bin.
Definition: Generic2D.h:215
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:293
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:236