ATLAS Offline Software
MuonPRD_MultiTruthMaker.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 
8 
9 #include "StoreGate/ReadHandle.h"
10 #include "StoreGate/WriteHandle.h"
11 
12 //================================================================
14  ATH_MSG_DEBUG("MuonPRD_MultiTruthMaker::initialize()");
15  ATH_CHECK(m_idHelperSvc.retrieve());
16  ATH_CHECK(m_MdtPrdKey.initialize(!m_MdtPrdKey.empty()));
17  ATH_CHECK(m_CscPrdKey.initialize(!m_CscPrdKey.empty()));
18  ATH_CHECK(m_RpcPrdKey.initialize(!m_RpcPrdKey.empty()));
19  ATH_CHECK(m_TgcPrdKey.initialize(!m_TgcPrdKey.empty()));
20  ATH_CHECK(m_sTgcPrdKey.initialize(!m_sTgcPrdKey.empty()));
21  ATH_CHECK(m_MmPrdKey.initialize(!m_MmPrdKey.empty()));
22 
29 
36  return StatusCode::SUCCESS;
37 }
38 
39 //================================================================
40 StatusCode MuonPRD_MultiTruthMaker::execute(const EventContext& ctx) const {
41  ATH_MSG_DEBUG("MuonPRD_MultiTruthMaker::execute()");
48  return StatusCode::SUCCESS;
49 }
50 
51 //================================================================
52 template <class PrdType, class SimCollection>
57 
58  if (prdKey.empty()) {
59  ATH_MSG_DEBUG("No key has been defined for "<<typeid(PrdType).name()<<". Bail out silently");
60  return StatusCode::SUCCESS;
61  }
62  SG::ReadHandle prdContainer{prdKey, ctx};
63  if (!prdContainer.isPresent()) {
64  ATH_MSG_ERROR("Could not read " << prdKey.key());
65  return StatusCode::FAILURE;
66  }
67 
68  SG::ReadHandle simDataMap{sdoKey, ctx};
69  if (!simDataMap.isPresent()) {
70  ATH_MSG_ERROR("SimDataCollection for key=" << sdoKey.key() << " not in storegate.");
71  return StatusCode::FAILURE;
72  }
73  // Create and fill the PRD truth structure
74  ATH_MSG_DEBUG("make PRD truth for " << outputKey.key());
75  SG::WriteHandle prdTruth{outputKey, ctx};
76  ATH_CHECK(prdTruth.record(std::make_unique<PRD_MultiTruthCollection>()));
77 
78  for (const Muon::MuonPrepDataCollection<PrdType>* coll : *prdContainer) {
79  for (const PrdType* prd : *coll) {
80  ATH_MSG_VERBOSE("addPrepRawDatum(): new PRD " << prd << ", id=" << prd->identify() << ", number of RDOs: " << prd->rdoList().size());
81  bool gotSDO{false}, gotValidParticle{false};
82 
83  for (const auto& nextRDO : prd->rdoList()) {
84  typename SimCollection::const_iterator iter(simDataMap->find(nextRDO));
85  if (iter == simDataMap->end()) {
86  continue;
87  }
88  gotSDO = true;
89  // Got an SDO. Try to associate the PRD to MC particles we have info about.
90  typedef typename SimCollection::mapped_type SIMDATA;
91  const SIMDATA& sdo = iter->second;
92  const std::vector<typename SIMDATA::Deposit>& deposits = sdo.getdeposits();
93  if (deposits.empty()) { continue; }
94  for (const auto& [particleLink, mcData] : deposits) {
95  ATH_MSG_VERBOSE("addPrepRawDatum(): particleLink.isValid() " << particleLink.isValid());
96  ATH_MSG_VERBOSE("addPrepRawDatum(): Barcode " << particleLink.barcode() << " evt " << particleLink.eventIndex());
97  if (!particleLink.isValid()) {
98  continue;
99  }
100  gotValidParticle = true;
101  // Associate the particle to the PRD. But don't add duplicates.
102  // Note: it may be more efficient to filter out duplicates among particles for the current PRD, then check-and-add the
103  // reduced set to the large multimap. But may be not for the typically small RDO/PRD ratio.
104  typedef PRD_MultiTruthCollection::iterator truthiter;
105  std::pair<truthiter, truthiter> r = prdTruth->equal_range(prd->identify());
106  const auto& pl = particleLink; // Work around problem with clang 6.0.1
107  if (r.second == std::find_if(r.first, r.second, [pl](const PRD_MultiTruthCollection::value_type& prd_to_truth) {
108  return prd_to_truth.second == pl;
109  })) {
110  prdTruth->insert(std::make_pair(prd->identify(), particleLink));
111  }
112  }
113  }
114  if (gotSDO && !gotValidParticle) {
115  // Looked at all the deposits from all the SDOs, but did not find any valid particle link.
116  // prdTruth->insert(std::make_pair(prd, particleLinkUnknown));
117  ATH_MSG_DEBUG("addPrepRawDatum(): got SDO but no particles");
118  }
119  }
120  }
121  return StatusCode::SUCCESS;
122 }
123 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
beamspotman.r
def r
Definition: beamspotman.py:676
Muon::MuonPrepDataContainer
Template for Muon PRD containers (which are basically collections of MuonPrepDataCollections).
Definition: MuonPrepDataContainer.h:42
MuonPRD_MultiTruthMaker::m_MdtSDOKey
SG::ReadHandleKey< MuonSimDataCollection > m_MdtSDOKey
Definition: MuonPRD_MultiTruthMaker.h:37
MuonPRD_MultiTruthMaker.h
MuonPRD_MultiTruthMaker::m_MmPrdKey
SG::ReadHandleKey< Muon::MMPrepDataContainer > m_MmPrdKey
Definition: MuonPRD_MultiTruthMaker.h:35
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MuonPRD_MultiTruthMaker::m_CscTruthMapKey
SG::WriteHandleKey< PRD_MultiTruthCollection > m_CscTruthMapKey
Definition: MuonPRD_MultiTruthMaker.h:46
MuonPRD_MultiTruthMaker::m_sTgcPrdKey
SG::ReadHandleKey< Muon::sTgcPrepDataContainer > m_sTgcPrdKey
Definition: MuonPRD_MultiTruthMaker.h:34
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
MuonPRD_MultiTruthMaker::m_CscPrdKey
SG::ReadHandleKey< Muon::CscPrepDataContainer > m_CscPrdKey
Definition: MuonPRD_MultiTruthMaker.h:31
MuonPRD_MultiTruthMaker::m_sTgcSDOKey
SG::ReadHandleKey< MuonSimDataCollection > m_sTgcSDOKey
Definition: MuonPRD_MultiTruthMaker.h:41
MuonPRD_MultiTruthMaker::initialize
virtual StatusCode initialize() override final
Definition: MuonPRD_MultiTruthMaker.cxx:13
WriteHandle.h
Handle class for recording to StoreGate.
TileDigitizationConfig.outputKey
outputKey
Definition: TileDigitizationConfig.py:104
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::WriteHandleKey< PRD_MultiTruthCollection >
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
MuonPRD_MultiTruthMaker::m_CscSDOKey
SG::ReadHandleKey< CscSimDataCollection > m_CscSDOKey
Definition: MuonPRD_MultiTruthMaker.h:38
MuonPRD_MultiTruthMaker::m_TgcTruthMapKey
SG::WriteHandleKey< PRD_MultiTruthCollection > m_TgcTruthMapKey
Definition: MuonPRD_MultiTruthMaker.h:47
MuonPRD_MultiTruthMaker::m_MmTruthMapKey
SG::WriteHandleKey< PRD_MultiTruthCollection > m_MmTruthMapKey
Definition: MuonPRD_MultiTruthMaker.h:49
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
MuonPRD_MultiTruthMaker::m_RpcPrdKey
SG::ReadHandleKey< Muon::RpcPrepDataContainer > m_RpcPrdKey
Definition: MuonPRD_MultiTruthMaker.h:32
MuonPRD_MultiTruthMaker::m_sTgcTruthMapKey
SG::WriteHandleKey< PRD_MultiTruthCollection > m_sTgcTruthMapKey
Definition: MuonPRD_MultiTruthMaker.h:48
Muon::MuonPrepDataCollection
Template to hold collections of MuonPrepRawData objects.
Definition: MuonPrepDataCollection.h:46
MuonPRD_MultiTruthMaker::m_MdtPrdKey
SG::ReadHandleKey< Muon::MdtPrepDataContainer > m_MdtPrdKey
Definition: MuonPRD_MultiTruthMaker.h:30
MuonPRD_MultiTruthMaker::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: MuonPRD_MultiTruthMaker.cxx:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MuonPRD_MultiTruthMaker::m_TgcSDOKey
SG::ReadHandleKey< MuonSimDataCollection > m_TgcSDOKey
Definition: MuonPRD_MultiTruthMaker.h:40
MuonPRD_MultiTruthMaker::buildPRD_Truth
StatusCode buildPRD_Truth(const EventContext &ctx, const SG::ReadHandleKey< Muon::MuonPrepDataContainerT< PrdType >> &prepDataKey, const SG::ReadHandleKey< SimCollection > &sdoKey, const SG::WriteHandleKey< PRD_MultiTruthCollection > &outputKey) const
Definition: MuonPRD_MultiTruthMaker.cxx:53
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
MuonPRD_MultiTruthMaker::m_MdtTruthMapKey
SG::WriteHandleKey< PRD_MultiTruthCollection > m_MdtTruthMapKey
Definition: MuonPRD_MultiTruthMaker.h:44
MuonPRD_MultiTruthMaker::m_RpcSDOKey
SG::ReadHandleKey< MuonSimDataCollection > m_RpcSDOKey
Definition: MuonPRD_MultiTruthMaker.h:39
MuonPRD_MultiTruthMaker::m_MmSDOKey
SG::ReadHandleKey< MuonSimDataCollection > m_MmSDOKey
Definition: MuonPRD_MultiTruthMaker.h:42
MuonPRD_MultiTruthMaker::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonPRD_MultiTruthMaker.h:28
ReadHandle.h
Handle class for reading from StoreGate.
MuonPRD_MultiTruthMaker::m_RpcTruthMapKey
SG::WriteHandleKey< PRD_MultiTruthCollection > m_RpcTruthMapKey
Definition: MuonPRD_MultiTruthMaker.h:45
MuonPRD_MultiTruthMaker::m_TgcPrdKey
SG::ReadHandleKey< Muon::TgcPrepDataContainer > m_TgcPrdKey
Definition: MuonPRD_MultiTruthMaker.h:33