| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions | List of all members
Gaudi::Histogram1D Class Reference

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

`#include <H1D.h>`

Inheritance diagram for Gaudi::Histogram1D:
[legend]
Collaboration diagram for Gaudi::Histogram1D:
[legend]

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

## Static Public Member Functions
static const CLID & | classID ()
Static Public Member Functions inherited from DataObject
static const CLID & | classID ()
| Retrieve reference to class definition structure (static access)

## Protected Attributes
double | m_sumwx
| cache sumwx when setting contents since I don't have bin mean
Protected Attributes inherited from Gaudi::Generic1D< INTERFACE, IMPLEMENTATION >
Axis | m_axis
| Axis member.
AIDA::Annotation | m_annotation
| Object annotations.
IMPLEMENTATION * | m_rep
| Reference to underlying implementation.
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
Friends inherited from DataObject

## 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.

{
m_rep = new TH1D();
init("",false);
}

Gaudi::Histogram1D::Histogram1D | ( | TH1D * | rep | ) |

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

Definition at line 65 of file H1D.cpp.

{
m_rep = rep;
init(m_rep->GetTitle());
initSums();
}

virtual Gaudi::Histogram1D::~Histogram1D | ( |  | ) |
| inline virtual

Destructor.

Definition at line 30 of file H1D.h.

{}

## 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.

{
Gaudi::Generic1D<AIDA::IHistogram1D,TH1D>::adoptRepresentation(rep);
if ( m_rep ) {
init(m_rep->GetTitle());
initSums();
}
}

static const CLID& Gaudi::Histogram1D::classID | ( |  | ) |
| inline static

Definition at line 47 of file H1D.h.

{ return CLID_H1D; }

virtual const CLID& Gaudi::Histogram1D::clID | ( |  | ) | const
| inline virtual

Retrieve reference to class defininition identifier.

Reimplemented from DataObject.

Definition at line 46 of file H1D.h.

{ return classID(); }

void Gaudi::Histogram1D::copyFromAida | ( | const AIDA::IHistogram1D & | h | ) |

Create new histogram from any AIDA based histogram.

Definition at line 164 of file H1D.cpp.

{
// implement here the copy
std::string tit = h.title()+"Copy";
delete m_rep;
if (h.axis().isFixedBinning() ) {
m_rep = new TH1D(tit.c_str(),tit.c_str(),h.axis().bins(),h.axis().lowerEdge(),h.axis().upperEdge());
}
else {
Edges e;
for (int i =0; i < h.axis().bins(); ++i) {
e.push_back(h.axis().binLowerEdge(i));
}
// add also upperedges at the end
e.push_back(h.axis().upperEdge() );
m_rep = new TH1D(tit.c_str(),tit.c_str(),e.size()-1,&e.front());
}
m_axis.initialize(m_rep->GetXaxis(),false);
m_rep->Sumw2();
m_sumEntries = 0;
m_sumwx = 0;
// sumw
double sumw = h.sumBinHeights();
// sumw2
double sumw2 = 0;
if (h.equivalentBinEntries() != 0)
sumw2 = ( sumw * sumw ) /h.equivalentBinEntries();
double sumwx = h.mean()*h.sumBinHeights();
double sumwx2 = (h.mean()*h.mean() + h.rms()*h.rms() )*h.sumBinHeights();
// copy the contents in
for (int i=-2; i < axis().bins(); ++i) {
// root binning starts from one !
m_rep->SetBinContent(rIndex(i),h.binHeight(i) );
m_rep->SetBinError(rIndex(i),h.binError(i) );
}
// need to do set entries after setting contents otherwise root will recalulate them
// taking into account how many time SetBinContents() has been called
m_rep->SetEntries(h.allEntries());
// stat vector
std::vector<double> stat(11);
stat[0] = sumw;
stat[1] = sumw2;
stat[2] = sumwx;
stat[3] = sumwx2;
m_rep->PutStats(&stat.front());
}

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.

{
(weight == 1.) ? m_rep->Fill(x) : m_rep->Fill(x,weight);
return true;
}

void Gaudi::Histogram1D::init | ( | const std::string & | title,
|  | bool | initialize_axis = `true`
| ) |  |
| private

Definition at line 71 of file H1D.cpp.

{
m_classType = "IHistogram1D";
if ( initialize_axis ) {
m_axis.initialize(m_rep->GetXaxis(),false);
}
const TArrayD* a = m_rep->GetSumw2();
if ( 0 == a || (a && a->GetSize()==0) ) m_rep->Sumw2();
setTitle(title);
m_rep->SetDirectory(0);
m_sumEntries = 0;
m_sumwx = 0;
}

void Gaudi::Histogram1D::initSums | ( |  | ) |
| private

Definition at line 84 of file H1D.cpp.

{
m_sumwx = 0;
m_sumEntries = 0;
for(int i=1, n=m_rep->GetNbinsX(); i<=n; ++i) {
m_sumwx += m_rep->GetBinContent(i)*m_rep->GetBinCenter(i);
m_sumEntries += (int)m_rep->GetBinContent(i);
}
}

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.

{
m_sumwx = 0;
m_sumEntries = 0;
return Base::reset();
}

StreamBuffer & Gaudi::Histogram1D::serialize | ( | StreamBuffer & | s | ) |

Serialization mechanism, Serialize the object for reading.

Parameters

  s | the StreamBuffer containing the data to be read

Returns
  the resulting StreamBuffer, after reading

Definition at line 217 of file H1D.cpp.

{
//DataObject::serialize(s);
std::string title;
int size;
s >> size;
for (int j = 0; j < size; j++) {
std::string key, value;
s >> key >> value;
annotation().addItem (key, value);
if ("Title" == key) {
title = value;
}
}
double lowerEdge, upperEdge, binHeight, binError;
int isFixedBinning, bins;
s >> isFixedBinning >> bins;
if ( m_rep ) delete m_rep;
if ( isFixedBinning ) {
s >> lowerEdge >> upperEdge;
m_rep = new TH1D(title.c_str(),title.c_str(),bins,lowerEdge,upperEdge);
} else {
Edges edges;
edges.resize(bins);
for ( int i = 0; i <= bins; ++i )
s >> *(double*)&edges[i];
m_rep = new TH1D(title.c_str(),title.c_str(),edges.size()-1,&edges.front());
}
m_axis.initialize(m_rep->GetXaxis(),true);
m_rep->Sumw2();
m_sumEntries = 0;
m_sumwx = 0;
for ( int i = 0; i <= bins + 1; ++i ) {
s >> binHeight >> binError;
m_rep->SetBinContent( i, binHeight );
m_rep->SetBinError( i, binError );
}
Stat_t allEntries;
s >> allEntries;
m_rep->SetEntries( allEntries );
Stat_t stats[4]; // stats array
s >> stats[0] >> stats[1] >> stats[2] >> stats[3];
m_rep->PutStats( stats );
return s;
}

StreamBuffer & Gaudi::Histogram1D::serialize | ( | StreamBuffer & | s | ) | const

Serialization mechanism, Serialize the object for writing.

Parameters

  s | the StreamBuffer where to write the data

Returns
  the resulting StreamBuffer, after wrinting

Definition at line 264 of file H1D.cpp.

{
//DataObject::serialize(s);
s << static_cast<int>( annotation().size() );
for (int i = 0; i < annotation().size(); i++) {
s << annotation().key(i);
s << annotation().value(i);
}
const AIDA::IAxis & axis( this->axis() );
const int isFixedBinning = axis.isFixedBinning();
const int bins = axis.bins();
s << isFixedBinning << bins;
if ( isFixedBinning ) {
s << axis.lowerEdge();
}
else {
for ( int i = 0; i < bins; ++i )
s << axis.binLowerEdge(i);
}
s << axis.upperEdge();
for ( int i = 0; i <= bins + 1; ++i )
s << m_rep->GetBinContent(i) << m_rep->GetBinError( i );
s << m_rep->GetEntries();
Stat_t stats[4]; // stats array
m_rep->GetStats( stats );
s << stats[0] << stats[1] << stats[2] << stats[3];
return s;
}

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.

{
m_rep->SetBinContent(rIndex(i),height);
m_rep->SetBinError(rIndex(i),error);
// accumulate sumwx for in range bins
if (i != AIDA::IAxis::UNDERFLOW_BIN && i != AIDA::IAxis::OVERFLOW_BIN )
m_sumwx += centre*height;
m_sumEntries += entries;
return true;
}

bool Gaudi::Histogram1D::setRms | ( | double | rms | ) |

Update histogram RMS.

Definition at line 124 of file H1D.cpp.

{
m_rep->SetEntries(m_sumEntries);
std::vector<double> stat(11);
// sum weights
stat[0] = sumBinHeights();
stat[1] = 0;
if (equivalentBinEntries() != 0)
stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries();
stat[2] = m_sumwx;
double mean = 0;
if ( sumBinHeights() != 0 ) mean = m_sumwx/ sumBinHeights();
stat[3] = ( mean*mean + rms*rms )* sumBinHeights();
m_rep->PutStats(&stat.front());
return true;
}

bool Gaudi::Histogram1D::setStatistics | ( | int | allEntries,
|  | double | eqBinEntries,
|  | double | mean,
|  | double | rms
| ) |  |
| virtual

set histogram statistics

Definition at line 141 of file H1D.cpp.

{
m_rep->SetEntries(allEntries);
// fill statistcal vector for Root
std::vector<double> stat(11);
// sum weights
stat[0] = sumBinHeights();
// sum weights **2
stat[1] = 0;
if (eqBinEntries != 0)
stat[1] = ( sumBinHeights() * sumBinHeights() ) / eqBinEntries;
// sum weights * x
stat[2] = mean*sumBinHeights();
// sum weight * x **2
stat[3] = ( mean*mean + rms*rms )* sumBinHeights();
m_rep->PutStats(&stat.front());
return true;
}

## 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:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiCommonSvc/src/HistogramSvc/H1D.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiCommonSvc/src/HistogramSvc/H1D.cpp