ATLAS Offline Software
InDetPlotBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 #include "InDetPlotBase.h"
12 
13 #include "TEfficiency.h"
14 
15 #include <cmath>
16 
17 namespace {
18  bool
19  validArguments(const float arg) {
20  return not (std::isnan(arg));
21  }
22 
23  bool
24  validArguments(const float arg, const float arg2) {
25  return not (std::isnan(arg) or std::isnan(arg2));
26  }
27 
28  bool
29  validArguments(const float arg, const float arg2, const float arg3) {
30  return not (std::isnan(arg) or std::isnan(arg2) or std::isnan(arg3));
31  }
32 }
33 
34 
35 InDetPlotBase::InDetPlotBase(InDetPlotBase* pParent, const std::string& dirName) :
36  PlotBase(pParent, dirName),
37  AthMessaging("InDetPlotBase"),
38  m_histoDefSvc("HistogramDefinitionSvc", "InDetPlotBase")
39 {
40 }
41 
42 void
44  if (hd.isValid()) {
45  pHisto = Book1D(hd.name, hd.allTitles, hd.nBinsX, hd.xAxis.first, hd.xAxis.second, false);
46  }
47  }
48 void
50  if (hd.isValid()) {
51  pHisto = BookTProfile(hd.name, hd.allTitles, hd.nBinsX, hd.xAxis.first, hd.xAxis.second, hd.yAxis.first,
52  hd.yAxis.second, false);
53  }
54  }
55 void
56 InDetPlotBase::book(TProfile2D*& pHisto, const SingleHistogramDefinition& hd) {
57  if (hd.isValid()) {
58  pHisto = BookTProfile2D(hd.name, hd.allTitles, hd.nBinsX, hd.xAxis.first, hd.xAxis.second, hd.nBinsY, hd.yAxis.first,
59  hd.yAxis.second, false);
60  }
61  }
62 void
64  if (hd.isValid()) {
65  pHisto = Book2D(hd.name, hd.allTitles, hd.nBinsX, hd.xAxis.first, hd.xAxis.second, hd.nBinsY, hd.yAxis.first,
66  hd.yAxis.second, false);
67  }
68  }
69 
70 void
71 InDetPlotBase::book(TEfficiency*& pHisto, const SingleHistogramDefinition& hd) {
72  if (hd.isValid()) {
73  if(hd.nBinsY==0) {
74  pHisto = BookTEfficiency(hd.name, hd.allTitles, hd.nBinsX, hd.xAxis.first, hd.xAxis.second, false);
75  } else {
76  pHisto = BookTEfficiency(hd.name, hd.allTitles, hd.nBinsX, hd.xAxis.first, hd.xAxis.second, hd.nBinsY, hd.yAxis.first, hd.yAxis.second, false);
77  }
78  }
79  }
80 
81 void
82 InDetPlotBase::fillHisto(TProfile* pTprofile, const float bin, const float weight, const float weight2) {
83  if (pTprofile and validArguments(bin, weight)) {
84  pTprofile->Fill(bin, weight,weight2);
85  }
86 }
87 
88 void
89 InDetPlotBase::fillHisto(TProfile2D* pTprofile, const float xval, const float yval, const float weight, const float weight2) {
90  if (pTprofile and validArguments(xval,yval, weight) and validArguments(weight2)) {
91  pTprofile->Fill(xval,yval, weight,weight2);
92  }
93 }
94 
95 //
96 void
97 InDetPlotBase::fillHisto(TH1* pTh1, const float value) {
98  if (pTh1 and validArguments(value)) {
99  pTh1->Fill(value);
100  }
101 }
102 
103 void
104 InDetPlotBase::fillHisto(TH1* pTh1, const float value, const float weight) {
105  if (pTh1 and validArguments(value)) {
106  pTh1->Fill(value, weight);
107  }
108 }
109 
110 //
111 void
112 InDetPlotBase::fillHisto(TH2* pTh2, const float xval, const float yval) {
113  if (pTh2 and validArguments(xval, yval)) {
114  pTh2->Fill(xval, yval);
115  }
116 }
117 
118 //
119 void
120 InDetPlotBase::fillHisto(TH2* pTh2, const float xval, const float yval, const float weight) {
121  if (pTh2 and validArguments(xval, yval)) {
122  pTh2->Fill(xval, yval, weight);
123  }
124 }
125 
126 void
127 InDetPlotBase::fillHisto(TH3* pTh3, const float xval, const float yval, const float zval) {
128  if (pTh3 and validArguments(xval, yval, zval)) {
129  pTh3->Fill(xval, yval, zval);
130  }
131 }
132 
133 void
134 InDetPlotBase::fillHisto(TEfficiency* pTeff, const float value, const bool accepted, float weight) {
135  if (pTeff and validArguments(value)) {
136  if(weight==1.) pTeff->Fill(accepted, value); // To get proper error estimate when possible
137  else pTeff->FillWeighted(accepted, weight, value);
138  }
139 }
140 
141 void
142 InDetPlotBase::fillHisto(TEfficiency* eff2d, const float xvalue, const float yvalue, const bool accepted, const float weight) {
143  if (eff2d and validArguments(xvalue, yvalue)) {
144  if(weight==1.) eff2d->Fill(accepted, xvalue, yvalue);
145  else eff2d->FillWeighted(accepted, weight, xvalue, yvalue);
146  }
147 }
148 
149 
151 InDetPlotBase::retrieveDefinition(const std::string& histoIdentifier, const std::string& folder, const std::string & nameOverride) {
152 
153  ATH_CHECK( m_histoDefSvc.retrieve(), {} );
154 
155  bool folderDefault = (folder.empty() or folder == "default");
156  SingleHistogramDefinition s = m_histoDefSvc->definition(histoIdentifier, folder);
157  // "default" and empty string should be equivalent
158  if (folderDefault and s.empty()) {
159  const std::string otherDefault = (folder.empty()) ? ("default") : "";
160  s = m_histoDefSvc->definition(histoIdentifier, otherDefault);
161  }
162  if (s.empty()) {
163  ATH_MSG_WARNING("Histogram definition is empty for identifier " << histoIdentifier);
164  }
165  if (!nameOverride.empty()){
166  s.name = nameOverride;
167  }
168  return s;
169 }
SingleHistogramDefinition::nBinsX
unsigned int nBinsX
Definition: SingleHistogramDefinition.h:47
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
PlotBase
Definition: PlotBase.h:34
AthCheckMacros.h
InDetPlotBase::book
void book(Htype *&pHisto, const std::string &histoIdentifier, const std::string &nameOverride="", const std::string &folder="default")
Helper method to book histograms using an identifier string.
PlotBase::BookTEfficiency
TEfficiency * BookTEfficiency(const std::string &name, const std::string &labels, const int nBinsX, const float xlo, const float xhi, const bool prependDir=true)
Book a (1-D) TEfficiency histogram.
Definition: PlotBase.cxx:257
bin
Definition: BinsDiffFromStripMedian.h:43
PlotBase::Book2D
TH2F * Book2D(const std::string &name, const std::string &labels, int nBinsX, float startX, float endX, int nBinsY, float startY, float endY, bool prependDir=true)
Book a TH2F histogram.
Definition: PlotBase.cxx:123
athena.value
value
Definition: athena.py:124
PlotBase::BookTProfile2D
TProfile2D * BookTProfile2D(const std::string &name, const std::string &labels, const int nBinsX, const double xlo, const double xhi, const int nBinsY, const double ylo, const double yhi, bool prependDir=true, bool useRMS=false)
Book a TProfile 2D histogram with variable binning in x-axis and limits in y-values.
Definition: PlotBase.cxx:231
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
PlotBase::Book1D
TH1D * Book1D(const std::string &name, const std::string &labels, int nBins, float start, float end, bool prependDir=true)
Book a TH1D histogram.
Definition: PlotBase.cxx:94
InDetPlotBase
Mixin class to give extra capabilities to plots such as ATH_MSG and an easier booking interface,...
Definition: InDetPlotBase.h:33
SingleHistogramDefinition::xAxis
IHistogramDefinitionSvc::axesLimits_t xAxis
Definition: SingleHistogramDefinition.h:50
InDetPlotBase.h
plotting.yearwise_efficiency_vs_mu.xval
float xval
Definition: yearwise_efficiency_vs_mu.py:35
python.TrigEgammaMonitorHelper.TProfile
def TProfile(*args, **kwargs)
Definition: TrigEgammaMonitorHelper.py:81
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SingleHistogramDefinition
Almost-a-struct for holding the single histogram definition.
Definition: SingleHistogramDefinition.h:17
InDetPlotBase::m_histoDefSvc
ServiceHandle< IHistogramDefinitionSvc > m_histoDefSvc
Definition: InDetPlotBase.h:88
create_dcsc_inputs_sqlite.arg
list arg
Definition: create_dcsc_inputs_sqlite.py:48
InDetPlotBase::InDetPlotBase
InDetPlotBase(InDetPlotBase *pParent, const std::string &dirName)
Constructor taking parent node and directory name for plots.
Definition: InDetPlotBase.cxx:35
plotting.yearwise_efficiency_vs_mu.yval
float yval
Definition: yearwise_efficiency_vs_mu.py:36
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
PlotBase::BookTProfile
TProfile * BookTProfile(const std::string &name, const std::string &labels, int nBinsX, float startX, float endX, float startY=-1, float endY=-1, bool prependDir=true, bool useRMS=false)
Book a TProfile histogram.
Definition: PlotBase.cxx:186
SingleHistogramDefinition::name
std::string name
Definition: SingleHistogramDefinition.h:44
CaloCondBlobAlgs_fillNoiseFromASCII.folder
folder
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:56
SingleHistogramDefinition::yAxis
IHistogramDefinitionSvc::axesLimits_t yAxis
Definition: SingleHistogramDefinition.h:51
SingleHistogramDefinition::isValid
bool isValid() const
Is the histogram definition valid.
Definition: SingleHistogramDefinition.cxx:104
SingleHistogramDefinition::allTitles
std::string allTitles
Definition: SingleHistogramDefinition.h:56
InDetPlotBase::fillHisto
static void fillHisto(TProfile *pTprofile, const float bin, const float weight, const float weight2=1.0)
Definition: InDetPlotBase.cxx:82
InDetPlotBase::retrieveDefinition
SingleHistogramDefinition retrieveDefinition(const std::string &histoIdentifier, const std::string &folder="default", const std::string &nameOverride="")
Retrieve a single histogram definition, given the unique string identifier.
Definition: InDetPlotBase.cxx:151
SingleHistogramDefinition::nBinsY
unsigned int nBinsY
Definition: SingleHistogramDefinition.h:48