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"
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:
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 <>
66  int rBin = m_rep->GetBin(rIndexX(idX),rIndexY(idY));
67  return int(m_rep->GetBinEntries(rBin)+0.5);
68  }
69 
70  template <>
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 
int m_sumEntries
cache sumEntries (allEntries) when setting contents since Root can't compute by himself ...
Definition: Generic2D.h:147
virtual const CLID & clID() const
Retrieve reference to class defininition identifier.
Definition: P2D.cpp:47
bool fill(double x, double y, double z, double weight)
Fill bin content.
Definition: P2D.cpp:42
AIDA implementation for 2 D profiles using ROOT TProfile2D.
Definition: P2D.cpp:27
virtual int binEntries(int indexX, int indexY) const
The number of entries (ie the number of times fill was called for this bin).
std::pair< DataObject *, AIDA::IProfile2D * > createProf2D(const AIDA::IProfile2D &hist)
Copy constructor.
void * cast(const std::string &className) const
Introspection method.
Gaudi::Profile2D P2D
Definition: P2D.cpp:111
std::string m_classType
class type
Definition: Generic2D.h:145
unsigned int CLID
Class ID definition.
Definition: ClassID.h:9
virtual ~Profile2D()
Destructor.
Definition: P2D.cpp:40
#define DECLARE_DATAOBJECT_FACTORY(x)
Definition: ObjectFactory.h:21
static const CLID & classID()
Definition: P2D.cpp:48
This is a number of static methods for bootstrapping the Gaudi framework.
Definition: Bootstrap.h:15
Profile2D()
Default Constructor.
Definition: P2D.cpp:30
#define GAUDI_API
Definition: Kernel.h:108
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:31
virtual void adoptRepresentation(TObject *rep)
Adopt ROOT histogram representation.
IMPLEMENTATION * m_rep
Reference to underlying implementation.
Definition: Generic2D.h:143
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
Definition: Generic2D.h:30