ATLAS Offline Software
TrackStateOnSurface.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 #include "GaudiKernel/MsgStream.h"
8 #include <stdexcept>
9 #include <string>
10 
11 namespace Trk {
13 
14 // partial
16  const FitQualityOnSurface& fitQoS,
17  std::unique_ptr<MeasurementBase> meas,
18  std::unique_ptr<TrackParameters> trackParameters,
19  std::unique_ptr<MaterialEffectsBase> materialEffects,
20  std::unique_ptr<AlignmentEffectsOnTrack> alignmentEffectsOnTrack)
21  : m_fitQualityOnSurface(fitQoS)
22  , m_trackParameters(std::move(trackParameters))
23  , m_measurementOnTrack(std::move(meas))
24  , m_materialEffectsOnTrack(std::move(materialEffects))
25  , m_alignmentEffectsOnTrack(std::move(alignmentEffectsOnTrack))
26 {
27  assert(isSane());
28  setFlags();
29 }
30 
32  std::unique_ptr<MeasurementBase> meas,
33  std::unique_ptr<TrackParameters> trackParameters,
34  std::unique_ptr<MaterialEffectsBase> materialEffects,
35  std::unique_ptr<AlignmentEffectsOnTrack> alignmentEffectsOnTrack)
36  : m_fitQualityOnSurface{}
37  , m_trackParameters(std::move(trackParameters))
38  , m_measurementOnTrack(std::move(meas))
39  , m_materialEffectsOnTrack(std::move(materialEffects))
40  , m_alignmentEffectsOnTrack(std::move(alignmentEffectsOnTrack))
41 {
42  assert(isSane());
43  setFlags();
44 }
45 
46 // full
48  const FitQualityOnSurface& fitQoS,
49  std::unique_ptr<MeasurementBase> meas,
50  std::unique_ptr<TrackParameters> trackParameters,
51  std::unique_ptr<MaterialEffectsBase> materialEffects,
52  const std::bitset<TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes>& typePattern,
53  std::unique_ptr<AlignmentEffectsOnTrack> alignmentEffectsOnTrack)
54  : m_fitQualityOnSurface(fitQoS)
55  , m_trackParameters(std::move(trackParameters))
56  , m_measurementOnTrack(std::move(meas))
57  , m_materialEffectsOnTrack(std::move(materialEffects))
58  , m_alignmentEffectsOnTrack(std::move(alignmentEffectsOnTrack))
59  , m_typeFlags(typePattern.to_ulong())
60 {
61  assert(isSane());
62 }
63 
65  std::unique_ptr<MeasurementBase> meas,
66  std::unique_ptr<TrackParameters> trackParameters,
67  std::unique_ptr<MaterialEffectsBase> materialEffects,
68  const std::bitset<TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes>& typePattern,
69  std::unique_ptr<AlignmentEffectsOnTrack> alignmentEffectsOnTrack)
70  : m_fitQualityOnSurface{}
71  , m_trackParameters(std::move(trackParameters))
72  , m_measurementOnTrack(std::move(meas))
73  , m_materialEffectsOnTrack(std::move(materialEffects))
74  , m_alignmentEffectsOnTrack(std::move(alignmentEffectsOnTrack))
75  , m_typeFlags(typePattern.to_ulong())
76 {
77  assert(isSane());
78 }
79 
80 // copy
82  : m_fitQualityOnSurface(rhs.m_fitQualityOnSurface),
83  m_trackParameters(rhs.m_trackParameters ? rhs.m_trackParameters->clone()
84  : nullptr),
85  m_measurementOnTrack(rhs.m_measurementOnTrack
86  ? rhs.m_measurementOnTrack->clone()
87  : nullptr),
88  m_materialEffectsOnTrack(rhs.m_materialEffectsOnTrack
89  ? rhs.m_materialEffectsOnTrack->clone()
90  : nullptr),
91  m_alignmentEffectsOnTrack(rhs.m_alignmentEffectsOnTrack
93  *rhs.m_alignmentEffectsOnTrack)
94  : nullptr),
95  m_typeFlags(rhs.m_typeFlags) {}
96 
97 // move
99  : m_fitQualityOnSurface(rhs.m_fitQualityOnSurface)
100  , m_trackParameters(std::move(rhs.m_trackParameters))
101  , m_measurementOnTrack(std::move(rhs.m_measurementOnTrack))
102  , m_materialEffectsOnTrack(std::move(rhs.m_materialEffectsOnTrack))
103  , m_alignmentEffectsOnTrack(std::move(rhs.m_alignmentEffectsOnTrack))
104  , m_typeFlags(rhs.m_typeFlags)
105 {
106 }
107 
108 // copy assignment
111 {
112  if (this != &rhs) {
114  m_trackParameters.reset(
115  rhs.m_trackParameters ? rhs.m_trackParameters->clone() : nullptr);
116  m_measurementOnTrack.reset(
117  rhs.m_measurementOnTrack ? rhs.m_measurementOnTrack->clone() : nullptr);
119  ? rhs.m_materialEffectsOnTrack->clone()
120  : nullptr);
122  ? std::make_unique<AlignmentEffectsOnTrack>(
124  : nullptr;
125  m_typeFlags = rhs.m_typeFlags;
126  assert(isSane());
127  }
128  return *this;
129 }
130 
131 // move assignment
134 {
135  if (this != &rhs) {
136  m_fitQualityOnSurface = rhs.m_fitQualityOnSurface;
137  m_trackParameters = std::move(rhs.m_trackParameters);
138  m_measurementOnTrack = std::move(rhs.m_measurementOnTrack);
139  m_materialEffectsOnTrack = std::move(rhs.m_materialEffectsOnTrack);
140  m_alignmentEffectsOnTrack = std::move(rhs.m_alignmentEffectsOnTrack);
141  m_typeFlags = rhs.m_typeFlags;
142  }
143  return *this;
144 }
145 
146 std::string
148 {
149  std::string type;
150  const auto& typesSet = types();
151  if (typesSet.test(TrackStateOnSurface::Measurement)) {
152  type += "Measurement ";
153  }
154  if (typesSet.test(TrackStateOnSurface::InertMaterial)) {
155  type += "InertMaterial ";
156  }
157  if (typesSet.test(TrackStateOnSurface::BremPoint)) {
158  type += "BremPoint ";
159  }
160  if (typesSet.test(TrackStateOnSurface::Scatterer)) {
161  type += "Scatterer ";
162  }
163  if (typesSet.test(TrackStateOnSurface::Perigee)) {
164  type += "Perigee ";
165  }
166  if (typesSet.test(TrackStateOnSurface::Outlier)) {
167  type += "Outlier ";
168  }
169  if (typesSet.test(TrackStateOnSurface::Hole)) {
170  type += "Hole ";
171  }
172  if (typesSet.test(TrackStateOnSurface::CaloDeposit)) {
173  type += "CaloDeposit ";
174  }
175  if (typesSet.test(TrackStateOnSurface::Parameter)) {
176  type += "Parameter ";
177  }
178  if (typesSet.test(TrackStateOnSurface::FitQuality)) {
179  type += "FitQuality ";
180  }
181  if (typesSet.test(TrackStateOnSurface::Alignment)) {
182  type += "Alignment ";
183  }
184  return type;
185 }
186 
187 const Surface&
189 {
190  if (m_trackParameters) {
191  return m_trackParameters->associatedSurface();
192  }
193  if (m_measurementOnTrack) {
194  return m_measurementOnTrack->associatedSurface();
195  }
197  return m_materialEffectsOnTrack->associatedSurface();
198  }
199  throw std::runtime_error("TrackStateOnSurface without Surface!");
200 }
201 
202 bool
204 {
205  bool surfacesDiffer =
209  if (surfacesDiffer) {
210  std::cerr << "TrackStateOnSurface::isSane. With :" << '\n';
211  std::cerr << "Types : " << types().to_string() << '\n';
212  std::cerr << "Hints " << hints().to_string() << '\n';
213  std::cerr << "Surfaces differ! " << std::endl;
214  if (m_trackParameters) {
215  std::cerr << "ParamSurf: [" << &(m_trackParameters->associatedSurface())
216  << "] " << m_trackParameters->associatedSurface() << std::endl;
217  }
218  if (m_measurementOnTrack) {
219  std::cerr << "measSurf: [" << &(m_measurementOnTrack->associatedSurface())
220  << "] " << m_measurementOnTrack->associatedSurface()
221  << std::endl;
222  }
224  std::cerr << "matSurf: ["
225  << &(m_materialEffectsOnTrack->associatedSurface()) << "] "
226  << m_materialEffectsOnTrack->associatedSurface() << std::endl;
227  }
228  return false;
229  }
230 
231  return true;
232 }
233 
234 void
236 {
237  // The extra "hidden" bit we save (1<<NumberOfPersistencyHints)
238  // is to dissalow repeated calls to setHints(0).
239  uint8_t exp = 0;
240  if (!m_hints.compare_exchange_strong(
241  exp, hints | (1 << NumberOfPersistencyHints))) {
242  throw std::runtime_error(
243  "TSOS trying to set again already set Persistification Hints");
244  }
245 }
246 
249 MsgStream&
250 operator<<(MsgStream& sl, const TrackStateOnSurface& tsos)
251 {
252  std::string name("TrackStateOnSurface: ");
253  sl << name << "\t of type : " << tsos.dumpType() << endmsg;
254 
255  if (sl.level() < MSG::INFO) {
256  sl << name << "Detailed dump of contained objects follows:" << endmsg;
257  sl << (tsos.fitQualityOnSurface()) << "\n (end of FitQualityOnSurface dump)"
258  << endmsg;
259 
260  if (tsos.trackParameters() != nullptr) {
261  sl << *(tsos.trackParameters()) << "\n (end of TrackParameters dump)"
262  << endmsg;
263  }
264 
265  if (tsos.measurementOnTrack() != nullptr) {
266  sl << *(tsos.measurementOnTrack()) << "\n (end of MeasurementBase dump"
267  << endmsg;
268  }
269 
270  if (tsos.materialEffectsOnTrack() != nullptr) {
271  sl << *(tsos.materialEffectsOnTrack())
272  << "\n (end of MaterialEffectsBase dump)" << endmsg;
273  }
274 
275  if (tsos.alignmentEffectsOnTrack() != nullptr) {
276  sl << *(tsos.alignmentEffectsOnTrack())
277  << "\n (end of AlignmentEffectsOnTrack dump)" << endmsg;
278  }
279  }
280  return sl;
281 }
282 
283 std::ostream&
284 operator<<(std::ostream& sl, const TrackStateOnSurface& tsos)
285 {
286  std::string name("TrackStateOnSurface: ");
287  sl << name << "\t of type : " << tsos.dumpType() << std::endl;
288 
289  sl << "\t FitQualityOnSurface(s)." << std::endl;
290  sl << "\t \t" << (tsos.fitQualityOnSurface()) << std::endl;
291 
292  if (tsos.trackParameters() != nullptr) {
293  sl << "\t HAS TrackParameter(s)." << std::endl;
294  sl << "\t \t" << *(tsos.trackParameters()) << std::endl;
295  } else {
296  sl << "\t NO TrackParameters." << std::endl;
297  }
298 
299  if (tsos.measurementOnTrack() != nullptr) {
300  sl << "\t HAS MeasurementBase(s)." << std::endl;
301  sl << "\t \t" << *(tsos.measurementOnTrack()) << std::endl;
302  } else {
303  sl << "\t NO MeasurementBase." << std::endl;
304  }
305 
306  if (tsos.materialEffectsOnTrack() != nullptr) {
307  sl << "\t HAS MaterialEffectsBase." << std::endl;
308  sl << "\t \t" << *(tsos.materialEffectsOnTrack()) << std::endl;
309  } else {
310  sl << "\t NO MaterialEffects." << std::endl;
311  }
313  if (tsos.alignmentEffectsOnTrack() != nullptr) {
314  sl << "\t HAS AlignmentEffectsOnTrack." << std::endl;
315  sl << "\t \t" << *(tsos.alignmentEffectsOnTrack()) << std::endl;
316  } else {
317  sl << "\t NO AlignmentEffectsOnTrack." << std::endl;
318  }
319  return sl;
320 }
321 } // namespace Trk
Trk::TrackStateOnSurface::trackParameters
const TrackParameters * trackParameters() const
return ptr to trackparameters const overload
Trk::TrackStateOnSurface::m_fitQualityOnSurface
FitQualityOnSurface m_fitQualityOnSurface
Definition: TrackStateOnSurface.h:367
Trk::TrackStateOnSurface::CaloDeposit
@ CaloDeposit
This TSOS contains a CaloEnergy object.
Definition: TrackStateOnSurface.h:135
Trk::TrackStateOnSurface::operator=
Trk::TrackStateOnSurface & operator=(const Trk::TrackStateOnSurface &rhs)
Definition: TrackStateOnSurface.cxx:110
Trk::TrackStateOnSurface::Perigee
@ Perigee
This represents a perigee, and so will contain a Perigee object only.
Definition: TrackStateOnSurface.h:117
Trk::TrackStateOnSurface::NumberOfPersistencyHints
@ NumberOfPersistencyHints
Definition: TrackStateOnSurface.h:174
SurfaceConsistencyCheck.h
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
Trk::TrackStateOnSurface::TrackStateOnSurface
TrackStateOnSurface()
Default ctor for POOL.
Trk::TrackStateOnSurface::surface
const Trk::Surface & surface() const
return associated surface
Definition: TrackStateOnSurface.cxx:188
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
Trk::TrackStateOnSurface::m_materialEffectsOnTrack
std::unique_ptr< MaterialEffectsBase > m_materialEffectsOnTrack
Definition: TrackStateOnSurface.h:370
Trk::TrackStateOnSurface::dumpType
std::string dumpType() const
returns a string with the expanded type of the object (i.e.
Definition: TrackStateOnSurface.cxx:147
Trk::TrackStateOnSurface::measurementOnTrack
const MeasurementBase * measurementOnTrack() const
returns MeasurementBase const overload
Trk::TrackStateOnSurface::types
const std::bitset< NumberOfTrackStateOnSurfaceTypes > types() const
returns a bitset with the types of this bitset.
Trk::TrackStateOnSurface::setFlags
void setFlags()
set sensible default flags
Trk::AlignmentEffectsOnTrack
Class to represent misalignments or 'discontinuities' on tracks These have a surface where the z axis...
Definition: AlignmentEffectsOnTrack.h:24
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
Trk::TrackStateOnSurface::Alignment
@ Alignment
This TSOS contains a Trk::AlignmentEffectsOnTrack.
Definition: TrackStateOnSurface.h:150
python.Utilities.clone
clone
Definition: Utilities.py:134
Trk::TrackStateOnSurface::fitQualityOnSurface
const FitQualityOnSurface & fitQualityOnSurface() const
return FitQuality On Surface const overload
Trk::TrackStateOnSurface::isSane
bool isSane() const
Definition: TrackStateOnSurface.cxx:203
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
Trk::FitQualityOnSurface
Definition: FitQualityOnSurface.h:19
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::TrackStateOnSurface::Hole
@ Hole
A hole on the track - this is defined in the following way.
Definition: TrackStateOnSurface.h:128
Trk::TrackStateOnSurface::materialEffectsOnTrack
const MaterialEffectsBase * materialEffectsOnTrack() const
return material effects const overload
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
Trk::TrackStateOnSurface::Parameter
@ Parameter
This TSOS contains a Trk::ParameterBase.
Definition: TrackStateOnSurface.h:140
Trk::TrackStateOnSurface::BremPoint
@ BremPoint
This represents a brem point on the track, and so will contain TrackParameters and MaterialEffectsBas...
Definition: TrackStateOnSurface.h:109
Trk::TrackStateOnSurface::alignmentEffectsOnTrack
const AlignmentEffectsOnTrack * alignmentEffectsOnTrack() const
return the the alignment effects const overload
Trk::TrackStateOnSurface::m_trackParameters
std::unique_ptr< TrackParameters > m_trackParameters
Definition: TrackStateOnSurface.h:368
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
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:221
Trk::TrackStateOnSurface::InertMaterial
@ InertMaterial
This represents inert material, and so will contain MaterialEffectsBase.
Definition: TrackStateOnSurface.h:105
Trk::TrackStateOnSurface::setHints
void setHints(const uint8_t hints) const
Use this method to set persistification hints.
Definition: TrackStateOnSurface.cxx:235
Trk::TrackStateOnSurface::hints
const std::bitset< NumberOfPersistencyHints > hints() const
Use this method to get the persistification hints.
Trk::operator<<
MsgStream & operator<<(MsgStream &sl, const AlignModule &alignModule)
overload of << operator for MsgStream for debug output
Definition: AlignModule.cxx:204
Trk::TrackStateOnSurface::m_hints
std::atomic< uint8_t > m_hints
Definition: TrackStateOnSurface.h:374
Trk::TrackStateOnSurface::Scatterer
@ Scatterer
This represents a scattering point on the track, and so will contain TrackParameters and MaterialEffe...
Definition: TrackStateOnSurface.h:113
Trk::TrackStateOnSurface::FitQuality
@ FitQuality
This TSOS contains a Trk::FitQualityOnSurface.
Definition: TrackStateOnSurface.h:145
Trk::TrackStateOnSurface::m_measurementOnTrack
std::unique_ptr< MeasurementBase > m_measurementOnTrack
Definition: TrackStateOnSurface.h:369
Trk::TrackStateOnSurface::m_alignmentEffectsOnTrack
std::unique_ptr< AlignmentEffectsOnTrack > m_alignmentEffectsOnTrack
Definition: TrackStateOnSurface.h:371
Trk::consistentSurfaces
bool consistentSurfaces(U)
Definition: SurfaceConsistencyCheck.h:17
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
Trk::TrackStateOnSurface::Measurement
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
Definition: TrackStateOnSurface.h:101
TrackStateOnSurface.h
Trk::TrackStateOnSurface::m_typeFlags
uint16_t m_typeFlags
Definition: TrackStateOnSurface.h:373