ATLAS Offline Software
Loading...
Searching...
No Matches
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
18namespace {
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
35TCCPlotsBase::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
42void 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
50void 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
58void 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
66void 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
75void 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
83void 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//
94void TCCPlotsBase::fillHisto(TH1* pTh1, const float value) {
95 if (pTh1 and validArguments(value)) {
96 pTh1->Fill(value);
97 }
98}
99
100void 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//
107void 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
113void 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//
120void 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
126void 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
132SingleHistogramDefinition 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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
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
PlotBase(PlotBase *parent, const std::string &sDir)
Definition PlotBase.cxx:29
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
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
Almost-a-struct for holding the single histogram definition.
bool isValid() const
Is the histogram definition valid.
IHistogramDefinitionSvc::axesLimits_t zAxis
bool empty() const
Is the histogram definition empty?
IHistogramDefinitionSvc::axesLimits_t xAxis
IHistogramDefinitionSvc::axesLimits_t yAxis
std::string m_folder
static void fillHisto(TH1 *pTh1, const float value)
void book(TH1 *&pHisto, const SingleHistogramDefinition &hd)
Book a TH1 histogram.
ServiceHandle< IHistogramDefinitionSvc > m_histoDefSvc
TCCPlotsBase(PlotBase *pParent, const std::string &folder)
SingleHistogramDefinition retrieveDefinition(const std::string &histoIdentifier, const std::string &folder="default")
Retrieve a single histogram definition, given the unique string identifier.