ATLAS Offline Software
MuPatTrack.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <algorithm>
8 
10 #include "TrkTrack/Track.h"
11 
12 namespace Muon {
13 
14  // Static functions
15 
17  static const unsigned int maxlen = []() -> unsigned int {
18  const std::vector<std::string>& pss = processingStageStrings();
19  auto it = std::max_element(pss.begin(), pss.end(),
20  [](const std::string& lhs, const std::string& rhs) { return lhs.size() < rhs.size(); });
21 
22  if (it != pss.end())
23  return it->size();
24  return 0u;
25  }();
26 
27  return maxlen;
28  }
29 
30  std::vector<std::string> MuPatTrack::initProcessingStageStrings() {
31  std::vector<std::string> pss;
32  pss.resize(NumberOfProcessingStages + 1);
33  pss[Unknown] = "Unknown";
34  pss[InitialLoop] = "InitialLoop";
35  pss[LayerRecovery] = "LayerRecov";
36  pss[ExtendedWithSegment] = "ExtWSegment";
37  pss[SegmentRecovery] = "SegmentRecov";
38  pss[FitRemovedSegment] = "FitRmSegment";
39  pss[RefitRemovedSegment] = "RefitRmSegment";
40  pss[AmbiguityCreateCandidateFromSeeds] = "AmbiCreate";
41  pss[AmbiguitySelectCandidates] = "AmbiSelect";
42  pss[MatchFail] = "MatchFail";
43  pss[FitFail] = "FitFail";
44  pss[FitWorse] = "FitWorse";
45  pss[UnassociatedEM] = "UnassocEM";
46  pss[FitRemovedLayer] = "FitRmLayer";
47  pss[TrackSelector] = "TrackSelect";
48  pss[KeptUntilEndOfCombi] = "--KEPT--";
49  pss[NumberOfProcessingStages] = "OutOfBounds";
50 
51  return pss;
52  }
53 
54  const std::vector<std::string>& MuPatTrack::processingStageStrings()
55  {
56  static const std::vector<std::string> processingStrings =
58  return processingStrings;
59  }
60 
62  const std::vector<std::string>& pss = processingStageStrings();
63 
64  if (static_cast<size_t>(stage) < pss.size()) {
65  return pss[static_cast<size_t>(stage)];
66  } else {
67  return pss[NumberOfProcessingStages];
68  }
69  }
70 
71  // member functions
72  MuPatTrack::MuPatTrack(const std::vector<MuPatSegment*>& segments, std::unique_ptr<Trk::Track>& track, MuPatSegment* seedSeg) :
73  MuPatCandidateBase(), m_segments(segments) {
74 
75  m_track.swap(track);
76  // increase segment counters
79 
80  // now update links between tracks and segments
81  updateSegments(true);
82 
83  if (seedSeg){
84  m_seedSeg = seedSeg;
85  addToTrash(seedSeg->garbage());
86  } else if (!segments.empty())
87  m_seedSeg = segments[0];
88  for (MuPatSegment* seg : segments){
89  addToTrash(seg->garbage());
90  }
91  }
92 
93  MuPatTrack::MuPatTrack(MuPatSegment* segment, std::unique_ptr<Trk::Track>& track) :
95  m_track.swap(track);
96 
97  m_segments.reserve(3);
98  m_segments.push_back(segment);
99  addToTrash(segment->garbage());
100  // increase segment counters
103 
104  // now update links between tracks and segments
105  updateSegments(true);
106 
107  }
108 
109  MuPatTrack::MuPatTrack(MuPatSegment* segment1, MuPatSegment* segment2, std::unique_ptr<Trk::Track>& track, MuPatSegment* seedSeg) :
111  m_track.swap(track);
112 
113  m_segments.reserve(3);
114  m_segments.push_back(segment1);
115  m_segments.push_back(segment2);
116  // increase segment counters
119 
120  // now update links between tracks and segments
121  updateSegments(true);
122 
123  m_excludedSegments.clear();
124  if (seedSeg)
125  m_seedSeg = seedSeg;
126  else
127  m_seedSeg = segment1 ? segment1 : segment2;
128  for (MuPatSegment* seg : {segment1, segment2, seedSeg}) {
129  if (seg) addToTrash(seg->garbage());
130  }
131  }
132 
134  // now update links between tracks and segments
135  updateSegments(false);
136  }
137 
140  Trk::ObjectCounter<MuPatTrack>(can),
141  created(can.created),
142  lastSegmentChange(can.lastSegmentChange),
143  m_segments(can.m_segments),
144  m_excludedSegments(can.m_excludedSegments),
145  m_track (std::make_unique<Trk::Track>(can.track())),
146  m_seedSeg(can.m_seedSeg) {
147  m_hasMomentum = can.m_hasMomentum;
148  // increase segment counters
150 
151  // now update links between tracks and segments
152  updateSegments(true);
153  }
154 
156  if (&can != this) {
157 
158  // now update links between tracks and segments, remove old links
159  updateSegments(false);
160 
161  // decrease old segment counters
163 
164  // copy members
165  MuPatCandidateBase::operator=(can);
166  created = can.created;
167  lastSegmentChange = can.lastSegmentChange;
168  m_segments = can.m_segments;
169  m_excludedSegments = can.m_excludedSegments;
170 
171  m_track = std::make_unique<Trk::Track>(can.track());
172  m_chambers = can.m_chambers;
173  m_stations = can.m_stations;
174  m_hasMomentum = can.m_hasMomentum;
175  m_seedSeg = can.m_seedSeg;
176 
177  // increase new segment counters
179 
180  // now update links between tracks and segments, add new segments
181  updateSegments(true);
182  }
183  return *this;
184  }
185 
186  bool MuPatTrack::hasMomentum() const {
187  if (!m_track) return false;
188  return hasMomentum(*m_track);
189  }
190 
192  // use track info if set properly
194 
195  bool hasMom = false;
196  const Trk::Perigee* pp = track.perigeeParameters();
197  if (pp) {
198  const AmgSymMatrix(5)* cov = pp->covariance();
199  if (cov) {
200  // sum covariance terms of momentum, use it to determine whether fit was SL fit
201  double momCov = 0.;
202  for (int i = 0; i < 4; ++i) momCov += std::abs((*cov)(4, i));
203  for (int i = 0; i < 4; ++i) momCov += std::abs((*cov)(i, 4));
204  if (momCov > 1e-10) { hasMom = true; }
205  }
206  }
207  return hasMom;
208  }
209 
210  void MuPatTrack::updateTrack(std::unique_ptr<Trk::Track>& track) { m_track.swap(track); }
211 
215  }
216  void MuPatTrack::addSegment(MuPatSegment* segment, std::unique_ptr<Trk::Track>& newTrack) {
217  // add segment and increase counter
218  m_segments.push_back(segment);
219  addToTrash(segment->garbage());
220  segment->addTrack(this);
221  ++segment->usedInFit;
222  for (const MuonStationIndex::ChIndex& chit : segment->chambers()) addChamber(chit);
223 
224  if (newTrack) {
225  // delete old track, assign new
226  m_track.swap(newTrack);
227  }
229  }
230 
232  // modify usedInFit counter of segment
233  for (MuPatSegment* seg : m_segments) {
234  for (const MuonStationIndex::ChIndex& chit : seg->chambers()) addChamber(chit);
235  seg->usedInFit += change;
236  }
237  }
238 
239  bool MuPatTrack::resetChambersOnCandidate(const std::set<MuonStationIndex::ChIndex>& chambers) {
240  // loop over input chambers, check whether segments have a chamber in the list
241  // remove segment if not in the list
242  setChambers(chambers); // also updates station list
243 
244  bool bRemovedSegments = false;
246  // NOTE: can not cache m_segments.end() because it may change in the loop
247  while (it != m_segments.end()) {
248  bool inChamberSet = false;
249  for (const MuonStationIndex::ChIndex& chit : (*it)->chambers()) {
250  if (containsChamber(chit)) {
251  inChamberSet = true;
252  break;
253  }
254  }
255  if (inChamberSet) {
256  ++it;
257  } else {
258  (*it)->removeTrack(this);
259  bRemovedSegments = true;
260  it = m_segments.erase(it); // it points to next element
261  }
262  }
263 
264  return bRemovedSegments;
265  }
266 
267  std::vector<MuonStationIndex::StIndex> MuPatTrack::stationsInOrder() {
268  std::vector<MuonStationIndex::StIndex> stations;
269  stations.reserve(m_segments.size());
270  for (MuPatSegment* seg : m_segments) stations.push_back(seg->stIndex);
271  return stations;
272  }
273 
274  std::string MuPatTrack::segmentNames() const {
275  std::string names;
276  // rest with spaces
277  for (const MuPatSegment* seg : m_segments) {
278  names += seg->name;
279  names += " ";
280  }
282  return names.substr(0, names.size() - 1);
283  }
284 
286  for (MuPatSegment* seg : m_segments) {
287  if (add) {
288  seg->addTrack(this);
289  } else {
290  seg->removeTrack(this);
291  }
292  }
293  }
294 
295 } // namespace Muon
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
Muon::MuPatTrack::InitialLoop
@ InitialLoop
Definition: MuPatTrack.h:44
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
Muon::MuPatCandidateBase::addToTrash
void addToTrash(std::unique_ptr< const Trk::MeasurementBase > meas)
adds the measurement to the garbage container.
Definition: MuPatCandidateBase.cxx:91
Muon::MuPatTrack::Unknown
@ Unknown
Definition: MuPatTrack.h:43
TrackParameters.h
python.FPGATrackSimAnalysisConfig.stage
stage
Definition: FPGATrackSimAnalysisConfig.py:558
Muon::MuPatCandidateBase
track candidate entry object.
Definition: MuPatCandidateBase.h:46
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
Muon::MuPatTrack::TrackSelector
@ TrackSelector
Definition: MuPatTrack.h:57
Muon::MuPatTrack::segmentNames
std::string segmentNames() const
string containing the names of the segments on the candidate
Definition: MuPatTrack.cxx:274
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
Muon::MuPatCandidateBase::m_hasMomentum
bool m_hasMomentum
Definition: MuPatCandidateBase.h:172
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
Trk::Track::info
const TrackInfo & info() const
Returns a const ref to info of a const tracks.
Muon::MuPatCandidateBase::chambers
const std::set< MuonStationIndex::ChIndex > & chambers() const
returns set with contained chamberIndices
Definition: MuPatCandidateBase.cxx:31
Muon::MuPatTrack::updateSegments
void updateSegments(bool add)
update segment/track association, if add == true ,will add track to segments else remove it
Definition: MuPatTrack.cxx:285
Muon::MuPatTrack::m_track
std::unique_ptr< Trk::Track > m_track
Definition: MuPatTrack.h:158
Muon::MuPatTrack::FitWorse
@ FitWorse
Definition: MuPatTrack.h:54
skel.it
it
Definition: skel.GENtoEVGEN.py:396
plotBeamSpotVxVal.cov
cov
Definition: plotBeamSpotVxVal.py:201
Muon::MuPatTrack::AmbiguitySelectCandidates
@ AmbiguitySelectCandidates
Definition: MuPatTrack.h:51
Muon
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Definition: TrackSystemController.h:45
Muon::MuPatTrack::isSegmentExcluded
bool isSegmentExcluded(const MuPatSegment *segment) const
loops over the excluded segment collection and checks whether the pointer is in there
Definition: MuPatTrack.cxx:213
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
AmgSymMatrix
#define AmgSymMatrix(dim)
Definition: EventPrimitives.h:50
Muon::MuPatTrack::FitRemovedLayer
@ FitRemovedLayer
Definition: MuPatTrack.h:56
Muon::MuPatTrack::SegmentRecovery
@ SegmentRecovery
Definition: MuPatTrack.h:47
Muon::MuPatTrack::initProcessingStageStrings
static std::vector< std::string > initProcessingStageStrings()
Initialize s_processingStageStrings & s_processingStageStringMaxLen.
Definition: MuPatTrack.cxx:30
Muon::MuPatTrack::addSegment
void addSegment(MuPatSegment *segment, std::unique_ptr< Trk::Track > &newTrack)
add segment + the associated new track.
Definition: MuPatTrack.cxx:216
Track.h
Muon::MuPatTrack::LayerRecovery
@ LayerRecovery
Definition: MuPatTrack.h:45
Trk::TrackInfo::StraightTrack
@ StraightTrack
A straight track.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/TrackInfo.h:84
Muon::MuPatTrack::hasMomentum
bool hasMomentum() const
returns whether canditate has a momentum measurement
Definition: MuPatTrack.cxx:186
Muon::MuPatTrack::resetChambersOnCandidate
bool resetChambersOnCandidate(const std::set< MuonStationIndex::ChIndex > &chambers)
reset chambers on the candidate.
Definition: MuPatTrack.cxx:239
PlotPulseshapeFromCool.can
can
Definition: PlotPulseshapeFromCool.py:91
Muon::MuPatTrack::operator=
MuPatTrack & operator=(const MuPatTrack &can)
assignment operator.
Definition: MuPatTrack.cxx:155
lumiFormat.i
int i
Definition: lumiFormat.py:85
Muon::MuPatTrack::created
ProcessingStage created
Definition: MuPatTrack.h:144
Muon::MuPatTrack::processingStageStringMaxLen
static unsigned int processingStageStringMaxLen()
maximum width of the strings corresponding to the ProcessingStage
Definition: MuPatTrack.cxx:16
Muon::MuPatTrack::m_excludedSegments
std::vector< MuPatSegment * > m_excludedSegments
Definition: MuPatTrack.h:157
python.subdetectors.mmg.names
names
Definition: mmg.py:8
Muon::MuPatCandidateBase::m_stations
std::set< MuonStationIndex::StIndex > m_stations
Definition: MuPatCandidateBase.h:171
Muon::MuPatCandidateBase::setChambers
void setChambers(const std::set< MuonStationIndex::ChIndex > &chambers)
Set the list of chambers and update list of stations.
Definition: MuPatCandidateBase.cxx:14
Muon::MuPatTrack::processingStageStrings
static const std::vector< std::string > & processingStageStrings()
Return list of processing stage strings.
Definition: MuPatTrack.cxx:54
Muon::MuPatTrack::ProcessingStage
ProcessingStage
enum to keep track of the life of candidates
Definition: MuPatTrack.h:42
MuPatTrack.h
Muon::MuPatTrack::FitRemovedSegment
@ FitRemovedSegment
Definition: MuPatTrack.h:48
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
Muon::MuPatTrack::m_seedSeg
MuPatSegment * m_seedSeg
The special segment for this track.
Definition: MuPatTrack.h:159
Muon::MuPatTrack::MatchFail
@ MatchFail
Definition: MuPatTrack.h:52
Muon::MuPatTrack::stationsInOrder
std::vector< MuonStationIndex::StIndex > stationsInOrder()
returns vector with contained stationIndices in the order they were added
Definition: MuPatTrack.cxx:267
Muon::MuPatTrack::addExcludedSegment
void addExcludedSegment(MuPatSegment *segment)
add segment that does not match the track
Definition: MuPatTrack.cxx:212
Muon::MuPatTrack::modifySegmentCounters
void modifySegmentCounters(int change)
increase the segment counters by the passed number
Definition: MuPatTrack.cxx:231
Trk::Track::perigeeParameters
const Perigee * perigeeParameters() const
return Perigee.
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:163
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Muon::MuPatTrack::lastSegmentChange
ProcessingStage lastSegmentChange
Definition: MuPatTrack.h:145
Muon::MuPatTrack::updateTrack
void updateTrack(std::unique_ptr< Trk::Track > &newTrack)
update track.
Definition: MuPatTrack.cxx:210
Muon::MuPatTrack::NumberOfProcessingStages
@ NumberOfProcessingStages
Definition: MuPatTrack.h:59
Muon::MuPatSegment
segment candidate object.
Definition: MuPatSegment.h:43
Muon::MuPatTrack::processingStageString
static const std::string & processingStageString(ProcessingStage stage)
Convert enum to string.
Definition: MuPatTrack.cxx:61
Muon::MuPatCandidateBase::containsChamber
bool containsChamber(MuonStationIndex::ChIndex chIndex) const
returns whether the ChamberIndex is already contained in candidate
Definition: MuPatCandidateBase.cxx:75
Muon::MuPatTrack::track
Trk::Track & track() const
access to track
Definition: MuPatTrack.h:175
Muon::MuPatTrack::KeptUntilEndOfCombi
@ KeptUntilEndOfCombi
Definition: MuPatTrack.h:58
Muon::MuPatTrack
track candidate object.
Definition: MuPatTrack.h:37
Muon::MuPatCandidateBase::m_chambers
std::set< MuonStationIndex::ChIndex > m_chambers
Definition: MuPatCandidateBase.h:170
Muon::MuPatTrack::RefitRemovedSegment
@ RefitRemovedSegment
Definition: MuPatTrack.h:49
Muon::MuPatTrack::ExtendedWithSegment
@ ExtendedWithSegment
Definition: MuPatTrack.h:46
Muon::MuPatCandidateBase::addChamber
void addChamber(MuonStationIndex::ChIndex chIndex)
add the chamber to the list of contained chambers.
Definition: MuPatCandidateBase.cxx:38
Muon::MuonStationIndex::ChIndex
ChIndex
enum to classify the different chamber layers in the muon spectrometer
Definition: MuonStationIndex.h:15
Track
Definition: TriggerChamberClusterOnTrackCreator.h:21
Muon::MuPatTrack::FitFail
@ FitFail
Definition: MuPatTrack.h:53
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
Muon::MuPatTrack::m_segments
std::vector< MuPatSegment * > m_segments
Definition: MuPatTrack.h:156
Muon::MuPatTrack::MuPatTrack
MuPatTrack(const std::vector< MuPatSegment * > &segments, std::unique_ptr< Trk::Track > &track, MuPatSegment *seedSeg=0)
constructor taking a vector of MuPatSegment object, the candidate takes ownership of the track It wil...
Definition: MuPatTrack.cxx:72
Muon::MuPatTrack::UnassociatedEM
@ UnassociatedEM
Definition: MuPatTrack.h:55
Muon::MuPatTrack::segments
const std::vector< MuPatSegment * > & segments() const
access to segments
Definition: MuPatTrack.h:167
Muon::MuPatTrack::AmbiguityCreateCandidateFromSeeds
@ AmbiguityCreateCandidateFromSeeds
Definition: MuPatTrack.h:50
Muon::MuPatTrack::~MuPatTrack
~MuPatTrack()
destructor, decrease the usedInFit counter of all MuPatSegment objects by one
Definition: MuPatTrack.cxx:133
Trk::TrackInfo::trackProperties
bool trackProperties(const TrackProperties &property) const
Access methods for track properties.
Muon::MuPatCandidateBase::stations
const std::set< MuonStationIndex::StIndex > & stations() const
returns set with contained stationIndices
Definition: MuPatCandidateBase.cxx:29
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5
Muon::MuPatCandidateBase::garbage
const std::vector< std::shared_ptr< const Trk::MeasurementBase > > & garbage() const
Definition: MuPatCandidateBase.cxx:98