ATLAS Offline Software
Loading...
Searching...
No Matches
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
9
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 ) :
36 ManagedMonitorToolBase( type, name, 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
74 ATH_CHECK( m_eventInfoContainerName.initialize() );
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
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
header file for class of same name
bool empty(Stage stage=FULL)
check if collection are empty
StatusCode fillTruthVertexContainer(const SG::ReadHandleKey< xAOD::TruthVertexContainer > &truthVertexHandleKey)
fill FULL vertex collections and vectors
void clear(Stage stage=FULL)
Clear vectors.
void copyFS()
copy content of FS vectors to InRoI vectors
StatusCode fillTrigVertexContainer(const SG::ReadHandleKey< xAOD::VertexContainer > &handleKey)
Trigger vertices.
std::string printInfo(Stage stage=FULL, bool printVertex=true) const
print information about tracks in the collection(s)
StatusCode fillTruthPartContainer(const SG::ReadHandleKey< xAOD::TruthParticleContainer > &truthPartHandleKey)
fill FULL track collections and vectors
StatusCode fillEventInfo(const SG::ReadHandleKey< xAOD::EventInfo > &eventInfoHandleKey, const SG::ReadHandleKey< xAOD::TruthEventContainer > &truthEventHandleKey, const SG::ReadHandleKey< xAOD::TruthPileupEventContainer > &truthPUEventHandleKey)
— Setter methods —
const xAOD::EventInfo * eventInfo()
get event info
StatusCode fillTrigTrackContainer(const SG::ReadHandleKey< xAOD::TrackParticleContainer > &handleKey)
Trigger track particles.
void newChain()
update before running on new chain
StatusCode fillOfflTrackContainer(const SG::ReadHandleKey< xAOD::TrackParticleContainer > &handleKey)
Offline track particles.
StatusCode fillOfflVertexContainer(const SG::ReadHandleKey< xAOD::VertexContainer > &handleKey)
Offline vertices.
void newRoI()
update before running on new RoI
virtual StatusCode initialize()
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_triggerTrkParticleName
Trigger TrackParticleContainer's name.
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoContainerName
EventInfo container name.
ToolHandle< IDTPM::TrackRoiSelectionTool > m_trackRoiSelectionTool
ToolHandle< IDTPM::VertexRoiSelectionTool > m_vertexRoiSelectionTool
StatusCode loadCollections(IDTPM::TrackAnalysisCollections &trkAnaColls)
retrieve all collections and load them into trkAnaCollections object
SG::WriteHandleKey< xAOD::BaseContainer > m_trkAnaInfoKey
WriteHandle for trkAnaInfo for reprocessing.
InDetTrackPerfMonTool()
prevent default construction
SG::ReadHandleKey< xAOD::TruthEventContainer > m_truthEventName
TruthEvent container's name.
SmartIF< ITrackAnalysisDefinitionSvc > m_trkAnaDefSvc
TrackAnalysisDefinitionSvc.
SG::ReadHandleKey< xAOD::TruthPileupEventContainer > m_truthPileUpEventName
TruthPileupEvent container's name.
SG::ReadHandleKey< xAOD::VertexContainer > m_offlineVertexContainerName
Offline Primary vertex container's name.
SG::ReadHandleKey< xAOD::VertexContainer > m_triggerVertexContainerName
Trigger Primary vertex container's name.
ToolHandle< IDTPM::IVertexSelectionTool > m_vertexQualitySelectionTool
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticleName
TruthParticle container's name.
ToolHandle< IDTPM::RoiSelectionTool > m_roiSelectionTool
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_offlineTrkParticleName
Offline TrackParticleContainer's name.
virtual StatusCode bookHistograms()
std::vector< std::unique_ptr< IDTPM::TrackAnalysisPlotsMgr > > m_trkAnaPlotsMgrVec
plots
virtual ~InDetTrackPerfMonTool()
Destructor.
ToolHandle< IDTPM::ITrackMatchingTool > m_trackMatchingTool
SG::ReadHandleKey< xAOD::TruthVertexContainer > m_truthVertexContainerName
Truth vertex container's name.
ToolHandle< IDTPM::TrackAnalysisInfoWriteTool > m_trkAnaInfoWriteTool
ToolHandle< IDTPM::ITrackSelectionTool > m_trackQualitySelectionTool
virtual StatusCode procHistograms()
virtual StatusCode fillHistograms()
A container of information describing a monitoring object.
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 ...
PublicToolHandle< Trig::ITrigDecisionTool > m_trigDecTool
ManagedMonitorToolBase(const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode regEfficiency(TEfficiency *e, const MonGroup &group)
Registers a TEfficiency to be included in the output stream using logical parameters that describe th...
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
uint64_t eventNumber() const
The current event's event number.
int ir
counter of the current depth
Definition fastadd.cxx:49