Gaudi::Histogram1D Class Reference

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

#include <GaudiCommonSvc/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...
 
void adoptRepresentation (TObject *rep) override
 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...
 
bool reset () override
 need to overwrite reset to reset the sums More...
 
virtual bool setStatistics (int allEntries, double eqBinEntries, double mean, double rms)
 set histogram statistics More...
 
bool fill (double x, double weight) override
 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...
 
const CLIDclID () const override
 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 &rhs)
 Copy Constructor. More...
 
DataObjectoperator= (const DataObject &rhs)
 Assignment Operator. More...
 
 DataObject (DataObject &&rhs)
 Move Constructor. More...
 
DataObjectoperator= (DataObject &&rhs)
 Move Assignment Operator. 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::stringname () 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::ostreamfillStream (std::ostream &s) const
 Fill the output stream (ASCII) More...
 
- Public Member Functions inherited from Gaudi::Generic1D< INTERFACE, IMPLEMENTATION >
 Generic1D ()=default
 Default constructor. More...
 
 ~Generic1D () override=default
 Default destructor. More...
 
virtual const std::stringuserLevelClassType () const
 The AIDA user-level unterface leaf class type. More...
 
void * cast (const std::string &cl) const override
 Manual cast by class name. More...
 
TObject * representation () const override
 ROOT object implementation. More...
 
std::string title () const override
 Get the title of the object. More...
 
bool setTitle (const std::string &title) override
 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...
 
AIDA::IAnnotation & annotation () override
 Access annotation object. More...
 
const AIDA::IAnnotation & annotation () const override
 Access annotation object (cons) More...
 
Axisaxis ()
 Access to axis object. More...
 
const Axisaxis () const override
 Get the x axis of the IHistogram1D. More...
 
int entries () const override
 Get the number or all the entries. More...
 
int allEntries () const override
 Get the number or all the entries, both in range and underflow/overflow bins of the IProfile. More...
 
int extraEntries () const override
 Get the number of entries in the underflow and overflow bins. More...
 
int binEntries (int index) const override
 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
 
double sumBinHeights () const override
 Get the sum of in range bin heights in the IProfile. More...
 
double sumAllBinHeights () const override
 Get the sum of all the bins heights (including underflow and overflow bin). More...
 
double sumExtraBinHeights () const override
 Get the sum of the underflow and overflow bin height. More...
 
double minBinHeight () const override
 Get the minimum height of the in-range bins. More...
 
double maxBinHeight () const override
 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...
 
bool reset () override
 Reset the Histogram; as if just created. More...
 
bool add (const INTERFACE &profile) override
 Modifies this IProfile1D by adding the contents of profile to it. More...
 
virtual int rIndex (int index) const
 operator methods More...
 
double binMean (int index) const override
 The weighted mean of a bin. More...
 
double binHeight (int index) const override
 Total height of the corresponding bin (ie the sum of the weights in this bin). More...
 
double binError (int index) const override
 The error of a given bin. More...
 
double mean () const override
 The mean of the whole IHistogram1D. More...
 
double rms () const override
 The RMS of the whole IHistogram1D. More...
 
int coordToIndex (double coord) const override
 Get the bin number corresponding to a given coordinate along the x axis. More...
 
int dimension () const override
 Get the Histogram's dimension. More...
 
std::ostreamprint (std::ostream &s) const override
 Print (ASCII) the histogram into the output stream. More...
 
std::ostreamwrite (std::ostream &s) const override
 Write (ASCII) the histogram table into the output stream. More...
 
int write (const char *file_name) const override
 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 ()=default
 

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 = 0
 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...
 
std::unique_ptr< 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
 
- Protected Member Functions inherited from Gaudi::Generic1D< INTERFACE, IMPLEMENTATION >
 Generic1D (IMPLEMENTATION *p)
 constructor More...
 

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 58 of file H1D.cpp.

59  : Base( new TH1D() )
60 {
61  init("",false);
62 }
void init(const std::string &title, bool initialize_axis=true)
Definition: H1D.cpp:70
Generic1D< INTERFACE, IMPLEMENTATION > Base
Definition: Generic1D.h:37
Gaudi::Histogram1D::Histogram1D ( TH1D *  rep)

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

Definition at line 64 of file H1D.cpp.

64  {
65  m_rep.reset( rep );
66  init(m_rep->GetTitle());
67  initSums();
68 }
void initSums()
Definition: H1D.cpp:83
void init(const std::string &title, bool initialize_axis=true)
Definition: H1D.cpp:70
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic1D.h:129
T reset(T...args)

Member Function Documentation

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

Adopt ROOT histogram representation.

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

Definition at line 99 of file H1D.cpp.

99  {
101  if ( m_rep ) {
102  init(m_rep->GetTitle());
103  initSums();
104  }
105 }
void initSums()
Definition: H1D.cpp:83
void init(const std::string &title, bool initialize_axis=true)
Definition: H1D.cpp:70
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic1D.h:129
static const CLID& Gaudi::Histogram1D::classID ( )
inlinestatic

Definition at line 46 of file H1D.h.

46 { return CLID_H1D; }
const CLID& Gaudi::Histogram1D::clID ( ) const
inlineoverridevirtual

Retrieve reference to class defininition identifier.

Reimplemented from DataObject.

Definition at line 45 of file H1D.h.

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

Create new histogram from any AIDA based histogram.

Definition at line 163 of file H1D.cpp.

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

Fill the Profile1D with a value and the corresponding weight.

Definition at line 158 of file H1D.cpp.

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

Definition at line 70 of file H1D.cpp.

70  {
71  m_classType = "IHistogram1D";
72  if ( initialize_axis ) {
73  m_axis.initialize(m_rep->GetXaxis(),false);
74  }
75  const TArrayD* a = m_rep->GetSumw2();
76  if ( !a || (a && a->GetSize()==0) ) m_rep->Sumw2();
77  setTitle(title);
78  m_rep->SetDirectory(nullptr);
79  m_sumEntries = 0;
80  m_sumwx = 0;
81 }
std::string m_classType
Definition: Generic1D.h:131
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic1D.h:129
bool setTitle(const std::string &title) override
Set the title of the object.
Definition: Generic1D.h:137
Axis m_axis
Axis member.
Definition: Generic1D.h:125
void initialize(TAxis *itaxi, bool)
Definition: Axis.h:66
double m_sumwx
cache sumwx when setting contents since I don&#39;t have bin mean
Definition: H1D.h:23
void Gaudi::Histogram1D::initSums ( )
private

Definition at line 83 of file H1D.cpp.

83  {
84  m_sumwx = 0;
85  m_sumEntries = 0;
86  for(int i=1, n=m_rep->GetNbinsX(); i<=n; ++i) {
87  m_sumwx += m_rep->GetBinContent(i)*m_rep->GetBinCenter(i);
88  m_sumEntries += m_rep->GetBinContent(i);
89  }
90 }
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic1D.h:129
double m_sumwx
cache sumwx when setting contents since I don&#39;t have bin mean
Definition: H1D.h:23
bool Gaudi::Histogram1D::reset ( )
override

need to overwrite reset to reset the sums

Definition at line 92 of file H1D.cpp.

92  {
93  m_sumwx = 0;
94  m_sumEntries = 0;
95  return Base::reset();
96 }
double m_sumwx
cache sumwx when setting contents since I don&#39;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 215 of file H1D.cpp.

215  {
216  //DataObject::serialize(s);
218  int size;
219  s >> size;
220  for (int j = 0; j < size; j++) {
221  std::string key, value;
222  s >> key >> value;
223  annotation().addItem (key, value);
224  if ("Title" == key) {
225  title = value;
226  }
227  }
228  double lowerEdge, upperEdge, binHeight, binError;
229  int isFixedBinning, bins;
230  s >> isFixedBinning >> bins;
231 
232  if ( isFixedBinning ) {
233  s >> lowerEdge >> upperEdge;
234  m_rep.reset( new TH1D(title.c_str(),title.c_str(),bins,lowerEdge,upperEdge) );
235  } else {
236  Edges edges;
237  edges.resize(bins);
238  for ( int i = 0; i <= bins; ++i )
239  s >> *(double*)&edges[i];
240  m_rep.reset( new TH1D(title.c_str(),title.c_str(),edges.size()-1,&edges.front()) );
241  }
242  m_axis.initialize(m_rep->GetXaxis(),true);
243  m_rep->Sumw2();
244  m_sumEntries = 0;
245  m_sumwx = 0;
246 
247  for ( int i = 0; i <= bins + 1; ++i ) {
248  s >> binHeight >> binError;
249  m_rep->SetBinContent( i, binHeight );
250  m_rep->SetBinError( i, binError );
251  }
252  Stat_t allEntries;
253  s >> allEntries;
254  m_rep->SetEntries( allEntries );
255  Stat_t stats[4]; // stats array
256  s >> stats[0] >> stats[1] >> stats[2] >> stats[3];
257  m_rep->PutStats( stats );
258  return s;
259 }
std::string title() const override
Get the title of the object.
Definition: Generic1D.h:55
double binHeight(int index) const override
Total height of the corresponding bin (ie the sum of the weights in this bin).
Definition: Generic1D.h:164
std::vector< double > Edges
Definition: GaudiPI.h:17
T resize(T...args)
double binError(int index) const override
The error of a given bin.
Definition: Generic1D.h:169
STL class.
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic1D.h:129
int allEntries() const override
Get the number or all the entries, both in range and underflow/overflow bins of the IProfile...
Definition: Generic1D.h:74
Axis m_axis
Axis member.
Definition: Generic1D.h:125
T reset(T...args)
void initialize(TAxis *itaxi, bool)
Definition: Axis.h:66
T c_str(T...args)
string s
Definition: gaudirun.py:245
AIDA::IAnnotation & annotation() override
Access annotation object.
Definition: Generic1D.h:63
double m_sumwx
cache sumwx when setting contents since I don&#39;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 261 of file H1D.cpp.

261  {
262  //DataObject::serialize(s);
263  s << static_cast<int>( annotation().size() );
264  for (int i = 0; i < annotation().size(); i++) {
265  s << annotation().key(i);
266  s << annotation().value(i);
267  }
268  const AIDA::IAxis & axis( this->axis() );
269  const int isFixedBinning = axis.isFixedBinning();
270  const int bins = axis.bins();
271  s << isFixedBinning << bins;
272  if ( isFixedBinning ) {
273  s << axis.lowerEdge();
274  }
275  else {
276  for ( int i = 0; i < bins; ++i )
277  s << axis.binLowerEdge(i);
278  }
279  s << axis.upperEdge();
280  for ( int i = 0; i <= bins + 1; ++i )
281  s << m_rep->GetBinContent(i) << m_rep->GetBinError( i );
282 
283  s << m_rep->GetEntries();
284  Stat_t stats[4]; // stats array
285  m_rep->GetStats( stats );
286  s << stats[0] << stats[1] << stats[2] << stats[3];
287  return s;
288 }
bool isFixedBinning() const override
Check if the IAxis has fixed binning, i.e.
Definition: Axis.h:73
Axis & axis()
Access to axis object.
Definition: Generic1D.h:67
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic1D.h:129
int bins() const override
The number of bins (excluding underflow and overflow) on the IAxis.
Definition: Axis.h:97
double binLowerEdge(int index) const override
Get the lower edge of the specified bin.
Definition: Axis.h:105
double lowerEdge() const override
Get the lower edge of the IAxis.
Definition: Axis.h:83
string s
Definition: gaudirun.py:245
AIDA::IAnnotation & annotation() override
Access annotation object.
Definition: Generic1D.h:63
double upperEdge() const override
Get the upper edge of the IAxis.
Definition: Axis.h:90
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 107 of file H1D.cpp.

107  {
108  m_rep->SetBinContent(rIndex(i),height);
109  m_rep->SetBinError(rIndex(i),error);
110  // accumulate sumwx for in range bins
111  if (i != AIDA::IAxis::UNDERFLOW_BIN && i != AIDA::IAxis::OVERFLOW_BIN )
112  m_sumwx += centre*height;
114  return true;
115 }
int entries() const override
Get the number or all the entries.
Definition: Generic1D.h:72
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic1D.h:129
virtual int rIndex(int index) const
operator methods
Definition: Generic1D.h:101
double m_sumwx
cache sumwx when setting contents since I don&#39;t have bin mean
Definition: H1D.h:23
bool Gaudi::Histogram1D::setRms ( double  rms)

Update histogram RMS.

Definition at line 123 of file H1D.cpp.

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

set histogram statistics

Definition at line 140 of file H1D.cpp.

140  {
141  m_rep->SetEntries(allEntries);
142  // fill statistcal vector for Root
143  std::vector<double> stat(11);
144  // sum weights
145  stat[0] = sumBinHeights();
146  // sum weights **2
147  stat[1] = 0;
148  if (eqBinEntries != 0)
149  stat[1] = ( sumBinHeights() * sumBinHeights() ) / eqBinEntries;
150  // sum weights * x
151  stat[2] = mean*sumBinHeights();
152  // sum weight * x **2
153  stat[3] = ( mean*mean + rms*rms )* sumBinHeights();
154  m_rep->PutStats(&stat.front());
155  return true;
156 }
double sumBinHeights() const override
Get the sum of in range bin heights in the IProfile.
Definition: Generic1D.h:82
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic1D.h:129
int allEntries() const override
Get the number or all the entries, both in range and underflow/overflow bins of the IProfile...
Definition: Generic1D.h:74
double rms() const override
The RMS of the whole IHistogram1D.
Definition: Generic1D.h:111
double mean() const override
The mean of the whole IHistogram1D.
Definition: Generic1D.h:109

Member Data Documentation

double Gaudi::Histogram1D::m_sumwx = 0
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: