ATLAS Offline Software
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 
18 namespace InDet {
19 #if 0 /*no-op block for better indentation in Emacs*/
20 }
21 #endif
22 
23 //================================================================
24 PRD_MultiTruthBuilder::PRD_MultiTruthBuilder(const std::string& type, const std::string& name, const IInterface* 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 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
AtlasDetectorID::is_pixel
bool is_pixel(Identifier id) const
Definition: AtlasDetectorID.h:760
beamspotman.r
def r
Definition: beamspotman.py:676
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
InDet::PRD_MultiTruthBuilder::addPrepRawDatum
virtual void addPrepRawDatum(PRD_MultiTruthCollection *prdTruth, const Trk::PrepRawData *prd, const InDetSimDataCollection *simDataMap, bool pixels) const
Definition: PRD_MultiTruthBuilder.cxx:44
PixelID::phi_index
int phi_index(const Identifier &id) const
Definition: PixelID.h:658
InDetSimData::getdeposits
const std::vector< Deposit > & getdeposits() const
Definition: InDetSimData.h:74
AtlasDetectorID::is_sct
bool is_sct(Identifier id) const
Definition: AtlasDetectorID.h:770
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
PRD_MultiTruthCollection
A PRD is mapped onto all contributing particles.
Definition: PRD_MultiTruthCollection.h:24
Trk::PrepRawData::rdoList
const std::vector< Identifier > & rdoList() const
return the List of rdo identifiers (pointers)
InDetSimDataCollection
Definition: InDetSimDataCollection.h:25
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
PrepRawData.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
SiReadoutCellId.h
InDet::PRD_MultiTruthBuilder::m_sctThreshold
Gaudi::Property< float > m_sctThreshold
Definition: PRD_MultiTruthBuilder.h:41
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
InDetSimData
Definition: InDetSimData.h:42
HepMC::uniqueID
int uniqueID(const T &p)
Definition: MagicNumbers.h:116
test_pyathena.parent
parent
Definition: test_pyathena.py:15
PixelID::eta_index
int eta_index(const Identifier &id) const
Definition: PixelID.h:664
Trk::PrepRawData
Definition: PrepRawData.h:62
Trk::PrepRawData::identify
Identifier identify() const
return the identifier
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MagicNumbers.h
InDet::PRD_MultiTruthBuilder::initialize
virtual StatusCode initialize()
Definition: PRD_MultiTruthBuilder.cxx:31
InDet::PRD_MultiTruthBuilder::m_idHelperPixel
const PixelID * m_idHelperPixel
Definition: PRD_MultiTruthBuilder.h:32
PRD_MultiTruthBuilder.h
SiDetectorElement.h
InDetSimDataCollection.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
PRD_MultiTruthCollection.h
AthAlgTool
Definition: AthAlgTool.h:26
InDet::PRD_MultiTruthBuilder::m_pixelThreshold
Gaudi::Property< float > m_pixelThreshold
Definition: PRD_MultiTruthBuilder.h:34