ATLAS Offline Software
Loading...
Searching...
No Matches
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
12namespace 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) :
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())
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
141 created(can.created),
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
187 if (!m_track) return false;
188 return hasMomentum(*m_track);
189 }
190
192 // use track info if set properly
193 if (track.info().trackProperties(Trk::TrackInfo::StraightTrack)) return false;
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
213 bool MuPatTrack::isSegmentExcluded(const MuPatSegment* segment) const {
214 return std::find(m_excludedSegments.begin(), m_excludedSegments.end(), segment) != m_excludedSegments.end();
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;
245 std::vector<MuPatSegment*>::iterator it = m_segments.begin();
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
#define AmgSymMatrix(dim)
MuPatCandidateBase()=default
constructor.
const Trk::MeasurementBase * addToTrash(std::unique_ptr< const Trk::MeasurementBase > meas)
adds the measurement to the garbage container.
std::set< MuonStationIndex::StIndex > m_stations
void setChambers(const std::set< MuonStationIndex::ChIndex > &chambers)
Set the list of chambers and update list of stations.
bool containsChamber(MuonStationIndex::ChIndex chIndex) const
returns whether the ChamberIndex is already contained in candidate
void addChamber(MuonStationIndex::ChIndex chIndex)
add the chamber to the list of contained chambers.
const std::set< MuonStationIndex::StIndex > & stations() const
returns set with contained stationIndices
const std::vector< std::shared_ptr< const Trk::MeasurementBase > > & garbage() const
const std::set< MuonStationIndex::ChIndex > & chambers() const
returns set with contained chamberIndices
std::set< MuonStationIndex::ChIndex > m_chambers
segment candidate object.
void addTrack(MuPatTrack *)
add a new track to the segment
bool isSegmentExcluded(const MuPatSegment *segment) const
loops over the excluded segment collection and checks whether the pointer is in there
static const std::vector< std::string > & processingStageStrings()
Return list of processing stage strings.
void addExcludedSegment(MuPatSegment *segment)
add segment that does not match the track
std::vector< MuonStationIndex::StIndex > stationsInOrder()
returns vector with contained stationIndices in the order they were added
Trk::Track & track() const
access to track
Definition MuPatTrack.h:175
void updateSegments(bool add)
update segment/track association, if add == true ,will add track to segments else remove it
MuPatSegment * m_seedSeg
The special segment for this track.
Definition MuPatTrack.h:159
ProcessingStage created
Definition MuPatTrack.h:144
static std::vector< std::string > initProcessingStageStrings()
Initialize s_processingStageStrings & s_processingStageStringMaxLen.
static const std::string & processingStageString(ProcessingStage stage)
Convert enum to string.
bool hasMomentum() const
returns whether canditate has a momentum measurement
MuPatTrack & operator=(const MuPatTrack &can)
assignment operator.
ProcessingStage
enum to keep track of the life of candidates
Definition MuPatTrack.h:42
@ AmbiguityCreateCandidateFromSeeds
Definition MuPatTrack.h:50
void updateTrack(std::unique_ptr< Trk::Track > &newTrack)
update track.
void addSegment(MuPatSegment *segment, std::unique_ptr< Trk::Track > &newTrack)
add segment + the associated new track.
ProcessingStage lastSegmentChange
Definition MuPatTrack.h:145
~MuPatTrack()
destructor, decrease the usedInFit counter of all MuPatSegment objects by one
void modifySegmentCounters(int change)
increase the segment counters by the passed number
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...
std::vector< MuPatSegment * > m_segments
Definition MuPatTrack.h:156
std::vector< MuPatSegment * > m_excludedSegments
Definition MuPatTrack.h:157
bool resetChambersOnCandidate(const std::set< MuonStationIndex::ChIndex > &chambers)
reset chambers on the candidate.
static unsigned int processingStageStringMaxLen()
maximum width of the strings corresponding to the ProcessingStage
std::unique_ptr< Trk::Track > m_track
Definition MuPatTrack.h:158
std::string segmentNames() const
string containing the names of the segments on the candidate
const std::vector< MuPatSegment * > & segments() const
access to segments
Definition MuPatTrack.h:167
bool add(const std::string &hname, TKey *tobj)
Definition fastadd.cxx:55
ChIndex
enum to classify the different chamber layers in the muon spectrometer
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Ensure that the ATLAS eigen extensions are properly loaded.
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
STL namespace.