ATLAS Offline Software
TruthMeasMarkerAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 #include "TruthMeasMarkerAlg.h"
5 
7 #include "StoreGate/ReadHandle.h"
12 
13 namespace MuonR4 {
16  using SegLinkVec_t = std::vector<SegLink_t>;
17 
20 
22  using namespace DerivationFramework;
23 
25  ATH_CHECK(m_segKey.initialize());
26  if (m_measKeys.empty()) {
27  ATH_MSG_FATAL("Please configure the measurement containers to decorate.");
28  return StatusCode::FAILURE;
29  }
30  ATH_CHECK(m_measKeys.initialize());
31  for (const auto& key : m_measKeys) {
32  m_writeMarkKeys.emplace_back(key, m_writeMarker);
33  m_writeSegLinkKeys.emplace_back(key, m_segLink);
34  }
35  ATH_CHECK(m_writeMarkKeys.initialize());
36  ATH_CHECK(m_writeSegLinkKeys.initialize());
37  return StatusCode::SUCCESS;
38  }
39  StatusCode TruthMeasMarkerAlg::execute(const EventContext& ctx) const {
40  SG::ReadHandle segContainer{m_segKey, ctx};
41 
42  std::unordered_map<const SG::AuxVectorData*, MarkerHandle_t> markers{};
43  std::unordered_map<Muon::MuonStationIndex::TechnologyIndex, std::vector<const PrdCont_t*>> techConts{};
44  for (const WriteDecorKey_t& key : m_writeMarkKeys) {
45  SG::ReadHandle readHandle{key.contHandleKey(), ctx};
46  ATH_CHECK(readHandle.isPresent());
47  if (readHandle->empty()) {
48  continue;
49  }
50  MarkerHandle_t decor{makeHandle(ctx, key, false)};
51  markers.insert(std::make_pair(readHandle.cptr(), std::move(decor)));
53  m_idHelperSvc->technologyIndex(xAOD::identify(readHandle->at(0)));
54  techConts[techIdx].push_back(readHandle.cptr());
55  }
56  std::unordered_map<const SG::AuxVectorData*, LinkHandle_t> links{};
57  for (const WriteDecorKey_t& key : m_writeSegLinkKeys) {
58  SG::ReadHandle readHandle{key.contHandleKey(), ctx};
59  if (readHandle->empty()){
60  continue;
61  }
62  LinkHandle_t decor{makeHandle(ctx, key,SegLinkVec_t{})};
63  links.insert(std::make_pair(readHandle.cptr(), std::move(decor)));
64  }
65 
66  auto fetchPrd = [&techConts,this](const xAOD::MuonSimHit* hit) -> const xAOD::UncalibratedMeasurement*{
67  for (const PrdCont_t* prdCont : techConts[m_idHelperSvc->technologyIndex(hit->identify())]){
68  for (const xAOD::UncalibratedMeasurement* prd : *prdCont) {
69  if (getTruthMatchedHit(*prd) == hit){
70  ATH_MSG_VERBOSE("Found hit matched to "<<m_idHelperSvc->toString(hit->identify()));
71  return prd;
72  }
73  }
74  }
75  ATH_MSG_VERBOSE("Nothing could be matched to "<<m_idHelperSvc->toString(hit->identify()));
76  return nullptr;
77  };
78 
79  for (const xAOD::MuonSegment* segment : *segContainer) {
80  const auto truthHits{getMatchingSimHits(*segment)};
81 
82  SegLink_t segLink{segContainer.cptr(), segment->index()};
83  for (const xAOD::MuonSimHit* simHit : truthHits) {
84  const xAOD::UncalibratedMeasurement* prd = fetchPrd(simHit);
85  if (!prd) {
86  continue;
87  }
88  markers.at(prd->container())(*prd) = true;
89  links.at(prd->container())(*prd).push_back(segLink);
90  }
91  }
92  return StatusCode::SUCCESS;
93  }
94 
95 }
SG::WriteDecorHandleKey
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Definition: StoreGate/StoreGate/WriteDecorHandleKey.h:89
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
Utils.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MuonR4::PrdCont_t
xAOD::UncalibratedMeasurementContainer PrdCont_t
Definition: MeasurementMarkerAlg.cxx:13
ViewHelper::makeHandle
SG::ReadHandle< T > makeHandle(const SG::View *view, const SG::ReadHandleKey< T > &rhKey, const EventContext &context)
navigate from the TrigComposite to nearest view and fetch object from it
Definition: ViewHelper.h:265
MuonR4::LinkHandle_t
SG::WriteDecorHandle< PrdCont_t, SegLinkVec_t > LinkHandle_t
Definition: MeasurementMarkerAlg.cxx:21
xAOD::MuonSegment_v1
Class describing a MuonSegment.
Definition: MuonSegment_v1.h:33
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TruthMeasMarkerAlg.h
MuonR4::TruthMeasMarkerAlg::initialize
virtual StatusCode initialize() override final
Definition: TruthMeasMarkerAlg.cxx:24
xAOD::UncalibratedMeasurement_v1
Definition: UncalibratedMeasurement_v1.h:13
MuonR4::MarkerHandle_t
SG::WriteDecorHandle< PrdCont_t, bool > MarkerHandle_t
Definition: MeasurementMarkerAlg.cxx:20
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DMTest::links
links
Definition: CLinks_v1.cxx:22
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
MuonR4::SegLink_t
ElementLink< xAOD::MuonSegmentContainer > SegLink_t
Definition: MeasurementMarkerAlg.cxx:14
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
CoreClass.markers
list markers
Definition: CoreClass.py:17
xAOD::UncalibratedMeasurementContainer
UncalibratedMeasurementContainer_v1 UncalibratedMeasurementContainer
Define the version of the uncalibrated measurement container.
Definition: UncalibratedMeasurementContainer.h:14
MuonR4::TruthMeasMarkerAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: TruthMeasMarkerAlg.cxx:39
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
MuonR4::SegLinkVec_t
std::vector< SegLink_t > SegLinkVec_t
Definition: MeasurementMarkerAlg.cxx:15
MuonR4::WriteDecorKey_t
SG::WriteDecorHandleKey< xAOD::UncalibratedMeasurementContainer > WriteDecorKey_t
Definition: MeasurementMarkerAlg.cxx:23
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
ReadDecorHandle.h
Handle class for reading a decoration on an object.
SG::AuxElement::container
const SG::AuxVectorData * container() const
Return the container holding this element.
ReadHandle.h
Handle class for reading from StoreGate.
Muon::MuonStationIndex::TechnologyIndex
TechnologyIndex
enum to classify the different layers in the muon spectrometer
Definition: MuonStationIndex.h:54
MuonR4::getMatchingSimHits
std::unordered_set< const xAOD::MuonSimHit * > getMatchingSimHits(const xAOD::MuonSegment &segment)
: Returns all sim hits matched to a xAOD::MuonSegment
Definition: MuonSimHitHelpers.cxx:24
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37