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

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

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

Inheritance diagram for Gaudi::Histogram3D:
Collaboration diagram for Gaudi::Histogram3D:

Public Member Functions

 Histogram3D ()
 Standard Constructor.
 
 Histogram3D (TH3D *rep)
 Standard Constructor.
 
bool fill (double x, double y, double z, double weight) override
 Fill bin content.
 
virtual bool setBinContents (int i, int j, int k, int entries, double height, double error, double centreX, double centreY, double centreZ)
 Fast filling method for a given bin. It can be also the over/underflow bin.
 
virtual bool setRms (double rmsX, double rmsY, double rmsZ)
 Sets the rms of the histogram.
 
bool reset () override
 
void * cast (const std::string &className) const override
 Introspection method.
 
void copyFromAida (const AIDA::IHistogram3D &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::Generic3D< AIDA::IHistogram3D, TH3D >
void adoptRepresentation (TObject *rep)
 Adopt ROOT histogram representation.
 
 Generic3D ()=default
 Default constructor.
 
TObject * representation () const override
 ROOT object implementation.
 
void adoptRepresentation (TObject *rep) override
 Adopt ROOT histogram representation.
 
void adoptRepresentation (TObject *rep)
 Adopt ROOT histogram representation.
 
int dimension () const override
 Get the Histogram's dimension.
 
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)
 Sets the name of the object.
 
AIDA::IAnnotation & annotation () override
 Access annotation object.
 
const AIDA::IAnnotation & annotation () const override
 Access annotation object (cons)
 
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.
 
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.
 
int rIndexX (int index) const
 
int rIndexY (int index) const
 
int rIndexZ (int index) const
 
double binMeanX (int indexX, int, int) const override
 The weighted mean along the x axis of a given bin.
 
double binMeanY (int, int indexY, int) const override
 The weighted mean along the y axis of a given bin.
 
double binMeanZ (int, int, int indexZ) const override
 The weighted mean along the z axis of a given bin.
 
int binEntries (int indexX, int indexY, int indexZ) const override
 Number of entries in the corresponding bin (ie the number of times fill was calle d for this bin).
 
int binEntriesX (int index) const override
 Sum of all the entries of the bins along a given x bin.
 
int binEntriesY (int index) const override
 Sum of all the entries of the bins along a given y bin.
 
int binEntriesZ (int index) const override
 Sum of all the entries of the bins along a given z bin.
 
double binHeight (int indexX, int indexY, int indexZ) const
 Total height of the corresponding bin (ie the sum of the weights in this bin).
 
double binHeightX (int index) const override
 Sum of all the heights of the bins along a given x bin.
 
double binHeightY (int index) const override
 Sum of all the heights of the bins along a given y bin.
 
double binHeightZ (int index) const override
 Sum of all the heights of the bins along a given z bin.
 
double binError (int indexX, int indexY, int indexZ) const override
 The error of a given bin.
 
double meanX () const override
 The mean of the IHistogram3D along the x axis.
 
double meanY () const override
 The mean of the IHistogram3D along the y axis.
 
double meanZ () const override
 The mean of the IHistogram3D along the z axis.
 
double rmsX () const override
 The RMS of the IHistogram3D along the x axis.
 
double rmsY () const override
 The RMS of the IHistogram3D along the y axis.
 
double rmsZ () const override
 The RMS of the IHistogram3D along the z axis.
 
const AIDA::IAxis & xAxis () const override
 Get the x axis of the IHistogram3D.
 
const AIDA::IAxis & yAxis () const override
 Get the y axis of the IHistogram3D.
 
const AIDA::IAxis & zAxis () const override
 Get the z axis of the IHistogram3D.
 
int coordToIndexX (double coord) const override
 Get the bin number corresponding to a given coordinate along the x axis.
 
int coordToIndexY (double coord) const override
 Get the bin number corresponding to a given coordinate along the y axis.
 
int coordToIndexZ (double coord) const override
 Get the bin number corresponding to a given coordinate along the z axis.
 
double equivalentBinEntries () const override
 Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
 
bool scale (double scaleFactor) override
 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::IHistogram3D &hist) override
 Add to this Histogram3D the contents of another IHistogram3D.
 
int extraEntries () const override
 
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
 
double m_sumwz = 0
 
- Protected Attributes inherited from Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >
Gaudi::Axis m_xAxis
 
Gaudi::Axis m_yAxis
 
Gaudi::Axis m_zAxis
 
AIDA::Annotation m_annotation
 Object annotations.
 
std::unique_ptr< TH3D > m_rep
 Reference to underlying implementation.
 
std::string m_classType
 
int m_sumEntries
 

Private Attributes

std::mutex m_fillSerialization
 

Friends

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

Additional Inherited Members

- Public Types inherited from Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >
typedef Generic3D< AIDA::IHistogram3D, TH3D > Base
 
- Protected Member Functions inherited from Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >
 Generic3D (TH3D *p)
 constructor
 

Detailed Description

AIDA implementation for 3 D histograms using ROOT THD2.

Author
M.Frank

Definition at line 29 of file H3D.h.

Constructor & Destructor Documentation

◆ Histogram3D() [1/2]

Gaudi::Histogram3D::Histogram3D ( )

Standard Constructor.

Definition at line 73 of file H3D.cpp.

73 : Base( new TH3D() ) {
74 setTitle( "" );
75 m_rep->Sumw2();
76 m_sumwx = 0;
77 m_sumwy = 0;
78 m_sumwz = 0;
79 m_rep->SetDirectory( nullptr );
80}
Generic3D< AIDA::IHistogram3D, TH3D > Base
Definition Generic3D.h:47
bool setTitle(const std::string &title) override
Definition Generic3D.h:237
double m_sumwy
Definition H3D.h:60
double m_sumwz
Definition H3D.h:61
double m_sumwx
Definition H3D.h:59

◆ Histogram3D() [2/2]

Gaudi::Histogram3D::Histogram3D ( TH3D * rep)

Standard Constructor.

Definition at line 82 of file H3D.cpp.

82 {
84 m_sumwx = 0;
85 m_sumwy = 0;
86 m_sumwz = 0;
87 m_rep->SetDirectory( nullptr );
88}

Member Function Documentation

◆ cast()

void * Gaudi::Histogram3D::cast ( const std::string & className) const
override

Introspection method.

Definition at line 121 of file H3D.cpp.

121 {
122 if ( className == "AIDA::IHistogram3D" ) {
123 return (AIDA::IHistogram3D*)this;
124 } else if ( className == "AIDA::IHistogram" ) {
125 return (AIDA::IHistogram*)this;
126 }
127 return nullptr;
128}

◆ classID()

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

Definition at line 55 of file H3D.h.

55{ return CLID_H3D; }

◆ clID()

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

Retrieve reference to class defininition identifier.

Reimplemented from DataObject.

Definition at line 54 of file H3D.h.

54{ return classID(); }
static const CLID & classID()
Definition H3D.h:55

◆ copyFromAida()

void Gaudi::Histogram3D::copyFromAida ( const AIDA::IHistogram3D & h)

Create new histogram from any AIDA based histogram.

Definition at line 158 of file H3D.cpp.

158 {
159 // implement here the copy
160 std::string titlestr = h.title();
161 const char* title = titlestr.c_str();
162 if ( h.xAxis().isFixedBinning() && h.yAxis().isFixedBinning() && h.zAxis().isFixedBinning() ) {
163 m_rep = std::make_unique<TH3D>( title, title, h.xAxis().bins(), h.xAxis().lowerEdge(), h.xAxis().upperEdge(),
164 h.yAxis().bins(), h.yAxis().lowerEdge(), h.yAxis().upperEdge(), h.zAxis().bins(),
165 h.zAxis().lowerEdge(), h.zAxis().upperEdge() );
166 } else {
167 Edges eX, eY, eZ;
168 for ( int i = 0; i < h.xAxis().bins(); ++i ) eX.push_back( h.xAxis().binLowerEdge( i ) );
169 // add also upperedges at the end
170 eX.push_back( h.xAxis().upperEdge() );
171 for ( int i = 0; i < h.yAxis().bins(); ++i ) eY.push_back( h.yAxis().binLowerEdge( i ) );
172 // add also upperedges at the end
173 eY.push_back( h.yAxis().upperEdge() );
174 for ( int i = 0; i < h.zAxis().bins(); ++i ) eZ.push_back( h.zAxis().binLowerEdge( i ) );
175 // add also upperedges at the end
176 eZ.push_back( h.zAxis().upperEdge() );
177 m_rep.reset(
178 new TH3D( title, title, eX.size() - 1, &eX.front(), eY.size() - 1, &eY.front(), eZ.size() - 1, &eZ.front() ) );
179 }
180 m_xAxis.initialize( m_rep->GetXaxis(), true );
181 m_yAxis.initialize( m_rep->GetYaxis(), true );
182 m_zAxis.initialize( m_rep->GetZaxis(), true );
183 const TArrayD* a = m_rep->GetSumw2();
184 if ( !a || ( a && a->GetSize() == 0 ) ) m_rep->Sumw2();
185 m_sumEntries = 0;
186 m_sumwx = 0;
187 m_sumwy = 0;
188 m_sumwz = 0;
189
190 // statistics
191 double sumw = h.sumBinHeights();
192 double sumw2 = 0;
193 if ( std::abs( h.equivalentBinEntries() ) > std::numeric_limits<double>::epsilon() )
194 sumw2 = ( sumw * sumw ) / h.equivalentBinEntries();
195 double sumwx = h.meanX() * h.sumBinHeights();
196 double sumwx2 = ( h.meanX() * h.meanX() + h.rmsX() * h.rmsX() ) * h.sumBinHeights();
197 double sumwy = h.meanY() * h.sumBinHeights();
198 double sumwy2 = ( h.meanY() * h.meanY() + h.rmsY() * h.rmsY() ) * h.sumBinHeights();
199 double sumwz = h.meanZ() * h.sumBinHeights();
200 double sumwz2 = ( h.meanZ() * h.meanZ() + h.rmsZ() * h.rmsZ() ) * h.sumBinHeights();
201 double sumwxy = 0;
202 double sumwxz = 0;
203 double sumwyz = 0;
204
205 // copy the contents in (AIDA underflow/overflow are -2,-1)
206 for ( int i = -2; i < xAxis().bins(); ++i ) {
207 for ( int j = -2; j < yAxis().bins(); ++j ) {
208 for ( int k = -2; k < zAxis().bins(); ++k ) {
209 m_rep->SetBinContent( rIndexX( i ), rIndexY( j ), rIndexZ( k ), h.binHeight( i, j, k ) );
210 m_rep->SetBinError( rIndexX( i ), rIndexY( j ), rIndexZ( k ), h.binError( i, j, k ) );
211 // calculate statistics
212 if ( i >= 0 && j >= 0 && k >= 0 ) {
213 sumwxy += h.binHeight( i, j, k ) * h.binMeanX( i, j, k ) * h.binMeanY( i, j, k );
214 sumwxz += h.binHeight( i, j, k ) * h.binMeanX( i, j, k ) * h.binMeanZ( i, j, k );
215 sumwyz += h.binHeight( i, j, k ) * h.binMeanY( i, j, k ) * h.binMeanZ( i, j, k );
216 }
217 }
218 }
219 }
220 // need to do set entries after setting contents otherwise root will recalulate them
221 // taking into account how many time SetBinContents() has been called
222 m_rep->SetEntries( h.allEntries() );
223
224 // fill stat vector
225 std::vector<double> stat( 11 );
226 stat[0] = sumw;
227 stat[1] = sumw2;
228 stat[2] = sumwx;
229 stat[3] = sumwx2;
230 stat[4] = sumwy;
231 stat[5] = sumwy2;
232 stat[6] = sumwxy;
233 stat[7] = sumwz;
234 stat[8] = sumwz2;
235 stat[9] = sumwxz;
236 stat[10] = sumwyz;
237 m_rep->PutStats( &stat.front() );
238}
const AIDA::IAxis & zAxis() const override
Definition Generic3D.h:184
std::string title() const override
Definition Generic3D.h:64
const AIDA::IAxis & yAxis() const override
Definition Generic3D.h:182
const AIDA::IAxis & xAxis() const override
Definition Generic3D.h:180
Gaudi::ParticleID abs(const Gaudi::ParticleID &p)
Return the absolute value for a PID.
Definition ParticleID.h:191

◆ fill()

bool Gaudi::Histogram3D::fill ( double x,
double y,
double z,
double weight )
override

Fill bin content.

Definition at line 114 of file H3D.cpp.

114 {
115 // avoid race conditiosn when filling the histogram
116 auto guard = std::scoped_lock{ m_fillSerialization };
117 m_rep->Fill( x, y, z, weight );
118 return true;
119}
std::mutex m_fillSerialization
Definition H3D.h:64

◆ reset()

bool Gaudi::Histogram3D::reset ( )
override

Definition at line 105 of file H3D.cpp.

105 {
106 m_sumwx = 0;
107 m_sumwy = 0;
108 m_sumwz = 0;
109 m_sumEntries = 0;
110 m_rep->Reset();
111 return true;
112}

◆ setBinContents()

bool Gaudi::Histogram3D::setBinContents ( int i,
int j,
int k,
int entries,
double height,
double error,
double centreX,
double centreY,
double centreZ )
virtual

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

Definition at line 91 of file H3D.cpp.

92 {
93 m_rep->SetBinContent( rIndexX( i ), rIndexY( j ), rIndexZ( k ), height );
94 m_rep->SetBinError( rIndexX( i ), rIndexY( j ), rIndexZ( k ), error );
95 // accumulate sum bin centers
96 if ( i >= 0 && j >= 0 && k >= 0 ) {
97 m_sumwx += centreX * height;
98 m_sumwy += centreY * height;
99 m_sumwz += centreZ * height;
100 }
102 return true;
103}

◆ setRms()

bool Gaudi::Histogram3D::setRms ( double rmsX,
double rmsY,
double rmsZ )
virtual

Sets the rms of the histogram.

Definition at line 130 of file H3D.cpp.

130 {
131 m_rep->SetEntries( m_sumEntries );
132 std::vector<double> stat( 11 );
133 // sum weights
134 stat[0] = sumBinHeights();
135 stat[1] = 0;
136 if ( std::abs( equivalentBinEntries() ) > std::numeric_limits<double>::epsilon() )
137 stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries();
138 stat[2] = m_sumwx;
139 stat[4] = m_sumwy;
140 stat[6] = 0;
141 stat[7] = m_sumwz;
142 double meanX = 0;
143 double meanY = 0;
144 double meanZ = 0;
145 if ( std::abs( sumBinHeights() ) > std::numeric_limits<double>::epsilon() ) {
149 }
150 stat[3] = ( meanX * meanX + rmsX * rmsX ) * sumBinHeights();
151 stat[5] = ( meanY * meanY + rmsY * rmsY ) * sumBinHeights();
152 stat[8] = ( meanZ * meanZ + rmsZ * rmsZ ) * sumBinHeights();
153 // do not need to use sumwxy sumwxz and sumwyz
154 m_rep->PutStats( &stat.front() );
155 return true;
156}
double equivalentBinEntries() const override
Definition Generic3D.h:281

Friends And Related Symbol Documentation

◆ reset

void reset ( Histogram3D & h)
friend

Definition at line 46 of file H3D.h.

46{ h.reset(); }

◆ to_json

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

conversion to json via nlohmann library

Definition at line 48 of file H3D.h.

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

Member Data Documentation

◆ m_fillSerialization

std::mutex Gaudi::Histogram3D::m_fillSerialization
private

Definition at line 64 of file H3D.h.

◆ m_sumwx

double Gaudi::Histogram3D::m_sumwx = 0
protected

Definition at line 59 of file H3D.h.

◆ m_sumwy

double Gaudi::Histogram3D::m_sumwy = 0
protected

Definition at line 60 of file H3D.h.

◆ m_sumwz

double Gaudi::Histogram3D::m_sumwz = 0
protected

Definition at line 61 of file H3D.h.


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