1 #ifndef GAUDISVC_GENERIC2D_H
2 #define GAUDISVC_GENERIC2D_H 1
7 #include "AIDA/IProfile2D.h"
29 template <
class INTERFACE,
class IMPLEMENTATION>
42 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 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 const AIDA::IAxis &
xAxis()
const {
return m_xAxis; }
59 virtual const AIDA::IAxis &
yAxis()
const {
return m_yAxis; }
61 virtual int rIndexX(
int index)
const {
return m_xAxis.rIndex(index); }
63 virtual int rIndexY(
int index)
const {
return m_yAxis.rIndex(index); }
66 virtual int entries()
const;
68 virtual int allEntries()
const;
70 virtual int extraEntries()
const;
72 virtual double sumBinHeights()
const;
74 virtual double sumAllBinHeights()
const;
78 virtual double minBinHeight()
const;
80 virtual double maxBinHeight()
const;
83 virtual double binMeanX(
int indexX,
int indexY)
const;
85 virtual double binMeanY(
int indexX,
int indexY)
const;
87 virtual int binEntries (
int indexX,
int indexY )
const;
89 virtual int binEntriesX(
int indexX)
const;
91 virtual int binEntriesY(
int indexY)
const;
93 virtual double binHeight(
int indexX,
int indexY)
const;
95 virtual double binHeightX(
int indexX)
const;
97 virtual double binHeightY(
int indexY)
const;
99 virtual double binError(
int indexX,
int indexY)
const;
101 virtual double binRms(
int indexX,
int indexY)
const;
103 virtual double meanX()
const;
105 virtual double meanY()
const;
107 virtual double rmsX()
const;
109 virtual double rmsY()
const;
111 virtual int coordToIndexX(
double coordX)
const;
113 virtual int coordToIndexY(
double coordY)
const;
115 virtual double equivalentBinEntries ( )
const;
117 virtual bool scale(
double scaleFactor );
119 virtual bool add(
const INTERFACE & h);
123 void * cast(
const std::string & className)
const;
129 virtual std::ostream& print( std::ostream&
s )
const;
131 virtual std::ostream& write( std::ostream&
s )
const;
133 virtual int write(
const char* file_name )
const;
150 template <
class INTERFACE,
class IMPLEMENTATION>
152 m_rep->SetTitle(title.c_str());
153 if ( !annotation().addItem(
"Title", title ) )
154 m_annotation.setValue(
"Title" , title );
155 if ( !annotation().addItem(
"title", title ) )
156 annotation().setValue(
"title", title );
160 template <
class INTERFACE,
class IMPLEMENTATION>
162 m_rep->SetName(newName.c_str());
163 m_annotation.setValue(
"Name", newName );
167 template <
class INTERFACE,
class IMPLEMENTATION>
169 return (
int)m_rep->GetEntries();
172 template <
class INTERFACE,
class IMPLEMENTATION>
174 return int(m_rep->GetEntries());
177 template <
class INTERFACE,
class IMPLEMENTATION>
179 return m_rep->GetMinimum();
182 template <
class INTERFACE,
class IMPLEMENTATION>
184 return m_rep->GetMaximum();
187 template <
class INTERFACE,
class IMPLEMENTATION>
189 return m_rep->GetSumOfWeights();
192 template <
class INTERFACE,
class IMPLEMENTATION>
194 return m_rep->GetSum();
197 template <
class INTERFACE,
class IMPLEMENTATION>
199 return m_rep->GetBinError ( rIndexX(indexX), rIndexY(indexY) );
202 template <
class INTERFACE,
class IMPLEMENTATION>
204 return (m_rep->GetXaxis())->GetBinCenter( rIndexX(indexX) );
207 template <
class INTERFACE,
class IMPLEMENTATION>
209 return (m_rep->GetYaxis())->GetBinCenter( rIndexY(indexY) );
212 template <
class INTERFACE,
class IMPLEMENTATION>
215 for (
int iY = -2; iY < yAxis().bins(); ++iY)
216 n += binEntries(index,iY);
220 template <
class INTERFACE,
class IMPLEMENTATION>
223 for (
int iX = -2; iX < xAxis().bins(); ++iX)
224 n += binEntries(iX,index);
228 template <
class INTERFACE,
class IMPLEMENTATION>
230 return m_rep->GetBinContent ( rIndexX(indexX), rIndexY(indexY) );
233 template <
class INTERFACE,
class IMPLEMENTATION>
236 for (
int iY = -2; iY < yAxis().bins(); ++iY) {
237 s += binHeight(index,iY);
242 template <
class INTERFACE,
class IMPLEMENTATION>
245 for (
int iX = -2; iX < xAxis().bins(); ++iX)
246 s += binHeight(iX,index);
250 template <
class INTERFACE,
class IMPLEMENTATION>
252 return m_rep->GetBinError ( rIndexX(indexX), rIndexY(indexY ) );
255 template <
class INTERFACE,
class IMPLEMENTATION>
257 return m_rep->GetMean(1);
260 template <
class INTERFACE,
class IMPLEMENTATION>
262 return m_rep->GetMean(2);
265 template <
class INTERFACE,
class IMPLEMENTATION>
267 return m_rep->GetRMS(1);
270 template <
class INTERFACE,
class IMPLEMENTATION>
272 return m_rep->GetRMS(2);
275 template <
class INTERFACE,
class IMPLEMENTATION>
277 return xAxis().coordToIndex(coord);
280 template <
class INTERFACE,
class IMPLEMENTATION>
282 return yAxis().coordToIndex(coord);
285 template <
class INTERFACE,
class IMPLEMENTATION>
287 const Base* p =
dynamic_cast<const Base*
>(&hist);
289 m_rep->Add(p->
m_rep);
292 throw std::runtime_error(
"Cannot add profile histograms of different implementations.");
295 template <
class INTERFACE,
class IMPLEMENTATION>
298 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
299 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
300 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
301 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN);
304 template <
class INTERFACE,
class IMPLEMENTATION>
306 if (sumBinHeights() <= 0)
return 0;
308 m_rep->GetStats(stats);
309 return stats[0]*stats[0]/stats[1];
312 template <
class INTERFACE,
class IMPLEMENTATION>
314 m_rep->Scale ( scaleFactor );
318 template <
class INTERFACE,
class IMPLEMENTATION>
325 template <
class INTERFACE,
class IMPLEMENTATION>
334 template <
class INTERFACE,
class IMPLEMENTATION>
337 s << std::endl <<
"2D Histogram Table: " << std::endl;
338 s <<
"BinX, BinY, Height, Error " << std::endl;
339 for (
int i = 0;
i < xAxis().bins(); ++
i ) {
340 for (
int j = 0; j < yAxis().bins(); ++j ) {
341 s << binMeanX(
i, j ) <<
", "
342 << binMeanY(
i, j ) <<
", "
343 << binHeight(
i, j ) <<
", "
344 << binError (
i, j ) << std::endl;
352 template <
class INTERFACE,
class IMPLEMENTATION>
355 TFile *f = TFile::Open(file_name,
"RECREATE");
356 Int_t nbytes = m_rep->Write();
361 #endif // GAUDIPI_GENERIC2D_H
int m_sumEntries
cache sumEntries (allEntries) when setting contents since Root can't compute by himself ...
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
virtual int binEntriesY(int indexY) const
Equivalent to projectionY().binEntries(indexY).
virtual ~Generic2D()
Destructor.
TObject * representation() const
ROOT object implementation.
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.
Implementation of the AIDA IAnnotation interface class.
virtual std::ostream & write(std::ostream &s) const
Write (ASCII) the histogram table into the output stream.
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.
virtual std::ostream & print(std::ostream &s) const
Print (ASCII) the histogram into the output stream.
This is a number of static methods for bootstrapping the Gaudi framework.
virtual int coordToIndexY(double coordY) const
Convenience method, equivalent to yAxis().coordToIndex(coord).
virtual int rIndexY(int index) const
operator methods
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).
An IAxis represents a binned histogram axis.
virtual const AIDA::IAxis & xAxis() const
Return the X axis.
IMPLEMENTATION * m_rep
Reference to underlying implementation.
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.