ATLAS Offline Software
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 
12 namespace InDet {
13 
14 //================================================================
15 InDetDetailedTrackTruthMaker::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 
52 
54 
55  //----------------
56  return StatusCode::SUCCESS;
57 }
58 
59 // -----------------------------------------------------------------------------------------------------
61 {
62  ATH_MSG_DEBUG ("InDetDetailedTrackTruthMaker finalized");
63  return StatusCode::SUCCESS;
64 }
65 
66 // -----------------------------------------------------------------------------------------------------
67 StatusCode 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
InDet::InDetDetailedTrackTruthMaker::m_PRDTruthNameTRT
SG::ReadHandleKey< PRD_MultiTruthCollection > m_PRDTruthNameTRT
Definition: InDetDetailedTrackTruthMaker.h:44
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
InDet::InDetDetailedTrackTruthMaker::m_detailedTrackTruthName
SG::WriteHandleKey< DetailedTrackTruthCollection > m_detailedTrackTruthName
Definition: InDetDetailedTrackTruthMaker.h:49
InDet::InDetDetailedTrackTruthMaker::m_PRDTruthNameSCT
SG::ReadHandleKey< PRD_MultiTruthCollection > m_PRDTruthNameSCT
Definition: InDetDetailedTrackTruthMaker.h:43
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
InDet::InDetDetailedTrackTruthMaker::m_truthTool
ToolHandle< Trk::IDetailedTrackTruthBuilder > m_truthTool
Definition: InDetDetailedTrackTruthMaker.h:52
InDet::InDetDetailedTrackTruthMaker::m_trackCollectionName
SG::ReadHandleKey< TrackCollection > m_trackCollectionName
Definition: InDetDetailedTrackTruthMaker.h:46
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
InDet::InDetDetailedTrackTruthMaker::finalize
virtual StatusCode finalize()
Definition: InDetDetailedTrackTruthMaker.cxx:60
InDet::InDetDetailedTrackTruthMaker::initialize
virtual StatusCode initialize()
Definition: InDetDetailedTrackTruthMaker.cxx:34
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
InDet::InDetDetailedTrackTruthMaker::execute
virtual StatusCode execute(const EventContext &ctx) const
Definition: InDetDetailedTrackTruthMaker.cxx:67
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
InDetDetailedTrackTruthMaker.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
InDet::InDetDetailedTrackTruthMaker::InDetDetailedTrackTruthMaker
InDetDetailedTrackTruthMaker(const std::string &name, ISvcLocator *pSvcLocator)
Definition: InDetDetailedTrackTruthMaker.cxx:15
InDet::InDetDetailedTrackTruthMaker::m_PRDTruthNamePixel
SG::ReadHandleKey< PRD_MultiTruthCollection > m_PRDTruthNamePixel
Definition: InDetDetailedTrackTruthMaker.h:42
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32