Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  ISvcLocator* svcLoc = Gaudi::svcLocator();
55  SmartIF<IPlotsDefinitionSvc> plotsDefSvc(svcLoc->service( "PlotsDefSvc"+m_anaTag ));
56  ATH_CHECK( plotsDefSvc.isValid(), {} );
57 
59  SinglePlotDefinition sDef = plotsDefSvc->definition( identifier );
60 
62  if( sDef.isEmpty() or not sDef.isValid() ) return sDef;
63 
65  if( not folderOverride.empty() ) sDef.folder( folderOverride );
66 
68  if( not nameOverride.empty() ) sDef.name( nameOverride );
69 
70  return sDef;
71 }
72 
73 
79  TH1*& pHisto, const IDTPM::SinglePlotDefinition& def )
80 {
81  if( not def.isValid() ) {
82  ATH_MSG_ERROR( "Non-valid TH1 plot : " << def.identifier() );
83  return StatusCode::FAILURE;
84  }
85 
86  pHisto = Book1D( def.name(), def.titleDigest(),
87  def.nBinsX(), def.xLow(), def.xHigh(),
88  false );
89 
90  if( def.doLogLinBinsX() ) {
91  ATH_CHECK( setLogLinearBins( pHisto, def.nBinsX(), def.xLow(), def.xHigh(), 'X' ) );
92  }
93 
94  if( def.doVarBinsX() ) {
95  ATH_CHECK( setVariableBins( pHisto, def.xBinsVec(), 'X' ) );
96  }
97 
98  if( not def.xBinLabelsVec().empty() ) {
99  ATH_CHECK( setBinLabels( pHisto, def.xBinLabelsVec(), 'X' ) );
100  }
101 
102  return StatusCode::SUCCESS;
103 }
104 
105 
108  TH2*& pHisto, const IDTPM::SinglePlotDefinition& def )
109 {
110  if( not def.isValid() ) {
111  ATH_MSG_ERROR( "Non-valid TH2 plot : " << def.identifier() );
112  return StatusCode::FAILURE;
113  }
114 
115  pHisto = Book2D( def.name(), def.titleDigest(),
116  def.nBinsX(), def.xLow(), def.xHigh(),
117  def.nBinsY(), def.yLow(), def.yHigh(),
118  false );
119 
120  if( def.doLogLinBinsX() ) {
121  ATH_CHECK( setLogLinearBins( pHisto, def.nBinsX(), def.xLow(), def.xHigh(), 'X' ) );
122  }
123 
124  if( def.doLogLinBinsY() ) {
125  ATH_CHECK( setLogLinearBins( pHisto, def.nBinsY(), def.yLow(), def.yHigh(), 'Y' ) );
126  }
127 
128  if( def.doVarBinsX() ) {
129  ATH_CHECK( setVariableBins( pHisto, def.xBinsVec(), 'X' ) );
130  }
131 
132  if( def.doVarBinsY() ) {
133  ATH_CHECK( setVariableBins( pHisto, def.yBinsVec(), 'Y' ) );
134  }
135 
136  if( not def.xBinLabelsVec().empty() ) {
137  ATH_CHECK( setBinLabels( pHisto, def.xBinLabelsVec(), 'X' ) );
138  }
139 
140  if( not def.yBinLabelsVec().empty() ) {
141  ATH_CHECK( setBinLabels( pHisto, def.yBinLabelsVec(), 'Y' ) );
142  }
143 
144  return StatusCode::SUCCESS;
145 }
146 
147 
150  TH3*& pHisto, const IDTPM::SinglePlotDefinition& def )
151 {
152  if( not def.isValid() ) {
153  ATH_MSG_ERROR( "Non-valid TH3 plot : " << def.identifier() );
154  return StatusCode::FAILURE;
155  }
156 
157  pHisto = Book3D( def.name(), def.titleDigest(),
158  def.nBinsX(), def.xLow(), def.xHigh(),
159  def.nBinsY(), def.yLow(), def.yHigh(),
160  def.nBinsZ(), def.zLow(), def.zHigh(),
161  false );
162 
163  if( def.doLogLinBinsX() ) {
164  ATH_CHECK( setLogLinearBins( pHisto, def.nBinsX(), def.xLow(), def.xHigh(), 'X' ) );
165  }
166 
167  if( def.doLogLinBinsY() ) {
168  ATH_CHECK( setLogLinearBins( pHisto, def.nBinsY(), def.yLow(), def.yHigh(), 'Y' ) );
169  }
170 
171  if( def.doLogLinBinsZ() ) {
172  ATH_CHECK( setLogLinearBins( pHisto, def.nBinsZ(), def.zLow(), def.zHigh(), 'Z' ) );
173  }
174 
175  if( def.doVarBinsX() ) {
176  ATH_CHECK( setVariableBins( pHisto, def.xBinsVec(), 'X' ) );
177  }
178 
179  if( def.doVarBinsY() ) {
180  ATH_CHECK( setVariableBins( pHisto, def.yBinsVec(), 'Y' ) );
181  }
182 
183  if( def.doVarBinsZ() ) {
184  ATH_CHECK( setVariableBins( pHisto, def.zBinsVec(), 'Z' ) );
185  }
186 
187  if( not def.xBinLabelsVec().empty() ) {
188  ATH_CHECK( setBinLabels( pHisto, def.xBinLabelsVec(), 'X' ) );
189  }
190 
191  if( not def.yBinLabelsVec().empty() ) {
192  ATH_CHECK( setBinLabels( pHisto, def.yBinLabelsVec(), 'Y' ) );
193  }
194 
195  if( not def.zBinLabelsVec().empty() ) {
196  ATH_CHECK( setBinLabels( pHisto, def.zBinLabelsVec(), 'Z' ) );
197  }
198 
199  return StatusCode::SUCCESS;
200 }
201 
202 
205  TProfile*& pHisto, const IDTPM::SinglePlotDefinition& def )
206 {
207  if( not def.isValid() ) {
208  ATH_MSG_ERROR( "Non-valid TProfile plot : " << def.identifier() );
209  return StatusCode::FAILURE;
210  }
211 
212  pHisto = BookTProfile( def.name(), def.titleDigest(),
213  def.nBinsX(), def.xLow(), def.xHigh(),
214  def.yLow(), def.yHigh(),
215  false );
216 
217  if( def.doLogLinBinsX() ) {
218  ATH_CHECK( setLogLinearBins( pHisto, def.nBinsX(), def.xLow(), def.xHigh(), 'X' ) );
219  }
220 
221  if( def.doVarBinsX() ) {
222  ATH_CHECK( setVariableBins( pHisto, def.xBinsVec(), 'X' ) );
223  }
224 
225  if( not def.xBinLabelsVec().empty() ) {
226  ATH_CHECK( setBinLabels( pHisto, def.xBinLabelsVec(), 'X' ) );
227  }
228 
229  return StatusCode::SUCCESS;
230 }
231 
232 
235  TProfile2D*& pHisto, const IDTPM::SinglePlotDefinition& def )
236 {
237  if( not def.isValid() ) {
238  ATH_MSG_ERROR( "Non-valid TProfile2D plot : " << def.identifier() );
239  return StatusCode::FAILURE;
240  }
241 
242  pHisto = BookTProfile2D( def.name(), def.titleDigest(),
243  def.nBinsX(), def.xLow(), def.xHigh(),
244  def.nBinsY(), def.yLow(), def.yHigh(),
245  false );
246 
247  if( def.doLogLinBinsX() ) {
248  ATH_CHECK( setLogLinearBins( pHisto, def.nBinsX(), def.xLow(), def.xHigh(), 'X' ) );
249  }
250 
251  if( def.doLogLinBinsY() ) {
252  ATH_CHECK( setLogLinearBins( pHisto, def.nBinsY(), def.yLow(), def.yHigh(), 'Y' ) );
253  }
254 
255  if( def.doVarBinsX() ) {
256  ATH_CHECK( setVariableBins( pHisto, def.xBinsVec(), 'X' ) );
257  }
258 
259  if( def.doVarBinsY() ) {
260  ATH_CHECK( setVariableBins( pHisto, def.yBinsVec(), 'Y' ) );
261  }
262 
263  if( not def.xBinLabelsVec().empty() ) {
264  ATH_CHECK( setBinLabels( pHisto, def.xBinLabelsVec(), 'X' ) );
265  }
266 
267  if( not def.yBinLabelsVec().empty() ) {
268  ATH_CHECK( setBinLabels( pHisto, def.yBinLabelsVec(), 'Y' ) );
269  }
270 
271  return StatusCode::SUCCESS;
272 }
273 
274 
277  TEfficiency*& pHisto, const IDTPM::SinglePlotDefinition& def )
278 {
279  if( not def.isValid() ) {
280  ATH_MSG_ERROR( "Non-valid TEfficiency plot : " << def.identifier() );
281  return StatusCode::FAILURE;
282  }
283 
284  pHisto = ( def.nBinsY() == 0 ) ?
285  BookTEfficiency( def.name(), def.titleDigest(),
286  def.nBinsX(), def.xLow(), def.xHigh(),
287  false ) :
288  BookTEfficiency( def.name(), def.titleDigest(),
289  def.nBinsX(), def.xLow(), def.xHigh(),
290  def.nBinsY(), def.yLow(), def.yHigh(),
291  false );
292 
293  if( def.doLogLinBinsX() ) {
294  ATH_CHECK( setLogLinearBinsEff( pHisto, def.nBinsX(), def.xLow(), def.xHigh(), 'X' ) );
295  }
296 
297  if( def.doLogLinBinsY() and def.nBinsY() != 0 ) {
298  ATH_CHECK( setLogLinearBinsEff( pHisto, def.nBinsY(), def.yLow(), def.yHigh(), 'Y' ) );
299  }
300 
301  if( def.doVarBinsX() ) {
302  ATH_CHECK( setVariableBinsEff( pHisto, def.xBinsVec(), 'X' ) );
303  }
304 
305  if( def.doVarBinsY() and def.nBinsY() != 0 ) {
306  ATH_CHECK( setVariableBinsEff( pHisto, def.yBinsVec(), 'Y' ) );
307  }
308 
309  return StatusCode::SUCCESS;
310 }
311 
312 
318  TH1* pTh1, float value, float weight ) const
319 {
320  if( not pTh1 ) {
321  ATH_MSG_ERROR( "Trying to fill non-definded TH1" );
322  return StatusCode::FAILURE;
323  }
324 
325  if( std::isnan( value ) or std::isnan( weight ) ) {
326  ATH_MSG_ERROR( "Non-valid fill arguments for TH1:" << pTh1->GetName() );
327  return StatusCode::FAILURE;
328  }
329 
331  pTh1->Fill( value, weight );
332  return StatusCode::SUCCESS;
333 }
334 
335 
338  TH2* pTh2, float xval, float yval, float weight ) const
339 {
340  if( not pTh2 ) {
341  ATH_MSG_ERROR( "Trying to fill non-definded TH2" );
342  return StatusCode::FAILURE;
343  }
344 
345  if( std::isnan( xval ) or std::isnan( yval ) or std::isnan( weight ) ) {
346  ATH_MSG_ERROR( "Non-valid fill arguments for TH2:" << pTh2->GetName() );
347  return StatusCode::FAILURE;
348  }
349 
351  pTh2->Fill( xval, yval, weight );
352  return StatusCode::SUCCESS;
353 }
354 
355 
358  TH3* pTh3, float xval, float yval, float zval, float weight ) const
359 {
360  if( not pTh3 ) {
361  ATH_MSG_ERROR( "Trying to fill non-definded TH3" );
362  return StatusCode::FAILURE;
363  }
364 
365  if( std::isnan( xval ) or std::isnan( yval ) or
366  std::isnan( zval ) or std::isnan( weight ) ) {
367  ATH_MSG_ERROR( "Non-valid fill arguments for TH3:" << pTh3->GetName() );
368  return StatusCode::FAILURE;
369  }
370 
371 
373  pTh3->Fill( xval, yval, zval, weight );
374  return StatusCode::SUCCESS;
375 }
376 
377 
380  TProfile* pTprofile, float xval, float yval, float weight ) const
381 {
382  if( not pTprofile ) {
383  ATH_MSG_ERROR( "Trying to fill non-definded TProfile" );
384  return StatusCode::FAILURE;
385  }
386 
387  if( std::isnan( xval ) or std::isnan( yval ) or std::isnan( weight ) ) {
388  ATH_MSG_ERROR( "Non-valid fill arguments for TProfile:" << pTprofile->GetName() );
389  return StatusCode::FAILURE;
390  }
391 
393  pTprofile->Fill( xval, yval, weight );
394  return StatusCode::SUCCESS;
395 }
396 
397 
400  TProfile2D* pTprofile, float xval, float yval, float zval, float weight ) const
401 {
402  if( not pTprofile ) {
403  ATH_MSG_ERROR( "Trying to fill non-definded TProfile2D" );
404  return StatusCode::FAILURE;
405  }
406 
407  if( std::isnan( xval ) or std::isnan( yval ) or
408  std::isnan( zval ) or std::isnan( weight ) ) {
409  ATH_MSG_ERROR( "Non-valid fill arguments for TProfile2D:" << pTprofile->GetName() );
410  return StatusCode::FAILURE;
411  }
412 
414  pTprofile->Fill( xval, yval, zval, weight );
415  return StatusCode::SUCCESS;
416 }
417 
418 
421  TEfficiency* pTeff, float value, bool accepted, float weight ) const
422 {
423  if( not pTeff ) {
424  ATH_MSG_ERROR( "Trying to fill non-definded 1D TEfficiency" );
425  return StatusCode::FAILURE;
426  }
427 
428  if( std::isnan( value ) or std::isnan( weight ) ) {
429  ATH_MSG_ERROR( "Non-valid fill arguments for 1D TEfficiency:" << pTeff->GetName() );
430  return StatusCode::FAILURE;
431  }
432 
435  if( weight==1.) pTeff->Fill( accepted, value );
436  else pTeff->FillWeighted( accepted, weight, value );
437  return StatusCode::SUCCESS;
438 }
439 
440 
443  TEfficiency* pTeff2d, float xvalue, float yvalue, bool accepted, float weight ) const
444 {
445  if( not pTeff2d ) {
446  ATH_MSG_ERROR( "Trying to fill non-definded 2D TEfficiency" );
447  return StatusCode::FAILURE;
448  }
449 
450  if( std::isnan( xvalue ) or std::isnan( yvalue ) or std::isnan( weight ) ) {
451  ATH_MSG_ERROR( "Non-valid fill arguments for 2D TEfficiency:" << pTeff2d->GetName() );
452  return StatusCode::FAILURE;
453  }
454 
457  if( weight==1.) pTeff2d->Fill( accepted, xvalue, yvalue );
458  else pTeff2d->FillWeighted( accepted, weight, xvalue, yvalue );
459  return StatusCode::SUCCESS;
460 }
461 
462 
465  unsigned int nBins, float absMin, float absMax, bool symmetriseAroundZero )
466 {
467  std::vector<float> emptyVec;
469  if( absMin<=0 or absMax<=0 ) {
470  ATH_MSG_WARNING( "absMin or absMax argument to getLogLinearBins is out of range" );
471  return emptyVec;
472  } else if( nBins==0 ) {
473  ATH_MSG_WARNING( "nBins argument to getLogLinearBins is zero" );
474  return emptyVec;
475  }
477  unsigned int asymVecSize = nBins + 1;
478  std::vector<float> theBinning( asymVecSize, 0.);
480  float logStart = std::log( absMin );
481  float logDist = std::log( absMax ) - logStart;
482  float logStep = logDist / (float) nBins;
484  float thisLog{ logStart };
485  for( float& thisBin : theBinning ) {
486  thisBin = std::exp( thisLog );
487  thisLog += logStep;
488  }
489  if( symmetriseAroundZero ) {
491  return emptyVec;
492  }
493  return theBinning;
494 }
IDTPM::PlotMgr::book
StatusCode book(TH1 *&pHisto, const SinglePlotDefinition &def)
Book a TH1 histogram.
Definition: PlotMgr.cxx:78
IDTPM::SinglePlotDefinition::zBinsVec
const std::vector< float > & zBinsVec() const
Definition: SinglePlotDefinition.h:78
IDTPM::SinglePlotDefinition::doVarBinsZ
bool doVarBinsZ() const
Definition: SinglePlotDefinition.h:81
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:464
PlotBase
Definition: PlotBase.h:34
IDTPM::SinglePlotDefinition::name
const std::string & name() const
Definition: SinglePlotDefinition.h:58
IDTPM::SinglePlotDefinition::isEmpty
bool isEmpty() const
Definition: SinglePlotDefinition.h:86
IDTPM::SinglePlotDefinition::isValid
bool isValid() const
Definition: SinglePlotDefinition.cxx:82
IPlotsDefinitionSvc.h
IDTPM::SinglePlotDefinition::doVarBinsX
bool doVarBinsX() const
Definition: SinglePlotDefinition.h:79
IDTPM::SinglePlotDefinition::xBinLabelsVec
const std::vector< std::string > & xBinLabelsVec() const
Definition: SinglePlotDefinition.h:82
IDTPM::SinglePlotDefinition::yLow
float yLow() const
Definition: SinglePlotDefinition.h:69
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
PrintTrkAnaSummary.dirName
dirName
Definition: PrintTrkAnaSummary.py:126
xAOD::identifier
identifier
Definition: UncalibratedMeasurement_v1.cxx:15
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
IDTPM::SinglePlotDefinition::doLogLinBinsY
bool doLogLinBinsY() const
Definition: SinglePlotDefinition.h:74
IDTPM::SinglePlotDefinition::nBinsX
unsigned int nBinsX() const
Definition: SinglePlotDefinition.h:64
IDTPM::SinglePlotDefinition::identifier
const std::string & identifier() const
Definition: SinglePlotDefinition.h:87
IDTPM::SinglePlotDefinition::yBinsVec
const std::vector< float > & yBinsVec() const
Definition: SinglePlotDefinition.h:77
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
IDTPM::SinglePlotDefinition::xHigh
float xHigh() const
Definition: SinglePlotDefinition.h:68
IDTPM::SinglePlotDefinition::nBinsZ
unsigned int nBinsZ() const
Definition: SinglePlotDefinition.h:66
IDTPM::PlotMgr
Definition: PlotMgr.h:33
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
IDTPM::SinglePlotDefinition::zBinLabelsVec
const std::vector< std::string > & zBinLabelsVec() const
Definition: SinglePlotDefinition.h:84
IDTPM::SinglePlotDefinition::doVarBinsY
bool doVarBinsY() const
Definition: SinglePlotDefinition.h:80
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
PlotBase::initialize
void initialize()
Definition: PlotBase.cxx:39
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:72
IDTPM::SinglePlotDefinition::nBinsY
unsigned int nBinsY() const
Definition: SinglePlotDefinition.h:65
IDTPM::SinglePlotDefinition::yHigh
float yHigh() const
Definition: SinglePlotDefinition.h:70
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
IDTPM::SinglePlotDefinition::xBinsVec
const std::vector< float > & xBinsVec() const
Definition: SinglePlotDefinition.h:76
IDTPM::SinglePlotDefinition::xLow
float xLow() const
Definition: SinglePlotDefinition.h:67
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
IDTPM::SinglePlotDefinition::doLogLinBinsZ
bool doLogLinBinsZ() const
Definition: SinglePlotDefinition.h:75
dumpTgcDigiJitter.nBins
list nBins
Definition: dumpTgcDigiJitter.py:29
IDTPM::SinglePlotDefinition::yBinLabelsVec
const std::vector< std::string > & yBinLabelsVec() const
Definition: SinglePlotDefinition.h:83
IDTPM::SinglePlotDefinition::titleDigest
const std::string & titleDigest() const
Definition: SinglePlotDefinition.h:89
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:317
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
IDTPM::SinglePlotDefinition::zLow
float zLow() const
Definition: SinglePlotDefinition.h:71
IDTPM::PlotMgr::initialize
StatusCode initialize()
initialize
Definition: PlotMgr.cxx:37
IDTPM::SinglePlotDefinition::folder
const std::string & folder() const
Definition: SinglePlotDefinition.h:85
IDTPM::SinglePlotDefinition::doLogLinBinsX
bool doLogLinBinsX() const
Definition: SinglePlotDefinition.h:73
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65