ATLAS Offline Software
Loading...
Searching...
No Matches
MuonTrackStatisticsAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8
10
11// CONSTRUCTOR:
12MuonTrackStatisticsAlg::MuonTrackStatisticsAlg(const std::string& name, ISvcLocator* pSvcLocator) :
13 AthAlgorithm(name, pSvcLocator), m_writeToFile(false), m_doTruth(false) {
14 declareProperty("doTruth", m_doTruth);
15 declareProperty("writeToFile", m_writeToFile);
16 declareProperty("FileName", m_fileName);
17}
19// INITIALIZE METHOD:
20
22 ATH_CHECK(m_statisticsTool.retrieve());
23 ATH_CHECK(m_trackKeys.initialize());
24 ATH_CHECK(m_truthKeys.initialize());
25
26 for (unsigned int i = 0; i < m_trackKeys.size(); i++) m_statisticsTool->addTrackCounters(m_trackKeys[i].key());
27 for (unsigned int i = 0; i < m_truthKeys.size(); i++) m_statisticsTool->addTrackCounters(m_truthKeys[i].key());
28
29 return StatusCode::SUCCESS;
30}
31
33 ATH_MSG_DEBUG("MuonTrackStatisticsAlg in execute() ...");
34
35 for (SG::ReadHandle<TrackCollection>& trackColl : m_trackKeys.makeHandles()) {
36 if (!trackColl.isPresent()) {
37 ATH_MSG_DEBUG("track collection " << trackColl.key() << " not present");
38 continue;
39 }
40 if (!trackColl.isValid()) {
41 ATH_MSG_WARNING("track collection " << trackColl.key() << " not valid!");
42 return StatusCode::FAILURE;
43 }
44 ATH_CHECK(m_statisticsTool->updateTrackCounters(trackColl.key(), trackColl.cptr()));
45 }
46
47 for (SG::ReadHandle<DetailedTrackTruthCollection>& truthMap : m_truthKeys.makeHandles()) {
48 if (!truthMap.isPresent()) {
49 ATH_MSG_DEBUG("truth map " << truthMap.key() << " not present");
50 continue;
51 }
52 if (!truthMap.isValid()) {
53 ATH_MSG_WARNING("truth map " << truthMap.key() << " not valid!");
54 return StatusCode::FAILURE;
55 }
56 ATH_CHECK(m_statisticsTool->updateTruthTrackCounters(truthMap.key(), truthMap.cptr()));
57 }
58
59 return StatusCode::SUCCESS;
60}
61
63// ATHENA FINALIZE:
64
66 ATH_MSG_INFO(std::endl << m_statisticsTool->printTrackCounters());
67 // write to file
68 if (m_writeToFile) {
69 m_fileOutput.open(m_fileName.c_str(), std::ios::trunc);
70 m_fileOutput << m_statisticsTool->printTrackCounters() << std::endl;
71 m_fileOutput.close();
72 }
73
74 return StatusCode::SUCCESS;
75}
76
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
virtual StatusCode execute() override
std::string m_fileName
name of external file to write statistics
SG::ReadHandleKeyArray< DetailedTrackTruthCollection > m_truthKeys
std::ofstream m_fileOutput
output file
SG::ReadHandleKeyArray< TrackCollection > m_trackKeys
virtual StatusCode initialize() override
ToolHandle< MuonTrackStatisticsTool > m_statisticsTool
MuonTrackStatisticsAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode finalize() override
virtual ~MuonTrackStatisticsAlg()