| The Gaudi Framework v27r1

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

- File List
- File Members

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 auto _p = new TProfile(title.c_str(),title.c_str(),nBins,xlow,xup,ylow,yup,opt.c_str() ) ;
23 auto p = new Profile1D(_p);
24 return {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 auto p = new Profile1D(new TProfile(title.c_str(),title.c_str(),e.size()-1,&e.front(),ylow,yup,opt.c_str()));
33 return {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 auto n = ( h ? new Profile1D(new TProfile(*h)) : nullptr );
39 return {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 nullptr;
56 }
57
58 template <>
59 void Generic1D<AIDA::IProfile1D,TProfile>::adoptRepresentation(TObject* rep) {
60 TProfile* imp = dynamic_cast<TProfile*>(rep);
61 if ( !imp ) throw std::runtime_error("Cannot adopt native histogram representation.");
62 m_rep.reset( imp );
63 m_axis.initialize(m_rep->GetXaxis(),true);
64 const TArrayD* a = m_rep->GetSumw2();
65 if ( !a || (a && a->GetSize()==0) ) m_rep->Sumw2();
66 setTitle(m_rep->GetTitle());
67 }
68 }
69
70 Gaudi::Profile1D::Profile1D()
71 : Base( new TProfile() )
72 {
73 init("",false);
74 }
75
76 Gaudi::Profile1D::Profile1D(TProfile* rep)
77 : Base( rep)
78 {
79 init(m_rep->GetTitle());
80 }
81
82 void Gaudi::Profile1D::init(const std::string& title, bool initialize_axis) {
83 m_classType = "IProfile1D";
84 setTitle(title);
85 setName(title);
86 if ( initialize_axis ) {
87 axis().initialize(m_rep->GetXaxis(),false);
88 }
89 //m_rep->SetErrorOption("s");
90 m_rep->SetDirectory(nullptr);
91 m_sumEntries = 0;
92 }
93
94 bool Gaudi::Profile1D::setBinContents(int i, int entries,double height,double /*error*/, double spread, double /* centre */ ) {
95 m_rep->SetBinEntries(rIndex(i), entries );
96 // set content takes in root height * entries
97 m_rep->SetBinContent(rIndex(i), height*entries );
98 // set error takes sqrt of bin sum(w*y**2)
99 double sumwy2Bin = ( spread*spread + height*height )*entries;
100 m_rep->SetBinError(rIndex(i), sqrt(sumwy2Bin) );
101 m_sumEntries += entries;
102 // not very efficient (but do evey bin since root cannot figure out by himself)
103 m_rep->SetEntries(m_sumEntries);
104 return true;
105 }
106
107 #ifdef __ICC
108 // disable icc remark #1572: floating-point equality and inequality comparisons are unreliable
109 // The comparison is correct
110 #pragma warning(disable:1572)
111 #endif
112 bool Gaudi::Profile1D::fill ( double x, double y, double weight ) {
113 (weight == 1.) ? m_rep->Fill(x,y) : m_rep->Fill(x,y,weight);
114 return true;
115 }
116
117 typedef Gaudi::Profile1D P1D;
118 DECLARE_DATAOBJECT_FACTORY(P1D)
P1D
Gaudi::Profile1D P1D
Definition: P1D.cpp:117
Gaudi::Generic1D::cast
void * cast(const std::string &cl) const override
Manual cast by class name.
Gaudi::Profile1D
AIDA implementation for 1 D profiles using ROOT TProfile.
Definition: P1D.h:20
ObjectFactory.h
GaudiPluginService.cpluginsvc.n
list n
Definition: cpluginsvc.py:217
Gaudi::Profile1D::setBinContents
virtual bool setBinContents(int i, int entries, double height, double error, double spread, double centre)
Definition: P1D.cpp:94
Gaudi::Generic1D::adoptRepresentation
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
P1D.h
std::string
STL class.
Gaudi::Generic1D::m_rep
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic1D.h:128
std::runtime_error
STL class.
HiveAlgSequencer.h
tuple h
Definition: HiveAlgSequencer.py:24
ana.opt
string opt
print 'Summary: %32s [s] d d steps'%(summary.protocol,summary.type,summary.nevt,len(summary.data),)
Definition: ana.py:116
std::pair
Gaudi::Profile1D::Profile1D
Profile1D()
Default Constructor.
Definition: P1D.cpp:70
std::string::c_str
T c_str(T...args)
DECLARE_DATAOBJECT_FACTORY
#define DECLARE_DATAOBJECT_FACTORY(x)
Definition: ObjectFactory.h:21
Gaudi::Generic1D::binEntries
int binEntries(int index) const override
Number of entries in the corresponding bin (ie the number of times fill was called for this bin)...
Gaudi::Profile1D::fill
bool fill(double x, double y, double weight=1.) override
Fill the Profile1D with a value and the corresponding weight.
Definition: P1D.cpp:112
Gaudi::createProf1D
std::pair< DataObject *, AIDA::IProfile1D * > createProf1D(const AIDA::IProfile1D &hist)
Copy constructor.
ana.i
list i
Definition: ana.py:128
Gaudi::Profile1D::init
void init(const std::string &title, bool initialize_axis=true)
Definition: P1D.cpp:82
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
Gaudi::Generic1D
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
Definition: Generic1D.h:34