| The Gaudi Framework v27r1

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

- File List
- File Members

P2D.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 #include "GaudiKernel/DataObject.h"
13 #include "GaudiKernel/ObjectFactory.h"
14 #include "GaudiPI.h"
15 #include "Generic2D.h"
16 #include "TProfile2D.h"
17 #include "TH2D.h"
18
19 namespace Gaudi {
20
27 class GAUDI_API Profile2D : public DataObject, public Generic2D<AIDA::IProfile2D,TProfile2D> {
28 public:
30 Profile2D() : Base( new TProfile2D() )
31 {
32 m_classType = "IProfile2D";
33 m_rep->SetErrorOption("s");
34 m_rep->SetDirectory(nullptr);
35 }
37 Profile2D(TProfile2D* rep);
39 ~Profile2D() override = default;
41 bool fill(double x,double y,double z,double weight) override {
42 m_rep->Fill(x,y,z,weight);
43 return true;
44 }
46 const CLID& clID() const override { return classID(); }
47 static const CLID& classID() { return CLID_ProfileH2; }
48 };
49 }
50
51 namespace Gaudi {
52 template <>
53 void* Generic2D<AIDA::IProfile2D,TProfile2D>::cast(const std::string& className) const {
54 if (className == "AIDA::IProfile2D")
55 return const_cast<AIDA::IProfile2D*>((AIDA::IProfile2D*)this);
56 else if (className == "AIDA::IProfile")
57 return const_cast<AIDA::IProfile*>((AIDA::IProfile*)this);
58 else if (className == "AIDA::IBaseHistogram")
59 return const_cast<AIDA::IBaseHistogram*>((AIDA::IBaseHistogram*)this);
60 return nullptr;
61 }
62
63 template <>
64 int Generic2D<AIDA::IProfile2D,TProfile2D>::binEntries(int idX, int idY) const {
65 int rBin = m_rep->GetBin(rIndexX(idX),rIndexY(idY));
66 return int(m_rep->GetBinEntries(rBin)+0.5);
67 }
68
69 template <>
70 void Generic2D<AIDA::IProfile2D,TProfile2D>::adoptRepresentation(TObject* rep) {
71 TProfile2D* imp = dynamic_cast<TProfile2D*>(rep);
72 if ( !imp ) throw std::runtime_error("Cannot adopt native histogram representation.");
73 m_rep.reset( imp );
74 m_xAxis.initialize(m_rep->GetXaxis(),true);
75 m_yAxis.initialize(m_rep->GetYaxis(),true);
76 setTitle(m_rep->GetTitle());
77 }
78 }
79
80 std::pair<DataObject*,AIDA::IProfile2D*> Gaudi::createProf2D(const std::string& title, const Edges& eX, const Edges& eY, double /* zlow */ , double /* zup */) {
81 // Not implemented in ROOT! Can only use TProfile2D with no z-limits
82 auto p = new Profile2D(new TProfile2D(title.c_str(),title.c_str(),eX.size()-1,&eX.front(), eY.size()-1,&eY.front()/*,zlow,zup */));
83 return {p,p};
84 }
85
86 std::pair<DataObject*,AIDA::IProfile2D*>
87 Gaudi::createProf2D(const std::string& title,int binsX,double xlow,double xup,int binsY,double ylow,double yup,double zlow,double zup) {
88 auto p = new Profile2D(new TProfile2D(title.c_str(),title.c_str(),binsX,xlow,xup,binsY,ylow,yup,zlow,zup));
89 return {p,p};
90 }
91
92 std::pair<DataObject*,AIDA::IProfile2D*> Gaudi::createProf2D(const AIDA::IProfile2D& hist) {
93 auto h = getRepresentation<AIDA::IProfile2D,TProfile2D>(hist);
94 auto n = ( h ? new Profile2D(new TProfile2D(*h)) : nullptr );
95 return {n,n};
96 }
97
98 Gaudi::Profile2D::Profile2D(TProfile2D* rep) {
99 m_classType = "IProfile2D";
100 rep->SetDirectory(nullptr);
101 adoptRepresentation(rep);
102 m_sumEntries = 0;
103 }
104
105 typedef Gaudi::Profile2D P2D;
106 DECLARE_DATAOBJECT_FACTORY(P2D)
Gaudi::Generic2D::m_sumEntries
int m_sumEntries
cache sumEntries (allEntries) when setting contents since Root can't compute by himself ...
Definition: Generic2D.h:154
Gaudi::Profile2D
AIDA implementation for 2 D profiles using ROOT TProfile2D.
Definition: P2D.cpp:27
ObjectFactory.h
GaudiPluginService.cpluginsvc.n
list n
Definition: cpluginsvc.py:217
Gaudi::Generic2D::binEntries
int binEntries(int indexX, int indexY) const override
The number of entries (ie the number of times fill was called for this bin).
GaudiPI.h
Gaudi::createProf2D
std::pair< DataObject *, AIDA::IProfile2D * > createProf2D(const AIDA::IProfile2D &hist)
Copy constructor.
std::string
STL class.
Gaudi::Generic2D::adoptRepresentation
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
Gaudi::Generic2D::cast
void * cast(const std::string &className) const
Introspection method.
P2D
Gaudi::Profile2D P2D
Definition: P2D.cpp:105
Gaudi::Generic2D::m_classType
std::string m_classType
class type
Definition: Generic2D.h:152
std::runtime_error
STL class.
HiveAlgSequencer.h
tuple h
Definition: HiveAlgSequencer.py:24
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
std::pair
Generic2D.h
Gaudi::Profile2D::clID
const CLID & clID() const override
Retrieve reference to class defininition identifier.
Definition: P2D.cpp:46
std::string::c_str
T c_str(T...args)
DECLARE_DATAOBJECT_FACTORY
#define DECLARE_DATAOBJECT_FACTORY(x)
Definition: ObjectFactory.h:21
Gaudi::Profile2D::classID
static const CLID & classID()
Definition: P2D.cpp:47
Gaudi::Profile2D::Profile2D
Profile2D()
Default Constructor.
Definition: P2D.cpp:30
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:107
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
Gaudi::Profile2D::fill
bool fill(double x, double y, double z, double weight) override
Fill bin content.
Definition: P2D.cpp:41
DataObject.h
Gaudi::Generic2D
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
Definition: Generic2D.h:35