1 #ifndef GAUDISVC_GENERIC3D_H
2 #define GAUDISVC_GENERIC3D_H 1
9 #include "GaudiKernel/HistogramBase.h"
10 #include "AIDA/IHistogram3D.h"
29 template<
typename INTERFACE,
typename IMPLEMENTATION>
44 void adoptRepresentation(TObject* rep)
override;
49 std::string
title()
const override {
return m_annotation.value(
"Title");}
51 bool setTitle(
const std::string & title)
override;
53 std::string
name()
const {
return m_annotation.value(
"Name"); }
55 bool setName(
const std::string& newName);
57 AIDA::IAnnotation &
annotation()
override {
return m_annotation; }
59 const AIDA::IAnnotation &
annotation()
const override {
return m_annotation; }
62 int entries()
const override;
64 int allEntries()
const override;
66 double sumBinHeights()
const override;
68 double sumAllBinHeights()
const override;
72 double minBinHeight()
const override;
74 double maxBinHeight()
const override;
76 int rIndexX(
int index)
const {
return m_xAxis.rIndex(index);}
77 int rIndexY(
int index)
const {
return m_yAxis.rIndex(index);}
78 int rIndexZ(
int index)
const {
return m_zAxis.rIndex(index);}
82 {
return m_rep->GetXaxis()->GetBinCenter( rIndexX(indexX) ); }
85 {
return m_rep->GetYaxis()->GetBinCenter( rIndexY(indexY) ); }
88 {
return m_rep->GetYaxis()->GetBinCenter( rIndexY(indexZ) ); }
91 if (binHeight(indexX, indexY, indexZ)<=0)
return 0;
92 double xx = binHeight(indexX, indexY, indexZ)/binError(indexX, indexY, indexZ);
93 return int(xx*xx+0.5);
98 for (
int i = -2;
i < yAxis().bins(); ++
i)
99 for (
int j = -2; j < zAxis().bins(); ++j)
100 n += binEntries(index,
i,j);
107 for (
int i = -2;
i < xAxis().bins(); ++
i)
108 for (
int j = -2; j < zAxis().bins(); ++j)
109 n += binEntries(
i,index,j);
116 for (
int i = -2;
i < xAxis().bins(); ++
i)
117 for (
int j = -2; j < yAxis().bins(); ++j)
118 n += binEntries(
i,j,index);
123 double binHeight (
int indexX,
int indexY,
int indexZ )
const
124 {
return m_rep->GetBinContent ( rIndexX(indexX), rIndexY(indexY), rIndexZ(indexZ) ); }
129 for (
int i = -2;
i < yAxis().bins(); ++
i)
130 for (
int j = -2; j < zAxis().bins(); ++j)
131 s += binHeight(index,
i,j);
137 for (
int i = -2;
i < xAxis().bins(); ++
i)
138 for (
int j = -2; j < zAxis().bins(); ++j)
139 s += binHeight(
i,index,j);
145 for (
int i = -2;
i < xAxis().bins(); ++
i)
146 for (
int j = -2; j < yAxis().bins(); ++j)
147 s += binHeight(
i,j,index);
151 double binError (
int indexX,
int indexY,
int indexZ )
const override
152 {
return m_rep->GetBinError ( rIndexX(indexX), rIndexY(indexY ), rIndexZ(indexZ ) ); }
154 double meanX ( )
const override {
return m_rep->GetMean ( 1); }
157 double meanY ( )
const override {
return m_rep->GetMean ( 2 ); }
159 double meanZ ( )
const override {
return m_rep->GetMean ( 3 ); }
161 double rmsX ( )
const override {
return m_rep->GetRMS( 1 ); }
163 double rmsY ( )
const override {
return m_rep->GetRMS( 2 ); }
165 double rmsZ ( )
const override {
return m_rep->GetRMS( 3 ); }
167 const AIDA::IAxis &
xAxis ( )
const override {
return m_xAxis; }
169 const AIDA::IAxis &
yAxis ( )
const override {
return m_yAxis; }
171 const AIDA::IAxis &
zAxis ( )
const override {
return m_zAxis; }
173 int coordToIndexX (
double coord )
const override {
return xAxis().coordToIndex(coord);}
175 int coordToIndexY (
double coord )
const override {
return yAxis().coordToIndex(coord);}
177 int coordToIndexZ (
double coord )
const override {
return zAxis().coordToIndex(coord);}
180 double equivalentBinEntries ( )
const override;
182 bool scale(
double scaleFactor )
override;
184 bool add (
const INTERFACE & hist )
override {
185 const Base* p =
dynamic_cast<const Base*
>(&hist);
186 if ( !p )
throw std::runtime_error(
"Cannot add profile histograms of different implementations.");
187 m_rep->Add(p->
m_rep.get());
194 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
195 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
196 binEntries(AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
197 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
198 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
199 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
200 binEntries(AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN);
203 std::ostream& print( std::ostream&
s )
const override;
205 std::ostream& write( std::ostream&
s )
const override;
207 int write(
const char* file_name )
const override;
216 std::unique_ptr<IMPLEMENTATION>
m_rep;
220 int m_sumEntries = 0;
223 template <
class INTERFACE,
class IMPLEMENTATION>
225 m_rep->SetTitle(title.c_str());
226 if ( !annotation().addItem(
"Title", title ) )
227 m_annotation.setValue(
"Title" , title );
228 if ( !annotation().addItem(
"title", title ) )
229 annotation().setValue(
"title", title );
233 template <
class INTERFACE,
class IMPLEMENTATION>
235 m_rep->SetName(newName.c_str());
236 m_annotation.setValue(
"Name", newName );
239 template <
class INTERFACE,
class IMPLEMENTATION>
241 return m_rep->GetEntries();
244 template <
class INTERFACE,
class IMPLEMENTATION>
246 return int(m_rep->GetEntries());
249 template <
class INTERFACE,
class IMPLEMENTATION>
251 return m_rep->GetMinimum();
254 template <
class INTERFACE,
class IMPLEMENTATION>
256 return m_rep->GetMaximum();
259 template <
class INTERFACE,
class IMPLEMENTATION>
261 return m_rep->GetSumOfWeights();
264 template <
class INTERFACE,
class IMPLEMENTATION>
266 return m_rep->GetSum();
269 template <
class INTERFACE,
class IMPLEMENTATION>
271 if (sumBinHeights() <= 0)
return 0;
273 m_rep->GetStats(stats);
274 return stats[0]*stats[0]/stats[1];
277 template <
class INTERFACE,
class IMPLEMENTATION>
279 m_rep->Scale ( scaleFactor );
283 template <
class INTERFACE,
class IMPLEMENTATION>
293 template <
class INTERFACE,
class IMPLEMENTATION>
296 s <<
"\n3D Histogram Table: " << std::endl;
297 s <<
"BinX, BinY, BinZ, Height, Error " << std::endl;
298 for (
int i = 0;
i < xAxis().bins(); ++
i )
299 for (
int j = 0; j < yAxis().bins(); ++j )
300 for (
int k = 0; k < zAxis().bins(); ++k )
301 s << binMeanX(
i, j, k ) <<
", "
302 << binMeanY(
i, j, k ) <<
", "
303 << binMeanZ(
i, j, k ) <<
", "
304 << binHeight(
i, j, k ) <<
", "
305 << binError (
i, j, k ) << std::endl;
311 template <
class INTERFACE,
class IMPLEMENTATION>
314 TFile *f = TFile::Open(file_name,
"RECREATE");
315 Int_t nbytes = m_rep->Write();
320 #endif // GAUDIPI_GENERIC3D_H
int rIndexZ(int index) const
int rIndexX(int index) const
AIDA::IAnnotation & annotation() override
Access annotation object.
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 sumAllBinHeights() const override
Get the sum of all the bins heights (including underflow and overflow bin).
int coordToIndexY(double coord) const override
Get the bin number corresponding to a given coordinate along the y axis.
double binMeanX(int indexX, int, int) const
The weighted mean along the x axis of a given bin.
const AIDA::IAxis & xAxis() const override
Get the x axis of the IHistogram3D.
int binEntriesZ(int index) const override
Sum of all the entries of the bins along a given z bin.
double binMeanZ(int, int, int indexZ) const
The weighted mean along the z axis of a given bin.
double sumExtraBinHeights() const override
Get the sum of the underflow and overflow bin height.
TObject * representation() const override
ROOT object implementation.
double sumBinHeights() const override
Get the sum of in range bin heights in the IProfile.
std::string title() const override
Get the title of the object.
std::string name() const
object name
bool add(const INTERFACE &hist) override
Add to this Histogram3D the contents of another IHistogram3D.
int entries() const override
Get the number or all the entries.
const AIDA::IAxis & zAxis() const override
Get the z axis of the IHistogram3D.
double maxBinHeight() const override
Get the maximum height of the in-range bins.
double meanX() const override
The mean of the IHistogram3D along the x axis.
int binEntriesY(int index) const override
Sum of all the entries of the bins along a given y bin.
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 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 g...
bool setName(const std::string &newName)
Sets the name of the object.
bool setTitle(const std::string &title) override
Set the title of the object.
int rIndexY(int index) const
Generic3D< INTERFACE, IMPLEMENTATION > Base
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
double binHeight(int indexX, int indexY, int indexZ) const
Total height of the corresponding bin (ie the sum of the weights in this bin).
int dimension() const override
Get the Histogram's dimension.
int allEntries() const override
Get the number or all the entries, both in range and underflow/overflow bins of the IProfile...
double binHeightZ(int index) const override
Sum of all the heights of the bins along a given z bin.
double rmsY() const override
The RMS of the IHistogram3D along the y axis.
double binHeightY(int index) const override
Sum of all the heights of the bins along a given y bin.
Common base class for all histograms Use is solely functional to minimize dynamic_casts inside Histog...
int coordToIndexX(double coord) const override
Get the bin number corresponding to a given coordinate along the x axis.
AIDA::Annotation m_annotation
Object annotations.
const AIDA::IAnnotation & annotation() const override
Access annotation object (cons)
std::ostream & write(std::ostream &s) const override
Write (ASCII) the histogram table into the output stream.
double minBinHeight() const override
Get the minimum height of the in-range bins.
int coordToIndexZ(double coord) const override
Get the bin number corresponding to a given coordinate along the z axis.
int binEntriesX(int index) const override
Sum of all the entries of the bins along a given x bin.
std::ostream & print(std::ostream &s) const override
Print (ASCII) the histogram into the output stream.
double rmsZ() const override
The RMS of the IHistogram3D along the z axis.
double binError(int indexX, int indexY, int indexZ) const override
The error of a given bin.
double meanY() const override
The mean of the IHistogram3D along the y axis.
double binHeightX(int index) const override
Sum of all the heights of the bins along a given x bin.
Generic3D(IMPLEMENTATION *p)
constructor
Helper functions to set/get the application return code.
An IAxis represents a binned histogram axis.
double rmsX() const override
The RMS of the IHistogram3D along the x axis.
double meanZ() const override
The mean of the IHistogram3D along the z axis.
double equivalentBinEntries() const override
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
const AIDA::IAxis & yAxis() const override
Get the y axis of the IHistogram3D.