The Gaudi Framework  v36r10 (fc05264c)
Gaudi::Histogram3D Class Reference

#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. More...
 
 Histogram3D (TH3D *rep)
 Standard Constructor. More...
 
bool fill (double x, double y, double z, double weight) override
 Fill bin content. More...
 
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. More...
 
virtual bool setRms (double rmsX, double rmsY, double rmsZ)
 Sets the rms of the histogram. More...
 
bool reset () override
 
nlohmann::json toJSON () const
 dumps Histogram to json data More...
 
void * cast (const std::string &className) const override
 Introspection method. More...
 
void copyFromAida (const AIDA::IHistogram3D &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::Generic3D< AIDA::IHistogram3D, TH3D >
 Generic3D ()=default
 Default constructor. More...
 
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...
 
int dimension () const override
 Get the Histogram's dimension. 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)
 Sets 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...
 
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...
 
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...
 
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. More...
 
double binMeanY (int, int indexY, int) const override
 The weighted mean along the y axis of a given bin. More...
 
double binMeanZ (int, int, int indexZ) const override
 The weighted mean along the z axis of a given bin. More...
 
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). More...
 
int binEntriesX (int index) const override
 Sum of all the entries of the bins along a given x bin. More...
 
int binEntriesY (int index) const override
 Sum of all the entries of the bins along a given y bin. More...
 
int binEntriesZ (int index) const override
 Sum of all the entries of the bins along a given z bin. More...
 
double binHeight (int indexX, int indexY, int indexZ) const
 Total height of the corresponding bin (ie the sum of the weights in this bin). More...
 
double binHeightX (int index) const override
 Sum of all the heights of the bins along a given x bin. More...
 
double binHeightY (int index) const override
 Sum of all the heights of the bins along a given y bin. More...
 
double binHeightZ (int index) const override
 Sum of all the heights of the bins along a given z bin. More...
 
double binError (int indexX, int indexY, int indexZ) const override
 The error of a given bin. More...
 
double meanX () const override
 The mean of the IHistogram3D along the x axis. More...
 
double meanY () const override
 The mean of the IHistogram3D along the y axis. More...
 
double meanZ () const override
 The mean of the IHistogram3D along the z axis. More...
 
double rmsX () const override
 The RMS of the IHistogram3D along the x axis. More...
 
double rmsY () const override
 The RMS of the IHistogram3D along the y axis. More...
 
double rmsZ () const override
 The RMS of the IHistogram3D along the z axis. More...
 
const AIDA::IAxis & xAxis () const override
 Get the x axis of the IHistogram3D. More...
 
const AIDA::IAxis & yAxis () const override
 Get the y axis of the IHistogram3D. More...
 
const AIDA::IAxis & zAxis () const override
 Get the z axis of the IHistogram3D. More...
 
int coordToIndexX (double coord) const override
 Get the bin number corresponding to a given coordinate along the x axis. More...
 
int coordToIndexY (double coord) const override
 Get the bin number corresponding to a given coordinate along the y axis. More...
 
int coordToIndexZ (double coord) const override
 Get the bin number corresponding to a given coordinate along the z axis. More...
 
double equivalentBinEntries () const override
 Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ] More...
 
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. More...
 
bool add (const AIDA::IHistogram3D &hist) override
 Add to this Histogram3D the contents of another IHistogram3D. More...
 
int extraEntries () const override
 
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
 
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. More...
 
std::unique_ptr< TH3D > m_rep
 Reference to underlying implementation. More...
 
std::string m_classType
 
int m_sumEntries
 

Private Attributes

std::mutex m_fillSerialization
 

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 More...
 

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 79 of file H3D.cpp.

79  : Base( new TH3D() ) {
80  setTitle( "" );
81  m_rep->Sumw2();
82  m_sumwx = 0;
83  m_sumwy = 0;
84  m_sumwz = 0;
85  m_rep->SetDirectory( nullptr );
86 }

◆ Histogram3D() [2/2]

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

Standard Constructor.

Definition at line 88 of file H3D.cpp.

88  {
89  adoptRepresentation( rep );
90  m_sumwx = 0;
91  m_sumwy = 0;
92  m_sumwz = 0;
93  m_rep->SetDirectory( nullptr );
94 }

Member Function Documentation

◆ cast()

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

Introspection method.

Definition at line 129 of file H3D.cpp.

129  {
130  if ( className == "AIDA::IHistogram3D" ) {
131  return (AIDA::IHistogram3D*)this;
132  } else if ( className == "AIDA::IHistogram" ) {
133  return (AIDA::IHistogram*)this;
134  }
135  return nullptr;
136 }

◆ classID()

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

Definition at line 53 of file H3D.h.

53 { return CLID_H3D; }

◆ clID()

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

Retrieve reference to class defininition identifier.

Reimplemented from DataObject.

Definition at line 52 of file H3D.h.

52 { return classID(); }

◆ copyFromAida()

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

Create new histogram from any AIDA based histogram.

Definition at line 170 of file H3D.cpp.

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

◆ fill()

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

Fill bin content.

Definition at line 122 of file H3D.cpp.

122  {
123  // avoid race conditiosn when filling the histogram
124  auto guard = std::scoped_lock{ m_fillSerialization };
125  m_rep->Fill( x, y, z, weight );
126  return true;
127 }

◆ reset()

bool Gaudi::Histogram3D::reset ( )
override

Definition at line 111 of file H3D.cpp.

111  {
112  m_sumwx = 0;
113  m_sumwy = 0;
114  m_sumwz = 0;
115  m_sumEntries = 0;
116  m_rep->Reset();
117  return true;
118 }

◆ 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 97 of file H3D.cpp.

98  {
99  m_rep->SetBinContent( rIndexX( i ), rIndexY( j ), rIndexZ( k ), height );
100  m_rep->SetBinError( rIndexX( i ), rIndexY( j ), rIndexZ( k ), error );
101  // accumulate sum bin centers
102  if ( i >= 0 && j >= 0 && k >= 0 ) {
103  m_sumwx += centreX * height;
104  m_sumwy += centreY * height;
105  m_sumwz += centreZ * height;
106  }
108  return true;
109 }

◆ setRms()

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

Sets the rms of the histogram.

Definition at line 144 of file H3D.cpp.

144  {
145  m_rep->SetEntries( m_sumEntries );
146  std::vector<double> stat( 11 );
147  // sum weights
148  stat[0] = sumBinHeights();
149  stat[1] = 0;
150  if ( equivalentBinEntries() != 0 ) stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries();
151  stat[2] = m_sumwx;
152  double meanX = 0;
153  if ( sumBinHeights() != 0 ) meanX = m_sumwx / sumBinHeights();
154  stat[3] = ( meanX * meanX + rmsX * rmsX ) * sumBinHeights();
155  stat[4] = m_sumwy;
156  double meanY = 0;
157  if ( sumBinHeights() != 0 ) meanY = m_sumwy / sumBinHeights();
158  stat[5] = ( meanY * meanY + rmsY * rmsY ) * sumBinHeights();
159  stat[6] = 0;
160  stat[7] = m_sumwz;
161  double meanZ = 0;
162  if ( sumBinHeights() != 0 ) meanZ = m_sumwz / sumBinHeights();
163  stat[8] = ( meanZ * meanZ + rmsZ * rmsZ ) * sumBinHeights();
164  // do not need to use sumwxy sumwxz and sumwyz
165 
166  m_rep->PutStats( &stat.front() );
167  return true;
168 }

◆ toJSON()

nlohmann::json Gaudi::Histogram3D::toJSON ( ) const

dumps Histogram to json data

Definition at line 120 of file H3D.cpp.

120 { return *m_rep.get(); }

Member Data Documentation

◆ m_fillSerialization

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

Definition at line 62 of file H3D.h.

◆ m_sumwx

double Gaudi::Histogram3D::m_sumwx = 0
protected

Definition at line 57 of file H3D.h.

◆ m_sumwy

double Gaudi::Histogram3D::m_sumwy = 0
protected

Definition at line 58 of file H3D.h.

◆ m_sumwz

double Gaudi::Histogram3D::m_sumwz = 0
protected

Definition at line 59 of file H3D.h.


The documentation for this class was generated from the following files:
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::meanX
double meanX() const override
The mean of the IHistogram3D along the x axis.
Definition: Generic3D.h:168
std::string
STL class.
Gaudi::Histogram3D::m_sumwx
double m_sumwx
Definition: H3D.h:57
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::rmsY
double rmsY() const override
The RMS of the IHistogram3D along the y axis.
Definition: Generic3D.h:177
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::m_rep
std::unique_ptr< TH3D > m_rep
Reference to underlying implementation.
Definition: Generic3D.h:230
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::m_zAxis
Gaudi::Axis m_zAxis
Definition: Generic3D.h:226
std::vector< double >
std::string::size
T size(T... args)
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::m_xAxis
Gaudi::Axis m_xAxis
Definition: Generic3D.h:224
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::equivalentBinEntries
double equivalentBinEntries() const override
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
Definition: Generic3D.h:282
Gaudi::Histogram3D::m_sumwz
double m_sumwz
Definition: H3D.h:59
Gaudi::Histogram3D::classID
static const CLID & classID()
Definition: H3D.h:53
std::unique_ptr::get
T get(T... args)
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::m_yAxis
Gaudi::Axis m_yAxis
Definition: Generic3D.h:225
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::zAxis
const AIDA::IAxis & zAxis() const override
Get the z axis of the IHistogram3D.
Definition: Generic3D.h:185
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::meanZ
double meanZ() const override
The mean of the IHistogram3D along the z axis.
Definition: Generic3D.h:173
std::unique_ptr::reset
T reset(T... args)
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::Base
Generic3D< AIDA::IHistogram3D, TH3D > Base
Definition: Generic3D.h:48
std::vector::push_back
T push_back(T... args)
Gaudi::Histogram3D::m_fillSerialization
std::mutex m_fillSerialization
Definition: H3D.h:62
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::rIndexX
int rIndexX(int index) const
Definition: Generic3D.h:92
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::xAxis
const AIDA::IAxis & xAxis() const override
Get the x axis of the IHistogram3D.
Definition: Generic3D.h:181
std::string::c_str
T c_str(T... args)
Gaudi::Axis::initialize
void initialize(TAxis *itaxi, bool)
Definition: Axis.h:63
AlgSequencer.h
h
Definition: AlgSequencer.py:32
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::yAxis
const AIDA::IAxis & yAxis() const override
Get the y axis of the IHistogram3D.
Definition: Generic3D.h:183
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::rIndexY
int rIndexY(int index) const
Definition: Generic3D.h:93
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::rmsX
double rmsX() const override
The RMS of the IHistogram3D along the x axis.
Definition: Generic3D.h:175
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::meanY
double meanY() const override
The mean of the IHistogram3D along the y axis.
Definition: Generic3D.h:171
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::sumBinHeights
double sumBinHeights() const override
Get the sum of in range bin heights in the IProfile.
Definition: Generic3D.h:272
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::rmsZ
double rmsZ() const override
The RMS of the IHistogram3D along the z axis.
Definition: Generic3D.h:179
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::adoptRepresentation
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
Gaudi::Histogram3D::m_sumwy
double m_sumwy
Definition: H3D.h:58
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::entries
int entries() const override
Get the number or all the entries.
Definition: Generic3D.h:252
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::rIndexZ
int rIndexZ(int index) const
Definition: Generic3D.h:94
Gaudi::Edges
std::vector< double > Edges
Definition: GaudiPI.h:28
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::setTitle
bool setTitle(const std::string &title) override
Set the title of the object.
Definition: Generic3D.h:238
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::title
std::string title() const override
Get the title of the object.
Definition: Generic3D.h:65
Gaudi::Generic3D< AIDA::IHistogram3D, TH3D >::m_sumEntries
int m_sumEntries
Definition: Generic3D.h:234