ATLAS Offline Software
Loading...
Searching...
No Matches
PRD_MultiTruthBuilder.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
14//#include <stdexcept>
15//#include <ext/functional>
16
17
18namespace InDet {
19#if 0 /*no-op block for better indentation in Emacs*/
20}
21#endif
22
23//================================================================
24PRD_MultiTruthBuilder::PRD_MultiTruthBuilder(const std::string& type, const std::string& name, const IInterface* parent)
25 : AthAlgTool(type,name,parent)
26 , m_idHelperPixel(nullptr)
27{
28 declareInterface<IPRD_MultiTruthBuilder>(this);
29}
30
32 ATH_MSG_DEBUG("PRD truth builder initialization");
33
34 StatusCode sc = detStore()->retrieve(m_idHelperPixel, "PixelID");
35 if (!sc.isSuccess()) {
36 ATH_MSG_FATAL("Could not get Pixel ID helper");
37 return sc;
38 }
39
40 return sc;
41}
42
43//================================================================
45 const Trk::PrepRawData* prd,
46 const InDetSimDataCollection* simDataMap,
47 bool pixels
48 ) const
49{
50 if(!prdTruth || !prd || !simDataMap) {
51 return;
52 }
53 ATH_MSG_VERBOSE("addPrepRawDatum(): new PRD "<<prd<<", id="<<prd->identify()<<", number of RDOs: " << prd->rdoList().size());
54
55 bool gotSDO = false;
56 bool gotValidParticle = false;
57
58 // loop over RDOs
59 std::vector<Identifier>::const_iterator nextRDO = prd->rdoList().begin();
60 std::vector<Identifier>::const_iterator lastRDO = prd->rdoList().end();
61 for (; nextRDO!=lastRDO; ++nextRDO) {
62 InDetSimDataCollection::const_iterator iter(simDataMap->find(*nextRDO));
63
64 if ( pixels && iter == simDataMap->end() ) {
65 ATH_MSG_VERBOSE ( "Pixel=" << m_idHelperPixel->eta_index(*nextRDO) << "," <<m_idHelperPixel->phi_index(*nextRDO) << " does not match any SDO");
66 }
67
68 bool isPixel = m_idHelperPixel->is_pixel( *nextRDO );
69 bool isSCT = m_idHelperPixel->is_sct( *nextRDO );
70
71 if(iter != simDataMap->end() ) {
72 gotSDO = true;
73 // Got an SDO. Try to associate the PRD to MC particles we have info about.
74 const InDetSimData& sdo = iter->second;
75 const std::vector< InDetSimData::Deposit >& deposits = sdo.getdeposits();
76 std::vector< InDetSimData::Deposit >::const_iterator nextdeposit = deposits.begin();
77 std::vector< InDetSimData::Deposit >::const_iterator lastdeposit = deposits.end();
78 for( ; nextdeposit!=lastdeposit; ++nextdeposit) {
79 const HepMcParticleLink& particleLink = nextdeposit->first;
80
81 ATH_MSG_VERBOSE("addPrepRawDatum(): Unique ID " << HepMC::uniqueID(&particleLink) << " with charge " << nextdeposit->second );
82
83 // Confirm that the energy deposited in the RDO is significant
84 if( isPixel && nextdeposit->second < m_pixelThreshold ){
85 ATH_MSG_VERBOSE("addPrepRawDatum() ignored PIXEL: Unique ID " << HepMC::uniqueID(particleLink.cptr()) << " with charge " << nextdeposit->second );
86 continue;
87 }
88
89 if( isSCT && nextdeposit->second < m_sctThreshold ){
90 ATH_MSG_VERBOSE("addPrepRawDatum() ignored SCT: Unique ID " << HepMC::uniqueID(particleLink.cptr()) << " with charge " << nextdeposit->second );
91 continue;
92 }
93
94 if (particleLink.isValid()) {
95 gotValidParticle = true;
96 // Associate the particle to the PRD. But don't add duplicates.
97 // Note: it may be more efficient to filter out duplicates among particles for the current PRD, then check-and-add the reduced set to the large multimap.
98 // But may be not for the typically small RDO/PRD ratio.
99 using truthiter = PRD_MultiTruthCollection::iterator;
100 std::pair<truthiter, truthiter> r = prdTruth->equal_range(prd->identify());
101 if(r.second == std::find_if(r.first, r.second,
102 [ particleLink ](const PRD_MultiTruthCollection::value_type &prd_to_truth) {
103 return prd_to_truth.second == particleLink;
104 } ))
105 {
106 prdTruth->insert(std::make_pair(prd->identify(), particleLink));
107 }
108 }
109 }
110 }
111 }
112
113 if(gotSDO && !gotValidParticle) {
114 // Looked at all the deposits from all the SDOs, but did not find any valid particle link.
115 //prdTruth->insert(std::make_pair(prd, particleLinkUnknown));
116 ATH_MSG_VERBOSE("addPrepRawDatum(): got SDO but no particles");
117 }
118
119 // No SDO found after all, for all the RDOs? Then (and only then) this PRD is noise.
120 //if(!gotSDO) {
121 //prdTruth->insert(std::make_pair(prd, particleLinkNoise) );
122 //}
123
124}
125
126//================================================================
127
128} // namespace InDet
129
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
This is an Identifier helper class for the Pixel subdetector.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
const std::vector< Deposit > & getdeposits() const
Gaudi::Property< float > m_sctThreshold
Gaudi::Property< float > m_pixelThreshold
PRD_MultiTruthBuilder(const std::string &type, const std::string &name, const IInterface *parent)
virtual void addPrepRawDatum(PRD_MultiTruthCollection *prdTruth, const Trk::PrepRawData *prd, const InDetSimDataCollection *simDataMap, bool pixels) const
A PRD is mapped onto all contributing particles.
Identifier identify() const
return the identifier
const std::vector< Identifier > & rdoList() const
return the List of rdo identifiers (pointers)
int r
Definition globals.cxx:22
int uniqueID(const T &p)
Primary Vertex Finder.