ATLAS Offline Software
Loading...
Searching...
No Matches
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
9
10#include "InDetPlotBase.h"
12
13#include "TEfficiency.h"
14
15#include <cmath>
16
17namespace {
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
35InDetPlotBase::InDetPlotBase(InDetPlotBase* pParent, const std::string& dirName) :
36 PlotBase(pParent, dirName),
37 AthMessaging("InDetPlotBase"),
38 m_histoDefSvc("HistogramDefinitionSvc", "InDetPlotBase")
39{
40}
41
42void
44 if (hd.isValid()) {
45 pHisto = Book1D(hd.name, hd.allTitles, hd.nBinsX, hd.xAxis.first, hd.xAxis.second, false);
46 }
47 }
48void
49InDetPlotBase::book(TProfile*& pHisto, const SingleHistogramDefinition& hd) {
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 }
55void
56InDetPlotBase::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 }
62void
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/**/
70void
71InDetPlotBase::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
81void
82InDetPlotBase::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
88void
89InDetPlotBase::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//
96void
97InDetPlotBase::fillHisto(TH1* pTh1, const float value) {
98 if (pTh1 and validArguments(value)) {
99 pTh1->Fill(value);
100 }
101}
102
103void
104InDetPlotBase::fillHisto(TH1* pTh1, const float value, const float weight) {
105 if (pTh1 and validArguments(value)) {
106 pTh1->Fill(value, weight);
107 }
108}
109
110//
111void
112InDetPlotBase::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//
119void
120InDetPlotBase::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
126void
127InDetPlotBase::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
133void
134InDetPlotBase::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
141void
142InDetPlotBase::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/**/
151InDetPlotBase::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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
static void fillHisto(TProfile *pTprofile, const float bin, const float weight, const float weight2=1.0)
ServiceHandle< IHistogramDefinitionSvc > m_histoDefSvc
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.
InDetPlotBase(InDetPlotBase *pParent, const std::string &dirName)
Constructor taking parent node and directory name for plots.
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.
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
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
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
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
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
Almost-a-struct for holding the single histogram definition.
bool isValid() const
Is the histogram definition valid.
IHistogramDefinitionSvc::axesLimits_t xAxis
IHistogramDefinitionSvc::axesLimits_t yAxis