1 #ifndef GAUDISVC_GENERIC2D_H
2 #define GAUDISVC_GENERIC2D_H 1
8 #include "AIDA/IProfile2D.h"
9 #include "GaudiKernel/HistogramBase.h"
30 template <
class INTERFACE,
class IMPLEMENTATION>
45 void adoptRepresentation(TObject* rep)
override;
47 virtual std::string
title()
const {
return m_annotation.value(
"Title" ); }
49 virtual bool setTitle(
const std::string & title);
51 std::string
name()
const {
return m_annotation.value(
"Name"); }
53 bool setName(
const std::string& newName );
55 virtual AIDA::IAnnotation &
annotation() {
return m_annotation; }
57 virtual const AIDA::IAnnotation &
annotation()
const {
return m_annotation; }
60 virtual const AIDA::IAxis &
xAxis()
const {
return m_xAxis; }
62 virtual const AIDA::IAxis &
yAxis()
const {
return m_yAxis; }
64 virtual int rIndexX(
int index)
const {
return m_xAxis.rIndex(index); }
66 virtual int rIndexY(
int index)
const {
return m_yAxis.rIndex(index); }
69 virtual int entries()
const;
71 virtual int allEntries()
const;
73 virtual int extraEntries()
const;
75 virtual double sumBinHeights()
const;
77 virtual double sumAllBinHeights()
const;
81 virtual double minBinHeight()
const;
83 virtual double maxBinHeight()
const;
86 virtual double binMeanX(
int indexX,
int indexY)
const;
88 virtual double binMeanY(
int indexX,
int indexY)
const;
90 virtual int binEntries (
int indexX,
int indexY )
const;
92 virtual int binEntriesX(
int indexX)
const;
94 virtual int binEntriesY(
int indexY)
const;
96 virtual double binHeight(
int indexX,
int indexY)
const;
98 virtual double binHeightX(
int indexX)
const;
100 virtual double binHeightY(
int indexY)
const;
102 virtual double binError(
int indexX,
int indexY)
const;
104 virtual double binRms(
int indexX,
int indexY)
const;
106 virtual double meanX()
const;
108 virtual double meanY()
const;
110 virtual double rmsX()
const;
112 virtual double rmsY()
const;
114 virtual int coordToIndexX(
double coordX)
const;
116 virtual int coordToIndexY(
double coordY)
const;
118 virtual double equivalentBinEntries ( )
const;
120 virtual bool scale(
double scaleFactor );
122 virtual bool add(
const INTERFACE & h);
126 void * cast(
const std::string & className)
const;
132 std::ostream& print( std::ostream&
s )
const override;
134 std::ostream& write( std::ostream&
s )
const override;
136 int write(
const char* file_name )
const override;
146 std::unique_ptr<IMPLEMENTATION>
m_rep;
150 int m_sumEntries = 0;
153 template <
class INTERFACE,
class IMPLEMENTATION>
155 m_rep->SetTitle(title.c_str());
156 if ( !annotation().addItem(
"Title", title ) )
157 m_annotation.setValue(
"Title" , title );
158 if ( !annotation().addItem(
"title", title ) )
159 annotation().setValue(
"title", title );
163 template <
class INTERFACE,
class IMPLEMENTATION>
165 m_rep->SetName(newName.c_str());
166 m_annotation.setValue(
"Name", newName );
170 template <
class INTERFACE,
class IMPLEMENTATION>
172 return m_rep->GetEntries();
175 template <
class INTERFACE,
class IMPLEMENTATION>
177 return m_rep->GetEntries();
180 template <
class INTERFACE,
class IMPLEMENTATION>
182 return m_rep->GetMinimum();
185 template <
class INTERFACE,
class IMPLEMENTATION>
187 return m_rep->GetMaximum();
190 template <
class INTERFACE,
class IMPLEMENTATION>
192 return m_rep->GetSumOfWeights();
195 template <
class INTERFACE,
class IMPLEMENTATION>
197 return m_rep->GetSum();
200 template <
class INTERFACE,
class IMPLEMENTATION>
202 return m_rep->GetBinError ( rIndexX(indexX), rIndexY(indexY) );
205 template <
class INTERFACE,
class IMPLEMENTATION>
207 return m_rep->GetXaxis()->GetBinCenter( rIndexX(indexX) );
210 template <
class INTERFACE,
class IMPLEMENTATION>
212 return m_rep->GetYaxis()->GetBinCenter( rIndexY(indexY) );
215 template <
class INTERFACE,
class IMPLEMENTATION>
218 for (
int iY = -2; iY < yAxis().bins(); ++iY)
219 n += binEntries(index,iY);
223 template <
class INTERFACE,
class IMPLEMENTATION>
226 for (
int iX = -2; iX < xAxis().bins(); ++iX)
227 n += binEntries(iX,index);
231 template <
class INTERFACE,
class IMPLEMENTATION>
233 return m_rep->GetBinContent ( rIndexX(indexX), rIndexY(indexY) );
236 template <
class INTERFACE,
class IMPLEMENTATION>
239 for (
int iY = -2; iY < yAxis().bins(); ++iY) {
240 s += binHeight(index,iY);
245 template <
class INTERFACE,
class IMPLEMENTATION>
248 for (
int iX = -2; iX < xAxis().bins(); ++iX)
249 s += binHeight(iX,index);
253 template <
class INTERFACE,
class IMPLEMENTATION>
255 return m_rep->GetBinError ( rIndexX(indexX), rIndexY(indexY ) );
258 template <
class INTERFACE,
class IMPLEMENTATION>
260 return m_rep->GetMean(1);
263 template <
class INTERFACE,
class IMPLEMENTATION>
265 return m_rep->GetMean(2);
268 template <
class INTERFACE,
class IMPLEMENTATION>
270 return m_rep->GetRMS(1);
273 template <
class INTERFACE,
class IMPLEMENTATION>
275 return m_rep->GetRMS(2);
278 template <
class INTERFACE,
class IMPLEMENTATION>
280 return xAxis().coordToIndex(coord);
283 template <
class INTERFACE,
class IMPLEMENTATION>
285 return yAxis().coordToIndex(coord);
288 template <
class INTERFACE,
class IMPLEMENTATION>
290 const Base* p =
dynamic_cast<const Base*
>(&hist);
291 if ( !p )
throw std::runtime_error(
"Cannot add profile histograms of different implementations.");
292 m_rep->Add(p->
m_rep.get());
296 template <
class INTERFACE,
class IMPLEMENTATION>
299 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
300 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
301 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
302 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN);
305 template <
class INTERFACE,
class IMPLEMENTATION>
307 if (sumBinHeights() <= 0)
return 0;
309 m_rep->GetStats(stats);
310 return stats[0]*stats[0]/stats[1];
313 template <
class INTERFACE,
class IMPLEMENTATION>
315 m_rep->Scale ( scaleFactor );
319 template <
class INTERFACE,
class IMPLEMENTATION>
326 template <
class INTERFACE,
class IMPLEMENTATION>
335 template <
class INTERFACE,
class IMPLEMENTATION>
338 s << std::endl <<
"2D Histogram Table: " << std::endl;
339 s <<
"BinX, BinY, Height, Error " << std::endl;
340 for (
int i = 0;
i < xAxis().bins(); ++
i ) {
341 for (
int j = 0; j < yAxis().bins(); ++j ) {
342 s << binMeanX(
i, j ) <<
", "
343 << binMeanY(
i, j ) <<
", "
344 << binHeight(
i, j ) <<
", "
345 << binError (
i, j ) << std::endl;
353 template <
class INTERFACE,
class IMPLEMENTATION>
356 TFile *f = TFile::Open(file_name,
"RECREATE");
357 Int_t nbytes = m_rep->Write();
362 #endif // GAUDIPI_GENERIC2D_H
virtual double binHeightY(int indexY) const
Equivalent to projectionY().binHeight(indexY).
virtual bool setTitle(const std::string &title)
Set the title of the object.
virtual AIDA::IAnnotation & annotation()
Access annotation object.
virtual double equivalentBinEntries() const
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
virtual double rmsX() const
Returns the rms of the profile as calculated on filling-time projected on the X axis.
virtual double minBinHeight() const
Get the minimum height of the in-range bins.
virtual double binMeanX(int indexX, int indexY) const
The weighted mean along x of a given bin.
Generic2D< INTERFACE, IMPLEMENTATION > Base
Generic2D(IMPLEMENTATION *p)
constructor
virtual int binEntriesY(int indexY) const
Equivalent to projectionY().binEntries(indexY).
virtual double sumBinHeights() const
Get the sum of in range bin heights in the IProfile.
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
virtual int extraEntries() const
Get the number of entries in the underflow and overflow bins.
virtual double maxBinHeight() const
Get the maximum height of the in-range bins.
virtual int dimension() const
Get the Histogram's dimension.
virtual double binError(int indexX, int indexY) const
The error on this bin.
std::string m_classType
class type
Axis m_xAxis
X axis member.
virtual std::string title() const
Get the title of the object.
std::ostream & write(std::ostream &s) const override
Write (ASCII) the histogram table into the output stream.
Implementation of the AIDA IAnnotation interface class.
virtual bool add(const INTERFACE &h)
Modifies this profile by adding the contents of profile to it.
virtual double meanY() const
Returns the mean of the profile, as calculated on filling-time projected on the Y axis...
virtual int allEntries() const
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.
Common base class for all histograms Use is solely functional to minimize dynamic_casts inside Histog...
AIDA::Annotation m_annotation
Object annotations.
virtual int coordToIndexX(double coordX) const
Convenience method, equivalent to xAxis().coordToIndex(coord).
virtual double sumAllBinHeights() const
Get the sum of all the bins heights (including underflow and overflow bin).
virtual double binHeight(int indexX, int indexY) const
Total height of the corresponding bin (ie the sum of the weights in this bin).
Axis m_yAxis
Y axis member.
virtual double sumExtraBinHeights() const
Get the sum of the underflow and overflow bin height.
virtual double binHeightX(int indexX) const
Equivalent to projectionX().binHeight(indexX).
virtual int entries() const
Get the number or all the entries.
virtual const AIDA::IAxis & yAxis() const
Return the Y axis.
virtual const AIDA::IAnnotation & annotation() const
Access annotation object (cons)
virtual double binMeanY(int indexX, int indexY) const
The weighted mean along y of a given bin.
virtual double binRms(int indexX, int indexY) const
The spread (RMS) of this bin.
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
virtual int coordToIndexY(double coordY) const
Convenience method, equivalent to yAxis().coordToIndex(coord).
virtual int rIndexY(int index) const
operator methods
TObject * representation() const override
ROOT object implementation.
std::ostream & print(std::ostream &s) const override
Print (ASCII) the histogram into the output stream.
virtual double rmsY() const
Returns the rms of the profile as calculated on filling-time projected on the Y axis.
virtual int binEntriesX(int indexX) const
Equivalent to projectionX().binEntries(indexX).
Helper functions to set/get the application return code.
An IAxis represents a binned histogram axis.
virtual const AIDA::IAxis & xAxis() const
Return the X axis.
virtual double meanX() const
Returns the mean of the profile, as calculated on filling-time projected on the X axis...
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.