ATLAS Offline Software
Loading...
Searching...
No Matches
PRD_TruthTrajectoryBuilder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 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
60
61 ATH_MSG_INFO("Calling refreshEvent() to reset cache and retrieve collections");
62 // clear the cache & reserve
65 // load the PRD collections from SG
66 for(const auto& pmtCollNameIter:m_prdMultiTruthCollectionNames){
67 // try to retrieve the PRD multi truth collection
68 SG::ReadHandle<PRD_MultiTruthCollection> curColl (pmtCollNameIter);
69 if (!curColl.isValid()){
70 ATH_MSG_WARNING("Could not retrieve " << pmtCollNameIter << ". Ignoring ... ");
71 }
72 else{
73 ATH_MSG_INFO("Added " << pmtCollNameIter << " to collection list for truth track creation.");
74 m_prdMultiTruthCollections.push_back(curColl.cptr());
75 }
76 }
77 // all good
78 return StatusCode::SUCCESS;
79
80}
81
82std::map<HepMC::ConstGenParticlePtr, Trk::PRD_TruthTrajectory > Trk::PRD_TruthTrajectoryBuilder::truthTrajectories() const {
83 // ndof
84 size_t ndofTotal = 0;
85 size_t ndof = 0;
86
87 std::map< HepMC::ConstGenParticlePtr, PRD_TruthTrajectory > gpPrdTruthTrajectories;
88
89 // PART 1 --------------------------------------------------------------------------------------------------------
90 // loop over the PRD_MultiTruthCollection, search for the PRD and create (if necessary and entry in the return map)
91 std::vector<const PRD_MultiTruthCollection*>::const_iterator pmtCollIter = m_prdMultiTruthCollections.begin();
92 std::vector<const PRD_MultiTruthCollection*>::const_iterator pmtCollIterE = m_prdMultiTruthCollections.end();
93 for ( ; pmtCollIter != pmtCollIterE; ++pmtCollIter ){
94 // loop over the map and get the identifier, GenParticle relation
95 PRD_MultiTruthCollection::const_iterator prdMtCIter = (*pmtCollIter)->begin();
96 PRD_MultiTruthCollection::const_iterator prdMtCIterE = (*pmtCollIter)->end();
97 for ( ; prdMtCIter != prdMtCIterE; ++ prdMtCIter ){
98
99 // check if entry exists and if
100#ifdef HEPMC3
101 HepMC::ConstGenParticlePtr curGenP = (*prdMtCIter).second.scptr();
102#else
103//AV Looks like an implicit conversion
104 HepMC::ConstGenParticlePtr curGenP = (*prdMtCIter).second;
105#endif
106 Identifier curIdentifier = (*prdMtCIter).first;
107 // apply the min pT cut
108 if ( curGenP->momentum().perp() < m_minPt ) continue;
109 // skip geantinos if required
110 if (!m_geantinos && std::abs(curGenP->pdg_id())==999) continue;
111 // get the associated PRD from the provider
112 const Trk::PrepRawData* prd = m_idHelper->is_indet(curIdentifier) ?
113 m_idPrdProvider->prdFromIdentifier(curIdentifier,ndof) : m_msPrdProvider->prdFromIdentifier(curIdentifier,ndof);
114 // stuff it into the trajectory if you found a PRD
115 if (prd){
116 // try to find the entry for this GenParticle
117 auto prdTrajIter = gpPrdTruthTrajectories.find(curGenP);
118 if ( prdTrajIter == gpPrdTruthTrajectories.end() ){
119 // first PRD associated to this: create PRD_TruthTrajectory object
120 Trk::PRD_TruthTrajectory newPrdTruthTrajectory;
121 newPrdTruthTrajectory.prds.push_back(prd);
122 newPrdTruthTrajectory.nDoF = ndof-5;
123 // register the GenParticle only once
124 newPrdTruthTrajectory.genParticle = curGenP;
125 // fill into map
126 gpPrdTruthTrajectories[curGenP] = newPrdTruthTrajectory;
127 ndofTotal = ndof;
128 } else {
129 // this PRD_TruthTrajectory already exists
130 (prdTrajIter->second).prds.push_back(prd);
131 (prdTrajIter->second).nDoF += ndof;
132 ndofTotal = (prdTrajIter->second).nDoF;
133 }
134 ATH_MSG_DEBUG(" Associating PRD with " << ndof << " degrees of freedom, total N.d.o.F : " << ndofTotal );
135 ATH_MSG_DEBUG(" Associating Identifier " << curIdentifier << " with particle at [ " << curGenP << " ]." );
136 std::string prdtype = m_idHelper->is_pixel(curIdentifier) ? "Pixel" : m_idHelper->is_sct(curIdentifier) ? "SCT" : "TRT";
137 ATH_MSG_DEBUG(" PRD is a " << prdtype);
138 } else {
139 std::string prdtype = m_idHelper->is_pixel(curIdentifier) ? "Pixel" : m_idHelper->is_sct(curIdentifier) ? "SCT" : "TRT";
140 ATH_MSG_DEBUG(" Failed to get " << prdtype << " PRD");
141 }
142 }
143 }
144 // PART 2 --------------------------------------------------------------------------------------------------------
145 // loop through the provided list of manipulators ( sorter is included )
146 auto prdTruthTrajIter = gpPrdTruthTrajectories.begin();
147 auto prdTruthTrajIterE = gpPrdTruthTrajectories.end();
148 for ( ; prdTruthTrajIter != prdTruthTrajIterE; ++prdTruthTrajIter ){
149 if ( !m_prdTruthTrajectoryManipulators.empty() ){
150 ToolHandleArray<IPRD_TruthTrajectoryManipulator>::const_iterator prdTTMIter = m_prdTruthTrajectoryManipulators.begin();
151 ToolHandleArray<IPRD_TruthTrajectoryManipulator>::const_iterator prdTTMIterE = m_prdTruthTrajectoryManipulators.end();
152 for ( ; prdTTMIter != prdTTMIterE; ++prdTTMIter ){
153 if ((*prdTTMIter)->manipulateTruthTrajectory((*prdTruthTrajIter).second))
154 ATH_MSG_DEBUG("PRD truth trajectory got manipulated by: " << (*prdTTMIter).name() );
155 }
156 }
157 }
158 // return the truth trajectories and leave it to the TruthTrack creation to proceed further
159 return gpPrdTruthTrajectories;
160}
161
163{
164 // clear the cache a last time
166 return StatusCode::SUCCESS;
167}
168
#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
std::vector< const PRD_MultiTruthCollection * > m_prdMultiTruthCollections
the retrieved PRD muli truth collections
virtual std::map< HepMC::ConstGenParticlePtr, PRD_TruthTrajectory > truthTrajectories() const override
return a vector of PrepRawData trajectories - uses internal cache
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 StatusCode refreshEvent() override
Event refresh - can't be an IIncident, because it has to run after PRD creation and PRD truth creatio...
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