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->doTrigNavigation() } ) );
65  ATH_CHECK( m_roiSelectionTool.retrieve( EnableTool{ m_trkAnaDefSvc->doTrigNavigation() } ) );
66  ATH_CHECK( m_trackRoiSelectionTool.retrieve( EnableTool{ m_trkAnaDefSvc->doTrigNavigation() } ) );
67  ATH_CHECK( m_vertexRoiSelectionTool.retrieve( EnableTool{ m_trkAnaDefSvc->doTrigNavigation() } ) );
68  ATH_CHECK( m_trackMatchingTool.retrieve( EnableTool{ m_doMatch.value() } ) );
69  ATH_CHECK( m_trkAnaInfoWriteTool.retrieve( EnableTool{ m_writeOut.value() } ) );
70 
71  ATH_MSG_DEBUG( "Initializing collections" );
72 
75  ATH_CHECK( m_truthEventName.initialize(
76  m_trkAnaDefSvc->useTruth() and not m_truthEventName.key().empty() ) );
78  m_trkAnaDefSvc->useTruth() and not m_truthPileUpEventName.key().empty() and
79  m_trkAnaDefSvc->hasFullPileupTruth() ) );
80 
83  m_trkAnaDefSvc->useOffline() and not m_offlineTrkParticleName.key().empty() ) );
85  m_trkAnaDefSvc->useTrigger() and not m_triggerTrkParticleName.key().empty() ) );
87  m_trkAnaDefSvc->useTruth() and not m_truthParticleName.key().empty() ) );
88 
91  m_trkAnaDefSvc->useOffline() and not m_offlineVertexContainerName.key().empty() ) );
93  m_trkAnaDefSvc->useTrigger() and not m_triggerVertexContainerName.key().empty() ) );
95  m_trkAnaDefSvc->useTruth() and not m_truthVertexContainerName.key().empty() ) );
96 
98  ATH_CHECK( m_trkAnaInfoKey.initialize() );
99 
101  const std::vector< std::string >& configuredChains = m_trkAnaDefSvc->configuredChains();
102  m_trkAnaPlotsMgrVec.reserve( configuredChains.size() );
103 
105  for( const std::string& thisChain : configuredChains ) {
106  ATH_MSG_DEBUG( "Booking TrkAnalysis/histograms for chain : " << thisChain );
107 
110  m_trkAnaPlotsMgrVec.emplace_back(
111  std::make_unique< IDTPM::TrackAnalysisPlotsMgr >(
112  m_trkAnaDefSvc->plotsFullDir( thisChain ),
113  m_anaTag.value(),
114  thisChain ) );
115  } // close m_configuredChains loop
116 
117  return StatusCode::SUCCESS;
118 }
119 
120 
125 {
126  ATH_MSG_DEBUG( "Booking plots" );
127 
128  for( size_t iAna=0 ; iAna < m_trkAnaPlotsMgrVec.size() ; iAna++ ) {
129 
132 
135  std::vector< HistData > hists = m_trkAnaPlotsMgrVec[iAna]->retrieveBookedHistograms();
136  for ( size_t ih=0 ; ih<hists.size() ; ih++ ) {
137  ATH_CHECK( regHist( hists[ih].first, hists[ih].second, all ) );
138  }
139 
140  // do the same for Efficiencies, but there's a twist:
141  std::vector< EfficiencyData > effs = m_trkAnaPlotsMgrVec[iAna]->retrieveBookedEfficiencies();
142  for ( size_t ie=0 ; ie<effs.size() ; ie++ ) {
143  ATH_CHECK( regEfficiency( effs[ie].first, MonGroup( this, effs[ie].second, all ) ) );
144  }
145 
146  } // closing loop over TrkAnalyses
147 
148  return StatusCode::SUCCESS;
149 }
150 
151 
156 
157  ATH_MSG_DEBUG("Filling hists " << name() << " ...");
158 
160  SG::WriteHandle< xAOD::BaseContainer > outTrkAnaInfoContHandle( m_trkAnaInfoKey );
161  if( m_writeOut ) {
162  ATH_CHECK( outTrkAnaInfoContHandle.record(
163  std::make_unique< xAOD::BaseContainer >(),
164  std::make_unique< xAOD::AuxContainerBase >() ) );
165  }
166 
169  IDTPM::TrackAnalysisCollections thisTrkAnaCollections( m_anaTag.value() );
170  ATH_CHECK( thisTrkAnaCollections.initialize() );
171 
173  ATH_CHECK( loadCollections( thisTrkAnaCollections ) );
174 
175  ATH_MSG_DEBUG( "Processing event = " <<
176  thisTrkAnaCollections.eventInfo()->eventNumber() <<
177  "\n==========================================" );
178  ATH_MSG_DEBUG( "ALL Track Info: " << thisTrkAnaCollections.printInfo() );
179 
181  if( thisTrkAnaCollections.empty() ) {
182  ATH_MSG_DEBUG( "Some FULL collections are empty." );
183  }
184 
188  ATH_CHECK( m_trackQualitySelectionTool->selectTracks( thisTrkAnaCollections ) );
189 
191  if( thisTrkAnaCollections.empty( IDTPM::TrackAnalysisCollections::FS ) ) {
192  ATH_MSG_DEBUG( "Some collections are empty after quality selection." );
193  }
194 
198  ATH_CHECK( m_vertexQualitySelectionTool->selectVertices( thisTrkAnaCollections ) );
199 
205  for( size_t iAna=0 ; iAna < m_trkAnaPlotsMgrVec.size() ; iAna++ ) {
206 
207  const std::string& thisChain = m_trkAnaPlotsMgrVec[iAna]->chain();
208  ATH_MSG_DEBUG( "Processing chain = " << thisChain );
209 
213 
215  if( m_trkAnaDefSvc->doTrigNavigation() and
216  not thisChain.empty() and thisChain != "Offline" ) {
217 
218  unsigned decisionType = TrigDefs::Physics; // TrigDefs::includeFailedDecisions;
219 
220  if( not m_trigDecTool->isPassed( thisChain, decisionType ) ) {
221  ATH_MSG_DEBUG( "Trigger chain " << thisChain << " is not fired. Skipping" );
222  continue;
223  }
224  }
225 
229  std::vector< TrigCompositeUtils::LinkInfo< TrigRoiDescriptorCollection > > selectedRois;
230  size_t selectedRoisSize(1); // by default only one "dummy" RoI, i.e. for offline analysis
231 
232  if( m_trkAnaDefSvc->doTrigNavigation() ) {
233  selectedRois = m_roiSelectionTool->getRois( thisChain );
234  selectedRoisSize = selectedRois.size();
235  }
236 
241  for( size_t ir=0 ; ir<selectedRoisSize ; ir++ ) {
242 
244  thisTrkAnaCollections.clear( IDTPM::TrackAnalysisCollections::InRoI );
245 
248  std::string thisRoiStr( "Full Scan" );
249  if( m_trkAnaDefSvc->doTrigNavigation() ) {
250  thisRoiLink = selectedRois.at(ir).link;
251 
253  if( not thisRoiLink.isValid() ) {
254  ATH_MSG_WARNING( "Found non-valid RoI ElementLink" );
255  continue;
256  }
257 
259  thisRoiStr = std::string( **thisRoiLink.cptr() );
260  }
261 
262  ATH_MSG_DEBUG( "Processing selected RoI : " << thisRoiStr );
263 
267  if( m_trkAnaDefSvc->doTrigNavigation() ) {
269  ATH_CHECK( m_trackRoiSelectionTool->selectTracksInRoI(
270  thisTrkAnaCollections, thisRoiLink ) );
271 
273  ATH_CHECK( m_vertexRoiSelectionTool->selectVerticesInRoI(
274  thisTrkAnaCollections, thisRoiLink ) );
275  } else {
277  thisTrkAnaCollections.copyFS();
278  }
279 
281  if( thisTrkAnaCollections.empty( IDTPM::TrackAnalysisCollections::InRoI ) ) {
282  ATH_MSG_DEBUG( "Some collections are empty after RoI selection." );
283  }
284 
288  std::string chainRoIName = thisChain;
289  if( m_trkAnaDefSvc->doTrigNavigation() ) {
290  chainRoIName += "_RoI_"+std::to_string(ir);
291  }
292 
293  if( m_doMatch.value() ) {
294  ATH_MSG_DEBUG( "Doing Test-Reference matching..." );
295  ATH_CHECK( m_trackMatchingTool->match( thisTrkAnaCollections,
296  chainRoIName, thisRoiStr ) );
297  }
298 
302  ATH_CHECK( m_trkAnaPlotsMgrVec[iAna]->fill( thisTrkAnaCollections ) );
303 
307  if( m_writeOut ) {
308  ATH_CHECK( m_trkAnaInfoWriteTool->write( outTrkAnaInfoContHandle,
309  thisTrkAnaCollections,
310  thisChain, ir, thisRoiStr ) );
311  }
312 
313  thisTrkAnaCollections.newRoI();
314  } // close selectedRois loop
315 
316  thisTrkAnaCollections.newChain();
317  } // close TrkAnalyses loop
318 
319  if( m_writeOut ) {
320  ATH_MSG_DEBUG( m_trkAnaInfoWriteTool->printInfo( outTrkAnaInfoContHandle ) );
321  }
322 
323  return StatusCode::SUCCESS;
324 }
325 
326 
331 
332  ATH_MSG_DEBUG( "Finalizing plots" );
333 
334  if( endOfRunFlag() ) {
335  for( size_t iAna=0 ; iAna < m_trkAnaPlotsMgrVec.size() ; iAna++ ) {
336  m_trkAnaPlotsMgrVec[iAna]->finalize();
337  }
338  }
339 
340  ATH_MSG_DEBUG( "Successfully finalized hists" );
341 
342  return StatusCode::SUCCESS;
343 }
344 
345 
350 
351  ATH_MSG_DEBUG( "Loading collections" );
352 
354  ATH_CHECK( trkAnaColls.fillEventInfo(
356 
361 
366 
367  return StatusCode::SUCCESS;
368 }
IDTPM::TrackAnalysisCollections::printInfo
std::string printInfo(Stage stage=FULL, bool printVertex=true) const
print information about tracks in the collection(s)
Definition: TrackAnalysisCollections.cxx:1034
InDetTrackPerfMonTool::loadCollections
StatusCode loadCollections(IDTPM::TrackAnalysisCollections &trkAnaColls)
retrieve all collections and load them into trkAnaCollections object
Definition: InDetTrackPerfMonTool.cxx:349
IDTPM::TrackAnalysisCollections::fillOfflVertexContainer
StatusCode fillOfflVertexContainer(const SG::ReadHandleKey< xAOD::VertexContainer > &handleKey)
Offline vertices.
Definition: TrackAnalysisCollections.cxx:404
IDTPM::TrackAnalysisCollections::fillTruthVertexContainer
StatusCode fillTruthVertexContainer(const SG::ReadHandleKey< xAOD::TruthVertexContainer > &truthVertexHandleKey)
fill FULL vertex collections and vectors
Definition: TrackAnalysisCollections.cxx:373
InDetTrackPerfMonTool::m_vertexRoiSelectionTool
ToolHandle< IDTPM::VertexRoiSelectionTool > m_vertexRoiSelectionTool
Definition: InDetTrackPerfMonTool.h:124
InDetTrackPerfMonTool::procHistograms
virtual StatusCode procHistograms()
Definition: InDetTrackPerfMonTool.cxx:330
IDTPM::TrackAnalysisCollections
Definition: TrackAnalysisCollections.h:46
InDetTrackPerfMonTool::m_vertexQualitySelectionTool
ToolHandle< IDTPM::IVertexSelectionTool > m_vertexQualitySelectionTool
Definition: InDetTrackPerfMonTool.h:115
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:127
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:73
TruthParticleContainer.h
InDetTrackPerfMonTool::m_anaTag
StringProperty m_anaTag
Definition: InDetTrackPerfMonTool.h:133
ManagedMonitorToolBase::m_trigDecTool
PublicToolHandle< Trig::ITrigDecisionTool > m_trigDecTool
Definition: ManagedMonitorToolBase.h:845
python.SystemOfUnits.second
float second
Definition: SystemOfUnits.py:135
InDetTrackPerfMonTool::m_offlineTrkParticleName
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_offlineTrkParticleName
Offline TrackParticleContainer's name.
Definition: InDetTrackPerfMonTool.h:69
InDetTrackPerfMonTool::m_trkAnaDefSvc
SmartIF< ITrackAnalysisDefinitionSvc > m_trkAnaDefSvc
TrackAnalysisDefinitionSvc.
Definition: InDetTrackPerfMonTool.h:140
IDTPM::TrackAnalysisCollections::eventInfo
const xAOD::EventInfo * eventInfo()
get event info
Definition: TrackAnalysisCollections.h:200
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:81
InDetTrackPerfMonTool::m_truthParticleName
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticleName
TruthParticle container's name.
Definition: InDetTrackPerfMonTool.h:77
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
InDetTrackPerfMonTool::m_eventInfoContainerName
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoContainerName
EventInfo container name.
Definition: InDetTrackPerfMonTool.h:89
PlotCalibFromCool.ie
ie
Definition: PlotCalibFromCool.py:420
IDTPM::TrackAnalysisCollections::fillTrigVertexContainer
StatusCode fillTrigVertexContainer(const SG::ReadHandleKey< xAOD::VertexContainer > &handleKey)
Trigger vertices.
Definition: TrackAnalysisCollections.cxx:433
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:118
IDTPM::TrackAnalysisCollections::clear
void clear(Stage stage=FULL)
Clear vectors.
Definition: TrackAnalysisCollections.cxx:628
IDTPM::TrackAnalysisCollections::fillTruthPartContainer
StatusCode fillTruthPartContainer(const SG::ReadHandleKey< xAOD::TruthParticleContainer > &truthPartHandleKey)
fill FULL track collections and vectors
Definition: TrackAnalysisCollections.cxx:108
ManagedMonitorToolBase::initialize
virtual StatusCode initialize()
Definition: ManagedMonitorToolBase.cxx:616
InDetTrackPerfMonTool::m_truthVertexContainerName
SG::ReadHandleKey< xAOD::TruthVertexContainer > m_truthVertexContainerName
Truth vertex container's name.
Definition: InDetTrackPerfMonTool.h:101
InDetTrackPerfMonTool::m_trackQualitySelectionTool
ToolHandle< IDTPM::ITrackSelectionTool > m_trackQualitySelectionTool
Definition: InDetTrackPerfMonTool.h:112
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:54
InDetTrackPerfMonTool::m_triggerVertexContainerName
SG::ReadHandleKey< xAOD::VertexContainer > m_triggerVertexContainerName
Trigger Primary vertex container's name.
Definition: InDetTrackPerfMonTool.h:97
InDetTrackPerfMonTool.h
InDetTrackPerfMonTool::m_trackRoiSelectionTool
ToolHandle< IDTPM::TrackRoiSelectionTool > m_trackRoiSelectionTool
Definition: InDetTrackPerfMonTool.h:121
IDTPM::TrackAnalysisCollections::newChain
void newChain()
update before running on new chain
Definition: TrackAnalysisCollections.h:171
InDetTrackPerfMonTool::m_truthPileUpEventName
SG::ReadHandleKey< xAOD::TruthPileupEventContainer > m_truthPileUpEventName
TruthPileupEvent container's name.
Definition: InDetTrackPerfMonTool.h:85
test_pyathena.parent
parent
Definition: test_pyathena.py:15
InDetTrackPerfMonTool::bookHistograms
virtual StatusCode bookHistograms()
Definition: InDetTrackPerfMonTool.cxx:124
InDetTrackPerfMonTool::fillHistograms
virtual StatusCode fillHistograms()
Definition: InDetTrackPerfMonTool.cxx:155
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:135
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:137
IDTPM::TrackAnalysisCollections::fillEventInfo
StatusCode fillEventInfo(const SG::ReadHandleKey< xAOD::EventInfo > &eventInfoHandleKey, const SG::ReadHandleKey< xAOD::TruthEventContainer > &truthEventHandleKey, const SG::ReadHandleKey< xAOD::TruthPileupEventContainer > &truthPUEventHandleKey)
— Setter methods —
Definition: TrackAnalysisCollections.cxx:68
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:1444
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
EventInfo.h
IDTPM::TrackAnalysisCollections::newRoI
void newRoI()
update before running on new RoI
Definition: TrackAnalysisCollections.h:177
IDTPM::TrackAnalysisCollections::initialize
StatusCode initialize()
initialize
Definition: TrackAnalysisCollections.cxx:41
InDetTrackPerfMonTool::m_trkAnaPlotsMgrVec
std::vector< std::unique_ptr< IDTPM::TrackAnalysisPlotsMgr > > m_trkAnaPlotsMgrVec
plots
Definition: InDetTrackPerfMonTool.h:143
ir
int ir
counter of the current depth
Definition: fastadd.cxx:49
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
InDetTrackPerfMonTool::m_trkAnaInfoWriteTool
ToolHandle< IDTPM::TrackAnalysisInfoWriteTool > m_trkAnaInfoWriteTool
Definition: InDetTrackPerfMonTool.h:130
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:105
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
IDTPM::TrackAnalysisCollections::InRoI
@ InRoI
Definition: TrackAnalysisCollections.h:54
ManagedMonitorToolBase::endOfRunFlag
bool endOfRunFlag() const
Definition: ManagedMonitorToolBase.h:797
DeMoScan.first
bool first
Definition: DeMoScan.py:534
ManagedMonitorToolBase::all
@ all
Definition: ManagedMonitorToolBase.h:115
InDetTrackPerfMonTool::m_offlineVertexContainerName
SG::ReadHandleKey< xAOD::VertexContainer > m_offlineVertexContainerName
Offline Primary vertex container's name.
Definition: InDetTrackPerfMonTool.h:93
IDTPM::TrackAnalysisCollections::empty
bool empty(Stage stage=FULL)
check if collection are empty
Definition: TrackAnalysisCollections.cxx:607
IDTPM::TrackAnalysisCollections::fillTrigTrackContainer
StatusCode fillTrigTrackContainer(const SG::ReadHandleKey< xAOD::TrackParticleContainer > &handleKey)
Trigger track particles.
Definition: TrackAnalysisCollections.cxx:196
IDTPM::TrackAnalysisCollections::copyFS
void copyFS()
copy content of FS vectors to InRoI vectors
Definition: TrackAnalysisCollections.cxx:664
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:1344
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:166