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>
15 #include <GaudiCommonSvc/P2D.h>
16 #include <TProfile2D.h>
17 #include <TH2D.h>
18 #include "GaudiPI.h"
19 
20 namespace Gaudi {
21  template <>
23  if (className == "AIDA::IProfile2D")
24  return const_cast<AIDA::IProfile2D*>((AIDA::IProfile2D*)this);
25  else if (className == "AIDA::IProfile")
26  return const_cast<AIDA::IProfile*>((AIDA::IProfile*)this);
27  else if (className == "AIDA::IBaseHistogram")
28  return const_cast<AIDA::IBaseHistogram*>((AIDA::IBaseHistogram*)this);
29  return nullptr;
30  }
31 
32  template <>
34  int rBin = m_rep->GetBin(rIndexX(idX),rIndexY(idY));
35  return int(m_rep->GetBinEntries(rBin)+0.5);
36  }
37 
38  template <>
40  TProfile2D* imp = dynamic_cast<TProfile2D*>(rep);
41  if ( !imp ) throw std::runtime_error("Cannot adopt native histogram representation.");
42  m_rep.reset( imp );
43  m_xAxis.initialize(m_rep->GetXaxis(),true);
44  m_yAxis.initialize(m_rep->GetYaxis(),true);
45  setTitle(m_rep->GetTitle());
46  }
47 }
48 
49 std::pair<DataObject*,AIDA::IProfile2D*> Gaudi::createProf2D(const std::string& title, const Edges& eX, const Edges& eY, double /* zlow */ , double /* zup */) {
50  // Not implemented in ROOT! Can only use TProfile2D with no z-limits
51  auto p = new Profile2D(new TProfile2D(title.c_str(),title.c_str(),eX.size()-1,&eX.front(), eY.size()-1,&eY.front()/*,zlow,zup */));
52  return {p,p};
53 }
54 
56 Gaudi::createProf2D(const std::string& title,int binsX,double xlow,double xup,int binsY,double ylow,double yup,double zlow,double zup) {
57  auto p = new Profile2D(new TProfile2D(title.c_str(),title.c_str(),binsX,xlow,xup,binsY,ylow,yup,zlow,zup));
58  return {p,p};
59 }
60 
62  auto h = getRepresentation<AIDA::IProfile2D,TProfile2D>(hist);
63  auto n = ( h ? new Profile2D(new TProfile2D(*h)) : nullptr );
64  return {n,n};
65 }
66 
67 Gaudi::Profile2D::Profile2D(TProfile2D* rep) {
68  m_classType = "IProfile2D";
69  rep->SetDirectory(nullptr);
70  adoptRepresentation(rep);
71  m_sumEntries = 0;
72 }
AIDA implementation for 2 D profiles using ROOT TProfile2D.
Definition: P2D.h:17
std::vector< double > Edges
Definition: GaudiPI.h:17
std::pair< DataObject *, AIDA::IProfile2D * > createProf2D(const AIDA::IProfile2D &hist)
Copy constructor.
STL class.
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
int binEntries(int indexX, int indexY) const override
The number of entries (ie the number of times fill was called for this bin).
T c_str(T...args)
void * cast(const std::string &className) const override
Introspection method.
Profile2D()
Default Constructor.
Definition: P2D.h:20
Helper functions to set/get the application return code.
Definition: __init__.py:1