ATLAS Offline Software
InDetTrackPerfMonTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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  m_trkAnaDefSvc( nullptr ) { }
38 
39 
44 
45 
50 
52 
54  if ( not m_trkAnaDefSvc ) {
55  ATH_MSG_DEBUG( "Retrieving TrkAnaDefSvc" << m_anaTag.value() );
56  ISvcLocator* svcLoc = Gaudi::svcLocator();
57  ATH_CHECK( svcLoc->service( "TrkAnaDefSvc"+m_anaTag.value(), m_trkAnaDefSvc ) );
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 
68 
70  m_trkAnaDefSvc->useOffline() and not m_offlineTrkParticleName.key().empty() ) );
72  m_trkAnaDefSvc->useTrigger() and not m_triggerTrkParticleName.key().empty() ) );
74  m_trkAnaDefSvc->useTruth() and not m_truthParticleName.key().empty() ) );
75 
77  const std::vector< std::string >& configuredChains = m_trkAnaDefSvc->configuredChains();
78  m_trkAnaPlotsMgrVec.reserve( configuredChains.size() );
79 
81  for( const std::string& thisChain : configuredChains ) {
82  ATH_MSG_DEBUG( "Booking TrkAnalysis/histograms for chain : " << thisChain );
83 
86  m_trkAnaPlotsMgrVec.emplace_back(
87  std::make_unique< IDTPM::TrackAnalysisPlotsMgr >(
88  m_trkAnaDefSvc->plotsFullDir( thisChain ),
89  m_anaTag.value(),
90  thisChain ) );
91  } // close m_configuredChains loop
92 
93  return StatusCode::SUCCESS;
94 }
95 
96 
101 {
102  ATH_MSG_INFO( "Booking plots" );
103 
104  for( size_t iAna=0 ; iAna < m_trkAnaPlotsMgrVec.size() ; iAna++ ) {
105 
108 
111  std::vector< HistData > hists = m_trkAnaPlotsMgrVec[iAna]->retrieveBookedHistograms();
112  for ( size_t ih=0 ; ih<hists.size() ; ih++ ) {
113  ATH_CHECK( regHist( hists[ih].first, hists[ih].second, all ) );
114  }
115 
116  // do the same for Efficiencies, but there's a twist:
117  std::vector< EfficiencyData > effs = m_trkAnaPlotsMgrVec[iAna]->retrieveBookedEfficiencies();
118  for ( size_t ie=0 ; ie<effs.size() ; ie++ ) {
119  ATH_CHECK( regEfficiency( effs[ie].first, MonGroup( this, effs[ie].second, all ) ) );
120  }
121 
122  } // closing loop over TrkAnalyses
123 
124  return StatusCode::SUCCESS;
125 }
126 
127 
132 
133  ATH_MSG_INFO( "Filling hists " << name() << " ..." );
134 
137  IDTPM::TrackAnalysisCollections thisTrkAnaCollections( m_anaTag.value() );
138  ATH_CHECK( thisTrkAnaCollections.initialize() );
139 
141 
143  ATH_CHECK( loadCollections( thisTrkAnaCollections ) );
144 
145  ATH_MSG_DEBUG( "Processing event = " << pie->eventNumber() <<
146  "\n==========================================" );
147  ATH_MSG_DEBUG( "ALL Track Info: " << thisTrkAnaCollections.printInfo() );
148 
150  if( thisTrkAnaCollections.empty() ) {
151  ATH_MSG_DEBUG( "Some FULL collections are empty. Skipping event." );
152  return StatusCode::SUCCESS;
153  }
154 
159  ATH_CHECK( m_trackQualitySelectionTool->selectTracks( thisTrkAnaCollections ) );
160 
162  if( thisTrkAnaCollections.empty( IDTPM::TrackAnalysisCollections::FS ) ) {
163  ATH_MSG_DEBUG( "Some collections are empty after quality selection. Skipping event." );
164  return StatusCode::SUCCESS;
165  }
166 
172  for( size_t iAna=0 ; iAna < m_trkAnaPlotsMgrVec.size() ; iAna++ ) {
173 
174  const std::string& thisChain = m_trkAnaPlotsMgrVec[iAna]->chain();
175  ATH_MSG_DEBUG( "Processing chain = " << thisChain );
176 
180  unsigned decisionType = TrigDefs::Physics; // TrigDefs::includeFailedDecisions;
181 
183  if( !thisChain.empty() and thisChain != "Offline" and m_trkAnaDefSvc->useTrigger() and not m_trkAnaDefSvc->useEFTrigger() ) {
184  if( not m_trigDecTool->isPassed( thisChain, decisionType ) ) {
185  ATH_MSG_DEBUG( "Trigger chain " << thisChain << " is not fired. Skipping" );
186  continue;
187  }
188  }
189 
193  std::vector< TrigCompositeUtils::LinkInfo< TrigRoiDescriptorCollection > > selectedRois;
194  size_t selectedRoisSize(1); // by default only one "dummy" RoI, i.e. for offline analysis
195 
197  selectedRois = m_roiSelectionTool->getRois( thisChain );
198  selectedRoisSize = selectedRois.size();
199  }
200 
205  for( size_t ir=0 ; ir<selectedRoisSize ; ir++ ) {
206 
208  thisTrkAnaCollections.clear( IDTPM::TrackAnalysisCollections::InRoI );
209 
211  if( m_trkAnaDefSvc->useTrigger() and not m_trkAnaDefSvc->useEFTrigger() ) thisRoiLink = selectedRois.at(ir).link;
212  const TrigRoiDescriptor* const* thisRoi = m_trkAnaDefSvc->useTrigger() and not m_trkAnaDefSvc->useEFTrigger() ?
213  thisRoiLink.cptr() : nullptr;
214  std::string thisRoiStr = m_trkAnaDefSvc->useTrigger() and not m_trkAnaDefSvc->useEFTrigger()?
215  std::string( **thisRoi ) : "Full Scan";
216 
217  ATH_MSG_DEBUG( "Processing selected RoI : " << thisRoiStr );
218 
224  ATH_CHECK( m_trackRoiSelectionTool->selectTracksInRoI(
225  thisTrkAnaCollections, thisRoiLink ) );
226  } else {
228  thisTrkAnaCollections.copyFS();
229  }
230 
232  if( thisTrkAnaCollections.empty( IDTPM::TrackAnalysisCollections::InRoI ) ) {
233  ATH_MSG_DEBUG( "Some collections are empty after RoI selection. Skipping event." );
234  continue;
235  }
236 
240  std::string chainRoIName = thisChain;
241  if( m_trkAnaDefSvc->useTrigger() and not m_trkAnaDefSvc->useEFTrigger() ) chainRoIName += "_RoI_"+std::to_string(ir);
242 
243  if( m_doMatch.value() ) {
244  ATH_MSG_DEBUG( "Doing Test-Reference matching..." );
245  ATH_CHECK( m_trackMatchingTool->match( thisTrkAnaCollections,
246  chainRoIName, thisRoiStr ) );
247  }
248 
252  ATH_CHECK( m_trkAnaPlotsMgrVec[iAna]->fill( thisTrkAnaCollections ) );
253 
254  } // close selectedRois loop
255 
256  } // close TrkAnalyses loop
257 
258  return StatusCode::SUCCESS;
259 }
260 
261 
266 
267  ATH_MSG_INFO( "Finalizing plots" );
268 
269  if( endOfRunFlag() ) {
270  for( size_t iAna=0 ; iAna < m_trkAnaPlotsMgrVec.size() ; iAna++ ) {
271  m_trkAnaPlotsMgrVec[iAna]->finalize();
272  }
273  }
274 
275  ATH_MSG_INFO( "Successfully finalized hists" );
276 
277  return StatusCode::SUCCESS;
278 }
279 
280 
285 
286  ATH_MSG_INFO( "Loading collections" );
290 
291  return StatusCode::SUCCESS;
292 }
ITrackAnalysisDefinitionSvc::useEFTrigger
virtual bool useEFTrigger() const =0
InDetTrackPerfMonTool::loadCollections
StatusCode loadCollections(IDTPM::TrackAnalysisCollections &trkAnaColls)
reatrieve all collections and load them into trkAnaCollections object
Definition: InDetTrackPerfMonTool.cxx:284
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
InDetTrackPerfMonTool::procHistograms
virtual StatusCode procHistograms()
Definition: InDetTrackPerfMonTool.cxx:265
ITrackAnalysisDefinitionSvc::useOffline
virtual bool useOffline() const =0
IDTPM::TrackAnalysisCollections
Definition: TrackAnalysisCollections.h:41
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:88
InDetTrackPerfMonTool::~InDetTrackPerfMonTool
virtual ~InDetTrackPerfMonTool()
Destructor.
ManagedMonitorToolBase
Provides functionality for users to implement and save histograms, ntuples, and summary data,...
Definition: ManagedMonitorToolBase.h:74
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TruthParticleContainer.h
InDetTrackPerfMonTool::m_anaTag
StringProperty m_anaTag
Definition: InDetTrackPerfMonTool.h:91
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
IDTPM::TrackAnalysisCollections::fillTruthPartContainer
StatusCode fillTruthPartContainer(const SG::ReadHandleKey< xAOD::TruthParticleContainer > &handleKey)
— Setter methods —
Definition: TrackAnalysisCollections.cxx:62
ManagedMonitorToolBase::fill
@ fill
Definition: ManagedMonitorToolBase.h:116
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_trkAnaDefSvc
ITrackAnalysisDefinitionSvc * m_trkAnaDefSvc
TrackAnalysisDefinitionSvc.
Definition: InDetTrackPerfMonTool.h:96
InDetTrackPerfMonTool::m_trackRoiSelectionTool
ToolHandle< IDTPM::ITrackSelectionTool > m_trackRoiSelectionTool
Definition: InDetTrackPerfMonTool.h:85
PlotCalibFromCool.ie
ie
Definition: PlotCalibFromCool.py:420
ITrackAnalysisDefinitionSvc::configuredChains
virtual const std::vector< std::string > & configuredChains() const =0
ManagedMonitorToolBase::MonGroup
A container of information describing a monitoring object.
Definition: ManagedMonitorToolBase.h:138
InDetTrackPerfMonTool::m_roiSelectionTool
ToolHandle< IDTPM::RoiSelectionTool > m_roiSelectionTool
Definition: InDetTrackPerfMonTool.h:82
IDTPM::TrackAnalysisCollections::clear
void clear(Stage stage=FULL)
Clear vectors.
Definition: TrackAnalysisCollections.cxx:314
ITrackAnalysisDefinitionSvc::useTrigger
virtual bool useTrigger() const =0
ManagedMonitorToolBase::initialize
virtual StatusCode initialize()
Definition: ManagedMonitorToolBase.cxx:669
ITrackAnalysisDefinitionSvc::plotsFullDir
virtual std::string plotsFullDir(std::string chain="") const =0
InDetTrackPerfMonTool::m_trackQualitySelectionTool
ToolHandle< IDTPM::ITrackSelectionTool > m_trackQualitySelectionTool
Definition: InDetTrackPerfMonTool.h:79
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:49
InDetTrackPerfMonTool.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
InDetTrackPerfMonTool::bookHistograms
virtual StatusCode bookHistograms()
Definition: InDetTrackPerfMonTool.cxx:100
InDetTrackPerfMonTool::fillHistograms
virtual StatusCode fillHistograms()
Definition: InDetTrackPerfMonTool.cxx:131
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:93
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
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:1648
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
InDetTrackPerfMonTool::m_truthParticleName
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthParticleName
TruthParticle container's name.
Definition: InDetTrackPerfMonTool.h:69
InDetTrackPerfMonTool::m_trigDecTool
PublicToolHandle< Trig::TrigDecisionTool > m_trigDecTool
Definition: InDetTrackPerfMonTool.h:76
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:99
ir
int ir
counter of the current depth
Definition: fastadd.cxx:49
InDetTrackPerfMonTool::m_offlineTrkParticleName
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_offlineTrkParticleName
Offline TrackParticleContainer's name.
Definition: InDetTrackPerfMonTool.h:61
InDetTrackPerfMonTool::m_eventInfoContainerName
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoContainerName
EventInfo container name.
Definition: InDetTrackPerfMonTool.h:73
IDTPM::TrackAnalysisCollections::InRoI
@ InRoI
Definition: TrackAnalysisCollections.h:49
ManagedMonitorToolBase::endOfRunFlag
bool endOfRunFlag() const
Definition: ManagedMonitorToolBase.h:859
ITrackAnalysisDefinitionSvc::useTruth
virtual bool useTruth() const =0
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DeMoScan.first
bool first
Definition: DeMoScan.py:534
ManagedMonitorToolBase::all
@ all
Definition: ManagedMonitorToolBase.h:116
IDTPM::TrackAnalysisCollections::printInfo
std::string printInfo(Stage stage=FULL) const
print Information about tracks in the collection(s)
Definition: TrackAnalysisCollections.cxx:488
IDTPM::TrackAnalysisCollections::empty
bool empty(Stage stage=FULL)
— Utility methods —
Definition: TrackAnalysisCollections.cxx:293
IDTPM::TrackAnalysisCollections::fillTrigTrackContainer
StatusCode fillTrigTrackContainer(const SG::ReadHandleKey< xAOD::TrackParticleContainer > &handleKey)
Trigger track particles.
Definition: TrackAnalysisCollections.cxx:122
IDTPM::TrackAnalysisCollections::copyFS
void copyFS()
copy content of FS vectors to InRoI vectors
Definition: TrackAnalysisCollections.cxx:335
InDetTrackPerfMonTool::InDetTrackPerfMonTool
InDetTrackPerfMonTool()
prevent default construction
InDetTrackPerfMonTool::m_triggerTrkParticleName
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_triggerTrkParticleName
Trigger TrackParticleContainer's name.
Definition: InDetTrackPerfMonTool.h:65
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:1454
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:92