| # Gaudi Framework, version v21r8 |

Home |  | Generated: 17 Mar 2010

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

List of all members.

## 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 ()

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

    00051                                {
    00052   m_rep = new TH1D();
    00053   init("",false);
    00054 }

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

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

Definition at line 56 of file H1D.cpp.

    00056                                         {
    00057   m_rep = rep;
    00058   init(m_rep->GetTitle());
    00059   initSums();
    00060 }

virtual Gaudi::Histogram1D::~Histogram1D | ( |  | ) | `[inline, virtual]`

Destructor.

Definition at line 30 of file H1D.h.

    00030 {}

## Member Function Documentation

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

Definition at line 62 of file H1D.cpp.

    00062                                                                          {
    00063   m_classType = "IHistogram1D";
    00064   if ( initialize_axis )  {
    00065     m_axis.initialize(m_rep->GetXaxis(),false);
    00066   }
    00067   const TArrayD* a = m_rep->GetSumw2();
    00068   if ( 0 == a || (a && a->GetSize()==0) ) m_rep->Sumw2();
    00069   setTitle(title);
    00070   m_rep->SetDirectory(0);
    00071   m_sumEntries = 0;
    00072   m_sumwx = 0;
    00073 }

void Gaudi::Histogram1D::initSums | ( |  | ) | `[private]`

Definition at line 75 of file H1D.cpp.

    00075                                  {
    00076   m_sumwx = 0;
    00077   m_sumEntries = 0;
    00078   for(int i=1, n=m_rep->GetNbinsX(); i<=n; ++i)    {
    00079     m_sumwx += m_rep->GetBinContent(i)*m_rep->GetBinCenter(i);
    00080     m_sumEntries += (int)m_rep->GetBinContent(i);
    00081   }
    00082 }

void Gaudi::Histogram1D::adoptRepresentation | ( | TObject * | rep | ) | `[virtual]`

Adopt ROOT histogram representation.

Definition at line 91 of file H1D.cpp.

    00091                                                         {
    00092   Gaudi::Generic1D<AIDA::IHistogram1D,TH1D>::adoptRepresentation(rep);
    00093   if ( m_rep )  {
    00094     init(m_rep->GetTitle());
    00095     initSums();
    00096   }
    00097 }

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

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

bool Gaudi::Histogram1D::reset | ( |  | ) | `[virtual]`

need to overwrite reset to reset the sums

Definition at line 84 of file H1D.cpp.

    00084                                {
    00085   m_sumwx = 0;
    00086   m_sumEntries = 0;
    00087   return Base::reset();
    00088 }

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

set histogram statistics

Definition at line 126 of file H1D.cpp.

    00126                                                                                               {
    00127   m_rep->SetEntries(allEntries);
    00128   // fill statistcal vector for Root
    00129   std::vector<double> stat(11);
    00130   // sum weights
    00131   stat[0] =  sumBinHeights();
    00132   // sum weights **2
    00133   stat[1] = 0;
    00134   if (eqBinEntries != 0)
    00135     stat[1] = (  sumBinHeights() * sumBinHeights() ) / eqBinEntries;
    00136   // sum weights * x
    00137   stat[2] = mean*sumBinHeights();
    00138   // sum weight * x **2
    00139   stat[3] = ( mean*mean + rms*rms )* sumBinHeights();
    00140   m_rep->PutStats(&stat.front());
    00141   return true;
    00142 }

bool Gaudi::Histogram1D::fill | ( | double | x,
|  | double | weight |
| ) |  |  | `[virtual]`

Fill the Profile1D with a value and the corresponding weight.

Definition at line 144 of file H1D.cpp.

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

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

Update histogram RMS.

Definition at line 109 of file H1D.cpp.

    00109                                         {
    00110   m_rep->SetEntries(m_sumEntries);
    00111   std::vector<double> stat(11);
    00112   // sum weights
    00113   stat[0] =  sumBinHeights();
    00114   stat[1] = 0;
    00115   if (equivalentBinEntries() != 0)
    00116     stat[1] = (  sumBinHeights() * sumBinHeights() ) / equivalentBinEntries();
    00117   stat[2] = m_sumwx;
    00118   double mean = 0;
    00119   if ( sumBinHeights() != 0 ) mean =  m_sumwx/ sumBinHeights();
    00120   stat[3] = ( mean*mean + rms*rms )* sumBinHeights();
    00121   m_rep->PutStats(&stat.front());
    00122   return true;
    00123 }

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

Create new histogram from any AIDA based histogram.

Definition at line 149 of file H1D.cpp.

    00149                                                               {
    00150  // implement here the copy
    00151   std::string tit = h.title()+"Copy";
    00152   delete m_rep;
    00153   if (h.axis().isFixedBinning() )  {
    00154     m_rep = new TH1D(tit.c_str(),tit.c_str(),h.axis().bins(),h.axis().lowerEdge(),h.axis().upperEdge());
    00155   }
    00156   else {
    00157     Edges e;
    00158     for (int i =0; i < h.axis().bins(); ++i)  {
    00159       e.push_back(h.axis().binLowerEdge(i));
    00160     }
    00161     // add also upperedges at the end
    00162     e.push_back(h.axis().upperEdge() );
    00163     m_rep = new TH1D(tit.c_str(),tit.c_str(),e.size()-1,&e.front());
    00164   }
    00165   m_axis.initialize(m_rep->GetXaxis(),false);
    00166   m_rep->Sumw2();
    00167   m_sumEntries = 0;
    00168   m_sumwx = 0;
    00169   // sumw
    00170   double sumw = h.sumBinHeights();
    00171   // sumw2
    00172   double sumw2 = 0;
    00173   if (h.equivalentBinEntries() != 0)
    00174     sumw2 = ( sumw * sumw ) /h.equivalentBinEntries();
    00175
    00176   double sumwx = h.mean()*h.sumBinHeights();
    00177   double sumwx2 = (h.mean()*h.mean() + h.rms()*h.rms() )*h.sumBinHeights();
    00178
    00179   // copy the contents in
    00180   for (int i=-2; i < axis().bins(); ++i) {
    00181     // root binning starts from one !
    00182     m_rep->SetBinContent(rIndex(i),h.binHeight(i) );
    00183     m_rep->SetBinError(rIndex(i),h.binError(i) );
    00184   }
    00185   // need to do set entries after setting contents otherwise root will recalulate them
    00186   // taking into account how many time  SetBinContents() has been called
    00187   m_rep->SetEntries(h.allEntries());
    00188     // stat vector
    00189   std::vector<double> stat(11);
    00190   stat[0] = sumw;
    00191   stat[1] = sumw2;
    00192   stat[2] = sumwx;
    00193   stat[3] = sumwx2;
    00194   m_rep->PutStats(&stat.front());
    00195 }

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.

    00046 { return Gaudi::Histogram1D::classID(); }

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.

    00047 { return CLID_H1D; }

StreamBuffer & Gaudi::Histogram1D::serialize | ( | StreamBuffer & | s | ) | `[virtual]`

Serialization mechanism, Serialize the object for reading.

Parameters:

  | s | the StreamBuffer containing the data to be read

Returns:
  the resulting StreamBuffer, after reading

Reimplemented from DataObject.

Definition at line 197 of file H1D.cpp.

    00197                                                          {
    00198   DataObject::serialize(s);
    00199   std::string title;
    00200   int size;
    00201   s >> size;
    00202   for (int j = 0; j < size; j++) {
    00203     std::string key, value;
    00204     s >> key >> value;
    00205     annotation().addItem (key, value);
    00206     if ("Title" == key) {
    00207       title = value;
    00208     }
    00209   }
    00210   double lowerEdge, upperEdge, binHeight, binError;
    00211   int    isFixedBinning, bins;
    00212   s >> isFixedBinning >> bins;
    00213
    00214   if ( m_rep ) delete m_rep;
    00215   if ( isFixedBinning ) {
    00216     s >> lowerEdge >> upperEdge;
    00217     m_rep = new TH1D(title.c_str(),title.c_str(),bins,lowerEdge,upperEdge);
    00218   } else {
    00219     Edges edges;
    00220     edges.resize(bins);
    00221     for ( int i = 0; i <= bins; ++i )
    00222       s >> *(double*)&edges[i];
    00223     m_rep = new TH1D(title.c_str(),title.c_str(),edges.size()-1,&edges.front());
    00224   }
    00225   m_axis.initialize(m_rep->GetXaxis(),true);
    00226   m_rep->Sumw2();
    00227   m_sumEntries = 0;
    00228   m_sumwx = 0;
    00229
    00230   for ( int i = 0; i <= bins + 1; ++i ) {
    00231     s >> binHeight >> binError;
    00232     m_rep->SetBinContent( i, binHeight );
    00233     m_rep->SetBinError( i, binError );
    00234   }
    00235   Stat_t allEntries;
    00236   s >> allEntries;
    00237   m_rep->SetEntries( allEntries );
    00238   Stat_t stats[4];                                    // stats array
    00239   s >> stats[0] >> stats[1] >> stats[2] >> stats[3];
    00240   m_rep->PutStats( stats );
    00241   return s;
    00242 }

StreamBuffer & Gaudi::Histogram1D::serialize | ( | StreamBuffer & | s | ) | const`[virtual]`

Serialization mechanism, Serialize the object for writing.

Parameters:

  | s | the StreamBuffer where to write the data

Returns:
  the resulting StreamBuffer, after wrinting

Reimplemented from DataObject.

Definition at line 244 of file H1D.cpp.

    00244                                                                {
    00245   DataObject::serialize(s);
    00246   s << static_cast<int>( annotation().size() );
    00247   for (int i = 0; i < annotation().size(); i++) {
    00248     s << annotation().key(i);
    00249     s << annotation().value(i);
    00250   }
    00251   const AIDA::IAxis & axis( this->axis() );
    00252   const int isFixedBinning = axis.isFixedBinning();
    00253   const int bins = axis.bins();
    00254   s << isFixedBinning << bins;
    00255   if ( isFixedBinning ) {
    00256     s << axis.lowerEdge();
    00257   }
    00258   else {
    00259     for ( int i = 0; i < bins; ++i )
    00260       s << axis.binLowerEdge(i);
    00261   }
    00262   s << axis.upperEdge();
    00263   for ( int i = 0; i <= bins + 1; ++i )
    00264     s << m_rep->GetBinContent(i) << m_rep->GetBinError( i );
    00265
    00266   s << m_rep->GetEntries();
    00267   Stat_t stats[4];  // stats array
    00268   m_rep->GetStats( stats );
    00269   s << stats[0] << stats[1] << stats[2] << stats[3];
    00270   return s;
    00271 }

## 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_v21r8/GaudiSvc/src/HistogramSvc/H1D.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r8/GaudiSvc/src/HistogramSvc/H1D.cpp