| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Generic2D.h
Go to the documentation of this file.
1 #ifndef GAUDISVC_GENERIC2D_H
2 #define GAUDISVC_GENERIC2D_H 1
3
4 #include "AIDA_visibility_hack.h"
5
6 #include <stdexcept>
7 #include "AIDA/IProfile2D.h"
8 #include "GaudiKernel/HistogramBase.h"
9 #include "Annotation.h"
10 #include "Axis.h"
11 #include "TFile.h"
12
13
14 /*
15 * Gaudi namespace
16 */
17 namespace Gaudi {
18
29 template <class INTERFACE, class IMPLEMENTATION>
30 class GAUDI_API Generic2D : virtual public INTERFACE, virtual public HistogramBase {
31 public:
32 typedef Generic2D<INTERFACE,IMPLEMENTATION> Base;
33
34 Generic2D() : m_rep(0) {}
35
37 virtual ~Generic2D() { delete m_rep; }
38
40 TObject* representation() const { return m_rep; }
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; }
55
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); }
64
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;
76 virtual double sumExtraBinHeights ( ) const { return sumAllBinHeights()-sumBinHeights(); }
78 virtual double minBinHeight() const;
80 virtual double maxBinHeight() const;
81
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);
120 // overwrite reset
121 bool reset ( );
123 void * cast(const std::string & className) const;
125 const std::string& userLevelClassType() const { return m_classType; }
127 virtual int dimension() const { return 2; }
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;
134
135 protected:
137 Axis m_xAxis;
139 Axis m_yAxis;
141 mutable AIDA::Annotation m_annotation;
143 IMPLEMENTATION* m_rep;
145 std::string m_classType;
147 int m_sumEntries;
148 };
149
150 template <class INTERFACE, class IMPLEMENTATION>
151 bool Generic2D<INTERFACE,IMPLEMENTATION>::setTitle(const std::string & title) {
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 );
157 return true;
158 }
159
160 template <class INTERFACE, class IMPLEMENTATION>
161 bool Generic2D<INTERFACE,IMPLEMENTATION>::setName( const std::string& newName ) {
162 m_rep->SetName(newName.c_str());
163 m_annotation.setValue( "Name", newName );
164 return true;
165 }
166
167 template <class INTERFACE, class IMPLEMENTATION>
168 int Generic2D<INTERFACE,IMPLEMENTATION>::entries() const {
169 return (int)m_rep->GetEntries();
170 }
171
172 template <class INTERFACE, class IMPLEMENTATION>
173 int Generic2D<INTERFACE,IMPLEMENTATION>::allEntries ( ) const {
174 return int(m_rep->GetEntries());
175 }
176
177 template <class INTERFACE, class IMPLEMENTATION>
178 double Generic2D<INTERFACE,IMPLEMENTATION>::minBinHeight() const {
179 return m_rep->GetMinimum();
180 }
181
182 template <class INTERFACE, class IMPLEMENTATION>
183 double Generic2D<INTERFACE,IMPLEMENTATION>::maxBinHeight() const {
184 return m_rep->GetMaximum();
185 }
186
187 template <class INTERFACE, class IMPLEMENTATION>
188 double Generic2D<INTERFACE,IMPLEMENTATION>::sumBinHeights () const {
189 return m_rep->GetSumOfWeights();
190 }
191
192 template <class INTERFACE, class IMPLEMENTATION>
193 double Generic2D<INTERFACE,IMPLEMENTATION>::sumAllBinHeights () const {
194 return m_rep->GetSum();
195 }
196
197 template <class INTERFACE, class IMPLEMENTATION>
198 double Generic2D<INTERFACE,IMPLEMENTATION>::binRms(int indexX,int indexY) const {
199 return m_rep->GetBinError ( rIndexX(indexX), rIndexY(indexY) );
200 }
201
202 template <class INTERFACE, class IMPLEMENTATION>
203 double Generic2D<INTERFACE,IMPLEMENTATION>::binMeanX(int indexX,int ) const {
204 return (m_rep->GetXaxis())->GetBinCenter( rIndexX(indexX) );
205 }
206
207 template <class INTERFACE, class IMPLEMENTATION>
208 double Generic2D<INTERFACE,IMPLEMENTATION>::binMeanY(int,int indexY) const {
209 return (m_rep->GetYaxis())->GetBinCenter( rIndexY(indexY) );
210 }
211
212 template <class INTERFACE, class IMPLEMENTATION>
213 int Generic2D<INTERFACE,IMPLEMENTATION>::binEntriesX(int index) const {
214 int n = 0;
215 for (int iY = -2; iY < yAxis().bins(); ++iY)
216 n += binEntries(index,iY);
217 return n;
218 }
219
220 template <class INTERFACE, class IMPLEMENTATION>
221 int Generic2D<INTERFACE,IMPLEMENTATION>::binEntriesY(int index) const {
222 int n = 0;
223 for (int iX = -2; iX < xAxis().bins(); ++iX)
224 n += binEntries(iX,index);
225 return n;
226 }
227
228 template <class INTERFACE, class IMPLEMENTATION>
229 double Generic2D<INTERFACE,IMPLEMENTATION>::binHeight ( int indexX,int indexY ) const {
230 return m_rep->GetBinContent ( rIndexX(indexX), rIndexY(indexY) );
231 }
232
233 template <class INTERFACE, class IMPLEMENTATION>
234 double Generic2D<INTERFACE,IMPLEMENTATION>::binHeightX(int index) const {
235 double s = 0;
236 for (int iY = -2; iY < yAxis().bins(); ++iY) {
237 s += binHeight(index,iY);
238 }
239 return s;
240 }
241
242 template <class INTERFACE, class IMPLEMENTATION>
243 double Generic2D<INTERFACE,IMPLEMENTATION>::binHeightY(int index) const {
244 double s = 0;
245 for (int iX = -2; iX < xAxis().bins(); ++iX)
246 s += binHeight(iX,index);
247 return s;
248 }
249
250 template <class INTERFACE, class IMPLEMENTATION>
251 double Generic2D<INTERFACE,IMPLEMENTATION>::binError(int indexX,int indexY) const {
252 return m_rep->GetBinError ( rIndexX(indexX), rIndexY(indexY ) );
253 }
254
255 template <class INTERFACE, class IMPLEMENTATION>
256 double Generic2D<INTERFACE,IMPLEMENTATION>::meanX() const {
257 return m_rep->GetMean(1);
258 }
259
260 template <class INTERFACE, class IMPLEMENTATION>
261 double Generic2D<INTERFACE,IMPLEMENTATION>::meanY() const {
262 return m_rep->GetMean(2);
263 }
264
265 template <class INTERFACE, class IMPLEMENTATION>
266 double Generic2D<INTERFACE,IMPLEMENTATION>::rmsX() const {
267 return m_rep->GetRMS(1);
268 }
269
270 template <class INTERFACE, class IMPLEMENTATION>
271 double Generic2D<INTERFACE,IMPLEMENTATION>::rmsY() const {
272 return m_rep->GetRMS(2);
273 }
274
275 template <class INTERFACE, class IMPLEMENTATION>
276 int Generic2D<INTERFACE,IMPLEMENTATION>::coordToIndexX ( double coord ) const {
277 return xAxis().coordToIndex(coord);
278 }
279
280 template <class INTERFACE, class IMPLEMENTATION>
281 int Generic2D<INTERFACE,IMPLEMENTATION>::coordToIndexY ( double coord ) const {
282 return yAxis().coordToIndex(coord);
283 }
284
285 template <class INTERFACE, class IMPLEMENTATION>
286 bool Generic2D<INTERFACE,IMPLEMENTATION>::add ( const INTERFACE & hist ) {
287 const Base* p = dynamic_cast<const Base*>(&hist);
288 if ( p ) {
289 m_rep->Add(p->m_rep);
290 return true;
291 }
292 throw std::runtime_error("Cannot add profile histograms of different implementations.");
293 }
294
295 template <class INTERFACE, class IMPLEMENTATION>
296 int Generic2D<INTERFACE,IMPLEMENTATION>::extraEntries() const {
297 return
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);
302 }
303
304 template <class INTERFACE, class IMPLEMENTATION>
305 double Generic2D<INTERFACE,IMPLEMENTATION>::equivalentBinEntries() const {
306 if (sumBinHeights() <= 0) return 0;
307 Stat_t stats[11]; // cover up to 3D...
308 m_rep->GetStats(stats);
309 return stats[0]*stats[0]/stats[1];
310 }
311
312 template <class INTERFACE, class IMPLEMENTATION>
313 bool Generic2D<INTERFACE,IMPLEMENTATION>::scale(double scaleFactor) {
314 m_rep->Scale ( scaleFactor );
315 return true;
316 }
317
318 template <class INTERFACE, class IMPLEMENTATION>
319 bool Generic2D<INTERFACE,IMPLEMENTATION>::reset ( ) {
320 m_sumEntries = 0;
321 m_rep->Reset ( );
322 return true;
323 }
324
325 template <class INTERFACE, class IMPLEMENTATION>
326 std::ostream& Generic2D<INTERFACE,IMPLEMENTATION>::print( std::ostream& s ) const
327 {
329 m_rep->Print("all");
330 return s;
331 }
332
334 template <class INTERFACE, class IMPLEMENTATION>
335 std::ostream& Generic2D<INTERFACE,IMPLEMENTATION>::write( std::ostream& s ) const
336 {
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;
345 }
346 }
347 s << std::endl;
348 return s;
349 }
350
352 template <class INTERFACE, class IMPLEMENTATION>
353 int Generic2D<INTERFACE,IMPLEMENTATION>::write( const char* file_name ) const
354 {
355 TFile *f = TFile::Open(file_name,"RECREATE");
356 Int_t nbytes = m_rep->Write();
357 f->Close();
358 return nbytes;
359 }
360 } // end namespace AIDA
361 #endif // GAUDIPI_GENERIC2D_H