ATLAS Offline Software
MsTrackSeeder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
7 
8 namespace MuonR4{
10 
11  MsTrackSeeder::MsTrackSeeder(const std::string& msgName, Config&& cfg):
12  AthMessaging{msgName},
13  m_cfg{std::move(cfg)}{}
14 
16  const Location loc) const {
17  const Amg::Vector3D pos{segment.position()};
18  const Amg::Vector3D dir{segment.direction()};
19 
20  const Amg::Vector2D projPos{pos.perp(), pos.z()};
21  const Amg::Vector2D projDir{dir.perp(), dir.z()};
22 
23  double lambda{0.};
24  if (Location::Barrel == loc) {
25  lambda = Amg::intersect<2>(projPos, projDir, Amg::Vector2D::UnitX(),
26  m_cfg.barrelRadius).value_or(10. * Gaudi::Units::km);
27  } else {
28  lambda = Amg::intersect<2>(projPos, projDir, Amg::Vector2D::UnitY(),
29  sign(projPos[1])* m_cfg.endcapDiscZ).value_or(10. * Gaudi::Units::km);
30  }
31  return projPos + lambda * projDir;
32  }
34  const Location loc) const {
35  using enum Location;
36  if (loc == Barrel && std::abs(projPos[1]) > std::min(m_cfg.endcapDiscZ, m_cfg.barrelLength)) {
37  ATH_MSG_VERBOSE(__func__<<"() "<<__LINE__<<" Position "<<Amg::toString(projPos)<<
38  "exceeds cylinder boundaries ("<<m_cfg.barrelRadius<<", "
40  return false;
41  } else if (loc == Endcap && (0 > projPos[0] || projPos[0] > m_cfg.endcapDiscRadius)) {
42  ATH_MSG_VERBOSE(__func__<<"() "<<__LINE__<<" Position "<<Amg::toString(projPos)<<
43  "exceeds endcap boundaries ("<<m_cfg.endcapDiscRadius<<", "<<(sign(projPos[1])*m_cfg.endcapDiscZ)<<")");
44  return false;
45  }
46  return true;
47  }
49  const Location loc,
50  TreeRawVec_t& outContainer) const {
51 
52  const Amg::Vector2D refPoint{expressOnCylinder(*segment, loc)};
53  ATH_MSG_VERBOSE(__func__<<"() "<<__LINE__<<" - Try to add new segment: "
54  <<detailedSegment(*segment)->msSector()->identString()<<" "
55  <<Amg::toString(segment->position())<<" + "<<Amg::toString(segment->direction())
56  <<" --> "<<Amg::toString(refPoint));
57  if (!withinBounds(refPoint, loc)) {
58  return;
59  }
60  std::array<double, 3> coords{};
61  coords[eDetSection] = sign(refPoint[1]) * static_cast<int>(loc);
62  const int sector = detailedSegment(*segment)->msSector()->sector();
63  coords[eSector] = sector;
64  coords[ePosOnCylinder] = refPoint[Location::Barrel == loc];
65  outContainer.emplace_back(std::move(coords), segment);
67  if (sector == 1 || sector== 16) {
68  outContainer.emplace_back(outContainer.back()).first[eSector] = (sector == 1 ? 17 : 0);
69  }
70  }
72  TreeRawVec_t rawData{};
73  rawData.reserve(2*segments.size());
74  for (const xAOD::MuonSegment* segment : segments){
77  }
78  ATH_MSG_VERBOSE("Create a new tree with "<<rawData.size()<<" entries. ");
79  return SearchTree_t{std::move(rawData)};
80  }
81  std::unique_ptr<MsTrackSeedContainer> MsTrackSeeder::findTrackSeeds(const EventContext& ctx,
82  const xAOD::MuonSegmentContainer& segments) const {
83  SearchTree_t orderedSegs{constructTree(segments)};
84  MsTrackSeedContainer trackSeeds{};
85 
86  for (const auto& [coords, seedCandidate] : orderedSegs) {
89  const Segment* recoCandidate = detailedSegment(*seedCandidate);
90  if (coords[eSector] == 0 || coords[eSector] == 17 ||
91  !m_cfg.selector->passSeedingQuality(ctx, *recoCandidate)){
92  continue;
93  }
95  SearchTree_t::range_t selectRange{};
98  selectRange[eDetSection].shrink(coords[eDetSection] - 0.1, coords[eDetSection] + 0.1);
100  selectRange[ePosOnCylinder].shrink(coords[ePosOnCylinder] - m_cfg.seedHalfLength,
103  selectRange[eSector].shrink(coords[eSector]-1.25, coords[eSector] + 1.25);
104 
105  MsTrackSeed newSeed{static_cast<Location>(std::abs(coords[eDetSection]))};
108  orderedSegs.rangeSearchMapDiscard(selectRange, [this, &ctx, &newSeed, &recoCandidate](
109  const SearchTree_t::coordinate_t& /*coords*/,
110  const xAOD::MuonSegment* extendWithMe) {
112  const Segment* extendCandidate = detailedSegment(*extendWithMe);
113  if (m_cfg.selector->compatibleForTrack(ctx, *recoCandidate, *extendCandidate)) {
114  newSeed.addSegment(extendWithMe);
115  }
116  });
118  if (newSeed.segments().empty()) {
119  continue;
120  }
121  newSeed.addSegment(seedCandidate);
123  const double r = newSeed.location() == Location::Barrel ? m_cfg.barrelRadius : coords[ePosOnCylinder];
124  const double z = newSeed.location() == Location::Barrel ? coords[ePosOnCylinder]
125  : coords[eDetSection]* m_cfg.endcapDiscZ;
126  Amg::Vector3D pos = r * Amg::dirFromAngles(seedCandidate->position().phi(), 90. * Gaudi::Units::deg)
127  + z * Amg::Vector3D::UnitZ();
128 
129  newSeed.setPosition(std::move(pos));
130  trackSeeds.emplace_back(std::move(newSeed));
131  }
132  return resolveOverlaps(std::move(trackSeeds));
133  }
134  std::unique_ptr<MsTrackSeedContainer>
136 
138  std::ranges::sort(unresolved, [](const MsTrackSeed& a, const MsTrackSeed&b) {
139  return a.segments().size() > b.segments().size();
140  });
141  auto outputSeeds = std::make_unique<MsTrackSeedContainer>();
142  outputSeeds->reserve(unresolved.size());
143  std::ranges::copy_if(std::move(unresolved), std::back_inserter(*outputSeeds),
144  [this, &outputSeeds](const MsTrackSeed& testMe) {
146  const bool add = std::ranges::none_of(*outputSeeds, [&testMe](const MsTrackSeed& goodSeed){
147  return testMe < goodSeed;
148  });
149  if (add) {
150  ATH_MSG_VERBOSE("Add new seed "<<std::endl<<testMe);
151  }
152  return add;
153  });
154  return outputSeeds;
155  }
156 }
MuonR4::MsTrackSeed::Location::Barrel
@ Barrel
beamspotman.r
def r
Definition: beamspotman.py:674
MuonR4::MsTrackSeeder::findTrackSeeds
std::unique_ptr< MsTrackSeedContainer > findTrackSeeds(const EventContext &ctx, const xAOD::MuonSegmentContainer &segments) const
Constructs the MS track seeds from the segment container.
Definition: MsTrackSeeder.cxx:81
MuonGMR4::SpectrometerSector::sector
int sector() const
Returns the sector of the MS-sector.
Definition: SpectrometerSector.cxx:64
MuonR4::ISegmentSelectionTool::passSeedingQuality
virtual bool passSeedingQuality(const EventContext &ctx, const Segment &segment) const =0
Returns whether a segment provides enough mdt & phi measurements to use it for track finding seeding.
MuonR4::MsTrackSeeder::Config::barrelRadius
double barrelRadius
The radius of the barrel cylinder to seed.
Definition: MsTrackSeeder.h:30
MuonR4::MsTrackSeeder::withinBounds
bool withinBounds(const Amg::Vector2D &projPos, const Location loc) const
Returns whether the expression on the cylinder is within the surface bounds.
Definition: MsTrackSeeder.cxx:33
MuonR4::MsTrackSeeder::Config::barrelLength
double barrelLength
The maximum length of the barrel cylinder, if not capped by the placement of the endcap discs.
Definition: MsTrackSeeder.h:33
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
MuonR4::MsTrackSeed
Definition: MsTrackSeed.h:18
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
MuonR4::ISegmentSelectionTool::compatibleForTrack
virtual bool compatibleForTrack(const EventContext &ctx, const Segment &segA, const Segment &segB) const =0
Returns whether a segment passes the base selection quality in order to be picked up onto a track.
MuonR4::Segment
Placeholder for what will later be the muon segment EDM representation.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:19
MsTrackSeeder.h
MuonR4::MsTrackSeeder::SearchTree_t
Acts::KDTree< 3, const xAOD::MuonSegment *, double, std::array, 6 > SearchTree_t
Definition of the search tree class.
Definition: MsTrackSeeder.h:46
deg
#define deg
Definition: SbPolyhedron.cxx:17
xAOD::MuonSegment_v1
Class describing a MuonSegment.
Definition: MuonSegment_v1.h:33
MuonR4::MsTrackSeed::Location::Endcap
@ Endcap
MuonR4::MsTrackSeeder::appendSegment
void appendSegment(const xAOD::MuonSegment *segment, const Location loc, TreeRawVec_t &outContainer) const
Append the to the raw data container.
Definition: MsTrackSeeder.cxx:48
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MuonR4::MsTrackSeeder::eSector
@ eSector
Sector of the associated spectrometer sector.
Definition: MsTrackSeeder.h:54
MuonR4::MsTrackSeeder::Config::endcapDiscZ
double endcapDiscZ
Position of the endcap discs.
Definition: MsTrackSeeder.h:35
MuonGMR4::SpectrometerSector::identString
std::string identString() const
Returns a string encoding the chamber index & the sector of the MS sector.
Definition: SpectrometerSector.cxx:66
MatrixUtils.h
MuonR4::MsTrackSeed::Location
Location
Enum defining whether the seed is made in the endcap / barrel.
Definition: MsTrackSeed.h:21
MuonR4::detailedSegment
const Segment * detailedSegment(const xAOD::MuonSegment &seg)
Helper function to navigate from the xAOD::MuonSegment to the MuonR4::Segment.
Definition: TrackingHelpers.cxx:7
MuonR4::MsTrackSeeder::m_cfg
Config m_cfg
Definition: MsTrackSeeder.h:98
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
MuonR4::MsTrackSeeder::constructTree
SearchTree_t constructTree(const xAOD::MuonSegmentContainer &segments) const
Construct a complete search tree from a MuonSegment container.
Definition: MsTrackSeeder.cxx:71
z
#define z
MuonR4::MsTrackSeeder::TreeRawVec_t
SearchTree_t::vector_t TreeRawVec_t
Abbrivation of the KDTree raw data vector.
Definition: MsTrackSeeder.h:84
AnalysisUtils::copy_if
Out copy_if(In first, const In &last, Out res, const Pred &p)
Definition: IFilterUtils.h:30
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
MuonR4::MsTrackSeeder::Location
MsTrackSeed::Location Location
Enum toggling whether the segment is in the endcap or barrel.
Definition: MsTrackSeeder.h:48
python.SystemOfUnits.km
float km
Definition: SystemOfUnits.py:110
MuonR4::Segment::msSector
const MuonGMR4::SpectrometerSector * msSector() const
Returns the associated MS sector.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:39
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
beamspotman.dir
string dir
Definition: beamspotman.py:621
MuonR4::MsTrackSeeder::ePosOnCylinder
@ ePosOnCylinder
Extrapolation position along the cylinder surface.
Definition: MsTrackSeeder.h:56
TrackingHelpers.h
MuonR4::sign
constexpr double sign(const double x)
Returns the sign of a number.
Definition: MatrixUtils.h:11
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:76
MuonR4::MsTrackSeeder::Config::endcapDiscRadius
double endcapDiscRadius
Radius of the endcap discs.
Definition: MsTrackSeeder.h:37
MuonR4::SearchTree_t
MsTrackSeeder::SearchTree_t SearchTree_t
Definition: MsTrackSeeder.cxx:9
MuonR4::MsTrackSeeder::Config::seedHalfLength
double seedHalfLength
Maximum separation of point on the cylinder to be picked up onto a seed.
Definition: MsTrackSeeder.h:40
WriteCaloSwCorrections.cfg
cfg
Definition: WriteCaloSwCorrections.py:23
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:16
Amg::dirFromAngles
Amg::Vector3D dirFromAngles(const double phi, const double theta)
Constructs a direction vector from the azimuthal & polar angles.
Definition: GeoPrimitivesHelpers.h:299
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
MuonR4::MsTrackSeeder::Config::selector
const ISegmentSelectionTool * selector
Pointer to the segement selection tool which compares two segments for their compatibilitiy.
Definition: MsTrackSeeder.h:43
a
TList * a
Definition: liststreamerinfos.cxx:10
MuonR4::MsTrackSeedContainer
std::vector< MsTrackSeed > MsTrackSeedContainer
Definition: MsTrackSeed.h:61
MuonR4::MsTrackSeeder::resolveOverlaps
std::unique_ptr< MsTrackSeedContainer > resolveOverlaps(MsTrackSeedContainer &&unresolved) const
Removes exact duplciates or partial subsets of the MsTrackSeeds.
Definition: MsTrackSeeder.cxx:135
MuonR4::MsTrackSeeder::Config
Definition: MsTrackSeeder.h:28
MuonR4::MsTrackSeed::addSegment
void addSegment(const xAOD::MuonSegment *seg)
Append a segment to the seed.
Definition: MsTrackSeed.cxx:55
MuonR4::MsTrackSeeder::expressOnCylinder
Amg::Vector2D expressOnCylinder(const xAOD::MuonSegment &segment, const Location loc) const
Expresses the segment on the cylinder surface.
Definition: MsTrackSeeder.cxx:15
MuonR4::MsTrackSeeder::eDetSection
@ eDetSection
Encode the seed location (-1,1 -> endcaps, 0 -> barrel
Definition: MsTrackSeeder.h:52
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5
MuonR4::MsTrackSeeder::MsTrackSeeder
MsTrackSeeder(const std::string &msgName, Config &&cfg)
Standard constructor.
Definition: MsTrackSeeder.cxx:11