ATLAS Offline Software
Loading...
Searching...
No Matches
SegmentFitParDecorAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
5
14
15namespace {
16 std::string print(const xAOD::MuonMeasurementContainer& container) {
17 if (container.empty()) {
18 return "empty container";
19 }
20 const Muon::IMuonIdHelperSvc* idHelperSvc = container.at(0)->readoutElement()->idHelperSvc();
21 std::stringstream sstr{};
22 for (const xAOD::MuonMeasurement* m : container) {
23 sstr<<" --- "<<idHelperSvc->toString(m->identify())<<", hash: "<<m->identifierHash()<<", dim:"<<m->numDimensions()<<std::endl;
24 }
25 return sstr.str();
26 }
27}
28
29
30namespace MuonR4 {
31 using namespace SegmentFit;
32 using SegPars = xAOD::MeasVector<Acts::toUnderlying(ParamDefs::nPars)>;
33
35 ATH_CHECK(m_idHelperSvc.retrieve());
36 ATH_CHECK(m_geoCtxKey.initialize());
37 ATH_CHECK(detStore()->retrieve(m_detMgr));
38 ATH_CHECK(m_segmentKey.initialize());
39 ATH_CHECK(m_locParKey.initialize());
40 ATH_CHECK(m_prdLinkKey.initialize());
41 ATH_CHECK(m_keyTgc.initialize(!m_keyTgc.empty()));
42 ATH_CHECK(m_keyRpc.initialize(!m_keyRpc.empty()));
43 ATH_CHECK(m_keyMdt.initialize(!m_keyMdt.empty()));
44 ATH_CHECK(m_keysTgc.initialize(!m_keysTgc.empty()));
45 ATH_CHECK(m_keyMM.initialize(!m_keyMM.empty()));
46 return StatusCode::SUCCESS;
47 }
50 switch (idx) {
51 using enum TechIdx_t;
52 case MDT: return m_keyMdt;
53 case RPC: return m_keyRpc;
54 case TGC: return m_keyTgc;
55 case MM: return m_keyMM;
56 case STGC: return m_keysTgc;
57 default:
58 THROW_EXCEPTION("Invalid technology index "<<idx);
59 }
60 return m_keyMdt;
61 }
62
63 StatusCode SegmentFitParDecorAlg::execute(const EventContext& ctx) const {
64 const xAOD::MuonSegmentContainer* segmentContainer{nullptr};
65 const ActsTrk::GeometryContext* gctx{nullptr};
66
67 ATH_CHECK(SG::get(segmentContainer, m_segmentKey, ctx));
68 ATH_CHECK(SG::get(gctx, m_geoCtxKey, ctx));
69
72 for (const xAOD::MuonSegment* seg : *segmentContainer) {
73 PrdLinkVec& prdLinks{prdLinkDecor(*seg)};
74 const Trk::Segment* trkSeg{*seg->muonSegment()};
75
76 std::array<std::vector<Identifier>, toInt(TechIdx_t::TechnologyIndexMax)> idsPerTech{};
78 auto appendId = [&] (const Identifier& id) {
79 idsPerTech[toInt(m_idHelperSvc->technologyIndex(id))].push_back(id);
80 };
81 for (const Trk::MeasurementBase* meas : trkSeg->containedMeasurements()) {
82 if (const auto* rot = dynamic_cast<const Trk::RIO_OnTrack*>(meas)) {
83 appendId(rot->identify());
84 } else if (const auto* cRot = dynamic_cast<const Trk::CompetingRIOsOnTrack*>(meas)){
85 for (unsigned int r = 0 ; r < cRot->numberOfContainedROTs(); ++r){
86 appendId(cRot->rioOnTrack(r).identify());
87 }
88 }
89 }
90 for (std::vector<Identifier>& ids : idsPerTech) {
91 if (ids.empty()) {
92 continue;
93 }
94 std::ranges::sort(ids,[this](const Identifier& a, const Identifier& b){
95 return m_idHelperSvc->detElementHash(a) < m_idHelperSvc->detElementHash(b);
96 });
97 const MeasKey_t& key = fetchKey(m_idHelperSvc->technologyIndex(ids.front()));
98 if (key.empty()) {
99 ATH_MSG_ERROR(__func__<<"() "<<__LINE__<<" - The key for technology "
100 <<m_idHelperSvc->technologyIndex(ids.front())<<" is empty.");
101 return StatusCode::FAILURE;
102 }
103 const xAOD::MuonMeasurementContainer* container{nullptr};
104 ATH_CHECK(SG::get(container, key, ctx));
105 ATH_MSG_VERBOSE("Retrieve container "<<container->size()<<"\n\n"<<print(*container));
106 xAOD::ChamberViewer viewer{*container};
107 if (!viewer.loadView(m_idHelperSvc->detElementHash(ids.front()))){
108 ATH_MSG_ERROR(__func__<<"() "<<__LINE__<<" - Cannot find a xAOD view for "
109 <<m_idHelperSvc->toStringDetEl(ids.front())<<"\n\n"<<print(*container));
110 return StatusCode::FAILURE;
111 }
112 for (const Identifier& id : ids) {
113 const IdentifierHash dHash = m_idHelperSvc->detElementHash(id);
114 ATH_MSG_VERBOSE(__func__<<"() "<<__LINE__<<" - Search for view "
115 <<m_idHelperSvc->toStringDetEl(id)<<", hash: "<<dHash);
116 while(viewer.at(0)->identifierHash() != dHash) {
117 if (!viewer.next()) {
118 if (viewer.loadView(dHash)) {
119 ATH_MSG_WARNING(__func__<<"() "<<__LINE__<<" - Container is not sorted "
120 <<m_idHelperSvc->toStringDetEl(id)<<".");
121 break;
122 }
123 ATH_MSG_ERROR(__func__<<"() "<<__LINE__<<" - Cannot find a xAOD view for "
124 <<m_idHelperSvc->toStringDetEl(id)<<"\n\n"<<print(*container));
125 return StatusCode::FAILURE;
126 }
127 }
128 const auto itr = std::ranges::find_if(viewer,[&id](const xAOD::MuonMeasurement* meas){
129 return meas->identify() == id;
130 });
131 if (itr == viewer.end()) {
132 ATH_MSG_ERROR(__func__<<"() "<<__LINE__<<" - Cannot find measurement "<<m_idHelperSvc->toString(id)
133 <<"\n\n"<<print(*container));
134 return StatusCode::FAILURE;
135 }
136 const auto* m{*itr};
137 prdLinks.emplace_back(container, m->index());
138 }
139 }
140 const MuonGMR4::SpectrometerSector* chamber = m_detMgr->getSectorEnvelope(seg->chamberIndex(),
141 seg->sector(),
142 seg->etaIndex());
143 const Amg::Transform3D globToLoc{chamber->globalToLocalTransform(*gctx)};
144
145 SegPars& locPars{parDecor(*seg)};
146
147 const Amg::Vector3D locDir = globToLoc.linear() * seg->direction();
148 const Amg::Vector3D locPos = globToLoc * seg->position();
149
150 const double travDist = Amg::intersect<3>(locPos, locDir, Amg::Vector3D::UnitZ(), 0).value_or(0);
151 const Amg::Vector3D atCentre = locPos + travDist * locDir;
152
153 locPars[Acts::toUnderlying(ParamDefs::x0)] = atCentre.x();
154 locPars[Acts::toUnderlying(ParamDefs::y0)] = atCentre.y();
155 locPars[Acts::toUnderlying(ParamDefs::theta)] = locDir.theta();
156 locPars[Acts::toUnderlying(ParamDefs::phi)] = locDir.phi();
157 ATH_MSG_VERBOSE("Segment "<<chamber->identString()<<" at chamber centre "<<Amg::toString(atCentre)
158 <<" + x *"<<Amg::toString(locDir));
159 }
160 return StatusCode::SUCCESS;
161 }
162}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
static Double_t a
@ STGC
Definition RegSelEnums.h:39
@ MM
Definition RegSelEnums.h:38
@ RPC
Definition RegSelEnums.h:32
@ MDT
Definition RegSelEnums.h:31
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
void print(char *figname, TCanvas *c1)
const ServiceHandle< StoreGateSvc > & detStore() const
This is a "hash" representation of an Identifier.
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
SG::WriteDecorHandleKey< xAOD::MuonSegmentContainer > m_prdLinkKey
Decoration key of the associated prep data objects.
const MeasKey_t & fetchKey(const TechIdx_t idx) const
Fetch the read handle key to the Muon measurement container.
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
Muon::MuonStationIndex::TechnologyIndex TechIdx_t
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
virtual std::string toString(const Identifier &id) const =0
print all fields to string
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
const_iterator end() const noexcept
End iterator of the current chamber view.
const_ref at(const std::size_t idx) const
Returns the i-the measurement from the current chamber.
bool loadView(const Identifier &chamberId)
Loads the view matching the parsed identifier.
bool next()
Loads the hits from the next chamber.
const Identifier & identify() const
Returns the Athena identifier of the measurement.
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.
std::string print(const cont_t &container)
Print a space point container to string.
xAOD::MeasVector< Acts::toUnderlying(ParamDefs::nPars)> SegPars
constexpr int toInt(const EnumType enumVal)
const SG::AuxVectorData * container() const
Return the container holding this element.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition TgcBase.h:6
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".
Eigen::Matrix< float, N, 1 > MeasVector
Abrivation of the Matrix & Covariance definitions.
MuonMeasurement_v1 MuonMeasurement
MuonSegment_v1 MuonSegment
Reference the current persistent version:
MuonMeasurementContainer_v1 MuonMeasurementContainer
#define THROW_EXCEPTION(MESSAGE)
Definition throwExcept.h:10