ATLAS Offline Software
Loading...
Searching...
No Matches
PlotMgr.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef INDETTRACKPERFMON_PLOTMGR_H
6#define INDETTRACKPERFMON_PLOTMGR_H
7
16
22
25
27#include <string>
28#include <string_view>
29#include <vector>
30
31
32namespace IDTPM {
33
34 class PlotMgr : public PlotBase, public AthMessaging {
35
36 public:
37
40 PlotMgr( const std::string& dirName,
41 const std::string& anaTag,
42 PlotMgr* pParent = nullptr );
43
45 virtual ~PlotMgr() = default;
46
48 StatusCode initialize();
49
52 const std::string& identifier,
53 std::string_view folderOverride = "",
54 std::string_view nameOverride = "" ) const;
55
64 template < class P >
65 StatusCode retrieveAndBook(
66 P*& pHisto,
67 const std::string& identifier,
68 std::string_view folderOverride = "",
69 std::string_view nameOverride = "" )
70 {
71 const SinglePlotDefinition& def =
72 retrieveDefinition( identifier, folderOverride, nameOverride );
73 if( def.isEmpty() or not def.isValid() ) {
74 ATH_MSG_WARNING( "Trying to book empty or non-valid plot : " << identifier );
75 return StatusCode::RECOVERABLE;
76 }
77 ATH_CHECK( book( pHisto, def ) );
78 return StatusCode::SUCCESS;
79 }
80
82 StatusCode book( TH1*& pHisto, const SinglePlotDefinition& def );
83
85 StatusCode book( TH2*& pHisto, const SinglePlotDefinition& def );
86
88 StatusCode book( TH3*& pHisto, const SinglePlotDefinition& def );
89
91 StatusCode book( TProfile*& pHisto, const SinglePlotDefinition& def );
92
94 StatusCode book( TProfile2D*& pHisto, const SinglePlotDefinition& def );
95
97 StatusCode book( TEfficiency*& pHisto, const SinglePlotDefinition& def );
98
103 StatusCode fill(
104 TH1* pTh1, float value, float weight=1. ) const;
105
107 StatusCode fill(
108 TH2* pTh2, float xval, float yval, float weight=1. ) const;
109
111 StatusCode fill(
112 TH3* pTh3, float xval, float yval, float zval, float weight=1. ) const;
113
116 StatusCode fill(
117 TProfile* pTprofile, float xval, float yval, float weight=1. ) const;
118
121 StatusCode fill(
122 TProfile2D* pTprofile, float xval, float yval, float zval, float weight=1. ) const;
123
125 StatusCode fill(
126 TEfficiency* pTeff, float value, bool accepted, float weight=1. ) const;
127
129 StatusCode fill(
130 TEfficiency* pTeff2d, float xvalue, float yvalue, bool accepted, float weight=1. ) const;
131
132 protected:
133
135 template < class P >
136 StatusCode setVariableBins(
137 P*& pHisto, const std::vector<float>& binning, char axis )
138 {
139 if( binning.empty() ) {
140 ATH_MSG_ERROR( "Non-valid variable plot binning : " << pHisto->GetName() );
141 return StatusCode::FAILURE;
142 }
143 if( axis == 'X' ) pHisto->GetXaxis()->Set( binning.size()-1, binning.data() );
144 if( axis == 'Y' ) pHisto->GetYaxis()->Set( binning.size()-1, binning.data() );
145 if( axis == 'Z' ) pHisto->GetZaxis()->Set( binning.size()-1, binning.data() );
146 return StatusCode::SUCCESS;
147 }
148
150 template < class P >
152 P*& pHisto, const std::vector<float>& binning, char axis )
153 {
154 if( binning.empty() ) {
155 ATH_MSG_ERROR( "Non-valid variable plot binning : " << pHisto->GetName() );
156 return StatusCode::FAILURE;
157 }
158 std::vector<double> binningD( binning.begin(), binning.end() );
159 if( axis == 'X' ) pHisto->SetBins( binningD.size()-1, binningD.data() );
160 if( axis == 'Y' ) {
161 pHisto->SetBins(
162 pHisto->GetTotalHistogram()->GetNbinsX(),
163 pHisto->GetTotalHistogram()->GetXaxis()->GetXbins()->GetArray(),
164 binningD.size()-1, binningD.data() );
165 }
166 return StatusCode::SUCCESS;
167 }
168
170 template < class P >
172 P*& pHisto, unsigned int nBins, float absMin, float absMax, char axis )
173 {
174 std::vector<float> binning = getLogLinearBins( nBins, absMin, absMax );
175 ATH_CHECK( setVariableBins( pHisto, binning, axis ) );
176 return StatusCode::SUCCESS;
177 }
178
180 template < class P >
182 P*& pHisto, unsigned int nBins, float absMin, float absMax, char axis )
183 {
184 std::vector<float> binning = getLogLinearBins( nBins, absMin, absMax );
185 ATH_CHECK( setVariableBinsEff( pHisto, binning, axis ) );
186 return StatusCode::SUCCESS;
187 }
188
191 std::vector<float> getLogLinearBins(
192 unsigned int nBins, float absMin, float absMax,
193 bool symmetriseAroundZero = false );
194
196 template < class P >
197 StatusCode setBinLabels(
198 P*& pHisto, const std::vector< std::string >& binLabels, char axis )
199 {
200 if( axis == 'X' ) {
201 size_t nBinsX = pHisto->GetXaxis()->GetNbins();
202 if( nBinsX != binLabels.size() ) {
203 ATH_MSG_ERROR( "Mismstch in number of X bin labels for : " << pHisto->GetName() );
204 return StatusCode::FAILURE;
205 }
206 for( size_t bin = 0; bin < nBinsX; bin++ ) {
207 pHisto->GetXaxis()->SetBinLabel( bin+1, binLabels[ bin ].c_str() );
208 }
209 }
210 if( axis == 'Y' ) {
211 size_t nBinsY = pHisto->GetYaxis()->GetNbins();
212 if( nBinsY != binLabels.size() ) {
213 ATH_MSG_ERROR( "Mismstch in number of Y bin labels for : " << pHisto->GetName() );
214 return StatusCode::FAILURE;
215 }
216 for( size_t bin = 0; bin < nBinsY; bin++ ) {
217 pHisto->GetYaxis()->SetBinLabel( bin+1, binLabels[ bin ].c_str() );
218 }
219 }
220 if( axis == 'Z' ) {
221 size_t nBinsZ = pHisto->GetZaxis()->GetNbins();
222 if( nBinsZ != binLabels.size() ) {
223 ATH_MSG_ERROR( "Mismstch in number of Z bin labels for : " << pHisto->GetName() );
224 return StatusCode::FAILURE;
225 }
226 for( size_t bin = 0; bin < nBinsZ; bin++ ) {
227 pHisto->GetZaxis()->SetBinLabel( bin+1, binLabels[ bin ].c_str() );
228 }
229 }
230 return StatusCode::SUCCESS;
231 }
232
233 std::string m_anaTag;
234
235 }; // class PlotMgr
236
237} // namespace IDTPM
238
239#endif // > ! INDETTRACKPERFMON_PLOTMGR_H
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
static Double_t P(Double_t *tt, Double_t *par)
Class to store (internally) each plot definition in this package (originally based on the SingleHisto...
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
StatusCode setLogLinearBins(P *&pHisto, unsigned int nBins, float absMin, float absMax, char axis)
Set Log-Linear axis.
Definition PlotMgr.h:171
StatusCode setVariableBins(P *&pHisto, const std::vector< float > &binning, char axis)
SetVariableBins.
Definition PlotMgr.h:136
StatusCode setBinLabels(P *&pHisto, const std::vector< std::string > &binLabels, char axis)
SetBinLabels (for TH* and TProfile* only).
Definition PlotMgr.h:197
StatusCode setLogLinearBinsEff(P *&pHisto, unsigned int nBins, float absMin, float absMax, char axis)
Set Log-Linear axis (for Efficiencies).
Definition PlotMgr.h:181
StatusCode retrieveAndBook(P *&pHisto, const std::string &identifier, std::string_view folderOverride="", std::string_view nameOverride="")
Definition PlotMgr.h:65
std::string m_anaTag
Definition PlotMgr.h:233
SinglePlotDefinition retrieveDefinition(const std::string &identifier, std::string_view folderOverride="", std::string_view nameOverride="") const
Retrieve a single histogram definition, given the unique string identifier.
Definition PlotMgr.cxx:48
StatusCode book(TH1 *&pHisto, const SinglePlotDefinition &def)
Book a TH1 histogram.
Definition PlotMgr.cxx:78
StatusCode setVariableBinsEff(P *&pHisto, const std::vector< float > &binning, char axis)
SetVariableBins (for Efficiencies).
Definition PlotMgr.h:151
std::vector< float > getLogLinearBins(unsigned int nBins, float absMin, float absMax, bool symmetriseAroundZero=false)
Get Log-Linear binning vector inherited from InDetPhysValMonitoring/src/logLinearBinning....
Definition PlotMgr.cxx:464
StatusCode initialize()
initialize
Definition PlotMgr.cxx:37
StatusCode fill(TH1 *pTh1, float value, float weight=1.) const
Definition PlotMgr.cxx:317
PlotMgr(const std::string &dirName, const std::string &anaTag, PlotMgr *pParent=nullptr)
Constructor taking parent node and directory name for plots pParent = nullptr by default to book plot...
Definition PlotMgr.cxx:25
virtual ~PlotMgr()=default
Destructor.
PlotBase(PlotBase *parent, std::string_view sDir)
Definition PlotBase.cxx:29
Athena include(s).