The Gaudi Framework  master (594c33fa)
Gaudi::Histogram2D Class Reference

#include </builds/gaudi/Gaudi/GaudiCommonSvc/include/GaudiCommonSvc/H2D.h>

Inheritance diagram for Gaudi::Histogram2D:
Collaboration diagram for Gaudi::Histogram2D:

Public Member Functions

 Histogram2D ()
 Standard Constructor. More...
 
 Histogram2D (TH2D *rep)
 Standard initializing Constructor with TH2D representation to be adopted. More...
 
bool fill (double x, double y, double weight=1.) override
 Fill the Histogram2D with a value and the. More...
 
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. More...
 
bool setRms (double rmsX, double rmsY)
 Sets the rms of the histogram. More...
 
bool reset () override
 
void copyFromAida (const AIDA::IHistogram2D &h)
 Create new histogram from any AIDA based histogram. More...
 
const CLIDclID () const override
 Retrieve reference to class defininition identifier. 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 ()
 Retrieve Link manager. More...
 
const LinkManagerlinkMgr () const
 
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::Generic2D< AIDA::IHistogram2D, TH2D >
 Generic2D ()=default
 
TObject * representation () const override
 ROOT object implementation. More...
 
void adoptRepresentation (TObject *rep) override
 Adopt ROOT histogram representation. More...
 
void adoptRepresentation (TObject *rep)
 Adopt ROOT histogram representation. More...
 
void adoptRepresentation (TObject *rep)
 Adopt ROOT histogram representation. 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...
 
const AIDA::IAxis & xAxis () const override
 Return the X axis. More...
 
const AIDA::IAxis & yAxis () const override
 Return the Y axis. More...
 
virtual int rIndexX (int index) const
 operator methods More...
 
virtual int rIndexY (int index) const
 operator methods 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...
 
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...
 
double binMeanX (int indexX, int indexY) const override
 The weighted mean along x of a given bin. More...
 
double binMeanY (int indexX, int indexY) const override
 The weighted mean along y of a given bin. More...
 
int binEntries (int indexX, int indexY) const override
 The number of entries (ie the number of times fill was called for this bin). More...
 
int binEntries (int indexX, int indexY) const
 
int binEntries (int idX, int idY) const
 
int binEntriesX (int indexX) const override
 Equivalent to projectionX().binEntries(indexX). More...
 
int binEntriesY (int indexY) const override
 Equivalent to projectionY().binEntries(indexY). More...
 
double binHeight (int indexX, int indexY) const override
 Total height of the corresponding bin (ie the sum of the weights in this bin). More...
 
double binHeightX (int indexX) const override
 Equivalent to projectionX().binHeight(indexX). More...
 
double binHeightY (int indexY) const override
 Equivalent to projectionY().binHeight(indexY). More...
 
double binError (int indexX, int indexY) const override
 The error on this bin. More...
 
virtual double binRms (int indexX, int indexY) const
 The spread (RMS) of this bin. More...
 
double meanX () const override
 Returns the mean of the profile, as calculated on filling-time projected on the X axis. More...
 
double meanY () const override
 Returns the mean of the profile, as calculated on filling-time projected on the Y axis. More...
 
double rmsX () const override
 Returns the rms of the profile as calculated on filling-time projected on the X axis. More...
 
double rmsY () const override
 Returns the rms of the profile as calculated on filling-time projected on the Y axis. More...
 
int coordToIndexX (double coordX) const override
 Convenience method, equivalent to xAxis().coordToIndex(coord). More...
 
int coordToIndexY (double coordY) const override
 Convenience method, equivalent to yAxis().coordToIndex(coord). 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 add (const AIDA::IHistogram2D &h) override
 Modifies this profile by adding the contents of profile to it. More...
 
bool reset () override
 
void * cast (const std::string &className) const override
 Introspection method. More...
 
void * cast (const std::string &className) const
 
void * cast (const std::string &className) const
 
const std::stringuserLevelClassType () const
 The AIDA user-level unterface leaf class type. 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...
 
- Public Member Functions inherited from Gaudi::HistogramBase
virtual TObject * representation () const =0
 ROOT object implementation. More...
 
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
 
double m_sumwy = 0
 
- Protected Attributes inherited from Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >
Axis m_xAxis
 X axis member. More...
 
Axis m_yAxis
 Y axis member. More...
 
AIDA::Annotation m_annotation
 Object annotations. More...
 
std::unique_ptr< TH2D > m_rep
 Reference to underlying implementation. More...
 
std::string m_classType
 class type More...
 
int m_sumEntries
 cache sumEntries (allEntries) when setting contents since Root can't compute by himself More...
 

Private Attributes

std::mutex m_fillSerialization
 

Friends

void reset (Histogram2D &h)
 
void to_json (nlohmann::json &j, Histogram2D const &h)
 conversion to json via nlohmann library More...
 

Additional Inherited Members

- Public Types inherited from Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >
typedef Generic2D< AIDA::IHistogram2D, TH2D > Base
 
- Protected Member Functions inherited from Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >
 Generic2D (TH2D *p)
 constructor More...
 

Detailed Description

AIDA implementation for 2 D histograms using ROOT THD2

Author
M.Frank

Definition at line 30 of file H2D.h.

Constructor & Destructor Documentation

◆ Histogram2D() [1/2]

Gaudi::Histogram2D::Histogram2D ( )

Standard Constructor.

Definition at line 145 of file H2D.cpp.

145  : Base( new TH2D() ) {
146  m_rep->Sumw2();
147  m_sumwx = m_sumwy = 0;
148  setTitle( "" );
149  m_rep->SetDirectory( nullptr );
150 }

◆ Histogram2D() [2/2]

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

Standard initializing Constructor with TH2D representation to be adopted.

Definition at line 152 of file H2D.cpp.

152  {
153  adoptRepresentation( rep );
154  m_sumwx = m_sumwy = 0;
155  m_rep->SetDirectory( nullptr );
156 }

Member Function Documentation

◆ classID()

static const CLID& Gaudi::Histogram2D::classID ( )
inlinestatic

Definition at line 54 of file H2D.h.

54 { return CLID_H2D; }

◆ clID()

const CLID& Gaudi::Histogram2D::clID ( ) const
inlineoverridevirtual

Retrieve reference to class defininition identifier.

Reimplemented from DataObject.

Definition at line 53 of file H2D.h.

53 { return classID(); }

◆ copyFromAida()

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

Create new histogram from any AIDA based histogram.

Definition at line 206 of file H2D.cpp.

206  {
207  // implement here the copy
208  std::string titlestr = h.title();
209  const char* title = titlestr.c_str();
210  if ( h.xAxis().isFixedBinning() && h.yAxis().isFixedBinning() )
211  m_rep.reset( new TH2D( title, title, h.xAxis().bins(), h.xAxis().lowerEdge(), h.xAxis().upperEdge(),
212  h.yAxis().bins(), h.yAxis().lowerEdge(), h.yAxis().upperEdge() ) );
213  else {
214  Edges eX, eY;
215  for ( int i = 0; i < h.xAxis().bins(); ++i ) eX.push_back( h.xAxis().binLowerEdge( i ) );
216  // add also upperedges at the end
217  eX.push_back( h.xAxis().upperEdge() );
218  for ( int i = 0; i < h.yAxis().bins(); ++i ) eY.push_back( h.yAxis().binLowerEdge( i ) );
219  // add also upperedges at the end
220  eY.push_back( h.yAxis().upperEdge() );
221  m_rep.reset( new TH2D( title, title, eX.size() - 1, &eX.front(), eY.size() - 1, &eY.front() ) );
222  }
223  m_xAxis.initialize( m_rep->GetXaxis(), true );
224  m_yAxis.initialize( m_rep->GetYaxis(), true );
225  m_rep->Sumw2();
226  m_sumEntries = 0;
227  m_sumwx = 0;
228  m_sumwy = 0;
229  // statistics
230  double sumw = h.sumBinHeights();
231  double sumw2 = 0;
232  if ( std::abs( h.equivalentBinEntries() ) > std::numeric_limits<double>::epsilon() )
233  sumw2 = ( sumw * sumw ) / h.equivalentBinEntries();
234  double sumwx = h.meanX() * h.sumBinHeights();
235  double sumwx2 = ( h.meanX() * h.meanX() + h.rmsX() * h.rmsX() ) * h.sumBinHeights();
236  double sumwy = h.meanY() * h.sumBinHeights();
237  double sumwy2 = ( h.meanY() * h.meanY() + h.rmsY() * h.rmsY() ) * h.sumBinHeights();
238  double sumwxy = 0;
239 
240  // copy the contents in (AIDA underflow/overflow are -2,-1)
241  for ( int i = -2; i < xAxis().bins(); ++i ) {
242  for ( int j = -2; j < yAxis().bins(); ++j ) {
243  // root binning starts from one !
244  m_rep->SetBinContent( rIndexX( i ), rIndexY( j ), h.binHeight( i, j ) );
245  m_rep->SetBinError( rIndexX( i ), rIndexY( j ), h.binError( i, j ) );
246  // calculate statistics
247  if ( i >= 0 && j >= 0 ) { sumwxy += h.binHeight( i, j ) * h.binMeanX( i, j ) * h.binMeanY( i, j ); }
248  }
249  }
250  // need to do set entries after setting contents otherwise root will recalculate them
251  // taking into account how many time SetBinContents() has been called
252  m_rep->SetEntries( h.allEntries() );
253  // fill stat vector
254  std::array<double, 11> stat = { { sumw, sumw2, sumwx, sumwx2, sumwy, sumwy2, sumwxy } };
255  m_rep->PutStats( stat.data() );
256 }

◆ fill()

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

Fill the Histogram2D with a value and the.

Definition at line 177 of file H2D.cpp.

177  {
178  // avoid race conditiosn when filling the histogram
179  auto guard = std::scoped_lock{ m_fillSerialization };
180  m_rep->Fill( x, y, weight );
181  return true;
182 }

◆ reset()

bool Gaudi::Histogram2D::reset ( )
override

Definition at line 171 of file H2D.cpp.

171  {
172  m_sumwx = 0;
173  m_sumwy = 0;
174  return Base::reset();
175 }

◆ setBinContents()

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 158 of file H2D.cpp.

159  {
160  m_rep->SetBinContent( rIndexX( i ), rIndexY( j ), height );
161  m_rep->SetBinError( rIndexX( i ), rIndexY( j ), error );
162  // accumulate sumwx for in range bins
163  if ( i >= 0 && j >= 0 ) {
164  m_sumwx += centreX * height;
165  m_sumwy += centreY * height;
166  }
168  return true;
169 }

◆ setRms()

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

Sets the rms of the histogram.

Definition at line 184 of file H2D.cpp.

184  {
185  m_rep->SetEntries( m_sumEntries );
186  std::vector<double> stat( 11 );
187  stat[0] = sumBinHeights();
188  stat[1] = 0;
190  stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries();
191  stat[2] = m_sumwx;
192  stat[4] = m_sumwy;
193  double meanX = 0;
194  double meanY = 0;
198  }
199  stat[3] = ( meanX * meanX + rmsX * rmsX ) * sumBinHeights();
200  stat[5] = ( meanY * meanY + rmsY * rmsY ) * sumBinHeights();
201  stat[6] = 0;
202  m_rep->PutStats( &stat.front() );
203  return true;
204 }

Friends And Related Function Documentation

◆ reset

void reset ( Histogram2D h)
friend

Definition at line 47 of file H2D.h.

47 { h.reset(); }

◆ to_json

void to_json ( nlohmann::json &  j,
Histogram2D const &  h 
)
friend

conversion to json via nlohmann library

Definition at line 49 of file H2D.h.

49 { j = *h.m_rep.get(); }

Member Data Documentation

◆ m_fillSerialization

std::mutex Gaudi::Histogram2D::m_fillSerialization
private

Definition at line 62 of file H2D.h.

◆ m_sumwx

double Gaudi::Histogram2D::m_sumwx = 0
protected

Definition at line 58 of file H2D.h.

◆ m_sumwy

double Gaudi::Histogram2D::m_sumwy = 0
protected

Definition at line 59 of file H2D.h.


The documentation for this class was generated from the following files:
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::Base
Generic2D< AIDA::IHistogram2D, TH2D > Base
Definition: Generic2D.h:48
Gaudi::Histogram2D::m_sumwx
double m_sumwx
Definition: H2D.h:58
std::string
STL class.
Gaudi::Histogram2D::m_sumwy
double m_sumwy
Definition: H2D.h:59
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::xAxis
const AIDA::IAxis & xAxis() const override
Return the X axis.
Definition: Generic2D.h:75
Gaudi::Histogram2D::classID
static const CLID & classID()
Definition: H2D.h:54
std::vector< double >
std::string::size
T size(T... args)
std::abs
Gaudi::ParticleID abs(const Gaudi::ParticleID &p)
Return the absolute value for a PID.
Definition: ParticleID.h:191
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::rIndexY
virtual int rIndexY(int index) const
operator methods
Definition: Generic2D.h:81
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::rIndexX
virtual int rIndexX(int index) const
operator methods
Definition: Generic2D.h:79
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::setTitle
bool setTitle(const std::string &title) override
Set the title of the object.
Definition: Generic2D.h:170
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::rmsY
double rmsY() const override
Returns the rms of the profile as calculated on filling-time projected on the Y axis.
Definition: Generic2D.h:283
std::unique_ptr::reset
T reset(T... args)
std::vector::push_back
T push_back(T... args)
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::adoptRepresentation
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
ProduceConsume.j
j
Definition: ProduceConsume.py:101
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::m_yAxis
Axis m_yAxis
Y axis member.
Definition: Generic2D.h:158
std::string::c_str
T c_str(T... args)
Gaudi::Histogram2D::m_fillSerialization
std::mutex m_fillSerialization
Definition: H2D.h:62
Gaudi::Axis::initialize
void initialize(TAxis *itaxi, bool)
Definition: Axis.h:63
AlgSequencer.h
h
Definition: AlgSequencer.py:31
std::array
STL class.
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::reset
bool reset() override
Definition: Generic2D.h:328
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::yAxis
const AIDA::IAxis & yAxis() const override
Return the Y axis.
Definition: Generic2D.h:77
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::m_xAxis
Axis m_xAxis
X axis member.
Definition: Generic2D.h:156
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::meanX
double meanX() const override
Returns the mean of the profile, as calculated on filling-time projected on the X axis.
Definition: Generic2D.h:268
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::title
std::string title() const override
Get the title of the object.
Definition: Generic2D.h:62
std::numeric_limits::epsilon
T epsilon(T... args)
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::rmsX
double rmsX() const override
Returns the rms of the profile as calculated on filling-time projected on the X axis.
Definition: Generic2D.h:278
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::m_rep
std::unique_ptr< TH2D > m_rep
Reference to underlying implementation.
Definition: Generic2D.h:162
Gaudi::Edges
std::vector< double > Edges
Definition: GaudiPI.h:28
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::m_sumEntries
int m_sumEntries
cache sumEntries (allEntries) when setting contents since Root can't compute by himself
Definition: Generic2D.h:166
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::entries
int entries() const override
Get the number or all the entries.
Definition: Generic2D.h:185
std::numeric_limits
std::array::data
T data(T... args)
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::sumBinHeights
double sumBinHeights() const override
Get the sum of in range bin heights in the IProfile.
Definition: Generic2D.h:205
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::meanY
double meanY() const override
Returns the mean of the profile, as calculated on filling-time projected on the Y axis.
Definition: Generic2D.h:273
Gaudi::Generic2D< AIDA::IHistogram2D, TH2D >::equivalentBinEntries
virtual double equivalentBinEntries() const
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
Definition: Generic2D.h:314