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 }
36 const EventContext& ctx{Gaudi::Hive::currentContext()};
37 const ActsTrk::GeometryContext* gctx{};
38 ATH_CHECK(SG::get(gctx, m_geoCtxKey, ctx));
39
40 std::unordered_map<const xAOD::MuonSimHit*, const xAOD::TruthParticle*> hitPartMap{};
41 const xAOD::MuonSegmentContainer* truthSegs{nullptr};
42 ATH_CHECK(SG::get(truthSegs, m_truthSegKey, ctx));
43 for (const xAOD::MuonSegment* segment : *truthSegs) {
44 const xAOD::TruthParticle* truthPart = getTruthMatchedParticle(*segment);
45 for (const xAOD::MuonSimHit* hit : getMatchingSimHits(*segment)) {
46 hitPartMap[hit] = truthPart;
47 }
48 }
49
51 const SpacePointContainer* spCont{nullptr};
52 ATH_CHECK(SG::get(spCont,key, ctx));
53 for (const SpacePointBucket* bucket : *spCont) {
54 m_spCollection->push_back(*bucket);
55 for (const auto& sp : *bucket) {
56 const xAOD::MuonSimHit* simHit = getTruthMatchedHit(*sp->primaryMeasurement());
57 m_muonP4->push_back(hitPartMap[simHit]);
58 m_truthLink[fillSpacePoint(*gctx, *sp)] = m_muonP4->find(hitPartMap[simHit]);
59 }
60 }
61 }
62 ATH_CHECK(m_tree.fill(ctx));
63
64 return StatusCode::SUCCESS;
65 }
67 const Amg::Transform3D& lToGlob = sp.msSector()->localToGlobalTrans(gctx);
68 std::size_t idx = m_spCollection->push_back(sp);
69 m_spGlobPos.set(lToGlob * sp.localPosition(), idx);
70
71 switch (sp.type()) {
72 using enum xAOD::UncalibMeasType;
73 case MdtDriftCircleType:{
74 const auto* prd = static_cast<const xAOD::MdtDriftCircle*>(sp.primaryMeasurement());
75 const auto* re = prd->readoutElement();
76 m_spGlobEdgeLow.set(re->readOutPos(gctx, prd->measurementHash()), idx);
77 m_spGlobEdgeHigh.set(re->highVoltPos(gctx, prd->measurementHash()), idx);
78 m_spReadoutSide[idx] = re->getParameters().readoutSide;
79 m_spTime[idx] = prd->tdc();
80 break;
81 }
82 case RpcStripType: {
83 const auto* prd = static_cast<const xAOD::RpcMeasurement*>(sp.primaryMeasurement());
84 const auto* re = prd->readoutElement();
85 m_spGlobEdgeLow.set(re->rightStripEdge(gctx, prd->measurementHash()), idx);
86 m_spGlobEdgeHigh.set(re->leftStripEdge(gctx, prd->measurementHash()), idx);
87 m_spReadoutSide[idx] = 1.;
88 m_spTime[idx] = prd->time();
89 break;
90 }
91 case TgcStripType: {
92 const auto* prd = static_cast<const xAOD::TgcStrip*>(sp.primaryMeasurement());
93 const auto* re = prd->readoutElement();
94 const MuonGMR4::StripDesign& design = re->sensorLayout(prd->layerHash())->design();
95 const double halfLength = design.stripLength(prd->channelNumber());
96 m_spReadoutSide[idx] = 1.;
97 m_spGlobEdgeLow.set( lToGlob*(sp.localPosition() -halfLength * sp.sensorDirection()) , idx);
98 m_spGlobEdgeHigh.set(lToGlob*(sp.localPosition() +halfLength * sp.sensorDirection()) , idx);
99 m_spTime[idx] = prd->bcBitMap();
100 break;
101 }
102 case MMClusterType: {
103 const auto* prd = static_cast<const xAOD::MMCluster*>(sp.primaryMeasurement());
104 const auto* re = prd->readoutElement();
105 m_spGlobEdgeLow.set(re->rightStripEdge(gctx, prd->measurementHash()), idx);
106 m_spGlobEdgeHigh.set(re->leftStripEdge(gctx, prd->measurementHash()), idx);
107 m_spReadoutSide[idx] = re->readoutSide(prd->measurementHash());
108 m_spTime[idx] = prd->time();
109 break;
110 }
111 case sTgcStripType: {
112 const auto* prd = static_cast<const xAOD::sTgcMeasurement*>(sp.primaryMeasurement());
113 const auto* re = prd->readoutElement();
114 m_spReadoutSide[idx] = 1.;
115 m_spTime[idx] = prd->time();
116 switch (prd->channelType()) {
118 case Pad:{
119 double xLow{std::numeric_limits<double>::max()},
120 xHigh{-std::numeric_limits<double>::max()},
121 yLow{std::numeric_limits<double>::max()},
122 yHigh{-std::numeric_limits<double>::max()};
123 for (const Amg::Vector2D& corner : re->localPadCorners(prd->measurementHash())) {
124 xLow = std::min(xLow, corner.x());
125 yLow = std::min(yLow, corner.y());
126 xHigh = std::max(xHigh, corner.x());
127 yHigh = std::max(yHigh, corner.y());
128 }
129 const Amg::Transform3D& padTrf{re->localToGlobalTrans(gctx, prd->layerHash())};
130 m_spGlobEdgeLow.set(padTrf * Amg::Vector3D{xLow,yLow, 0.}, idx);
131 m_spGlobEdgeHigh.set(padTrf * Amg::Vector3D{xHigh,yHigh, 0.}, idx);
132 break;
133 }
134 case Strip:
135 case Wire: {
136 const double halfLength = 0.5* re->stripLength(prd->measurementHash());
137 m_spGlobEdgeLow.set( lToGlob*(sp.localPosition() -halfLength * sp.sensorDirection()) , idx);
138 m_spGlobEdgeHigh.set(lToGlob*(sp.localPosition() +halfLength * sp.sensorDirection()) , idx);
139 break;
140 }
141 }
142 break;
143 }
144 default: break;
145 }
146 return idx;
147 }
149 ATH_CHECK(m_tree.write());
150 return StatusCode::SUCCESS;
151 }
152}
const boost::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
virtual StatusCode execute() override final
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 finalize() override final
virtual StatusCode initialize() override final
MuonVal::ThreeVectorBranch m_spGlobPos
MuonVal::ThreeVectorBranch m_spGlobEdgeHigh
SG::ReadHandleKey< ActsTrk::GeometryContext > m_geoCtxKey
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.
const xAOD::MuonSimHit * getTruthMatchedHit(const xAOD::UncalibratedMeasurement &prdHit)
Returns the MuonSimHit, if there's any, matched to the uncalibrated muon measurement.
std::unordered_set< const xAOD::MuonSimHit * > getMatchingSimHits(const xAOD::MuonSegment &segment)
: Returns all sim hits matched to a xAOD::MuonSegment
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: