ATLAS Offline Software
Loading...
Searching...
No Matches
NswSegmentFinderAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
12
13
16
19
21
22#include "Acts/Seeding/CombinatorialSeedSolver.hpp"
23
24#include <ranges>
25#include <format>
26
27using namespace Acts::Experimental::CombinatorialSeedSolver;
28namespace {
29 inline const MuonGMR4::StripDesign& getDesign(const MuonR4::SpacePoint& sp) {
31 const auto* prd = static_cast<const xAOD::MMCluster*>(sp.primaryMeasurement());
32 return prd->readoutElement()->stripLayer(prd->measurementHash()).design();
33 } else if (sp.type() == xAOD::UncalibMeasType::sTgcStripType) {
34 const auto* prd = static_cast<const xAOD::sTgcMeasurement*>(sp.primaryMeasurement());
35 const auto* re = prd->readoutElement();
36 switch(prd->channelType()) {
38 return re->stripDesign(prd->measurementHash());
40 return re->wireDesign(prd->measurementHash());
42 return re->padDesign(prd->measurementHash());
43 }
44 }
45 THROW_EXCEPTION("Invalid space point for design retrieval "<<sp.msSector()->idHelperSvc()->toString(sp.identify()));
46 }
47 inline double stripHalfLength(const MuonR4::SpacePoint& sp) {
48 const auto& design = getDesign(sp);
50 const auto* prd = static_cast<const xAOD::MMCluster*>(sp.primaryMeasurement());
51 return 0.5* design.stripLength(prd->channelNumber());
52 } else{
53 const auto* prd = static_cast<const xAOD::sTgcMeasurement*>(sp.primaryMeasurement());
54 if(prd->channelType() == sTgcIdHelper::Pad){
55 const auto& padDesign = static_cast<const MuonGMR4::PadDesign&>(design);
56 auto padCorners = padDesign.padCorners(prd->channelNumber());
57 return 0.5* std::abs(padCorners[0].x() - padCorners[1].x());
58 }
59 return 0.5* design.stripLength(prd->channelNumber());
60 }
61
62 return 0.;
63 }
64 inline std::string sTgcChannelType(const int chType) {
65 return chType == sTgcIdHelper::Strip ? "S" :
66 chType == sTgcIdHelper::Wire ? "W" : "P";
67 }
68
69 //local struct to encapsulate hit candidates data (e.g for seed extension)
70 struct HitCandidate {
71 double minPull{std::numeric_limits<float>::max()};
72 const MuonR4::SpacePoint* spacePoint{nullptr};
73 };
74}
75
76namespace MuonR4 {
77
78using namespace SegmentFit;
79constexpr unsigned minLayers{4};
80
82
84 ATH_CHECK(m_geoCtxKey.initialize());
85 ATH_CHECK(m_etaKey.initialize());
86 ATH_CHECK(m_writeSegmentKey.initialize());
87 ATH_CHECK(m_writeSegmentSeedKey.initialize());
88 ATH_CHECK(m_idHelperSvc.retrieve());
89 ATH_CHECK(m_calibTool.retrieve());
90 ATH_CHECK(m_visionTool.retrieve(DisableTool{m_visionTool.empty()}));
91 ATH_CHECK(detStore()->retrieve(m_detMgr));
92
93 if (!(m_idHelperSvc->hasMM() || m_idHelperSvc->hasSTGC())) {
94 ATH_MSG_ERROR("MM or STGC not part of initialized detector layout");
95 return StatusCode::FAILURE;
96 }
97
99 fitCfg.calibrator = m_calibTool.get();
100 fitCfg.visionTool = m_visionTool.get();
101 fitCfg.calcAlongStrip = false;
102 fitCfg.idHelperSvc = m_idHelperSvc.get();
103 fitCfg.parsToUse = {ParamDefs::x0, ParamDefs::y0, ParamDefs::theta, ParamDefs::phi};
104
105 m_lineFitter = std::make_unique<SegmentFit::SegmentLineFitter>(name(), std::move(fitCfg));
106
108 m_seedCounter = std::make_unique<SeedStatistics>();
109 }
110
111 return StatusCode::SUCCESS;
112}
113
116 UsedHitMarker_t emptyKeeper(sortedSp.size());
117 for (std::size_t l = 0; l < sortedSp.size(); ++l) {
118 emptyKeeper[l].resize(sortedSp[l].size(), 0);
119 }
120 return emptyKeeper;
121}
122
125
127 const auto& design = getDesign(sp);
128 if (!design.hasStereoAngle()) {
129 return StripOrient::X;
130 }
131 return design.stereoAngle() > 0. ? StripOrient::U : StripOrient::V;
132 } else if (sp.type() == xAOD::UncalibMeasType::sTgcStripType) {
133 const auto* prd = static_cast<const xAOD::sTgcMeasurement*>(sp.primaryMeasurement());
134 if (sp.dimension() == 2) {
135 return StripOrient::C;
136 }
137 //check if we have strip only or wire only measurements
138 return prd->channelType() == sTgcIdHelper::Strip ? StripOrient::X : StripOrient::P;
139
140 }
141 ATH_MSG_WARNING("Cannot classify orientation of "<<m_idHelperSvc->toString(sp.identify()));
143}
146 const Amg::Vector3D& beamSpotPos,
147 const Amg::Vector3D& dirEstUp,
148 const Amg::Vector3D& dirEstDn) const{
149
150 const Amg::Vector3D estPlaneArrivalUp = SeedingAux::extrapolateToPlane(beamSpotPos, dirEstUp, testHit);
151 const Amg::Vector3D estPlaneArrivalDn = SeedingAux::extrapolateToPlane(beamSpotPos, dirEstDn, testHit);
152
153 bool below{true}, above{true};
154 switch (classifyStrip(testHit)) {
155 using enum StripOrient;
156 case U:
157 case V:{
158 const double halfLength = 0.5* stripHalfLength(testHit);
160 const Amg::Vector3D leftEdge = testHit.localPosition() - halfLength * testHit.sensorDirection();
161 const Amg::Vector3D rightEdge = testHit.localPosition() + halfLength * testHit.sensorDirection();
162
164 below = estPlaneArrivalDn.y() > std::max(leftEdge.y(), rightEdge.y());
166 above = estPlaneArrivalUp.y() < std::min(leftEdge.y(), rightEdge.y());
167 break;
168 } case X:
169 case C: {
171 const double hY = testHit.localPosition().y();
172 below = estPlaneArrivalDn.y() > hY;
174 above = estPlaneArrivalUp.y() < hY;
175 break;
176 }
177 case P:{
178 break;
179 }
180 case Unknown:{
181 break;
182 }
183
184 }
185 ATH_MSG_VERBOSE("Hit " << m_idHelperSvc->toString(testHit.identify())
186 << (below || above ? " is outside the window" : " is inside the window"));
187 if(below) {
188 return HitWindow::tooLow;
189 }
190 if(above) {
191 return HitWindow::tooHigh;
192 }
193 return HitWindow::inside;
194};
195
197#define TEST_HIT_CORRIDOR(LAYER, HIT_ITER, START_LAYER) \
198{ \
199 const SpacePoint* testMe = combinatoricLayers[LAYER].get()[HIT_ITER]; \
200 if (usedHits[LAYER].get()[HIT_ITER] > m_maxUsed) { \
201 ATH_MSG_VERBOSE(__func__<<":"<<__LINE__<<" - " \
202 <<m_idHelperSvc->toString(testMe->identify()) \
203 <<" already used in good seed." ); \
204 continue; \
205 } \
206 const HitWindow inWindow = hitFromIPCorridor(*testMe, beamSpot, dirEstUp, dirEstDn); \
207 if(inWindow == HitWindow::tooHigh) { \
208 ATH_MSG_VERBOSE(__func__<<":"<<__LINE__<<" - Hit " \
209 <<m_idHelperSvc->toString(testMe->identify()) \
210 <<" is beyond the corridor. Break loop"); \
211 break; \
212 } else if (inWindow == HitWindow::tooLow) { \
213 START_LAYER = HIT_ITER + 1; \
214 ATH_MSG_VERBOSE(__func__<<":"<<__LINE__<<" - Hit " \
215 <<m_idHelperSvc->toString(testMe->identify()) \
216 <<" is still below the corridor. Update start to " \
217 <<START_LAYER); \
218 continue; \
219 } \
220}
221
223 const HitLaySpan_t& combinatoricLayers,
224 const UsedHitSpan_t& usedHits,
225 InitialSeedVec_t& seedHitsFromLayers) const {
227 seedHitsFromLayers.clear();
228 std::size_t maxSize{1};
229 for (const HitVec& hitVec : combinatoricLayers) {
230 maxSize = maxSize * hitVec.size();
231 }
232 seedHitsFromLayers.reserve(maxSize);
233
234 unsigned iterLay0{0}, iterLay1{0}, iterLay2{0}, iterLay3{0};
235 unsigned startLay1{0}, startLay2{0}, startLay3{0};
236
237 for( ; iterLay0 < combinatoricLayers[0].get().size() ; ++iterLay0){
239 if (usedHits[0].get()[iterLay0] > m_maxUsed) {
240 continue;
241 }
242 const SpacePoint* hit0 = combinatoricLayers[0].get()[iterLay0];
244 const Amg::Vector3D initSeedDir{(beamSpot - hit0->localPosition()).unit()};
245 const Amg::Vector3D dirEstUp = Amg::dirFromAngles(initSeedDir.phi(), initSeedDir.theta() - m_windowTheta);
246 const Amg::Vector3D dirEstDn = Amg::dirFromAngles(initSeedDir.phi(), initSeedDir.theta() + m_windowTheta);
247
248 ATH_MSG_VERBOSE("Reference hit: "<<m_idHelperSvc->toString(hit0->identify())
249 <<", position: "<<Amg::toString(hit0->localPosition())
250 <<", seed dir: "<<Amg::toString(initSeedDir)
251 <<", seed plane: "<<Amg::toString(SeedingAux::extrapolateToPlane(beamSpot, initSeedDir, *hit0)));
253 for( iterLay1 = startLay1; iterLay1 < combinatoricLayers[1].get().size() ; ++iterLay1){
254 TEST_HIT_CORRIDOR(1, iterLay1, startLay1);
255 for( iterLay2 = startLay2; iterLay2 < combinatoricLayers[2].get().size() ; ++iterLay2){
256 TEST_HIT_CORRIDOR(2, iterLay2, startLay2);
257 for( iterLay3 = startLay3; iterLay3 < combinatoricLayers[3].get().size(); ++iterLay3){
258 TEST_HIT_CORRIDOR(3, iterLay3, startLay3);
259 seedHitsFromLayers.emplace_back(std::array{hit0, combinatoricLayers[1].get()[iterLay1],
260 combinatoricLayers[2].get()[iterLay2],
261 combinatoricLayers[3].get()[iterLay3]});
262 }
263 }
264 }
265 }
266}
267#undef TEST_HIT_CORRIDOR
268
271 const Amg::Vector3D& direction,
272 const HitLaySpan_t& extensionLayers,
273 const UsedHitSpan_t& usedHits) const {
274
275 //the hits we need to return to extend the segment seed
276 HitVec combinatoricHits;
277
278 for (std::size_t i = 0; i < extensionLayers.size(); ++i) {
279 const HitVec& layer{extensionLayers[i].get()};
280 const Amg::Vector3D extrapPos = SeedingAux::extrapolateToPlane(startPos, direction, *layer.front());
281
282
283 unsigned triedHit{0};
284 HitCandidate precisionHit, noPrecisionHit;
285 ATH_MSG_VERBOSE("Moving to next layer");
286
287 for (unsigned j = 0; j < layer.size(); ++j) {
288 if (usedHits[i].get().at(j) > m_maxUsed) {
289 continue;
290 }
291 auto hit = layer.at(j);
292 const double pull = std::sqrt(SeedingAux::chi2Term(extrapPos, direction, *hit));
293 ATH_MSG_VERBOSE("Trying extension with hit " << m_idHelperSvc->toString(hit->identify())<<" and pull "<<pull);
294 bool isPrecision = isPrecisionHit(*hit);
295 double minPull = isPrecision ? precisionHit.minPull : noPrecisionHit.minPull;
296 //find the hit with the minimum pull (check at least three hits after we have increasing pulls)
297 if (pull > minPull) {
298 triedHit+=1;
299 continue;
300 }
301
302 if(triedHit>3){
303 break;
304 }
305
306 if(isPrecision){
307 precisionHit.spacePoint = hit;
308 precisionHit.minPull = pull;
309 continue;
310 }
311
312 noPrecisionHit.spacePoint = hit;
313 noPrecisionHit.minPull = pull;
314 }
315
316 // complete the seed with the extended hits
317 //we first choose the precision hit and if does not exist then we pick the non precision hit
318 const SpacePoint* bestCand{nullptr};
319 if(precisionHit.minPull < m_minPullThreshold){
320 bestCand = precisionHit.spacePoint;
321 }else if(noPrecisionHit.minPull < m_minPullThreshold){
322 bestCand = noPrecisionHit.spacePoint;
323 }else{
324 ATH_MSG_VERBOSE("No hit found in layer "<<i<<" with pull below threshold "<<m_minPullThreshold);
325 continue;
326 }
327 ATH_MSG_VERBOSE("Extension successfull - hit" << m_idHelperSvc->toString(bestCand->identify())
328 <<", pos: "<<Amg::toString(bestCand->localPosition())
329 <<", dir: "<<Amg::toString(bestCand->sensorDirection()));
330 combinatoricHits.push_back(bestCand);
331 }
332
333 return combinatoricHits;
334}
335
336std::unique_ptr<SegmentSeed>
338 const AmgSymMatrix(2)& bMatrix,
339 const HoughMaximum& max,
340 const HitLaySpan_t& extensionLayers,
341 const UsedHitSpan_t& usedHits) const {
342 bool allValid = std::any_of(initialSeed.begin(), initialSeed.end(),
343 [this](const auto& hit){
344 if (hit->type() == xAOD::UncalibMeasType::MMClusterType) {
345 const auto* mmClust = static_cast<const xAOD::MMCluster*>(hit->primaryMeasurement());
346 return mmClust->stripNumbers().size() >= m_minClusSize;
347 }
348 return true;
349 });
350
351 if (!allValid) {
352 ATH_MSG_VERBOSE("Seed rejection: Not all clusters meet minimum strip size");
353 return nullptr;
354 }
355
356
357 std::array<double, 4> params = defineParameters(bMatrix, initialSeed);
358
359 const auto [segPos, direction] = seedSolution(initialSeed, params);
360
361 // check the consistency of the parameters - expected to lay in the strip's
362 // length
363 for (std::size_t i = 0; i < 4; ++i) {
364 const double halfLength = stripHalfLength(*initialSeed[i]);
365
366 if (std::abs(params[i]) > halfLength) {
367 ATH_MSG_VERBOSE("Seed Rejection: Invalid seed - outside of the strip's length "<< m_idHelperSvc->toString(initialSeed[i]->identify())
368 <<", param: "<<params[i]<<", halfLength: "<<halfLength);
369 return nullptr;
370 }
371 }
372 double tanAlpha = houghTanAlpha(direction);
373 double tanBeta = houghTanBeta(direction);
374
375 double interceptX = segPos.x();
376 double interceptY = segPos.y();
377
378 //seed quality check - we expect the tanAlpha not to be too big which would mean big deflection along the strip layers
379 if(std::abs(tanAlpha) > m_maxTanAlpha){
380 ATH_MSG_VERBOSE("Seed Rejection: Invalid seed - tanAlpha "<<tanAlpha<<" above threshold "<<m_maxTanAlpha);
381 return nullptr;
382 }
383
384
385 // extend the seed to the segment -- include hits from the other layers too
386 auto extendedHits = extendHits(segPos, direction, extensionLayers, usedHits);
387 HitVec hits{initialSeed.begin(),initialSeed.end()};
388 std::ranges::move(extendedHits, std::back_inserter(hits));
389
390 return std::make_unique<SegmentSeed>(tanBeta, interceptY, tanAlpha,
391 interceptX, hits.size(),
392 std::move(hits), max.parentBucket());
393}
394
395
396std::unique_ptr<Segment> NswSegmentFinderAlg::fitSegmentSeed(const EventContext& ctx,
397 const ActsTrk::GeometryContext& gctx,
398 const SegmentSeed* patternSeed) const{
399
400 if(patternSeed->getHitsInMax().size() < m_minSeedHits){
401 ATH_MSG_VERBOSE("Not enough hits in the SegmentSeed to fit a segment");
402 return nullptr;
403 }
404
405 ATH_MSG_VERBOSE("Fit the SegmentSeed");
406 if (msgLvl(MSG::VERBOSE)) {
407 std::stringstream hitStream{};
408 for (const auto& hit : patternSeed->getHitsInMax()) {
409 hitStream<<"**** "<< (*hit)<<std::endl;
410 }
411 ATH_MSG_VERBOSE(__func__<<"() - "<<__LINE__ <<": Uncalibrated space points for the segment fit: "<<std::endl
412 <<hitStream.str());
413 }
414
415 //Calibration of the seed spacepoints
416 CalibSpacePointVec calibratedHits = m_calibTool->calibrate(ctx, patternSeed->getHitsInMax(),
417 patternSeed->localPosition(),
418 patternSeed->localDirection(), 0.);
419
420 const Amg::Transform3D& locToGlob{patternSeed->msSector()->localToGlobalTransform(gctx)};
421
422 return m_lineFitter->fitSegment(ctx, patternSeed, patternSeed->parameters(),
423 locToGlob, std::move(calibratedHits));
424}
425
426void NswSegmentFinderAlg::processSegment(std::unique_ptr<Segment> segment,
427 const HitVec& seedHits,
428 const HitLayVec& hitLayers,
429 UsedHitMarker_t& usedHits,
430 SegmentVec_t& segments) const {
431
432 if (!segment) {
433 ATH_MSG_VERBOSE("Seed Rejection: Segment fit failed");
434
435 if (m_markHitsFromSeed && seedHits.size() > m_minSeedHits) {
436 // Mark hits from extended seed (used increment by 1)
437 markHitsAsUsed(seedHits, hitLayers, usedHits, 1, false);
438 }
439 return;
440 }
441
442 // -------- success path --------
443 ATH_MSG_DEBUG("Segment built with "
444 << segment->measurements().size()
445 << " hits, chi2/ndof: "
446 << segment->chi2() / std::max(1u,segment->nDoF()));
447
448 HitVec segMeasSP;
449 segMeasSP.reserve(segment->measurements().size());
450
451 std::ranges::transform(
452 segment->measurements(),
453 std::back_inserter(segMeasSP),
454 [](const auto& m) { return m->spacePoint(); }
455 );
456
457 // Mark segment hits as fully used (used increment by 10,
458 // hits are effectively removed)
459 markHitsAsUsed(segMeasSP, hitLayers, usedHits, 10, true);
460 segments.push_back(std::move(segment));
461
462}
463
464std::pair<NswSegmentFinderAlg::SegmentSeedVec_t, NswSegmentFinderAlg::SegmentVec_t>
466 const ActsTrk::GeometryContext &gctx,
467 const HitLayVec& hitLayers,
468 const HoughMaximum& max,
469 const Amg::Vector3D& beamSpotPos,
470 UsedHitMarker_t& usedHits) const {
471
472 //go through the layers and build seeds from the combinations of hits
473 //starting from the outermost layers with 2D measurements (excluding pads)
474 SegmentSeedVec_t seeds{};
475 SegmentVec_t segments{};
476 std::size_t layerSize = hitLayers.size();
477 double thetaWindowCut{std::cos(2*m_windowTheta)};
478
479 // lamda helper to check if the spacepoint is combined (but not pad) and unused in an already constructed seed
480 auto isUnusedCombined = [&](std::size_t layIdx, std::size_t hitIdx) -> bool {
481 const SpacePoint* sp = hitLayers[layIdx][hitIdx];
483 THROW_EXCEPTION("Space point is not of sTgc type: "<<sp->msSector()->idHelperSvc()->toString(sp->identify()));
484 }
485 const auto* prd = static_cast<const xAOD::sTgcMeasurement*>(sp->primaryMeasurement());
486 bool isCombined = sTgcChannelType(prd->channelType()) == "S" && sp->dimension() == 2;
487 bool isUnused = usedHits[layIdx].at(hitIdx) <= m_maxUsed;
488 return isCombined && isUnused;
489
490 };
491
492 // find the 2D measurements from the outermost layers - even move one layer inside
493 for(std::size_t layIdx1 = 0; layIdx1 < 2; ++layIdx1){
494 for(std::size_t layIdx2 = layerSize-1; layIdx2 >= layerSize-2; --layIdx2){
495 //in case of MM layers we stop - the layers are sorted in Z
496 if(hitLayers[layIdx1].front()->type() == xAOD::UncalibMeasType::MMClusterType ||
497 hitLayers[layIdx2].front()->type() == xAOD::UncalibMeasType::MMClusterType){
498 ATH_MSG_VERBOSE("Outermost layers are MM - stop searching for sTgc Measurements");
499 return std::make_pair(std::move(seeds), std::move(segments));
500 }
501
502 //check if we have 2D measurements on these layers that are unused (excluding the pads)
503 for(std::size_t hitIdx1 = 0; hitIdx1 < hitLayers[layIdx1].size(); ++hitIdx1) {
504 const SpacePoint* hit1 = hitLayers[layIdx1][hitIdx1];
505 if(!isUnusedCombined(layIdx1, hitIdx1)){
506 continue;
507 }
508 for(std::size_t hitIdx2 = 0; hitIdx2 < hitLayers[layIdx2].size(); ++hitIdx2) {
509 const SpacePoint* hit2 = hitLayers[layIdx2][hitIdx2];
510 if(!isUnusedCombined(layIdx2, hitIdx2)){
511 continue;
512 }
513 //test if this selection of the hits from the two layers is aligned with the beam spot
514 const Amg::Vector3D beamSpotHitDir{(beamSpotPos - hit1->localPosition()).unit()};
515 const Amg::Vector3D seedDir{(hit2->localPosition() - hit1->localPosition()).unit()};
516 const double cosAngle = beamSpotHitDir.dot(seedDir);
517 //accept the deflection of direction with a tolerance of 1 deg
518 if(std::abs(cosAngle) < thetaWindowCut){
519 continue;
520 }
521 //found 2D hits on the outermost layers - build a seed
522 HitVec seedHits{hit1, hit2};
523 //get the seed direction and position from the two 2D hits
524 const Amg::Vector3D seedPos = hit1->localPosition();
525 //express position in z=0
526 const Amg::Vector3D seedPosZ0 = seedPos + Amg::intersect<3>(seedPos, seedDir, Amg::Vector3D::UnitZ(), 0.).value_or(0.)*seedDir;
527 // extend the seed to the other layers
528 HitLaySpan_t extensionLayers{};
529 UsedHitSpan_t usedExtensionHits{};
530 extensionLayers.reserve(hitLayers.size());
531 usedExtensionHits.reserve(hitLayers.size());
532 for (std::size_t e = 0 ; e < hitLayers.size(); ++e) {
533 if (!(e == layIdx1 || e == layIdx2)){
534 extensionLayers.emplace_back(hitLayers[e]);
535 usedExtensionHits.emplace_back(usedHits[e]);
536 }
537 }
538 auto extendedHits = extendHits(seedPosZ0, seedDir, extensionLayers, usedExtensionHits);
539 std::ranges::move(extendedHits, std::back_inserter(seedHits));
540
541 //make seed
542 auto seed = std::make_unique<SegmentSeed>(houghTanBeta(seedDir), seedPosZ0.y(),
543 houghTanAlpha(seedDir), seedPosZ0.x(),
544 seedHits.size(), std::move(seedHits),
545 max.parentBucket());
546
547 //skip segment fit with less than 5 hits
548 if(seed->getHitsInMax().size() < m_minSeedHits){
549 seeds.push_back(std::move(seed));
550 continue;
551 }
552 //fit the segment seed
553 std::unique_ptr<Segment> segment = fitSegmentSeed(ctx, gctx, seed.get());
554 processSegment(std::move(segment), seed->getHitsInMax(), hitLayers, usedHits, segments);
555 seeds.push_back(std::move(seed));
556
557 }
558 }
559 }
560 }
561 return std::make_pair(std::move(seeds),std::move(segments));
562}
563
564std::pair<NswSegmentFinderAlg::SegmentSeedVec_t, NswSegmentFinderAlg::SegmentVec_t>
566 const ActsTrk::GeometryContext &gctx,
567 const HitLayVec& hitLayers,
568 const HoughMaximum& max,
569 const Amg::Vector3D& beamSpotPos,
570 UsedHitMarker_t& usedHits,
571 bool useOnlyMM) const {
572
573 //go through the layers and build seeds from the combinations of hits
574 SegmentSeedVec_t seeds{};
575 SegmentVec_t segments{};
576 std::size_t layerSize = hitLayers.size();
577
578 if(layerSize < minLayers){
579 ATH_MSG_VERBOSE("Not enough layers to build a seed");
580 return {std::move(seeds), std::move(segments)};
581 }
582
583 //lamda helper to find the first unused strip hit on the layer
584 auto unusedStripHit = [&](const HitVec& layerHits, unsigned int layIdx) -> const SpacePoint* {
585 //in case of MM only combinatorial seeding - we consider only MM strip hits for seeding
586 bool isMM = useOnlyMM ? layerHits.front()->type() == xAOD::UncalibMeasType::MMClusterType : true;
587 for (auto [idx, hit] : Acts::enumerate(layerHits)) {
588 auto spOrient = classifyStrip(*hit);
589 bool isStrip = spOrient == StripOrient::X || spOrient == StripOrient::U || spOrient == StripOrient::V;
590 bool isUnused = usedHits[layIdx].at(idx) <= m_maxUsed;
591 if (isStrip && isUnused && isMM) {
592 return hit;
593 }
594 }
595 return nullptr;
596 };
597
598 std::array<const SpacePoint*, 4> seedHits{};
599 InitialSeedVec_t preLimSeeds{};
600
601 for (std::size_t i = 0; i < layerSize - 3; ++i) {
602 seedHits[0] = unusedStripHit(hitLayers[i], i);
603 if(!seedHits[0]) {
604 continue;
605 }
606 for (std::size_t j = i + 1; j < layerSize - 2; ++j) {
607 seedHits[1] = unusedStripHit(hitLayers[j], j);
608 if(!seedHits[1]){
609 continue;
610 }
611 for (std::size_t l = layerSize - 1; l > j+1; --l) {
612 seedHits[3] = unusedStripHit(hitLayers[l], l);
613 if(!seedHits[3]){
614 continue;
615 }
616 for (std::size_t k = l-1; k > j ; --k) {
617 seedHits[2] = unusedStripHit(hitLayers[k], k);
618 if(!seedHits[2]){
619 continue;
620 }
621
622 const HitLaySpan_t layers{hitLayers[i], hitLayers[j], hitLayers[k], hitLayers[l]};
623 //skip combination with at least one too busy layer
624 bool tooBusy = std::ranges::any_of(layers,
625 [this](const auto& layer) {
626 return layer.get().size() > m_maxClustersInLayer;
627 });
628 if (tooBusy) {
629 continue; // skip this combination
630 }
631
632 AmgSymMatrix(2) bMatrix = betaMatrix(seedHits);
633
634 if (std::abs(bMatrix.determinant()) < 1.e-6) {
635 continue;
636 }
637 ATH_MSG_DEBUG("Space point positions for seed layers: \n"
638 <<(*seedHits[0]) << ",\n"
639 <<(*seedHits[1]) << ",\n"
640 <<(*seedHits[2]) << ",\n"
641 <<(*seedHits[3]));
642
643
644 UsedHitSpan_t usedHitsSpan{usedHits[i], usedHits[j], usedHits[k], usedHits[l]};
645 // each layer may have more than one hit - take the hit combinations
646 constructPreliminarySeeds(beamSpotPos, layers, usedHitsSpan, preLimSeeds);
647
648 //the layers not participated in the seed build - gonna be used for the extension
649 HitLaySpan_t extensionLayers{};
650 UsedHitSpan_t usedExtensionHits{};
651 usedExtensionHits.reserve(hitLayers.size());
652 extensionLayers.reserve(hitLayers.size());
653 for (std::size_t e = 0 ; e < hitLayers.size(); ++e) {
654 if (!(e == i || e == j || e == k || e == l)){
655 extensionLayers.emplace_back(hitLayers[e]);
656 usedExtensionHits.emplace_back(usedHits[e]);
657 }
658 }
659 // we have made sure to have hits from all the four layers -
660 // start by 4 hits for the seed and try to build the extended seed for the combinatorics found
661 for (auto &combinatoricHits : preLimSeeds) {
662 auto seed = constructCombinatorialSeed(combinatoricHits, bMatrix, max, extensionLayers, usedExtensionHits);
663 if(!seed){
664 continue;
665 }
666 if (seed->getHitsInMax().size() < m_minSeedHits) {
667 seeds.push_back(std::move(seed));
668 continue;
669 }
670 std::unique_ptr<Segment> segment = fitSegmentSeed(ctx, gctx, seed.get());
671 processSegment(std::move(segment), seed->getHitsInMax(), hitLayers, usedHits, segments);
672 seeds.push_back(std::move(seed));
673
674 }
675 }
676 }
677 }
678 }
679 return std::make_pair(std::move(seeds),std::move(segments));
680}
681
682std::pair<NswSegmentFinderAlg::SegmentSeedVec_t, NswSegmentFinderAlg::SegmentVec_t>
684 const ActsTrk::GeometryContext &gctx,
685 const EventContext& ctx) const {
686 // first sort the hits per layer from the maximum
687 SpacePointPerLayerSplitter hitLayers{max.getHitsInMax()};
688
689 const HitLayVec& stripHitsLayers{hitLayers.stripHits()};
690 const std::size_t layerSize = stripHitsLayers.size();
691
692 //seeds and segments containers
693 SegmentSeedVec_t seeds{};
694 SegmentVec_t segments{};
695
696 const Amg::Transform3D globToLocal = max.msSector()->globalToLocalTransform(gctx);
697 //counters for the number of seeds, extented seeds and segments
698
699 if (layerSize < minLayers) {
700 ATH_MSG_VERBOSE("Not enough layers to build a seed");
701 return std::make_pair(std::move(seeds),std::move(segments));
702 }
703
704 if (m_visionTool.isEnabled()) {
706 constexpr double legX{0.2};
707 double legY{0.8};
708 for (const SpacePoint* sp : max.getHitsInMax()) {
709 const xAOD::MuonSimHit* simHit = getTruthMatchedHit(*sp->primaryMeasurement());
710 if (!simHit) {
711 continue;
712 }
713
714 const MuonGMR4::MuonReadoutElement* reEle = m_detMgr->getReadoutElement(simHit->identify());
715 const Amg::Transform3D toChamb = reEle->msSector()->globalToLocalTransform(gctx) *
716 reEle->localToGlobalTransform(gctx, sp->identify());
717
718 const Amg::Vector3D hitPos = toChamb * xAOD::toEigen(simHit->localPosition());
719 const Amg::Vector3D hitDir = toChamb.linear() * xAOD::toEigen(simHit->localDirection());
720 const double pull = std::sqrt(SeedingAux::chi2Term(hitPos, hitDir, *sp));
721
723 const auto* mmClust = static_cast<const xAOD::MMCluster*>(sp->primaryMeasurement());
724 const MuonGMR4::MmReadoutElement* mmEle = mmClust->readoutElement();
725 const auto& design = mmEle->stripLayer(mmClust->measurementHash()).design();
726 std::string stereoDesign{!design.hasStereoAngle() ? "X" : design.stereoAngle() >0 ? "U": "V"};
727 primitives.push_back(MuonValR4::drawLabel(std::format("ml: {:1d}, gap: {:1d}, {:}, pull: {:.2f}",
728 mmEle->multilayer(), mmClust->gasGap(),
729 stereoDesign, pull), legX, legY, 14));
730 } else if(sp->type() == xAOD::UncalibMeasType::sTgcStripType) {
731 const auto* sTgcMeas = static_cast<const xAOD::sTgcMeasurement*>(sp->primaryMeasurement());
732 std::string channelString = sp->secondaryMeasurement() == nullptr ?
733 sTgcChannelType(sTgcMeas->channelType()) :
734 std::format("{:}/{:}", sTgcChannelType(sTgcMeas->channelType()),
735 sTgcChannelType(static_cast<const xAOD::sTgcMeasurement*>(sp->secondaryMeasurement())->channelType()));
736 primitives.push_back(MuonValR4::drawLabel(std::format("ml: {:1d}, gap: {:1d}, type: {:}, pull: {:.2f}",
737 sTgcMeas->readoutElement()->multilayer(), sTgcMeas->gasGap(),
738 channelString, pull), legX, legY, 14));
739 }
740 legY-=0.05;
741 }
742 m_visionTool->visualizeBucket(ctx, *max.parentBucket(),
743 "truth", std::move(primitives));
744 }
745
746 //dump spacepoints associated with truth sim hits to an obj file
747 if(m_dumpObj){
748 Acts::ObjVisualization3D visualHelper{};
749 for (const SpacePoint* sp : max.getHitsInMax()) {
750 const xAOD::MuonSimHit* simHit = getTruthMatchedHit(*sp->primaryMeasurement());
751 if (!simHit) {
752 continue;
753 }
754 MuonValR4::drawSpacePoint(gctx, *sp, visualHelper);
755 }
756 visualHelper.write(std::format("Event_{:}_{:}_spacepoints_truth.obj", ctx.eventID().event_number(), max.getHitsInMax().front()->chamber()->identString()));
757 }
758
759
760 UsedHitMarker_t allUsedHits = emptyBookKeeper(stripHitsLayers);
761 std::size_t nSeeds{0}, nExtSeeds{0}, nSegments{0}; //for the seed statistics
762
763 // helper lamda function to increase counters and fill the seeds and segments we want to return after we construct them
764 // the extended seeds are returned even if they did not make it to a segment and the segments only if successfully fitted
765 auto processSeedsAndSegments = [&](std::pair<SegmentSeedVec_t, SegmentVec_t>&& seedSegmentPairs, std::string_view source) {
766 auto& [returnSeeds, returnSegments] = seedSegmentPairs;
767 ATH_MSG_DEBUG("From " << source << ": built " << returnSeeds.size() << " seeds and " << returnSegments.size() << " segments.");
768 for(auto& seed : returnSeeds) {
769 ++nSeeds;
770 Acts::ObjVisualization3D visualHelper{};
771 if(seed->getHitsInMax().size() < m_minSeedHits){
772 ATH_MSG_VERBOSE("Seed with "<< seed->getHitsInMax().size() <<" hits rejected");
773 for(const auto& hit : seed->getHitsInMax()){
774 ATH_MSG_VERBOSE("Hit "<<m_idHelperSvc->toString(hit->identify())<<", "
775 <<Amg::toString(hit->localPosition())<<", dir: "
776 <<Amg::toString(hit->sensorDirection()));
777 if(m_dumpObj){
778 MuonValR4::drawSpacePoint(gctx, *hit, visualHelper);
779 }
780
781 }
782 if(m_dumpObj){
783 visualHelper.write(std::format("Event_{:}_{:}_notExtendedSeed.obj", ctx.eventID().event_number(), seed->getHitsInMax().front()->chamber()->identString()));
784 }
785 continue;
786 }
787 ++nExtSeeds;
788 seeds.push_back(std::move(seed));
789 }
790 //move all the segments to the output container
791 std::ranges::move(returnSegments, std::back_inserter(segments));
792 nSegments += returnSegments.size();
793 };
794
795 //Start from outermost sTgc layers with combined 2D measurements
796 ATH_MSG_VERBOSE("Start building seed from sTgc outermost layers");
797 processSeedsAndSegments(buildSegmentsFromSTGC(ctx, gctx, stripHitsLayers, max, globToLocal.translation(), allUsedHits), "sTgc segment seeds");
798
799 //continue with the combinatorial seeding for the strip measurements
801
802 ATH_MSG_VERBOSE("Start building combinatoric seeds only from Micromegas");
803 processSeedsAndSegments(buildSegmentsFromMM(ctx, gctx, stripHitsLayers, max, globToLocal.translation(), allUsedHits, true), "MM combinatoric segment seeds");
804
805 }else{
806
807 ATH_MSG_VERBOSE("Start building combinatoric seeds from Micromegas and sTgc hits");
808 processSeedsAndSegments(buildSegmentsFromMM(ctx, gctx, stripHitsLayers, max, globToLocal.translation(), allUsedHits, true), "MM combinatoric segment seeds");
809 processSeedsAndSegments(buildSegmentsFromMM(ctx, gctx, stripHitsLayers, max, globToLocal.translation(), allUsedHits, false), "MM and STGC combinatoric segment seeds");
810
811 }
812
813 if(m_seedCounter) {
814 m_seedCounter->addToStat(max.msSector(), nSeeds, nExtSeeds, nSegments);
815 }
816
817 return std::make_pair(std::move(seeds),std::move(segments));
818}
819
821 const HitLayVec& allSortHits,
822 UsedHitMarker_t& usedHitMarker,
823 unsigned incr,
824 bool markNeighborHits) const {
825
826 SpacePointPerLayerSorter layerSorter{};
827
828 for(const auto& sp : spacePoints){
829 // Proection against the auxiliary measurement
830 if(!sp){
831 continue;
832 }
833
834 unsigned measLayer = layerSorter.sectorLayerNum(*sp);
835
836 Amg::Vector2D spPosX{Amg::Vector2D::Zero()};
838 switch (sp->primaryMeasurement()->numDimensions()) {
839 case 1:
840 spPosX[Amg::x] = sp->primaryMeasurement()->localPosition<1>().x();
841 break;
842 case 2:
843 spPosX = xAOD::toEigen(sp->primaryMeasurement()->localPosition<2>());
844 break;
845 default:
846 THROW_EXCEPTION("Unsupported dimension");
847 }
848
849 for (std::size_t lIdx = 0; lIdx < allSortHits.size(); ++lIdx) {
850 const HitVec& hVec{allSortHits[lIdx]};
851 //check if they are not in the same layer
852 unsigned hitLayer = layerSorter.sectorLayerNum(*hVec.front());
853 if(hitLayer != measLayer) {
854 ATH_MSG_VERBOSE("Not in the same layer since measLayer = "<< measLayer << " and "<<hitLayer);
855 continue;
856 }
857 for (std::size_t hIdx = 0 ; hIdx < hVec.size(); ++hIdx) {
858 //check the dY between the measurement and the hits
859 auto testHit = hVec[hIdx];
860 if (testHit == sp) {
861 usedHitMarker[lIdx][hIdx] += incr;
862 if(!markNeighborHits){
863 break;
864 }
865 } else if (markNeighborHits) {
866 Amg::Vector2D testPosX{Amg::Vector2D::Zero()};
868 switch (testHit->primaryMeasurement()->numDimensions()) {
869 case 1:
870 testPosX[Amg::x] = testHit->primaryMeasurement()->localPosition<1>().x();
871 break;
872 case 2:
873 testPosX = xAOD::toEigen(testHit->primaryMeasurement()->localPosition<2>());
874 break;
875 default:
876 THROW_EXCEPTION("Unsupported dimension");
877 }
878 //if the hit not found let's see if it is too close to the segment's measurement
879 double deltaX = (testPosX - spPosX).mag();
880 if(deltaX < m_maxdYWindow){
881 usedHitMarker[lIdx][hIdx] += incr;
882 }
883 }
884 }
885 }
886 }
887}
888
889StatusCode NswSegmentFinderAlg::execute(const EventContext &ctx) const {
890 // read the inputs
891 const EtaHoughMaxContainer *maxima{nullptr};
892 ATH_CHECK(SG::get( maxima, m_etaKey, ctx));
893
894 const ActsTrk::GeometryContext *gctx{nullptr};
895 ATH_CHECK(SG::get(gctx, m_geoCtxKey, ctx));
896
897 // prepare our output collection
898 SG::WriteHandle writeSegments{m_writeSegmentKey, ctx};
899 ATH_CHECK(writeSegments.record(std::make_unique<SegmentContainer>()));
900
901 SG::WriteHandle writeSegmentSeeds{m_writeSegmentSeedKey, ctx};
902 ATH_CHECK(writeSegmentSeeds.record(std::make_unique<SegmentSeedContainer>()));
903
904 // we use the information from the previous eta-hough transform
905 // to get the combined hits that belong in the same maxima
906 for (const HoughMaximum *max : *maxima) {
907
908 auto [seeds, segments] = findSegmentsFromMaximum(*max, *gctx, ctx);
909
910 if (msgLvl(MSG::VERBOSE)) {
911 ATH_MSG_VERBOSE("Hits from Hough maximum");
912 for(const auto& hitMax : max->getHitsInMax()){
913 ATH_MSG_VERBOSE("Hit "<<m_idHelperSvc->toString(hitMax->identify())<<", "
914 <<Amg::toString(hitMax->localPosition())<<", dir: "
915 <<Amg::toString(hitMax->sensorDirection()));
916 }
917 }
918
919 for(auto& seed: seeds){
920
921 if (msgLvl(MSG::VERBOSE)){
922 std::stringstream sstr{};
923 sstr<<"Seed tanBeta = "<<seed->tanBeta()<<", y0 = "<<seed->interceptY()
924 <<", tanAlpha = "<<seed->tanAlpha()<<", x0 = "<<seed->interceptX()<<", hits in the seed "
925 <<seed->getHitsInMax().size()<<std::endl;
926
927 for(const auto& hit : seed->getHitsInMax()){
928 sstr<<" *** Hit "<<m_idHelperSvc->toString(hit->identify())<<", "
929 << Amg::toString(hit->localPosition())<<", dir: "<<Amg::toString(hit->sensorDirection())<<std::endl;
930 }
931 ATH_MSG_VERBOSE(sstr.str());
932 }
933 if (m_visionTool.isEnabled()) {
934 m_visionTool->visualizeSeed(ctx, *seed, "#phi-combinatorialSeed");
935 }
936
937 writeSegmentSeeds->push_back(std::move(seed));
938
939 }
940
941 for (auto &seg : segments) {
942 const Parameters pars = localSegmentPars(*gctx, *seg);
943
944 ATH_MSG_VERBOSE("Segment parameters : "<<toString(pars));
945
946 if (m_visionTool.isEnabled()) {
947 m_visionTool->visualizeSegment(ctx, *seg, "#phi-segment");
948 }
949
950 if(m_dumpObj){
951 Acts::ObjVisualization3D visualHelper{};
952 MuonValR4::drawSegmentMeasurements(*gctx, *seg, visualHelper);
953 MuonValR4::drawSegmentLine(*gctx, *seg, visualHelper);
954 visualHelper.write(std::format("Event_{:}_segment_{:}.obj", ctx.eventID().event_number(), seg->msSector()->identString()));
955 }
956
957 writeSegments->push_back(std::move(seg));
958
959 }
960 }
961
962 return StatusCode::SUCCESS;
963}
964
966 if(m_seedCounter) {
967 m_seedCounter->printTableSeedStats(msgStream());
968 }
969 return StatusCode::SUCCESS;
970}
971
972void NswSegmentFinderAlg::SeedStatistics::addToStat(const MuonGMR4::SpectrometerSector* msSector, unsigned seeds, unsigned extSeeds, unsigned segments){
973 std::unique_lock guard{m_mutex};
974 SectorField key{};
975 key.chIdx = msSector->chamberIndex();
976 key.phi = msSector->stationPhi();
977 key.eta = msSector->chambers().front()->stationEta();
978
979 auto &entry = m_seedStat[key];
980 entry.nSeeds += seeds;
981 entry.nExtSeeds += extSeeds;
982 entry.nSegments += segments;
983}
984
986
987
988 std::stringstream sstr{};
989 sstr<<"Seed statistics per sector:"<<std::endl;
990 sstr<<"-----------------------------------------------------"<<std::endl;
991 sstr<<"| Chamber | Phi | Eta | Seeds | ExtSeeds | Segments |"<<std::endl;
992 sstr<<"-----------------------------------------------------"<<std::endl;
993
994 using namespace Muon::MuonStationIndex;
995
996 for (const auto& [sector, stats] : m_seedStat) {
997 sstr << "| " << std::setw(3) << chName(sector.chIdx)
998 << " | " << std::setw(2) << static_cast<unsigned>(sector.phi)
999 << " | " << std::setw(3) << static_cast<int>(sector.eta)
1000 << " | " << std::setw(7) << stats.nSeeds
1001 << " | " << std::setw(8) << stats.nExtSeeds
1002 << " | " << std::setw(8) << stats.nSegments
1003 << " |"<<std::endl;
1004 }
1005
1006 sstr<<"------------------------------------------------------------"<<std::endl;
1007 msg<<MSG::ALWAYS<<"\n"<<sstr.str()<<endmsg;
1008 }
1009
1010
1011} // namespace MuonR4
const boost::regex re(r_e)
Scalar mag() const
mag method
#define endmsg
#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)
#define ATH_MSG_DEBUG(x)
#define AmgSymMatrix(dim)
ATLAS-specific HepMC functions.
static Double_t sp
static Double_t P(Double_t *tt, Double_t *par)
#define TEST_HIT_CORRIDOR(LAYER, HIT_ITER, START_LAYER)
Macro to check whether a hit is compatible with the hit corridor.
size_t size() const
Number of registered mappings.
#define x
#define max(a, b)
Definition cfImp.cxx:41
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
const StripLayer & stripLayer(const Identifier &measId) const
int multilayer() const
Returns the multi layer of the element [1-2].
MuonReadoutElement is an abstract class representing the geometry of a muon detector.
const Amg::Transform3D & localToGlobalTransform(const ActsTrk::GeometryContext &ctx) const
Returns the transformation from the local coordinate system of the readout element into the global AT...
const SpectrometerSector * msSector() const
Returns the pointer to the envelope volume enclosing all chambers in the sector.
A spectrometer sector forms the envelope of all chambers that are placed in the same MS sector & laye...
const Amg::Transform3D & localToGlobalTransform(const ActsTrk::GeometryContext &gctx) const
Returns the local -> global tarnsformation from the sector.
Amg::Transform3D globalToLocalTransform(const ActsTrk::GeometryContext &gctx) const
Returns the global -> local transformation from the ATLAS global.
const ChamberSet & chambers() const
Returns the associated chambers with this sector.
int stationPhi() const
: Returns the station phi of the sector
Muon::MuonStationIndex::ChIndex chamberIndex() const
Returns the chamber index scheme.
const StripDesign & design(bool phiView=false) const
Returns the underlying strip design.
Data class to represent an eta maximum in hough space.
std::vector< CalibSpacePointPtr > CalibSpacePointVec
void addToStat(const MuonGMR4::SpectrometerSector *msSector, unsigned int nSeeds, unsigned int nExtSeeds, unsigned int nSegments)
const MuonGMR4::MuonDetectorManager * m_detMgr
UnsignedIntegerProperty m_maxUsed
std::pair< SegmentSeedVec_t, SegmentVec_t > findSegmentsFromMaximum(const HoughMaximum &max, const ActsTrk::GeometryContext &gctx, const EventContext &ctx) const
Find seed and segment from an eta hough maximum.
std::unique_ptr< SegmentSeed > constructCombinatorialSeed(const InitialSeed_t &initialSeed, const AmgSymMatrix(2)&bMatrix, const HoughMaximum &max, const HitLaySpan_t &extensionLayers, const UsedHitSpan_t &usedHits) const
Construct a combinatorial seed from the initial 4-layer seed hits.
std::unique_ptr< SegmentFit::SegmentLineFitter > m_lineFitter
std::pair< SegmentSeedVec_t, SegmentVec_t > buildSegmentsFromMM(const EventContext &ctx, const ActsTrk::GeometryContext &gctx, const HitLayVec &hitLayers, const HoughMaximum &max, const Amg::Vector3D &beamSpotPos, UsedHitMarker_t &usedHits, bool useOnlyMM) const
Build the final segment seed from strip like measurements using the combinatorial seeding for MicroMe...
UnsignedIntegerProperty m_maxClustersInLayer
virtual StatusCode initialize() override
virtual StatusCode execute(const EventContext &ctx) const override
std::pair< SegmentSeedVec_t, SegmentVec_t > buildSegmentsFromSTGC(const EventContext &ctx, const ActsTrk::GeometryContext &gctx, const HitLayVec &hitLayers, const HoughMaximum &max, const Amg::Vector3D &beamSpotPos, UsedHitMarker_t &usedHits) const
Build the segment for a seed from STGC 2D measurement layers directly and then attempt to append hits...
HitWindow
To fastly check whether a hit is roughly compatible with a muon trajectory a narrow corridor is opene...
@ inside
The hit is below the predefined corridor.
@ tooHigh
The hit is inside the defined window and hence an initial candidate.
std::unique_ptr< Segment > fitSegmentSeed(const EventContext &ctx, const ActsTrk::GeometryContext &gctx, const SegmentSeed *patternSeed) const
Fit the segment seeds.
ToolHandle< MuonValR4::IPatternVisualizationTool > m_visionTool
Pattern visualization tool.
std::vector< std::reference_wrapper< const HitVec > > HitLaySpan_t
Abbrivation of the space comprising multiple hit vectors without copy.
std::array< const SpacePoint *, 4 > InitialSeed_t
Abbrivation of the initial seed.
SG::WriteHandleKey< SegmentSeedContainer > m_writeSegmentSeedKey
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.
std::vector< std::unique_ptr< SegmentSeed > > SegmentSeedVec_t
Abbrivation of the seed vector.
void constructPreliminarySeeds(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.
void processSegment(std::unique_ptr< Segment > segment, const HitVec &seedHits, const HitLayVec &hitLayers, UsedHitMarker_t &usedHits, SegmentVec_t &segments) const
Process the segment and mark the hits if it is successfully built or not by differently mark the hits...
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...
UsedHitMarker_t emptyBookKeeper(const HitLayVec &sortedSp) const
Constructs an empty HitMarker from the split space points.
virtual StatusCode finalize() override
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
SpacePointPerLayerSplitter::HitLayVec HitLayVec
SpacePointPerLayerSplitter::HitVec HitVec
std::vector< InitialSeed_t > InitialSeedVec_t
Vector of initial seeds.
StripOrient classifyStrip(const SpacePoint &spacePoint) const
Determines the orientation of the strip space point.
StripOrient
Enumeration to classify the orientation of a NSW strip.
@ X
Stereo strips with negative angle.
@ V
Stereo strips with positive angle.
@ Unknown
Combined 2D space point (sTGC wire + strip / sTgc pad).
std::vector< std::unique_ptr< Segment > > SegmentVec_t
Abbrivation of the final segment vector.
SG::WriteHandleKey< SegmentContainer > m_writeSegmentKey
SG::ReadHandleKey< ActsTrk::GeometryContext > m_geoCtxKey
std::vector< std::vector< unsigned int > > UsedHitMarker_t
Abbrivation of the container book keeping whether a hit is used or not.
ToolHandle< ISpacePointCalibrator > m_calibTool
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.
UnsignedIntegerProperty m_minSeedHits
SG::ReadHandleKey< EtaHoughMaxContainer > m_etaKey
std::vector< std::reference_wrapper< std::vector< unsigned int > > > UsedHitSpan_t
Abbrivation of the container to pass a subset of markers wtihout copy.
Representation of a segment seed (a fully processed hough maximum) produced by the hough transform.
Definition SegmentSeed.h:14
const std::vector< HitType > & getHitsInMax() const
Returns the list of assigned hits.
const Parameters & parameters() const
Returns the parameter array.
Amg::Vector3D localDirection() const
Returns the direction of the seed in the sector frame.
const MuonGMR4::SpectrometerSector * msSector() const
Returns the associated chamber.
Amg::Vector3D localPosition() const
Returns the position of the seed in the sector frame.
The SpacePointPerLayerSorter sort two given space points by their layer Identifier.
unsigned int sectorLayerNum(const SpacePoint &sp) const
method returning the logic layer number
The SpacePointPerLayerSplitter takes a set of spacepoints already sorted by layer Identifier (see Muo...
const HitLayVec & stripHits() const
Returns the sorted strip hits.
The muon space point is the combination of two uncalibrated measurements one of them measures the eta...
const Identifier & identify() const
: Identifier of the primary measurement
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ConstVectorMap< 3 > localDirection() const
Returns the local direction of the traversing particle.
Identifier identify() const
Returns the global ATLAS identifier of the SimHit.
ConstVectorMap< 3 > localPosition() const
Returns the local postion of the traversing particle.
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:132
struct color C
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.
Amg::Vector3D dirFromAngles(const double phi, const double theta)
Constructs a direction vector from the azimuthal & polar angles.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
Parameters localSegmentPars(const xAOD::MuonSegment &seg)
Returns the localSegPars decoration from a xAODMuon::Segment.
Acts::Experimental::CompositeSpacePointLineFitter::ParamVec_t Parameters
std::string toString(const Parameters &pars)
Dumps the parameters into a string with labels in front of each number.
This header ties the generic definitions in this package.
ISpacePointCalibrator::CalibSpacePointVec CalibSpacePointVec
double houghTanBeta(const Amg::Vector3D &v)
Returns the hough tanBeta [y] / [z].
DataVector< HoughMaximum > EtaHoughMaxContainer
const xAOD::MuonSimHit * getTruthMatchedHit(const xAOD::MuonMeasurement &prdHit)
Returns the MuonSimHit, if there's any, matched to the uncalibrated muon measurement.
constexpr unsigned minLayers
bool isPrecisionHit(const SpacePoint &hit)
Returns whether the uncalibrated spacepoint is a precision hit (Mdt, micromegas, stgc strips).
SpacePointPerLayerSplitter::HitVec HitVec
double houghTanAlpha(const Amg::Vector3D &v)
: Returns the hough tanAlpha [x] / [z]
std::unique_ptr< TLatex > drawLabel(const std::string &text, const double xPos, const double yPos, const double textSize=18, const bool useNDC=true, const int color=kBlack)
Create a TLatex label,.
void drawSpacePoint(const ActsTrk::GeometryContext &gctx, const MuonR4::SpacePoint &spacePoint, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewSensitive)
Draw an uncalibrated space point inside the obj file.
void drawSegmentMeasurements(const ActsTrk::GeometryContext &gctx, const xAOD::MuonSegment &segment, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewSensitive)
Draw all uncalibrated measurements associated to the segment.
void drawSegmentLine(const ActsTrk::GeometryContext &gctx, const xAOD::MuonSegment &segment, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewLine, const double standardLength=1.*Gaudi::Units::m)
Draw a segment line inside the obj file.
const std::string & chName(ChIndex index)
convert ChIndex into a string
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
Definition MuonSimHit.h:12
MMCluster_v1 MMCluster
sTgcMeasurement_v1 sTgcMeasurement
const ISpacePointCalibrator * calibrator
Pointer to the calibrator.
const Muon::IMuonIdHelperSvc * idHelperSvc
Pointer to the idHelperSvc.
const MuonValR4::IPatternVisualizationTool * visionTool
Pointer to the visualization tool.
#define THROW_EXCEPTION(MESSAGE)
Definition throwExcept.h:10