ATLAS Offline Software
Loading...
Searching...
No Matches
Tracking/TrkEvent/TrkTrack/src/Track.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4
5#include "TrkTrack/Track.h"
6
7#include <cassert>
8#include <iostream>
9#include <string>
10
11#include "GaudiKernel/MsgStream.h"
15
16Trk::Track::Track(const TrackInfo& info, std::unique_ptr<TrackStates> trackStateOnSurfaces,
17 std::unique_ptr<FitQuality> fitQuality)
26 // find the Perigee params they will become valid given the outcome
28}
29
30
32 : Trk::ObjectCounter<Trk::Track>(rhs),
37 m_fitQuality(nullptr) {
38 // Do the actual payload copy
39 copyHelper(rhs);
40}
41
43 if (this != &rhs) {
44 // First clear this object
45 m_fitQuality.reset(nullptr);
46 m_trackSummary.reset(nullptr);
47 // Invalidate the caches
49 m_trackStateVector.reset();
50 // copy payload of rhs to this
51 copyHelper(rhs);
52 }
53 return *this;
54}
55
57 // set the author to be that of the Track being copied.
59
60 // create & copy other variables if available
61 if (rhs.fitQuality() != nullptr) {
62 m_fitQuality = std::make_unique<Trk::FitQuality>(*(rhs.m_fitQuality));
63 }
64 // create & copy other variables
65 if (rhs.trackSummary() != nullptr) {
66 m_trackSummary = std::make_unique<Trk::TrackSummary>(*(rhs.m_trackSummary));
67 }
68 // Create the TrackStateVector and the perigeeParameters
69
70 if (rhs.m_trackStateVector != nullptr) {
71 m_trackStateVector = std::make_unique<TrackStates>();
72 m_trackStateVector->reserve(rhs.m_trackStateVector->size());
73
74 TSoS_iterator itTSoSEnd = rhs.m_trackStateVector->cend();
75 for (TSoS_iterator itTSoS = rhs.m_trackStateVector->cbegin();
76 itTSoS != itTSoSEnd; ++itTSoS) {
77 assert(*itTSoS != nullptr); // check that is defined.
78 // clone and store
79 TrackStateOnSurface* tsos = (**itTSoS).clone();
80 m_trackStateVector->push_back(tsos);
81 // Check if this a perigee so we can already cache it
82 if (tsos != nullptr && tsos->type(TrackStateOnSurface::Perigee)) {
83 const Trk::Perigee* perigee = nullptr;
84 const Trk::TrackParameters* tp = tsos->trackParameters();
85 if (tp && tp->type() == Trk::AtaSurface &&
86 tp->surfaceType() == Trk::SurfaceType::Perigee) {
87 perigee = static_cast<const Trk::Perigee*>(tp);
88 }
89 if (perigee != nullptr) {
90 m_perigeeParameters.store(perigee); // Now they will be valid
91 }
92 }
93 }
94 }
95}
96
98 const {
99
100 if (!m_trackStateVector) {
101 return nullptr;
102 }
103 // Do work only if it is not valid.
104 if (!m_cachedParameterVector.isValid()) {
105 // create cached parameter vector (which DOES NOT OWN ELEMENTS)
106 DataVector<const Trk::TrackParameters> tmp_ParameterVector(
108 tmp_ParameterVector.reserve(m_trackStateVector->size());
109 TSoS_iterator itTSoSEnd = m_trackStateVector->cend();
110 for (TSoS_iterator itTSoS = m_trackStateVector->cbegin(); itTSoS != itTSoSEnd;
111 ++itTSoS) {
112 const TrackParameters* trackParameters = (*itTSoS)->trackParameters();
113 // check to make sure that the TrackParameters exists first
114 if (trackParameters != nullptr) {
115 tmp_ParameterVector.push_back(trackParameters);
116 }
117 }
118 m_cachedParameterVector.set(std::move(tmp_ParameterVector));
119 }
120 return m_cachedParameterVector.ptr();
121}
122
124 if (!m_perigeeParameters.isValid()) {
126 }
127}
128
130 // loop through all passed parameters and, if there is a at Perigee in there,
131 // assign it to Perigee parameters. There should never be more
132 // than one perigee type.
133 // Note that there can be other objects, like VertexOnTrack measurements, with
134 // params at a Perigee surface, thus the TSoS check.
135
136 const Trk::Perigee* tmpPerigeeParameters = nullptr;
137 if (!m_trackStateVector) {
138 return;
139 }
141 m_trackStateVector->cbegin();
143 m_trackStateVector->cend();
144 for (; it != itEnd; ++it) {
145 if ((*it)->type(TrackStateOnSurface::Perigee)) {
146 const Trk::TrackParameters* tp = (*it)->trackParameters();
147 if (tp && tp->type() == Trk::AtaSurface &&
148 tp->surfaceType() == Trk::SurfaceType::Perigee) {
149 tmpPerigeeParameters = static_cast<const Trk::Perigee*>(tp);
150 }
151
152 if (tmpPerigeeParameters != nullptr) {
153 break; // found perigee so stop loop.
154 }
155 }
156 }
157 // set to value and valid
158 if (tmpPerigeeParameters) {
159 m_perigeeParameters.set(tmpPerigeeParameters);
160 }
161}
162
164 if (!m_perigeeParameters.isValid()) {
165 // findPerigee performs the setting of the parameters
166 // i.e does the CachedValue set
168 }
169
170 // Return payload if valid
171 if (m_perigeeParameters.isValid()) {
172 return *(m_perigeeParameters.ptr());
173 }
174
175 return nullptr;
176}
177
179 const {
180 if (!m_trackStateVector) {
181 return nullptr;
182 }
183
184 // We only need to do work if not valid.
185 if (!m_cachedMeasurementVector.isValid()) {
186 // create new DataVector which DOES NOT OWN ELEMENTS .
187 DataVector<const Trk::MeasurementBase> tmpMeasurementVector(
189 // for measurements on track it is very likely that #(meas) ~ #(TSOS)->
190 // reserve(#(TSOS))
191 tmpMeasurementVector.reserve(m_trackStateVector->size());
192
193 TSoS_iterator itTSoSEnd = m_trackStateVector->cend();
194 for (TSoS_iterator itTSoS = m_trackStateVector->cbegin(); itTSoS != itTSoSEnd;
195 ++itTSoS) {
196 if (!(*itTSoS)->type(TrackStateOnSurface::Outlier)) {
197 const Trk::MeasurementBase* rot = (*itTSoS)->measurementOnTrack();
198 // does it have a measurement ?
199 if (rot != nullptr) {
200 tmpMeasurementVector.push_back(rot);
201 }
202 }
203 }
204 m_cachedMeasurementVector.set(std::move(tmpMeasurementVector));
205 }
206
207 return m_cachedMeasurementVector.ptr();
208}
209
211 const {
212 if (!m_trackStateVector) {
213 return nullptr;
214 }
215 // We only need to do work if not valid
216 if (!m_cachedOutlierVector.isValid()) {
217 // create new DataVector which DOES NOT OWN ELEMENTS .
219 TSoS_iterator itTSoSEnd = m_trackStateVector->cend();
220 for (TSoS_iterator itTSoS = m_trackStateVector->cbegin(); itTSoS != itTSoSEnd;
221 ++itTSoS) {
222 if ((*itTSoS)->type(TrackStateOnSurface::Outlier)) {
223 const Trk::MeasurementBase* rot = (*itTSoS)->measurementOnTrack();
224 assert(rot != nullptr);
225 tmpOutlierVector.push_back(rot);
226 }
227 }
228 m_cachedOutlierVector.set(std::move(tmpOutlierVector));
229 }
230 return m_cachedOutlierVector.ptr();
231}
232
235MsgStream& Trk::operator<<(MsgStream& sl, const Trk::Track& track) {
236 std::string name("Track ");
237 sl << name << "Author = " << track.info().dumpInfo() << endmsg;
238 if (track.fitQuality() != nullptr) {
239 sl << *(track.fitQuality()) << endmsg;
240 }
241 if (track.trackSummary() != nullptr) {
242 sl << *(track.trackSummary()) << endmsg;
243 } else {
244 sl << "No TrackSummary available in this track." << endmsg;
245 }
246 if (track.trackStateOnSurfaces() != nullptr) {
247 sl << name << "has " << (track.trackStateOnSurfaces()->size())
248 << " trackStateOnSurface(s)" << endmsg;
249
250 // level() shows the output level, currentLevel()
251 // shows what the stream is set to
252 if (sl.level() < MSG::INFO) {
253 // loop over TrackStateOnSurfaces if verbose turned on
255 track.trackStateOnSurfaces()->cbegin();
256 int num = 0;
257 for (; it != track.trackStateOnSurfaces()->cend(); ++it) {
258 sl << " --------- Start of TrackStateOnSurface \t" << num << "\t-------"
259 << endmsg;
260 sl << (**it);
261 sl << " --------- End of TrackStateOnSurface \t" << num++
262 << "\t-------" << endmsg;
263 }
264 }
265 }
266 return sl;
267}
268
269std::ostream& Trk::operator<<(std::ostream& sl, const Trk::Track& track) {
270 std::string name("Track ");
271 sl << name << "Author = " << track.info().dumpInfo() << std::endl;
272 if (track.fitQuality() != nullptr) {
273 sl << *(track.fitQuality()) << std::endl;
274 }
275 if (track.trackSummary() != nullptr) {
276 sl << *(track.trackSummary()) << std::endl;
277 } else {
278 sl << "No TrackSummary available in this track." << std::endl;
279 }
280
281 if (track.trackStateOnSurfaces() != nullptr) {
282 sl << name << "has " << (track.trackStateOnSurfaces()->size())
283 << " trackStateOnSurface(s)" << std::endl;
285 track.trackStateOnSurfaces()->cbegin();
286 int num = 0;
287 for (; it != track.trackStateOnSurfaces()->cend(); ++it) {
288 sl << " --------- Start of TrackStateOnSurface \t" << num << "\t-------"
289 << std::endl;
290 sl << (**it);
291 sl << " --------- End of TrackStateOnSurface \t" << num++ << "\t-------"
292 << std::endl;
293 }
294 }
295 return sl;
296}
#define endmsg
Derived DataVector<T>.
Definition DataVector.h:795
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
This class is the pure abstract base class for all fittable tracking measurements.
Contains information about the 'fitter' of this track.
represents the track state (measurement, material, fit parameters and quality) at a surface.
virtual TrackStateOnSurface * clone() const
Pseudo-constructor: needed to avoid excessive RTTI.
const TrackParameters * trackParameters() const
return ptr to trackparameters const overload
bool type(const TrackStateOnSurfaceType type) const
Use this method to find out if the TSoS is of a certain type: i.e.
@ Perigee
This represents a perigee, and so will contain a Perigee object only.
@ Outlier
This TSoS contains an outlier, that is, it contains a MeasurementBase/RIO_OnTrack which was not used ...
CxxUtils::CachedValue< DataVector< const TrackParameters > > m_cachedParameterVector
A vector of TrackParameters: these can be any of the classes that derive from Trk::TrackParameters,...
Track()=default
Default constructor Here for POOL and simple tests.
CxxUtils::CachedValue< DataVector< const MeasurementBase > > m_cachedMeasurementVector
A vector of MeasurementBase: these objects represent the "hits" on the track (but not outliers - see ...
std::unique_ptr< Trk::TrackSummary > m_trackSummary
Datamember to cache the TrackSummary.
const Trk::TrackStates * trackStateOnSurfaces() const
return a pointer to a const DataVector of const TrackStateOnSurfaces.
const DataVector< const MeasurementBase > * measurementsOnTrack() const
return a pointer to a vector of MeasurementBase (NOT including any that come from outliers).
const DataVector< const TrackParameters > * trackParameters() const
Return a pointer to a vector of TrackParameters.
Trk::TrackInfo m_trackInfo
This is a class which stores the identity of where the track was created, fitted, which properties th...
void resetCaches()
reset all caches
void findPerigeeImpl() const
find PerigeeImpl.
Trk::TrackStates::const_iterator TSoS_iterator
const TrackInfo & info() const
Returns a const ref to info of a const tracks.
const Perigee * perigeeParameters() const
return Perigee.
Track & operator=(const Track &rhs)
assignment operator
std::unique_ptr< TrackStates > m_trackStateVector
TrackStateOnSurface.
CxxUtils::CachedValue< DataVector< const MeasurementBase > > m_cachedOutlierVector
These objects represent the "outliers" on the track.
const DataVector< const MeasurementBase > * outliersOnTrack() const
return a pointer to a vector of MeasurementBase, which represent outliers (i.e.
CxxUtils::CachedValue< const Perigee * > m_perigeeParameters
A pointer to the Track's Perigee parameters.
std::unique_ptr< FitQuality > m_fitQuality
A pointer to the Track's FitQuality.
void copyHelper(const Track &rhs)
Helper method to factor common part of copy ctor and copy assignment.
const Trk::TrackSummary * trackSummary() const
Returns a pointer to the const Trk::TrackSummary owned by this const track (could be nullptr)
const FitQuality * fitQuality() const
return a pointer to the fit quality const-overload
void findPerigee() const
Find perigee in the vector of track parameters.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Ensure that the ATLAS eigen extensions are properly loaded.
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
MsgStream & operator<<(MsgStream &sl, const AlignModule &alignModule)
overload of << operator for MsgStream for debug output
ParametersBase< TrackParametersDim, Charged > TrackParameters
STL namespace.