All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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"
10 #include "AIDA/IHistogram3D.h"
11 #include <stdexcept>
12 
13 /*
14  * Gaudi namespace
15  */
16 namespace Gaudi {
17 
28  template<typename INTERFACE, typename IMPLEMENTATION>
29  class GAUDI_API Generic3D : virtual public INTERFACE, virtual public HistogramBase {
30  public:
33  Generic3D() : m_rep(0) {}
35  virtual ~Generic3D() { delete m_rep; }
37  TObject* representation() const { return m_rep; }
39  virtual void adoptRepresentation(TObject* rep);
40 
42  virtual int dimension() const { return 3; }
44  virtual std::string title() const { return m_annotation.value("Title");}
46  virtual bool setTitle(const std::string & title);
48  virtual std::string name() const { return m_annotation.value("Name"); }
50  bool setName( const std::string& newName);
52  virtual AIDA::IAnnotation & annotation() { return m_annotation; }
54  virtual const AIDA::IAnnotation & annotation() const { return m_annotation; }
55 
57  virtual int entries() const;
59  virtual int allEntries() const;
61  virtual double sumBinHeights() const;
63  virtual double sumAllBinHeights() const;
65  virtual double sumExtraBinHeights ( ) const { return sumAllBinHeights()-sumBinHeights(); }
67  virtual double minBinHeight() const;
69  virtual double maxBinHeight() const;
70 
71  int rIndexX(int index) const { return m_xAxis.rIndex(index);}
72  int rIndexY(int index) const { return m_yAxis.rIndex(index);}
73  int rIndexZ(int index) const { return m_zAxis.rIndex(index);}
74 
76  double binMeanX(int indexX,int ,int ) const
77  { return (m_rep->GetXaxis())->GetBinCenter( rIndexX(indexX) ); }
79  double binMeanY(int,int indexY,int ) const
80  { return (m_rep->GetYaxis())->GetBinCenter( rIndexY(indexY) ); }
82  double binMeanZ(int ,int ,int indexZ) const
83  { return (m_rep->GetYaxis())->GetBinCenter( rIndexY(indexZ) ); }
85  int binEntries(int indexX,int indexY,int indexZ) const {
86  if (binHeight(indexX, indexY, indexZ)<=0) return 0;
87  double xx = binHeight(indexX, indexY, indexZ)/binError(indexX, indexY, indexZ);
88  return int(xx*xx+0.5);
89  }
91  virtual int binEntriesX(int index) const {
92  int n = 0;
93  for (int i = -2; i < yAxis().bins(); ++i)
94  for (int j = -2; j < zAxis().bins(); ++j)
95  n += binEntries(index,i,j);
96  return n;
97 
98  }
100  virtual int binEntriesY(int index) const {
101  int n = 0;
102  for (int i = -2; i < xAxis().bins(); ++i)
103  for (int j = -2; j < zAxis().bins(); ++j)
104  n += binEntries(i,index,j);
105  return n;
106  }
107 
109  virtual int binEntriesZ(int index) const {
110  int n = 0;
111  for (int i = -2; i < xAxis().bins(); ++i)
112  for (int j = -2; j < yAxis().bins(); ++j)
113  n += binEntries(i,j,index);
114  return n;
115  }
116 
118  double binHeight ( int indexX,int indexY,int indexZ ) const
119  { return m_rep->GetBinContent ( rIndexX(indexX), rIndexY(indexY), rIndexZ(indexZ) ); }
120 
122  virtual double binHeightX(int index) const {
123  double s = 0;
124  for (int i = -2; i < yAxis().bins(); ++i)
125  for (int j = -2; j < zAxis().bins(); ++j)
126  s += binHeight(index,i,j);
127  return s;
128  }
130  virtual double binHeightY(int index) const {
131  double s = 0;
132  for (int i = -2; i < xAxis().bins(); ++i)
133  for (int j = -2; j < zAxis().bins(); ++j)
134  s += binHeight(i,index,j);
135  return s;
136  }
138  virtual double binHeightZ(int index) const {
139  double s = 0;
140  for (int i = -2; i < xAxis().bins(); ++i)
141  for (int j = -2; j < yAxis().bins(); ++j)
142  s += binHeight(i,j,index);
143  return s;
144  }
146  virtual double binError ( int indexX,int indexY,int indexZ ) const
147  { return m_rep->GetBinError ( rIndexX(indexX), rIndexY(indexY ), rIndexZ(indexZ ) ); }
149  virtual double meanX ( ) const { return m_rep->GetMean ( 1); }
150 
152  virtual double meanY ( ) const { return m_rep->GetMean ( 2 ); }
154  virtual double meanZ ( ) const { return m_rep->GetMean ( 3 ); }
156  virtual double rmsX ( ) const { return m_rep->GetRMS( 1 ); }
158  virtual double rmsY ( ) const { return m_rep->GetRMS( 2 ); }
160  virtual double rmsZ ( ) const { return m_rep->GetRMS( 3 ); }
162  virtual const AIDA::IAxis & xAxis ( ) const { return m_xAxis; }
164  virtual const AIDA::IAxis & yAxis ( ) const { return m_yAxis; }
166  virtual const AIDA::IAxis & zAxis ( ) const { return m_zAxis; }
168  virtual int coordToIndexX ( double coord ) const { return xAxis().coordToIndex(coord);}
170  virtual int coordToIndexY ( double coord ) const { return yAxis().coordToIndex(coord);}
172  virtual int coordToIndexZ ( double coord ) const { return zAxis().coordToIndex(coord);}
173 
175  virtual double equivalentBinEntries ( ) const;
177  virtual bool scale( double scaleFactor );
179  virtual bool add ( const INTERFACE & hist ) {
180  const Base* p = dynamic_cast<const Base*>(&hist);
181  if ( p ) {
182  m_rep->Add(p->m_rep);
183  return true;
184  }
185  throw std::runtime_error("Cannot add profile histograms of different implementations.");
186  }
187 
188  // overwrite extraentries
189  int extraEntries() const {
190  return
191  binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
192  binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
193  binEntries(AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
194  binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
195  binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
196  binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
197  binEntries(AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN);
198  }
200  virtual std::ostream& print( std::ostream& s ) const;
202  virtual std::ostream& write( std::ostream& s ) const;
204  virtual int write( const char* file_name ) const;
205 
206  protected:
213  IMPLEMENTATION* m_rep;
214  // class type
215  std::string m_classType;
216  // cache sumEntries (allEntries) when setting contents since Root can't compute by himself
218  }; // end class IHistogram3D
219 
220  template <class INTERFACE, class IMPLEMENTATION>
221  bool Generic3D<INTERFACE,IMPLEMENTATION>::setTitle(const std::string & title) {
222  m_rep->SetTitle(title.c_str());
223  if ( !annotation().addItem( "Title", title ) )
224  m_annotation.setValue( "Title" , title );
225  if ( !annotation().addItem( "title", title ) )
226  annotation().setValue( "title", title );
227  return true;
228  }
229 
230  template <class INTERFACE, class IMPLEMENTATION>
231  bool Generic3D<INTERFACE,IMPLEMENTATION>::setName( const std::string& newName ) {
232  m_rep->SetName(newName.c_str());
233  m_annotation.setValue( "Name", newName );
234  return true;
235  }
236  template <class INTERFACE, class IMPLEMENTATION>
238  return (int)m_rep->GetEntries();
239  }
240 
241  template <class INTERFACE, class IMPLEMENTATION>
243  return int(m_rep->GetEntries());
244  }
245 
246  template <class INTERFACE, class IMPLEMENTATION>
248  return m_rep->GetMinimum();
249  }
250 
251  template <class INTERFACE, class IMPLEMENTATION>
253  return m_rep->GetMaximum();
254  }
255 
256  template <class INTERFACE, class IMPLEMENTATION>
258  return m_rep->GetSumOfWeights();
259  }
260 
261  template <class INTERFACE, class IMPLEMENTATION>
263  return m_rep->GetSum();
264  }
265 
266  template <class INTERFACE, class IMPLEMENTATION>
268  if (sumBinHeights() <= 0) return 0;
269  Stat_t stats[11]; // cover up to 3D...
270  m_rep->GetStats(stats);
271  return stats[0]*stats[0]/stats[1];
272  }
273 
274  template <class INTERFACE, class IMPLEMENTATION>
276  m_rep->Scale ( scaleFactor );
277  return true;
278  }
279 
280  template <class INTERFACE, class IMPLEMENTATION>
281  std::ostream& Generic3D<INTERFACE,IMPLEMENTATION>::print( std::ostream& s ) const
282  {
284  m_rep->Print("all");
285  return s;
286  }
287 
288 
290  template <class INTERFACE, class IMPLEMENTATION>
291  std::ostream& Generic3D<INTERFACE,IMPLEMENTATION>::write( std::ostream& s ) const
292  {
293  s << "\n3D Histogram Table: " << std::endl;
294  s << "BinX, BinY, BinZ, Height, Error " << std::endl;
295  for ( int i = 0; i < xAxis().bins(); ++i )
296  for ( int j = 0; j < yAxis().bins(); ++j )
297  for ( int k = 0; k < zAxis().bins(); ++k )
298  s << binMeanX( i, j, k ) << ", "
299  << binMeanY( i, j, k ) << ", "
300  << binMeanZ( i, j, k ) << ", "
301  << binHeight( i, j, k ) << ", "
302  << binError ( i, j, k ) << std::endl;
303  s << std::endl;
304  return s;
305  }
306 
308  template <class INTERFACE, class IMPLEMENTATION>
309  int Generic3D<INTERFACE,IMPLEMENTATION>::write( const char* file_name ) const
310  {
311  TFile *f = TFile::Open(file_name,"RECREATE");
312  Int_t nbytes = m_rep->Write();
313  f->Close();
314  return nbytes;
315  }
316 } // end namespace AIDA
317 #endif // GAUDIPI_GENERIC3D_H
virtual double minBinHeight() const
Get the minimum height of the in-range bins.
Definition: Generic3D.h:247
int rIndexZ(int index) const
Definition: Generic3D.h:73
int rIndexX(int index) const
Definition: Generic3D.h:71
virtual double binHeightY(int index) const
Sum of all the heights of the bins along a given y bin.
Definition: Generic3D.h:130
virtual int allEntries() const
Get the number or all the entries, both in range and underflow/overflow bins of the IProfile...
Definition: Generic3D.h:242
virtual double sumBinHeights() const
Get the sum of in range bin heights in the IProfile.
Definition: Generic3D.h:257
Gaudi::Axis m_xAxis
Definition: Generic3D.h:207
int binEntries(int indexX, int indexY, int indexZ) const
Number of entries in the corresponding bin (ie the number of times fill was calle d for this bin)...
Definition: Generic3D.h:85
Gaudi::Axis m_yAxis
Definition: Generic3D.h:208
double binMeanX(int indexX, int, int) const
The weighted mean along the x axis of a given bin.
Definition: Generic3D.h:76
virtual double rmsY() const
The RMS of the IHistogram3D along the y axis.
Definition: Generic3D.h:158
virtual int coordToIndexY(double coord) const
Get the bin number corresponding to a given coordinate along the y axis.
Definition: Generic3D.h:170
double binMeanZ(int, int, int indexZ) const
The weighted mean along the z axis of a given bin.
Definition: Generic3D.h:82
virtual std::ostream & print(std::ostream &s) const
Print (ASCII) the histogram into the output stream.
Definition: Generic3D.h:281
virtual double rmsZ() const
The RMS of the IHistogram3D along the z axis.
Definition: Generic3D.h:160
virtual int entries() const
Get the number or all the entries.
Definition: Generic3D.h:237
virtual double binHeightZ(int index) const
Sum of all the heights of the bins along a given z bin.
Definition: Generic3D.h:138
virtual int coordToIndexZ(double coord) const
Get the bin number corresponding to a given coordinate along the z axis.
Definition: Generic3D.h:172
IMPLEMENTATION * m_rep
Reference to underlying implementation.
Definition: Generic3D.h:213
virtual double sumExtraBinHeights() const
Get the sum of the underflow and overflow bin height.
Definition: Generic3D.h:65
virtual double meanZ() const
The mean of the IHistogram3D along the z axis.
Definition: Generic3D.h:154
virtual double binHeightX(int index) const
Sum of all the heights of the bins along a given x bin.
Definition: Generic3D.h:122
virtual const AIDA::IAxis & zAxis() const
Get the z axis of the IHistogram3D.
Definition: Generic3D.h:166
virtual ~Generic3D()
Destructor.
Definition: Generic3D.h:35
virtual double meanY() const
The mean of the IHistogram3D along the y axis.
Definition: Generic3D.h:152
int extraEntries() const
Definition: Generic3D.h:189
virtual AIDA::IAnnotation & annotation()
Access annotation object.
Definition: Generic3D.h:52
virtual std::string name() const
object name
Definition: Generic3D.h:48
double binMeanY(int, int indexY, int) const
The weighted mean along the y axis of a given bin.
Definition: Generic3D.h:79
Implementation of the AIDA IAnnotation interface class.
Definition: Annotation.h:18
bool setName(const std::string &newName)
Sets the name of the object.
Definition: Generic3D.h:231
Gaudi::Axis m_zAxis
Definition: Generic3D.h:209
int rIndexY(int index) const
Definition: Generic3D.h:72
Generic3D< INTERFACE, IMPLEMENTATION > Base
Definition: Generic3D.h:31
virtual bool add(const INTERFACE &hist)
Add to this Histogram3D the contents of another IHistogram3D.
Definition: Generic3D.h:179
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:118
virtual std::string title() const
Get the title of the object.
Definition: Generic3D.h:44
virtual int binEntriesX(int index) const
Sum of all the entries of the bins along a given x bin.
Definition: Generic3D.h:91
virtual double equivalentBinEntries() const
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
Definition: Generic3D.h:267
Common base class for all histograms Use is solely functional to minimize dynamic_casts inside Histog...
Definition: HistogramBase.h:22
AIDA::Annotation m_annotation
Object annotations.
Definition: Generic3D.h:211
virtual double binError(int indexX, int indexY, int indexZ) const
The error of a given bin.
Definition: Generic3D.h:146
virtual const AIDA::IAxis & xAxis() const
Get the x axis of the IHistogram3D.
Definition: Generic3D.h:162
std::string m_classType
Definition: Generic3D.h:215
virtual double rmsX() const
The RMS of the IHistogram3D along the x axis.
Definition: Generic3D.h:156
TObject * representation() const
ROOT object implementation.
Definition: Generic3D.h:37
string s
Definition: gaudirun.py:210
virtual const AIDA::IAnnotation & annotation() const
Access annotation object (cons)
Definition: Generic3D.h:54
virtual int coordToIndexX(double coord) const
Get the bin number corresponding to a given coordinate along the x axis.
Definition: Generic3D.h:168
This is a number of static methods for bootstrapping the Gaudi framework.
Definition: Bootstrap.h:15
Generic3D()
Default constructor.
Definition: Generic3D.h:33
virtual bool setTitle(const std::string &title)
Set the title of the object.
Definition: Generic3D.h:221
#define GAUDI_API
Definition: Kernel.h:108
list i
Definition: ana.py:128
virtual int binEntriesZ(int index) const
Sum of all the entries of the bins along a given z bin.
Definition: Generic3D.h:109
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: Generic3D.h:275
virtual double sumAllBinHeights() const
Get the sum of all the bins heights (including underflow and overflow bin).
Definition: Generic3D.h:262
virtual int dimension() const
Get the Histogram's dimension.
Definition: Generic3D.h:42
An IAxis represents a binned histogram axis.
Definition: Axis.h:31
virtual const AIDA::IAxis & yAxis() const
Get the y axis of the IHistogram3D.
Definition: Generic3D.h:164
virtual double maxBinHeight() const
Get the maximum height of the in-range bins.
Definition: Generic3D.h:252
virtual int binEntriesY(int index) const
Sum of all the entries of the bins along a given y bin.
Definition: Generic3D.h:100
virtual double meanX() const
The mean of the IHistogram3D along the x axis.
Definition: Generic3D.h:149
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
Definition: Generic3D.h:29
virtual std::ostream & write(std::ostream &s) const
Write (ASCII) the histogram table into the output stream.
Definition: Generic3D.h:291