ATLAS Offline Software
Loading...
Searching...
No Matches
MuonR4::TruthTrackSeederTool Class Reference

The TruthTrackSeederTool combines the Segments based on their common truthParticleLink. More...

#include <TruthTrackSeederTool.h>

Inheritance diagram for MuonR4::TruthTrackSeederTool:
Collaboration diagram for MuonR4::TruthTrackSeederTool:

Public Member Functions

virtual StatusCode initialize () override final
virtual StatusCode findTrackSeeds (const EventContext &ctx, std::vector< MsTrackSeed > &outSeeds) const override final
 Retrieves the segment container from StoreGate and constructs TrackSeeds from them.
virtual Acts::Result< Acts::BoundTrackParameters > estimateStartParameters (const EventContext &ctx, const MsTrackSeed &seed) const override final
 Estimate the start track parameters for a given track seed.

Private Attributes

SG::ReadHandleKey< xAOD::MuonSegmentContainer > m_segmentKey {this, "SegmentContainer", "MuonSegmentsFromR4" }
 Declare the data dependency on the standard Mdt+Rpc+Tgc segment container & on the NSW segment container.
SG::ReadDecorHandleKey< xAOD::MuonSegmentContainer > m_truthLinkKey {this, "TruthLinkKey", m_segmentKey, "truthParticleLink"}
 Dependency on the truth particle link.
MuonGMR4::MuonDetectorManager * m_detMgr {nullptr}
 Instance to the muon detector manager.
ActsTrk::ContextUtility m_ctxProvider {this}
 Context utility to retrieve the geometry context.

Detailed Description

The TruthTrackSeederTool combines the Segments based on their common truthParticleLink.

If multiple segments in the same chamber share the truthParticle, then the one which has the most amount of hits is chosen The initial track parameters are predicted from the closest truth segment along the trajectory. The tool only works on MC and is also entirely meant to evaluate the performance of the global chi2 fitter.

Definition at line 28 of file TruthTrackSeederTool.h.

Member Function Documentation

◆ estimateStartParameters()

Acts::Result< Acts::BoundTrackParameters > MuonR4::TruthTrackSeederTool::estimateStartParameters ( const EventContext & ctx,
const MsTrackSeed & seed ) const
finaloverridevirtual

Estimate the start track parameters for a given track seed.

Parameters
ctxEventContext
seedThe track seed for which to estimate start parameters
Returns
The estimated start parameters or an error

Get the first two segments

Definition at line 77 of file TruthTrackSeederTool.cxx.

78 {
79
80 const Acts::GeometryContext tgContext{m_ctxProvider.getGeometryContext(ctx)};
82 const xAOD::MuonSegment* firstSeg = seed.segments().front();
83 const xAOD::MuonSegment* secondSeg = seed.segments()[1];
84 // If both segments are on the same station (BI) check whether the order needs to be swapped
87 const xAOD::MuonSegment* truthSeg = getMatchedTruthSegment(*firstSeg);
88 if (!truthSeg) {
89 ATH_MSG_WARNING(__func__<<"() "<<__LINE__<<" - No truth segment found");
90 return Acts::Result<Acts::BoundTrackParameters>::failure(std::make_error_code(std::errc::invalid_argument));
91 }
92 const Acts::Surface& firstSurf{xAOD::muonSurface(firstMeasurement(*firstSeg, false))};
93 const Acts::Surface& secondSurf{xAOD::muonSurface(firstMeasurement(*secondSeg, false))};
94 const double distA = firstSurf.intersect(tgContext, truthSeg->position(), truthSeg->direction()).closest().pathLength();
95 const double distB = secondSurf.intersect(tgContext, truthSeg->position(), truthSeg->direction()).closest().pathLength();
96 ATH_MSG_VERBOSE(__func__<<" "<<__LINE__<<" - Detected segments in sector overlap "
97 <<printID(*firstSeg)<<" & "<<printID(*secondSeg)
98 <<". Check whether they need to be swapped "<<distA<<" vs. "<<distB);
99 if (distA> distB) {
100 std::swap(firstSeg, secondSeg);
101 }
102 }
103 const xAOD::MuonSegment* truthSeg = getMatchedTruthSegment(*firstSeg);
104 if (!truthSeg) {
105 ATH_MSG_WARNING(__func__<<"() "<<__LINE__<<" - No truth segment found");
106 return Acts::Result<Acts::BoundTrackParameters>::failure(std::make_error_code(std::errc::invalid_argument));
107 }
108 const xAOD::TruthParticle* truthPart = getTruthMatchedParticle(*truthSeg);
109 if (!truthPart) {
110 ATH_MSG_WARNING(__func__<<"() "<<__LINE__<<" - No truth particle found");
111 return Acts::Result<Acts::BoundTrackParameters>::failure(std::make_error_code(std::errc::invalid_argument));
112 }
113 const MuonGMR4::SpectrometerSector* msSector{m_detMgr->getSectorEnvelope(truthSeg->chamberIndex(),
114 truthSeg->sector(),
115 truthSeg->etaIndex())};
116 const Acts::Surface& sectorSurf{msSector->surface()};
117 const Amg::Vector3D firstPos{atFirstSurface(tgContext, *firstSeg, false)};
118 ATH_MSG_VERBOSE(__func__<<"() "<<__LINE__<<" - First measurement "
119 <<msSector->idHelperSvc()->toString(xAOD::identify(firstMeasurement(*firstSeg, false)))
120 <<", position: "<<Amg::toString(firstPos));
121
122 const Amg::Transform3D& oldTrf{sectorSurf.localToGlobalTransform(tgContext)};
123 const Amg::Vector3D segDir = truthSeg->direction();
124 const Amg::Vector3D locDir = oldTrf.inverse().linear() * segDir;
125 const double pathLength = std::abs((truthSeg->position() - firstPos).dot(segDir)) + 10._cm;
126
127 const Amg::Transform3D newTrf{oldTrf * Amg::getTranslate3D(-pathLength * locDir)};
128 ATH_MSG_VERBOSE(__func__<<"() "<<__LINE__<<" - Create new surface in front of "<<msSector->identString()
129 <<", "<<Amg::toString(newTrf));
130 auto shiftedSurf = Acts::Surface::makeShared<Acts::PlaneSurface>(newTrf);
131
132 Acts::BoundVector locPars = SegmentFit::boundSegmentPars(tgContext, *m_detMgr, *truthSeg).parameters();
133 static const SG::ConstAccessor<float> acc_pt{"pt"};
134 locPars[Acts::eBoundQOverP] = truthPart->charge() / ActsTrk::energyToActs(acc_pt(*truthSeg) * std::cosh(truthPart->eta()));
135 Acts::BoundTrackParameters result{shiftedSurf, locPars,
136 Acts::BoundMatrix::Identity(),
137 Acts::ParticleHypothesis::muon()};
138 using namespace Acts::detail::LineHelper;
139 if (msgLvl(MSG::VERBOSE)) {
140 std::stringstream outStream{};
141 outStream<<"Start parameters:\n"<<result<<",\n"
142 <<result.referenceSurface().toString(tgContext)
143 <<"absolute momentum: "
144 <<result.absoluteMomentum()<<"/"<<ActsTrk::energyToActs(truthPart->pt()* std::cosh(truthPart->eta()))
145 <<", start point closure: "<<(result.position(tgContext) + pathLength * segDir - truthSeg->position()).mag()
146 <<", angle closure: "<<Amg::angle(result.direction(), segDir) / 1._degree
147 <<"\n\ndump measurements:\n";
148
149 for (const xAOD::MuonSegment* segment : seed.segments()) {
150 outStream<<" - Segment "<<printID(*segment)<<" @ "<<Amg::toString(segment->position())<<"+"
151 <<Amg::toString(segment->direction())<<std::endl;
152 for (unsigned int m = 0; m < nMeasurements(*segment); ++m) {
153 const xAOD::UncalibratedMeasurement* meas = getMeasurement(*segment, m);
154 if (meas->type() == xAOD::UncalibMeasType::Other) {
155 continue;
156 }
157 const auto* mMeas = static_cast<const xAOD::MuonMeasurement*>(meas);
158 const Acts::Surface& surf{xAOD::muonSurface(meas)};
159 const double dist{surf.intersect(tgContext, result.position(tgContext), segDir,
160 Acts::BoundaryTolerance::Infinite()).closest().pathLength()};
161 outStream<<" *** "<<m_detMgr->idHelperSvc()->toString(mMeas->identify())
162 <<" @ "<<Amg::toString(surf.localToGlobalTransform(tgContext) * mMeas->localMeasurementPos())
163 <<", center: "<<Amg::toString(surf.center(tgContext))
164 <<", travelled distance: "<<dist<<std::endl;
165 }
166 }
167 ATH_MSG_VERBOSE(__func__<<"() "<<__LINE__<<" - Created start parameters:\n"<<outStream.str());
168 }
169 return result;
170 }
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
const Muon::IMuonIdHelperSvc * idHelperSvc() const
Returns the IdHelpeSvc.
std::string identString() const
Returns a string encoding the chamber index & the sector of the MS sector.
const Acts::PlaneSurface & surface() const
Returns the associated surface.
ActsTrk::ContextUtility m_ctxProvider
Context utility to retrieve the geometry context.
MuonGMR4::MuonDetectorManager * m_detMgr
Instance to the muon detector manager.
virtual std::string toString(const Identifier &id) const =0
print all fields to string
Amg::Vector3D direction() const
Returns the direction as Amg::Vector.
::Muon::MuonStationIndex::ChIndex chamberIndex() const
Returns the chamber index.
Amg::Vector3D position() const
Returns the position as Amg::Vector.
int etaIndex() const
Returns the eta index, which corresponds to stationEta in the offline identifiers (and the ).
virtual double pt() const override final
The transverse momentum ( ) of the particle.
double charge() const
Physical charge.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
virtual xAOD::UncalibMeasType type() const =0
Returns the type of the measurement type as a simple enumeration.
constexpr double energyToActs(const double athenaE)
Converts an energy scalar from Athena to Acts units.
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
double angle(const Amg::Vector3D &v1, const Amg::Vector3D &v2)
calculates the opening angle between two vectors
Amg::Isometry3D getTranslate3D(const double X, const double Y, const double Z)
: Returns a shift transformation along an arbitrary axis
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
Acts::BoundTrackParameters boundSegmentPars(const ActsTrk::GeometryContext &gctx, const MuonGMR4::MuonDetectorManager &detMgr, const xAOD::MuonSegment &segment, const Acts::ParticleHypothesis hypot=Acts::ParticleHypothesis::muon())
Returns the segment parameters as boundTrackParameters.
const xAOD::TruthParticle * getTruthMatchedParticle(const xAOD::MuonSegment &segment)
Returns the particle truth-matched to the segment.
std::string printID(const xAOD::MuonSegment &seg)
Print the chamber ID of a segment, e.g.
const xAOD::UncalibratedMeasurement * getMeasurement(const xAOD::MuonSegment &segment, const std::size_t n)
Returns the n-th uncalibrated measurement.
std::size_t nMeasurements(const xAOD::MuonSegment &segment)
Returns the number of associated Uncalibrated measurements.
const xAOD::UncalibratedMeasurement * firstMeasurement(const xAOD::MuonSegment &segment, const bool skipOutlier=true)
Retrieves the first measurement associated with the segment.
const xAOD::MuonSegment * getMatchedTruthSegment(const xAOD::MuonSegment &segment)
Returns the truth-matched segment.
Amg::Vector3D atFirstSurface(const Acts::GeometryContext &gctx, const xAOD::MuonSegment &segment, const bool skipOutlier=true)
Expresses the segment position on the surface of the first measurement.
StIndex toStationIndex(ChIndex index)
convert ChIndex into StIndex
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.
MuonMeasurement_v1 MuonMeasurement
TruthParticle_v1 TruthParticle
Typedef to implementation.
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.
MuonSegment_v1 MuonSegment
Reference the current persistent version:
const Acts::Surface & muonSurface(const UncalibratedMeasurement *meas)
Returns the associated Acts surface to the measurement.

◆ findTrackSeeds()

StatusCode MuonR4::TruthTrackSeederTool::findTrackSeeds ( const EventContext & ctx,
std::vector< MsTrackSeed > & outSeeds ) const
finaloverridevirtual

Retrieves the segment container from StoreGate and constructs TrackSeeds from them.

The seed canddiates are pushed to the output seed container

Parameters
ctxEventContext to access the xAOD::MuonSegmentContainer from store gate and additional conditions data if needed to construct the seed
outSeedsMutable reference to the container to whichh the seeds are pushed to.

Fill the truth seed map

Remove duplicate segments on the same station

Definition at line 39 of file TruthTrackSeederTool.cxx.

40 {
41 const xAOD::MuonSegmentContainer* segments{nullptr};
42 ATH_CHECK(SG::get(segments, m_segmentKey, ctx));
43 std::unordered_map<const xAOD::TruthParticle*, std::vector<const xAOD::MuonSegment*>> truthSeeds{};
45 for (const xAOD::MuonSegment* seg : *segments) {
46 const xAOD::TruthParticle* truthPart = getTruthMatchedParticle(*seg);
47 if (truthPart && truthPart->isMuon()) {
48 truthSeeds[truthPart].push_back(seg);
49 }
50 }
51 for (auto& [truthPart, assocSegs] : truthSeeds) {
52 std::ranges::sort(assocSegs, [](const xAOD::MuonSegment* a, const xAOD::MuonSegment* b){
53 if (a->chamberIndex() != b->chamberIndex()) {
54 return a->chamberIndex() < b->chamberIndex();
55 }
56 return countHits(*a) > countHits(*b);
57 });
59 auto [begin, end] = std::ranges::unique(assocSegs, [](const xAOD::MuonSegment* a, const xAOD::MuonSegment* b){
60 return a->chamberIndex() == b->chamberIndex();
61 });
62 assocSegs.erase(begin,end);
63 if (assocSegs.size() < 2) {
64 continue;
65 }
66 MsTrackSeed& seed = outSeeds.emplace_back(MsTrackSeed::Location::Barrel,
67 ExpandedSector{truthPart->phi()});
68 std::ranges::for_each(assocSegs, [&seed](const xAOD::MuonSegment* seg) {
69 seed.addSegment(seg);
70 });
71 }
72
73 return StatusCode::SUCCESS;
74 }
#define ATH_CHECK
Evaluate an expression and check for errors.
static Double_t a
SG::ReadHandleKey< xAOD::MuonSegmentContainer > m_segmentKey
Declare the data dependency on the standard Mdt+Rpc+Tgc segment container & on the NSW segment contai...
virtual double phi() const override final
The azimuthal angle ( ) of the particle.
bool isMuon() const
Whether the particle is a muon (or antimuon).
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".

◆ initialize()

StatusCode MuonR4::TruthTrackSeederTool::initialize ( )
finaloverridevirtual


Definition at line 32 of file TruthTrackSeederTool.cxx.

32 {
33 ATH_CHECK(m_segmentKey.initialize());
34 ATH_CHECK(m_truthLinkKey.initialize());
35 ATH_CHECK(detStore()->retrieve(m_detMgr));
36 ATH_CHECK(m_ctxProvider.initialize());
37 return StatusCode::SUCCESS;
38 }
SG::ReadDecorHandleKey< xAOD::MuonSegmentContainer > m_truthLinkKey
Dependency on the truth particle link.

Member Data Documentation

◆ m_ctxProvider

ActsTrk::ContextUtility MuonR4::TruthTrackSeederTool::m_ctxProvider {this}
private

Context utility to retrieve the geometry context.

Definition at line 50 of file TruthTrackSeederTool.h.

50{this};

◆ m_detMgr

MuonGMR4::MuonDetectorManager* MuonR4::TruthTrackSeederTool::m_detMgr {nullptr}
private

Instance to the muon detector manager.

Definition at line 48 of file TruthTrackSeederTool.h.

48{nullptr};

◆ m_segmentKey

SG::ReadHandleKey<xAOD::MuonSegmentContainer> MuonR4::TruthTrackSeederTool::m_segmentKey {this, "SegmentContainer", "MuonSegmentsFromR4" }
private

Declare the data dependency on the standard Mdt+Rpc+Tgc segment container & on the NSW segment container.

Definition at line 44 of file TruthTrackSeederTool.h.

44{this, "SegmentContainer", "MuonSegmentsFromR4" };

◆ m_truthLinkKey

SG::ReadDecorHandleKey<xAOD::MuonSegmentContainer> MuonR4::TruthTrackSeederTool::m_truthLinkKey {this, "TruthLinkKey", m_segmentKey, "truthParticleLink"}
private

Dependency on the truth particle link.

Definition at line 46 of file TruthTrackSeederTool.h.

46{this, "TruthLinkKey", m_segmentKey, "truthParticleLink"};

The documentation for this class was generated from the following files: