1 #ifndef GAUDISVC_GENERIC2D_H
2 #define GAUDISVC_GENERIC2D_H 1
8 #include "AIDA/IProfile2D.h"
9 #include "GaudiKernel/HistogramBase.h"
16 #pragma clang diagnostic push
19 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
34 template <
class INTERFACE,
class IMPLEMENTATION>
49 void adoptRepresentation(TObject* rep)
override;
51 std::string
title()
const override {
return m_annotation.value(
"Title" ); }
53 bool setTitle(
const std::string & title)
override;
55 std::string
name()
const {
return m_annotation.value(
"Name"); }
57 bool setName(
const std::string& newName );
59 AIDA::IAnnotation &
annotation()
override {
return m_annotation; }
61 const AIDA::IAnnotation &
annotation()
const override {
return m_annotation; }
64 const AIDA::IAxis &
xAxis()
const override {
return m_xAxis; }
66 const AIDA::IAxis &
yAxis()
const override {
return m_yAxis; }
68 virtual int rIndexX(
int index)
const {
return m_xAxis.rIndex(index); }
70 virtual int rIndexY(
int index)
const {
return m_yAxis.rIndex(index); }
73 int entries()
const override;
75 int allEntries()
const override;
77 int extraEntries()
const override;
79 double sumBinHeights()
const override;
81 double sumAllBinHeights()
const override;
85 double minBinHeight()
const override;
87 double maxBinHeight()
const override;
90 double binMeanX(
int indexX,
int indexY)
const override;
92 double binMeanY(
int indexX,
int indexY)
const override;
94 int binEntries (
int indexX,
int indexY )
const override;
96 int binEntriesX(
int indexX)
const override;
98 int binEntriesY(
int indexY)
const override;
100 double binHeight(
int indexX,
int indexY)
const override;
102 double binHeightX(
int indexX)
const override;
104 double binHeightY(
int indexY)
const override;
106 double binError(
int indexX,
int indexY)
const override;
108 virtual double binRms(
int indexX,
int indexY)
const;
110 double meanX()
const override;
112 double meanY()
const override;
114 double rmsX()
const override;
116 double rmsY()
const override;
118 int coordToIndexX(
double coordX)
const override;
120 int coordToIndexY(
double coordY)
const override;
122 virtual double equivalentBinEntries ( )
const;
124 virtual bool scale(
double scaleFactor );
126 bool add(
const INTERFACE &
h)
override;
128 bool reset ( )
override;
130 void * cast(
const std::string & className)
const;
136 std::ostream&
print( std::ostream&
s )
const override;
138 std::ostream& write( std::ostream&
s )
const override;
140 int write(
const char* file_name )
const override;
150 std::unique_ptr<IMPLEMENTATION>
m_rep;
154 int m_sumEntries = 0;
157 template <
class INTERFACE,
class IMPLEMENTATION>
159 m_rep->SetTitle(title.c_str());
160 if ( !annotation().addItem(
"Title", title ) )
161 m_annotation.setValue(
"Title" , title );
162 if ( !annotation().addItem(
"title", title ) )
163 annotation().setValue(
"title", title );
167 template <
class INTERFACE,
class IMPLEMENTATION>
169 m_rep->SetName(newName.c_str());
170 m_annotation.setValue(
"Name", newName );
174 template <
class INTERFACE,
class IMPLEMENTATION>
176 return m_rep->GetEntries();
179 template <
class INTERFACE,
class IMPLEMENTATION>
181 return m_rep->GetEntries();
184 template <
class INTERFACE,
class IMPLEMENTATION>
186 return m_rep->GetMinimum();
189 template <
class INTERFACE,
class IMPLEMENTATION>
191 return m_rep->GetMaximum();
194 template <
class INTERFACE,
class IMPLEMENTATION>
196 return m_rep->GetSumOfWeights();
199 template <
class INTERFACE,
class IMPLEMENTATION>
201 return m_rep->GetSum();
204 template <
class INTERFACE,
class IMPLEMENTATION>
206 return m_rep->GetBinError ( rIndexX(indexX), rIndexY(indexY) );
209 template <
class INTERFACE,
class IMPLEMENTATION>
211 return m_rep->GetXaxis()->GetBinCenter( rIndexX(indexX) );
214 template <
class INTERFACE,
class IMPLEMENTATION>
216 return m_rep->GetYaxis()->GetBinCenter( rIndexY(indexY) );
219 template <
class INTERFACE,
class IMPLEMENTATION>
222 for (
int iY = -2; iY < yAxis().bins(); ++iY)
223 n += binEntries(index,iY);
227 template <
class INTERFACE,
class IMPLEMENTATION>
230 for (
int iX = -2; iX < xAxis().bins(); ++iX)
231 n += binEntries(iX,index);
235 template <
class INTERFACE,
class IMPLEMENTATION>
237 return m_rep->GetBinContent ( rIndexX(indexX), rIndexY(indexY) );
240 template <
class INTERFACE,
class IMPLEMENTATION>
243 for (
int iY = -2; iY < yAxis().bins(); ++iY) {
244 s += binHeight(index,iY);
249 template <
class INTERFACE,
class IMPLEMENTATION>
252 for (
int iX = -2; iX < xAxis().bins(); ++iX)
253 s += binHeight(iX,index);
257 template <
class INTERFACE,
class IMPLEMENTATION>
259 return m_rep->GetBinError ( rIndexX(indexX), rIndexY(indexY ) );
262 template <
class INTERFACE,
class IMPLEMENTATION>
264 return m_rep->GetMean(1);
267 template <
class INTERFACE,
class IMPLEMENTATION>
269 return m_rep->GetMean(2);
272 template <
class INTERFACE,
class IMPLEMENTATION>
274 return m_rep->GetRMS(1);
277 template <
class INTERFACE,
class IMPLEMENTATION>
279 return m_rep->GetRMS(2);
282 template <
class INTERFACE,
class IMPLEMENTATION>
284 return xAxis().coordToIndex(coord);
287 template <
class INTERFACE,
class IMPLEMENTATION>
289 return yAxis().coordToIndex(coord);
292 template <
class INTERFACE,
class IMPLEMENTATION>
294 const Base* p =
dynamic_cast<const Base*
>(&hist);
295 if ( !p )
throw std::runtime_error(
"Cannot add profile histograms of different implementations.");
296 m_rep->Add(p->
m_rep.get());
300 template <
class INTERFACE,
class IMPLEMENTATION>
303 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
304 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
305 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
306 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN);
309 template <
class INTERFACE,
class IMPLEMENTATION>
311 if (sumBinHeights() <= 0)
return 0;
313 m_rep->GetStats(stats);
314 return stats[0]*stats[0]/stats[1];
317 template <
class INTERFACE,
class IMPLEMENTATION>
319 m_rep->Scale ( scaleFactor );
323 template <
class INTERFACE,
class IMPLEMENTATION>
330 template <
class INTERFACE,
class IMPLEMENTATION>
339 template <
class INTERFACE,
class IMPLEMENTATION>
342 s << std::endl <<
"2D Histogram Table: " << std::endl;
343 s <<
"BinX, BinY, Height, Error " << std::endl;
344 for (
int i = 0;
i < xAxis().bins(); ++
i ) {
345 for (
int j = 0; j < yAxis().bins(); ++j ) {
346 s << binMeanX(
i, j ) <<
", "
347 << binMeanY(
i, j ) <<
", "
348 << binHeight(
i, j ) <<
", "
349 << binError (
i, j ) << std::endl;
357 template <
class INTERFACE,
class IMPLEMENTATION>
360 TFile *f = TFile::Open(file_name,
"RECREATE");
361 Int_t nbytes = m_rep->Write();
368 #pragma clang diagnostic pop
371 #endif // GAUDIPI_GENERIC2D_H
double binHeightY(int indexY) const override
Equivalent to projectionY().binHeight(indexY).
double binMeanX(int indexX, int indexY) const override
The weighted mean along x of a given bin.
double sumExtraBinHeights() const override
Get the sum of the underflow and overflow bin height.
int dimension() const override
Get the Histogram's dimension.
virtual double equivalentBinEntries() const
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
int coordToIndexY(double coordY) const override
Convenience method, equivalent to yAxis().coordToIndex(coord).
Generic2D< INTERFACE, IMPLEMENTATION > Base
const AIDA::IAnnotation & annotation() const override
Access annotation object (cons)
Generic2D(IMPLEMENTATION *p)
constructor
int coordToIndexX(double coordX) const override
Convenience method, equivalent to xAxis().coordToIndex(coord).
double meanX() const override
Returns the mean of the profile, as calculated on filling-time projected on the X axis...
int entries() const override
Get the number or all the entries.
int binEntriesY(int indexY) const override
Equivalent to projectionY().binEntries(indexY).
double minBinHeight() const override
Get the minimum height of the in-range bins.
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...
std::string name() const
object name
bool setName(const std::string &newName)
Set the name of the object.
virtual int rIndexX(int index) const
operator methods
double binHeightX(int indexX) const override
Equivalent to projectionX().binHeight(indexX).
const AIDA::IAxis & yAxis() const override
Return the Y axis.
double sumBinHeights() const override
Get the sum of in range bin heights in the IProfile.
std::string m_classType
class type
Axis m_xAxis
X axis member.
std::ostream & write(std::ostream &s) const override
Write (ASCII) the histogram table into the output stream.
Implementation of the AIDA IAnnotation interface class.
const AIDA::IAxis & xAxis() const override
Return the X axis.
int allEntries() const override
Get the number or all the entries, both in range and underflow/overflow bins of the IProfile...
const std::string & userLevelClassType() const
The AIDA user-level unterface leaf class type.
AIDA::IAnnotation & annotation() override
Access annotation object.
std::string title() const override
Get the title of the object.
Common base class for all histograms Use is solely functional to minimize dynamic_casts inside Histog...
int extraEntries() const override
Get the number of entries in the underflow and overflow bins.
AIDA::Annotation m_annotation
Object annotations.
double rmsY() const override
Returns the rms of the profile as calculated on filling-time projected on the Y axis.
bool setTitle(const std::string &title) override
Set the title of the object.
double binError(int indexX, int indexY) const override
The error on this bin.
Axis m_yAxis
Y axis member.
virtual double binRms(int indexX, int indexY) const
The spread (RMS) of this bin.
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
int binEntriesX(int indexX) const override
Equivalent to projectionX().binEntries(indexX).
virtual int rIndexY(int index) const
operator methods
double maxBinHeight() const override
Get the maximum height of the in-range bins.
TObject * representation() const override
ROOT object implementation.
double meanY() const override
Returns the mean of the profile, as calculated on filling-time projected on the Y axis...
std::ostream & print(std::ostream &s) const override
Print (ASCII) the histogram into the output stream.
double sumAllBinHeights() const override
Get the sum of all the bins heights (including underflow and overflow bin).
double rmsX() const override
Returns the rms of the profile as calculated on filling-time projected on the X axis.
Helper functions to set/get the application return code.
An IAxis represents a binned histogram axis.
double binMeanY(int indexX, int indexY) const override
The weighted mean along y of a given bin.
bool add(const INTERFACE &h) override
Modifies this profile by adding the contents of profile to it.
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
double binHeight(int indexX, int indexY) const override
Total height of the corresponding bin (ie the sum of the weights in this bin).