|
Gaudi Framework, version v23r2 |
| Home | Generated: Thu Jun 28 2012 |
AIDA implementation for 1 D histograms using ROOT THD1. More...
#include <H1D.h>


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. | |
Static Public Member Functions | |
| 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 | |
Private Member Functions | |
| void | init (const std::string &title, bool initialize_axis=true) |
| void | initSums () |
AIDA implementation for 1 D histograms using ROOT THD1.
Definition at line 17 of file H1D.h.
| Gaudi::Histogram1D::Histogram1D | ( | ) |
| Gaudi::Histogram1D::Histogram1D | ( | TH1D * | rep ) |
| virtual Gaudi::Histogram1D::~Histogram1D | ( | ) | [inline, virtual] |
| void Gaudi::Histogram1D::adoptRepresentation | ( | TObject * | rep ) | [virtual] |
| static const CLID& Gaudi::Histogram1D::classID | ( | ) | [inline, static] |
Retrieve reference to class definition structure (static access)
Retrieve Pointer to class definition structure.
Reimplemented from DataObject.
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] |
| 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] |
| 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 ) | const |
Serialization mechanism, Serialize the object for writing.
| s | the StreamBuffer where to write the data |
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;
}
| StreamBuffer & Gaudi::Histogram1D::serialize | ( | StreamBuffer & | s ) |
Serialization mechanism, Serialize the object for reading.
| s | the StreamBuffer containing the data to be read |
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;
}
| bool Gaudi::Histogram1D::setBinContents | ( | int | i, |
| int | entries, | ||
| double | height, | ||
| double | error, | ||
| double | centre | ||
| ) | [virtual] |
set bin content (entries and centre are not used )
| 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;
}
double Gaudi::Histogram1D::m_sumwx [protected] |