ATLAS Offline Software
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 
22 
24 #include "SinglePlotDefinition.h"
25 
27 #include <string>
28 #include <vector>
29 
30 
31 namespace 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 
48 
51  const std::string& identifier,
52  const std::string& folderOverride = "",
53  const std::string& nameOverride = "" ) const;
54 
63  template < class P >
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 
103  TH1* pTh1, float value, float weight=1. ) const;
104 
107  TH2* pTh2, float xval, float yval, float weight=1. ) const;
108 
111  TH3* pTh3, float xval, float yval, float zval, float weight=1. ) const;
112 
116  TProfile* pTprofile, float xval, float yval, float weight=1. ) const;
117 
121  TProfile2D* pTprofile, float xval, float yval, float zval, float weight=1. ) const;
122 
125  TEfficiency* pTeff, float value, bool accepted, float weight=1. ) const;
126 
129  TEfficiency* pTeff2d, float xvalue, float yvalue, bool accepted, float weight=1. ) const;
130 
131  protected:
132 
134  template < class P >
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 
194  std::string m_anaTag;
195 
196  }; // class PlotMgr
197 
198 } // namespace IDTPM
199 
200 #endif // > ! INDETTRACKPERFMON_PLOTMGR_H
IDTPM::PlotMgr::book
StatusCode book(TH1 *&pHisto, const SinglePlotDefinition &def)
Book a TH1 histogram.
Definition: PlotMgr.cxx:78
AddEmptyComponent.binning
binning
Definition: AddEmptyComponent.py:34
SinglePlotDefinition.h
Class to store (internally) each plot definition in this package (originally based on the SingleHisto...
IDTPM::PlotMgr::getLogLinearBins
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:428
PlotBase
Definition: PlotBase.h:34
AthCheckMacros.h
AthMsgStreamMacros.h
IDTPM::PlotMgr::setVariableBinsEff
StatusCode setVariableBinsEff(P *&pHisto, const std::vector< float > &binning, char axis)
SetVariableBins (for Efficiencies)
Definition: PlotMgr.h:150
IDTPM::PlotMgr::setLogLinearBinsEff
StatusCode setLogLinearBinsEff(P *&pHisto, unsigned int nBins, float absMin, float absMax, char axis)
Set Log-Linear axis (for Efficiencies)
Definition: PlotMgr.h:180
DMTest::P
P_v1 P
Definition: P.h:23
IDTPM::SinglePlotDefinition::isEmpty
bool isEmpty() const
Definition: SinglePlotDefinition.h:80
IDTPM::SinglePlotDefinition::isValid
bool isValid() const
Definition: SinglePlotDefinition.cxx:72
yodamerge_tmp.axis
list axis
Definition: yodamerge_tmp.py:241
IDTPM::PlotMgr::~PlotMgr
virtual ~PlotMgr()=default
Destructor.
athena.value
value
Definition: athena.py:124
IDTPM::SinglePlotDefinition
Definition: SinglePlotDefinition.h:25
IDTPM::PlotMgr::retrieveDefinition
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
xAOD::identifier
identifier
Definition: UncalibratedMeasurement_v1.cxx:15
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
IDTPM::PlotMgr
Definition: PlotMgr.h:33
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
plotting.yearwise_efficiency_vs_mu.xval
float xval
Definition: yearwise_efficiency_vs_mu.py:35
python.TrigEgammaMonitorHelper.TProfile
def TProfile(*args, **kwargs)
Definition: TrigEgammaMonitorHelper.py:81
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IDTPM::PlotMgr::PlotMgr
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
dumpTgcDigiJitter.nBins
list nBins
Definition: dumpTgcDigiJitter.py:29
plotting.yearwise_efficiency_vs_mu.yval
float yval
Definition: yearwise_efficiency_vs_mu.py:36
IDTPM::PlotMgr::fill
StatusCode fill(TH1 *pTh1, float value, float weight=1.) const
Definition: PlotMgr.cxx:281
IDTPM::PlotMgr::setVariableBins
StatusCode setVariableBins(P *&pHisto, const std::vector< float > &binning, char axis)
SetVariableBins.
Definition: PlotMgr.h:135
IDTPM::PlotMgr::setLogLinearBins
StatusCode setLogLinearBins(P *&pHisto, unsigned int nBins, float absMin, float absMax, char axis)
Set Log-Linear axis.
Definition: PlotMgr.h:170
IDTPM::PlotMgr::retrieveAndBook
StatusCode retrieveAndBook(P *&pHisto, const std::string &identifier, const std::string &folderOverride="", const std::string &nameOverride="")
Definition: PlotMgr.h:64
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AthMessaging.h
IDTPM::PlotMgr::initialize
StatusCode initialize()
initialize
Definition: PlotMgr.cxx:37
IDTPM::PlotMgr::m_anaTag
std::string m_anaTag
Definition: PlotMgr.h:194
IDTPM
Athena include(s).
Definition: IPlotsDefinitionSvc.h:25
PlotBase.h