ATLAS Offline Software
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:
12 MuonTrackStatisticsAlg::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 
MuonTrackStatisticsAlg::initialize
virtual StatusCode initialize() override
Definition: MuonTrackStatisticsAlg.cxx:21
MuonTrackStatisticsAlg.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
MuonTrackStatisticsAlg::storeTruthTracks
void storeTruthTracks(void)
Definition: MuonTrackStatisticsAlg.cxx:77
MuonTrackStatisticsAlg::m_statisticsTool
ToolHandle< MuonTrackStatisticsTool > m_statisticsTool
Definition: MuonTrackStatisticsAlg.h:33
MuonTrackStatisticsAlg::~MuonTrackStatisticsAlg
virtual ~MuonTrackStatisticsAlg()
MuonTrackStatisticsAlg::finalize
virtual StatusCode finalize() override
Definition: MuonTrackStatisticsAlg.cxx:65
MuonTrackStatisticsAlg::m_fileOutput
std::ofstream m_fileOutput
output file
Definition: MuonTrackStatisticsAlg.h:41
MuonTrackStatisticsAlg::m_doTruth
bool m_doTruth
Definition: MuonTrackStatisticsAlg.h:44
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
MuonTrackStatisticsAlg::m_writeToFile
bool m_writeToFile
Definition: MuonTrackStatisticsAlg.h:43
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthAlgorithm
Definition: AthAlgorithm.h:47
MuonTrackStatisticsAlg::m_truthKeys
SG::ReadHandleKeyArray< DetailedTrackTruthCollection > m_truthKeys
Definition: MuonTrackStatisticsAlg.h:48
MuonTrackStatisticsAlg::execute
virtual StatusCode execute() override
Definition: MuonTrackStatisticsAlg.cxx:32
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MuonTrackStatisticsAlg::m_fileName
std::string m_fileName
name of external file to write statistics
Definition: MuonTrackStatisticsAlg.h:38
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
MuonTrackStatisticsAlg::MuonTrackStatisticsAlg
MuonTrackStatisticsAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MuonTrackStatisticsAlg.cxx:12
MuonTrackStatisticsTool.h
MuonTrackStatisticsAlg::m_trackKeys
SG::ReadHandleKeyArray< TrackCollection > m_trackKeys
Definition: MuonTrackStatisticsAlg.h:46