ATLAS Offline Software
PrdMultiTruthMaker.cxx
Go to the documentation of this file.
1 
2 /*
3  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 */
5 #include "PrdMultiTruthMaker.h"
6 
7 #include "StoreGate/ReadHandle.h"
9 
12 namespace MuonR4 {
14 
15  ATH_CHECK(m_xAODPrdKeys.initialize());
16  for (const xAODPrdKey_t& key : m_xAODPrdKeys) {
17  m_simHitDecorKeys.emplace_back(key, m_simLinkDecor);
18  }
19  if (m_xAODPrdKeys.empty()) {
20  ATH_MSG_FATAL("No input containers were defined "<<m_xAODPrdKeys);
21  return StatusCode::FAILURE;
22  }
23  ATH_CHECK(m_simHitDecorKeys.initialize());
25  return StatusCode::SUCCESS;
26  }
27 
28  StatusCode PrdMultiTruthMaker::execute(const EventContext& ctx) const {
29 
30  SG::WriteHandle prdTruth{m_writeKey, ctx};
31  ATH_CHECK(prdTruth.record(std::make_unique<PRD_MultiTruthCollection>()));
32 
33  for (const xAODPrdKey_t& key : m_xAODPrdKeys) {
34  SG::ReadHandle readHandle{key, ctx};
35  if (!readHandle.isPresent()) {
36  ATH_MSG_FATAL("Failed to load container "<<key.fullKey());
37  return StatusCode::FAILURE;
38  }
39  for (const xAOD::UncalibratedMeasurement* meas : *readHandle) {
40  const xAOD::MuonSimHit* truthHit{getTruthMatchedHit(*meas)};
41  if (!truthHit || !truthHit->genParticleLink().isValid()){
42  continue;
43  }
44  const auto& pl{truthHit->genParticleLink()};
46  using truthiter = PRD_MultiTruthCollection::iterator;
47  const Identifier prdId = xAOD::identify(meas);
48  std::pair<truthiter, truthiter> r = prdTruth->equal_range(prdId);
49  if (r.second == std::find_if(r.first, r.second,
50  [pl](const PRD_MultiTruthCollection::value_type& prd_to_truth) {
51  return prd_to_truth.second == pl;
52  })) {
53  prdTruth->insert(std::make_pair(prdId, pl));
54  }
55  }
56  }
57  return StatusCode::SUCCESS;
58  }
59 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
beamspotman.r
def r
Definition: beamspotman.py:676
MuonSimHitHelpers.h
xAOD::MuonSimHit_v1
Definition: MuonSimHit_v1.h:18
xAOD::identify
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx:61
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
UtilFunctions.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
MuonR4::PrdMultiTruthMaker::initialize
virtual StatusCode initialize() override final
Definition: PrdMultiTruthMaker.cxx:13
WriteHandle.h
Handle class for recording to StoreGate.
xAOD::UncalibratedMeasurement_v1
Definition: UncalibratedMeasurement_v1.h:13
xAOD::MuonSimHit_v1::genParticleLink
const HepMcParticleLink & genParticleLink() const
Returns the link to the HepMC particle producing this hit.
Definition: xAODMuonSimHit_V1.cxx:67
MuonR4::PrdMultiTruthMaker::m_xAODPrdKeys
SG::ReadHandleKeyArray< xAODPrdCont_t > m_xAODPrdKeys
Definition: PrdMultiTruthMaker.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MuonR4::PrdMultiTruthMaker::m_simHitDecorKeys
SG::ReadDecorHandleKeyArray< xAODPrdCont_t > m_simHitDecorKeys
Definition: PrdMultiTruthMaker.h:34
MuonR4::PrdMultiTruthMaker::m_writeKey
SG::WriteHandleKey< PRD_MultiTruthCollection > m_writeKey
Definition: PrdMultiTruthMaker.h:36
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
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
MuonR4::getTruthMatchedHit
const xAOD::MuonSimHit * getTruthMatchedHit(const xAOD::UncalibratedMeasurement &prdHit)
Returns the MuonSimHit, if there's any, matched to the uncalibrated muon measurement.
Definition: MuonSimHitHelpers.cxx:13
MuonR4::PrdMultiTruthMaker::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: PrdMultiTruthMaker.cxx:28
ReadHandle.h
Handle class for reading from StoreGate.
PrdMultiTruthMaker.h
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
MuonR4::PrdMultiTruthMaker::m_simLinkDecor
Gaudi::Property< std::string > m_simLinkDecor
Definition: PrdMultiTruthMaker.h:31
Identifier
Definition: IdentifierFieldParser.cxx:14