1 #ifndef GAUDISVC_GENERIC3D_H
2 #define GAUDISVC_GENERIC3D_H 1
9 #include "GaudiKernel/HistogramBase.h"
10 #include "AIDA/IHistogram3D.h"
15 #pragma clang diagnostic push
18 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
33 template<
typename INTERFACE,
typename IMPLEMENTATION>
48 void adoptRepresentation(TObject* rep)
override;
53 std::string
title()
const override {
return m_annotation.value(
"Title");}
55 bool setTitle(
const std::string & title)
override;
57 std::string
name()
const {
return m_annotation.value(
"Name"); }
59 bool setName(
const std::string& newName);
61 AIDA::IAnnotation &
annotation()
override {
return m_annotation; }
63 const AIDA::IAnnotation &
annotation()
const override {
return m_annotation; }
66 int entries()
const override;
68 int allEntries()
const override;
70 double sumBinHeights()
const override;
72 double sumAllBinHeights()
const override;
76 double minBinHeight()
const override;
78 double maxBinHeight()
const override;
80 int rIndexX(
int index)
const {
return m_xAxis.rIndex(index);}
81 int rIndexY(
int index)
const {
return m_yAxis.rIndex(index);}
82 int rIndexZ(
int index)
const {
return m_zAxis.rIndex(index);}
85 double binMeanX(
int indexX,
int ,
int )
const override
86 {
return m_rep->GetXaxis()->GetBinCenter( rIndexX(indexX) ); }
88 double binMeanY(
int,
int indexY,
int )
const override
89 {
return m_rep->GetYaxis()->GetBinCenter( rIndexY(indexY) ); }
91 double binMeanZ(
int ,
int ,
int indexZ)
const override
92 {
return m_rep->GetYaxis()->GetBinCenter( rIndexY(indexZ) ); }
94 int binEntries(
int indexX,
int indexY,
int indexZ)
const override {
95 if (binHeight(indexX, indexY, indexZ)<=0)
return 0;
96 double xx = binHeight(indexX, indexY, indexZ)/binError(indexX, indexY, indexZ);
97 return int(xx*xx+0.5);
102 for (
int i = -2;
i < yAxis().bins(); ++
i)
103 for (
int j = -2; j < zAxis().bins(); ++j)
104 n += binEntries(index,
i,j);
111 for (
int i = -2;
i < xAxis().bins(); ++
i)
112 for (
int j = -2; j < zAxis().bins(); ++j)
113 n += binEntries(
i,index,j);
120 for (
int i = -2;
i < xAxis().bins(); ++
i)
121 for (
int j = -2; j < yAxis().bins(); ++j)
122 n += binEntries(
i,j,index);
127 double binHeight (
int indexX,
int indexY,
int indexZ )
const
128 {
return m_rep->GetBinContent ( rIndexX(indexX), rIndexY(indexY), rIndexZ(indexZ) ); }
133 for (
int i = -2;
i < yAxis().bins(); ++
i)
134 for (
int j = -2; j < zAxis().bins(); ++j)
135 s += binHeight(index,
i,j);
141 for (
int i = -2;
i < xAxis().bins(); ++
i)
142 for (
int j = -2; j < zAxis().bins(); ++j)
143 s += binHeight(
i,index,j);
149 for (
int i = -2;
i < xAxis().bins(); ++
i)
150 for (
int j = -2; j < yAxis().bins(); ++j)
151 s += binHeight(
i,j,index);
155 double binError (
int indexX,
int indexY,
int indexZ )
const override
156 {
return m_rep->GetBinError ( rIndexX(indexX), rIndexY(indexY ), rIndexZ(indexZ ) ); }
158 double meanX ( )
const override {
return m_rep->GetMean ( 1); }
161 double meanY ( )
const override {
return m_rep->GetMean ( 2 ); }
163 double meanZ ( )
const override {
return m_rep->GetMean ( 3 ); }
165 double rmsX ( )
const override {
return m_rep->GetRMS( 1 ); }
167 double rmsY ( )
const override {
return m_rep->GetRMS( 2 ); }
169 double rmsZ ( )
const override {
return m_rep->GetRMS( 3 ); }
171 const AIDA::IAxis &
xAxis ( )
const override {
return m_xAxis; }
173 const AIDA::IAxis &
yAxis ( )
const override {
return m_yAxis; }
175 const AIDA::IAxis &
zAxis ( )
const override {
return m_zAxis; }
177 int coordToIndexX (
double coord )
const override {
return xAxis().coordToIndex(coord);}
179 int coordToIndexY (
double coord )
const override {
return yAxis().coordToIndex(coord);}
181 int coordToIndexZ (
double coord )
const override {
return zAxis().coordToIndex(coord);}
184 double equivalentBinEntries ( )
const override;
186 bool scale(
double scaleFactor )
override;
188 bool add (
const INTERFACE & hist )
override {
189 const Base* p =
dynamic_cast<const Base*
>(&hist);
190 if ( !p )
throw std::runtime_error(
"Cannot add profile histograms of different implementations.");
191 m_rep->Add(p->
m_rep.get());
198 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
199 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
200 binEntries(AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
201 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
202 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
203 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
204 binEntries(AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN);
207 std::ostream&
print( std::ostream&
s )
const override;
209 std::ostream& write( std::ostream&
s )
const override;
211 int write(
const char* file_name )
const override;
220 std::unique_ptr<IMPLEMENTATION>
m_rep;
224 int m_sumEntries = 0;
227 template <
class INTERFACE,
class IMPLEMENTATION>
229 m_rep->SetTitle(title.c_str());
230 if ( !annotation().addItem(
"Title", title ) )
231 m_annotation.setValue(
"Title" , title );
232 if ( !annotation().addItem(
"title", title ) )
233 annotation().setValue(
"title", title );
237 template <
class INTERFACE,
class IMPLEMENTATION>
239 m_rep->SetName(newName.c_str());
240 m_annotation.setValue(
"Name", newName );
243 template <
class INTERFACE,
class IMPLEMENTATION>
245 return m_rep->GetEntries();
248 template <
class INTERFACE,
class IMPLEMENTATION>
250 return int(m_rep->GetEntries());
253 template <
class INTERFACE,
class IMPLEMENTATION>
255 return m_rep->GetMinimum();
258 template <
class INTERFACE,
class IMPLEMENTATION>
260 return m_rep->GetMaximum();
263 template <
class INTERFACE,
class IMPLEMENTATION>
265 return m_rep->GetSumOfWeights();
268 template <
class INTERFACE,
class IMPLEMENTATION>
270 return m_rep->GetSum();
273 template <
class INTERFACE,
class IMPLEMENTATION>
275 if (sumBinHeights() <= 0)
return 0;
277 m_rep->GetStats(stats);
278 return stats[0]*stats[0]/stats[1];
281 template <
class INTERFACE,
class IMPLEMENTATION>
283 m_rep->Scale ( scaleFactor );
287 template <
class INTERFACE,
class IMPLEMENTATION>
297 template <
class INTERFACE,
class IMPLEMENTATION>
300 s <<
"\n3D Histogram Table: " << std::endl;
301 s <<
"BinX, BinY, BinZ, Height, Error " << std::endl;
302 for (
int i = 0;
i < xAxis().bins(); ++
i )
303 for (
int j = 0; j < yAxis().bins(); ++j )
304 for (
int k = 0; k < zAxis().bins(); ++k )
305 s << binMeanX(
i, j, k ) <<
", "
306 << binMeanY(
i, j, k ) <<
", "
307 << binMeanZ(
i, j, k ) <<
", "
308 << binHeight(
i, j, k ) <<
", "
309 << binError (
i, j, k ) << std::endl;
315 template <
class INTERFACE,
class IMPLEMENTATION>
318 TFile *f = TFile::Open(file_name,
"RECREATE");
319 Int_t nbytes = m_rep->Write();
326 #pragma clang diagnostic pop
329 #endif // GAUDIPI_GENERIC3D_H
int rIndexZ(int index) const
int rIndexX(int index) const
AIDA::IAnnotation & annotation() override
Access annotation object.
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.
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 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.
double binMeanY(int, int indexY, int) const override
The weighted mean along the y axis of a given bin.
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 binMeanX(int indexX, int, int) const override
The weighted mean along the x axis of a given bin.
double binMeanZ(int, int, int indexZ) const override
The weighted mean along the z axis of a given bin.
Implementation of the AIDA IAnnotation interface class.
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)...
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.
int extraEntries() const override
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.