ATLAS Offline Software
Loading...
Searching...
No Matches
PatternCnvAlg.cxx
Go to the documentation of this file.
1
2/*
3 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4*/
5#include "PatternCnvAlg.h"
6
8
9namespace{
12 using LegacyMax = MuonHough::MuonLayerHough::Maximum;
13}
14
15namespace MuonR4{
16
18 ATH_CHECK(m_idHelperSvc.retrieve());
19
20 ATH_CHECK(m_keyTgc.initialize(!m_keyTgc.empty()));
21 ATH_CHECK(m_keyRpc.initialize(!m_keyRpc.empty()));
22 ATH_CHECK(m_keyMdt.initialize(!m_keyMdt.empty()));
23 ATH_CHECK(m_keysTgc.initialize(!m_keysTgc.empty()));
24 ATH_CHECK(m_keyMM.initialize(!m_keyMM.empty()));
25
26 ATH_CHECK(m_combiKey.initialize());
27 ATH_CHECK(m_dataPerSecKey.initialize());
28 ATH_CHECK(m_readKeys.initialize());
29 ATH_CHECK(m_geoCtxKey.initialize());
30 return StatusCode::SUCCESS;
31 }
32
33 StatusCode PatternCnvAlg::execute(const EventContext& ctx) const {
34
35
36 auto translatedPatterns = std::make_unique<MuonPatternCombinationCollection>();
37 auto translatedHough = std::make_unique<Muon::HoughDataPerSectorVec>();
38
40 const SegmentSeedContainer* translateMe{nullptr};
41 ATH_CHECK(SG::get(translateMe, key, ctx));
42 ATH_CHECK(convertSeed(ctx, *translateMe, * translatedPatterns, *translatedHough));
43
44 }
45
47 ATH_CHECK(patternHandle.record(std::move(translatedPatterns)));
48
50 ATH_CHECK(houghDataHandle.record(std::move(translatedHough)));
51
52
53 return StatusCode::SUCCESS;
54 }
55 StatusCode PatternCnvAlg::convertSeed(const EventContext& ctx,
56 const SegmentSeedContainer& seedContainer,
57 ::MuonPatternCombinationCollection& patternContainer,
58 Muon::HoughDataPerSectorVec& houghDataSec) const {
59
60 const Muon::RpcPrepDataContainer* rpcPrds{nullptr};
61 const Muon::MdtPrepDataContainer* mdtPrds{nullptr};
62 const Muon::TgcPrepDataContainer* tgcPrds{nullptr};
63 const Muon::sTgcPrepDataContainer* stgcPrds{nullptr};
64 const Muon::MMPrepDataContainer* mmPrds{nullptr};
65 ATH_CHECK(SG::get(mdtPrds, m_keyMdt, ctx));
66 ATH_CHECK(SG::get(rpcPrds, m_keyRpc, ctx));
67 ATH_CHECK(SG::get(tgcPrds, m_keyTgc, ctx));
68 ATH_CHECK(SG::get(stgcPrds, m_keysTgc, ctx));
69 ATH_CHECK(SG::get(mmPrds, m_keyMM, ctx));
70
71 const ActsTrk::GeometryContext* gctx{nullptr};
72 ATH_CHECK(SG::get(gctx, m_geoCtxKey, ctx));
73
74
75
76 for (const SegmentSeed* seed: seedContainer) {
77 const Amg::Transform3D& localToGlobal = seed->msSector()->localToGlobalTrans(*gctx);
78
79 std::unordered_set<Identifier> channelsInMax{};
80 for (const HoughHitType& hit : seed->getHitsInMax()) {
81 channelsInMax.insert(hit->identify());
82 if (hit->secondaryMeasurement()) {
83 channelsInMax.insert(xAOD::identify(hit->secondaryMeasurement()));
84 }
85 }
86 std::vector<const Trk::PrepRawData*> trkHits{};
87 trkHits.reserve(channelsInMax.size());
89 for (const Identifier& chId : channelsInMax){
90 switch (m_idHelperSvc->technologyIndex(chId)){
91 case techIdx_t::MDT:
92 trkHits.push_back(fetchPrd(chId, mdtPrds));
93 break;
94 case techIdx_t::RPC:
95 trkHits.push_back(fetchPrd(chId, rpcPrds));
96 break;
97 case techIdx_t::TGC:
98 trkHits.push_back(fetchPrd(chId, tgcPrds));
99 break;
100 case techIdx_t::MM:
101 trkHits.push_back(fetchPrd(chId, mmPrds));
102 break;
103 case techIdx_t::STGC:
104 trkHits.push_back(fetchPrd(chId, stgcPrds));
105 break;
106 default:
107 ATH_MSG_WARNING("Cscs are not part of the new paradigms. Where are they now coming from? "
108 <<m_idHelperSvc->toString(chId));
109 };
110 }
111 if (std::find(trkHits.begin(), trkHits.end(), nullptr) != trkHits.end()){
112 ATH_MSG_ERROR("Errors during the Prd conversion occured");
113 return StatusCode::FAILURE;
114 }
115 const Amg::Vector3D maxPos{seed->localPosition()};
116 const Amg::Vector3D locDir{seed->localDirection()};
117
118 Trk::TrackSurfaceIntersection isect{localToGlobal * maxPos, localToGlobal.linear()*locDir,0.};
119 ATH_MSG_VERBOSE("Intersection at "<<m_idHelperSvc->toStringChamber(trkHits[0]->identify())<<" "<<Amg::toString(isect.position())<<" "<<Amg::toString(isect.direction())
120 <<Amg::angle(isect.position(), isect.direction()) / Gaudi::Units::deg );
121 Muon::MuonPatternChamberIntersect chamberIsect{std::move(isect), std::move(trkHits)};
122
123 convertMaximum(chamberIsect, houghDataSec);
124 std::vector<Muon::MuonPatternChamberIntersect> chamberData{std::move(chamberIsect)};
125
126 auto patternCombi = std::make_unique<Muon::MuonPatternCombination>(nullptr, std::move(chamberData));
127 patternContainer.push_back(std::move(patternCombi));
128 }
129
130 return StatusCode::SUCCESS;
131 }
133 Muon::HoughDataPerSectorVec& houghDataSec) const {
134
135 if (houghDataSec.vec.empty()) {
136 constexpr unsigned int nSectors = 16;
137 houghDataSec.vec.resize(nSectors);
138 for (unsigned int i = 0; i < nSectors; ++i) {
139 houghDataSec.vec[i].sector = i + 1;
140 }
141 }
142
143 const Identifier chId = intersect.prepRawDataVec()[0]->identify();
144 const DetIdx_t regionIndex = m_idHelperSvc->regionIndex(chId);
145 const LayIdx_t layerIndex = m_idHelperSvc->layerIndex(chId);
146 const unsigned int sectorLayerHash = Muon::MuonStationIndex::sectorLayerHash(regionIndex, layerIndex);
147 const int sector = m_idHelperSvc->sector(chId);
148 const bool barrel = !m_idHelperSvc->isEndcap(chId);
149
150 auto convertedMax = std::make_unique<LegacyMax>();
151 convertedMax->hough = &houghDataSec.detectorHoughTransforms.hough(sector, regionIndex, layerIndex);
152 convertedMax->theta = intersect.intersectDirection().theta();
153 for (const Trk::PrepRawData* prd : intersect.prepRawDataVec()) {
154 std::unique_ptr<MuonHough::Hit> hit{};
155 Amg::Vector3D gp{Amg::Vector3D::Zero()};
156 if (m_idHelperSvc->isMdt(prd->identify())){
157 gp = static_cast<const Muon::MdtPrepData*>(prd)->globalPosition();
158 } else {
159 gp = static_cast<const Muon::MuonCluster*>(prd)->globalPosition();
160 }
161
162 // TODO: Might need some fine-tuning if the hough hit information is needed downstream
163 hit = std::make_unique<MuonHough::Hit>(0, barrel ? gp.perp() : gp.z(),
164 barrel ? gp.z() : gp.perp(),
165 barrel ? gp.z() : gp.perp(),
166 1., nullptr, prd);
167 convertedMax->hits.emplace_back(std::move(hit));
168 }
169 houghDataSec.vec[sector-1].maxVec[sectorLayerHash].push_back(std::move(convertedMax));
170 }
171
172
173 template <class PrdType>
174 const PrdType* PatternCnvAlg::fetchPrd(const Identifier& prdId,
175 const Muon::MuonPrepDataContainerT<PrdType>* prdContainer) const {
176 if (!prdContainer) {
177 ATH_MSG_ERROR("Cannot fetch a prep data object as the container given for "<<
178 m_idHelperSvc->toString(prdId)<<" is a nullptr");
179 return nullptr;
180 }
181 const Muon::MuonPrepDataCollection<PrdType>* coll = prdContainer->indexFindPtr(m_idHelperSvc->moduleHash(prdId));
182 if (!coll) {
183 ATH_MSG_ERROR("No prep data collection where "<<m_idHelperSvc->toString(prdId)<<" can reside in.");
184 return nullptr;
185 }
186 for (const PrdType* prd : *coll) {
187 if (prd->identify() == prdId){
188 return prd;
189 }
190 }
191 ATH_MSG_ERROR("There is no measurement "<<m_idHelperSvc->toString(prdId));
192 return nullptr;
193 }
194}
#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)
DataVector< Muon::MuonPatternCombination > MuonPatternCombinationCollection
This typedef represents a collection of MuonPatternCombination objects.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
virtual const T * indexFindPtr(IdentifierHash hashId) const override final
return pointer on the found entry or null if out of range using hashed index - fast version,...
MuonLayerHough & hough(int sector, DetRegIdx region, LayIdx layer)
access precision transform
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
const PrdType * fetchPrd(const Identifier &prdId, const Muon::MuonPrepDataContainerT< PrdType > *prdContainer) const
void convertMaximum(const Muon::MuonPatternChamberIntersect &intersect, Muon::HoughDataPerSectorVec &houghDataSec) const
: Converts the maximum back into the HoughDataPersector
SG::WriteHandleKey<::MuonPatternCombinationCollection > m_combiKey
SG::ReadHandleKey< Muon::sTgcPrepDataContainer > m_keysTgc
StatusCode initialize() override final
SG::ReadHandleKey< Muon::MdtPrepDataContainer > m_keyMdt
SG::ReadHandleKey< Muon::RpcPrepDataContainer > m_keyRpc
SG::ReadHandleKey< Muon::MMPrepDataContainer > m_keyMM
SG::ReadHandleKey< Muon::TgcPrepDataContainer > m_keyTgc
Prep data container keys.
SG::ReadHandleKeyArray< SegmentSeedContainer > m_readKeys
SG::ReadHandleKey< ActsTrk::GeometryContext > m_geoCtxKey
StatusCode execute(const EventContext &ctx) const override final
StatusCode convertSeed(const EventContext &ctx, const SegmentSeedContainer &seedContainer, ::MuonPatternCombinationCollection &patternContainer, Muon::HoughDataPerSectorVec &houghDataSec) const
Converts each segment seed first into a PatternCombination - serving as input for the legacy segment ...
SG::WriteHandleKey< Muon::HoughDataPerSectorVec > m_dataPerSecKey
Representation of a segment seed (a fully processed hough maximum) produced by the hough transform.
Definition SegmentSeed.h:14
Class to represent measurements from the Monitored Drift Tubes.
Definition MdtPrepData.h:33
This class holds information needed for the Moore and MoMu pattern recognition for a muon chamber.
Template to hold collections of MuonPrepRawData objects.
Property holding a SG store/key/clid from which a ReadHandle is made.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
An intersection with a Surface is given by.
const Amg::Vector3D & direction() const
Method to retrieve the direction at the Intersection.
const Amg::Vector3D & position() const
Method to retrieve the position of the Intersection.
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
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
This header ties the generic definitions in this package.
DataVector< SegmentSeed > SegmentSeedContainer
const SpacePoint * HoughHitType
TechnologyIndex
enum to classify the different layers in the muon spectrometer
DetectorRegionIndex
enum to classify the different layers in the muon spectrometer
unsigned int sectorLayerHash(DetectorRegionIndex detectorRegionIndex, LayerIndex layerIndex)
create a hash out of region and layer
LayerIndex
enum to classify the different layers in the muon spectrometer
MuonPrepDataContainerT< RpcPrepData > RpcPrepDataContainer
MuonPrepDataContainer< MuonPrepDataCollection< PrdType > > MuonPrepDataContainerT
MuonPrepDataContainerT< TgcPrepData > TgcPrepDataContainer
MuonPrepDataContainerT< MdtPrepData > MdtPrepDataContainer
MuonPrepDataContainerT< sTgcPrepData > sTgcPrepDataContainer
MuonPrepDataContainerT< MMPrepData > MMPrepDataContainer
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.
struct representing the maximum in the hough space
std::vector< HoughDataPerSec > vec
MuonHough::MuonDetectorHough detectorHoughTransforms