ATLAS Offline Software
TCCPlotsBase.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 #include "TCCPlotsBase.h"
6 
7 // bring Gaudi utilities in scope
8 #include "GaudiKernel/Bootstrap.h"
9 #include "GaudiKernel/ISvcLocator.h"
10 #include "GaudiKernel/Service.h"
11 #include "GaudiKernel/IToolSvc.h"
12 
13 
14 // to retrieve HistogramDefinitionSvc
17 
18 #include <cmath>
19 
20 namespace {
21  bool
22  validArguments(const float arg) {
23  return not (std::isnan(arg));
24  }
25 
26  bool
27  validArguments(const float arg1, const float arg2) {
28  return not (std::isnan(arg1) or std::isnan(arg2));
29  }
30 
31  bool
32  validArguments(const float arg1, const float arg2, const float arg3) {
33  return not (std::isnan(arg1) or std::isnan(arg2) or std::isnan(arg3));
34  }
35 }
36 
37 TCCPlotsBase::TCCPlotsBase(PlotBase* pParent, const std::string& folder):
38  PlotBase(pParent, folder),
39  AthMessaging("TCCPlots"),
40  m_folder(folder),
41  m_histoDefSvc(nullptr) {}
42 
43 
44 void TCCPlotsBase::book(TH1*& pHisto, const std::string& histoIdentifier, const std::string& folder) {
45  const SingleHistogramDefinition hd = retrieveDefinition(histoIdentifier, folder);
46  if (hd.empty()) {
47  ATH_MSG_WARNING("Histogram definition is empty for identifier " << histoIdentifier);
48  }
49  book(pHisto, hd);
50 }
51 
53  if (hd.isValid()) {
54  pHisto = Book1D(hd.name, hd.allTitles,
55  hd.nBinsX, hd.xAxis.first, hd.xAxis.second,
56  false);
57  }
58  }
59 
60 void TCCPlotsBase::book(TH2*& pHisto, const std::string& histoIdentifier, const std::string& folder) {
61  const SingleHistogramDefinition hd = retrieveDefinition(histoIdentifier, folder);
62  if (hd.empty()) {
63  ATH_MSG_WARNING("Histogram definition is empty for identifier " << histoIdentifier);
64  }
65  book(pHisto, hd);
66 }
67 
69  if (hd.isValid()) {
70  pHisto = Book2D(hd.name, hd.allTitles,
71  hd.nBinsX, hd.xAxis.first, hd.xAxis.second,
72  hd.nBinsY, hd.yAxis.first, hd.yAxis.second,
73  false);
74  }
75  }
76 
77 void TCCPlotsBase::book(TH3*& pHisto, const std::string& histoIdentifier, const std::string& folder) {
78  const SingleHistogramDefinition hd = retrieveDefinition(histoIdentifier, folder);
79  if (hd.empty()) {
80  ATH_MSG_WARNING("Histogram definition is empty for identifier " << histoIdentifier);
81  }
82  book(pHisto, hd);
83 }
84 
86  if (hd.isValid()) {
87  pHisto = Book3D(hd.name, hd.allTitles,
88  hd.nBinsX, hd.xAxis.first, hd.xAxis.second,
89  hd.nBinsY, hd.yAxis.first, hd.yAxis.second,
90  hd.nBinsZ, hd.zAxis.first, hd.zAxis.second,
91  false);
92  }
93  }
94 
95 //
96 void TCCPlotsBase::fillHisto(TH1* pTh1, const float value) {
97  if (pTh1 and validArguments(value)) {
98  pTh1->Fill(value);
99  }
100 }
101 
102 void TCCPlotsBase::fillHisto(TH1* pTh1, const float value, const float weight) {
103  if (pTh1 and validArguments(value)) {
104  pTh1->Fill(value, weight);
105  }
106 }
107 
108 //
109 void TCCPlotsBase::fillHisto(TH2* pTh2, const float xval, const float yval) {
110  if (pTh2 and validArguments(xval, yval)) {
111  pTh2->Fill(xval, yval);
112  }
113 }
114 
115 void TCCPlotsBase::fillHisto(TH2* pTh2, const float xval, const float yval, const float weight) {
116  if (pTh2 and validArguments(xval, yval)) {
117  pTh2->Fill(xval, yval, weight);
118  }
119 }
120 
121 //
122 void TCCPlotsBase::fillHisto(TH3* pTh3, const float xval, const float yval, const float zval) {
123  if (pTh3 and validArguments(xval, yval, zval)) {
124  pTh3->Fill(xval, yval, zval);
125  }
126 }
127 
128 void TCCPlotsBase::fillHisto(TH3* pTh3, const float xval, const float yval, const float zval, const float weight) {
129  if (pTh3 and validArguments(xval, yval, zval)) {
130  pTh3->Fill(xval, yval, zval, weight);
131  }
132 }
133 
134 SingleHistogramDefinition TCCPlotsBase::retrieveDefinition(const std::string& histoIdentifier, const std::string& folder) {
135  SingleHistogramDefinition s; // invalid result
136 
137  ATH_MSG_DEBUG("Retrieving SingleHistogramDefinition for "<< histoIdentifier);
138 
139  if (not m_histoDefSvc) {
140  ISvcLocator* svcLoc = Gaudi::svcLocator();
141  StatusCode sc = svcLoc->service("HistogramDefinitionSvc", m_histoDefSvc);
142  if (sc.isFailure()) {
143  ATH_MSG_FATAL("failed to retrieve HistogramDefinitionSvc in " << __FILE__);
144  throw std::runtime_error("Could initialise the HistogramDefinitionSvc");
145  return s;
146  }
147  }
148  bool folderDefault = (folder.empty() or folder == "default");
149  s = m_histoDefSvc->definition(histoIdentifier, folder);
150  // "default" and empty string should be equivalent
151  if (folderDefault and s.empty()) {
152  const std::string otherDefault = (folder.empty()) ? ("default") : "";
153  s = m_histoDefSvc->definition(histoIdentifier, otherDefault);
154  }
155  if (s.empty()) {
156  ATH_MSG_WARNING("Histogram definition is empty for identifier " << histoIdentifier);
157  }
158  return s;
159 }
SingleHistogramDefinition::nBinsX
unsigned int nBinsX
Definition: SingleHistogramDefinition.h:47
TH2::Fill
int Fill(double, double)
Definition: rootspy.cxx:382
SingleHistogramDefinition.h
PlotBase::Book1D
TH1F * 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:88
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
PlotBase
Definition: PlotBase.h:33
SingleHistogramDefinition::nBinsZ
unsigned int nBinsZ
Definition: SingleHistogramDefinition.h:49
HistogramDefinitionSvc.h
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 TH2D histogram.
Definition: PlotBase.cxx:117
athena.value
value
Definition: athena.py:122
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
SingleHistogramDefinition::xAxis
IHistogramDefinitionSvc::axesLimits_t xAxis
Definition: SingleHistogramDefinition.h:50
TCCPlotsBase.h
TCCPlotsBase::fillHisto
static void fillHisto(TH1 *pTh1, const float value)
Definition: TCCPlotsBase.cxx:96
TCCPlotsBase::retrieveDefinition
SingleHistogramDefinition retrieveDefinition(const std::string &histoIdentifier, const std::string &folder="default")
Retrieve a single histogram definition, given the unique string identifier.
Definition: TCCPlotsBase.cxx:134
TH3::Fill
int Fill(double, double, double)
Definition: rootspy.cxx:453
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TCCPlotsBase::m_histoDefSvc
IHistogramDefinitionSvc * m_histoDefSvc
Definition: TCCPlotsBase.h:49
TH3
Definition: rootspy.cxx:440
plotting.yearwise_efficiency.yval
float yval
Definition: yearwise_efficiency.py:43
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
IHistogramDefinitionSvc::definition
virtual SingleHistogramDefinition definition(const std::string &name, const std::string &dirName="") const =0
Return a histogram definition, retrieved by histogram identifier (and directory name,...
TH1::Fill
int Fill(double)
Definition: rootspy.cxx:285
plotting.yearwise_efficiency.xval
float xval
Definition: yearwise_efficiency.py:42
TH2
Definition: rootspy.cxx:373
PlotBase::Book3D
TH3F * Book3D(const std::string &name, const std::string &labels, int nBinsX, float startX, float endX, int nBinsY, float startY, float endY, int nBinsZ, float startZ, float endZ, bool prependDir=true)
Book a TH3D histogram.
Definition: PlotBase.cxx:151
SingleHistogramDefinition
Almost-a-struct for holding the single histogram definition.
Definition: SingleHistogramDefinition.h:17
create_dcsc_inputs_sqlite.arg
list arg
Definition: create_dcsc_inputs_sqlite.py:48
TCCPlotsBase::TCCPlotsBase
TCCPlotsBase(PlotBase *pParent, const std::string &folder)
Definition: TCCPlotsBase.cxx:37
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TH1
Definition: rootspy.cxx:268
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
SingleHistogramDefinition::zAxis
IHistogramDefinitionSvc::axesLimits_t zAxis
Definition: SingleHistogramDefinition.h:52
SingleHistogramDefinition::empty
bool empty() const
Is the histogram definition empty?
Definition: SingleHistogramDefinition.cxx:81
TCCPlotsBase::book
void book(TH1 *&pHisto, const SingleHistogramDefinition &hd)
Book a TH1 histogram.
Definition: TCCPlotsBase.cxx:52
SingleHistogramDefinition::nBinsY
unsigned int nBinsY
Definition: SingleHistogramDefinition.h:48