ATLAS Offline Software
TCCPlotsBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 
15 
16 #include <cmath>
17 
18 namespace {
19  bool
20  validArguments(const float arg) {
21  return not (std::isnan(arg));
22  }
23 
24  bool
25  validArguments(const float arg1, const float arg2) {
26  return not (std::isnan(arg1) or std::isnan(arg2));
27  }
28 
29  bool
30  validArguments(const float arg1, const float arg2, const float arg3) {
31  return not (std::isnan(arg1) or std::isnan(arg2) or std::isnan(arg3));
32  }
33 }
34 
35 TCCPlotsBase::TCCPlotsBase(PlotBase* pParent, const std::string& folder):
36  PlotBase(pParent, folder),
37  AthMessaging("TCCPlots"),
38  m_folder(folder),
39  m_histoDefSvc("HistogramDefinitionSvc", "TCCPlots") {}
40 
41 
42 void TCCPlotsBase::book(TH1*& pHisto, const std::string& histoIdentifier, const std::string& folder) {
43  const SingleHistogramDefinition hd = retrieveDefinition(histoIdentifier, folder);
44  if (hd.empty()) {
45  ATH_MSG_WARNING("Histogram definition is empty for identifier " << histoIdentifier);
46  }
47  book(pHisto, hd);
48 }
49 
50 void TCCPlotsBase::book(TH1*& pHisto, const SingleHistogramDefinition& hd) {
51  if (hd.isValid()) {
52  pHisto = Book1D(hd.name, hd.allTitles,
53  hd.nBinsX, hd.xAxis.first, hd.xAxis.second,
54  false);
55  }
56  }
57 
58 void TCCPlotsBase::book(TH2*& pHisto, const std::string& histoIdentifier, const std::string& folder) {
59  const SingleHistogramDefinition hd = retrieveDefinition(histoIdentifier, folder);
60  if (hd.empty()) {
61  ATH_MSG_WARNING("Histogram definition is empty for identifier " << histoIdentifier);
62  }
63  book(pHisto, hd);
64 }
65 
66 void TCCPlotsBase::book(TH2*& pHisto, const SingleHistogramDefinition& hd) {
67  if (hd.isValid()) {
68  pHisto = Book2D(hd.name, hd.allTitles,
69  hd.nBinsX, hd.xAxis.first, hd.xAxis.second,
70  hd.nBinsY, hd.yAxis.first, hd.yAxis.second,
71  false);
72  }
73  }
74 
75 void TCCPlotsBase::book(TH3*& pHisto, const std::string& histoIdentifier, const std::string& folder) {
76  const SingleHistogramDefinition hd = retrieveDefinition(histoIdentifier, folder);
77  if (hd.empty()) {
78  ATH_MSG_WARNING("Histogram definition is empty for identifier " << histoIdentifier);
79  }
80  book(pHisto, hd);
81 }
82 
83 void TCCPlotsBase::book(TH3*& pHisto, const SingleHistogramDefinition& hd) {
84  if (hd.isValid()) {
85  pHisto = Book3D(hd.name, hd.allTitles,
86  hd.nBinsX, hd.xAxis.first, hd.xAxis.second,
87  hd.nBinsY, hd.yAxis.first, hd.yAxis.second,
88  hd.nBinsZ, hd.zAxis.first, hd.zAxis.second,
89  false);
90  }
91  }
92 
93 //
94 void TCCPlotsBase::fillHisto(TH1* pTh1, const float value) {
95  if (pTh1 and validArguments(value)) {
96  pTh1->Fill(value);
97  }
98 }
99 
100 void TCCPlotsBase::fillHisto(TH1* pTh1, const float value, const float weight) {
101  if (pTh1 and validArguments(value)) {
102  pTh1->Fill(value, weight);
103  }
104 }
105 
106 //
107 void TCCPlotsBase::fillHisto(TH2* pTh2, const float xval, const float yval) {
108  if (pTh2 and validArguments(xval, yval)) {
109  pTh2->Fill(xval, yval);
110  }
111 }
112 
113 void TCCPlotsBase::fillHisto(TH2* pTh2, const float xval, const float yval, const float weight) {
114  if (pTh2 and validArguments(xval, yval)) {
115  pTh2->Fill(xval, yval, weight);
116  }
117 }
118 
119 //
120 void TCCPlotsBase::fillHisto(TH3* pTh3, const float xval, const float yval, const float zval) {
121  if (pTh3 and validArguments(xval, yval, zval)) {
122  pTh3->Fill(xval, yval, zval);
123  }
124 }
125 
126 void TCCPlotsBase::fillHisto(TH3* pTh3, const float xval, const float yval, const float zval, const float weight) {
127  if (pTh3 and validArguments(xval, yval, zval)) {
128  pTh3->Fill(xval, yval, zval, weight);
129  }
130 }
131 
132 SingleHistogramDefinition TCCPlotsBase::retrieveDefinition(const std::string& histoIdentifier, const std::string& folder) {
133  SingleHistogramDefinition s; // invalid result
134 
135  ATH_MSG_DEBUG("Retrieving SingleHistogramDefinition for "<< histoIdentifier);
136 
137  ATH_CHECK( m_histoDefSvc.retrieve(), s );
138  bool folderDefault = (folder.empty() or folder == "default");
139  s = m_histoDefSvc->definition(histoIdentifier, folder);
140  // "default" and empty string should be equivalent
141  if (folderDefault and s.empty()) {
142  const std::string otherDefault = (folder.empty()) ? ("default") : "";
143  s = m_histoDefSvc->definition(histoIdentifier, otherDefault);
144  }
145  if (s.empty()) {
146  ATH_MSG_WARNING("Histogram definition is empty for identifier " << histoIdentifier);
147  }
148  return s;
149 }
SingleHistogramDefinition::nBinsX
unsigned int nBinsX
Definition: SingleHistogramDefinition.h:47
SingleHistogramDefinition.h
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
PlotBase
Definition: PlotBase.h:34
AthCheckMacros.h
SingleHistogramDefinition::nBinsZ
unsigned int nBinsZ
Definition: SingleHistogramDefinition.h:49
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
TCCPlotsBase::m_histoDefSvc
ServiceHandle< IHistogramDefinitionSvc > m_histoDefSvc
Definition: TCCPlotsBase.h:50
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
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:94
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:132
plotting.yearwise_efficiency_vs_mu.xval
float xval
Definition: yearwise_efficiency_vs_mu.py:35
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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 TH3F histogram.
Definition: PlotBase.cxx:157
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
plotting.yearwise_efficiency_vs_mu.yval
float yval
Definition: yearwise_efficiency_vs_mu.py:36
TCCPlotsBase::TCCPlotsBase
TCCPlotsBase(PlotBase *pParent, const std::string &folder)
Definition: TCCPlotsBase.cxx:35
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
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:50
SingleHistogramDefinition::nBinsY
unsigned int nBinsY
Definition: SingleHistogramDefinition.h:48