1 #ifndef GAUDISVC_GENERIC1D_H
2 #define GAUDISVC_GENERIC1D_H 1
10 #include "GaudiKernel/HistogramBase.h"
11 #include "AIDA/IProfile1D.h"
15 #pragma clang diagnostic push
18 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
33 template <
class INTERFACE,
class IMPLEMENTATION>
48 void* cast(
const std::string& cl)
const override;
52 void adoptRepresentation(TObject*rep)
override;
54 std::string
title()
const override {
return m_annotation.value(
"Title"); }
56 bool setTitle(
const std::string & title)
override;
58 std::string
name()
const {
return m_annotation.value(
"Name"); }
60 bool setName(
const std::string& newName );
62 AIDA::IAnnotation &
annotation()
override {
return m_annotation; }
64 const AIDA::IAnnotation &
annotation()
const override {
return m_annotation; }
68 const Axis &
axis ()
const override {
return m_axis; }
71 int entries()
const override {
return m_rep->GetEntries(); }
73 int allEntries()
const override {
return m_rep->GetEntries(); }
75 int extraEntries()
const override;
77 int binEntries (
int index )
const override;
79 virtual double binRms(
int index)
const;
81 double sumBinHeights()
const override {
return m_rep->GetSumOfWeights(); }
87 double minBinHeight()
const override {
return m_rep->GetMinimum(); }
89 double maxBinHeight()
const override {
return m_rep->GetMaximum(); }
92 virtual double equivalentBinEntries ( )
const;
94 virtual bool scale(
double scaleFactor ) ;
96 bool reset()
override;
98 bool add(
const INTERFACE & profile)
override;
100 virtual int rIndex(
int index)
const {
return m_axis.rIndex(index);}
102 double binMean(
int index)
const override;
104 double binHeight(
int index)
const override;
106 double binError(
int index)
const override;
108 double mean()
const override {
return m_rep->GetMean(); }
110 double rms ()
const override {
return m_rep->GetRMS(); }
112 int coordToIndex (
double coord )
const override{
return axis().coordToIndex(coord);}
116 std::ostream&
print( std::ostream&
s )
const override;
118 std::ostream& write( std::ostream&
s )
const override;
120 int write(
const char* file_name )
const override;
128 std::unique_ptr<IMPLEMENTATION>
m_rep;
135 template <
class INTERFACE,
class IMPLEMENTATION>
137 m_rep->SetTitle(title.c_str());
138 if ( !annotation().addItem(
"Title", title ) )
139 m_annotation.setValue(
"Title" , title );
140 if ( !annotation().addItem(
"title", title ) )
141 annotation().setValue(
"title", title );
145 template <
class INTERFACE,
class IMPLEMENTATION>
147 m_rep->SetName(newName.c_str());
148 m_annotation.setValue(
"Name", newName );
152 template <
class INTERFACE,
class IMPLEMENTATION>
154 return m_rep->GetBinError ( rIndex(index) );
157 template <
class INTERFACE,
class IMPLEMENTATION>
159 return m_rep->GetBinCenter ( rIndex(index) );
162 template <
class INTERFACE,
class IMPLEMENTATION>
164 return m_rep->GetBinContent ( rIndex(index) );
167 template <
class INTERFACE,
class IMPLEMENTATION>
169 return m_rep->GetBinError ( rIndex(index) );
172 template <
class INTERFACE,
class IMPLEMENTATION>
174 return binEntries(AIDA::IAxis::UNDERFLOW_BIN) +
175 binEntries(AIDA::IAxis::OVERFLOW_BIN);
177 template <
class INTERFACE,
class IMPLEMENTATION>
184 template <
class INTERFACE,
class IMPLEMENTATION>
186 if (sumBinHeights() <= 0)
return 0;
188 m_rep->GetStats(stats);
189 return stats[0]*stats[0]/stats[1];
192 template <
class INTERFACE,
class IMPLEMENTATION>
194 m_rep->Scale ( scaleFactor );
198 template <
class INTERFACE,
class IMPLEMENTATION>
203 m_rep->Add(p->
m_rep.get());
206 throw std::runtime_error(
"Cannot add profile histograms of different implementations.");
209 template <
class INTERFACE,
class IMPLEMENTATION>
217 template <
class INTERFACE,
class IMPLEMENTATION>
219 s <<
"\n1D Histogram Table: " << std::endl;
220 s <<
"Bin, Height, Error " << std::endl;
221 for(
int i = 0;
i < axis().bins(); ++
i )
222 s << binMean(
i ) <<
", "
223 << binHeight(
i ) <<
", "
224 << binError (
i ) << std::endl;
230 template <
class INTERFACE,
class IMPLEMENTATION>
233 TFile *f = TFile::Open(file_name,
"RECREATE");
234 Int_t nbytes = m_rep->Write();
241 #pragma clang diagnostic pop
244 #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 override
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 Axis & axis() const override
Get the x axis of the IHistogram1D.
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.
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.