Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 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 
4 #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:
207  Gaudi::Axis m_xAxis;
208  Gaudi::Axis m_yAxis;
209  Gaudi::Axis m_zAxis;
213  IMPLEMENTATION* m_rep;
214  // class type
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>
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>
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>
282  {
284  m_rep->Print("all");
285  return s;
286  }
287 
288 
290  template <class INTERFACE, class IMPLEMENTATION>
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

Generated at Wed Nov 28 2012 12:17:10 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004