| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

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

- Search for |

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# Gaudi::Histogram2D Class Reference

`#include <H2D.h>`

Inheritance diagram for Gaudi::Histogram2D:

[legend]
Collaboration diagram for Gaudi::Histogram2D:

[legend]
List of all members.

## Detailed Description

AIDA implementation for 2 D histograms using ROOT THD2.

Author:
  M.Frank

Definition at line 20 of file H2D.h.

## Public Member Functions
| Histogram2D ()
| Standard Constructor.
| Histogram2D (TH2D *rep)
| Standard initializing Constructor with TH2D representation to be adopted.
virtual | ~Histogram2D ()
| Destructor.
bool | fill (double x, double y, double weight=1.)
| Fill the Histogram2D with a value and the.
virtual bool | setBinContents (int binIndexX, int binIndexY, int entries, double height, double error, double centreX, double centreY)
| Fast filling method for a given bin. It can be also the over/underflow bin.
bool | setRms (double rmsX, double rmsY)
| Sets the rms of the histogram.
bool | reset ()
void | copyFromAida (const IHistogram2D &h)
| Create new histogram from any AIDA based histogram.
virtual const CLID & | clID () const
| Retrieve reference to class defininition identifier.
## Static Public Member Functions
static const CLID & | classID ()
| Retrieve reference to class definition structure (static access).
## Protected Attributes
double | m_sumwx
double | m_sumwy

## Constructor & Destructor Documentation

Gaudi::Histogram2D::Histogram2D | ( |  | ) |

Standard Constructor.

Definition at line 112 of file H2D.cpp.

References Histogram2D(), Gaudi::Generic2D< IHistogram2D, TH2D >::m_rep, Gaudi::Generic2D< IHistogram2D, TH2D >::m_sumEntries, m_sumwx, m_sumwy, and Gaudi::Generic2D< IHistogram2D, TH2D >::setTitle().

Referenced by Histogram2D().

    00112                               {
    00113   m_rep = new TH2D();
    00114   m_rep->Sumw2();
    00115   m_sumEntries = 0;
    00116   m_sumwx = m_sumwy = 0;
    00117   setTitle("");
    00118   m_rep->SetDirectory(0);
    00119 }

Gaudi::Histogram2D::Histogram2D | ( | TH2D * | rep | ) |

Standard initializing Constructor with TH2D representation to be adopted.

Definition at line 121 of file H2D.cpp.

References Gaudi::Generic2D< IHistogram2D, TH2D >::adoptRepresentation(), Histogram2D(), Gaudi::Generic2D< IHistogram2D, TH2D >::m_rep, Gaudi::Generic2D< IHistogram2D, TH2D >::m_sumEntries, m_sumwx, and m_sumwy.

    00121                                         {
    00122   m_rep = 0;
    00123   adoptRepresentation(rep);
    00124   m_sumEntries = 0;
    00125   m_sumwx = m_sumwy = 0;
    00126   m_rep->SetDirectory(0);
    00127 }

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

Destructor.

Definition at line 27 of file H2D.h.

    00027 {}

## Member Function Documentation

bool Gaudi::Histogram2D::fill | ( | double | x,
|  | double | y,
|  | double | weight = `1.` |
| ) |  |  |

Fill the Histogram2D with a value and the.

Definition at line 129 of file H2D.cpp.

References Gaudi::Generic2D< IHistogram2D, TH2D >::m_rep.

    00129                                                              {
    00130   (weight==1.) ? m_rep->Fill(x,y) : m_rep->Fill(x,y,weight );
    00131   return true;
    00132 }

bool Gaudi::Histogram2D::setBinContents | ( | int | binIndexX,
|  | int | binIndexY,
|  | int | entries,
|  | double | height,
|  | double | error,
|  | double | centreX,
|  | double | centreY |
| ) |  |  | `[virtual]`

Fast filling method for a given bin. It can be also the over/underflow bin.

Definition at line 134 of file H2D.cpp.

References Gaudi::Generic2D< IHistogram2D, TH2D >::m_rep, Gaudi::Generic2D< IHistogram2D, TH2D >::m_sumEntries, m_sumwx, m_sumwy, Gaudi::Generic2D< IHistogram2D, TH2D >::rIndexX(), Gaudi::Generic2D< IHistogram2D, TH2D >::rIndexY(), and setBinContents().

Referenced by setBinContents().

    00134                                                                                                                        {
    00135   m_rep->SetBinContent(rIndexX(i), rIndexY(j), height);
    00136   m_rep->SetBinError(rIndexX(i), rIndexY(j), error);
    00137   // accumulate sumwx for in range bins
    00138   if (i >=0 && j >= 0) {
    00139     m_sumwx += centreX*height;
    00140     m_sumwy += centreY*height;
    00141   }
    00142   m_sumEntries += entries;
    00143   return true;
    00144 }

bool Gaudi::Histogram2D::setRms | ( | double | rmsX,
|  | double | rmsY |
| ) |  |  |

Sets the rms of the histogram.

Definition at line 146 of file H2D.cpp.

References Gaudi::Generic2D< IHistogram2D, TH2D >::equivalentBinEntries(), std::vector< _Tp, _Alloc >::front(), Gaudi::Generic2D< IHistogram2D, TH2D >::m_rep, Gaudi::Generic2D< IHistogram2D, TH2D >::m_sumEntries, m_sumwx, m_sumwy, Gaudi::Generic2D< IHistogram2D, TH2D >::meanX(), Gaudi::Generic2D< IHistogram2D, TH2D >::meanY(), setRms(), and Gaudi::Generic2D< IHistogram2D, TH2D >::sumBinHeights().

Referenced by setRms().

    00146                                                      {
    00147   m_rep->SetEntries(m_sumEntries);
    00148   std::vector<double> stat(11);
    00149   stat[0] =  sumBinHeights();
    00150   stat[1] = 0;
    00151   if(equivalentBinEntries() != 0)
    00152     stat[1] = (sumBinHeights() * sumBinHeights()) / equivalentBinEntries();
    00153   stat[2] = m_sumwx;
    00154   double meanX = 0;
    00155   if(sumBinHeights() != 0) meanX =  m_sumwx/ sumBinHeights();
    00156   stat[3] = (meanX*meanX + rmsX*rmsX) * sumBinHeights();
    00157   stat[4] = m_sumwy;
    00158   double meanY = 0;
    00159   if(sumBinHeights() != 0) meanY =  m_sumwy/ sumBinHeights();
    00160   stat[5] = (meanY*meanY + rmsY*rmsY) * sumBinHeights();
    00161   stat[6] = 0;
    00162   m_rep->PutStats(&stat.front());
    00163   return true;
    00164 }

bool Gaudi::Histogram2D::reset | ( |  | ) |

Reimplemented from Gaudi::Generic2D< IHistogram2D, TH2D >.

Definition at line 166 of file H2D.cpp.

References m_sumwx, m_sumwy, and reset().

Referenced by reset().

    00166                               {
    00167   m_sumwx = 0;
    00168   m_sumwy = 0;
    00169   return Base::reset();
    00170 }

void Gaudi::Histogram2D::copyFromAida | ( | const IHistogram2D & | h | ) |

Create new histogram from any AIDA based histogram.

Definition at line 172 of file H2D.cpp.

References copyFromAida(), std::vector< _Tp, _Alloc >::front(), Gaudi::Axis::initialize(), Gaudi::Generic2D< IHistogram2D, TH2D >::m_rep, Gaudi::Generic2D< IHistogram2D, TH2D >::m_sumEntries, m_sumwx, m_sumwy, Gaudi::Generic2D< IHistogram2D, TH2D >::m_xAxis, Gaudi::Generic2D< IHistogram2D, TH2D >::m_yAxis, std::vector< _Tp, _Alloc >::push_back(), Gaudi::Generic2D< IHistogram2D, TH2D >::rIndexX(), Gaudi::Generic2D< IHistogram2D, TH2D >::rIndexY(), std::vector< _Tp, _Alloc >::size(), Gaudi::Generic2D< IHistogram2D, TH2D >::xAxis(), and Gaudi::Generic2D< IHistogram2D, TH2D >::yAxis().

Referenced by copyFromAida().

    00172                                                          {
    00173   // implement here the copy
    00174   delete m_rep;
    00175   const char* tit = h.title().c_str();
    00176   if (h.xAxis().isFixedBinning() && h.yAxis().isFixedBinning()  )
    00177     m_rep = new TH2D(tit,tit,
    00178                      h.xAxis().bins(),h.xAxis().lowerEdge(),h.xAxis().upperEdge(),
    00179                      h.yAxis().bins(),h.yAxis().lowerEdge(),h.yAxis().upperEdge() );
    00180   else {
    00181     Edges eX, eY;
    00182     for (int i =0; i < h.xAxis().bins(); ++i)
    00183       eX.push_back(h.xAxis().binLowerEdge(i));
    00184     // add also upperedges at the end
    00185     eX.push_back(h.xAxis().upperEdge() );
    00186     for (int i =0; i < h.yAxis().bins(); ++i)
    00187       eY.push_back(h.yAxis().binLowerEdge(i));
    00188     // add also upperedges at the end
    00189     eY.push_back(h.yAxis().upperEdge() );
    00190     m_rep = new TH2D(tit,tit,eX.size()-1,&eX.front(),eY.size()-1,&eY.front());
    00191   }
    00192   m_xAxis.initialize(m_rep->GetXaxis(),true);
    00193   m_yAxis.initialize(m_rep->GetYaxis(),true);
    00194   m_rep->Sumw2();
    00195   m_sumEntries = 0;
    00196   m_sumwx = 0;
    00197   m_sumwy = 0;
    00198   // statistics
    00199   double sumw = h.sumBinHeights();
    00200   double sumw2 = 0;
    00201   if (h.equivalentBinEntries() != 0)
    00202     sumw2 = ( sumw * sumw ) /h.equivalentBinEntries();
    00203   double sumwx = h.meanX()*h.sumBinHeights();
    00204   double sumwx2 = (h.meanX()*h.meanX() + h.rmsX()*h.rmsX() )*h.sumBinHeights();
    00205   double sumwy = h.meanY()*h.sumBinHeights();
    00206   double sumwy2 = (h.meanY()*h.meanY() + h.rmsY()*h.rmsY() )*h.sumBinHeights();
    00207   double sumwxy = 0;
    00208
    00209   // copy the contents in  (AIDA underflow/overflow are -2,-1)
    00210   for (int i=-2; i < xAxis().bins(); ++i) {
    00211     for (int j=-2; j < yAxis().bins(); ++j) {
    00212       // root binning starts from one !
    00213       m_rep->SetBinContent(rIndexX(i), rIndexY(j), h.binHeight(i,j) );
    00214       m_rep->SetBinError(rIndexX(i), rIndexY(j), h.binError(i,j) );
    00215       // calculate statistics
    00216       if ( i >= 0 && j >= 0) {
    00217         sumwxy += h.binHeight(i,j)*h.binMeanX(i,j)*h.binMeanY(i,j);
    00218       }
    00219     }
    00220   }
    00221   // need to do set entries after setting contents otherwise root will recalulate them
    00222   // taking into account how many time  SetBinContents() has been called
    00223   m_rep->SetEntries(h.allEntries());
    00224   // fill stat vector
    00225   std::vector<double> stat(11);
    00226   stat[0] = sumw;
    00227   stat[1] = sumw2;
    00228   stat[2] = sumwx;
    00229   stat[3] = sumwx2;
    00230   stat[4] = sumwy;
    00231   stat[5] = sumwy2;
    00232   stat[6] = sumwxy;
    00233   m_rep->PutStats(&stat.front());
    00234 }

virtual const CLID& Gaudi::Histogram2D::clID | ( |  | ) | const`[inline, virtual]`

Retrieve reference to class defininition identifier.

Reimplemented from DataObject.

Definition at line 41 of file H2D.h.

References classID(), and clID().

Referenced by clID().

    00041 { return Gaudi::Histogram2D::classID(); }

static const CLID& Gaudi::Histogram2D::classID | ( |  | ) | `[inline, static]`

Retrieve reference to class definition structure (static access).

Reimplemented from DataObject.

Definition at line 42 of file H2D.h.

References classID(), and CLID_H2D.

Referenced by classID(), and clID().

    00042 { return CLID_H2D; }

## Member Data Documentation

double Gaudi::Histogram2D::m_sumwx`[protected]`

Definition at line 45 of file H2D.h.

Referenced by copyFromAida(), Histogram2D(), reset(), setBinContents(), and setRms().

double Gaudi::Histogram2D::m_sumwy`[protected]`

Definition at line 46 of file H2D.h.

Referenced by copyFromAida(), Histogram2D(), reset(), setBinContents(), and setRms().

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r2/GaudiSvc/v17r1/src/HistogramSvc/H2D.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r2/GaudiSvc/v17r1/src/HistogramSvc/H2D.cpp