ATLAS Offline Software
TProfile_LW.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Implementation of class TProfile_LW //
9 // //
10 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11 // Initial version: March 2009 //
12 // //
14 
15 #include "LWHists/TProfile_LW.h"
16 #include "LWHists/LWHistControls.h"
17 #include "Flex1DProfileHisto.h"
18 #include "LWHistRootUtils.h"
19 #include "TProfile.h"
20 #include <utility>
21 
22 #define CALL(x,y) m_rootHisto ? m_rootHisto-> x : m_flexHisto-> y
23 #ifdef LW_DEBUG_HEAVY_USERS
24 #define LWCOUNTCALL {if (m_flexHisto) m_flexHisto->countCall(LWHistTraceUtils::getAdresses());};
25 #define LWREPORT {if (m_flexHisto) m_flexHisto->produceReport(GetName());};
26 #else
27 #define LWCOUNTCALL {};
28 #define LWREPORT {};
29 #endif
30 
31 //____________________________________________________________________
32 TProfile_LW * TProfile_LW::create( const char* name, const char* title,
33  unsigned nbinsx, const double& xlow, const double& xup, const char* option )
34 {
35  return actualcreate(name,title,nbinsx,xlow,xup,0.0,0.0,0,0,option);
36 }
37 
38 //____________________________________________________________________
39 TProfile_LW * TProfile_LW::create( const char* name, const char* title,
40  unsigned nbinsx, const double& xlow, const double& xup,
41  const double& ylow, const double& yup, const char* option )
42 {
43  return actualcreate(name,title,nbinsx,xlow,xup,ylow,yup,0,0,option);
44 }
45 
46 //____________________________________________________________________
47 TProfile_LW * TProfile_LW::create( const char* name, const char* title,unsigned nbinsx, const float* xbins, const char* option)
48 {
49  return actualcreate(name,title,nbinsx,xbins[0],xbins[nbinsx],0.0,0.0,xbins,0,option);
50 }
51 
52 //____________________________________________________________________
53 TProfile_LW * TProfile_LW::create( const char* name, const char* title,unsigned nbinsx, const double* xbins, const char* option)
54 {
55  return actualcreate(name,title,nbinsx,xbins[0],xbins[nbinsx],0.0,0.0,0,xbins,option);
56 }
57 
58 //____________________________________________________________________
59 TProfile_LW * TProfile_LW::create( const char* name, const char* title,unsigned nbinsx, const double* xbins,
60  const double& ylow, const double& yup, const char* option)
61 {
62  return actualcreate(name,title,nbinsx,xbins[0],xbins[nbinsx],ylow,yup,0,xbins,option);
63 }
64 
65 
66 //____________________________________________________________________
67 TProfile_LW * TProfile_LW::actualcreate( const char* name, const char* title,
68  unsigned nbinsx, const double& xlow, const double& xup,
69  const double& ylow, const double& yup,
70  const float* xbins_flt, const double* xbins_dbl, const char* option )
71 {
72  bool rootbackend(LWHistControls::hasROOTBackend());
73  TProfile_LW * h;
74  if (rootbackend) {
75  h = new TProfile_LW(name,title,nbinsx,xlow,xup,ylow,yup,xbins_flt,xbins_dbl,option,rootbackend);
76  } else {
77  h = MP_NEW(TProfile_LW)(name,title,nbinsx,xlow,xup,ylow,yup,xbins_flt,xbins_dbl,option,rootbackend);
78  h->m_nBytesFromPool = sizeof(TProfile_LW);
79  }
80  return h;
81 }
82 
83 //____________________________________________________________________
84 TProfile_LW::TProfile_LW( const char* name, const char* title,
85  unsigned nbinsx, const double& xlow, const double& xup,
86  const double& ylow, const double& yup,
87  const float* xbins_flt, const double* xbins_dbl,
88  const char* option, bool rootbackend )
89  : LWHist(name,title,rootbackend),
90  m_flexHisto(0),
91  m_rootHisto(0)
92 {
93  //Fixme: these asserts could be in common for all binnings... [+nan
94  //checking) (check input and revert to dummy range in case of
95  //problems +emit warning).
96  assert(!(xbins_flt&&xbins_dbl));//max one var binning defined
97  assert(!xbins_flt||(xbins_flt[0]==xlow&&xbins_flt[nbinsx]==xup));
98  assert(!xbins_dbl||(xbins_dbl[0]==xlow&&xbins_dbl[nbinsx]==xup));
99  assert(!xbins_flt||(ylow==0.0&&yup==0.0));//because otherwise we would have to use
100  //a non-existing constructor from root.
101  assert(xup>xlow);
102  assert(nbinsx>0);
103  if (rootbackend) {
104  if (xbins_dbl)
105  m_rootHisto = new TProfile(name,title,nbinsx,xbins_dbl,ylow,yup,option);
106  else if (xbins_flt)
107  m_rootHisto = new TProfile(name,title,nbinsx,xbins_flt,option);
108  else
109  m_rootHisto = new TProfile(name,title,nbinsx,xlow,xup,ylow,yup,option);
110  } else {
111  if (xbins_dbl)
112  m_flexHisto = Flex1DProfileHisto::create(nbinsx,xbins_dbl,ylow,yup);
113  else if (xbins_flt)
114  m_flexHisto = Flex1DProfileHisto::create(nbinsx,xbins_flt,ylow,yup);
115  else
116  m_flexHisto = Flex1DProfileHisto::create(nbinsx,xlow,xup,ylow,yup);
118  }
119 }
120 
121 //____________________________________________________________________
123 {
125  clear();
126  if (ownsROOTHisto())
127  delete m_rootHisto;//for root backend
128 }
129 
130 //____________________________________________________________________
132 {
133  return m_rootHisto;
134 }
136 {
137  return m_rootHisto;
138 }
141 {
142  if (!m_rootHisto) {
144  if (!apply(h))
145  assert(false);
146  double stats[6];
147  getSums(stats[0],stats[1],stats[2],stats[3],stats[4],stats[5]);
148  h->PutStats(stats);
150  clear();
151  m_rootHisto = h;
152  }
153  return m_rootHisto;
154 }
155 
156 //____________________________________________________________________
158 {
159  LWREPORT
160  LWHist::clear();
162  m_flexHisto = 0;
163 }
164 
165 //____________________________________________________________________
167 {
169  return;
170 
171  if (m_rootHisto) {
172  if (usingROOTBackend())
173  delete m_rootHisto;
174  else
176 
177  m_rootHisto = 0;
178  }
179 }
180 
181 //____________________________________________________________________
183 {
184  if (m_rootHisto) {
185  m_rootHisto->Reset();
186  return;
187  }
188  if (m_flexHisto) {
189  LWREPORT
190  m_flexHisto->reset();
191  }
192 }
193 
194 void TProfile_LW::SetErrorOption(Option_t *option) { CALL(SetErrorOption(option),setErrorOptionFromString(option)); }
195 const char* TProfile_LW::GetErrorOption() const { return CALL(GetErrorOption(),getErrorOptionAsString()); }
196 
197 const float * TProfile_LW::getVarBins() const
198 {
199  assert(!m_rootHisto);
200  return std::as_const(m_flexHisto)->getVarBins();
201 }
202 
204 {
205  assert(!m_rootHisto);
206  return m_flexHisto->getVarBins();
207 }
208 
209 double TProfile_LW::getXMin() const
210 {
211  if (m_rootHisto)
212  return std::as_const(*m_rootHisto).GetXaxis()->GetXmin();
213  return m_flexHisto->getXMin();
214 }
215 
216 double TProfile_LW::getXMax() const
217 {
218  if (m_rootHisto)
219  return std::as_const(*m_rootHisto).GetXaxis()->GetXmax();
220  return m_flexHisto->getXMax();
221 }
222 
223 void TProfile_LW::Fill(const double& x, const double& y)
224 {
226  if (m_rootHisto)
227  m_rootHisto->Fill(x,y);
228  else
229  m_flexHisto->fill(x,y);
230 }
231 
232 void TProfile_LW::Fill(const double& x, const double& y, const double& w)
233 {
235  if (m_rootHisto)
236  m_rootHisto->Fill(x,y,w);
237  else
238  m_flexHisto->fill(x,y,w);
239 }
240 
241 unsigned TProfile_LW::GetNbinsX() const { return CALL(GetNbinsX(),getNBins()); }
242 double TProfile_LW::GetBinEntries(unsigned bin) const { LWCOUNTCALL;return CALL(GetBinEntries(bin),getBinEntries(bin)); }
243 double TProfile_LW::GetBinContent(unsigned bin) const { LWCOUNTCALL;return CALL(GetBinContent(bin),getBinContent(bin)); }
244 double TProfile_LW::GetBinError(unsigned bin) const { LWCOUNTCALL;return CALL(GetBinError(bin),getBinError(bin)); }
245 void TProfile_LW::SetBinEntries(unsigned bin, const double& c) { LWCOUNTCALL;CALL(SetBinEntries(bin,c),setBinEntries(bin,c)); }
246 void TProfile_LW::SetBinContent(unsigned bin, const double& c) { LWCOUNTCALL;CALL(SetBinContent(bin,c),setBinContent(bin,c)); }
247 void TProfile_LW::SetBinError(unsigned bin, const double& e ) { LWCOUNTCALL;CALL(SetBinError(bin,e),setBinError(bin,e)); }
248 unsigned TProfile_LW::GetEntries() const
249 {
250  if (m_rootHisto)
251  return static_cast<unsigned>(m_rootHisto->GetEntries());
252  else
253  return m_flexHisto->getEntries();
254 }
255 void TProfile_LW::SetEntries(unsigned n) { CALL(SetEntries(n),setEntries(n)); }
256 
257 void TProfile_LW::getSums( double& sumW, double& sumW2,
258  double& sumWX,double& sumWX2,
259  double& sumWY,double& sumWY2 ) const
260 {
261  if (m_rootHisto) {
262  sumW = LWHistRootUtils::getSumW(m_rootHisto);
263  sumW2 = LWHistRootUtils::getSumW2(m_rootHisto);
264  sumWX = LWHistRootUtils::getSumWX(m_rootHisto);
265  sumWX2 = LWHistRootUtils::getSumWX2(m_rootHisto);
266  sumWY = LWHistRootUtils::getSumWY(m_rootHisto);
267  sumWY2 = LWHistRootUtils::getSumWY2(m_rootHisto);
268  } else {
269  sumW = m_flexHisto->getSumW(); sumW2 = m_flexHisto->getSumW2();
270  sumWX = m_flexHisto->getSumWX(); sumWX2 = m_flexHisto->getSumWX2();
271  sumWY = m_flexHisto->getSumWProfPar(); sumWY2 = m_flexHisto->getSumWProfPar2();
272  }
273 }
274 
275 void TProfile_LW::setSums( const double& sumW, const double&sumW2,
276  const double& sumWX, const double& sumWX2,
277  const double& sumWY, const double& sumWY2 )
278 {
279  if (m_rootHisto) {
280  LWHistRootUtils::setSumW(m_rootHisto,sumW);
281  LWHistRootUtils::setSumW2(m_rootHisto,sumW2);
282  LWHistRootUtils::setSumWX(m_rootHisto,sumWX);
283  LWHistRootUtils::setSumWX2(m_rootHisto,sumWX2);
284  LWHistRootUtils::setSumWY(m_rootHisto,sumWY);
285  LWHistRootUtils::setSumWY2(m_rootHisto,sumWY2);
286  } else {
287  m_flexHisto->setSums(sumW,sumW2,sumWX,sumWX2,sumWY,sumWY2);
288  }
289 }
290 double TProfile_LW::Integral() const { return CALL(Integral(),integral()); }
291 void TProfile_LW::GetBinInfo(unsigned bin,double& entries, double& content, double&error) const
292 {
293  LWCOUNTCALL;
294  if (m_rootHisto) {
295  entries = m_rootHisto->GetBinEntries(bin);
297  error = m_rootHisto->GetBinError(bin);
298  } else {
300  }
301 }
302 
303 void TProfile_LW::SetBinInfo(unsigned bin, const double& entries, const double& content, const double& error)
304 {
305  LWCOUNTCALL;
306  if (m_rootHisto) {
307  m_rootHisto->SetBinEntries(bin,entries);
308  m_rootHisto->SetBinContent(bin,content);
309  m_rootHisto->SetBinError(bin,error);
310  } else {
312  }
313 }
314 
316 {
317  if (m_rootHisto) {
318  assert(false);
319  return 0;
320  }
321  return m_flexHisto->getBinCenter(bin);
322 }
323 
324 unsigned TProfile_LW::actualFindBinX(const double&x) const
325 {
326  assert(!m_rootHisto);//Should have called the TAxis method
327  return m_flexHisto->valueToBin(x);
328 }
329 
LWHist
Definition: LWHist.h:26
TProfile_LW::getROOTHistBase
virtual TH1 * getROOTHistBase() override
Definition: TProfile_LW.cxx:139
TProfile_LW::m_rootHisto
TProfile * m_rootHisto
Definition: TProfile_LW.h:101
Flex1DProfileHisto::getSumWProfPar2
double getSumWProfPar2() const
Definition: Flex1DProfileHisto.h:72
TProfile_LW::GetBinContent
double GetBinContent(unsigned bin) const
Definition: TProfile_LW.cxx:243
TProfile_LW::actualcreate
static TProfile_LW * actualcreate(const char *name, const char *title, unsigned nbinsx, const double &xlow, const double &xup, const double &ylow, const double &yup, const float *xbins_flt, const double *xbins_dbl, const char *option)
Definition: TProfile_LW.cxx:67
TProfile_LW::clearKeptROOTHist
virtual void clearKeptROOTHist() override
Definition: TProfile_LW.cxx:166
integral
double integral(TH1 *h)
Definition: computils.cxx:57
TProfile_LW::getXMax
double getXMax() const
Definition: TProfile_LW.cxx:216
Flex1DProfileHisto::getSumW2
double getSumW2() const
Definition: Flex1DProfileHisto.h:68
Flex1DProfileHisto::reset
void reset()
Flex1DProfileHisto::valueToBin
unsigned valueToBin(const double &x) const
TProfile_LW::GetNbinsX
unsigned GetNbinsX() const
Definition: TProfile_LW.cxx:241
TProfile_LW::GetBinError
double GetBinError(unsigned bin) const
Definition: TProfile_LW.cxx:244
TProfile_LW::~TProfile_LW
virtual ~TProfile_LW()
Definition: TProfile_LW.cxx:122
TProfile_LW::setSums
void setSums(const double &sumW, const double &sumW2, const double &sumWX, const double &sumWX2, const double &sumWY, const double &sumWY2)
Definition: TProfile_LW.cxx:275
TProfile_LW::SetBinContent
void SetBinContent(unsigned bin, const double &)
Definition: TProfile_LW.cxx:246
Flex1DProfileHisto::create
static Flex1DProfileHisto * create(unsigned nbins, const double &xmin, const double &xmax, const double &profparmin, const double &profparmax)
LWCOUNTCALL
#define LWCOUNTCALL
Definition: TProfile_LW.cxx:27
Flex1DProfileHisto::getSumWX
double getSumWX() const
Definition: Flex1DProfileHisto.h:69
CALL
#define CALL(x, y)
Definition: TProfile_LW.cxx:22
bin
Definition: BinsDiffFromStripMedian.h:43
TProfile_LW::GetEntries
virtual unsigned GetEntries() const override
Definition: TProfile_LW.cxx:248
TProfile_LW.h
LWHist::ownsROOTHisto
bool ownsROOTHisto() const
Definition: LWHist.h:74
TProfile_LW::getROOTHist
TProfile * getROOTHist()
Definition: TProfile_LW.cxx:140
TProfile_LW::SetBinEntries
void SetBinEntries(unsigned bin, const double &)
Definition: TProfile_LW.cxx:245
TProfile_LW::actualFindBinX
virtual unsigned actualFindBinX(const double &) const override
Definition: TProfile_LW.cxx:324
TProfile_LW::SetEntries
virtual void SetEntries(unsigned) override
Definition: TProfile_LW.cxx:255
trigbs_dumpHLTContentInBS.stats
stats
Definition: trigbs_dumpHLTContentInBS.py:91
TProfile_LW
Definition: TProfile_LW.h:24
LWHistRootUtils::createRootProfileHisto
TProfile * createRootProfileHisto(TProfile_LW *lwhist, Flex1DProfileHisto *flexHist)
x
#define x
TProfile_LW::getROOTHistBaseNoAlloc
virtual const TH1 * getROOTHistBaseNoAlloc() const override
Definition: TProfile_LW.cxx:131
TProfile_LW::Reset
virtual void Reset() override
Definition: TProfile_LW.cxx:182
TProfile_LW::getSums
void getSums(double &sumW, double &sumW2, double &sumWX, double &sumWX2, double &sumWY, double &sumWY2) const
Definition: TProfile_LW.cxx:257
TProfile_LW::SetBinInfo
void SetBinInfo(unsigned bin, const double &entries, const double &content, const double &error)
Definition: TProfile_LW.cxx:303
grepfile.content
string content
Definition: grepfile.py:56
LWHist::usingROOTBackend
bool usingROOTBackend() const
Definition: LWHist.h:73
Flex1DProfileHisto::getXMax
double getXMax() const
Definition: Flex1DProfileHisto.h:41
TProfile_LW::getVarBins
const float * getVarBins() const
Definition: TProfile_LW.cxx:197
TProfile_LW::actualGetBinCenterX
virtual double actualGetBinCenterX(int bin) const override
Definition: TProfile_LW.cxx:315
Flex1DProfileHisto::getXMin
double getXMin() const
Definition: Flex1DProfileHisto.h:40
Flex1DProfileHisto::fill
void fill(const double &x, const double &profiledpar)
Flex1DProfileHisto::getSumW
double getSumW() const
Definition: Flex1DProfileHisto.h:67
MP_NEW
#define MP_NEW(Class)
Definition: LWPools.h:26
TProfile_LW::create
static TProfile_LW * create(const char *name, const char *title, unsigned nbinsx, const double &xlow, const double &xup, const char *option=" ")
Definition: TProfile_LW.cxx:32
TProfile_LW::GetErrorOption
const char * GetErrorOption() const
Definition: TProfile_LW.cxx:195
TProfile_LW::SetBinError
void SetBinError(unsigned bin, const double &)
Definition: TProfile_LW.cxx:247
python.TrigEgammaMonitorHelper.TProfile
def TProfile(*args, **kwargs)
Definition: TrigEgammaMonitorHelper.py:81
beamspotman.n
n
Definition: beamspotman.py:731
Flex1DProfileHisto::setSums
void setSums(const double &sumW, const double &sumW2, const double &sumWX, const double &sumWX2, const double &sumWProfPar, const double &sumWProfPar2)
extractSporadic.h
list h
Definition: extractSporadic.py:97
covarianceTool.title
title
Definition: covarianceTool.py:542
TProfile_LW::GetBinInfo
void GetBinInfo(unsigned bin, double &entries, double &content, double &error) const
Definition: TProfile_LW.cxx:291
LWHistControls::hasROOTBackend
static bool hasROOTBackend()
Definition: LWHistControls.cxx:47
Flex1DProfileHisto::getVarBins
const float * getVarBins() const
Definition: Flex1DProfileHisto.h:42
LWREPORT
#define LWREPORT
Definition: TProfile_LW.cxx:28
TProfile_LW::Fill
void Fill(const double &x, const double &y)
Definition: TProfile_LW.cxx:223
Flex1DProfileHisto.h
Flex1DProfileHisto::getBinCenter
double getBinCenter(int bin) const
LWHistControls::cleanupOnGetROOT
static bool cleanupOnGetROOT()
Definition: LWHistControls.cxx:35
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
Flex1DProfileHisto::destroy
static void destroy(Flex1DProfileHisto *)
LWHist::clear
virtual void clear()
Definition: LWHist.cxx:474
TProfile
Definition: rootspy.cxx:515
Flex1DProfileHisto::setErrorOptionFromString
void setErrorOptionFromString(const char *option)
Definition: Flex1DProfileHisto.h:62
LArCellBinning.xbins
int xbins
Definition: LArCellBinning.py:163
Flex1DProfileHisto::getEntries
unsigned getEntries() const
Flex1DProfileHisto::getSumWProfPar
double getSumWProfPar() const
Definition: Flex1DProfileHisto.h:71
TProfile_LW::SetErrorOption
void SetErrorOption(const char *option)
Definition: TProfile_LW.cxx:194
TProfile_LW::GetBinEntries
double GetBinEntries(unsigned bin) const
Definition: TProfile_LW.cxx:242
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
y
#define y
h
TProfile::Fill
int Fill(double, double)
Definition: rootspy.cxx:523
LWHist::apply
virtual bool apply(TH1 *) const
Definition: LWHist.cxx:256
Flex1DProfileHisto::getSumWX2
double getSumWX2() const
Definition: Flex1DProfileHisto.h:70
TH1
Definition: rootspy.cxx:268
TProfile_LW::getXMin
double getXMin() const
Definition: TProfile_LW.cxx:209
Flex1DProfileHisto::getBinInfo
void getBinInfo(unsigned bin, double &entries, double &content, double &error) const
entries
double entries
Definition: listroot.cxx:49
LWHistRootUtils.h
Flex1DProfileHisto::setBinInfo
void setBinInfo(unsigned bin, const double &entries, const double &content, const double &error)
TProfile_LW::TProfile_LW
TProfile_LW(const char *name, const char *title, unsigned nbinsx, const double &xlow, const double &xup, const double &ylow, const double &yup, const float *xbins_flt, const double *xbins_dbl, const char *option, bool rootbackend)
Definition: TProfile_LW.cxx:84
TProfile_LW::m_flexHisto
Flex1DProfileHisto * m_flexHisto
Definition: TProfile_LW.h:100
LWHistControls.h
TProfile_LW::clear
virtual void clear() override
Definition: TProfile_LW.cxx:157
LWHistRootUtils::deleteProfileHisto
void deleteProfileHisto(TProfileX *rootHist)
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
error
Definition: IImpactPoint3dEstimator.h:70
python.compressB64.c
def c
Definition: compressB64.py:93
TProfile::GetBinContent
double GetBinContent(int) const
Definition: rootspy.cxx:527
TProfile_LW::Integral
virtual double Integral() const override
Definition: TProfile_LW.cxx:290