1 #ifndef GAUDISVC_GENERIC1D_H
2 #define GAUDISVC_GENERIC1D_H 1
10 #include "GaudiKernel/HistogramBase.h"
11 #include "AIDA/IProfile1D.h"
29 template <
class INTERFACE,
class IMPLEMENTATION>
44 void* cast(
const std::string& cl)
const override;
48 void adoptRepresentation(TObject*rep)
override;
50 std::string
title()
const override {
return m_annotation.value(
"Title"); }
52 bool setTitle(
const std::string & title)
override;
54 std::string
name()
const {
return m_annotation.value(
"Name"); }
56 bool setName(
const std::string& newName );
58 AIDA::IAnnotation &
annotation()
override {
return m_annotation; }
60 const AIDA::IAnnotation &
annotation()
const override {
return m_annotation; }
67 int entries()
const override {
return m_rep->GetEntries(); }
69 int allEntries()
const override {
return m_rep->GetEntries(); }
71 int extraEntries()
const override;
73 int binEntries (
int index )
const override;
75 virtual double binRms(
int index)
const;
77 double sumBinHeights()
const override {
return m_rep->GetSumOfWeights(); }
83 double minBinHeight()
const override {
return m_rep->GetMinimum(); }
85 double maxBinHeight()
const override {
return m_rep->GetMaximum(); }
88 virtual double equivalentBinEntries ( )
const ;
90 virtual bool scale(
double scaleFactor ) ;
92 bool reset()
override;
94 bool add(
const INTERFACE & profile)
override;
96 virtual int rIndex(
int index)
const {
return m_axis.rIndex(index);}
98 double binMean(
int index)
const override;
100 double binHeight(
int index)
const override;
102 double binError(
int index)
const override;
104 double mean()
const override {
return m_rep->GetMean(); }
106 double rms ()
const override {
return m_rep->GetRMS(); }
108 int coordToIndex (
double coord )
const override{
return axis().coordToIndex(coord);}
112 std::ostream& print( std::ostream&
s )
const override;
114 std::ostream& write( std::ostream&
s )
const override;
116 int write(
const char* file_name )
const override;
124 std::unique_ptr<IMPLEMENTATION>
m_rep;
131 template <
class INTERFACE,
class IMPLEMENTATION>
133 m_rep->SetTitle(title.c_str());
134 if ( !annotation().addItem(
"Title", title ) )
135 m_annotation.setValue(
"Title" , title );
136 if ( !annotation().addItem(
"title", title ) )
137 annotation().setValue(
"title", title );
141 template <
class INTERFACE,
class IMPLEMENTATION>
143 m_rep->SetName(newName.c_str());
144 m_annotation.setValue(
"Name", newName );
148 template <
class INTERFACE,
class IMPLEMENTATION>
150 return m_rep->GetBinError ( rIndex(index) );
153 template <
class INTERFACE,
class IMPLEMENTATION>
155 return m_rep->GetBinCenter ( rIndex(index) );
158 template <
class INTERFACE,
class IMPLEMENTATION>
160 return m_rep->GetBinContent ( rIndex(index) );
163 template <
class INTERFACE,
class IMPLEMENTATION>
165 return m_rep->GetBinError ( rIndex(index) );
168 template <
class INTERFACE,
class IMPLEMENTATION>
170 return binEntries(AIDA::IAxis::UNDERFLOW_BIN) +
171 binEntries(AIDA::IAxis::OVERFLOW_BIN);
173 template <
class INTERFACE,
class IMPLEMENTATION>
180 template <
class INTERFACE,
class IMPLEMENTATION>
182 if (sumBinHeights() <= 0)
return 0;
184 m_rep->GetStats(stats);
185 return stats[0]*stats[0]/stats[1];
188 template <
class INTERFACE,
class IMPLEMENTATION>
190 m_rep->Scale ( scaleFactor );
194 template <
class INTERFACE,
class IMPLEMENTATION>
199 m_rep->Add(p->
m_rep.get());
202 throw std::runtime_error(
"Cannot add profile histograms of different implementations.");
205 template <
class INTERFACE,
class IMPLEMENTATION>
213 template <
class INTERFACE,
class IMPLEMENTATION>
215 s <<
"\n1D Histogram Table: " << std::endl;
216 s <<
"Bin, Height, Error " << std::endl;
217 for(
int i = 0;
i < axis().bins(); ++
i )
218 s << binMean(
i ) <<
", "
219 << binHeight(
i ) <<
", "
220 << binError (
i ) << std::endl;
226 template <
class INTERFACE,
class IMPLEMENTATION>
229 TFile *f = TFile::Open(file_name,
"RECREATE");
230 Int_t nbytes = m_rep->Write();
236 #endif // AIDAROOT_GENERIC1D_H
double maxBinHeight() const override
Get the maximum height of the in-range bins.
double rms() const override
The RMS of the whole IHistogram1D.
double sumAllBinHeights() const override
Get the sum of all the bins heights (including underflow and overflow bin).
bool reset() override
Reset the Histogram; as if just created.
std::ostream & print(std::ostream &s) const override
Print (ASCII) the histogram into the output stream.
double binMean(int index) const override
The weighted mean of a bin.
virtual double binRms(int index) const
double binError(int index) const override
The error of a given bin.
int allEntries() const override
Get the number or all the entries, both in range and underflow/overflow bins of the IProfile...
Axis & axis()
Access to axis object.
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
double sumBinHeights() const override
Get the sum of in range bin heights in the IProfile.
int coordToIndex(double coord) const override
Get the bin number corresponding to a given coordinate along the x axis.
AIDA::Annotation m_annotation
Object annotations.
double mean() const override
The mean of the whole IHistogram1D.
bool add(const INTERFACE &profile) override
Modifies this IProfile1D by adding the contents of profile to it.
bool setTitle(const std::string &title) override
Set the title of the object.
double sumExtraBinHeights() const override
Get the sum of the underflow and overflow bin height.
Generic1D(IMPLEMENTATION *p)
constructor
Implementation of the AIDA IAnnotation interface class.
Generic1D< INTERFACE, IMPLEMENTATION > Base
TObject * representation() const
ROOT object implementation.
virtual const std::string & userLevelClassType() const
The AIDA user-level unterface leaf class type.
int dimension() const override
Get the Histogram's dimension.
int extraEntries() const override
Get the number of entries in the underflow and overflow bins.
Common base class for all histograms Use is solely functional to minimize dynamic_casts inside Histog...
const AIDA::IAnnotation & annotation() const override
Access annotation object (cons)
double minBinHeight() const override
Get the minimum height of the in-range bins.
int entries() const override
Get the number or all the entries.
virtual double equivalentBinEntries() const
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
double binHeight(int index) const override
Total height of the corresponding bin (ie the sum of the weights in this bin).
std::ostream & write(std::ostream &s) const override
Write (ASCII) the histogram table into the output stream.
virtual int rIndex(int index) const
operator methods
AIDA::IAnnotation & annotation() override
Access annotation object.
const Axis & axis() const
Get the x axis of the IHistogram1D.
std::string title() const override
Get the title of the object.
Helper functions to set/get the application return code.
An IAxis represents a binned histogram axis.
bool setName(const std::string &newName)
Set the name of the object.
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
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.