ATLAS Offline Software
PlotMgr.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 #include "PlotMgr.h"
13 
15 #include "GaudiKernel/ISvcLocator.h"
16 #include "GaudiKernel/Service.h"
17 
19 #include <cmath> // for std::isnan
20 
21 
26  const std::string& dirName,
27  const std::string& anaTag,
28  PlotMgr* pParent ) :
29  PlotBase( pParent, dirName ),
30  AthMessaging( "PlotMgr"+anaTag ),
31  m_anaTag( anaTag ) { }
32 
33 
38 {
41  return StatusCode::SUCCESS;
42 }
43 
44 
49  const std::string& identifier,
50  const std::string& folderOverride,
51  const std::string& nameOverride ) const
52 {
54  IPlotsDefinitionSvc* plotsDefSvc;
55  ISvcLocator* svcLoc = Gaudi::svcLocator();
56  StatusCode sc = svcLoc->service( "PlotsDefSvc"+m_anaTag, plotsDefSvc );
57  if( sc.isFailure() ) {
58  ATH_MSG_ERROR( "Could not load PlotsDefSvc"+m_anaTag );
59  SinglePlotDefinition nullDef;
60  return nullDef;
61  }
62 
64  SinglePlotDefinition sDef = plotsDefSvc->definition( identifier );
65 
67  if( sDef.isEmpty() or not sDef.isValid() ) return sDef;
68 
70  if( not folderOverride.empty() ) sDef.folder( folderOverride );
71 
73  if( not nameOverride.empty() ) sDef.name( nameOverride );
74 
75  return sDef;
76 }
77 
78 
84  TH1*& pHisto, const IDTPM::SinglePlotDefinition& def )
85 {
86  if( not def.isValid() ) {
87  ATH_MSG_ERROR( "Non-valid TH1 plot : " << def.identifier() );
88  return StatusCode::FAILURE;
89  }
90  pHisto = Book1D( def.name(), def.titleDigest(),
91  def.nBinsX(), def.xLow(), def.xHigh(),
92  false );
93 
94  return StatusCode::SUCCESS;
95 }
96 
97 
100  TH2*& pHisto, const IDTPM::SinglePlotDefinition& def )
101 {
102  if( not def.isValid() ) {
103  ATH_MSG_ERROR( "Non-valid TH2 plot : " << def.identifier() );
104  return StatusCode::FAILURE;
105  }
106  pHisto = Book2D( def.name(), def.titleDigest(),
107  def.nBinsX(), def.xLow(), def.xHigh(),
108  def.nBinsY(), def.yLow(), def.yHigh(),
109  false );
110  return StatusCode::SUCCESS;
111 }
112 
113 
116  TH3*& pHisto, const IDTPM::SinglePlotDefinition& def )
117 {
118  if( not def.isValid() ) {
119  ATH_MSG_ERROR( "Non-valid TH3 plot : " << def.identifier() );
120  return StatusCode::FAILURE;
121  }
122  pHisto = Book3D( def.name(), def.titleDigest(),
123  def.nBinsX(), def.xLow(), def.xHigh(),
124  def.nBinsY(), def.yLow(), def.yHigh(),
125  def.nBinsZ(), def.zLow(), def.zHigh(),
126  false );
127  return StatusCode::SUCCESS;
128 }
129 
130 
133  TProfile*& pHisto, const IDTPM::SinglePlotDefinition& def )
134 {
135  if( not def.isValid() ) {
136  ATH_MSG_ERROR( "Non-valid TProfile plot : " << def.identifier() );
137  return StatusCode::FAILURE;
138  }
139  pHisto = BookTProfile( def.name(), def.titleDigest(),
140  def.nBinsX(), def.xLow(), def.xHigh(),
141  def.yLow(), def.yHigh(),
142  false );
143  return StatusCode::SUCCESS;
144 }
145 
146 
149  TProfile2D*& pHisto, const IDTPM::SinglePlotDefinition& def )
150 {
151  if( not def.isValid() ) {
152  ATH_MSG_ERROR( "Non-valid TProfile2D plot : " << def.identifier() );
153  return StatusCode::FAILURE;
154  }
155  pHisto = BookTProfile2D( def.name(), def.titleDigest(),
156  def.nBinsX(), def.xLow(), def.xHigh(),
157  def.nBinsY(), def.yLow(), def.yHigh(),
158  false );
159  return StatusCode::SUCCESS;
160 }
161 
162 
165  TEfficiency*& pHisto, const IDTPM::SinglePlotDefinition& def )
166 {
167  if( not def.isValid() ) {
168  ATH_MSG_ERROR( "Non-valid TEfficiency plot : " << def.identifier() );
169  return StatusCode::FAILURE;
170  }
171  pHisto = ( def.nBinsY() == 0 ) ?
172  BookTEfficiency( def.name(), def.titleDigest(),
173  def.nBinsX(), def.xLow(), def.xHigh(),
174  false ) :
175  BookTEfficiency( def.name(), def.titleDigest(),
176  def.nBinsX(), def.xLow(), def.xHigh(),
177  def.nBinsY(), def.yLow(), def.yHigh(),
178  false );
179  return StatusCode::SUCCESS;
180 }
181 
182 
188  TH1* pTh1, float value, float weight ) const
189 {
190  if( not pTh1 ) {
191  ATH_MSG_ERROR( "Trying to fill non-definded TH1" );
192  return StatusCode::FAILURE;
193  }
194 
195  if( std::isnan( value ) or std::isnan( weight ) ) {
196  ATH_MSG_ERROR( "Non-valid fill arguments for TH1:" << pTh1->GetName() );
197  return StatusCode::FAILURE;
198  }
199 
201  pTh1->Fill( value, weight );
202  return StatusCode::SUCCESS;
203 }
204 
205 
208  TH2* pTh2, float xval, float yval, float weight ) const
209 {
210  if( not pTh2 ) {
211  ATH_MSG_ERROR( "Trying to fill non-definded TH2" );
212  return StatusCode::FAILURE;
213  }
214 
215  if( std::isnan( xval ) or std::isnan( yval ) or std::isnan( weight ) ) {
216  ATH_MSG_ERROR( "Non-valid fill arguments for TH2:" << pTh2->GetName() );
217  return StatusCode::FAILURE;
218  }
219 
221  pTh2->Fill( xval, yval, weight );
222  return StatusCode::SUCCESS;
223 }
224 
225 
228  TH3* pTh3, float xval, float yval, float zval, float weight ) const
229 {
230  if( not pTh3 ) {
231  ATH_MSG_ERROR( "Trying to fill non-definded TH3" );
232  return StatusCode::FAILURE;
233  }
234 
235  if( std::isnan( xval ) or std::isnan( yval ) or
236  std::isnan( zval ) or std::isnan( weight ) ) {
237  ATH_MSG_ERROR( "Non-valid fill arguments for TH3:" << pTh3->GetName() );
238  return StatusCode::FAILURE;
239  }
240 
241 
243  pTh3->Fill( xval, yval, zval, weight );
244  return StatusCode::SUCCESS;
245 }
246 
247 
250  TProfile* pTprofile, float xval, float yval, float weight ) const
251 {
252  if( not pTprofile ) {
253  ATH_MSG_ERROR( "Trying to fill non-definded TProfile" );
254  return StatusCode::FAILURE;
255  }
256 
257  if( std::isnan( xval ) or std::isnan( yval ) or std::isnan( weight ) ) {
258  ATH_MSG_ERROR( "Non-valid fill arguments for TProfile:" << pTprofile->GetName() );
259  return StatusCode::FAILURE;
260  }
261 
263  pTprofile->Fill( xval, yval, weight );
264  return StatusCode::SUCCESS;
265 }
266 
267 
270  TProfile2D* pTprofile, float xval, float yval, float zval, float weight ) const
271 {
272  if( not pTprofile ) {
273  ATH_MSG_ERROR( "Trying to fill non-definded TProfile2D" );
274  return StatusCode::FAILURE;
275  }
276 
277  if( std::isnan( xval ) or std::isnan( yval ) or
278  std::isnan( zval ) or std::isnan( weight ) ) {
279  ATH_MSG_ERROR( "Non-valid fill arguments for TProfile2D:" << pTprofile->GetName() );
280  return StatusCode::FAILURE;
281  }
282 
284  pTprofile->Fill( xval, yval, zval, weight );
285  return StatusCode::SUCCESS;
286 }
287 
288 
291  TEfficiency* pTeff, float value, bool accepted, float weight ) const
292 {
293  if( not pTeff ) {
294  ATH_MSG_ERROR( "Trying to fill non-definded 1D TEfficiency" );
295  return StatusCode::FAILURE;
296  }
297 
298  if( std::isnan( value ) or std::isnan( weight ) ) {
299  ATH_MSG_ERROR( "Non-valid fill arguments for 1D TEfficiency:" << pTeff->GetName() );
300  return StatusCode::FAILURE;
301  }
302 
305  if( weight==1.) pTeff->Fill( accepted, value );
306  else pTeff->FillWeighted( accepted, weight, value );
307  return StatusCode::SUCCESS;
308 }
309 
310 
313  TEfficiency* pTeff2d, float xvalue, float yvalue, bool accepted, float weight ) const
314 {
315  if( not pTeff2d ) {
316  ATH_MSG_ERROR( "Trying to fill non-definded 2D TEfficiency" );
317  return StatusCode::FAILURE;
318  }
319 
320  if( std::isnan( xvalue ) or std::isnan( yvalue ) or std::isnan( weight ) ) {
321  ATH_MSG_ERROR( "Non-valid fill arguments for 2D TEfficiency:" << pTeff2d->GetName() );
322  return StatusCode::FAILURE;
323  }
324 
327  if( weight==1.) pTeff2d->Fill( accepted, xvalue, yvalue );
328  else pTeff2d->FillWeighted( accepted, weight, xvalue, yvalue );
329  return StatusCode::SUCCESS;
330 }
IDTPM::PlotMgr::book
StatusCode book(TH1 *&pHisto, const SinglePlotDefinition &def)
Book a TH1 histogram.
Definition: PlotMgr.cxx:83
IPlotsDefinitionSvc
Definition: IPlotsDefinitionSvc.h:31
PlotBase
Definition: PlotBase.h:33
IDTPM::SinglePlotDefinition::name
const std::string & name() const
Definition: SinglePlotDefinition.h:51
IDTPM::SinglePlotDefinition::isEmpty
bool isEmpty() const
Definition: SinglePlotDefinition.h:67
IDTPM::SinglePlotDefinition::isValid
bool isValid() const
Definition: SinglePlotDefinition.cxx:65
IPlotsDefinitionSvc.h
TProfile2D
Definition: rootspy.cxx:531
IDTPM::SinglePlotDefinition::yLow
float yLow() const
Definition: SinglePlotDefinition.h:62
athena.value
value
Definition: athena.py:122
IDTPM::SinglePlotDefinition
Definition: SinglePlotDefinition.h:24
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
IDTPM::SinglePlotDefinition::nBinsX
unsigned int nBinsX() const
Definition: SinglePlotDefinition.h:57
IDTPM::SinglePlotDefinition::identifier
const std::string & identifier() const
Definition: SinglePlotDefinition.h:68
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
IDTPM::SinglePlotDefinition::xHigh
float xHigh() const
Definition: SinglePlotDefinition.h:61
IDTPM::SinglePlotDefinition::nBinsZ
unsigned int nBinsZ() const
Definition: SinglePlotDefinition.h:59
IDTPM::PlotMgr
Definition: PlotMgr.h:32
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
PlotBase::initialize
void initialize()
Definition: PlotBase.cxx:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
PlotMgr.h
Derived class to give extra capabilities to TrkValHistUtils/PlotBase.h such as ATH_MSG and an easier ...
IDTPM::SinglePlotDefinition::zHigh
float zHigh() const
Definition: SinglePlotDefinition.h:65
TH3
Definition: rootspy.cxx:440
IDTPM::SinglePlotDefinition::nBinsY
unsigned int nBinsY() const
Definition: SinglePlotDefinition.h:58
plotting.yearwise_efficiency.yval
float yval
Definition: yearwise_efficiency.py:43
IDTPM::SinglePlotDefinition::yHigh
float yHigh() const
Definition: SinglePlotDefinition.h:63
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
IDTPM::SinglePlotDefinition::xLow
float xLow() const
Definition: SinglePlotDefinition.h:60
IPlotsDefinitionSvc::definition
virtual const IDTPM::SinglePlotDefinition & definition(const std::string &identifier) const =0
Get the plot definition.
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
plotting.yearwise_efficiency.xval
float xval
Definition: yearwise_efficiency.py:42
TH2
Definition: rootspy.cxx:373
IDTPM::SinglePlotDefinition::titleDigest
const std::string & titleDigest() const
Definition: SinglePlotDefinition.h:70
TProfile
Definition: rootspy.cxx:515
IDTPM::PlotMgr::fill
StatusCode fill(TH1 *pTh1, float value, float weight=1.) const
Definition: PlotMgr.cxx:187
TH1
Definition: rootspy.cxx:268
IDTPM::SinglePlotDefinition::zLow
float zLow() const
Definition: SinglePlotDefinition.h:64
IDTPM::PlotMgr::initialize
StatusCode initialize()
initialize
Definition: PlotMgr.cxx:37
IDTPM::SinglePlotDefinition::folder
const std::string & folder() const
Definition: SinglePlotDefinition.h:66