ATLAS Offline Software
Loading...
Searching...
No Matches
MuonLayerHoughTool.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef MUONHOUGHPATTERNTOOLS_MUONLAYERHOUGHTOOL_H
6#define MUONHOUGHPATTERNTOOLS_MUONLAYERHOUGHTOOL_H
7
8#include <set>
9
12#include "GaudiKernel/ServiceHandle.h"
13#include "GaudiKernel/ToolHandle.h"
29#include "TFile.h"
30#include "TTree.h"
35namespace Trk {
36 class PrepRawData;
37}
38
39
40namespace MuonHough {
41 class HitDebugInfo;
42}
43
44namespace Muon {
45
46 class MuonLayerHoughTool : public extends<AthAlgTool, IMuonHoughPatternFinderTool> {
47 public:
48 using HashVec = std::vector<IdentifierHash>;
49 using RegionHashVec = std::vector<HashVec>;
50 using TechnologyRegionHashVec = std::vector<RegionHashVec>;
52
57 typedef std::vector<CollectionsPerSector> CollectionsPerSectorVec;
58
69
70 class Road {
71 public:
72 Road(std::shared_ptr<MuonHough::MuonLayerHough::Maximum> seed_) :
73 seed(seed_) { add(seed_); }
74 Road() = default;
76 DetRegIdx neighbouringRegion{DetRegIdx::DetectorRegionUnknown};
78 std::shared_ptr<MuonHough::MuonLayerHough::Maximum> seed{nullptr};
79 void add(std::shared_ptr<MuonHough::MuonLayerHough::Maximum> max) {
80 maxima.emplace_back(max);
81 maximumSet.insert(max);
82 }
83 void add(std::shared_ptr<MuonHough::MuonPhiLayerHough::Maximum> max) { phiMaxima.emplace_back(max); }
86
87 std::set<std::shared_ptr<MuonHough::MuonLayerHough::Maximum>> maximumSet{};
88
89 std::vector<MuonHough::MuonPhiLayerHough::Maximum> mergedPhiMaxima{};
90 };
91
93 using base_class::base_class;
95 virtual ~MuonLayerHoughTool() = default;
96
97 virtual StatusCode initialize() override;
98
99 virtual std::pair<std::unique_ptr<MuonPatternCombinationCollection>, std::unique_ptr<HoughDataPerSectorVec>> find(
100 const MdtPrepDataContainer* mdtCont, const CscPrepDataContainer* cscCols, const TgcPrepDataContainer* tgcCont,
101 const RpcPrepDataContainer* rpcCont, const sTgcPrepDataContainer* stgcCont, const MMPrepDataContainer* mmCont,
102 const EventContext& ctx) const override;
103
105 virtual std::pair<std::unique_ptr<MuonPatternCombinationCollection>, std::unique_ptr<HoughDataPerSectorVec>> find(
106 const std::vector<const MdtPrepDataCollection*>& mdtCols, const std::vector<const CscPrepDataCollection*>& cscCols,
107 const std::vector<const TgcPrepDataCollection*>& tgcCols, const std::vector<const RpcPrepDataCollection*>& rpcCols,
108 const MuonSegmentCombinationCollection*, const EventContext& ctx) const override;
109
110 private:
112
113 void getSectors(const Amg::Vector3D& pos, std::vector<int>& sectors) const;
114 void getSectors(const TgcClusterObj3D& tgc, std::vector<int>& sectors) const;
115
116 double rCor(const Amg::Vector3D& pos, const Identifier& id) const;
117 double rCor(const MuonCluster& rpc) const;
118 double rCor(const MdtPrepData& mdt) const;
119 double rCor(const TgcClusterObj3D& tgc, const TgcEdge val, int sector) const;
120
121 int sublay(const Identifier& id, float z = 0) const; // the z value is only used for the tgcs
122
123 struct State {
124 MaximumVec seedMaxima{}; // Does not own the contained objects, they're just references to objects stored in houghDataPerSectorVec.
125 std::unique_ptr<HoughDataPerSectorVec> houghDataPerSectorVec{std::make_unique<HoughDataPerSectorVec>()};
126 std::set<Identifier> truthHits;
127 std::set<Identifier> foundTruthHits;
128 std::set<Identifier> outputTruthHits;
129 };
130
131 std::pair<std::unique_ptr<MuonPatternCombinationCollection>, std::unique_ptr<HoughDataPerSectorVec>> analyse(State& state) const;
132
133 void fillHitsPerSector(const EventContext& ctx, State& state, const int sector, const CollectionsPerSector& hashes,
134 const MdtPrepDataContainer* mdtCont, const CscPrepDataContainer* cscCont,
135 const TgcPrepDataContainer* tgcCont, const RpcPrepDataContainer* rpcCont,
136 const sTgcPrepDataContainer* stgcCont, const MMPrepDataContainer* mmCont) const;
137
138 void fill(const EventContext& ctx, std::set<Identifier>& truthHits, const MdtPrepDataCollection& mdts, HitVec& hits) const;
139 void fill(const EventContext& ctx, std::set<Identifier>& truthHits,
140 std::vector<std::unique_ptr<TgcHitClusteringObj>>& tgcClusteringObjs, const TgcPrepDataCollection& tgcs, HitVec& hits,
141 PhiHitVec& phiHits, int sector) const;
142 void fill(const EventContext& ctx, std::set<Identifier>& truthHits, const RpcPrepDataCollection& rpcs, HitVec& hits,
143 PhiHitVec& phiHits) const;
144 void fill(const EventContext& ctx, std::set<Identifier>& truthHits, const MMPrepDataCollection& mdts, HitVec& hits) const;
145 void fill(const EventContext& ctx, std::set<Identifier>& truthHits, const sTgcPrepDataCollection& stgcs, HitVec& hits,
146 PhiHitVec& phiHits, int sector) const;
147
148 void fill(const EventContext& ctx, std::set<Identifier>& truthHits, const CscPrepDataCollection& cscs, HitVec& hits,
149 PhiHitVec& phiHits) const;
150
151 bool findMaxima(MaximumVec& seedMaxima,
152 MuonHough::MuonLayerHough& hough, HitVec& hits, MaximumVec& maxima) const;
154 PhiHitVec& hits, PhiMaximumVec& maxima, int sector) const;
155
157 std::map<MuonHough::MuonPhiLayerHough::Maximum*, MaximumVec>& phiEtaAssociations,
158 std::vector<MaximumVec>& unassEtaMaxima) const;
159
161 std::vector<HoughDataPerSector>& houghDataPerSectorVec) const;
162
163 void extendSeed(MuonHough::MuonDetectorHough& detectorHoughTransforms,
164 Road& road, HoughDataPerSector& sectorData) const; // const;
165 void associatePhiMaxima(Road& road, PhiMaximumVec& phiMaxima) const;
166
167 double combinedPeakheight(double ph, double ph1, double ph2, double phn, double rot, int layer, int /*region*/) const;
168 void createPatternCombinations(std::vector<MaximumVec>& maxima, MuonPatternCombinationCollection& patternCombis) const;
169
170 void createPatternCombinations(std::map<MuonHough::MuonPhiLayerHough::Maximum*, MaximumVec>& phiEtaAssociations,
171 MuonPatternCombinationCollection& patternCombis) const;
172
173 void insertHash(const IdentifierHash& hash, const Identifier& id) const;
174 void insertHash(int sector, const IdentifierHash& hash, const Identifier& id) const;
175
176 void matchTruth(std::set<Identifier>& truthHits, const PRD_MultiTruthCollection& truthCol, const Identifier& id,
178
179 void initializeSectorMapping(const EventContext& ctx) const;
180 void printTruthSummary(std::set<Identifier>& truth, std::set<Identifier>& found) const;
181
182 void buildRoads(MaximumVec& seedMaxima, MuonHough::MuonDetectorHough& detectorHoughTransforms,
183 std::unique_ptr<HoughDataPerSectorVec>& houghDataPerSectorVec,
184 std::vector<Road>& roads) const;
185 void mergePhiMaxima(Road& road) const;
186
187 Gaudi::Property<bool> m_useSeeds{this, "UseSeeds", true};
188
189 SG::ReadCondHandleKey<MuonGM::MuonDetectorManager> m_muonManagerKey{this, "MuonManagerKey", "MuonDetectorManager", "MuonManager ReadKey for IOV Range intersection"};
190
191
192 ServiceHandle<IMuonIdHelperSvc> m_idHelperSvc{this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
193 PublicToolHandle<MuonEDMPrinterTool> m_printer{this, "printerTool", "Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"};
194
195 std::vector<MuonHough::MuonLayerHoughSelector> m_selectors;
196 std::vector<MuonHough::MuonLayerHoughSelector> m_selectorsLoose;
197
199
200 Gaudi::Property<bool> m_useRpcTimeVeto{this, "RpcTimeVeto", false};
201 Gaudi::Property<bool> m_requireTriggerConfirmationNSW{this, "TriggerConfirmationNSW", false};
202 Gaudi::Property<bool> m_onlyUseCurrentBunch{this, "OnlyUseCurrentBunch", false};
203 Gaudi::Property<bool> m_debugHough{this, "DebugHough", false};
204 Gaudi::Property<bool> m_doParabolicExtrapolation{this, "DoParabolicExtrapolation",
205 true}; // if true, do parabolic; if false, do linear extrapolation
206 Gaudi::Property<float> m_extrapolationDistance{this, "ExtrapolationDistance", 1500.}; // default value is 1500
207 Gaudi::Property<bool> m_addSectors{this, "AddSectors", false}; // default false
208 unsigned int m_ntechnologies{UINT_MAX};
209 std::map<unsigned int, unsigned int> m_techToTruthNameIdx{}; // mapping the muon technology to the index of the m_truthNames vector
210
212
213 mutable std::mutex m_mutex ATLAS_THREAD_SAFE;
214 mutable CollectionsPerSectorVec m_collectionsPerSector ATLAS_THREAD_SAFE;
215 mutable bool m_sectorSetup ATLAS_THREAD_SAFE{false};
216 };
217
220 return s2->maxEtaHits() < s1->maxEtaHits();
221 }
222 };
223
224 inline void MuonLayerHoughTool::getSectors(const TgcClusterObj3D& tgc, std::vector<int>& sectors) const {
225 getSectors(tgc.getEdge(TgcEdge::LowEtaLowPhi), sectors);
226 }
227
228 inline void MuonLayerHoughTool::getSectors(const Amg::Vector3D& pos, std::vector<int>& sectors) const {
229 return m_sectorMapping.getSectors(pos.phi(), sectors);
230 }
231
232 inline double MuonLayerHoughTool::rCor(const Amg::Vector3D& pos, const Identifier& id) const {
233 return m_sectorMapping.transformRToSector(pos.perp(), pos.phi(), m_idHelperSvc->sector(id));
234 }
235
236 inline double MuonLayerHoughTool::rCor(const MuonCluster& mm) const { return rCor(mm.globalPosition(), mm.identify()); }
237
238 inline double MuonLayerHoughTool::rCor(const MdtPrepData& mm) const { return rCor(mm.globalPosition(), mm.identify()); }
239
240 inline double MuonLayerHoughTool::rCor(const TgcClusterObj3D& tgc, const TgcEdge val, int sector) const {
241 const Amg::Vector3D& pos{tgc.getEdge(val)};
242 return m_sectorMapping.transformRToSector(pos.perp(), pos.phi(), sector);
243 }
244
245 inline int MuonLayerHoughTool::sublay(const Identifier& id, float /*z*/) const {
246 int sublayer = 0;
247 if (m_idHelperSvc->isMdt(id)) {
248 sublayer = m_idHelperSvc->mdtIdHelper().tubeLayer(id) - 1;
249 if (m_idHelperSvc->mdtIdHelper().multilayer(id) == 2) sublayer += 4;
250 } else if (m_idHelperSvc->isMM(id)) {
251 sublayer = m_idHelperSvc->mmIdHelper().gasGap(id) - 1;
252 if (m_idHelperSvc->mmIdHelper().multilayer(id) == 2) sublayer += 4;
253 sublayer += 600; // type info
254 } else if (m_idHelperSvc->issTgc(id)) {
255 sublayer = m_idHelperSvc->stgcIdHelper().gasGap(id) - 1;
256 if (m_idHelperSvc->stgcIdHelper().multilayer(id) == 2) sublayer += 4;
257 sublayer += 500; // type info
258 } else if (m_idHelperSvc->isRpc(id)) {
259 sublayer = m_idHelperSvc->rpcIdHelper().gasGap(id) - 1;
260 if (m_idHelperSvc->rpcIdHelper().doubletR(id) == 2) sublayer += 2;
261 sublayer += 100; // type info
262 } else if (m_idHelperSvc->isTgc(id)) {
263 sublayer = m_idHelperSvc->tgcIdHelper().gasGap(id) - 1;
264 using namespace MuonStationIndex;
265 StIndex stIndex = m_idHelperSvc->stationIndex(id);
266 if (stIndex == StIndex::EM) {
267 // T1 gets +3; T2 gets +3+3; T3 gets +3+6; T4 gets0 (because it is also EI)
268 PhiIndex phiIndex = m_idHelperSvc->phiIndex(id);
269 sublayer += 3;
270 if (phiIndex == PhiIndex::T2)
271 sublayer += 3;
272 else if (phiIndex == PhiIndex::T3)
273 sublayer += 6;
274 // float fz = fabs(z);
275 // if( fz < 13350 ) sublayer += 0;
276 // else if( fz < 13440 ) sublayer += 3;
277 // else if( fz < 13520 ) sublayer += 6;
278 // else if( fz < 13600 ) sublayer += 9;
279 // else if( fz < 14650 ) sublayer += 12;
280 // else if( fz < 14740 ) sublayer += 15;
281 // else if( fz < 14800 ) sublayer += 18;
282 // else if( fz < 14850 ) sublayer += 21;
283 // else if( fz < 15070 ) sublayer += 24;
284 // else if( fz < 15150 ) sublayer += 27;
285 // else if( fz < 15220 ) sublayer += 30;
286 // else if( fz < 15250 ) sublayer += 33;
287 // else sublayer += 36;
288 }
289 sublayer += 300; // type info
290 }
291 return sublayer;
292 }
293
294 inline double MuonLayerHoughTool::combinedPeakheight(double ph, double ph1, double ph2, double phn, double /*rot*/, int layer,
295 int /*region*/) const {
296 if (layer == 0 && ph < 3.) return ph;
297 if (layer == 1 && ph < 4.) return ph;
298 if (layer == 2 && ph < 3.) return ph;
299
300 if (phn > 7) ph += phn;
301
302 if (layer == 0) {
303 if (ph1 > 6.9) ph += 2;
304 if (ph1 > 8.9) ph += 2;
305 if (ph2 > 5.9) ph += 2;
306 if (ph2 > 7.9) ph += 2;
307 }
308 if (layer == 1) {
309 if (ph1 > 6.9) ph += 2;
310 if (ph2 > 5.9) ph += 2;
311 if (ph2 > 7.9) ph += 2;
312 if (ph2 > 11.9) ph += 2;
313 }
314 if (layer == 2) {
315 if (ph1 > 6.9) ph += 2;
316 if (ph2 > 6.9) ph += 2;
317 if (ph2 > 8.9) ph += 2;
318 }
319 return ph;
320 }
321
322} // namespace Muon
323#endif
const bool debug
DataVector< Muon::MuonPatternCombination > MuonPatternCombinationCollection
This typedef represents a collection of MuonPatternCombination objects.
DataVector< Muon::MuonSegmentCombination > MuonSegmentCombinationCollection
This typedef represents a collection of MuonSegmentCombination objects.
#define z
#define max(a, b)
Definition cfImp.cxx:41
This is a "hash" representation of an Identifier.
struct containing additional debug information on the hits that is not needed for the actual alg but ...
class managing all Hough transforms in the detector
Class to represent measurements from the Monitored Drift Tubes.
Definition MdtPrepData.h:33
void add(std::shared_ptr< MuonHough::MuonLayerHough::Maximum > max)
std::vector< MuonHough::MuonPhiLayerHough::Maximum > mergedPhiMaxima
void add(std::shared_ptr< MuonHough::MuonPhiLayerHough::Maximum > max)
MuonStationIndex::DetectorRegionIndex DetRegIdx
std::set< std::shared_ptr< MuonHough::MuonLayerHough::Maximum > > maximumSet
std::shared_ptr< MuonHough::MuonLayerHough::Maximum > seed
Road(std::shared_ptr< MuonHough::MuonLayerHough::Maximum > seed_)
Gaudi::Property< bool > m_useSeeds
void printTruthSummary(std::set< Identifier > &truth, std::set< Identifier > &found) const
HoughDataPerSec::RegionMaximumVec RegionMaximumVec
std::vector< MuonHough::MuonLayerHoughSelector > m_selectorsLoose
std::vector< MuonHough::MuonLayerHoughSelector > m_selectors
void associateMaximaToPhiMaxima(MuonStationIndex::DetectorRegionIndex region, HoughDataPerSector &houghData, std::map< MuonHough::MuonPhiLayerHough::Maximum *, MaximumVec > &phiEtaAssociations, std::vector< MaximumVec > &unassEtaMaxima) const
HoughDataPerSec::RegionHitVec RegionHitVec
void extendSeed(MuonHough::MuonDetectorHough &detectorHoughTransforms, Road &road, HoughDataPerSector &sectorData) const
void mergePhiMaxima(Road &road) const
HoughDataPerSec::HitVec HitVec
SG::ReadHandleKeyArray< PRD_MultiTruthCollection > m_truthNames
bool findMaxima(MaximumVec &seedMaxima, MuonHough::MuonLayerHough &hough, HitVec &hits, MaximumVec &maxima) const
HoughDataPerSec::RegionPhiHitVec RegionPhiHitVec
HoughDataPerSec HoughDataPerSector
Gaudi::Property< bool > m_onlyUseCurrentBunch
void getSectors(const Amg::Vector3D &pos, std::vector< int > &sectors) const
ServiceHandle< IMuonIdHelperSvc > m_idHelperSvc
MuonSectorMapping m_sectorMapping
PublicToolHandle< MuonEDMPrinterTool > m_printer
HoughDataPerSec::MaximumAssociationMap MaximumAssociationMap
std::pair< std::unique_ptr< MuonPatternCombinationCollection >, std::unique_ptr< HoughDataPerSectorVec > > analyse(State &state) const
Gaudi::Property< bool > m_requireTriggerConfirmationNSW
Gaudi::Property< bool > m_useRpcTimeVeto
int sublay(const Identifier &id, float z=0) const
void fill(const EventContext &ctx, std::set< Identifier > &truthHits, const MdtPrepDataCollection &mdts, HitVec &hits) const
std::map< unsigned int, unsigned int > m_techToTruthNameIdx
MuonStationIndex::DetectorRegionIndex DetRegIdx
void createPatternCombinations(std::vector< MaximumVec > &maxima, MuonPatternCombinationCollection &patternCombis) const
double rCor(const Amg::Vector3D &pos, const Identifier &id) const
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_muonManagerKey
HoughDataPerSec::PhiMaximumVec PhiMaximumVec
std::vector< RegionHashVec > TechnologyRegionHashVec
void insertHash(const IdentifierHash &hash, const Identifier &id) const
TgcClusterObj3D::Edge TgcEdge
HoughDataPerSec::RegionPhiMaximumVec RegionPhiMaximumVec
HoughDataPerSec::PhiHitVec PhiHitVec
std::vector< HashVec > RegionHashVec
void matchTruth(std::set< Identifier > &truthHits, const PRD_MultiTruthCollection &truthCol, const Identifier &id, MuonHough::HitDebugInfo &debug) const
void fillHitsPerSector(const EventContext &ctx, State &state, const int sector, const CollectionsPerSector &hashes, const MdtPrepDataContainer *mdtCont, const CscPrepDataContainer *cscCont, const TgcPrepDataContainer *tgcCont, const RpcPrepDataContainer *rpcCont, const sTgcPrepDataContainer *stgcCont, const MMPrepDataContainer *mmCont) const
Gaudi::Property< float > m_extrapolationDistance
void associatePhiMaxima(Road &road, PhiMaximumVec &phiMaxima) const
std::vector< CollectionsPerSector > CollectionsPerSectorVec
std::mutex m_mutex ATLAS_THREAD_SAFE
virtual StatusCode initialize() override
Gaudi::Property< bool > m_addSectors
Gaudi::Property< bool > m_debugHough
double combinedPeakheight(double ph, double ph1, double ph2, double phn, double rot, int layer, int) const
virtual std::pair< std::unique_ptr< MuonPatternCombinationCollection >, std::unique_ptr< HoughDataPerSectorVec > > find(const MdtPrepDataContainer *mdtCont, const CscPrepDataContainer *cscCols, const TgcPrepDataContainer *tgcCont, const RpcPrepDataContainer *rpcCont, const sTgcPrepDataContainer *stgcCont, const MMPrepDataContainer *mmCont, const EventContext &ctx) const override
void associateMaximaInNeighbouringSectors(HoughDataPerSector &houghData, std::vector< HoughDataPerSector > &houghDataPerSectorVec) const
Gaudi::Property< bool > m_doParabolicExtrapolation
void buildRoads(MaximumVec &seedMaxima, MuonHough::MuonDetectorHough &detectorHoughTransforms, std::unique_ptr< HoughDataPerSectorVec > &houghDataPerSectorVec, std::vector< Road > &roads) const
std::vector< IdentifierHash > HashVec
virtual ~MuonLayerHoughTool()=default
Destructor.
void initializeSectorMapping(const EventContext &ctx) const
HoughDataPerSec::MaximumVec MaximumVec
Edge
Representation of the four edge points.
Amg::Vector3D & getEdge(const Edge e)
A PRD is mapped onto all contributing particles.
Eigen::Matrix< double, 3, 1 > Vector3D
StIndex
enum to classify the different station layers in the muon spectrometer
DetectorRegionIndex
enum to classify the different layers in the muon spectrometer
PhiIndex
enum to classify the different phi layers in the muon spectrometer
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
MuonPrepDataCollection< CscPrepData > CscPrepDataCollection
MuonPrepDataCollection< TgcPrepData > TgcPrepDataCollection
MuonPrepDataContainerT< RpcPrepData > RpcPrepDataContainer
MuonPrepDataCollection< MMPrepData > MMPrepDataCollection
MuonPrepDataContainerT< TgcPrepData > TgcPrepDataContainer
MuonPrepDataContainerT< MdtPrepData > MdtPrepDataContainer
MuonPrepDataContainerT< sTgcPrepData > sTgcPrepDataContainer
MuonPrepDataContainerT< MMPrepData > MMPrepDataContainer
MuonPrepDataCollection< MdtPrepData > MdtPrepDataCollection
MuonPrepDataContainerT< CscPrepData > CscPrepDataContainer
MuonPrepDataCollection< RpcPrepData > RpcPrepDataCollection
MuonPrepDataCollection< sTgcPrepData > sTgcPrepDataCollection
HandleKeyArray< ReadHandle< T >, ReadHandleKey< T >, Gaudi::DataHandle::Reader > ReadHandleKeyArray
Ensure that the ATLAS eigen extensions are properly loaded.
std::map< MuonHough::MuonLayerHough::Maximum *, MaximumVec > MaximumAssociationMap
std::vector< std::shared_ptr< MuonHough::MuonPhiLayerHough::Maximum > > PhiMaximumVec
std::vector< std::shared_ptr< MuonHough::MuonLayerHough::Maximum > > MaximumVec
std::vector< HitVec > RegionHitVec
std::vector< PhiMaximumVec > RegionPhiMaximumVec
MuonHough::PhiHitVec PhiHitVec
std::vector< PhiHitVec > RegionPhiHitVec
MuonHough::HitVec HitVec
std::vector< MaximumVec > RegionMaximumVec
std::unique_ptr< HoughDataPerSectorVec > houghDataPerSectorVec
std::set< Identifier > foundTruthHits
std::set< Identifier > outputTruthHits
bool operator()(const MuonLayerHoughTool::HoughDataPerSector *s1, const MuonLayerHoughTool::HoughDataPerSector *s2) const