| # 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
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() {
31 m_classType = "IProfile2D";
32 m_rep = new TProfile2D();
33 m_rep->SetErrorOption("s");
34 m_rep->SetDirectory(0);
35 m_sumEntries = 0;
36 }
38 Profile2D(TProfile2D* rep);
40 virtual ~Profile2D() {}
42 bool fill(double x,double y,double z,double weight) {
43 m_rep->Fill(x,y,z,weight);
44 return true;
45 }
47 virtual const CLID& clID() const { return classID(); }
48 static const CLID& classID() { return CLID_ProfileH2; }
49 };
50 }
51
52 namespace Gaudi {
53 template <>
54 void* Generic2D<AIDA::IProfile2D,TProfile2D>::cast(const std::string& className) const {
55 if (className == "AIDA::IProfile2D")
56 return const_cast<AIDA::IProfile2D*>((AIDA::IProfile2D*)this);
57 else if (className == "AIDA::IProfile")
58 return const_cast<AIDA::IProfile*>((AIDA::IProfile*)this);
59 else if (className == "AIDA::IBaseHistogram")
60 return const_cast<AIDA::IBaseHistogram*>((AIDA::IBaseHistogram*)this);
61 return 0;
62 }
63
64 template <>
65 int Generic2D<AIDA::IProfile2D,TProfile2D>::binEntries(int idX, int idY) const {
66 int rBin = m_rep->GetBin(rIndexX(idX),rIndexY(idY));
67 return int(m_rep->GetBinEntries(rBin)+0.5);
68 }
69
70 template <>
71 void Generic2D<AIDA::IProfile2D,TProfile2D>::adoptRepresentation(TObject* rep) {
72 TProfile2D* imp = dynamic_cast<TProfile2D*>(rep);
73 if ( imp ) {
74 if ( m_rep ) delete m_rep;
75 m_rep = imp;
76 m_xAxis.initialize(m_rep->GetXaxis(),true);
77 m_yAxis.initialize(m_rep->GetYaxis(),true);
78 setTitle(m_rep->GetTitle());
79 return;
80 }
81 throw std::runtime_error("Cannot adopt native histogram representation.");
82 }
83 }
84
85 std::pair<DataObject*,AIDA::IProfile2D*> Gaudi::createProf2D(const std::string& title, const Edges& eX, const Edges& eY, double /* zlow */ , double /* zup */) {
86 // Not implemented in ROOT! Can only use TProfile2D with no z-limits
87 Profile2D* p = new Profile2D(new TProfile2D(title.c_str(),title.c_str(),eX.size()-1,&eX.front(), eY.size()-1,&eY.front()/*,zlow,zup */));
88 return std::pair<DataObject*,AIDA::IProfile2D*>(p,p);
89 }
90
91 std::pair<DataObject*,AIDA::IProfile2D*>
92 Gaudi::createProf2D(const std::string& title,int binsX,double xlow,double xup,int binsY,double ylow,double yup,double zlow,double zup) {
93 Profile2D* p = new Profile2D(new TProfile2D(title.c_str(),title.c_str(),binsX,xlow,xup,binsY,ylow,yup,zlow,zup));
94 return std::pair<DataObject*,AIDA::IProfile2D*>(p,p);
95 }
96
97 std::pair<DataObject*,AIDA::IProfile2D*> Gaudi::createProf2D(const AIDA::IProfile2D& hist) {
98 TProfile2D *h = getRepresentation<AIDA::IProfile2D,TProfile2D>(hist);
99 Profile2D *n = h ? new Profile2D(new TProfile2D(*h)) : 0;
100 return std::pair<DataObject*,AIDA::IProfile2D*>(n,n);
101 }
102
103 Gaudi::Profile2D::Profile2D(TProfile2D* rep) {
104 m_rep = 0;
105 m_classType = "IProfile2D";
106 rep->SetDirectory(0);
107 adoptRepresentation(rep);
108 m_sumEntries = 0;
109 }
110
111 typedef Gaudi::Profile2D P2D;
112 DECLARE_DATAOBJECT_FACTORY(P2D)