ATLAS Offline Software
Loading...
Searching...
No Matches
SegmentFitParDecorAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
5
13namespace MuonR4 {
14 using namespace SegmentFit;
15 using SegPars = xAOD::MeasVector<Acts::toUnderlying(ParamDefs::nPars)>;
17
19 ATH_CHECK(m_idHelperSvc.retrieve());
20 ATH_CHECK(m_geoCtxKey.initialize());
21 ATH_CHECK(detStore()->retrieve(m_detMgr));
22 ATH_CHECK(m_segmentKey.initialize());
23 ATH_CHECK(m_locParKey.initialize());
24 ATH_CHECK(m_prdLinkKey.initialize());
25 ATH_CHECK(m_keyTgc.initialize(!m_keyTgc.empty()));
26 ATH_CHECK(m_keyRpc.initialize(!m_keyRpc.empty()));
27 ATH_CHECK(m_keyMdt.initialize(!m_keyMdt.empty()));
28 ATH_CHECK(m_keysTgc.initialize(!m_keysTgc.empty()));
29 ATH_CHECK(m_keyMM.initialize(!m_keyMM.empty()));
30 return StatusCode::SUCCESS;
31 }
32 StatusCode SegmentFitParDecorAlg::fetchMeasurement(const EventContext& ctx,
33 const MeasKey_t& key,
34 const Identifier& measId,
35 const xAOD::UncalibratedMeasurement*& meas) const {
36 const PrdCont_t* cont{nullptr};
37 ATH_CHECK(SG::get(cont, key, ctx));
38 if (!cont) {
39 ATH_MSG_VERBOSE("No container key given");
40 return StatusCode::SUCCESS;
41 }
42 for (const xAOD::UncalibratedMeasurement* inCont : *cont) {
43 if (xAOD::identify(inCont) == measId) {
44 meas = inCont;
45 break;
46 }
47 }
48 if (!meas) {
49 ATH_MSG_WARNING("Failed to find the hit "<<m_idHelperSvc->toString(measId));
50 }
51 return StatusCode::SUCCESS;
52 }
53 StatusCode SegmentFitParDecorAlg::addLink(const EventContext& ctx,
54 const Identifier& rotId,
55 PrdLinkVec& prdLinks) const {
56 const xAOD::UncalibratedMeasurement* prd{nullptr};
57 switch(m_idHelperSvc->technologyIndex(rotId)){
58 case TechIdx_t::MDT:
59 ATH_CHECK(fetchMeasurement(ctx, m_keyMdt, rotId, prd));
60 break;
61 case TechIdx_t::RPC:
62 ATH_CHECK(fetchMeasurement(ctx, m_keyRpc, rotId, prd));
63 break;
64 case TechIdx_t::TGC:
65 ATH_CHECK(fetchMeasurement(ctx, m_keyTgc, rotId, prd));
66 break;
67 case TechIdx_t::MM:
68 ATH_CHECK(fetchMeasurement(ctx, m_keyMM, rotId, prd));
69 break;
70 case TechIdx_t::STGC:
71 ATH_CHECK(fetchMeasurement(ctx, m_keysTgc, rotId, prd));
72 break;
73 default:
74 break;
75 };
76 if (!prd) {
77 return StatusCode::SUCCESS;
78 }
79 ATH_MSG_VERBOSE("Link new measurement "<<m_idHelperSvc->toString(rotId));
80 PrdLink_t link{*static_cast<const PrdCont_t*>(prd->container()),
81 prd->index()};
82 prdLinks.push_back(std::move(link));
83 return StatusCode::SUCCESS;
84 }
85
86
87 StatusCode SegmentFitParDecorAlg::execute(const EventContext& ctx) const {
88 const xAOD::MuonSegmentContainer* segmentContainer{nullptr};
89 const ActsTrk::GeometryContext* gctx{nullptr};
90
91 ATH_CHECK(SG::get(segmentContainer, m_segmentKey, ctx));
92 ATH_CHECK(SG::get(gctx, m_geoCtxKey, ctx));
93
96 for (const xAOD::MuonSegment* seg : *segmentContainer) {
97 PrdLinkVec& prdLinks{prdLinkDecor(*seg)};
98 const Trk::Segment* trkSeg{*seg->muonSegment()};
99
100 for (const Trk::MeasurementBase* meas : trkSeg->containedMeasurements()) {
101 const auto* rot = dynamic_cast<const Trk::RIO_OnTrack*>(meas);
102 if (rot) {
103 ATH_CHECK(addLink(ctx, rot->identify(), prdLinks));
104 continue;
105 }
106 const auto* cRot = dynamic_cast<const Trk::CompetingRIOsOnTrack*>(meas);
107 if (cRot) {
108 for (unsigned int r = 0 ; r < cRot->numberOfContainedROTs(); ++r){
109 ATH_CHECK(addLink(ctx, cRot->rioOnTrack(r).identify(), prdLinks));
110 }
111 }
112 }
113 const MuonGMR4::SpectrometerSector* chamber = m_detMgr->getSectorEnvelope(xAOD::identify(*prdLinks.front()));
114 const Amg::Transform3D globToLoc{chamber->globalToLocalTrans(*gctx)};
115
116 SegPars& locPars{parDecor(*seg)};
117
118 const Amg::Vector3D locDir = globToLoc.linear() * seg->direction();
119 const Amg::Vector3D locPos = globToLoc * seg->position();
120
121 const double travDist = Amg::intersect<3>(locPos, locDir, Amg::Vector3D::UnitZ(), 0).value_or(0);
122 const Amg::Vector3D atCentre = locPos + travDist * locDir;
123
124 locPars[Acts::toUnderlying(ParamDefs::x0)] = atCentre.x();
125 locPars[Acts::toUnderlying(ParamDefs::y0)] = atCentre.y();
126 locPars[Acts::toUnderlying(ParamDefs::theta)] = locDir.theta();
127 locPars[Acts::toUnderlying(ParamDefs::phi)] = locDir.phi();
128 ATH_MSG_VERBOSE("Segment "<<chamber->identString()<<" at chamber centre "<<Amg::toString(atCentre)
129 <<" + x *"<<Amg::toString(locDir));
130 }
131 return StatusCode::SUCCESS;
132 }
133}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
const ServiceHandle< StoreGateSvc > & detStore() const
A spectrometer sector forms the envelope of all chambers that are placed in the same MS sector & laye...
virtual StatusCode execute(const EventContext &ctx) const override final
SG::ReadHandleKey< xAOD::MuonSegmentContainer > m_segmentKey
xAOD::UncalibratedMeasurementContainer PrdCont_t
StatusCode addLink(const EventContext &ctx, const Identifier &rotId, PrdLinkVec &prdLinks) const
Tries to add the Link to the uncalibrated measurement corresponding to the passed ROT id.
SG::WriteDecorHandleKey< xAOD::MuonSegmentContainer > m_prdLinkKey
Decoration key of the associated prep data objects.
SG::ReadHandleKey< PrdCont_t > MeasKey_t
SG::ReadHandleKey< ActsTrk::GeometryContext > m_geoCtxKey
const MuonGMR4::MuonDetectorManager * m_detMgr
virtual StatusCode initialize() override final
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
SG::WriteDecorHandleKey< xAOD::MuonSegmentContainer > m_locParKey
Decoration key of the local parameters.
std::vector< PrdLink_t > PrdLinkVec
ElementLink< PrdCont_t > PrdLink_t
StatusCode fetchMeasurement(const EventContext &ctx, const MeasKey_t &key, const Identifier &measId, const xAOD::UncalibratedMeasurement *&meas) const
Tries to load the PrdCont_t from StoreGate and then to find the uncalibrated measurement with the sam...
const SG::AuxVectorData * container() const
Return the container holding this element.
size_t index() const
Return the index of this element within its container.
Handle class for adding a decoration to an object.
Base class for all CompetingRIOsOnTack implementations, extends the common MeasurementBase.
This class is the pure abstract base class for all fittable tracking measurements.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Definition RIO_OnTrack.h:70
Base class for all TrackSegment implementations, extends the common MeasurementBase.
const std::vector< const Trk::MeasurementBase * > & containedMeasurements() const
returns the vector of Trk::MeasurementBase objects
int r
Definition globals.cxx:22
std::optional< double > intersect(const AmgVector(N)&posA, const AmgVector(N)&dirA, const AmgVector(N)&posB, const AmgVector(N)&dirB)
Calculates the point B' along the line B that's closest to a second line A.
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
This header ties the generic definitions in this package.
Muon::MuonStationIndex::TechnologyIndex TechIdx_t
xAOD::MeasVector< Acts::toUnderlying(ParamDefs::nPars)> SegPars
TechnologyIndex
enum to classify the different layers in the muon spectrometer
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".
Eigen::Matrix< float, N, 1 > MeasVector
Abrivation of the Matrix & Covariance definitions.
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.
MuonSegment_v1 MuonSegment
Reference the current persistent version:
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.