All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Generic1D.h
Go to the documentation of this file.
1 #ifndef GAUDISVC_GENERIC1D_H
2 #define GAUDISVC_GENERIC1D_H 1
3 #include "AIDA_visibility_hack.h"
5 
6 #include <stdexcept>
7 #include "Axis.h"
8 #include "Annotation.h"
10 #include "AIDA/IProfile1D.h"
11 #include "TFile.h"
12 
13 /*
14  * Gaudi namespace
15  */
16 namespace Gaudi {
17 
28  template <class INTERFACE, class IMPLEMENTATION>
29  class GAUDI_API Generic1D : virtual public INTERFACE, virtual public HistogramBase {
30  public:
33  Generic1D() : m_rep(0) {}
35  virtual ~Generic1D() { delete m_rep; }
37  virtual const std::string& userLevelClassType() const{ return m_classType; }
39  virtual void* cast(const std::string& cl) const;
41  TObject* representation() const { return m_rep; }
43  virtual void adoptRepresentation(TObject*rep);
45  virtual std::string title() const { return m_annotation.value("Title"); }
47  virtual bool setTitle(const std::string & title);
49  std::string name() const { return m_annotation.value("Name"); }
51  bool setName( const std::string& newName );
53  virtual AIDA::IAnnotation & annotation() { return m_annotation; }
55  virtual const AIDA::IAnnotation & annotation() const { return m_annotation; }
57  Axis & axis () { return m_axis; }
59  const Axis & axis () const { return m_axis; }
60 
62  virtual int entries() const { return (int)m_rep->GetEntries(); }
64  virtual int allEntries() const { return int(m_rep->GetEntries()); }
66  virtual int extraEntries() const;
68  virtual int binEntries ( int index ) const;
69  // spread
70  virtual double binRms(int index) const;
72  virtual double sumBinHeights() const { return m_rep->GetSumOfWeights(); }
74  virtual double sumAllBinHeights() const { return m_rep->GetSum(); }
76  virtual double sumExtraBinHeights () const { return sumAllBinHeights()-sumBinHeights(); }
78  virtual double minBinHeight() const { return m_rep->GetMinimum(); }
80  virtual double maxBinHeight() const { return m_rep->GetMaximum(); }
81 
83  virtual double equivalentBinEntries ( ) const;
85  virtual bool scale( double scaleFactor );
87  virtual bool reset();
89  virtual bool add(const INTERFACE & profile);
91  virtual int rIndex(int index) const { return m_axis.rIndex(index);}
93  virtual double binMean(int index) const;
95  virtual double binHeight(int index) const;
97  virtual double binError(int index) const;
99  virtual double mean() const { return m_rep->GetMean(); }
101  virtual double rms () const { return m_rep->GetRMS(); }
103  virtual int coordToIndex ( double coord ) const { return axis().coordToIndex(coord);}
105  virtual int dimension ( ) const { return 1; }
107  virtual std::ostream& print( std::ostream& s ) const;
109  virtual std::ostream& write( std::ostream& s ) const;
111  virtual int write( const char* file_name ) const;
112 
113  protected:
119  IMPLEMENTATION* m_rep;
120  // class type
121  std::string m_classType;
122  // cache sumEntries (allEntries) when setting contents since Root can't compute by himself
124  }; // end class Generic1D
125 
126  template <class INTERFACE, class IMPLEMENTATION>
127  bool Generic1D<INTERFACE,IMPLEMENTATION>::setTitle(const std::string & title) {
128  m_rep->SetTitle(title.c_str());
129  if ( !annotation().addItem( "Title", title ) )
130  m_annotation.setValue( "Title" , title );
131  if ( !annotation().addItem( "title", title ) )
132  annotation().setValue( "title", title );
133  return true;
134  }
135 
136  template <class INTERFACE, class IMPLEMENTATION>
137  bool Generic1D<INTERFACE,IMPLEMENTATION>::setName( const std::string& newName ) {
138  m_rep->SetName(newName.c_str());
139  m_annotation.setValue( "Name", newName );
140  return true;
141  }
142 
143  template <class INTERFACE, class IMPLEMENTATION>
145  return m_rep->GetBinError ( rIndex(index) );
146  }
147 
148  template <class INTERFACE, class IMPLEMENTATION>
149  double Generic1D<INTERFACE,IMPLEMENTATION>::binMean ( int index ) const {
150  return m_rep->GetBinCenter ( rIndex(index) );
151  }
152 
153  template <class INTERFACE, class IMPLEMENTATION>
155  return m_rep->GetBinContent ( rIndex(index) );
156  }
157 
158  template <class INTERFACE, class IMPLEMENTATION>
160  return m_rep->GetBinError ( rIndex(index) );
161  }
162 
163  template <class INTERFACE, class IMPLEMENTATION>
165  return binEntries(AIDA::IAxis::UNDERFLOW_BIN) +
166  binEntries(AIDA::IAxis::OVERFLOW_BIN);
167  }
168  template <class INTERFACE, class IMPLEMENTATION>
170  m_sumEntries = 0;
171  m_rep->Reset();
172  return true;
173  }
174 
175  template <class INTERFACE, class IMPLEMENTATION>
177  if (sumBinHeights() <= 0) return 0;
178  Stat_t stats[11]; // cover up to 3D...
179  m_rep->GetStats(stats);
180  return stats[0]*stats[0]/stats[1];
181  }
182 
183  template <class INTERFACE, class IMPLEMENTATION>
185  m_rep->Scale ( scaleFactor );
186  return true;
187  }
188 
189  template <class INTERFACE, class IMPLEMENTATION>
190  bool Generic1D<INTERFACE,IMPLEMENTATION>::add(const INTERFACE & h) {
192  dynamic_cast<const Generic1D<INTERFACE,IMPLEMENTATION>*>(&h);
193  if ( p ) {
194  m_rep->Add(p->m_rep);
195  return true;
196  }
197  throw std::runtime_error("Cannot add profile histograms of different implementations.");
198  }
199 
200  template <class INTERFACE, class IMPLEMENTATION>
201  std::ostream& Generic1D<INTERFACE,IMPLEMENTATION>::print( std::ostream& s ) const {
203  m_rep->Print("all");
204  return s;
205  }
206 
208  template <class INTERFACE, class IMPLEMENTATION>
209  std::ostream& Generic1D<INTERFACE,IMPLEMENTATION>::write( std::ostream& s ) const {
210  s << "\n1D Histogram Table: " << std::endl;
211  s << "Bin, Height, Error " << std::endl;
212  for( int i = 0; i < axis().bins(); ++i )
213  s << binMean( i ) << ", "
214  << binHeight( i ) << ", "
215  << binError ( i ) << std::endl;
216  s << std::endl;
217  return s;
218  }
219 
221  template <class INTERFACE, class IMPLEMENTATION>
222  int Generic1D<INTERFACE,IMPLEMENTATION>::write( const char* file_name ) const
223  {
224  TFile *f = TFile::Open(file_name,"RECREATE");
225  Int_t nbytes = m_rep->Write();
226  f->Close();
227  return nbytes;
228  }
229 } // end namespace AIDA
230 
231 #endif // AIDAROOT_GENERIC1D_H
virtual bool add(const INTERFACE &profile)
Modifies this IProfile1D by adding the contents of profile to it.
Definition: Generic1D.h:190
virtual std::string title() const
Get the title of the object.
Definition: Generic1D.h:45
virtual std::ostream & write(std::ostream &s) const
Write (ASCII) the histogram table into the output stream.
Definition: Generic1D.h:209
virtual int entries() const
Get the number or all the entries.
Definition: Generic1D.h:62
std::string m_classType
Definition: Generic1D.h:121
virtual double maxBinHeight() const
Get the maximum height of the in-range bins.
Definition: Generic1D.h:80
Generic1D()
Default constructor.
Definition: Generic1D.h:33
virtual double binError(int index) const
The error of a given bin.
Definition: Generic1D.h:159
virtual double binRms(int index) const
Definition: Generic1D.h:144
Axis & axis()
Access to axis object.
Definition: Generic1D.h:57
virtual std::ostream & print(std::ostream &s) const
Print (ASCII) the histogram into the output stream.
Definition: Generic1D.h:201
AIDA::Annotation m_annotation
Object annotations.
Definition: Generic1D.h:117
virtual ~Generic1D()
Default destructor.
Definition: Generic1D.h:35
virtual double sumExtraBinHeights() const
Get the sum of the underflow and overflow bin height.
Definition: Generic1D.h:76
virtual int coordToIndex(double coord) const
Get the bin number corresponding to a given coordinate along the x axis.
Definition: Generic1D.h:103
Implementation of the AIDA IAnnotation interface class.
Definition: Annotation.h:18
Axis m_axis
Axis member.
Definition: Generic1D.h:115
IMPLEMENTATION * m_rep
Reference to underlying implementation.
Definition: Generic1D.h:119
Generic1D< INTERFACE, IMPLEMENTATION > Base
Definition: Generic1D.h:31
virtual int dimension() const
Get the Histogram's dimension.
Definition: Generic1D.h:105
TObject * representation() const
ROOT object implementation.
Definition: Generic1D.h:41
virtual const std::string & userLevelClassType() const
The AIDA user-level unterface leaf class type.
Definition: Generic1D.h:37
Common base class for all histograms Use is solely functional to minimize dynamic_casts inside Histog...
Definition: HistogramBase.h:22
virtual double minBinHeight() const
Get the minimum height of the in-range bins.
Definition: Generic1D.h:78
virtual bool setTitle(const std::string &title)
Set the title of the object.
Definition: Generic1D.h:127
string s
Definition: gaudirun.py:210
virtual int allEntries() const
Get the number or all the entries, both in range and underflow/overflow bins of the IProfile...
Definition: Generic1D.h:64
virtual double binMean(int index) const
The weighted mean of a bin.
Definition: Generic1D.h:149
virtual double equivalentBinEntries() const
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
Definition: Generic1D.h:176
virtual int rIndex(int index) const
operator methods
Definition: Generic1D.h:91
virtual double binHeight(int index) const
Total height of the corresponding bin (ie the sum of the weights in this bin).
Definition: Generic1D.h:154
virtual int extraEntries() const
Get the number of entries in the underflow and overflow bins.
Definition: Generic1D.h:164
This is a number of static methods for bootstrapping the Gaudi framework.
Definition: Bootstrap.h:14
virtual double sumAllBinHeights() const
Get the sum of all the bins heights (including underflow and overflow bin).
Definition: Generic1D.h:74
#define GAUDI_API
Definition: Kernel.h:108
list i
Definition: ana.py:128
virtual double sumBinHeights() const
Get the sum of in range bin heights in the IProfile.
Definition: Generic1D.h:72
const Axis & axis() const
Get the x axis of the IHistogram1D.
Definition: Generic1D.h:59
An IAxis represents a binned histogram axis.
Definition: Axis.h:31
virtual bool reset()
Reset the Histogram; as if just created.
Definition: Generic1D.h:169
virtual AIDA::IAnnotation & annotation()
Access annotation object.
Definition: Generic1D.h:53
bool setName(const std::string &newName)
Set the name of the object.
Definition: Generic1D.h:137
virtual const AIDA::IAnnotation & annotation() const
Access annotation object (cons)
Definition: Generic1D.h:55
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: Generic1D.h:184
virtual double rms() const
The RMS of the whole IHistogram1D.
Definition: Generic1D.h:101
std::string name() const
object name
Definition: Generic1D.h:49
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
Definition: Generic1D.h:29
virtual double mean() const
The mean of the whole IHistogram1D.
Definition: Generic1D.h:99