ATLAS Offline Software
NswSegmentFinderAlg.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 MUONR4_MUONPATTERNRECOGNITIONALGS_NSWSEGMENTFINDERALG_H
6 #define MUONR4_MUONPATTERNRECOGNITIONALGS_NSWSEGMENTFINDERALG_H
7 
11 
15 
20 
22 
23 
25 
26 #include <span>
27 #include <vector>
28 
29 
30 namespace MuonR4{
31 
32 
34 
35  public:
36  using AthReentrantAlgorithm::AthReentrantAlgorithm;
37  virtual ~NswSegmentFinderAlg() = default;
38  virtual StatusCode initialize() override;
39  virtual StatusCode execute(const EventContext& ctx) const override;
40  virtual StatusCode finalize() override;
41 
42  private:
43 
45  enum class StripOrient{
46  U,
47  V,
48  X,
49  P,
50  C,
51  Unknown
52  };
53 
56 
57  public:
58 
60 
61  SeedStatistics() = default;
62 
63  //dump seed statistics to the map
64  void addToStat(const MuonGMR4::SpectrometerSector* msSector,
65  unsigned int nSeeds,
66  unsigned int nExtSeeds,
67  unsigned int nSegments);
68 
69  // print the seed counting stats in the end of the algorithm */
70  void printTableSeedStats(MsgStream& msg) const;
71 
72  private:
73 
74  struct SeedField{
76  unsigned int nSeeds{0};
78  unsigned int nExtSeeds{0};
80  unsigned int nSegments{0};
81  };
82 
84  struct SectorField{
86  int phi{0};
87  int eta{0};
88  int8_t side{1};
89 
90  bool operator<(SectorField const& o) const noexcept {
91  if(chIdx != o.chIdx) return chIdx < o.chIdx;
92  if(eta != o.eta) return eta < o.eta;
93  if(side != o.side) return side < o.side;
94  return phi < o.phi;
95  }
96 
97  };
98 
99  using SeedStatistic_T = std::map<SectorField, SeedField>;
101 
103 
104  };
105 
107  StripOrient classifyStrip(const SpacePoint& spacePoint) const;
108 
110 
113  using HitLaySpan_t = std::vector<std::reference_wrapper<const HitVec>>;
115  using UsedHitMarker_t = std::vector<std::vector<unsigned int>>;
117  using UsedHitSpan_t = std::vector<std::reference_wrapper<std::vector<unsigned int>>>;
119  using InitialSeed_t = std::array<const SpacePoint*, 4>;
121  using InitialSeedVec_t = std::vector<InitialSeed_t>;
124  UsedHitMarker_t emptyBookKeeper(const HitLayVec& sortedSp) const;
125 
131  enum class HitWindow{tooLow,
132  inside,
133  tooHigh};
134 
142  HitWindow hitFromIPCorridor(const SpacePoint& testHit,
143  const Amg::Vector3D& beamSpotPos,
144  const Amg::Vector3D& dirEstUp,
145  const Amg::Vector3D& dirEstDn) const;
155  const HitLaySpan_t& combinatoricLayers,
156  const UsedHitSpan_t& usedHits,
157  InitialSeedVec_t& outVec) const;
165  std::unique_ptr<SegmentSeed> buildSegmentSeed(const InitialSeed_t& initialSeed,
166  const AmgSymMatrix(2)& bMatrix,
167  const HoughMaximum& max,
168  const HitLaySpan_t& extensionLayers,
169  const UsedHitSpan_t& usedHits) const;
174  std::unique_ptr<Segment> fitSegmentSeed(const EventContext& ctx,
175  const ActsTrk::GeometryContext& gctx,
176  const SegmentSeed *patternSeed) const;
177 
185  void markHitsAsUsed(const HitVec& spacePoints,
186  const HitLayVec& allSortHits,
187  UsedHitMarker_t& usedHitMarker,
188  unsigned int increase,
189  bool markNeighborHits) const;
190 
191 
198  HitVec extendHits(const Amg::Vector3D& startPos,
199  const Amg::Vector3D& direction,
200  const HitLaySpan_t& extensionLayers,
201  const UsedHitSpan_t& usedHits) const;
202 
208  std::pair<std::vector<std::unique_ptr<SegmentSeed>>, std::vector<std::unique_ptr<Segment>>>
210  const ActsTrk::GeometryContext& gctx,
211  const EventContext& ctx) const;
212 
213  // read handle key for the input maxima (from a previous eta-transform)
214  SG::ReadHandleKey<EtaHoughMaxContainer> m_etaKey{this, "CombinatorialReadKey", "MuonHoughNswMaxima"};
215 
216  //write handle key for the segment seeds container
217  SG::WriteHandleKey<SegmentSeedContainer> m_writeSegmentSeedKey{this, "MuonNswSegmentSeedWriteKey", "MuonNswSegmentSeeds"};
218 
219  // write handle key for the segments container
220  SG::WriteHandleKey<SegmentContainer> m_writeSegmentKey{this, "MuonNswSegmentWriteKey", "MuonNswSegments"};
221 
222  // access to the ACTS geometry context
223  SG::ReadHandleKey<ActsTrk::GeometryContext> m_geoCtxKey{this, "AlignmentKey", "ActsAlignment", "cond handle key"};
224 
225  // access to the Muon Id Helper
226  ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
227 
229  ToolHandle<MuonValR4::IPatternVisualizationTool> m_visionTool{this, "VisualizationTool", ""};
230 
231  //Space point calibration tool
232  ToolHandle<ISpacePointCalibrator> m_calibTool{this, "Calibrator", "" };
233 
234  // Pointer to the line segment fitter
235  std::unique_ptr<SegmentFit::SegmentLineFitter> m_lineFitter{};
236 
237  //the window in theta to search for hits in the seed extension
238  DoubleProperty m_windowTheta {this, "thetaWindow", 0.5 * Gaudi::Units::deg};
239 
240  //apply a cut threshold in the pulls during the hit extension
241  DoubleProperty m_minPullThreshold{this, "maxPull", 5.};
242 
243  //minimum number of hits required to form a seed after extension
244  DoubleProperty m_minSeedHits{this, "minSeedHits", 6.};
245 
246  //maximum number of MM Clusters that are invalid in the seed
247  DoubleProperty m_maxInvalidClusters{this, "maxInvalidClusters", 4.};
248 
249  //reject also hits from the seed even if it does not lead to succesful segment
250  BooleanProperty m_markHitsFromSeed{this, "markHitsFromSeed", true};
251 
252  //maximum number that hit is allowed to be used
253  UnsignedIntegerProperty m_maxUsed{this, "maxHitIsUsed", 6};
254 
255  //minimum number of strips required for MMClusers not to be invalid
256  DoubleProperty m_minClusSize{this, "minClusterSize", 1.};
257 
258  //maximum number of chi2 cut for the segment
259  DoubleProperty m_maxChi2{this, "maxChi2", 6.};
260 
261  // maximum number of clusters in the layer for the seed finding
262  DoubleProperty m_maxClustersInLayer{this, "maxClustersInLayer", 8};
263 
264  //maximum number of dY window size for killing hits on the layer from the segments
265  DoubleProperty m_maxdYWindow{this, "maxdYWindow", 4.*Gaudi::Units::cm};
266 
267  //dump statistics for the seeds per sector
268  BooleanProperty m_dumpSeedStatistics{this, "dumpStatistics", true};
269 
270  std::unique_ptr<SeedStatistics> m_seedCounter ATLAS_THREAD_SAFE{};
271 
272 
273 };
274 
275 }
276 
277 #endif
MuonR4::NswSegmentFinderAlg::ATLAS_THREAD_SAFE
std::unique_ptr< SeedStatistics > m_seedCounter ATLAS_THREAD_SAFE
Definition: NswSegmentFinderAlg.h:270
MuonR4::NswSegmentFinderAlg::m_markHitsFromSeed
BooleanProperty m_markHitsFromSeed
Definition: NswSegmentFinderAlg.h:250
MuonR4::NswSegmentFinderAlg::HitWindow
HitWindow
To fastly check whether a hit is roughly compatible with a muon trajectory a narrow corridor is opene...
Definition: NswSegmentFinderAlg.h:131
MuonR4::NswSegmentFinderAlg::InitialSeed_t
std::array< const SpacePoint *, 4 > InitialSeed_t
Abbrivation of the
Definition: NswSegmentFinderAlg.h:119
MuonR4::NswSegmentFinderAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: NswSegmentFinderAlg.h:226
MuonR4::NswSegmentFinderAlg::HitLaySpan_t
std::vector< std::reference_wrapper< const HitVec > > HitLaySpan_t
Abbrivation of the space comprising multiple hit vectors without copy.
Definition: NswSegmentFinderAlg.h:113
MuonR4::NswSegmentFinderAlg::SeedStatistics::printTableSeedStats
void printTableSeedStats(MsgStream &msg) const
Definition: NswSegmentFinderAlg.cxx:672
MuonR4::NswSegmentFinderAlg::SeedStatistics::SeedStatistics
SeedStatistics()=default
MuonR4::NswSegmentFinderAlg
Definition: NswSegmentFinderAlg.h:33
MuonGMR4::SpectrometerSector
A spectrometer sector forms the envelope of all chambers that are placed in the same MS sector & laye...
Definition: SpectrometerSector.h:40
IPatternVisualizationTool.h
MuonR4::NswSegmentFinderAlg::SeedStatistics::m_mutex
std::mutex m_mutex
Definition: NswSegmentFinderAlg.h:102
MuonR4::SpacePointPerLayerSplitter::HitLayVec
std::vector< HitVec > HitLayVec
Definition: SpacePointPerLayerSplitter.h:19
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
MuonR4::NswSegmentFinderAlg::StripOrient
StripOrient
Enumeration to classify the orientation of a NSW strip
Definition: NswSegmentFinderAlg.h:45
MuonR4::NswSegmentFinderAlg::m_geoCtxKey
SG::ReadHandleKey< ActsTrk::GeometryContext > m_geoCtxKey
Definition: NswSegmentFinderAlg.h:223
MuonR4::NswSegmentFinderAlg::HitWindow::tooHigh
@ tooHigh
The hit is inside the defined window and hence an initial candidate.
MuonR4::NswSegmentFinderAlg::m_maxClustersInLayer
DoubleProperty m_maxClustersInLayer
Definition: NswSegmentFinderAlg.h:262
MuonR4::NswSegmentFinderAlg::SeedStatistics::SeedField::nExtSeeds
unsigned int nExtSeeds
number of successfully extended seeds
Definition: NswSegmentFinderAlg.h:78
MuonR4::NswSegmentFinderAlg::HitWindow::tooLow
@ tooLow
MuonR4::NswSegmentFinderAlg::m_lineFitter
std::unique_ptr< SegmentFit::SegmentLineFitter > m_lineFitter
Definition: NswSegmentFinderAlg.h:235
MuonR4::NswSegmentFinderAlg::SeedStatistics::SeedField::nSegments
unsigned int nSegments
number of segments constucted
Definition: NswSegmentFinderAlg.h:80
MuonR4::NswSegmentFinderAlg::SeedStatistics::SectorField::eta
int eta
Definition: NswSegmentFinderAlg.h:87
MuonR4::NswSegmentFinderAlg::buildSegmentSeed
std::unique_ptr< SegmentSeed > buildSegmentSeed(const InitialSeed_t &initialSeed, const AmgSymMatrix(2)&bMatrix, const HoughMaximum &max, const HitLaySpan_t &extensionLayers, const UsedHitSpan_t &usedHits) const
Build the final seed from the initial seed hits and then attempt to append hits from the complementar...
Definition: NswSegmentFinderAlg.cxx:299
MuonR4::NswSegmentFinderAlg::SeedStatistics
Seed statistics per sector to be printed in the end.
Definition: NswSegmentFinderAlg.h:55
deg
#define deg
Definition: SbPolyhedron.cxx:17
ISpacePointCalibrator.h
MuonR4::NswSegmentFinderAlg::SeedStatistics::SectorField::phi
int phi
Definition: NswSegmentFinderAlg.h:86
MuonR4::NswSegmentFinderAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: NswSegmentFinderAlg.cxx:581
MuonR4::NswSegmentFinderAlg::StripOrient::Unknown
@ Unknown
Combined 2D space point (sTGC wire + strip / sTgc pad)
MuonR4::NswSegmentFinderAlg::m_windowTheta
DoubleProperty m_windowTheta
Definition: NswSegmentFinderAlg.h:238
MuonR4::NswSegmentFinderAlg::SeedStatistics::m_seedStat
SeedStatistic_T m_seedStat
Definition: NswSegmentFinderAlg.h:100
SG::ReadHandleKey
Property holding a SG store/key/clid from which a ReadHandle is made.
Definition: StoreGate/StoreGate/ReadHandleKey.h:39
MuonR4::NswSegmentFinderAlg::m_maxUsed
UnsignedIntegerProperty m_maxUsed
Definition: NswSegmentFinderAlg.h:253
MuonR4::NswSegmentFinderAlg::constructPrelimnarySeeds
void constructPrelimnarySeeds(const Amg::Vector3D &beamSpot, const HitLaySpan_t &combinatoricLayers, const UsedHitSpan_t &usedHits, InitialSeedVec_t &outVec) const
Construct a set of prelimnary seeds from the selected combinatoric layers.
Definition: NswSegmentFinderAlg.cxx:197
MuonR4::SpacePointPerLayerSplitter::HitVec
std::vector< const SpacePoint * > HitVec
Definition: SpacePointPerLayerSplitter.h:18
MuonR4::NswSegmentFinderAlg::m_writeSegmentKey
SG::WriteHandleKey< SegmentContainer > m_writeSegmentKey
Definition: NswSegmentFinderAlg.h:220
MuonR4::NswSegmentFinderAlg::m_visionTool
ToolHandle< MuonValR4::IPatternVisualizationTool > m_visionTool
Pattern visualization tool.
Definition: NswSegmentFinderAlg.h:229
AmgSymMatrix
#define AmgSymMatrix(dim)
Definition: EventPrimitives.h:50
MuonR4::NswSegmentFinderAlg::markHitsAsUsed
void markHitsAsUsed(const HitVec &spacePoints, const HitLayVec &allSortHits, UsedHitMarker_t &usedHitMarker, unsigned int increase, bool markNeighborHits) const
Hits that are used in a good seed/segment built should be flagged as used and not contribute to other...
Definition: NswSegmentFinderAlg.cxx:527
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
MuonR4::NswSegmentFinderAlg::SeedStatistics::SeedStatistic_T
std::map< SectorField, SeedField > SeedStatistic_T
Definition: NswSegmentFinderAlg.h:99
MuonR4::NswSegmentFinderAlg::StripOrient::P
@ P
Ordinary eta strips.
MuonR4::NswSegmentFinderAlg::HitWindow::inside
@ inside
The hit is below the predefined corridor.
MuonR4::NswSegmentFinderAlg::SeedStatistics::SectorField::side
int8_t side
Definition: NswSegmentFinderAlg.h:88
cm
const double cm
Definition: Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/FCAL_ChannelMap.cxx:25
MuonR4::NswSegmentFinderAlg::m_minClusSize
DoubleProperty m_minClusSize
Definition: NswSegmentFinderAlg.h:256
SpacePointPerLayerSplitter.h
MuonR4::NswSegmentFinderAlg::m_etaKey
SG::ReadHandleKey< EtaHoughMaxContainer > m_etaKey
Definition: NswSegmentFinderAlg.h:214
MuonR4::NswSegmentFinderAlg::m_maxChi2
DoubleProperty m_maxChi2
Definition: NswSegmentFinderAlg.h:259
SG::WriteHandleKey
Property holding a SG store/key/clid from which a WriteHandle is made.
Definition: StoreGate/StoreGate/WriteHandleKey.h:40
MuonR4::NswSegmentFinderAlg::m_maxdYWindow
DoubleProperty m_maxdYWindow
Definition: NswSegmentFinderAlg.h:265
MuonR4::NswSegmentFinderAlg::SeedStatistics::SectorField::operator<
bool operator<(SectorField const &o) const noexcept
Definition: NswSegmentFinderAlg.h:90
MuonR4::NswSegmentFinderAlg::finalize
virtual StatusCode finalize() override
Definition: NswSegmentFinderAlg.cxx:650
MuonR4::NswSegmentFinderAlg::m_calibTool
ToolHandle< ISpacePointCalibrator > m_calibTool
Definition: NswSegmentFinderAlg.h:232
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MuonPatternContainer.h
MuonDetectorManager.h
MmIdHelper.h
MuonR4::NswSegmentFinderAlg::~NswSegmentFinderAlg
virtual ~NswSegmentFinderAlg()=default
MuonR4::NswSegmentFinderAlg::m_maxInvalidClusters
DoubleProperty m_maxInvalidClusters
Definition: NswSegmentFinderAlg.h:247
MuonR4::NswSegmentFinderAlg::findSegmentsFromMaximum
std::pair< std::vector< std::unique_ptr< SegmentSeed > >, std::vector< std::unique_ptr< Segment > > > findSegmentsFromMaximum(const HoughMaximum &max, const ActsTrk::GeometryContext &gctx, const EventContext &ctx) const
Find seed and segment from an eta hough maximum.
Definition: NswSegmentFinderAlg.cxx:376
ActsTrk::GeometryContext
Definition: GeometryContext.h:28
MuonR4::NswSegmentFinderAlg::SeedStatistics::SeedField
Definition: NswSegmentFinderAlg.h:74
F600IntegrationConfig.spacePoints
spacePoints
Definition: F600IntegrationConfig.py:122
MuonR4::NswSegmentFinderAlg::classifyStrip
StripOrient classifyStrip(const SpacePoint &spacePoint) const
Determines the orientation of the strip space point.
Definition: NswSegmentFinderAlg.cxx:100
MuonR4::NswSegmentFinderAlg::UsedHitSpan_t
std::vector< std::reference_wrapper< std::vector< unsigned int > >> UsedHitSpan_t
Abbrivation of the container to pass a subset of markers wtihout copy.
Definition: NswSegmentFinderAlg.h:117
MuonR4::NswSegmentFinderAlg::StripOrient::X
@ X
Stereo strips with negative angle.
MuonR4::SpacePoint
The muon space point is the combination of two uncalibrated measurements one of them measures the eta...
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/MuonSpacePoint/SpacePoint.h:24
ReadCondHandleKey.h
AthReentrantAlgorithm.h
MuonR4::NswSegmentFinderAlg::m_writeSegmentSeedKey
SG::WriteHandleKey< SegmentSeedContainer > m_writeSegmentSeedKey
Definition: NswSegmentFinderAlg.h:217
WriteHandleKey.h
Property holding a SG store/key/clid from which a WriteHandle is made.
MuonR4::NswSegmentFinderAlg::extendHits
HitVec extendHits(const Amg::Vector3D &startPos, const Amg::Vector3D &direction, const HitLaySpan_t &extensionLayers, const UsedHitSpan_t &usedHits) const
Extend the seed with the hits from the other layers.
Definition: NswSegmentFinderAlg.cxx:246
MuonHoughDefs.h
MuonR4::NswSegmentFinderAlg::SeedStatistics::SectorField
sector's field to dump the seed statistics
Definition: NswSegmentFinderAlg.h:84
MuonR4::NswSegmentFinderAlg::m_minPullThreshold
DoubleProperty m_minPullThreshold
Definition: NswSegmentFinderAlg.h:241
MuonR4::NswSegmentFinderAlg::SeedStatistics::addToStat
void addToStat(const MuonGMR4::SpectrometerSector *msSector, unsigned int nSeeds, unsigned int nExtSeeds, unsigned int nSegments)
Definition: NswSegmentFinderAlg.cxx:658
MuonR4::NswSegmentFinderAlg::m_dumpSeedStatistics
BooleanProperty m_dumpSeedStatistics
Definition: NswSegmentFinderAlg.h:268
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonR4::NswSegmentFinderAlg::hitFromIPCorridor
HitWindow hitFromIPCorridor(const SpacePoint &testHit, const Amg::Vector3D &beamSpotPos, const Amg::Vector3D &dirEstUp, const Amg::Vector3D &dirEstDn) const
The hit is above the predefined corridor.
Definition: NswSegmentFinderAlg.cxx:120
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
MuonR4::NswSegmentFinderAlg::InitialSeedVec_t
std::vector< InitialSeed_t > InitialSeedVec_t
Vector of initial seeds.
Definition: NswSegmentFinderAlg.h:121
MuonR4::NswSegmentFinderAlg::m_minSeedHits
DoubleProperty m_minSeedHits
Definition: NswSegmentFinderAlg.h:244
MuonR4::HoughMaximum
Data class to represent an eta maximum in hough space.
Definition: HoughMaximum.h:14
SegmentLineFitter.h
MuonR4::NswSegmentFinderAlg::StripOrient::U
@ U
SpacePointContainer.h
MuonR4::SegmentSeed
Representation of a segment seed (a fully processed hough maximum) produced by the hough transform.
Definition: SegmentSeed.h:14
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
MuonR4::NswSegmentFinderAlg::fitSegmentSeed
std::unique_ptr< Segment > fitSegmentSeed(const EventContext &ctx, const ActsTrk::GeometryContext &gctx, const SegmentSeed *patternSeed) const
Fit the segment seed.
Definition: NswSegmentFinderAlg.cxx:356
MuonR4::NswSegmentFinderAlg::StripOrient::V
@ V
Stereo strips with positive angle.
python.BuildSignatureFlags.beamSpot
AthConfigFlags beamSpot(AthConfigFlags flags, str instanceName, str recoMode)
Definition: BuildSignatureFlags.py:491
MuonR4::HitVec
SpacePointPerLayerSplitter::HitVec HitVec
Definition: SpacePointPerLayerSplitter.cxx:12
MuonR4::NswSegmentFinderAlg::HitLayVec
SpacePointPerLayerSplitter::HitLayVec HitLayVec
Definition: NswSegmentFinderAlg.h:111
MuonR4::NswSegmentFinderAlg::SeedStatistics::SectorField::chIdx
chIdx_t chIdx
Definition: NswSegmentFinderAlg.h:85
Muon::MuonStationIndex::ChIndex
ChIndex
enum to classify the different chamber layers in the muon spectrometer
Definition: MuonStationIndex.h:15
MuonR4::NswSegmentFinderAlg::initialize
virtual StatusCode initialize() override
Definition: NswSegmentFinderAlg.cxx:61
MuonR4::NswSegmentFinderAlg::SeedStatistics::SeedField::nSeeds
unsigned int nSeeds
number of total seeds constructed
Definition: NswSegmentFinderAlg.h:76
MuonR4::NswSegmentFinderAlg::UsedHitMarker_t
std::vector< std::vector< unsigned int > > UsedHitMarker_t
Abbrivation of the container book keeping whether a hit is used or not.
Definition: NswSegmentFinderAlg.h:115
MuonR4::NswSegmentFinderAlg::StripOrient::C
@ C
Single phi measurements.
MuonR4::NswSegmentFinderAlg::HitVec
SpacePointPerLayerSplitter::HitVec HitVec
Definition: NswSegmentFinderAlg.h:109
MuonR4::NswSegmentFinderAlg::emptyBookKeeper
UsedHitMarker_t emptyBookKeeper(const HitLayVec &sortedSp) const
Constructs an empty HitMarker from the split space points.
Definition: NswSegmentFinderAlg.cxx:91
ServiceHandle< Muon::IMuonIdHelperSvc >