ATLAS Offline Software
GXFTrackState.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 // GXFTrackState.cxx
7 // see header file for documentation.
9 //
10 #include "TrkTrack/GXFTrackState.h"
16 #include "TrkSurfaces/Surface.h"
19 #include <utility>
20 
21 namespace Trk {
23  m_measurement(rhs.m_measurement != nullptr ? std::unique_ptr<const MeasurementBase>(rhs.m_measurement->clone()) : nullptr),
24  m_tsType(rhs.m_tsType),
25  m_trackpar(std::unique_ptr<const TrackParameters>(rhs.m_trackpar != nullptr ? rhs.m_trackpar->clone() : nullptr)),
26  m_materialEffects(rhs.m_materialEffects != nullptr ? std::make_unique<GXFMaterialEffects>(*rhs. m_materialEffects) : nullptr),
27  m_derivs(rhs.m_derivs),
28  m_covariancematrix(rhs.m_covariancematrix),
29  m_covariance_set(rhs.m_covariance_set),
30  m_fitqual(rhs.m_fitqual),
31  m_sinstereo(rhs.m_sinstereo),
32  m_mType(rhs.m_mType),
33  m_recalib(rhs.m_recalib),
34  m_measphi(rhs.m_measphi)
35  {
36  for (int i = 0; i < 5; i++) {
37  m_measerror[i] = rhs.m_measerror[i];
38  for (int j = 0; j < 5; j++) {
39  m_jacobian(i, j) = rhs.m_jacobian(i, j);
40  }
41  }
42  }
43 
45  std::unique_ptr<const MeasurementBase> measurement,
46  std::unique_ptr<const TrackParameters> trackpar
47  ):
48  m_measurement(std::move(measurement)),
49  m_trackpar(std::move(trackpar)),
50  m_materialEffects(nullptr),
51  m_jacobian {},
52  m_derivs(),
53  m_covariancematrix(),
54  m_covariance_set(false),
55  m_fitqual(),
56  m_sinstereo(0),
57  m_mType(TrackState::unidentified),
58  m_recalib(false),
59  m_measphi(false) {
61  m_measerror[0] = m_measerror[1] = m_measerror[2] = m_measerror[3] = m_measerror[4] = -1;
62  }
63 
65  std::unique_ptr<const TrackParameters> trackpar,
67  ):
68  m_measurement(nullptr),
69  m_trackpar(std::move(trackpar)),
70  m_materialEffects(nullptr),
71  m_jacobian {},
72  m_derivs(),
73  m_covariancematrix(),
74  m_covariance_set(false),
75  m_fitqual(),
76  m_sinstereo(0),
77  m_mType(TrackState::unidentified),
78  m_recalib(false),
79  m_measphi(false)
80  {
81  setStateType(tsType);
82  m_measerror[0] = m_measerror[1] = m_measerror[2] = m_measerror[3] = m_measerror[4] = -1;
83  }
84 
86  std::unique_ptr<GXFMaterialEffects> mef,
87  std::unique_ptr<const TrackParameters> trackpar
88  ):
89  m_measurement(nullptr),
90  m_trackpar(std::move(trackpar)),
91  m_materialEffects(std::move(mef)),
92  m_jacobian {},
93  m_derivs(),
94  m_covariancematrix(),
95  m_covariance_set(false),
96  m_fitqual(),
97  m_sinstereo(0),
98  m_mType(TrackState::unidentified),
99  m_recalib(false),
100  m_measphi(false)
101  {
102  m_measerror[0] = m_measerror[1] = m_measerror[2] = m_measerror[3] = m_measerror[4] = -1;
103 
104  if (m_materialEffects->sigmaDeltaTheta() == 0) {
105  setStateType(TrackStateOnSurface::BremPoint);
106  } else {
107  setStateType(TrackStateOnSurface::Scatterer);
108  }
109  }
110 
111  bool
114  if (not consistentSurfaces(m_measurement.get(),m_trackpar.get(), eff) ){
115  std::cerr << "GXFTrackState::isSane. With :" << '\n';
116  std::cerr << "Types : " << m_tsType.to_string() << '\n';
117  std::cerr << "Surfaces differ! " << std::endl;
118  if (m_trackpar) {
119  std::cerr << "ParamSurf: [" << &(m_trackpar->associatedSurface())
120  << "] " << m_trackpar->associatedSurface() << std::endl;
121  }
122  if (m_measurement) {
123  std::cerr << "measSurf: [" << &(m_measurement->associatedSurface())
124  << "] " << m_measurement->associatedSurface()
125  << std::endl;
126  }
127  if (m_materialEffects) {
128  std::cerr << "matSurf: ["
129  << &(m_materialEffects->associatedSurface()) << "] "
130  << m_materialEffects->associatedSurface() << std::endl;
131  }
132  return false;
133  }
134  return true;
135  }
136 
137  void GXFTrackState::setMeasurement(std::unique_ptr<const MeasurementBase> meas) {
138  m_measurement = std::move(meas);
139  m_recalib = true;
140  }
141 
143  return m_measurement.get();
144  }
145 
146  void GXFTrackState::setTrackParameters(std::unique_ptr<const TrackParameters> par) {
147  m_trackpar = std::move(par);
148  }
149 
151  m_jacobian = jac;
152  }
153 
154  void
156  m_derivs = deriv;
157  }
158 
160  return m_measerror;
161  }
162 
163  void
164  GXFTrackState::setMeasurementErrors(const double *measerror) {
165  m_measerror[0] = measerror[0];
166  m_measerror[1] = measerror[1];
167  m_measerror[2] = measerror[2];
168  m_measerror[3] = measerror[3];
169  m_measerror[4] = measerror[4];
170  }
171 
172  double
174  return m_sinstereo;
175  }
176 
177  void
178  GXFTrackState::setSinStereo(double sinstereo) {
179  m_sinstereo = sinstereo;
180  }
181 
182  const Surface &
184  if (m_measurement != nullptr) {
185  return m_measurement->associatedSurface();
186  } if (m_trackpar != nullptr) {
187  return m_trackpar->associatedSurface();
188  } if (m_materialEffects != nullptr) {
189  return m_materialEffects->associatedSurface();
190  } else {
191  throw std::runtime_error("GXFTrackState::associatedSurface: None of measurement, track parameters or material effects are non-null pointers");
192  }
193 
194  }
195 
196  void
198  if (covmat == nullptr) {
199  m_covariance_set = false;
200  } else {
201  m_covariance_set = true;
202  m_covariancematrix = *covmat;
203  }
204  }
205 
207  m_fitqual = fitqual;
208  }
209 
211  return m_fitqual;
212  }
213 
214  int
216  int nmeas = 0;
217 
219  for (double i : m_measerror) {
220  if (i > 0) {
221  nmeas++;
222  }
223  }
224  }
225 
226  return nmeas;
227  }
228 
230  if (m_trackpar != nullptr) {
231  return m_trackpar->position();
232  } if (m_measurement != nullptr) {
233  return m_measurement->globalPosition();
234  }
235  // return surface()->center(); // Better than nothing...
236  return m_globpos;
237  }
238 
239  void
241  m_globpos = pos;
242  }
243 
244  bool
246  return m_measphi;
247  }
248 
249  void
251  m_measphi = measphi;
252  }
253 
254  void
256  m_recalib = isrecal;
257  }
258 
260  return m_covariance_set;
261  }
262 
264  m_covariance_set = true;
265  m_covariancematrix.setZero();
266  }
268  if (m_covariance_set) {
269  setTrackCovariance(nullptr);
270  }
271  }
272 
274  m_tsType.reset();
275  setStateType(t, v);
276  }
277 
279  m_tsType[t] = v;
280  }
281 
283  return m_tsType.test(t);
284  }
285 
286  std::optional<std::vector<std::unique_ptr<TrackParameters>>> & GXFTrackState::getHoles(void) {
287  return m_holes;
288  }
289 
290  void GXFTrackState::setHoles(std::vector<std::unique_ptr<TrackParameters>> && v) {
291  m_holes = std::move(v);
292  }
293 
294  std::unique_ptr<const TrackStateOnSurface>
296  std::unique_ptr<TrackParameters> trackpar = unique_clone(m_trackpar.get());
297  std::unique_ptr<MeasurementBase> measurement = unique_clone(m_measurement.get());
298 
300 
301  std::unique_ptr<MaterialEffectsBase> mateff = nullptr;
302  std::bitset<TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> typePattern;
305  typePattern.set(TrackStateOnSurface::Scatterer);
306  }
307 
308  if (m_materialEffects->sigmaDeltaE() > 0) {
309  if (m_materialEffects->sigmaDeltaTheta() == 0) {
310  typePattern.set(TrackStateOnSurface::CaloDeposit);
311  } else {
312  typePattern.set(TrackStateOnSurface::BremPoint);
313  }
314  }
315 
316  if (mateff == nullptr) {
317  mateff = m_materialEffects->makeMEOT();
318  }
319  } else {
321  typePattern.set(TrackStateOnSurface::Measurement);
322  if ((fitQual) && (fitQual.chiSquared() > 1.e5 || fitQual.chiSquared() < 0)) {
323  double newchi2 = 0;
324  int ndf = fitQual.numberDoF();
325 
326  if (fitQual.chiSquared() < 0) {
327  newchi2 = 0;
328  } else if (fitQual.chiSquared() > 1.e5) {
329  newchi2 = 1.e5;
330  }
331 
332  fitQual = FitQualityOnSurface(newchi2, ndf);
333  }
334  } else if (m_tsType.test(TrackStateOnSurface::Outlier)) {
335  typePattern.set(TrackStateOnSurface::Outlier);
336  } else if (m_tsType.test(TrackStateOnSurface::Perigee)) {
337  typePattern.set(TrackStateOnSurface::Perigee);
338  }
339  }
340  return std::make_unique<const TrackStateOnSurface>(
341  fitQual,
342  std::move(measurement),
343  std::move(trackpar),
344  std::move(mateff),
345  typePattern);
346  }
347 }
Trk::GXFTrackState::sinStereo
double sinStereo() const
Definition: GXFTrackState.cxx:173
covarianceTool.ndf
ndf
Definition: covarianceTool.py:678
Trk::TransportJacobian
Definition: TransportJacobian.h:46
Trk::TrackStateOnSurface::CaloDeposit
@ CaloDeposit
This TSOS contains a CaloEnergy object.
Definition: TrackStateOnSurface.h:135
Trk::TrackStateOnSurface::Perigee
@ Perigee
This represents a perigee, and so will contain a Perigee object only.
Definition: TrackStateOnSurface.h:117
Amg::MatrixX
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Definition: EventPrimitives.h:27
Trk::TrackStateOnSurface::TrackStateOnSurfaceType
TrackStateOnSurfaceType
Definition: TrackStateOnSurface.h:98
MeasurementBase.h
SurfaceConsistencyCheck.h
Trk::GXFTrackState::fitQuality
const FitQualityOnSurface fitQuality(void)
Definition: GXFTrackState.cxx:210
Surface.h
Trk::GXFTrackState::trackStateOnSurface
std::unique_ptr< const TrackStateOnSurface > trackStateOnSurface() const
Definition: GXFTrackState.cxx:295
Trk::GXFTrackState::GXFTrackState
GXFTrackState()=delete
Trk::GXFTrackState::numberOfMeasuredParameters
int numberOfMeasuredParameters()
Definition: GXFTrackState.cxx:215
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
GXFTrackState.h
Trk::GXFTrackState::setStateType
void setStateType(TrackStateOnSurface::TrackStateOnSurfaceType type, bool value=true)
Set a specific type bit.
Definition: GXFTrackState.cxx:278
Trk::GXFTrackState::measurement
const MeasurementBase * measurement(void)
Definition: GXFTrackState.cxx:142
Trk::GXFTrackState::getStateType
bool getStateType(TrackStateOnSurface::TrackStateOnSurfaceType type) const
Retrieve the value of a specific type bit.
Definition: GXFTrackState.cxx:282
plotBeamSpotVxVal.covmat
covmat
Definition: plotBeamSpotVxVal.py:206
Trk::GXFTrackState::m_measphi
bool m_measphi
Definition: GXFTrackState.h:140
Trk::GXFTrackState::setMeasuresPhi
void setMeasuresPhi(bool)
Definition: GXFTrackState.cxx:250
Trk::GXFTrackState::setPosition
void setPosition(Amg::Vector3D &)
Definition: GXFTrackState.cxx:240
Trk::GXFTrackState::position
Amg::Vector3D position()
Definition: GXFTrackState.cxx:229
Trk::GXFTrackState::setRecalibrated
void setRecalibrated(bool)
Definition: GXFTrackState.cxx:255
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
TransportJacobian.h
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
Trk::GXFTrackState::setMeasurementErrors
void setMeasurementErrors(const double *)
Definition: GXFTrackState.cxx:164
Trk::TrackState::unidentified
@ unidentified
Definition: TrackStateDefs.h:27
Trk::GXFTrackState::m_fitqual
FitQualityOnSurface m_fitqual
Definition: GXFTrackState.h:135
python.Utilities.clone
clone
Definition: Utilities.py:134
Trk::GXFTrackState::resetStateType
void resetStateType(TrackStateOnSurface::TrackStateOnSurfaceType type, bool value=true)
Set a specific type, wiping all others.
Definition: GXFTrackState.cxx:273
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
MaterialEffectsOnTrack.h
Trk::AmgSymMatrix
AmgSymMatrix(5) &GXFTrackState
Definition: GXFTrackState.h:156
Trk::FitQualityOnSurface
Definition: FitQualityOnSurface.h:19
Trk::GXFTrackState::m_globpos
Amg::Vector3D m_globpos
Definition: GXFTrackState.h:141
Trk::GXFTrackState::m_measerror
double m_measerror[5]
Measurement errors (corrected for stereo angle)
Definition: GXFTrackState.h:136
Trk::GXFTrackState::associatedSurface
const Surface & associatedSurface() const
Definition: GXFTrackState.cxx:183
Trk::GXFTrackState::m_holes
std::optional< std::vector< std::unique_ptr< TrackParameters > > > m_holes
Definition: GXFTrackState.h:142
Trk::GXFTrackState::setHoles
void setHoles(std::vector< std::unique_ptr< TrackParameters >> &&)
Definition: GXFTrackState.cxx:290
Trk::GXFTrackState::setTrackCovariance
void setTrackCovariance(AmgSymMatrix(5) *)
Definition: GXFTrackState.cxx:197
GXFMaterialEffects.h
lumiFormat.i
int i
Definition: lumiFormat.py:85
Trk::GXFTrackState::m_tsType
std::bitset< TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes > m_tsType
type of track state, eg Fittable, Outlier, Scatterer, Brem, Hole
Definition: GXFTrackState.h:126
Trk::GXFTrackState
Definition: GXFTrackState.h:30
Trk::GXFTrackState::setMeasurement
void setMeasurement(std::unique_ptr< const MeasurementBase >)
Definition: GXFTrackState.cxx:137
Trk::GXFTrackState::setDerivatives
void setDerivatives(Amg::MatrixX &)
Definition: GXFTrackState.cxx:155
Trk::GXFTrackState::m_trackpar
std::unique_ptr< const TrackParameters > m_trackpar
track parameters
Definition: GXFTrackState.h:127
Trk::GXFMaterialEffects
class that is similar to MaterialEffectsOnTrack, but has 'set' methods for more flexibility during tr...
Definition: GXFMaterialEffects.h:24
Trk::GXFTrackState::m_materialEffects
std::unique_ptr< GXFMaterialEffects > m_materialEffects
Material effects on track (ie scatterer, brem)
Definition: GXFTrackState.h:128
Trk::GXFTrackState::m_measurement
std::unique_ptr< const MeasurementBase > m_measurement
The measurement defining the track state.
Definition: GXFTrackState.h:125
Trk::ParametersBase
Definition: ParametersBase.h:55
Trk::FitQualityOnSurface::numberDoF
int numberDoF() const
returns the number of degrees of freedom of the overall track or vertex fit as integer
Definition: FitQuality.h:60
Trk::GXFTrackState::measurementErrors
double * measurementErrors()
Definition: GXFTrackState.cxx:159
Trk::TrackStateOnSurface::BremPoint
@ BremPoint
This represents a brem point on the track, and so will contain TrackParameters and MaterialEffectsBas...
Definition: TrackStateOnSurface.h:109
Trk::MeasurementBase
Definition: MeasurementBase.h:58
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
Trk::GXFTrackState::m_recalib
bool m_recalib
Has this measurement already been recalibrated?
Definition: GXFTrackState.h:139
Trk::GXFTrackState::getHoles
std::optional< std::vector< std::unique_ptr< TrackParameters > > > & getHoles(void)
Definition: GXFTrackState.cxx:286
Trk::GXFTrackState::m_derivs
Amg::MatrixX m_derivs
Derivatives of local parameters wrt fit parameters.
Definition: GXFTrackState.h:130
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::GXFTrackState::zeroTrackCovariance
void zeroTrackCovariance(void)
Definition: GXFTrackState.cxx:263
Trk::GXFTrackState::measuresPhi
bool measuresPhi() const
Definition: GXFTrackState.cxx:245
Trk::GXFTrackState::resetTrackCovariance
void resetTrackCovariance()
reset covariance to nullptr
Definition: GXFTrackState.cxx:267
Trk::GXFTrackState::isSane
bool isSane() const
Definition: GXFTrackState.cxx:112
Trk::GXFTrackState::setTrackParameters
void setTrackParameters(std::unique_ptr< const TrackParameters >)
Definition: GXFTrackState.cxx:146
Trk::GXFTrackState::setFitQuality
void setFitQuality(FitQualityOnSurface)
Definition: GXFTrackState.cxx:206
Trk::GXFTrackState::hasTrackCovariance
bool hasTrackCovariance(void) const
Definition: GXFTrackState.cxx:259
Trk::unique_clone
std::unique_ptr< T > unique_clone(const T *v)
Definition: unique_clone.h:8
Trk::TrackStateOnSurface::Scatterer
@ Scatterer
This represents a scattering point on the track, and so will contain TrackParameters and MaterialEffe...
Definition: TrackStateOnSurface.h:113
Trk::GXFTrackState::m_jacobian
Eigen::Matrix< double, 5, 5 > m_jacobian
Transport jacobian wrt previous state.
Definition: GXFTrackState.h:129
Trk::GXFTrackState::setJacobian
void setJacobian(TransportJacobian &)
Definition: GXFTrackState.cxx:150
dqt_zlumi_alleff_HIST.eff
int eff
Definition: dqt_zlumi_alleff_HIST.py:113
Trk::GXFTrackState::m_covariance_set
bool m_covariance_set
Definition: GXFTrackState.h:133
Trk::GXFTrackState::m_sinstereo
double m_sinstereo
stereo angle
Definition: GXFTrackState.h:137
Trk::consistentSurfaces
bool consistentSurfaces(U)
Definition: SurfaceConsistencyCheck.h:17
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
unique_clone.h
Trk::FitQualityOnSurface::chiSquared
double chiSquared() const
returns the of the overall track fit
Definition: FitQuality.h:56
Trk::TrackStateOnSurface::Measurement
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
Definition: TrackStateOnSurface.h:101
TrackStateOnSurface.h
Trk::v
@ v
Definition: ParamDefs.h:78
Trk::GXFTrackState::setSinStereo
void setSinStereo(double)
Definition: GXFTrackState.cxx:178