ATLAS Offline Software
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 
16 Trk::Track::Track(const TrackInfo& info, std::unique_ptr<TrackStates> trackStateOnSurfaces,
17  std::unique_ptr<FitQuality> fitQuality)
18  : Trk::ObjectCounter<Trk::Track>(),
19  m_trackStateVector(std::move(trackStateOnSurfaces)),
20  m_cachedParameterVector{},
21  m_cachedMeasurementVector{},
22  m_cachedOutlierVector{},
23  m_perigeeParameters{},
24  m_fitQuality(std::move(fitQuality)),
25  m_trackInfo(info) {
26  // find the Perigee params they will become valid given the outcome
27  findPerigeeImpl();
28 }
29 
30 
32  : Trk::ObjectCounter<Trk::Track>(rhs),
33  m_cachedParameterVector{},
34  m_cachedMeasurementVector{},
35  m_cachedOutlierVector{},
36  m_perigeeParameters{},
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
48  resetCaches();
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.
58  m_trackInfo = rhs.m_trackInfo;
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()) {
125  findPerigeeImpl();
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
167  findPerigeeImpl();
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 
235 MsgStream& 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 
269 std::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 }
DataVector::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
grepfile.info
info
Definition: grepfile.py:38
Trk::TrackStateOnSurface::trackParameters
const TrackParameters * trackParameters() const
return ptr to trackparameters const overload
Trk::TrackInfo
Contains information about the 'fitter' of this track.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/TrackInfo.h:32
Trk::TrackStateOnSurface::Perigee
@ Perigee
This represents a perigee, and so will contain a Perigee object only.
Definition: TrackStateOnSurface.h:117
AlignmentEffectsOnTrack.h
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
Trk::Track::fitQuality
const FitQuality * fitQuality() const
return a pointer to the fit quality const-overload
TrackParameters.h
MeasurementBase.h
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
Trk::TrackStateOnSurface::clone
virtual TrackStateOnSurface * clone() const
Pseudo-constructor: needed to avoid excessive RTTI.
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
skel.it
it
Definition: skel.GENtoEVGEN.py:423
ParticleTest.tp
tp
Definition: ParticleTest.py:25
Trk::ObjectCounter
Helper to enable counting number of instantiations in debug builds.
Definition: TrkObjectCounter.h:18
Trk::Track::m_fitQuality
std::unique_ptr< FitQuality > m_fitQuality
A pointer to the Track's FitQuality.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:293
Trk::TrackStateOnSurface::Outlier
@ Outlier
This TSoS contains an outlier, that is, it contains a MeasurementBase/RIO_OnTrack which was not used ...
Definition: TrackStateOnSurface.h:122
Track.h
Trk::Track::m_trackSummary
std::unique_ptr< Trk::TrackSummary > m_trackSummary
Datamember to cache the TrackSummary.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:298
Trk::TrackStateOnSurface::type
bool type(const TrackStateOnSurfaceType type) const
Use this method to find out if the TSoS is of a certain type: i.e.
Trk::Track::findPerigee
void findPerigee() const
Find perigee in the vector of track parameters.
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:123
Trk::Track::Track
Track()=default
Default constructor Here for POOL and simple tests.
Trk::Track::m_trackStateVector
std::unique_ptr< TrackStates > m_trackStateVector
TrackStateOnSurface.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:248
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
Trk::ParametersBase
Definition: ParametersBase.h:55
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Trk::Track::outliersOnTrack
const DataVector< const MeasurementBase > * outliersOnTrack() const
return a pointer to a vector of MeasurementBase, which represent outliers (i.e.
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:210
trigbs_pickEvents.num
num
Definition: trigbs_pickEvents.py:76
Trk::Track::m_trackInfo
Trk::TrackInfo m_trackInfo
This is a class which stores the identity of where the track was created, fitted, which properties th...
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:304
Trk::MeasurementBase
Definition: MeasurementBase.h:58
Trk::Track::trackParameters
const DataVector< const TrackParameters > * trackParameters() const
Return a pointer to a vector of TrackParameters.
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:97
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
Trk::SurfaceType::Perigee
@ Perigee
Trk::TrackStateOnSurface
represents the track state (measurement, material, fit parameters and quality) at a surface.
Definition: TrackStateOnSurface.h:71
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
Trk::GsfMeasurementUpdator::fitQuality
FitQualityOnSurface fitQuality(const MultiComponentState &, const MeasurementBase &)
Method for determining the chi2 of the multi-component state and the number of degrees of freedom.
Definition: GsfMeasurementUpdator.cxx:845
Trk::Track::measurementsOnTrack
const DataVector< const MeasurementBase > * measurementsOnTrack() const
return a pointer to a vector of MeasurementBase (NOT including any that come from outliers).
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:178
Trk::AtaSurface
@ AtaSurface
Definition: ParametersCommon.h:29
Trk::Track::copyHelper
void copyHelper(const Track &rhs)
Helper method to factor common part of copy ctor and copy assignment.
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:56
Trk::Track::trackSummary
const Trk::TrackSummary * trackSummary() const
Returns a pointer to the const Trk::TrackSummary owned by this const track (could be nullptr)
Trk::operator<<
MsgStream & operator<<(MsgStream &sl, const AlignModule &alignModule)
overload of << operator for MsgStream for debug output
Definition: AlignModule.cxx:204
Trk::Track::operator=
Track & operator=(const Track &rhs)
assignment operator
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:42
Track
Definition: TriggerChamberClusterOnTrackCreator.h:21
Trk::Track::findPerigeeImpl
void findPerigeeImpl() const
find PerigeeImpl.
Definition: Tracking/TrkEvent/TrkTrack/src/Track.cxx:129
xAOD::track
@ track
Definition: TrackingPrimitives.h:512