| The Gaudi Framework v29r0 (ff2e7097)

- 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 "AIDA/IProfile1D.h"
5 #include "Annotation.h"
6 #include "Axis.h"
7 #include "GaudiKernel/HistogramBase.h"
8 #include "TFile.h"
9 #include <memory>
10 #include <stdexcept>
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 {
24
35 template <class INTERFACE, class IMPLEMENTATION>
36 class GAUDI_API Generic1D : virtual public INTERFACE, virtual public HistogramBase
37 {
38 public:
39 typedef Generic1D<INTERFACE, IMPLEMENTATION> Base;
41 Generic1D() = default;
42
43 protected:
45 Generic1D( IMPLEMENTATION* p ) : m_rep( p ) {}
46
47 public:
49 ~Generic1D() override = default;
51 virtual const std::string& userLevelClassType() const { return m_classType; }
53 void* cast( const std::string& cl ) const override;
55 TObject* representation() const override { return m_rep.get(); }
57 void adoptRepresentation( TObject* rep ) override;
59 std::string title() const override { return m_annotation.value( "Title" ); }
61 bool setTitle( const std::string& title ) override;
63 std::string name() const { return m_annotation.value( "Name" ); }
65 bool setName( const std::string& newName );
67 AIDA::IAnnotation& annotation() override { return m_annotation; }
69 const AIDA::IAnnotation& annotation() const override { return m_annotation; }
71 Axis& axis() { return m_axis; }
73 const Axis& axis() const override { return m_axis; }
74
76 int entries() const override { return m_rep->GetEntries(); }
78 int allEntries() const override { return m_rep->GetEntries(); }
80 int extraEntries() const override;
82 int binEntries( int index ) const override;
83 // spread
84 virtual double binRms( int index ) const;
86 double sumBinHeights() const override { return m_rep->GetSumOfWeights(); }
88 double sumAllBinHeights() const override { return m_rep->GetSum(); }
90 double sumExtraBinHeights() const override { return sumAllBinHeights() - sumBinHeights(); }
92 double minBinHeight() const override { return m_rep->GetMinimum(); }
94 double maxBinHeight() const override { return m_rep->GetMaximum(); }
95
97 virtual double equivalentBinEntries() const;
100 virtual bool scale( double scaleFactor );
102 bool reset() override;
104 bool add( const INTERFACE& profile ) override;
106 virtual int rIndex( int index ) const { return m_axis.rIndex( index ); }
108 double binMean( int index ) const override;
110 double binHeight( int index ) const override;
112 double binError( int index ) const override;
114 double mean() const override { return m_rep->GetMean(); }
116 double rms() const override { return m_rep->GetRMS(); }
118 int coordToIndex( double coord ) const override { return axis().coordToIndex( coord ); }
120 int dimension() const override { return 1; }
122 std::ostream& print( std::ostream& s ) const override;
124 std::ostream& write( std::ostream& s ) const override;
126 int write( const char* file_name ) const override;
127
128 protected:
130 Axis m_axis;
132 mutable AIDA::Annotation m_annotation;
134 std::unique_ptr<IMPLEMENTATION> m_rep;
135 // class type
136 std::string m_classType;
137 // cache sumEntries (allEntries) when setting contents since Root can't compute by himself
138 int m_sumEntries;
139 }; // end class Generic1D
140
141 template <class INTERFACE, class IMPLEMENTATION>
142 bool Generic1D<INTERFACE, IMPLEMENTATION>::setTitle( const std::string& title )
143 {
144 m_rep->SetTitle( title.c_str() );
145 if ( !annotation().addItem( "Title", title ) ) m_annotation.setValue( "Title", title );
146 if ( !annotation().addItem( "title", title ) ) annotation().setValue( "title", title );
147 return true;
148 }
149
150 template <class INTERFACE, class IMPLEMENTATION>
151 bool Generic1D<INTERFACE, IMPLEMENTATION>::setName( const std::string& newName )
152 {
153 m_rep->SetName( newName.c_str() );
154 m_annotation.setValue( "Name", newName );
155 return true;
156 }
157
158 template <class INTERFACE, class IMPLEMENTATION>
159 double Generic1D<INTERFACE, IMPLEMENTATION>::binRms( int index ) const
160 {
161 return m_rep->GetBinError( rIndex( index ) );
162 }
163
164 template <class INTERFACE, class IMPLEMENTATION>
165 double Generic1D<INTERFACE, IMPLEMENTATION>::binMean( int index ) const
166 {
167 return m_rep->GetBinCenter( rIndex( index ) );
168 }
169
170 template <class INTERFACE, class IMPLEMENTATION>
171 double Generic1D<INTERFACE, IMPLEMENTATION>::binHeight( int index ) const
172 {
173 return m_rep->GetBinContent( rIndex( index ) );
174 }
175
176 template <class INTERFACE, class IMPLEMENTATION>
177 double Generic1D<INTERFACE, IMPLEMENTATION>::binError( int index ) const
178 {
179 return m_rep->GetBinError( rIndex( index ) );
180 }
181
182 template <class INTERFACE, class IMPLEMENTATION>
183 int Generic1D<INTERFACE, IMPLEMENTATION>::extraEntries() const
184 {
185 return binEntries( AIDA::IAxis::UNDERFLOW_BIN ) + binEntries( AIDA::IAxis::OVERFLOW_BIN );
186 }
187 template <class INTERFACE, class IMPLEMENTATION>
188 bool Generic1D<INTERFACE, IMPLEMENTATION>::reset()
189 {
190 m_sumEntries = 0;
191 m_rep->Reset();
192 return true;
193 }
194
195 template <class INTERFACE, class IMPLEMENTATION>
196 double Generic1D<INTERFACE, IMPLEMENTATION>::equivalentBinEntries() const
197 {
198 if ( sumBinHeights() <= 0 ) return 0;
199 Stat_t stats[11]; // cover up to 3D...
200 m_rep->GetStats( stats );
201 return stats[0] * stats[0] / stats[1];
202 }
203
204 template <class INTERFACE, class IMPLEMENTATION>
205 bool Generic1D<INTERFACE, IMPLEMENTATION>::scale( double scaleFactor )
206 {
207 m_rep->Scale( scaleFactor );
208 return true;
209 }
210
211 template <class INTERFACE, class IMPLEMENTATION>
212 bool Generic1D<INTERFACE, IMPLEMENTATION>::add( const INTERFACE& h )
213 {
214 const Generic1D<INTERFACE, IMPLEMENTATION>* p = dynamic_cast<const Generic1D<INTERFACE, IMPLEMENTATION>*>( &h );
215 if ( p ) {
216 m_rep->Add( p->m_rep.get() );
217 return true;
218 }
219 throw std::runtime_error( "Cannot add profile histograms of different implementations." );
220 }
221
222 template <class INTERFACE, class IMPLEMENTATION>
223 std::ostream& Generic1D<INTERFACE, IMPLEMENTATION>::print( std::ostream& s ) const
224 {
226 m_rep->Print( "all" );
227 return s;
228 }
229
231 template <class INTERFACE, class IMPLEMENTATION>
232 std::ostream& Generic1D<INTERFACE, IMPLEMENTATION>::write( std::ostream& s ) const
233 {
234 s << "\n1D Histogram Table: " << std::endl;
235 s << "Bin, Height, Error " << std::endl;
236 for ( int i = 0; i < axis().bins(); ++i )
237 s << binMean( i ) << ", " << binHeight( i ) << ", " << binError( i ) << std::endl;
238 s << std::endl;
239 return s;
240 }
241
243 template <class INTERFACE, class IMPLEMENTATION>
244 int Generic1D<INTERFACE, IMPLEMENTATION>::write( const char* file_name ) const
245 {
246 TFile* f = TFile::Open( file_name, "RECREATE" );
247 Int_t nbytes = m_rep->Write();
248 f->Close();
249 return nbytes;
250 }
251 }
252
253 #ifdef __clang__
254 #pragma clang diagnostic pop
255 #elif defined( __GNUC__ ) && __GNUC__ >= 5
256 #pragma GCC diagnostic pop
257 #endif
258
259 #endif // AIDAROOT_GENERIC1D_H
Gaudi::Generic1D::title
std::string title() const override
Get the title of the object.
Definition: Generic1D.h:59
Gaudi::Generic1D::write
std::ostream & write(std::ostream &s) const override
Write (ASCII) the histogram table into the output stream.
Definition: Generic1D.h:232
Gaudi::Generic1D::entries
int entries() const override
Get the number or all the entries.
Definition: Generic1D.h:76
Gaudi::Generic1D::reset
bool reset() override
Reset the Histogram; as if just created.
Definition: Generic1D.h:188
Gaudi::Generic1D::maxBinHeight
double maxBinHeight() const override
Get the maximum height of the in-range bins.
Definition: Generic1D.h:94
Gaudi::Generic1D::sumBinHeights
double sumBinHeights() const override
Get the sum of in range bin heights in the IProfile.
Definition: Generic1D.h:86
Gaudi::Generic1D::m_classType
std::string m_classType
Definition: Generic1D.h:136
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:171
Gaudi::Generic1D::sumExtraBinHeights
double sumExtraBinHeights() const override
Get the sum of the underflow and overflow bin height.
Definition: Generic1D.h:90
Gaudi::Generic1D::extraEntries
int extraEntries() const override
Get the number of entries in the underflow and overflow bins.
Definition: Generic1D.h:183
Gaudi::Generic1D::binError
double binError(int index) const override
The error of a given bin.
Definition: Generic1D.h:177
std::string
STL class.
Gaudi::Generic1D::binRms
virtual double binRms(int index) const
Definition: Generic1D.h:159
Gaudi::Generic1D::axis
const Axis & axis() const override
Get the x axis of the IHistogram1D.
Definition: Generic1D.h:73
Gaudi::Generic1D::axis
Axis & axis()
Access to axis object.
Definition: Generic1D.h:71
GaudiPython.Persistency.add
def add(instance)
Definition: Persistency.py:39
Gaudi::Generic1D::m_rep
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic1D.h:134
Gaudi::Generic1D::m_annotation
AIDA::Annotation m_annotation
Object annotations.
Definition: Generic1D.h:132
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:212
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:142
Gaudi::Generic1D::annotation
const AIDA::IAnnotation & annotation() const override
Access annotation object (cons)
Definition: Generic1D.h:69
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:78
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:88
Gaudi::Generic1D::Generic1D
Generic1D(IMPLEMENTATION *p)
constructor
Definition: Generic1D.h:45
AIDA::Annotation
Implementation of the AIDA IAnnotation interface class.
Definition: Annotation.h:17
Gaudi::Generic1D::m_axis
Axis m_axis
Axis member.
Definition: Generic1D.h:130
Gaudi::Generic1D::dimension
int dimension() const override
Get the Histogram&#39;s dimension.
Definition: Generic1D.h:120
Gaudi::Generic1D::minBinHeight
double minBinHeight() const override
Get the minimum height of the in-range bins.
Definition: Generic1D.h:92
Gaudi::Generic1D::rms
double rms() const override
The RMS of the whole IHistogram1D.
Definition: Generic1D.h:116
Gaudi::Generic1D::m_sumEntries
int m_sumEntries
Definition: Generic1D.h:138
Gaudi::Generic1D::userLevelClassType
virtual const std::string & userLevelClassType() const
The AIDA user-level unterface leaf class type.
Definition: Generic1D.h:51
Gaudi::Generic1D::print
std::ostream & print(std::ostream &s) const override
Print (ASCII) the histogram into the output stream.
Definition: Generic1D.h:223
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:23
Gaudi::Generic1D::representation
TObject * representation() const override
ROOT object implementation.
Definition: Generic1D.h:55
std::unique_ptr< IMPLEMENTATION >
Gaudi::Generic1D::binMean
double binMean(int index) const override
The weighted mean of a bin.
Definition: Generic1D.h:165
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:118
print
void print(string text)
Definition: mergesort.cpp:30
std::string::c_str
T c_str(T...args)
GaudiPython.GaudiAlgs.write
write
Definition: GaudiAlgs.py:1259
gaudirun.s
string s
Definition: gaudirun.py:253
Gaudi::Generic1D::equivalentBinEntries
virtual double equivalentBinEntries() const
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
Definition: Generic1D.h:196
Gaudi::Generic1D::rIndex
virtual int rIndex(int index) const
operator methods
Definition: Generic1D.h:106
Gaudi::Generic1D::annotation
AIDA::IAnnotation & annotation() override
Access annotation object.
Definition: Generic1D.h:67
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:110
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:30
Annotation.h
Gaudi::Generic1D::mean
double mean() const override
The mean of the whole IHistogram1D.
Definition: Generic1D.h:114
Gaudi::Generic1D::setName
bool setName(const std::string &newName)
Set the name of the object.
Definition: Generic1D.h:151
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:205
Gaudi::Generic1D::name
std::string name() const
object name
Definition: Generic1D.h:63
Gaudi::Generic1D::Base
Generic1D< INTERFACE, IMPLEMENTATION > Base
Definition: Generic1D.h:39
Gaudi::Generic1D
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
Definition: Generic1D.h:36