All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Gaudi::Histogram1D Class Reference

AIDA implementation for 1 D histograms using ROOT THD1. More...

#include <src/HistogramSvc/H1D.h>

Inheritance diagram for Gaudi::Histogram1D:
Collaboration diagram for Gaudi::Histogram1D:

Public Member Functions

 Histogram1D ()
 Standard constructor. More...
 
 Histogram1D (TH1D *rep)
 Standard constructor with initialization. The histogram representation will be adopted. More...
 
virtual ~Histogram1D ()
 Destructor. More...
 
virtual void adoptRepresentation (TObject *rep)
 Adopt ROOT histogram representation. More...
 
virtual bool setBinContents (int i, int entries, double height, double error, double centre)
 set bin content (entries and centre are not used ) More...
 
virtual bool reset ()
 need to overwrite reset to reset the sums More...
 
virtual bool setStatistics (int allEntries, double eqBinEntries, double mean, double rms)
 set histogram statistics More...
 
virtual bool fill (double x, double weight)
 Fill the Profile1D with a value and the corresponding weight. More...
 
bool setRms (double rms)
 Update histogram RMS. More...
 
void copyFromAida (const AIDA::IHistogram1D &h)
 Create new histogram from any AIDA based histogram. More...
 
virtual const CLIDclID () const
 Retrieve reference to class defininition identifier. More...
 
StreamBufferserialize (StreamBuffer &s)
 Serialization mechanism, Serialize the object for reading. More...
 
StreamBufferserialize (StreamBuffer &s) const
 Serialization mechanism, Serialize the object for writing. More...
 
- Public Member Functions inherited from DataObject
 DataObject ()
 Standard Constructor. More...
 
 DataObject (const DataObject &)
 Copy Constructor. More...
 
virtual ~DataObject ()
 Standard Destructor. More...
 
virtual unsigned long addRef ()
 Add reference to object. More...
 
virtual unsigned long release ()
 release reference to object More...
 
const std::string & name () const
 Retreive DataObject name. It is the name when registered in the store. More...
 
virtual StatusCode update ()
 Provide empty placeholder for internal object reconfiguration callback. More...
 
void setRegistry (IRegistry *pRegistry)
 Set pointer to Registry. More...
 
IRegistryregistry () const
 Get pointer to Registry. More...
 
LinkManagerlinkMgr () const
 Retrieve Link manager. More...
 
unsigned char version () const
 Retrieve version number of this object representation. More...
 
void setVersion (unsigned char vsn)
 Set version number of this object representation. More...
 
unsigned long refCount () const
 Return the refcount. More...
 
virtual std::ostream & fillStream (std::ostream &s) const
 Fill the output stream (ASCII) More...
 
- Public Member Functions inherited from Gaudi::Generic1D< INTERFACE, IMPLEMENTATION >
 Generic1D ()
 Default constructor. More...
 
virtual ~Generic1D ()
 Default destructor. More...
 
virtual const std::string & userLevelClassType () const
 The AIDA user-level unterface leaf class type. More...
 
virtual void * cast (const std::string &cl) const
 Manual cast by class name. More...
 
TObject * representation () const
 ROOT object implementation. More...
 
virtual std::string title () const
 Get the title of the object. More...
 
virtual bool setTitle (const std::string &title)
 Set the title of the object. More...
 
std::string name () const
 object name More...
 
bool setName (const std::string &newName)
 Set the name of the object. More...
 
virtual AIDA::IAnnotation & annotation ()
 Access annotation object. More...
 
virtual const AIDA::IAnnotation & annotation () const
 Access annotation object (cons) More...
 
Axisaxis ()
 Access to axis object. More...
 
const Axisaxis () const
 Get the x axis of the IHistogram1D. More...
 
virtual int entries () const
 Get the number or all the entries. More...
 
virtual int allEntries () const
 Get the number or all the entries, both in range and underflow/overflow bins of the IProfile. More...
 
virtual int extraEntries () const
 Get the number of entries in the underflow and overflow bins. More...
 
virtual int binEntries (int index) const
 Number of entries in the corresponding bin (ie the number of times fill was called for this bin). More...
 
virtual double binRms (int index) const
 
virtual double sumBinHeights () const
 Get the sum of in range bin heights in the IProfile. More...
 
virtual double sumAllBinHeights () const
 Get the sum of all the bins heights (including underflow and overflow bin). More...
 
virtual double sumExtraBinHeights () const
 Get the sum of the underflow and overflow bin height. More...
 
virtual double minBinHeight () const
 Get the minimum height of the in-range bins. More...
 
virtual double maxBinHeight () const
 Get the maximum height of the in-range bins. More...
 
virtual double equivalentBinEntries () const
 Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ] More...
 
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 given scale factor. More...
 
virtual bool add (const INTERFACE &profile)
 Modifies this IProfile1D by adding the contents of profile to it. More...
 
virtual int rIndex (int index) const
 operator methods More...
 
virtual double binMean (int index) const
 The weighted mean of a bin. More...
 
virtual double binHeight (int index) const
 Total height of the corresponding bin (ie the sum of the weights in this bin). More...
 
virtual double binError (int index) const
 The error of a given bin. More...
 
virtual double mean () const
 The mean of the whole IHistogram1D. More...
 
virtual double rms () const
 The RMS of the whole IHistogram1D. More...
 
virtual int coordToIndex (double coord) const
 Get the bin number corresponding to a given coordinate along the x axis. More...
 
virtual int dimension () const
 Get the Histogram's dimension. More...
 
virtual std::ostream & print (std::ostream &s) const
 Print (ASCII) the histogram into the output stream. More...
 
virtual std::ostream & write (std::ostream &s) const
 Write (ASCII) the histogram table into the output stream. More...
 
virtual int write (const char *file_name) const
 Write (ASCII) the histogram table into a file. More...
 
template<>
void * cast (const std::string &className) const
 
template<>
int binEntries (int index) const
 
template<>
void adoptRepresentation (TObject *rep)
 Adopt ROOT histogram representation. More...
 
template<>
int binEntries (int index) const
 
template<>
void * cast (const std::string &className) const
 
template<>
void adoptRepresentation (TObject *rep)
 Adopt ROOT histogram representation. More...
 
- Public Member Functions inherited from Gaudi::HistogramBase
virtual ~HistogramBase ()
 

Static Public Member Functions

static const CLIDclassID ()
 
- Static Public Member Functions inherited from DataObject
static const CLIDclassID ()
 Retrieve reference to class definition structure (static access) More...
 

Protected Attributes

double m_sumwx
 cache sumwx when setting contents since I don't have bin mean More...
 
- Protected Attributes inherited from Gaudi::Generic1D< INTERFACE, IMPLEMENTATION >
Axis m_axis
 Axis member. More...
 
AIDA::Annotation m_annotation
 Object annotations. More...
 
IMPLEMENTATION * m_rep
 Reference to underlying implementation. More...
 
std::string m_classType
 
int m_sumEntries
 

Private Member Functions

void init (const std::string &title, bool initialize_axis=true)
 
void initSums ()
 

Additional Inherited Members

- Public Types inherited from Gaudi::Generic1D< INTERFACE, IMPLEMENTATION >
typedef Generic1D< INTERFACE,
IMPLEMENTATION > 
Base
 

Detailed Description

AIDA implementation for 1 D histograms using ROOT THD1.

Author
M.Frank

Definition at line 17 of file H1D.h.

Constructor & Destructor Documentation

Gaudi::Histogram1D::Histogram1D ( )

Standard constructor.

Definition at line 60 of file H1D.cpp.

60  {
61  m_rep = new TH1D();
62  init("",false);
63 }
void init(const std::string &title, bool initialize_axis=true)
Definition: H1D.cpp:71
IMPLEMENTATION * m_rep
Reference to underlying implementation.
Definition: Generic1D.h:119
Gaudi::Histogram1D::Histogram1D ( TH1D *  rep)

Standard constructor with initialization. The histogram representation will be adopted.

Definition at line 65 of file H1D.cpp.

65  {
66  m_rep = rep;
67  init(m_rep->GetTitle());
68  initSums();
69 }
void initSums()
Definition: H1D.cpp:84
void init(const std::string &title, bool initialize_axis=true)
Definition: H1D.cpp:71
IMPLEMENTATION * m_rep
Reference to underlying implementation.
Definition: Generic1D.h:119
virtual Gaudi::Histogram1D::~Histogram1D ( )
inlinevirtual

Destructor.

Definition at line 30 of file H1D.h.

30 {}

Member Function Documentation

void Gaudi::Histogram1D::adoptRepresentation ( TObject *  rep)
virtual

Adopt ROOT histogram representation.

Reimplemented from Gaudi::Generic1D< INTERFACE, IMPLEMENTATION >.

Definition at line 100 of file H1D.cpp.

100  {
102  if ( m_rep ) {
103  init(m_rep->GetTitle());
104  initSums();
105  }
106 }
void initSums()
Definition: H1D.cpp:84
virtual void adoptRepresentation(TObject *rep)
Adopt ROOT histogram representation.
void init(const std::string &title, bool initialize_axis=true)
Definition: H1D.cpp:71
IMPLEMENTATION * m_rep
Reference to underlying implementation.
Definition: Generic1D.h:119
static const CLID& Gaudi::Histogram1D::classID ( )
inlinestatic

Definition at line 47 of file H1D.h.

47 { return CLID_H1D; }
virtual const CLID& Gaudi::Histogram1D::clID ( ) const
inlinevirtual

Retrieve reference to class defininition identifier.

Reimplemented from DataObject.

Definition at line 46 of file H1D.h.

46 { return classID(); }
static const CLID & classID()
Definition: H1D.h:47
void Gaudi::Histogram1D::copyFromAida ( const AIDA::IHistogram1D &  h)

Create new histogram from any AIDA based histogram.

Definition at line 164 of file H1D.cpp.

164  {
165  // implement here the copy
166  std::string tit = h.title()+"Copy";
167  delete m_rep;
168  if (h.axis().isFixedBinning() ) {
169  m_rep = new TH1D(tit.c_str(),tit.c_str(),h.axis().bins(),h.axis().lowerEdge(),h.axis().upperEdge());
170  }
171  else {
172  Edges e;
173  for (int i =0; i < h.axis().bins(); ++i) {
174  e.push_back(h.axis().binLowerEdge(i));
175  }
176  // add also upperedges at the end
177  e.push_back(h.axis().upperEdge() );
178  m_rep = new TH1D(tit.c_str(),tit.c_str(),e.size()-1,&e.front());
179  }
180  m_axis.initialize(m_rep->GetXaxis(),false);
181  m_rep->Sumw2();
182  m_sumEntries = 0;
183  m_sumwx = 0;
184  // sumw
185  double sumw = h.sumBinHeights();
186  // sumw2
187  double sumw2 = 0;
188  if (h.equivalentBinEntries() != 0)
189  sumw2 = ( sumw * sumw ) /h.equivalentBinEntries();
190 
191  double sumwx = h.mean()*h.sumBinHeights();
192  double sumwx2 = (h.mean()*h.mean() + h.rms()*h.rms() )*h.sumBinHeights();
193 
194  // copy the contents in
195  for (int i=-2; i < axis().bins(); ++i) {
196  // root binning starts from one !
197  m_rep->SetBinContent(rIndex(i),h.binHeight(i) );
198  m_rep->SetBinError(rIndex(i),h.binError(i) );
199  }
200  // need to do set entries after setting contents otherwise root will recalulate them
201  // taking into account how many time SetBinContents() has been called
202  m_rep->SetEntries(h.allEntries());
203  // stat vector
204  std::vector<double> stat(11);
205  stat[0] = sumw;
206  stat[1] = sumw2;
207  stat[2] = sumwx;
208  stat[3] = sumwx2;
209  m_rep->PutStats(&stat.front());
210 }
std::vector< double > Edges
Definition: GaudiPI.h:19
Axis & axis()
Access to axis object.
Definition: Generic1D.h:57
Axis m_axis
Axis member.
Definition: Generic1D.h:115
IMPLEMENTATION * m_rep
Reference to underlying implementation.
Definition: Generic1D.h:119
void initialize(TAxis *itaxi, bool)
Definition: Axis.h:71
virtual int bins() const
The number of bins (excluding underflow and overflow) on the IAxis.
Definition: Axis.h:105
virtual int rIndex(int index) const
operator methods
Definition: Generic1D.h:91
list i
Definition: ana.py:128
double m_sumwx
cache sumwx when setting contents since I don't have bin mean
Definition: H1D.h:23
bool Gaudi::Histogram1D::fill ( double  x,
double  weight 
)
virtual

Fill the Profile1D with a value and the corresponding weight.

Definition at line 159 of file H1D.cpp.

159  {
160  (weight == 1.) ? m_rep->Fill(x) : m_rep->Fill(x,weight);
161  return true;
162 }
IMPLEMENTATION * m_rep
Reference to underlying implementation.
Definition: Generic1D.h:119
void Gaudi::Histogram1D::init ( const std::string &  title,
bool  initialize_axis = true 
)
private

Definition at line 71 of file H1D.cpp.

71  {
72  m_classType = "IHistogram1D";
73  if ( initialize_axis ) {
74  m_axis.initialize(m_rep->GetXaxis(),false);
75  }
76  const TArrayD* a = m_rep->GetSumw2();
77  if ( 0 == a || (a && a->GetSize()==0) ) m_rep->Sumw2();
78  setTitle(title);
79  m_rep->SetDirectory(0);
80  m_sumEntries = 0;
81  m_sumwx = 0;
82 }
virtual std::string title() const
Get the title of the object.
Definition: Generic1D.h:45
std::string m_classType
Definition: Generic1D.h:121
Axis m_axis
Axis member.
Definition: Generic1D.h:115
IMPLEMENTATION * m_rep
Reference to underlying implementation.
Definition: Generic1D.h:119
void initialize(TAxis *itaxi, bool)
Definition: Axis.h:71
virtual bool setTitle(const std::string &title)
Set the title of the object.
Definition: Generic1D.h:127
double m_sumwx
cache sumwx when setting contents since I don't have bin mean
Definition: H1D.h:23
void Gaudi::Histogram1D::initSums ( )
private

Definition at line 84 of file H1D.cpp.

84  {
85  m_sumwx = 0;
86  m_sumEntries = 0;
87  for(int i=1, n=m_rep->GetNbinsX(); i<=n; ++i) {
88  m_sumwx += m_rep->GetBinContent(i)*m_rep->GetBinCenter(i);
89  m_sumEntries += (int)m_rep->GetBinContent(i);
90  }
91 }
IMPLEMENTATION * m_rep
Reference to underlying implementation.
Definition: Generic1D.h:119
list i
Definition: ana.py:128
double m_sumwx
cache sumwx when setting contents since I don't have bin mean
Definition: H1D.h:23
bool Gaudi::Histogram1D::reset ( )
virtual

need to overwrite reset to reset the sums

Reimplemented from Gaudi::Generic1D< INTERFACE, IMPLEMENTATION >.

Definition at line 93 of file H1D.cpp.

93  {
94  m_sumwx = 0;
95  m_sumEntries = 0;
96  return Base::reset();
97 }
double m_sumwx
cache sumwx when setting contents since I don't have bin mean
Definition: H1D.h:23
StreamBuffer & Gaudi::Histogram1D::serialize ( StreamBuffer s)

Serialization mechanism, Serialize the object for reading.

Parameters
sthe StreamBuffer containing the data to be read
Returns
the resulting StreamBuffer, after reading

Definition at line 217 of file H1D.cpp.

217  {
218  //DataObject::serialize(s);
219  std::string title;
220  int size;
221  s >> size;
222  for (int j = 0; j < size; j++) {
223  std::string key, value;
224  s >> key >> value;
225  annotation().addItem (key, value);
226  if ("Title" == key) {
227  title = value;
228  }
229  }
230  double lowerEdge, upperEdge, binHeight, binError;
231  int isFixedBinning, bins;
232  s >> isFixedBinning >> bins;
233 
234  if ( m_rep ) delete m_rep;
235  if ( isFixedBinning ) {
236  s >> lowerEdge >> upperEdge;
237  m_rep = new TH1D(title.c_str(),title.c_str(),bins,lowerEdge,upperEdge);
238  } else {
239  Edges edges;
240  edges.resize(bins);
241  for ( int i = 0; i <= bins; ++i )
242  s >> *(double*)&edges[i];
243  m_rep = new TH1D(title.c_str(),title.c_str(),edges.size()-1,&edges.front());
244  }
245  m_axis.initialize(m_rep->GetXaxis(),true);
246  m_rep->Sumw2();
247  m_sumEntries = 0;
248  m_sumwx = 0;
249 
250  for ( int i = 0; i <= bins + 1; ++i ) {
251  s >> binHeight >> binError;
252  m_rep->SetBinContent( i, binHeight );
253  m_rep->SetBinError( i, binError );
254  }
255  Stat_t allEntries;
256  s >> allEntries;
257  m_rep->SetEntries( allEntries );
258  Stat_t stats[4]; // stats array
259  s >> stats[0] >> stats[1] >> stats[2] >> stats[3];
260  m_rep->PutStats( stats );
261  return s;
262 }
virtual std::string title() const
Get the title of the object.
Definition: Generic1D.h:45
std::vector< double > Edges
Definition: GaudiPI.h:19
virtual double binError(int index) const
The error of a given bin.
Definition: Generic1D.h:159
Axis m_axis
Axis member.
Definition: Generic1D.h:115
IMPLEMENTATION * m_rep
Reference to underlying implementation.
Definition: Generic1D.h:119
void initialize(TAxis *itaxi, bool)
Definition: Axis.h:71
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 binHeight(int index) const
Total height of the corresponding bin (ie the sum of the weights in this bin).
Definition: Generic1D.h:154
list i
Definition: ana.py:128
virtual AIDA::IAnnotation & annotation()
Access annotation object.
Definition: Generic1D.h:53
double m_sumwx
cache sumwx when setting contents since I don't have bin mean
Definition: H1D.h:23
StreamBuffer & Gaudi::Histogram1D::serialize ( StreamBuffer s) const

Serialization mechanism, Serialize the object for writing.

Parameters
sthe StreamBuffer where to write the data
Returns
the resulting StreamBuffer, after wrinting

Definition at line 264 of file H1D.cpp.

264  {
265  //DataObject::serialize(s);
266  s << static_cast<int>( annotation().size() );
267  for (int i = 0; i < annotation().size(); i++) {
268  s << annotation().key(i);
269  s << annotation().value(i);
270  }
271  const AIDA::IAxis & axis( this->axis() );
272  const int isFixedBinning = axis.isFixedBinning();
273  const int bins = axis.bins();
274  s << isFixedBinning << bins;
275  if ( isFixedBinning ) {
276  s << axis.lowerEdge();
277  }
278  else {
279  for ( int i = 0; i < bins; ++i )
280  s << axis.binLowerEdge(i);
281  }
282  s << axis.upperEdge();
283  for ( int i = 0; i <= bins + 1; ++i )
284  s << m_rep->GetBinContent(i) << m_rep->GetBinError( i );
285 
286  s << m_rep->GetEntries();
287  Stat_t stats[4]; // stats array
288  m_rep->GetStats( stats );
289  s << stats[0] << stats[1] << stats[2] << stats[3];
290  return s;
291 }
virtual double binLowerEdge(int index) const
Get the lower edge of the specified bin.
Definition: Axis.h:113
virtual double lowerEdge() const
Get the lower edge of the IAxis.
Definition: Axis.h:91
virtual bool isFixedBinning() const
Check if the IAxis has fixed binning, i.e.
Definition: Axis.h:81
Axis & axis()
Access to axis object.
Definition: Generic1D.h:57
virtual double upperEdge() const
Get the upper edge of the IAxis.
Definition: Axis.h:98
IMPLEMENTATION * m_rep
Reference to underlying implementation.
Definition: Generic1D.h:119
string s
Definition: gaudirun.py:210
virtual int bins() const
The number of bins (excluding underflow and overflow) on the IAxis.
Definition: Axis.h:105
list i
Definition: ana.py:128
virtual AIDA::IAnnotation & annotation()
Access annotation object.
Definition: Generic1D.h:53
bool Gaudi::Histogram1D::setBinContents ( int  i,
int  entries,
double  height,
double  error,
double  centre 
)
virtual

set bin content (entries and centre are not used )

Definition at line 108 of file H1D.cpp.

108  {
109  m_rep->SetBinContent(rIndex(i),height);
110  m_rep->SetBinError(rIndex(i),error);
111  // accumulate sumwx for in range bins
112  if (i != AIDA::IAxis::UNDERFLOW_BIN && i != AIDA::IAxis::OVERFLOW_BIN )
113  m_sumwx += centre*height;
115  return true;
116 }
virtual int entries() const
Get the number or all the entries.
Definition: Generic1D.h:62
IMPLEMENTATION * m_rep
Reference to underlying implementation.
Definition: Generic1D.h:119
virtual int rIndex(int index) const
operator methods
Definition: Generic1D.h:91
list i
Definition: ana.py:128
double m_sumwx
cache sumwx when setting contents since I don't have bin mean
Definition: H1D.h:23
bool Gaudi::Histogram1D::setRms ( double  rms)

Update histogram RMS.

Definition at line 124 of file H1D.cpp.

124  {
125  m_rep->SetEntries(m_sumEntries);
126  std::vector<double> stat(11);
127  // sum weights
128  stat[0] = sumBinHeights();
129  stat[1] = 0;
130  if (equivalentBinEntries() != 0)
131  stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries();
132  stat[2] = m_sumwx;
133  double mean = 0;
134  if ( sumBinHeights() != 0 ) mean = m_sumwx/ sumBinHeights();
135  stat[3] = ( mean*mean + rms*rms )* sumBinHeights();
136  m_rep->PutStats(&stat.front());
137  return true;
138 }
IMPLEMENTATION * m_rep
Reference to underlying implementation.
Definition: Generic1D.h:119
virtual double equivalentBinEntries() const
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
Definition: Generic1D.h:176
virtual double sumBinHeights() const
Get the sum of in range bin heights in the IProfile.
Definition: Generic1D.h:72
double m_sumwx
cache sumwx when setting contents since I don't have bin mean
Definition: H1D.h:23
virtual double rms() const
The RMS of the whole IHistogram1D.
Definition: Generic1D.h:101
virtual double mean() const
The mean of the whole IHistogram1D.
Definition: Generic1D.h:99
bool Gaudi::Histogram1D::setStatistics ( int  allEntries,
double  eqBinEntries,
double  mean,
double  rms 
)
virtual

set histogram statistics

Definition at line 141 of file H1D.cpp.

141  {
142  m_rep->SetEntries(allEntries);
143  // fill statistcal vector for Root
144  std::vector<double> stat(11);
145  // sum weights
146  stat[0] = sumBinHeights();
147  // sum weights **2
148  stat[1] = 0;
149  if (eqBinEntries != 0)
150  stat[1] = ( sumBinHeights() * sumBinHeights() ) / eqBinEntries;
151  // sum weights * x
152  stat[2] = mean*sumBinHeights();
153  // sum weight * x **2
154  stat[3] = ( mean*mean + rms*rms )* sumBinHeights();
155  m_rep->PutStats(&stat.front());
156  return true;
157 }
IMPLEMENTATION * m_rep
Reference to underlying implementation.
Definition: Generic1D.h:119
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 sumBinHeights() const
Get the sum of in range bin heights in the IProfile.
Definition: Generic1D.h:72
virtual double rms() const
The RMS of the whole IHistogram1D.
Definition: Generic1D.h:101
virtual double mean() const
The mean of the whole IHistogram1D.
Definition: Generic1D.h:99

Member Data Documentation

double Gaudi::Histogram1D::m_sumwx
protected

cache sumwx when setting contents since I don't have bin mean

Definition at line 23 of file H1D.h.


The documentation for this class was generated from the following files: