ATLAS Offline Software
Loading...
Searching...
No Matches
PRD_TruthTrajectoryBuilder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6// PRD_TruthTrajectoryBuilder.cxx, (c) ATLAS Detector software
8
9// package include
11// Trk
13// DetectorDescription
15// HepMC
18
19
21Trk::PRD_TruthTrajectoryBuilder::PRD_TruthTrajectoryBuilder(const std::string& t, const std::string& n, const IInterface* p) :
22 AthAlgTool(t,n,p),
23 m_idHelper(nullptr)
24{
25 declareInterface<Trk::IPRD_TruthTrajectoryBuilder>(this);
26 // the PRD providers that turn Identifier -> IdentiferHash and get the PRD
27}
28
29// Athena algtool's Hooks - initialize
31{
32
33 // Set up ATLAS ID helper to be able to identify the PRD's det-subsystem
34 if (detStore()->retrieve(m_idHelper, "AtlasID").isFailure()) {
35 ATH_MSG_ERROR ("Could not get AtlasDetectorID helper. Arborting ...");
36 return StatusCode::FAILURE;
37 }
38 // get the ID PRD Provider
39 if ( !m_idPrdProvider.empty() && m_idPrdProvider.retrieve().isFailure()){
40 ATH_MSG_ERROR ("Could not get " << m_idPrdProvider << ". Arborting ..." );
41 return StatusCode::FAILURE;
42 }
43 // get the Muon System PRD Provider
44 if ( !m_msPrdProvider.empty() && m_msPrdProvider.retrieve().isFailure()){
45 ATH_MSG_ERROR ("Could not get " << m_msPrdProvider << ". Arborting ..." );
46 return StatusCode::FAILURE;
47 }
48 // get the manipulators
49 if ( !m_prdTruthTrajectoryManipulators.empty() && m_prdTruthTrajectoryManipulators.retrieve().isFailure()){
50 ATH_MSG_ERROR ("Could not get configured " << m_prdTruthTrajectoryManipulators << ". Arborting ..." );
51 return StatusCode::FAILURE;
52 }
53
55
56 return StatusCode::SUCCESS;
57}
58
59
60std::map<HepMC::ConstGenParticlePtr, Trk::PRD_TruthTrajectory > Trk::PRD_TruthTrajectoryBuilder::truthTrajectories(const EventContext& ctx) const {
61 // ndof
62 size_t ndofTotal = 0;
63 size_t ndof = 0;
64
65 std::map< HepMC::ConstGenParticlePtr, PRD_TruthTrajectory > gpPrdTruthTrajectories;
66
67 std::vector<const PRD_MultiTruthCollection*> prdMultiTruthCollections;
68
69 // load the PRD collections from SG
70 prdMultiTruthCollections.reserve(m_prdMultiTruthCollectionNames.size());
71 for(const auto& pmtCollNameIter:m_prdMultiTruthCollectionNames){
72 // try to retrieve the PRD multi truth collection
73 SG::ReadHandle<PRD_MultiTruthCollection> curColl (pmtCollNameIter, ctx);
74 if (!curColl.isValid()){
75 ATH_MSG_WARNING("Could not retrieve " << pmtCollNameIter << ". Ignoring ... ");
76 }
77 else{
78 ATH_MSG_INFO("Added " << pmtCollNameIter << " to collection list for truth track creation.");
79 prdMultiTruthCollections.push_back(curColl.cptr());
80 }
81 }
82
83 // PART 1 --------------------------------------------------------------------------------------------------------
84 // loop over the PRD_MultiTruthCollection, search for the PRD and create (if necessary and entry in the return map)
85 std::vector<const PRD_MultiTruthCollection*>::const_iterator pmtCollIter = prdMultiTruthCollections.begin();
86 std::vector<const PRD_MultiTruthCollection*>::const_iterator pmtCollIterE = prdMultiTruthCollections.end();
87 for ( ; pmtCollIter != pmtCollIterE; ++pmtCollIter ){
88 // loop over the map and get the identifier, GenParticle relation
89 PRD_MultiTruthCollection::const_iterator prdMtCIter = (*pmtCollIter)->begin();
90 PRD_MultiTruthCollection::const_iterator prdMtCIterE = (*pmtCollIter)->end();
91 for ( ; prdMtCIter != prdMtCIterE; ++ prdMtCIter ){
92
93 // check if entry exists and if
94 HepMC::ConstGenParticlePtr curGenP = (*prdMtCIter).second.scptr();
95 Identifier curIdentifier = (*prdMtCIter).first;
96 // apply the min pT cut
97 if ( curGenP->momentum().perp() < m_minPt ) continue;
98 // skip geantinos if required
99 if (!m_geantinos && std::abs(curGenP->pdg_id())==999) continue;
100 // get the associated PRD from the provider
101 const Trk::PrepRawData* prd = m_idHelper->is_indet(curIdentifier) ?
102 m_idPrdProvider->prdFromIdentifier(curIdentifier,ndof) : m_msPrdProvider->prdFromIdentifier(curIdentifier,ndof);
103 // stuff it into the trajectory if you found a PRD
104 if (prd){
105 // try to find the entry for this GenParticle
106 auto prdTrajIter = gpPrdTruthTrajectories.find(curGenP);
107 if ( prdTrajIter == gpPrdTruthTrajectories.end() ){
108 // first PRD associated to this: create PRD_TruthTrajectory object
109 Trk::PRD_TruthTrajectory newPrdTruthTrajectory;
110 newPrdTruthTrajectory.prds.push_back(prd);
111 newPrdTruthTrajectory.nDoF = ndof-5;
112 // register the GenParticle only once
113 newPrdTruthTrajectory.genParticle = curGenP;
114 // fill into map
115 gpPrdTruthTrajectories[curGenP] = newPrdTruthTrajectory;
116 ndofTotal = ndof;
117 } else {
118 // this PRD_TruthTrajectory already exists
119 (prdTrajIter->second).prds.push_back(prd);
120 (prdTrajIter->second).nDoF += ndof;
121 ndofTotal = (prdTrajIter->second).nDoF;
122 }
123 ATH_MSG_DEBUG(" Associating PRD with " << ndof << " degrees of freedom, total N.d.o.F : " << ndofTotal );
124 ATH_MSG_DEBUG(" Associating Identifier " << curIdentifier << " with particle at [ " << curGenP << " ]." );
125 std::string prdtype = m_idHelper->is_pixel(curIdentifier) ? "Pixel" : m_idHelper->is_sct(curIdentifier) ? "SCT" : "TRT";
126 ATH_MSG_DEBUG(" PRD is a " << prdtype);
127 } else {
128 std::string prdtype = m_idHelper->is_pixel(curIdentifier) ? "Pixel" : m_idHelper->is_sct(curIdentifier) ? "SCT" : "TRT";
129 ATH_MSG_DEBUG(" Failed to get " << prdtype << " PRD");
130 }
131 }
132 }
133 // PART 2 --------------------------------------------------------------------------------------------------------
134 // loop through the provided list of manipulators ( sorter is included )
135 auto prdTruthTrajIter = gpPrdTruthTrajectories.begin();
136 auto prdTruthTrajIterE = gpPrdTruthTrajectories.end();
137 for ( ; prdTruthTrajIter != prdTruthTrajIterE; ++prdTruthTrajIter ){
138 if ( !m_prdTruthTrajectoryManipulators.empty() ){
139 ToolHandleArray<IPRD_TruthTrajectoryManipulator>::const_iterator prdTTMIter = m_prdTruthTrajectoryManipulators.begin();
140 ToolHandleArray<IPRD_TruthTrajectoryManipulator>::const_iterator prdTTMIterE = m_prdTruthTrajectoryManipulators.end();
141 for ( ; prdTTMIter != prdTTMIterE; ++prdTTMIter ){
142 if ((*prdTTMIter)->manipulateTruthTrajectory((*prdTruthTrajIter).second))
143 ATH_MSG_DEBUG("PRD truth trajectory got manipulated by: " << (*prdTTMIter).name() );
144 }
145 }
146 }
147 // return the truth trajectories and leave it to the TruthTrack creation to proceed further
148 return gpPrdTruthTrajectories;
149}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandleKeyArray< PRD_MultiTruthCollection > m_prdMultiTruthCollectionNames
ToolHandle< IPRD_Provider > m_idPrdProvider
Helper to detect type of sub-detector from PRD->identify().
PRD_TruthTrajectoryBuilder(const std::string &t, const std::string &n, const IInterface *p)
Constructor.
virtual StatusCode initialize() override
ToolHandleArray< IPRD_TruthTrajectoryManipulator > m_prdTruthTrajectoryManipulators
PRD truth tracjectory manipulators.
virtual std::map< HepMC::ConstGenParticlePtr, PRD_TruthTrajectory > truthTrajectories(const EventContext &ctx) const override
return a vector of PrepRawData trajectories - uses internal cache
ToolHandle< IPRD_Provider > m_msPrdProvider
Identifier to PRD relation in the Muons System.
const GenParticle * ConstGenParticlePtr
Definition GenParticle.h:38
simple definitiion of a PRD_TruhtTrajectory
std::vector< const Trk::PrepRawData * > prds
public members
HepMC::ConstGenParticlePtr genParticle