| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Generic1D.h
Go to the documentation of this file.
1 #ifndef GAUDISVC_GENERIC1D_H
2 #define GAUDISVC_GENERIC1D_H 1
3
4 #include <stdexcept>
5 #include <memory>
6 #include "Axis.h"
7 #include "Annotation.h"
8 #include "GaudiKernel/HistogramBase.h"
9 #include "AIDA/IProfile1D.h"
10 #include "TFile.h"
11
12 // Hide warning message:
13 // warning: 'XYZ' overrides a member function but is not marked 'override'
14 #ifdef __clang__
15 #pragma clang diagnostic push
16 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
17 #elif defined(__GNUC__) && __GNUC__ >= 5
18 #pragma GCC diagnostic push
19 #pragma GCC diagnostic ignored "-Wsuggest-override"
20 #endif
21
22 namespace Gaudi {
23
34 template <class INTERFACE, class IMPLEMENTATION>
35 class GAUDI_API Generic1D : virtual public INTERFACE, virtual public HistogramBase {
36 public:
37 typedef Generic1D<INTERFACE,IMPLEMENTATION> Base;
39 Generic1D() = default;
40 protected:
42 Generic1D(IMPLEMENTATION* p) : m_rep(p) { }
43 public:
45 ~Generic1D() override = default ;
47 virtual const std::string& userLevelClassType() const { return m_classType; }
49 void* cast(const std::string& cl) const override;
51 TObject* representation() const override { return m_rep.get(); }
53 void adoptRepresentation(TObject*rep) override;
55 std::string title() const override { return m_annotation.value("Title"); }
57 bool setTitle(const std::string & title) override;
59 std::string name() const { return m_annotation.value("Name"); }
61 bool setName( const std::string& newName );
63 AIDA::IAnnotation & annotation() override { return m_annotation; }
65 const AIDA::IAnnotation & annotation() const override { return m_annotation; }
67 Axis & axis () { return m_axis; }
69 const Axis & axis () const override { return m_axis; }
70
72 int entries() const override { return m_rep->GetEntries(); }
74 int allEntries() const override { return m_rep->GetEntries(); }
76 int extraEntries() const override;
78 int binEntries ( int index ) const override;
79 // spread
80 virtual double binRms(int index) const;
82 double sumBinHeights() const override { return m_rep->GetSumOfWeights(); }
84 double sumAllBinHeights() const override { return m_rep->GetSum(); }
86 double sumExtraBinHeights () const override { return sumAllBinHeights()-sumBinHeights(); }
88 double minBinHeight() const override { return m_rep->GetMinimum(); }
90 double maxBinHeight() const override { return m_rep->GetMaximum(); }
91
93 virtual double equivalentBinEntries ( ) const;
95 virtual bool scale( double scaleFactor ) ;
97 bool reset() override;
99 bool add(const INTERFACE & profile) override;
101 virtual int rIndex(int index) const { return m_axis.rIndex(index);}
103 double binMean(int index) const override;
105 double binHeight(int index) const override;
107 double binError(int index) const override;
109 double mean() const override { return m_rep->GetMean(); }
111 double rms () const override { return m_rep->GetRMS(); }
113 int coordToIndex ( double coord ) const override{ return axis().coordToIndex(coord);}
115 int dimension ( ) const override { return 1; }
117 std::ostream& print( std::ostream& s ) const override;
119 std::ostream& write( std::ostream& s ) const override;
121 int write( const char* file_name ) const override;
122
123 protected:
125 Axis m_axis;
127 mutable AIDA::Annotation m_annotation;
129 std::unique_ptr<IMPLEMENTATION> m_rep;
130 // class type
131 std::string m_classType;
132 // cache sumEntries (allEntries) when setting contents since Root can't compute by himself
133 int m_sumEntries;
134 }; // end class Generic1D
135
136 template <class INTERFACE, class IMPLEMENTATION>
137 bool Generic1D<INTERFACE,IMPLEMENTATION>::setTitle(const std::string & title) {
138 m_rep->SetTitle(title.c_str());
139 if ( !annotation().addItem( "Title", title ) )
140 m_annotation.setValue( "Title" , title );
141 if ( !annotation().addItem( "title", title ) )
142 annotation().setValue( "title", title );
143 return true;
144 }
145
146 template <class INTERFACE, class IMPLEMENTATION>
147 bool Generic1D<INTERFACE,IMPLEMENTATION>::setName( const std::string& newName ) {
148 m_rep->SetName(newName.c_str());
149 m_annotation.setValue( "Name", newName );
150 return true;
151 }
152
153 template <class INTERFACE, class IMPLEMENTATION>
154 double Generic1D<INTERFACE,IMPLEMENTATION>::binRms(int index) const {
155 return m_rep->GetBinError ( rIndex(index) );
156 }
157
158 template <class INTERFACE, class IMPLEMENTATION>
159 double Generic1D<INTERFACE,IMPLEMENTATION>::binMean ( int index ) const {
160 return m_rep->GetBinCenter ( rIndex(index) );
161 }
162
163 template <class INTERFACE, class IMPLEMENTATION>
164 double Generic1D<INTERFACE,IMPLEMENTATION>::binHeight ( int index ) const {
165 return m_rep->GetBinContent ( rIndex(index) );
166 }
167
168 template <class INTERFACE, class IMPLEMENTATION>
169 double Generic1D<INTERFACE,IMPLEMENTATION>::binError ( int index ) const {
170 return m_rep->GetBinError ( rIndex(index) );
171 }
172
173 template <class INTERFACE, class IMPLEMENTATION>
174 int Generic1D<INTERFACE,IMPLEMENTATION>::extraEntries() const {
175 return binEntries(AIDA::IAxis::UNDERFLOW_BIN) +
176 binEntries(AIDA::IAxis::OVERFLOW_BIN);
177 }
178 template <class INTERFACE, class IMPLEMENTATION>
179 bool Generic1D<INTERFACE,IMPLEMENTATION>::reset() {
180 m_sumEntries = 0;
181 m_rep->Reset();
182 return true;
183 }
184
185 template <class INTERFACE, class IMPLEMENTATION>
186 double Generic1D<INTERFACE,IMPLEMENTATION>::equivalentBinEntries() const {
187 if (sumBinHeights() <= 0) return 0;
188 Stat_t stats[11]; // cover up to 3D...
189 m_rep->GetStats(stats);
190 return stats[0]*stats[0]/stats[1];
191 }
192
193 template <class INTERFACE, class IMPLEMENTATION>
194 bool Generic1D<INTERFACE,IMPLEMENTATION>::scale(double scaleFactor) {
195 m_rep->Scale ( scaleFactor );
196 return true;
197 }
198
199 template <class INTERFACE, class IMPLEMENTATION>
200 bool Generic1D<INTERFACE,IMPLEMENTATION>::add(const INTERFACE & h) {
201 const Generic1D<INTERFACE,IMPLEMENTATION>* p =
202 dynamic_cast<const Generic1D<INTERFACE,IMPLEMENTATION>*>(&h);
203 if ( p ) {
204 m_rep->Add(p->m_rep.get());
205 return true;
206 }
207 throw std::runtime_error("Cannot add profile histograms of different implementations.");
208 }
209
210 template <class INTERFACE, class IMPLEMENTATION>
211 std::ostream& Generic1D<INTERFACE,IMPLEMENTATION>::print( std::ostream& s ) const {
213 m_rep->Print("all");
214 return s;
215 }
216
218 template <class INTERFACE, class IMPLEMENTATION>
219 std::ostream& Generic1D<INTERFACE,IMPLEMENTATION>::write( std::ostream& s ) const {
220 s << "\n1D Histogram Table: " << std::endl;
221 s << "Bin, Height, Error " << std::endl;
222 for( int i = 0; i < axis().bins(); ++i )
223 s << binMean( i ) << ", "
224 << binHeight( i ) << ", "
225 << binError ( i ) << std::endl;
226 s << std::endl;
227 return s;
228 }
229
231 template <class INTERFACE, class IMPLEMENTATION>
232 int Generic1D<INTERFACE,IMPLEMENTATION>::write( const char* file_name ) const
233 {
234 TFile *f = TFile::Open(file_name,"RECREATE");
235 Int_t nbytes = m_rep->Write();
236 f->Close();
237 return nbytes;
238 }
239 }
240
241 #ifdef __clang__
242 #pragma clang diagnostic pop
243 #elif defined(__GNUC__) && __GNUC__ >= 5
244 #pragma GCC diagnostic pop
245 #endif
246
247 #endif // AIDAROOT_GENERIC1D_H
Gaudi::Generic1D::title
std::string title() const override
Get the title of the object.
Definition: Generic1D.h:55
Gaudi::Generic1D::write
std::ostream & write(std::ostream &s) const override
Write (ASCII) the histogram table into the output stream.
Definition: Generic1D.h:219
gaudirun.default
default
Definition: gaudirun.py:141
Gaudi::Generic1D::entries
int entries() const override
Get the number or all the entries.
Definition: Generic1D.h:72
Gaudi::Generic1D::reset
bool reset() override
Reset the Histogram; as if just created.
Definition: Generic1D.h:179
Gaudi::Generic1D::maxBinHeight
double maxBinHeight() const override
Get the maximum height of the in-range bins.
Definition: Generic1D.h:90
Gaudi::Generic1D::sumBinHeights
double sumBinHeights() const override
Get the sum of in range bin heights in the IProfile.
Definition: Generic1D.h:82
Gaudi::Generic1D::m_classType
std::string m_classType
Definition: Generic1D.h:131
std::endl
T endl(T...args)
Gaudi::Generic1D::binHeight
double binHeight(int index) const override
Total height of the corresponding bin (ie the sum of the weights in this bin).
Definition: Generic1D.h:164
Gaudi::Generic1D::sumExtraBinHeights
double sumExtraBinHeights() const override
Get the sum of the underflow and overflow bin height.
Definition: Generic1D.h:86
Gaudi::Generic1D::extraEntries
int extraEntries() const override
Get the number of entries in the underflow and overflow bins.
Definition: Generic1D.h:174
Gaudi::Generic1D::binError
double binError(int index) const override
The error of a given bin.
Definition: Generic1D.h:169
std::string
STL class.
Gaudi::Generic1D::binRms
virtual double binRms(int index) const
Definition: Generic1D.h:154
Gaudi::Generic1D::axis
const Axis & axis() const override
Get the x axis of the IHistogram1D.
Definition: Generic1D.h:69
Gaudi::Generic1D::axis
Axis & axis()
Access to axis object.
Definition: Generic1D.h:67
GaudiPython.Persistency.add
def add(instance)
Definition: Persistency.py:32
Gaudi::Generic1D::m_rep
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic1D.h:129
Gaudi::Generic1D::m_annotation
AIDA::Annotation m_annotation
Object annotations.
Definition: Generic1D.h:127
HistogramBase.h
Axis.h
Gaudi::Generic1D::add
bool add(const INTERFACE &profile) override
Modifies this IProfile1D by adding the contents of profile to it.
Definition: Generic1D.h:200
HiveAlgSequencer.h
h
Definition: HiveAlgSequencer.py:24
Gaudi::Generic1D::setTitle
bool setTitle(const std::string &title) override
Set the title of the object.
Definition: Generic1D.h:137
Gaudi::Generic1D::annotation
const AIDA::IAnnotation & annotation() const override
Access annotation object (cons)
Definition: Generic1D.h:65
Gaudi::Generic1D::allEntries
int allEntries() const override
Get the number or all the entries, both in range and underflow/overflow bins of the IProfile...
Definition: Generic1D.h:74
std::runtime_error
STL class.
Gaudi::Generic1D::sumAllBinHeights
double sumAllBinHeights() const override
Get the sum of all the bins heights (including underflow and overflow bin).
Definition: Generic1D.h:84
Gaudi::Generic1D::Generic1D
Generic1D(IMPLEMENTATION *p)
constructor
Definition: Generic1D.h:42
AIDA::Annotation
Implementation of the AIDA IAnnotation interface class.
Definition: Annotation.h:16
Gaudi::Generic1D::m_axis
Axis m_axis
Axis member.
Definition: Generic1D.h:125
Gaudi::Generic1D::dimension
int dimension() const override
Get the Histogram&#39;s dimension.
Definition: Generic1D.h:115
Gaudi::Generic1D::minBinHeight
double minBinHeight() const override
Get the minimum height of the in-range bins.
Definition: Generic1D.h:88
Gaudi::Generic1D::Base
Generic1D< INTERFACE, IMPLEMENTATION > Base
Definition: Generic1D.h:37
Gaudi::Generic1D::rms
double rms() const override
The RMS of the whole IHistogram1D.
Definition: Generic1D.h:111
Gaudi::Generic1D::m_sumEntries
int m_sumEntries
Definition: Generic1D.h:133
Gaudi::Generic1D::userLevelClassType
virtual const std::string & userLevelClassType() const
The AIDA user-level unterface leaf class type.
Definition: Generic1D.h:47
Gaudi::Generic1D::print
std::ostream & print(std::ostream &s) const override
Print (ASCII) the histogram into the output stream.
Definition: Generic1D.h:211
std::unique_ptr::get
T get(T...args)
Gaudi::HistogramBase
Common base class for all histograms Use is solely functional to minimize dynamic_casts inside Histog...
Definition: HistogramBase.h:22
Gaudi::Generic1D::representation
TObject * representation() const override
ROOT object implementation.
Definition: Generic1D.h:51
std::unique_ptr< IMPLEMENTATION >
Gaudi::Generic1D::binMean
double binMean(int index) const override
The weighted mean of a bin.
Definition: Generic1D.h:159
Gaudi::Generic1D::coordToIndex
int coordToIndex(double coord) const override
Get the bin number corresponding to a given coordinate along the x axis.
Definition: Generic1D.h:113
print
void print(string text)
Definition: mergesort.cpp:33
std::string::c_str
T c_str(T...args)
GaudiPython.GaudiAlgs.write
write
Definition: GaudiAlgs.py:1144
gaudirun.s
string s
Definition: gaudirun.py:245
Gaudi::Generic1D::equivalentBinEntries
virtual double equivalentBinEntries() const
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
Definition: Generic1D.h:186
Gaudi::Generic1D::rIndex
virtual int rIndex(int index) const
operator methods
Definition: Generic1D.h:101
Gaudi::Generic1D::annotation
AIDA::IAnnotation & annotation() override
Access annotation object.
Definition: Generic1D.h:63
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:107
std::ostream
STL class.
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
Gaudi::Axis
An IAxis represents a binned histogram axis.
Definition: Axis.h:29
Annotation.h
Gaudi::Generic1D::mean
double mean() const override
The mean of the whole IHistogram1D.
Definition: Generic1D.h:109
Gaudi::Generic1D::setName
bool setName(const std::string &newName)
Set the name of the object.
Definition: Generic1D.h:147
Gaudi::Generic1D::scale
virtual bool scale(double scaleFactor)
Scale the weights and the errors of all the IHistogram&#39;s bins (in-range and out-of-range ones) by a g...
Definition: Generic1D.h:194
Gaudi::Generic1D::name
std::string name() const
object name
Definition: Generic1D.h:59
Gaudi::Generic1D
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
Definition: Generic1D.h:35