| The Gaudi Framework v28r2p1 (f1a77ff4)

- 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 <GaudiCommonSvc/P1D.h>
15 #include <GaudiKernel/ObjectFactory.h>
16 #include <GaudiCommonSvc/HistogramUtility.h>
17 #include "GaudiPI.h"
18
19 std::pair<DataObject*,AIDA::IProfile1D*> Gaudi::createProf1D
20 ( const std::string& title ,
21 int nBins , double xlow, double xup,
22 double ylow, double yup, const std::string& opt )
23 {
24 auto _p = new TProfile(title.c_str(),title.c_str(),nBins,xlow,xup,ylow,yup,opt.c_str() ) ;
25 auto p = new Profile1D(_p);
26 return {p,p};
27 }
28
29 std::pair<DataObject*,AIDA::IProfile1D*> Gaudi::createProf1D
30 ( const std::string& title,
31 const Edges& e, double ylow, double yup ,
32 const std::string& opt )
33 {
34 auto p = new Profile1D(new TProfile(title.c_str(),title.c_str(),e.size()-1,&e.front(),ylow,yup,opt.c_str()));
35 return {p,p};
36 }
37
38 std::pair<DataObject*,AIDA::IProfile1D*> Gaudi::createProf1D(const AIDA::IProfile1D& hist) {
39 TProfile *h = getRepresentation<AIDA::IProfile1D,TProfile>(hist);
40 auto n = ( h ? new Profile1D(new TProfile(*h)) : nullptr );
41 return {n,n};
42 }
43
44 namespace Gaudi {
45 template <>
46 int Generic1D<AIDA::IProfile1D,TProfile>::binEntries (int index) const {
47 return int(m_rep->GetBinEntries( rIndex(index) )+0.5);
48 }
49
50 template <> void* Generic1D<AIDA::IProfile1D,TProfile>::cast(const std::string& className) const {
51 if (className == "AIDA::IProfile1D")
52 return const_cast<AIDA::IProfile1D*>((AIDA::IProfile1D*)this);
53 else if (className == "AIDA::IProfile")
54 return const_cast<AIDA::IProfile*>((AIDA::IProfile*)this);
55 else if (className == "AIDA::IBaseHistogram")
56 return const_cast<AIDA::IBaseHistogram*>((AIDA::IBaseHistogram*)this);
57 return nullptr;
58 }
59
60 template <>
61 void Generic1D<AIDA::IProfile1D,TProfile>::adoptRepresentation(TObject* rep) {
62 TProfile* imp = dynamic_cast<TProfile*>(rep);
63 if ( !imp ) throw std::runtime_error("Cannot adopt native histogram representation.");
64 m_rep.reset( imp );
65 m_axis.initialize(m_rep->GetXaxis(),true);
66 const TArrayD* a = m_rep->GetSumw2();
67 if ( !a || (a && a->GetSize()==0) ) m_rep->Sumw2();
68 setTitle(m_rep->GetTitle());
69 }
70 }
71
72 Gaudi::Profile1D::Profile1D()
73 : Base( new TProfile() )
74 {
75 init("",false);
76 }
77
78 Gaudi::Profile1D::Profile1D(TProfile* rep)
79 : Base( rep)
80 {
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(nullptr);
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 }
Gaudi::Generic1D::cast
void * cast(const std::string &cl) const override
Manual cast by class name.
Gaudi::Generic1D::entries
int entries() const override
Get the number or all the entries.
Definition: Generic1D.h:72
Gaudi::Generic1D::m_classType
std::string m_classType
Definition: Generic1D.h:131
ObjectFactory.h
Gaudi::Edges
std::vector< double > Edges
Definition: GaudiPI.h:17
Gaudi::Profile1D::setBinContents
virtual bool setBinContents(int i, int entries, double height, double error, double spread, double centre)
Definition: P1D.cpp:96
Gaudi::Generic1D::adoptRepresentation
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
GaudiPI.h
P1D.h
std::string
STL class.
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:217
Gaudi::Generic1D::axis
Axis & axis()
Access to axis object.
Definition: Generic1D.h:67
Gaudi::Generic1D::m_rep
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
Definition: Generic1D.h:129
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
std::runtime_error
STL class.
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::Generic1D::m_sumEntries
int m_sumEntries
Definition: Generic1D.h:133
std::pair
Gaudi::Profile1D::Profile1D
Profile1D()
Default Constructor.
Definition: P1D.cpp:72
Gaudi::Axis::initialize
void initialize(TAxis *itaxi, bool)
Definition: Axis.h:66
std::string::c_str
T c_str(T...args)
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:114
HistogramUtility.h
Gaudi::createProf1D
std::pair< DataObject *, AIDA::IProfile1D * > createProf1D(const AIDA::IProfile1D &hist)
Copy constructor.
Gaudi::Generic1D::rIndex
virtual int rIndex(int index) const
operator methods
Definition: Generic1D.h:101
Gaudi::Profile1D::init
void init(const std::string &title, bool initialize_axis=true)
Definition: P1D.cpp:84
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
Gaudi::Generic1D::setName
bool setName(const std::string &newName)
Set the name of the object.
Definition: Generic1D.h:147
Gaudi::Generic1D
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
Definition: Generic1D.h:35