1 #ifndef GAUDISVC_GENERIC3D_H
2 #define GAUDISVC_GENERIC3D_H 1
10 #include "AIDA/IHistogram3D.h"
28 template<
typename INTERFACE,
typename IMPLEMENTATION>
39 virtual void adoptRepresentation(TObject* rep);
44 virtual std::string
title()
const {
return m_annotation.value(
"Title");}
46 virtual bool setTitle(
const std::string & title);
48 virtual std::string
name()
const {
return m_annotation.value(
"Name"); }
50 bool setName(
const std::string& newName);
52 virtual AIDA::IAnnotation &
annotation() {
return m_annotation; }
54 virtual const AIDA::IAnnotation &
annotation()
const {
return m_annotation; }
57 virtual int entries()
const;
59 virtual int allEntries()
const;
61 virtual double sumBinHeights()
const;
63 virtual double sumAllBinHeights()
const;
67 virtual double minBinHeight()
const;
69 virtual double maxBinHeight()
const;
71 int rIndexX(
int index)
const {
return m_xAxis.rIndex(index);}
72 int rIndexY(
int index)
const {
return m_yAxis.rIndex(index);}
73 int rIndexZ(
int index)
const {
return m_zAxis.rIndex(index);}
77 {
return (m_rep->GetXaxis())->GetBinCenter( rIndexX(indexX) ); }
80 {
return (m_rep->GetYaxis())->GetBinCenter( rIndexY(indexY) ); }
83 {
return (m_rep->GetYaxis())->GetBinCenter( rIndexY(indexZ) ); }
86 if (binHeight(indexX, indexY, indexZ)<=0)
return 0;
87 double xx = binHeight(indexX, indexY, indexZ)/binError(indexX, indexY, indexZ);
88 return int(xx*xx+0.5);
93 for (
int i = -2;
i < yAxis().bins(); ++
i)
94 for (
int j = -2; j < zAxis().bins(); ++j)
95 n += binEntries(index,
i,j);
102 for (
int i = -2;
i < xAxis().bins(); ++
i)
103 for (
int j = -2; j < zAxis().bins(); ++j)
104 n += binEntries(
i,index,j);
111 for (
int i = -2;
i < xAxis().bins(); ++
i)
112 for (
int j = -2; j < yAxis().bins(); ++j)
113 n += binEntries(
i,j,index);
118 double binHeight (
int indexX,
int indexY,
int indexZ )
const
119 {
return m_rep->GetBinContent ( rIndexX(indexX), rIndexY(indexY), rIndexZ(indexZ) ); }
124 for (
int i = -2;
i < yAxis().bins(); ++
i)
125 for (
int j = -2; j < zAxis().bins(); ++j)
126 s += binHeight(index,
i,j);
132 for (
int i = -2;
i < xAxis().bins(); ++
i)
133 for (
int j = -2; j < zAxis().bins(); ++j)
134 s += binHeight(
i,index,j);
140 for (
int i = -2;
i < xAxis().bins(); ++
i)
141 for (
int j = -2; j < yAxis().bins(); ++j)
142 s += binHeight(
i,j,index);
146 virtual double binError (
int indexX,
int indexY,
int indexZ )
const
147 {
return m_rep->GetBinError ( rIndexX(indexX), rIndexY(indexY ), rIndexZ(indexZ ) ); }
149 virtual double meanX ( )
const {
return m_rep->GetMean ( 1); }
152 virtual double meanY ( )
const {
return m_rep->GetMean ( 2 ); }
154 virtual double meanZ ( )
const {
return m_rep->GetMean ( 3 ); }
156 virtual double rmsX ( )
const {
return m_rep->GetRMS( 1 ); }
158 virtual double rmsY ( )
const {
return m_rep->GetRMS( 2 ); }
160 virtual double rmsZ ( )
const {
return m_rep->GetRMS( 3 ); }
162 virtual const AIDA::IAxis &
xAxis ( )
const {
return m_xAxis; }
164 virtual const AIDA::IAxis &
yAxis ( )
const {
return m_yAxis; }
166 virtual const AIDA::IAxis &
zAxis ( )
const {
return m_zAxis; }
168 virtual int coordToIndexX (
double coord )
const {
return xAxis().coordToIndex(coord);}
170 virtual int coordToIndexY (
double coord )
const {
return yAxis().coordToIndex(coord);}
172 virtual int coordToIndexZ (
double coord )
const {
return zAxis().coordToIndex(coord);}
175 virtual double equivalentBinEntries ( )
const;
177 virtual bool scale(
double scaleFactor );
179 virtual bool add (
const INTERFACE & hist ) {
180 const Base* p =
dynamic_cast<const Base*
>(&hist);
182 m_rep->Add(p->
m_rep);
185 throw std::runtime_error(
"Cannot add profile histograms of different implementations.");
191 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
192 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
193 binEntries(AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
194 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
195 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
196 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
197 binEntries(AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN);
200 virtual std::ostream& print( std::ostream&
s )
const;
202 virtual std::ostream& write( std::ostream&
s )
const;
204 virtual int write(
const char* file_name )
const;
220 template <
class INTERFACE,
class IMPLEMENTATION>
222 m_rep->SetTitle(title.c_str());
223 if ( !annotation().addItem(
"Title", title ) )
224 m_annotation.setValue(
"Title" , title );
225 if ( !annotation().addItem(
"title", title ) )
226 annotation().setValue(
"title", title );
230 template <
class INTERFACE,
class IMPLEMENTATION>
232 m_rep->SetName(newName.c_str());
233 m_annotation.setValue(
"Name", newName );
236 template <
class INTERFACE,
class IMPLEMENTATION>
238 return (
int)m_rep->GetEntries();
241 template <
class INTERFACE,
class IMPLEMENTATION>
243 return int(m_rep->GetEntries());
246 template <
class INTERFACE,
class IMPLEMENTATION>
248 return m_rep->GetMinimum();
251 template <
class INTERFACE,
class IMPLEMENTATION>
253 return m_rep->GetMaximum();
256 template <
class INTERFACE,
class IMPLEMENTATION>
258 return m_rep->GetSumOfWeights();
261 template <
class INTERFACE,
class IMPLEMENTATION>
263 return m_rep->GetSum();
266 template <
class INTERFACE,
class IMPLEMENTATION>
268 if (sumBinHeights() <= 0)
return 0;
270 m_rep->GetStats(stats);
271 return stats[0]*stats[0]/stats[1];
274 template <
class INTERFACE,
class IMPLEMENTATION>
276 m_rep->Scale ( scaleFactor );
280 template <
class INTERFACE,
class IMPLEMENTATION>
290 template <
class INTERFACE,
class IMPLEMENTATION>
293 s <<
"\n3D Histogram Table: " << std::endl;
294 s <<
"BinX, BinY, BinZ, Height, Error " << std::endl;
295 for (
int i = 0;
i < xAxis().bins(); ++
i )
296 for (
int j = 0; j < yAxis().bins(); ++j )
297 for (
int k = 0; k < zAxis().bins(); ++k )
298 s << binMeanX(
i, j, k ) <<
", "
299 << binMeanY(
i, j, k ) <<
", "
300 << binMeanZ(
i, j, k ) <<
", "
301 << binHeight(
i, j, k ) <<
", "
302 << binError (
i, j, k ) << std::endl;
308 template <
class INTERFACE,
class IMPLEMENTATION>
311 TFile *f = TFile::Open(file_name,
"RECREATE");
312 Int_t nbytes = m_rep->Write();
317 #endif // GAUDIPI_GENERIC3D_H
virtual double minBinHeight() const
Get the minimum height of the in-range bins.
int rIndexZ(int index) const
int rIndexX(int index) const
virtual double binHeightY(int index) const
Sum of all the heights of the bins along a given y bin.
virtual int allEntries() const
Get the number or all the entries, both in range and underflow/overflow bins of the IProfile...
virtual double sumBinHeights() const
Get the sum of in range bin heights in the IProfile.
int binEntries(int indexX, int indexY, int indexZ) const
Number of entries in the corresponding bin (ie the number of times fill was calle d for this bin)...
double binMeanX(int indexX, int, int) const
The weighted mean along the x axis of a given bin.
virtual double rmsY() const
The RMS of the IHistogram3D along the y axis.
virtual int coordToIndexY(double coord) const
Get the bin number corresponding to a given coordinate along the y axis.
double binMeanZ(int, int, int indexZ) const
The weighted mean along the z axis of a given bin.
virtual std::ostream & print(std::ostream &s) const
Print (ASCII) the histogram into the output stream.
virtual double rmsZ() const
The RMS of the IHistogram3D along the z axis.
virtual int entries() const
Get the number or all the entries.
virtual double binHeightZ(int index) const
Sum of all the heights of the bins along a given z bin.
virtual int coordToIndexZ(double coord) const
Get the bin number corresponding to a given coordinate along the z axis.
IMPLEMENTATION * m_rep
Reference to underlying implementation.
virtual double sumExtraBinHeights() const
Get the sum of the underflow and overflow bin height.
virtual double meanZ() const
The mean of the IHistogram3D along the z axis.
virtual double binHeightX(int index) const
Sum of all the heights of the bins along a given x bin.
virtual const AIDA::IAxis & zAxis() const
Get the z axis of the IHistogram3D.
virtual ~Generic3D()
Destructor.
virtual double meanY() const
The mean of the IHistogram3D along the y axis.
virtual AIDA::IAnnotation & annotation()
Access annotation object.
virtual std::string name() const
object name
double binMeanY(int, int indexY, int) const
The weighted mean along the y axis of a given bin.
Implementation of the AIDA IAnnotation interface class.
bool setName(const std::string &newName)
Sets the name of the object.
int rIndexY(int index) const
Generic3D< INTERFACE, IMPLEMENTATION > Base
virtual bool add(const INTERFACE &hist)
Add to this Histogram3D the contents of another IHistogram3D.
double binHeight(int indexX, int indexY, int indexZ) const
Total height of the corresponding bin (ie the sum of the weights in this bin).
virtual std::string title() const
Get the title of the object.
virtual int binEntriesX(int index) const
Sum of all the entries of the bins along a given x bin.
virtual double equivalentBinEntries() const
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
Common base class for all histograms Use is solely functional to minimize dynamic_casts inside Histog...
AIDA::Annotation m_annotation
Object annotations.
virtual double binError(int indexX, int indexY, int indexZ) const
The error of a given bin.
virtual const AIDA::IAxis & xAxis() const
Get the x axis of the IHistogram3D.
virtual double rmsX() const
The RMS of the IHistogram3D along the x axis.
TObject * representation() const
ROOT object implementation.
virtual const AIDA::IAnnotation & annotation() const
Access annotation object (cons)
virtual int coordToIndexX(double coord) const
Get the bin number corresponding to a given coordinate along the x axis.
This is a number of static methods for bootstrapping the Gaudi framework.
Generic3D()
Default constructor.
virtual bool setTitle(const std::string &title)
Set the title of the object.
virtual int binEntriesZ(int index) const
Sum of all the entries of the bins along a given z bin.
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 g...
virtual double sumAllBinHeights() const
Get the sum of all the bins heights (including underflow and overflow bin).
virtual int dimension() const
Get the Histogram's dimension.
An IAxis represents a binned histogram axis.
virtual const AIDA::IAxis & yAxis() const
Get the y axis of the IHistogram3D.
virtual double maxBinHeight() const
Get the maximum height of the in-range bins.
virtual int binEntriesY(int index) const
Sum of all the entries of the bins along a given y bin.
virtual double meanX() const
The mean of the IHistogram3D along the x axis.
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
virtual std::ostream & write(std::ostream &s) const
Write (ASCII) the histogram table into the output stream.