The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
Gaudi::Histogram2D Class Reference

AIDA implementation for 2 D histograms using ROOT THD2. More...

#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.
 
 Histogram2D (TH2D *rep)
 Standard initializing Constructor with TH2D representation to be adopted.
 
bool fill (double x, double y, double weight=1.) override
 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 () override
 
void copyFromAida (const AIDA::IHistogram2D &h)
 Create new histogram from any AIDA based histogram.
 
const CLIDclID () const override
 Retrieve reference to class defininition identifier.
 
- Public Member Functions inherited from DataObject
 DataObject ()
 Standard Constructor.
 
 DataObject (const DataObject &rhs)
 Copy Constructor.
 
DataObjectoperator= (const DataObject &rhs)
 Assignment Operator.
 
 DataObject (DataObject &&rhs)
 Move Constructor.
 
DataObjectoperator= (DataObject &&rhs)
 Move Assignment Operator.
 
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.
 
IRegistryregistry () const
 Get pointer to Registry.
 
LinkManagerlinkMgr ()
 Retrieve Link manager.
 
const LinkManagerlinkMgr () const
 
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::Generic2D< AIDA::IHistogram2D, TH2D >
void * cast (const std::string &className) const
 
int binEntries (int indexX, int indexY) const
 
void adoptRepresentation (TObject *rep)
 Adopt ROOT histogram representation.
 
void * cast (const std::string &className) const
 
int binEntries (int idX, int idY) const
 
void adoptRepresentation (TObject *rep)
 Adopt ROOT histogram representation.
 
 Generic2D ()=default
 
TObject * representation () const override
 ROOT object implementation.
 
void adoptRepresentation (TObject *rep) override
 Adopt ROOT histogram representation.
 
void adoptRepresentation (TObject *rep)
 Adopt ROOT histogram representation.
 
void adoptRepresentation (TObject *rep)
 Adopt ROOT histogram representation.
 
std::string title () const override
 Get the title of the object.
 
bool setTitle (const std::string &title) override
 Set the title of the object.
 
std::string name () const
 object name
 
bool setName (const std::string &newName)
 Set the name of the object.
 
AIDA::IAnnotation & annotation () override
 Access annotation object.
 
const AIDA::IAnnotation & annotation () const override
 Access annotation object (cons)
 
const AIDA::IAxis & xAxis () const override
 Return the X axis.
 
const AIDA::IAxis & yAxis () const override
 Return the Y axis.
 
virtual int rIndexX (int index) const
 operator methods
 
virtual int rIndexY (int index) const
 operator methods
 
int entries () const override
 Get the number or all the entries.
 
int allEntries () const override
 Get the number or all the entries, both in range and underflow/overflow bins of the IProfile.
 
int extraEntries () const override
 Get the number of entries in the underflow and overflow bins.
 
double sumBinHeights () const override
 Get the sum of in range bin heights in the IProfile.
 
double sumAllBinHeights () const override
 Get the sum of all the bins heights (including underflow and overflow bin).
 
double sumExtraBinHeights () const override
 Get the sum of the underflow and overflow bin height.
 
double minBinHeight () const override
 Get the minimum height of the in-range bins.
 
double maxBinHeight () const override
 Get the maximum height of the in-range bins.
 
double binMeanX (int indexX, int indexY) const override
 The weighted mean along x of a given bin.
 
double binMeanY (int indexX, int indexY) const override
 The weighted mean along y of a given bin.
 
int binEntries (int indexX, int indexY) const override
 The number of entries (ie the number of times fill was called for this bin).
 
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).
 
int binEntriesY (int indexY) const override
 Equivalent to projectionY().binEntries(indexY).
 
double binHeight (int indexX, int indexY) const override
 Total height of the corresponding bin (ie the sum of the weights in this bin).
 
double binHeightX (int indexX) const override
 Equivalent to projectionX().binHeight(indexX).
 
double binHeightY (int indexY) const override
 Equivalent to projectionY().binHeight(indexY).
 
double binError (int indexX, int indexY) const override
 The error on this bin.
 
virtual double binRms (int indexX, int indexY) const
 The spread (RMS) of this bin.
 
double meanX () const override
 Returns the mean of the profile, as calculated on filling-time projected on the X axis.
 
double meanY () const override
 Returns the mean of the profile, as calculated on filling-time projected on the Y axis.
 
double rmsX () const override
 Returns the rms of the profile as calculated on filling-time projected on the X axis.
 
double rmsY () const override
 Returns the rms of the profile as calculated on filling-time projected on the Y axis.
 
int coordToIndexX (double coordX) const override
 Convenience method, equivalent to xAxis().coordToIndex(coord).
 
int coordToIndexY (double coordY) const override
 Convenience method, equivalent to yAxis().coordToIndex(coord).
 
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.
 
bool add (const AIDA::IHistogram2D &h) override
 Modifies this profile by adding the contents of profile to it.
 
bool reset () override
 
void * cast (const std::string &className) const override
 Introspection method.
 
void * cast (const std::string &className) const
 
void * cast (const std::string &className) const
 
const std::string & userLevelClassType () const
 The AIDA user-level unterface leaf class type.
 
int dimension () const override
 Get the Histogram's dimension.
 
std::ostream & print (std::ostream &s) const override
 Print (ASCII) the histogram into the output stream.
 
std::ostream & write (std::ostream &s) const override
 Write (ASCII) the histogram table into the output stream.
 
int write (const char *file_name) const override
 Write (ASCII) the histogram table into a file.
 
- Public Member Functions inherited from Gaudi::HistogramBase
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)
 

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.
 
Axis m_yAxis
 Y axis member.
 
AIDA::Annotation m_annotation
 Object annotations.
 
std::unique_ptr< TH2D > m_rep
 Reference to underlying implementation.
 
std::string m_classType
 class type
 
int m_sumEntries
 cache sumEntries (allEntries) when setting contents since Root can't compute by himself
 

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
 

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
 

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

140 : Base( new TH2D() ) {
141 m_rep->Sumw2();
142 m_sumwx = m_sumwy = 0;
143 setTitle( "" );
144 m_rep->SetDirectory( nullptr );
145}
Generic2D< AIDA::IHistogram2D, TH2D > Base
Definition Generic2D.h:47
bool setTitle(const std::string &title) override
Definition Generic2D.h:169
double m_sumwx
Definition H2D.h:58
double m_sumwy
Definition H2D.h:59

◆ Histogram2D() [2/2]

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

Standard initializing Constructor with TH2D representation to be adopted.

Definition at line 147 of file H2D.cpp.

147 {
148 adoptRepresentation( rep );
149 m_sumwx = m_sumwy = 0;
150 m_rep->SetDirectory( nullptr );
151}

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(); }
static const CLID & classID()
Definition H2D.h:54

◆ copyFromAida()

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

Create new histogram from any AIDA based histogram.

Definition at line 201 of file H2D.cpp.

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

◆ fill()

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

Fill the Histogram2D with a value and the.

Definition at line 172 of file H2D.cpp.

172 {
173 // avoid race conditiosn when filling the histogram
174 auto guard = std::scoped_lock{ m_fillSerialization };
175 m_rep->Fill( x, y, weight );
176 return true;
177}
std::mutex m_fillSerialization
Definition H2D.h:62

◆ reset()

bool Gaudi::Histogram2D::reset ( )
override

Definition at line 166 of file H2D.cpp.

166 {
167 m_sumwx = 0;
168 m_sumwy = 0;
169 return Base::reset();
170}

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

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

◆ setRms()

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

Sets the rms of the histogram.

Definition at line 179 of file H2D.cpp.

179 {
180 m_rep->SetEntries( m_sumEntries );
181 std::vector<double> stat( 11 );
182 stat[0] = sumBinHeights();
183 stat[1] = 0;
184 if ( std::abs( equivalentBinEntries() ) > std::numeric_limits<double>::epsilon() )
185 stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries();
186 stat[2] = m_sumwx;
187 stat[4] = m_sumwy;
188 double meanX = 0;
189 double meanY = 0;
190 if ( std::abs( sumBinHeights() ) > std::numeric_limits<double>::epsilon() ) {
193 }
194 stat[3] = ( meanX * meanX + rmsX * rmsX ) * sumBinHeights();
195 stat[5] = ( meanY * meanY + rmsY * rmsY ) * sumBinHeights();
196 stat[6] = 0;
197 m_rep->PutStats( &stat.front() );
198 return true;
199}
virtual double equivalentBinEntries() const
Definition Generic2D.h:313

Friends And Related Symbol 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: