ATLAS Offline Software
InDetTrackPerfMonTool.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 "InDetTrackPerfMonTool.h"
12 
14 #include "GaudiKernel/SystemOfUnits.h"
15 
20 
22 #include <algorithm>
23 #include <limits>
24 #include <cmath> // to get std::isnan(), std::abs etc.
25 #include <utility>
26 #include <cstdlib> // to getenv
27 
28 
33  const std::string& type,
34  const std::string& name,
35  const IInterface* parent ) :
37 { }
38 
39 
44 
45 
50 
52 
54  if ( not m_trkAnaDefSvc ) {
55  ATH_MSG_DEBUG( "Retrieving TrkAnaDefSvc" << m_anaTag.value() );
56  m_trkAnaDefSvc = Gaudi::svcLocator()->service( "TrkAnaDefSvc"+m_anaTag.value() );
57  ATH_CHECK( m_trkAnaDefSvc.isValid() );
58  }
59 
60  ATH_MSG_DEBUG( "Initializing sub-tools" );
61 
62  ATH_CHECK( m_trigDecTool.retrieve( EnableTool{ m_trkAnaDefSvc->useTrigger() and not m_trkAnaDefSvc->useEFTrigger() } ) );
63  ATH_CHECK( m_roiSelectionTool.retrieve( EnableTool{ m_trkAnaDefSvc->useTrigger() and not m_trkAnaDefSvc->useEFTrigger() } ) );
64  ATH_CHECK( m_trackRoiSelectionTool.retrieve( EnableTool{ m_trkAnaDefSvc->useTrigger() and not m_trkAnaDefSvc->useEFTrigger()} ) );
65  ATH_CHECK( m_trackMatchingTool.retrieve( EnableTool{ m_doMatch.value() } ) );
66  ATH_CHECK( m_trkAnaInfoWriteTool.retrieve( EnableTool{ m_writeOut.value() } ) );
67 
69 
71  m_trkAnaDefSvc->useOffline() and not m_offlineTrkParticleName.key().empty() ) );
73  m_trkAnaDefSvc->useTrigger() and not m_triggerTrkParticleName.key().empty() ) );
75  m_trkAnaDefSvc->useTruth() and not m_truthParticleName.key().empty() ) );
76  ATH_CHECK( m_truthEventName.initialize(
77  m_trkAnaDefSvc->useTruth() and not m_truthEventName.key().empty() and
78  m_trkAnaDefSvc->pileupSwitch() == "HardScatter" ) );
80  m_trkAnaDefSvc->useTruth() and not m_truthPileUpEventName.key().empty() and
81  m_trkAnaDefSvc->pileupSwitch() == "PileUp" ) );
82 
83  ATH_CHECK( m_trkAnaInfoKey.initialize() );
84 
86  const std::vector< std::string >& configuredChains = m_trkAnaDefSvc->configuredChains();
87  m_trkAnaPlotsMgrVec.reserve( configuredChains.size() );
88 
90  for( const std::string& thisChain : configuredChains ) {
91  ATH_MSG_DEBUG( "Booking TrkAnalysis/histograms for chain : " << thisChain );
92 
95  m_trkAnaPlotsMgrVec.emplace_back(
96  std::make_unique< IDTPM::TrackAnalysisPlotsMgr >(
97  m_trkAnaDefSvc->plotsFullDir( thisChain ),
98  m_anaTag.value(),
99  thisChain ) );
100  } // close m_configuredChains loop
101 
102  return StatusCode::SUCCESS;
103 }
104 
105 
110 {
111  ATH_MSG_INFO( "Booking plots" );
112 
113  for( size_t iAna=0 ; iAna < m_trkAnaPlotsMgrVec.size() ; iAna++ ) {
114 
117 
120  std::vector< HistData > hists = m_trkAnaPlotsMgrVec[iAna]->retrieveBookedHistograms();
121  for ( size_t ih=0 ; ih<hists.size() ; ih++ ) {
122  ATH_CHECK( regHist( hists[ih].first, hists[ih].second, all ) );
123  }
124 
125  // do the same for Efficiencies, but there's a twist:
126  std::vector< EfficiencyData > effs = m_trkAnaPlotsMgrVec[iAna]->retrieveBookedEfficiencies();
127  for ( size_t ie=0 ; ie<effs.size() ; ie++ ) {
128  ATH_CHECK( regEfficiency( effs[ie].first, MonGroup( this, effs[ie].second, all ) ) );
129  }
130 
131  } // closing loop over TrkAnalyses
132 
133  return StatusCode::SUCCESS;
134 }
135 
136 
141 
142  ATH_MSG_INFO( "Filling hists " << name() << " ..." );
143 
145  SG::WriteHandle< xAOD::BaseContainer > outTrkAnaInfoContHandle( m_trkAnaInfoKey );
146  if( m_writeOut ) {
147  ATH_CHECK( outTrkAnaInfoContHandle.record(
148  std::make_unique< xAOD::BaseContainer >(),
149  std::make_unique< xAOD::AuxContainerBase >() ) );
150  }
151 
154  IDTPM::TrackAnalysisCollections thisTrkAnaCollections( m_anaTag.value() );
155  ATH_CHECK( thisTrkAnaCollections.initialize() );
156 
158  ATH_CHECK( loadCollections( thisTrkAnaCollections ) );
159 
160  ATH_MSG_DEBUG( "Processing event = " <<
161  thisTrkAnaCollections.eventInfo()->eventNumber() <<
162  "\n==========================================" );
163  ATH_MSG_DEBUG( "ALL Track Info: " << thisTrkAnaCollections.printInfo() );
164 
166  if( thisTrkAnaCollections.empty() ) {
167  ATH_MSG_DEBUG( "Some FULL collections are empty." );
168  }
169 
174  ATH_CHECK( m_trackQualitySelectionTool->selectTracks( thisTrkAnaCollections ) );
175 
177  if( thisTrkAnaCollections.empty( IDTPM::TrackAnalysisCollections::FS ) ) {
178  ATH_MSG_DEBUG( "Some collections are empty after quality selection." );
179  }
180 
186  for( size_t iAna=0 ; iAna < m_trkAnaPlotsMgrVec.size() ; iAna++ ) {
187 
188  const std::string& thisChain = m_trkAnaPlotsMgrVec[iAna]->chain();
189  ATH_MSG_DEBUG( "Processing chain = " << thisChain );
190 
194  unsigned decisionType = TrigDefs::Physics; // TrigDefs::includeFailedDecisions;
195 
197  if( !thisChain.empty() and thisChain != "Offline" and m_trkAnaDefSvc->useTrigger() and not m_trkAnaDefSvc->useEFTrigger() ) {
198  if( not m_trigDecTool->isPassed( thisChain, decisionType ) ) {
199  ATH_MSG_DEBUG( "Trigger chain " << thisChain << " is not fired. Skipping" );
200  continue;
201  }
202  }
203 
207  std::vector< TrigCompositeUtils::LinkInfo< TrigRoiDescriptorCollection > > selectedRois;
208  size_t selectedRoisSize(1); // by default only one "dummy" RoI, i.e. for offline analysis
209 
210  if( m_trkAnaDefSvc->useTrigger() and not m_trkAnaDefSvc->useEFTrigger() ) {
211  selectedRois = m_roiSelectionTool->getRois( thisChain );
212  selectedRoisSize = selectedRois.size();
213  }
214 
219  for( size_t ir=0 ; ir<selectedRoisSize ; ir++ ) {
220 
222  thisTrkAnaCollections.clear( IDTPM::TrackAnalysisCollections::InRoI );
223 
225  if( m_trkAnaDefSvc->useTrigger() and not m_trkAnaDefSvc->useEFTrigger() ) thisRoiLink = selectedRois.at(ir).link;
226  const TrigRoiDescriptor* const* thisRoi = m_trkAnaDefSvc->useTrigger() and not m_trkAnaDefSvc->useEFTrigger() ?
227  thisRoiLink.cptr() : nullptr;
228  std::string thisRoiStr = m_trkAnaDefSvc->useTrigger() and not m_trkAnaDefSvc->useEFTrigger()?
229  std::string( **thisRoi ) : "Full Scan";
230 
231  ATH_MSG_DEBUG( "Processing selected RoI : " << thisRoiStr );
232 
236  if( m_trkAnaDefSvc->useTrigger() and not m_trkAnaDefSvc->useEFTrigger() ) {
238  ATH_CHECK( m_trackRoiSelectionTool->selectTracksInRoI(
239  thisTrkAnaCollections, thisRoiLink ) );
240  } else {
242  thisTrkAnaCollections.copyFS();
243  }
244 
246  if( thisTrkAnaCollections.empty( IDTPM::TrackAnalysisCollections::InRoI ) ) {
247  ATH_MSG_DEBUG( "Some collections are empty after RoI selection." );
248  }
249 
253  std::string chainRoIName = thisChain;
254  if( m_trkAnaDefSvc->useTrigger() and not m_trkAnaDefSvc->useEFTrigger() ) chainRoIName += "_RoI_"+std::to_string(ir);
255 
256  if( m_doMatch.value() ) {
257  ATH_MSG_DEBUG( "Doing Test-Reference matching..." );
258  ATH_CHECK( m_trackMatchingTool->match( thisTrkAnaCollections,
259  chainRoIName, thisRoiStr ) );
260  }
261 
265  ATH_CHECK( m_trkAnaPlotsMgrVec[iAna]->fill( thisTrkAnaCollections ) );
266 
270  if( m_writeOut ) {
271  ATH_CHECK( m_trkAnaInfoWriteTool->write( outTrkAnaInfoContHandle,
272  thisTrkAnaCollections,
273  thisChain, ir, thisRoiStr ) );
274  }
275 
276  } // close selectedRois loop
277 
278  } // close TrkAnalyses loop
279 
280  if( m_writeOut ) {
281  ATH_MSG_DEBUG( m_trkAnaInfoWriteTool->printInfo( outTrkAnaInfoContHandle ) );
282  }
283 
284  return StatusCode::SUCCESS;
285 }
286 
287 
292 
293  ATH_MSG_INFO( "Finalizing plots" );
294 
295  if( endOfRunFlag() ) {
296  for( size_t iAna=0 ; iAna < m_trkAnaPlotsMgrVec.size() ; iAna++ ) {
297  m_trkAnaPlotsMgrVec[iAna]->finalize();
298  }
299  }
300 
301  ATH_MSG_INFO( "Successfully finalized hists" );
302 
303  return StatusCode::SUCCESS;
304 }
305 
306 
311 
312  ATH_MSG_INFO( "Loading collections" );
314  ATH_CHECK( trkAnaColls.fillTruthPartContainer(
318 
319  return StatusCode::SUCCESS;
320 }
InDetTrackPerfMonTool::loadCollections
StatusCode loadCollections(IDTPM::TrackAnalysisCollections &trkAnaColls)
retrieve all collections and load them into trkAnaCollections object
Definition: InDetTrackPerfMonTool.cxx:310
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
InDetTrackPerfMonTool::procHistograms
virtual StatusCode procHistograms()
Definition: InDetTrackPerfMonTool.cxx:291
IDTPM::TrackAnalysisCollections
Definition: TrackAnalysisCollections.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::EventInfo_v1::eventNumber
uint64_t eventNumber() const
The current event's event number.
InDetTrackPerfMonTool::m_trackMatchingTool
ToolHandle< IDTPM::ITrackMatchingTool > m_trackMatchingTool
Definition: InDetTrackPerfMonTool.h:109
InDetTrackPerfMonTool::~InDetTrackPerfMonTool
virtual ~InDetTrackPerfMonTool()
Destructor.
ManagedMonitorToolBase
Provides functionality for users to implement and save histograms, ntuples, and summary data,...
Definition: ManagedMonitorToolBase.h:73
InDetTrackPerfMonTool::m_triggerTrkParticleName
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_triggerTrkParticleName
Trigger TrackParticleContainer's name.
Definition: InDetTrackPerfMonTool.h:70
TruthParticleContainer.h
InDetTrackPerfMonTool::m_anaTag
StringProperty m_anaTag
Definition: InDetTrackPerfMonTool.h:115
InDetTrackPerfMonTool::m_offlineTrkParticleName
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_offlineTrkParticleName
Offline TrackParticleContainer's name.
Definition: InDetTrackPerfMonTool.h:66
InDetTrackPerfMonTool::m_trkAnaDefSvc
SmartIF< ITrackAnalysisDefinitionSvc > m_trkAnaDefSvc
TrackAnalysisDefinitionSvc.
Definition: InDetTrackPerfMonTool.h:122
IDTPM::TrackAnalysisCollections::eventInfo
const xAOD::EventInfo * eventInfo()
get event info
Definition: TrackAnalysisCollections.h:135
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
ManagedMonitorToolBase::fill
@ fill
Definition: ManagedMonitorToolBase.h:115
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
InDetTrackPerfMonTool::m_truthEventName
SG::ReadHandleKey< xAOD::TruthEventContainer > m_truthEventName
TruthEvent container's name.
Definition: InDetTrackPerfMonTool.h:78
InDetTrackPerfMonTool::m_trackRoiSelectionTool
ToolHandle< IDTPM::ITrackSelectionTool > m_trackRoiSelectionTool
Definition: InDetTrackPerfMonTool.h:106
InDetTrackPerfMonTool::m_truthParticleName
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticleName
TruthParticle container's name.
Definition: InDetTrackPerfMonTool.h:74
InDetTrackPerfMonTool::m_eventInfoContainerName
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoContainerName
EventInfo container name.
Definition: InDetTrackPerfMonTool.h:86
PlotCalibFromCool.ie
ie
Definition: PlotCalibFromCool.py:420
ManagedMonitorToolBase::MonGroup
A container of information describing a monitoring object.
Definition: ManagedMonitorToolBase.h:137
InDetTrackPerfMonTool::m_roiSelectionTool
ToolHandle< IDTPM::RoiSelectionTool > m_roiSelectionTool
Definition: InDetTrackPerfMonTool.h:103
IDTPM::TrackAnalysisCollections::clear
void clear(Stage stage=FULL)
Clear vectors.
Definition: TrackAnalysisCollections.cxx:372
ManagedMonitorToolBase::initialize
virtual StatusCode initialize()
Definition: ManagedMonitorToolBase.cxx:617
IDTPM::TrackAnalysisCollections::fillEventInfo
StatusCode fillEventInfo(const SG::ReadHandleKey< xAOD::EventInfo > &handleKey)
— Setter methods —
Definition: TrackAnalysisCollections.cxx:60
InDetTrackPerfMonTool::m_trackQualitySelectionTool
ToolHandle< IDTPM::ITrackSelectionTool > m_trackQualitySelectionTool
Definition: InDetTrackPerfMonTool.h:100
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
IDTPM::TrackAnalysisCollections::FS
@ FS
Definition: TrackAnalysisCollections.h:52
InDetTrackPerfMonTool.h
InDetTrackPerfMonTool::m_truthPileUpEventName
SG::ReadHandleKey< xAOD::TruthPileupEventContainer > m_truthPileUpEventName
TruthPileupEvent container's name.
Definition: InDetTrackPerfMonTool.h:82
test_pyathena.parent
parent
Definition: test_pyathena.py:15
InDetTrackPerfMonTool::bookHistograms
virtual StatusCode bookHistograms()
Definition: InDetTrackPerfMonTool.cxx:109
InDetTrackPerfMonTool::fillHistograms
virtual StatusCode fillHistograms()
Definition: InDetTrackPerfMonTool.cxx:140
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MakeTH3DFromTH2Ds.hists
hists
Definition: MakeTH3DFromTH2Ds.py:72
InDetTrackPerfMonTool::m_doMatch
BooleanProperty m_doMatch
Definition: InDetTrackPerfMonTool.h:117
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
InDetTrackPerfMonTool::m_writeOut
BooleanProperty m_writeOut
Definition: InDetTrackPerfMonTool.h:119
ManagedMonitorToolBase::regEfficiency
virtual StatusCode regEfficiency(TEfficiency *e, const MonGroup &group)
Registers a TEfficiency to be included in the output stream using logical parameters that describe th...
Definition: ManagedMonitorToolBase.cxx:1446
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
IDTPM::TrackAnalysisCollections::fillTruthPartContainer
StatusCode fillTruthPartContainer(const SG::ReadHandleKey< xAOD::TruthParticleContainer > &truthPartHandleKey, const SG::ReadHandleKey< xAOD::TruthEventContainer > &truthEventHandleKey, const SG::ReadHandleKey< xAOD::TruthPileupEventContainer > &truthPUEventHandleKey)
fill FULL collections and vectors
Definition: TrackAnalysisCollections.cxx:80
InDetTrackPerfMonTool::m_trigDecTool
PublicToolHandle< Trig::TrigDecisionTool > m_trigDecTool
Definition: InDetTrackPerfMonTool.h:97
EventInfo.h
IDTPM::TrackAnalysisCollections::initialize
StatusCode initialize()
initialize
Definition: TrackAnalysisCollections.cxx:32
InDetTrackPerfMonTool::m_trkAnaPlotsMgrVec
std::vector< std::unique_ptr< IDTPM::TrackAnalysisPlotsMgr > > m_trkAnaPlotsMgrVec
plots
Definition: InDetTrackPerfMonTool.h:125
ir
int ir
counter of the current depth
Definition: fastadd.cxx:49
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
InDetTrackPerfMonTool::m_trkAnaInfoWriteTool
ToolHandle< IDTPM::TrackAnalysisInfoWriteTool > m_trkAnaInfoWriteTool
Definition: InDetTrackPerfMonTool.h:112
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
InDetTrackPerfMonTool::m_trkAnaInfoKey
SG::WriteHandleKey< xAOD::BaseContainer > m_trkAnaInfoKey
WriteHandle for trkAnaInfo for reprocessing.
Definition: InDetTrackPerfMonTool.h:90
IDTPM::TrackAnalysisCollections::InRoI
@ InRoI
Definition: TrackAnalysisCollections.h:52
ManagedMonitorToolBase::endOfRunFlag
bool endOfRunFlag() const
Definition: ManagedMonitorToolBase.h:797
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DeMoScan.first
bool first
Definition: DeMoScan.py:536
ManagedMonitorToolBase::all
@ all
Definition: ManagedMonitorToolBase.h:115
IDTPM::TrackAnalysisCollections::printInfo
std::string printInfo(Stage stage=FULL) const
print Information about tracks in the collection(s)
Definition: TrackAnalysisCollections.cxx:546
IDTPM::TrackAnalysisCollections::empty
bool empty(Stage stage=FULL)
— Utility methods —
Definition: TrackAnalysisCollections.cxx:351
IDTPM::TrackAnalysisCollections::fillTrigTrackContainer
StatusCode fillTrigTrackContainer(const SG::ReadHandleKey< xAOD::TrackParticleContainer > &handleKey)
Trigger track particles.
Definition: TrackAnalysisCollections.cxx:180
IDTPM::TrackAnalysisCollections::copyFS
void copyFS()
copy content of FS vectors to InRoI vectors
Definition: TrackAnalysisCollections.cxx:393
InDetTrackPerfMonTool::InDetTrackPerfMonTool
InDetTrackPerfMonTool()
prevent default construction
ManagedMonitorToolBase::regHist
virtual StatusCode regHist(TH1 *h, const std::string &system, Interval_t interval, MgmtAttr_t histo_mgmt=ATTRIB_MANAGED, const std::string &chain="", const std::string &merge="")
Registers a TH1 (including TH2, TH3, and TProfile) to be included in the output stream using logical ...
Definition: ManagedMonitorToolBase.cxx:1346
TrackParticleContainer.h
InDetTrackPerfMonTool::initialize
virtual StatusCode initialize()
Definition: InDetTrackPerfMonTool.cxx:49
IDTPM::TrackAnalysisCollections::fillOfflTrackContainer
StatusCode fillOfflTrackContainer(const SG::ReadHandleKey< xAOD::TrackParticleContainer > &handleKey)
Offline track particles.
Definition: TrackAnalysisCollections.cxx:150