ATLAS Offline Software
Loading...
Searching...
No Matches
PlotMgr.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 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 <vector>
29
30
31namespace IDTPM {
32
33 class PlotMgr : public PlotBase, public AthMessaging {
34
35 public:
36
39 PlotMgr( const std::string& dirName,
40 const std::string& anaTag,
41 PlotMgr* pParent = nullptr );
42
44 virtual ~PlotMgr() = default;
45
47 StatusCode initialize();
48
51 const std::string& identifier,
52 const std::string& folderOverride = "",
53 const std::string& nameOverride = "" ) const;
54
63 template < class P >
64 StatusCode retrieveAndBook(
65 P*& pHisto,
66 const std::string& identifier,
67 const std::string& folderOverride = "",
68 const std::string& nameOverride = "" )
69 {
70 const SinglePlotDefinition& def =
71 retrieveDefinition( identifier, folderOverride, nameOverride );
72 if( def.isEmpty() or not def.isValid() ) {
73 ATH_MSG_WARNING( "Trying to book empty or non-valid plot : " << identifier );
74 return StatusCode::RECOVERABLE;
75 }
76 ATH_CHECK( book( pHisto, def ) );
77 return StatusCode::SUCCESS;
78 }
79
81 StatusCode book( TH1*& pHisto, const SinglePlotDefinition& def );
82
84 StatusCode book( TH2*& pHisto, const SinglePlotDefinition& def );
85
87 StatusCode book( TH3*& pHisto, const SinglePlotDefinition& def );
88
90 StatusCode book( TProfile*& pHisto, const SinglePlotDefinition& def );
91
93 StatusCode book( TProfile2D*& pHisto, const SinglePlotDefinition& def );
94
96 StatusCode book( TEfficiency*& pHisto, const SinglePlotDefinition& def );
97
102 StatusCode fill(
103 TH1* pTh1, float value, float weight=1. ) const;
104
106 StatusCode fill(
107 TH2* pTh2, float xval, float yval, float weight=1. ) const;
108
110 StatusCode fill(
111 TH3* pTh3, float xval, float yval, float zval, float weight=1. ) const;
112
115 StatusCode fill(
116 TProfile* pTprofile, float xval, float yval, float weight=1. ) const;
117
120 StatusCode fill(
121 TProfile2D* pTprofile, float xval, float yval, float zval, float weight=1. ) const;
122
124 StatusCode fill(
125 TEfficiency* pTeff, float value, bool accepted, float weight=1. ) const;
126
128 StatusCode fill(
129 TEfficiency* pTeff2d, float xvalue, float yvalue, bool accepted, float weight=1. ) const;
130
131 protected:
132
134 template < class P >
135 StatusCode setVariableBins(
136 P*& pHisto, const std::vector<float>& binning, char axis )
137 {
138 if( binning.empty() ) {
139 ATH_MSG_ERROR( "Non-valid variable plot binning : " << pHisto->GetName() );
140 return StatusCode::FAILURE;
141 }
142 if( axis == 'X' ) pHisto->GetXaxis()->Set( binning.size()-1, binning.data() );
143 if( axis == 'Y' ) pHisto->GetYaxis()->Set( binning.size()-1, binning.data() );
144 if( axis == 'Z' ) pHisto->GetZaxis()->Set( binning.size()-1, binning.data() );
145 return StatusCode::SUCCESS;
146 }
147
149 template < class P >
151 P*& pHisto, const std::vector<float>& binning, char axis )
152 {
153 if( binning.empty() ) {
154 ATH_MSG_ERROR( "Non-valid variable plot binning : " << pHisto->GetName() );
155 return StatusCode::FAILURE;
156 }
157 std::vector<double> binningD( binning.begin(), binning.end() );
158 if( axis == 'X' ) pHisto->SetBins( binningD.size()-1, binningD.data() );
159 if( axis == 'Y' ) {
160 pHisto->SetBins(
161 pHisto->GetTotalHistogram()->GetNbinsX(),
162 pHisto->GetTotalHistogram()->GetXaxis()->GetXbins()->GetArray(),
163 binningD.size()-1, binningD.data() );
164 }
165 return StatusCode::SUCCESS;
166 }
167
169 template < class P >
171 P*& pHisto, unsigned int nBins, float absMin, float absMax, char axis )
172 {
173 std::vector<float> binning = getLogLinearBins( nBins, absMin, absMax );
174 ATH_CHECK( setVariableBins( pHisto, binning, axis ) );
175 return StatusCode::SUCCESS;
176 }
177
179 template < class P >
181 P*& pHisto, unsigned int nBins, float absMin, float absMax, char axis )
182 {
183 std::vector<float> binning = getLogLinearBins( nBins, absMin, absMax );
184 ATH_CHECK( setVariableBinsEff( pHisto, binning, axis ) );
185 return StatusCode::SUCCESS;
186 }
187
190 std::vector<float> getLogLinearBins(
191 unsigned int nBins, float absMin, float absMax,
192 bool symmetriseAroundZero = false );
193
195 template < class P >
196 StatusCode setBinLabels(
197 P*& pHisto, const std::vector< std::string >& binLabels, char axis )
198 {
199 if( axis == 'X' ) {
200 size_t nBinsX = pHisto->GetXaxis()->GetNbins();
201 if( nBinsX != binLabels.size() ) {
202 ATH_MSG_ERROR( "Mismstch in number of X bin labels for : " << pHisto->GetName() );
203 return StatusCode::FAILURE;
204 }
205 for( size_t bin = 0; bin < nBinsX; bin++ ) {
206 pHisto->GetXaxis()->SetBinLabel( bin+1, binLabels[ bin ].c_str() );
207 }
208 }
209 if( axis == 'Y' ) {
210 size_t nBinsY = pHisto->GetYaxis()->GetNbins();
211 if( nBinsY != binLabels.size() ) {
212 ATH_MSG_ERROR( "Mismstch in number of Y bin labels for : " << pHisto->GetName() );
213 return StatusCode::FAILURE;
214 }
215 for( size_t bin = 0; bin < nBinsY; bin++ ) {
216 pHisto->GetYaxis()->SetBinLabel( bin+1, binLabels[ bin ].c_str() );
217 }
218 }
219 if( axis == 'Z' ) {
220 size_t nBinsZ = pHisto->GetZaxis()->GetNbins();
221 if( nBinsZ != binLabels.size() ) {
222 ATH_MSG_ERROR( "Mismstch in number of Z bin labels for : " << pHisto->GetName() );
223 return StatusCode::FAILURE;
224 }
225 for( size_t bin = 0; bin < nBinsZ; bin++ ) {
226 pHisto->GetZaxis()->SetBinLabel( bin+1, binLabels[ bin ].c_str() );
227 }
228 }
229 return StatusCode::SUCCESS;
230 }
231
232 std::string m_anaTag;
233
234 }; // class PlotMgr
235
236} // namespace IDTPM
237
238#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:170
StatusCode setVariableBins(P *&pHisto, const std::vector< float > &binning, char axis)
SetVariableBins.
Definition PlotMgr.h:135
StatusCode setBinLabels(P *&pHisto, const std::vector< std::string > &binLabels, char axis)
SetBinLabels (for TH* and TProfile* only)
Definition PlotMgr.h:196
StatusCode retrieveAndBook(P *&pHisto, const std::string &identifier, const std::string &folderOverride="", const std::string &nameOverride="")
Definition PlotMgr.h:64
StatusCode setLogLinearBinsEff(P *&pHisto, unsigned int nBins, float absMin, float absMax, char axis)
Set Log-Linear axis (for Efficiencies)
Definition PlotMgr.h:180
std::string m_anaTag
Definition PlotMgr.h:232
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:150
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
SinglePlotDefinition retrieveDefinition(const std::string &identifier, const std::string &folderOverride="", const std::string &nameOverride="") const
Retrieve a single histogram definition, given the unique string identifier.
Definition PlotMgr.cxx:48
virtual ~PlotMgr()=default
Destructor.
PlotBase(PlotBase *parent, const std::string &sDir)
Definition PlotBase.cxx:29
Athena include(s).