ATLAS Offline Software
Loading...
Searching...
No Matches
InDetDetailedTrackTruthMaker.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Algorithm producing truth info for PrepRawData, keeping all MC particles contributed to a PRD.
6// A. Gaponenko, 2006
7
9
10#include <iterator>
11
12namespace InDet {
13
14//================================================================
15InDetDetailedTrackTruthMaker::InDetDetailedTrackTruthMaker(const std::string &name, ISvcLocator *pSvcLocator) :
16 AthReentrantAlgorithm(name,pSvcLocator),
17 m_PRDTruthNamePixel("PRD_MultiTruthPixel"),
18 m_PRDTruthNameSCT("PRD_MultiTruthSCT"),
19 m_PRDTruthNameTRT("PRD_MultiTruthTRT"),
20 m_trackCollectionName("Tracks"),
21 m_detailedTrackTruthName("DetailedTrackTruth"),
22 m_truthTool("Trk::DetailedTrackTruthBuilder")
23{
24 declareProperty("TruthNamePixel", m_PRDTruthNamePixel);
25 declareProperty("TruthNameSCT", m_PRDTruthNameSCT);
26 declareProperty("TruthNameTRT", m_PRDTruthNameTRT);
27 declareProperty("TrackCollectionName", m_trackCollectionName);
28 declareProperty("DetailedTrackTruthName", m_detailedTrackTruthName);
29 declareProperty("TruthTool", m_truthTool);
30}
31
32// Initialize method
33// -----------------------------------------------------------------------------------------------------
35{
36 ATH_MSG_DEBUG ("InDetDetailedTrackTruthMaker::initialize()");
37
38 //----------------
39 if ( m_truthTool.retrieve().isFailure() ) {
40 ATH_MSG_FATAL ("Failed to retrieve tool " << m_truthTool);
41 return StatusCode::FAILURE;
42 } else {
43 ATH_MSG_DEBUG ("Retrieved tool " << m_truthTool);
44 }
45
46 // Read Handle Key
47 ATH_CHECK(m_trackCollectionName.initialize());
48
49 ATH_CHECK(m_PRDTruthNamePixel.initialize(not m_PRDTruthNamePixel.key().empty()));
50 ATH_CHECK(m_PRDTruthNameSCT.initialize(not m_PRDTruthNameSCT.key().empty()));
51 ATH_CHECK(m_PRDTruthNameTRT.initialize(not m_PRDTruthNameTRT.key().empty()));
52
54
55 //----------------
56 return StatusCode::SUCCESS;
57}
58
59// -----------------------------------------------------------------------------------------------------
61{
62 ATH_MSG_DEBUG ("InDetDetailedTrackTruthMaker finalized");
63 return StatusCode::SUCCESS;
64}
65
66// -----------------------------------------------------------------------------------------------------
67StatusCode InDetDetailedTrackTruthMaker::execute(const EventContext &ctx) const
68{
69 ATH_MSG_DEBUG ("InDetDetailedTrackTruthMaker::execute(...)");
70
71 //----------------------------------------------------------------
72 // Retrieve track collection
74 if (!tracks.isValid()) {
75 ATH_MSG_ERROR ("TrackCollection "<<m_trackCollectionName.key()<<" NOT found");
76 return StatusCode::FAILURE;
77 } else {
78 ATH_MSG_DEBUG ("Got TrackCollection "<<m_trackCollectionName.key());
79 }
80
81 //----------------------------------------------------------------
82 // Retrieve prep raw data truth
83 std::vector<SG::ReadHandle<PRD_MultiTruthCollection> > read_handle;
84 read_handle.reserve(3);
85
86 std::vector<const PRD_MultiTruthCollection*> prdCollectionVector;
87 prdCollectionVector.reserve(3);
88
89 if(!m_PRDTruthNamePixel.key().empty()) {
90 read_handle.emplace_back(m_PRDTruthNamePixel,ctx );
91 if (!read_handle.back().isValid()) {
92 ATH_MSG_WARNING ("Pixel PRD_MultiTruthCollection "<<m_PRDTruthNamePixel.key()<<" NOT found");
93 }
94 else {
95 ATH_MSG_DEBUG ("Got Pixel PRD_MultiTruthCollection "<<m_PRDTruthNamePixel.key());
96 prdCollectionVector.push_back( &(*read_handle.back()) );
97 }
98 }
99
100 if(!m_PRDTruthNameSCT.key().empty()) {
101 read_handle.emplace_back(m_PRDTruthNameSCT,ctx );
102 if (!read_handle.back().isValid()) {
103 ATH_MSG_WARNING ("SCT PRD_MultiTruthCollection "<<m_PRDTruthNameSCT.key()<<" NOT found");
104 } else {
105 ATH_MSG_DEBUG ("Got SCT PRD_MultiTruthCollection "<<m_PRDTruthNameSCT.key());
106 prdCollectionVector.push_back( &(*read_handle.back()) );
107 }
108 }
109
110 if(!m_PRDTruthNameTRT.key().empty()) {
111 read_handle.emplace_back(m_PRDTruthNameTRT,ctx );
112 if (!read_handle.back().isValid()) {
113 ATH_MSG_WARNING ("TRT PRD_MultiTruthCollection "<<m_PRDTruthNameTRT.key()<<" NOT found");
114 } else {
115 ATH_MSG_DEBUG ("Got TRT PRD_MultiTruthCollection "<<m_PRDTruthNameTRT.key());
116 prdCollectionVector.push_back( &(*read_handle.back()) );
117 }
118 }
119
120 //----------------------------------------------------------------
121 // Produce and store the output.
123 if (dttc.record(std::make_unique<DetailedTrackTruthCollection>(&(*tracks))).isFailure()) {
124 ATH_MSG_ERROR ("DetailedTrackTruthCollection '" << m_detailedTrackTruthName.key() << "' could not be recorded !");
125 return StatusCode::FAILURE;
126 }
127 else {
128 ATH_MSG_DEBUG ("DetailedTrackTruthCollection '" << m_detailedTrackTruthName.key() << "' is registered in StoreGate, size="<<dttc->size());
129 m_truthTool->buildDetailedTrackTruth(&(*dttc), *tracks, prdCollectionVector, ctx);
130 return StatusCode::SUCCESS;
131 }
132
133}
134
135} // namespace InDet
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
An algorithm that can be simultaneously executed in multiple threads.
virtual StatusCode execute(const EventContext &ctx) const
SG::WriteHandleKey< DetailedTrackTruthCollection > m_detailedTrackTruthName
SG::ReadHandleKey< TrackCollection > m_trackCollectionName
SG::ReadHandleKey< PRD_MultiTruthCollection > m_PRDTruthNameTRT
ToolHandle< Trk::IDetailedTrackTruthBuilder > m_truthTool
InDetDetailedTrackTruthMaker(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< PRD_MultiTruthCollection > m_PRDTruthNamePixel
SG::ReadHandleKey< PRD_MultiTruthCollection > m_PRDTruthNameSCT
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Primary Vertex Finder.