ATLAS Offline Software
Loading...
Searching...
No Matches
GXFTrajectory.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
12
13
14namespace Trk {
16 m_straightline = true;
17 m_ndof = 0;
18 m_nperpars = -1;
19 m_nscatterers = 0;
21 m_nbrems = 0;
26 m_nsihits = 0;
27 m_ntrthits = 0;
30 m_npseudo = 0;
31 m_nhits = 0;
32 m_noutl = 0;
33 m_nmeasoutl = 0;
34 m_chi2 = 0;
35 m_prevchi2 = 0;
36 m_converged = false;
37 m_prefit = 0;
38 m_refpar.reset(nullptr);
39 m_totx0 = 0;
40 m_toteloss = 0;
41 m_mass = 0;
42 m_caloelossstate = nullptr;
43 }
44
48 m_ndof (rhs.m_ndof),
49 m_chi2 (rhs.m_chi2),
54 m_nbrems (rhs.m_nbrems),
59 m_nhits (rhs.m_nhits),
60 m_noutl (rhs.m_noutl),
61 m_nsihits (rhs.m_nsihits),
65 m_npseudo (rhs.m_npseudo),
67 m_refpar(rhs.m_refpar != nullptr ? rhs.m_refpar->clone() : nullptr),
71 m_brems (rhs.m_brems),
72 m_res (rhs.m_res),
73 m_errors (rhs.m_errors),
75 m_totx0 (rhs.m_totx0),
77 m_mass (rhs.m_mass),
78 m_prefit (rhs.m_prefit),
79 m_caloelossstate (nullptr),
81 {
82
83 m_states.reserve(rhs.m_states.size());
84 for (const std::unique_ptr<GXFTrackState> & i : rhs.m_states) {
85 m_states.emplace_back(std::make_unique<GXFTrackState>(*i));
86 }
87
88 if (rhs.m_caloelossstate != nullptr) {
89 for (auto & state : m_states) {
90 conditionalSetCalorimeterEnergyLossState(state.get());
91 }
92 }
93 }
94
95 GXFTrajectory & GXFTrajectory::operator =(const GXFTrajectory & rhs) {
96 if (this != &rhs) {
99 m_ndof = rhs.m_ndof;
103 m_nbrems = rhs.m_nbrems;
108 m_nsihits = rhs.m_nsihits;
112 m_nhits = rhs.m_nhits;
113 m_npseudo = rhs.m_npseudo;
114 m_noutl = rhs.m_noutl;
116 m_chi2 = rhs.m_chi2;
119 m_prefit = rhs.m_prefit;
120 m_refpar.reset(rhs.m_refpar != nullptr ? rhs.m_refpar->clone() : nullptr);
121
122 m_states.clear();
123 for (const std::unique_ptr<GXFTrackState> & i : rhs.m_states) {
124 m_states.push_back(std::make_unique<GXFTrackState>(*i));
125 }
126
129 m_brems = rhs.m_brems;
130 m_res = rhs.m_res;
131 m_errors = rhs.m_errors;
133 m_totx0 = rhs.m_totx0;
135 m_mass = rhs.m_mass;
136 m_caloelossstate = nullptr;
137
138 if (rhs.m_caloelossstate != nullptr) {
139 for (auto & state : m_states) {
141 }
142 }
144 }
145 return *this;
146 }
147
149 constexpr double perpThreshold = 1400;
150 constexpr double zThreshold = 3700;
151
152 const GXFMaterialEffects *meff = state->materialEffects();
153 const TrackParameters *par = state->trackParameters();
154
155 if (
156 meff != nullptr &&
157 par != nullptr &&
158 meff->sigmaDeltaE() > 0 &&
159 meff->sigmaDeltaPhi() == 0 &&
160 (par->position().perp() > perpThreshold || std::abs(par->position().z()) > zThreshold)
161 ) {
162 m_caloelossstate = state;
163 }
164 }
165
166 bool GXFTrajectory::addMeasurementState(std::unique_ptr<GXFTrackState> state, int index) {
167 if (!m_states.empty() && (m_states.back()->measurement() != nullptr)) {
168 const MeasurementBase *meas = m_states.back()->measurement();
169 const MeasurementBase *meas2 = state->measurement();
170
171 if (
172 &meas->associatedSurface() == &meas2->associatedSurface() &&
174 state->measurementType() != TrackState::MM
175 ) {
176 return false;
177 }
178 }
179
180 int nmeas = 0;
181 double *errors = state->measurementErrors();
182
183 for (int i = 0; i < 5; i++) {
184 if (errors[i] > 0) {
185 nmeas++;
186 }
187 }
188
189 if (state->getStateType(TrackStateOnSurface::Measurement)) {
190 m_ndof += nmeas;
191 } else {
192 m_nmeasoutl += nmeas;
193 m_noutl++;
194 }
195
196 if (state->measurementType() != TrackState::Pseudo) {
197 m_nhits++;
198 }
199
200 if (state->measurementType() == TrackState::Pixel
201 || state->measurementType() == TrackState::SCT) {
202 m_nsihits++;
203 }
204
205 if (state->measurementType() == TrackState::TRT) {
206 m_ntrthits++;
207 if (errors[0]<1) m_ntrtprechits++;
208 if (errors[0]>1) m_ntrttubehits++;
209 }
210
211 if (state->measurementType() == TrackState::Pseudo) {
212 m_npseudo++;
213 }
214
215 if (index == -1) {
216 m_states.push_back(std::move(state));
217 } else {
218 m_states.insert(m_states.begin() + index, std::move(state));
219 }
220
221 return true;
222 }
223
224 void GXFTrajectory::addMaterialState(std::unique_ptr<GXFTrackState> state, int index) {
225 GXFMaterialEffects *meff = state->materialEffects();
226
227 if (state->getStateType(TrackStateOnSurface::Scatterer)) {
229
230 if (meff->deltaE() == 0) {
232 }
233 }
234
235 if (meff->sigmaDeltaE() > 0) {
236 m_nbrems++;
238 }
239
240 m_toteloss += std::abs(meff->deltaE());
241 m_totx0 += meff->x0();
242
243 if (index == -1) {
244 m_states.push_back(std::move(state));
245
246 if (meff->sigmaDeltaE() > 0) {
247 m_brems.push_back(meff->delta_p());
248 }
249 } else {
250 m_states.insert(m_states.begin() + index, std::move(state));
251 int previousbrems = 0;
252
253 for (int i = 0; i < index; i++) {
254 if ((m_states[i]->materialEffects() != nullptr)
255 && m_states[i]->materialEffects()->sigmaDeltaE() > 0) {
256 previousbrems++;
257 }
258 }
259
260 if (meff->sigmaDeltaE() > 0) {
261 m_brems.insert(m_brems.begin() + previousbrems, meff->delta_p());
262 }
263 }
264 }
265
266 void GXFTrajectory::addBasicState(std::unique_ptr<GXFTrackState> state, int index) {
267 if (index == -1) {
268 m_states.push_back(std::move(state));
269 } else {
270 m_states.insert(m_states.begin() + index, std::move(state));
271 }
272 }
273
274 void GXFTrajectory::setReferenceParameters(std::unique_ptr<const TrackParameters> per) {
275 if (m_refpar != nullptr) {
276 m_refpar = std::move(per);
277 return;
278 }
279
280 m_refpar = std::move(per);
281
286
287 for (const auto & state : m_states) {
288 if (state->trackParameters() != nullptr) {
289 const double inprod = m_refpar->momentum().dot(state->position() - m_refpar->position());
290
291 if (inprod > 0) {
292 return;
293 }
294 } else {
295 const DistanceSolution distsol =
296 state->associatedSurface().straightLineDistanceEstimate(m_refpar->position(), m_refpar->momentum().unit());
297
298 double distance = 0;
299 if (distsol.numberOfSolutions() == 1) {
300 distance = distsol.first();
301 } else if (distsol.numberOfSolutions() == 2) {
302 distance =
303 std::abs(distsol.first()) < std::abs(distsol.second()) ?
304 distsol.first() :
305 distsol.second();
306 }
307
308 if (distance > 0) {
309 return;
310 }
311 }
312
314
315 const GXFMaterialEffects *meff = state->materialEffects();
316
317 if (
318 state->getStateType(TrackStateOnSurface::Scatterer) &&
319 meff->sigmaDeltaTheta() != 0
320 ) {
322
323 if (meff->deltaE() == 0) {
325 }
326 }
327
328 if (meff != nullptr && meff->sigmaDeltaE() > 0) {
330 }
331 }
332 }
333
337
339 m_refpar.reset(nullptr);
340 }
341
343 m_ndof -= nperpar;
344 m_nperpars = nperpar;
345 }
346
347 void GXFTrajectory::setOutlier(int index, bool isoutlier) {
348 if (isoutlier && m_states[index]->getStateType(TrackStateOnSurface::Outlier)) {
349 return;
350 }
351
352 if (!isoutlier && m_states[index]->getStateType(TrackStateOnSurface::Measurement)) {
353 return;
354 }
355
356 int nmeas = 0;
357 double *errors = m_states[index]->measurementErrors();
358
359 for (int i = 0; i < 5; i++) {
360 if (errors[i] > 0) {
361 nmeas++;
362 }
363 }
364
365 if (isoutlier) {
366 m_ndof -= nmeas;
368 m_nmeasoutl += nmeas;
369 m_noutl++;
370 m_states[index]->setFitQuality({});
371 } else {
372 m_ndof += nmeas;
374 m_nmeasoutl -= nmeas;
375 m_noutl--;
376 }
377 }
378
379 void GXFTrajectory::updateTRTHitCount(int index, float oldError) {
380 const double error = (m_states[index]->measurementErrors())[0];
381 if (m_states[index]->getStateType(TrackStateOnSurface::Outlier)) {
382 if (oldError<1) { m_ntrtprechits--; }
383 else {m_ntrttubehits--; }
384 }
385 if (error>1 && oldError<1) { // was precison, became tube
388 }
389 else if (error<1 && oldError>1) { // was tube, became precision
392 }
393 }
394
395 void GXFTrajectory::setPrefit(int isprefit) {
396 m_prefit = isprefit;
397 }
398
399 void GXFTrajectory::setConverged(bool isconverged) {
400 m_converged = isconverged;
401 }
402
404 m_res.resize(0);
405 m_weightresderiv.resize(0, 0);
406 m_errors.resize(0);
407 m_scatteringangles.clear();
408 m_scatteringsigmas.clear();
409 m_converged = false;
410 m_refpar.reset(nullptr);
411 }
412
414 return m_converged;
415 }
416
418 return m_prefit;
419 }
420
422 return m_nhits;
423 }
424
426 return m_noutl;
427 }
428
430 return m_nsihits;
431 }
432
434 return m_ntrthits;
435 }
436
438 return m_ntrtprechits;
439 }
440
442 return m_ntrttubehits;
443 }
444
448
450 if (m_prefit != 0) {
451 return m_ncaloscatterers;
452 }
453 return m_nscatterers;
454 }
455
457 m_nscatterers = nscat;
458 }
459
461 return m_nbrems;
462 }
463
465 m_nbrems = nbrem;
466 }
467
471
473 if (m_prefit == 0) {
475 }
477 }
478
482
486
488 if (m_prefit == 1) {
490 }
492 }
493
494 double GXFTrajectory::chi2() const {
495 return m_chi2;
496 }
497
498 double GXFTrajectory::prevchi2() const {
499 return m_prevchi2;
500 }
501
503 m_chi2 = chi2;
504 }
505
508 }
509
511 return m_ndof;
512 }
513
514 std::vector<std::pair<double, double>> & GXFTrajectory::scatteringAngles() {
515 if (m_scatteringangles.empty() && numberOfScatterers() > 0) {
516 m_scatteringsigmas.clear();
519 for (auto & state : m_states) {
520 if ((*state).getStateType(TrackStateOnSurface::Scatterer)
521 && ((m_prefit == 0) || (*state).materialEffects()->deltaE() == 0)) {
522 const double scatphi = (*state).materialEffects()->deltaPhi();
523 const double scattheta = (*state).materialEffects()->deltaTheta();
524 m_scatteringangles.emplace_back(scatphi, scattheta);
525 const double sigmascatphi = (*state).materialEffects()->sigmaDeltaPhi();
526 const double sigmascattheta = (*state).materialEffects()->sigmaDeltaTheta();
528 emplace_back(sigmascatphi, sigmascattheta);
529 }
530 }
531 }
532 return m_scatteringangles;
533 }
534
535 std::vector < std::pair < double, double >>&
542
543 std::vector<double> & GXFTrajectory::brems() {
544 return m_brems;
545 }
546
547 void
548
549 GXFTrajectory::setScatteringAngles(std::vector < std::pair < double,
550 double > >&scatteringangles) {
551 m_scatteringangles = scatteringangles;
552 int scatno = 0;
553 for (auto & state : m_states) {
554 if ((*state).getStateType(TrackStateOnSurface::Scatterer)
555 && ((m_prefit == 0) || (*state).materialEffects()->deltaE() == 0)) {
556 const double scatphi = scatteringangles[scatno].first;
557 const double scattheta = scatteringangles[scatno].second;
558 (*state).materialEffects()->setScatteringAngles(scatphi, scattheta);
559 scatno++;
560 }
561 }
562 }
563
564 void
565 GXFTrajectory::setBrems(std::vector<double> & brems) {
566 // if (m_prefit==1) return;
567 m_brems = brems;
568 int bremno = 0;
569 for (auto & state : m_states) {
570 if (((*state).materialEffects() != nullptr)
571 && (*state).materialEffects()->sigmaDeltaE() > 0) {
572 (*state).materialEffects()->setdelta_p(m_brems[bremno]);
573 bremno++;
574 }
575 }
576 }
577
578 const std::vector<std::unique_ptr<GXFTrackState>> & GXFTrajectory::trackStates() const {
579 return m_states;
580 }
581
582 std::vector<std::unique_ptr<GXFTrackState>> & GXFTrajectory::trackStates() {
583 return m_states;
584 }
585
587 if (m_res.size() == 0) {
589 }
590 return m_res;
591 }
592
594 if (m_errors.size() == 0) {
596 }
597 return m_errors;
598 }
599
609
610 double
612 return m_totx0;
613 }
614
615 double
617 return m_toteloss;
618 }
619
620 double
622 return m_mass;
623 }
624
625 void
627 m_mass = mass;
628 }
629
633
634 std::vector < std::pair < const Layer *, const Layer *>>&
638
639 std::pair<GXFTrackState *, GXFTrackState *> GXFTrajectory::findFirstLastMeasurement(void) {
640 GXFTrackState *firstmeasstate = nullptr;
641 GXFTrackState *lastmeasstate = nullptr;
642
643 for (std::unique_ptr<GXFTrackState> & hit : trackStates()) {
644 if (hit->measurement() != nullptr) {
645 if (firstmeasstate == nullptr) {
646 firstmeasstate = hit.get();
647 }
648 lastmeasstate = hit.get();
649 }
650 }
651
652 if (firstmeasstate == nullptr) {
653 throw std::logic_error("no first measurement.");
654 }
655
656 return std::make_pair(firstmeasstate, lastmeasstate);
657 }
658
660 for (auto & hit : trackStates()) {
661 if (
662 hit->measurementType() == TrackState::Pseudo &&
663 hit->getStateType(TrackStateOnSurface::Outlier)
664 ) {
665 continue;
666 }
667
668 if (
669 (hit->materialEffects() != nullptr) &&
670 hit->materialEffects()->isKink()
671 ) {
672 return true;
673 }
674 }
675
676 return false;
677 }
678
680 for (std::unique_ptr<GXFTrackState> & hit : trackStates()) {
681 hit->setTrackCovariance(nullptr);
682 }
683 }
684
685 std::unique_ptr<const FitQuality> GXFTrajectory::quality(void) const {
686 return std::make_unique<const FitQuality>(chi2(), nDOF());
687 }
688}
if(febId1==febId2)
Access to distance solutions.
double second() const
Distance to second intersection solution along direction (for a cylinder surface)
int numberOfSolutions() const
Number of intersection solutions.
double first() const
Distance to first intersection solution along direction.
class that is similar to MaterialEffectsOnTrack, but has 'set' methods for more flexibility during tr...
const TrackParameters * trackParameters(void) const
GXFMaterialEffects * materialEffects()
std::vector< std::unique_ptr< GXFTrackState > > m_states
The vector of track states, i.e.
void setPrevChi2(double)
int numberOfOutliers() const
void resetCovariances(void)
std::vector< double > & brems()
double chi2() const
double totalX0() const
void setNumberOfScatterers(int)
double mass() const
Amg::VectorX m_errors
int numberOfSiliconHits() const
std::vector< std::pair< const Layer *, const Layer * > > & upstreamMaterialLayers()
std::unique_ptr< const FitQuality > quality(void) const
int numberOfFitParameters() const
int numberOfTRTPrecHits() const
GXFTrackState * m_caloelossstate
double prevchi2() const
Amg::MatrixX & weightedResidualDerivatives()
std::vector< std::pair< const Layer *, const Layer * > > m_upstreammat
const std::vector< std::unique_ptr< GXFTrackState > > & trackStates() const
Amg::MatrixX m_weightresderiv
int numberOfTRTTubeHits() const
void conditionalSetCalorimeterEnergyLossState(GXFTrackState *)
int numberOfTRTHits() const
int numberOfUpstreamBrems() const
double totalEnergyLoss() const
std::unique_ptr< const TrackParameters > m_refpar
int numberOfUpstreamScatterers() const
int numberOfUpstreamStates() const
MagneticFieldProperties m_fieldprop
void setNumberOfPerigeeParameters(int)
const TrackParameters * referenceParameters()
std::vector< std::pair< double, double > > & scatteringSigmas()
std::vector< std::pair< double, double > > m_scatteringangles
std::pair< GXFTrackState *, GXFTrackState * > findFirstLastMeasurement(void)
void addMaterialState(std::unique_ptr< GXFTrackState >, int index=-1)
GXFTrackState * caloElossState()
int numberOfScatterers() const
bool addMeasurementState(std::unique_ptr< GXFTrackState >, int index=-1)
std::vector< std::pair< double, double > > & scatteringAngles()
void addBasicState(std::unique_ptr< GXFTrackState >, int index=-1)
Amg::VectorX & residuals()
void setBrems(std::vector< double > &)
std::vector< std::pair< double, double > > m_scatteringsigmas
int numberOfPerigeeParameters() const
int numberOfBrems() const
Amg::VectorX & errors()
std::vector< double > m_brems
void setOutlier(int, bool isoutlier=true)
void updateTRTHitCount(int index, float oldError)
void setScatteringAngles(std::vector< std::pair< double, double > > &)
int numberOfPseudoMeasurements() const
void setReferenceParameters(std::unique_ptr< const TrackParameters >)
int parameterKey() const
Identifier key for matrix expansion/reduction.
This class is the pure abstract base class for all fittable tracking measurements.
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
virtual const Surface & associatedSurface() const =0
Interface method to get the associated Surface.
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
@ Outlier
This TSoS contains an outlier, that is, it contains a MeasurementBase/RIO_OnTrack which was not used ...
@ Scatterer
This represents a scattering point on the track, and so will contain TrackParameters and MaterialEffe...
double chi2(TH1 *h0, TH1 *h1)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.
Ensure that the ATLAS eigen extensions are properly loaded.
ParametersBase< TrackParametersDim, Charged > TrackParameters
Definition index.py:1