Gaudi Framework, version v25r0

Home   Generated: Mon Feb 17 2014
 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 
4 #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
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>
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>
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>
203  m_rep->Print("all");
204  return s;
205  }
206 
208  template <class INTERFACE, class IMPLEMENTATION>
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

Generated at Mon Feb 17 2014 14:37:39 for Gaudi Framework, version v25r0 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004