ATLAS Offline Software
Loading...
Searching...
No Matches
MlHitDumperAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4
5#include "MlHitDumperAlg.h"
6
8
9
15
16#include <unordered_map>
17
18namespace MuonR4{
20 ATH_CHECK(m_spacePointKeys.initialize());
21 ATH_CHECK(m_geoCtxKey.initialize());
22
23 ATH_CHECK(m_truthSegKey.initialize());
24 ATH_CHECK(m_truthLinkKey.initialize());
25 m_tree.addBranch(std::make_unique<MuonVal::EventInfoBranch>(m_tree, MuonVal::EventInfoBranch::isMC));
26
27
28 m_spCollection = std::make_unique<MuonValR4::SpacePointTesterModule>(m_tree, m_spacePointKeys[0].key(), msgLevel());
29 m_tree.addBranch(m_spCollection);
30 m_muonP4 = std::make_unique<MuonValR4::IParticleFourMomBranch>(m_tree, "truthMuon");
31 m_tree.addBranch(m_muonP4);
32 ATH_CHECK(m_tree.init(this));
33 return StatusCode::SUCCESS;
34 }
35 StatusCode MlHitDumperAlg::execute(const EventContext& ctx) {
36 const ActsTrk::GeometryContext* gctx{};
37 ATH_CHECK(SG::get(gctx, m_geoCtxKey, ctx));
38
39 std::unordered_map<const xAOD::MuonSimHit*, const xAOD::TruthParticle*> hitPartMap{};
40 const xAOD::MuonSegmentContainer* truthSegs{nullptr};
41 ATH_CHECK(SG::get(truthSegs, m_truthSegKey, ctx));
42 for (const xAOD::MuonSegment* segment : *truthSegs) {
43 const xAOD::TruthParticle* truthPart = getTruthMatchedParticle(*segment);
44 for (const xAOD::MuonSimHit* hit : getMatchingSimHits(*segment)) {
45 hitPartMap[hit] = truthPart;
46 }
47 }
48
50 const SpacePointContainer* spCont{nullptr};
51 ATH_CHECK(SG::get(spCont,key, ctx));
52 for (const SpacePointBucket* bucket : *spCont) {
53 m_spCollection->push_back(*bucket);
54 for (const auto& sp : *bucket) {
55 const xAOD::MuonSimHit* simHit = getTruthMatchedHit(*sp->primaryMeasurement());
56 m_muonP4->push_back(hitPartMap[simHit]);
57 m_truthLink[fillSpacePoint(*gctx, *sp)] = m_muonP4->find(hitPartMap[simHit]);
58 }
59 }
60 }
61 ATH_CHECK(m_tree.fill(ctx));
62
63 return StatusCode::SUCCESS;
64 }
66 const Amg::Transform3D& lToGlob = sp.msSector()->localToGlobalTransform(gctx);
67 std::size_t idx = m_spCollection->push_back(sp);
68 m_spGlobPos.set(lToGlob * sp.localPosition(), idx);
69
70 switch (sp.type()) {
71 using enum xAOD::UncalibMeasType;
72 case MdtDriftCircleType:{
73 const auto* prd = static_cast<const xAOD::MdtDriftCircle*>(sp.primaryMeasurement());
74 const auto* re = prd->readoutElement();
75 m_spGlobEdgeLow.set(re->readOutPos(gctx, prd->measurementHash()), idx);
76 m_spGlobEdgeHigh.set(re->highVoltPos(gctx, prd->measurementHash()), idx);
77 m_spReadoutSide[idx] = re->getParameters().readoutSide;
78 m_spTime[idx] = prd->tdc();
79 break;
80 }
81 case RpcStripType: {
82 const auto* prd = static_cast<const xAOD::RpcMeasurement*>(sp.primaryMeasurement());
83 const auto* re = prd->readoutElement();
84 m_spGlobEdgeLow.set(re->rightStripEdge(gctx, prd->measurementHash()), idx);
85 m_spGlobEdgeHigh.set(re->leftStripEdge(gctx, prd->measurementHash()), idx);
86 m_spReadoutSide[idx] = 1.;
87 m_spTime[idx] = prd->time();
88 break;
89 }
90 case TgcStripType: {
91 const auto* prd = static_cast<const xAOD::TgcStrip*>(sp.primaryMeasurement());
92 const auto* re = prd->readoutElement();
93 const MuonGMR4::StripDesign& design = re->sensorLayout(prd->layerHash())->design();
94 const double halfLength = design.stripLength(prd->channelNumber());
95 m_spReadoutSide[idx] = 1.;
96 m_spGlobEdgeLow.set( lToGlob*(sp.localPosition() -halfLength * sp.sensorDirection()) , idx);
97 m_spGlobEdgeHigh.set(lToGlob*(sp.localPosition() +halfLength * sp.sensorDirection()) , idx);
98 m_spTime[idx] = prd->bcBitMap();
99 break;
100 }
101 case MMClusterType: {
102 const auto* prd = static_cast<const xAOD::MMCluster*>(sp.primaryMeasurement());
103 const auto* re = prd->readoutElement();
104 m_spGlobEdgeLow.set(re->rightStripEdge(gctx, prd->measurementHash()), idx);
105 m_spGlobEdgeHigh.set(re->leftStripEdge(gctx, prd->measurementHash()), idx);
106 m_spReadoutSide[idx] = re->readoutSide(prd->measurementHash());
107 m_spTime[idx] = prd->time();
108 break;
109 }
110 case sTgcStripType: {
111 const auto* prd = static_cast<const xAOD::sTgcMeasurement*>(sp.primaryMeasurement());
112 const auto* re = prd->readoutElement();
113 m_spReadoutSide[idx] = 1.;
114 m_spTime[idx] = prd->time();
115 switch (prd->channelType()) {
117 case Pad:{
118 double xLow{std::numeric_limits<double>::max()},
119 xHigh{-std::numeric_limits<double>::max()},
120 yLow{std::numeric_limits<double>::max()},
121 yHigh{-std::numeric_limits<double>::max()};
122 for (const Amg::Vector2D& corner : re->localPadCorners(prd->measurementHash())) {
123 xLow = std::min(xLow, corner.x());
124 yLow = std::min(yLow, corner.y());
125 xHigh = std::max(xHigh, corner.x());
126 yHigh = std::max(yHigh, corner.y());
127 }
128 const Amg::Transform3D& padTrf{re->localToGlobalTransform(gctx, prd->layerHash())};
129 m_spGlobEdgeLow.set(padTrf * Amg::Vector3D{xLow,yLow, 0.}, idx);
130 m_spGlobEdgeHigh.set(padTrf * Amg::Vector3D{xHigh,yHigh, 0.}, idx);
131 break;
132 }
133 case Strip:
134 case Wire: {
135 const double halfLength = 0.5* re->stripLength(prd->measurementHash());
136 m_spGlobEdgeLow.set( lToGlob*(sp.localPosition() -halfLength * sp.sensorDirection()) , idx);
137 m_spGlobEdgeHigh.set(lToGlob*(sp.localPosition() +halfLength * sp.sensorDirection()) , idx);
138 break;
139 }
140 }
141 break;
142 }
143 default: break;
144 }
145 return idx;
146 }
148 ATH_CHECK(m_tree.write());
149 return StatusCode::SUCCESS;
150 }
151}
const std::regex re(r_e)
#define ATH_CHECK
Evaluate an expression and check for errors.
static Double_t sp
virtual double stripLength(int stripNumb) const
Returns length of the strip.
MuonVal::VectorBranch< char > & m_spReadoutSide
MuonVal::MuonTesterTree m_tree
ActsTrk::GeoContextReadKey_t m_geoCtxKey
SG::ReadHandleKey< xAOD::MuonSegmentContainer > m_truthSegKey
std::size_t fillSpacePoint(const ActsTrk::GeometryContext &gctx, const SpacePoint &sp)
std::shared_ptr< MuonValR4::SpacePointTesterModule > m_spCollection
SG::ReadDecorHandleKey< xAOD::MuonSegmentContainer > m_truthLinkKey
MuonVal::VectorBranch< char > & m_truthLink
std::shared_ptr< MuonVal::IParticleFourMomBranch > m_muonP4
SG::ReadHandleKeyArray< SpacePointContainer > m_spacePointKeys
virtual StatusCode execute(const EventContext &ctx) override final
Execute method.
virtual StatusCode finalize() override final
virtual StatusCode initialize() override final
MuonVal::ThreeVectorBranch m_spGlobPos
MuonVal::ThreeVectorBranch m_spGlobEdgeHigh
MuonVal::ThreeVectorBranch m_spGlobEdgeLow
MuonVal::VectorBranch< float > & m_spTime
: The muon space point bucket represents a collection of points that will bre processed together in t...
The muon space point is the combination of two uncalibrated measurements one of them measures the eta...
@ isMC
Flag determining whether the branch is simulation.
Definition Pad.h:10
Property holding a SG store/key/clid from which a ReadHandle is made.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
This header ties the generic definitions in this package.
const xAOD::TruthParticle * getTruthMatchedParticle(const xAOD::MuonSegment &segment)
Returns the particle truth-matched to the segment.
std::unordered_set< const xAOD::MuonSimHit * > getMatchingSimHits(const xAOD::MuonSegment &segment)
: Returns all sim hits matched to a xAOD::MuonSegment
const xAOD::MuonSimHit * getTruthMatchedHit(const xAOD::MuonMeasurement &prdHit)
Returns the MuonSimHit, if there's any, matched to the uncalibrated muon measurement.
DataVector< SpacePointBucket > SpacePointContainer
Abrivation of the space point container type.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
MdtDriftCircle_v1 MdtDriftCircle
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
Definition MuonSimHit.h:12
TgcStrip_v1 TgcStrip
Definition TgcStripFwd.h:9
TruthParticle_v1 TruthParticle
Typedef to implementation.
UncalibMeasType
Define the type of the uncalibrated measurement.
RpcMeasurement_v1 RpcMeasurement
MMCluster_v1 MMCluster
sTgcMeasurement_v1 sTgcMeasurement
MuonSegment_v1 MuonSegment
Reference the current persistent version: