| # 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
P1D.cpp
Go to the documentation of this file.
1 #ifdef __ICC
2 // disable icc remark #2259: non-pointer conversion from "X" to "Y" may lose significant bits
3 // TODO: To be removed, since it comes from ROOT TMathBase.h
4 #pragma warning(disable:2259)
5 #endif
6 #ifdef WIN32
7 // Disable warning
8 // warning C4996: 'sprintf': This function or variable may be unsafe.
9 // coming from TString.h
10 #pragma warning(disable:4996)
11 #endif
12
13 #include <cmath>
14 #include "P1D.h"
15 #include "GaudiKernel/ObjectFactory.h"
16
17 std::pair<DataObject*,AIDA::IProfile1D*> Gaudi::createProf1D
18 ( const std::string& title ,
19 int nBins , double xlow, double xup,
20 double ylow, double yup, const std::string& opt )
21 {
22 TProfile* _p = new TProfile(title.c_str(),title.c_str(),nBins,xlow,xup,ylow,yup,opt.c_str() ) ;
23 Profile1D* p = new Profile1D(_p);
24 return std::pair<DataObject*,AIDA::IProfile1D*>(p,p);
25 }
26
27 std::pair<DataObject*,AIDA::IProfile1D*> Gaudi::createProf1D
28 ( const std::string& title,
29 const Edges& e, double ylow, double yup ,
30 const std::string& opt )
31 {
32 Profile1D* p = new Profile1D(new TProfile(title.c_str(),title.c_str(),e.size()-1,&e.front(),ylow,yup,opt.c_str()));
33 return std::pair<DataObject*,AIDA::IProfile1D*>(p,p);
34 }
35
36 std::pair<DataObject*,AIDA::IProfile1D*> Gaudi::createProf1D(const AIDA::IProfile1D& hist) {
37 TProfile *h = getRepresentation<AIDA::IProfile1D,TProfile>(hist);
38 Profile1D *n = h ? new Profile1D(new TProfile(*h)) : 0;
39 return std::pair<DataObject*,AIDA::IProfile1D*>(n,n);
40 }
41
42 namespace Gaudi {
43 template <>
44 int Generic1D<AIDA::IProfile1D,TProfile>::binEntries (int index) const {
45 return int(m_rep->GetBinEntries( rIndex(index) )+0.5);
46 }
47
48 template <> void* Generic1D<AIDA::IProfile1D,TProfile>::cast(const std::string& className) const {
49 if (className == "AIDA::IProfile1D")
50 return const_cast<AIDA::IProfile1D*>((AIDA::IProfile1D*)this);
51 else if (className == "AIDA::IProfile")
52 return const_cast<AIDA::IProfile*>((AIDA::IProfile*)this);
53 else if (className == "AIDA::IBaseHistogram")
54 return const_cast<AIDA::IBaseHistogram*>((AIDA::IBaseHistogram*)this);
55 return 0;
56 }
57
58 template <>
59 void Generic1D<AIDA::IProfile1D,TProfile>::adoptRepresentation(TObject* rep) {
60 TProfile* imp = dynamic_cast<TProfile*>(rep);
61 if ( imp ) {
62 if ( m_rep ) delete m_rep;
63 m_rep = imp;
64 m_axis.initialize(m_rep->GetXaxis(),true);
65 const TArrayD* a = m_rep->GetSumw2();
66 if ( 0 == a || (a && a->GetSize()==0) ) m_rep->Sumw2();
67 setTitle(m_rep->GetTitle());
68 return;
69 }
70 throw std::runtime_error("Cannot adopt native histogram representation.");
71 }
72 }
73
74 Gaudi::Profile1D::Profile1D() {
75 m_rep = new TProfile();
76 init("",false);
77 }
78
79 Gaudi::Profile1D::Profile1D(TProfile* rep) {
80 m_rep = rep;
81 init(m_rep->GetTitle());
82 }
83
84 void Gaudi::Profile1D::init(const std::string& title, bool initialize_axis) {
85 m_classType = "IProfile1D";
86 setTitle(title);
87 setName(title);
88 if ( initialize_axis ) {
89 axis().initialize(m_rep->GetXaxis(),false);
90 }
91 //m_rep->SetErrorOption("s");
92 m_rep->SetDirectory(0);
93 m_sumEntries = 0;
94 }
95
96 bool Gaudi::Profile1D::setBinContents(int i, int entries,double height,double /*error*/, double spread, double /* centre */ ) {
97 m_rep->SetBinEntries(rIndex(i), entries );
98 // set content takes in root height * entries
99 m_rep->SetBinContent(rIndex(i), height*entries );
100 // set error takes sqrt of bin sum(w*y**2)
101 double sumwy2Bin = ( spread*spread + height*height )*entries;
102 m_rep->SetBinError(rIndex(i), sqrt(sumwy2Bin) );
103 m_sumEntries += entries;
104 // not very efficient (but do evey bin since root cannot figure out by himself)
105 m_rep->SetEntries(m_sumEntries);
106 return true;
107 }
108
109 #ifdef __ICC
110 // disable icc remark #1572: floating-point equality and inequality comparisons are unreliable
111 // The comparison is correct
112 #pragma warning(disable:1572)
113 #endif
114 bool Gaudi::Profile1D::fill ( double x, double y, double weight ) {
115 (weight == 1.) ? m_rep->Fill(x,y) : m_rep->Fill(x,y,weight);
116 return true;
117 }
118
119 typedef Gaudi::Profile1D P1D;
120 DECLARE_DATAOBJECT_FACTORY(P1D)