Project
Loading...
Searching...
No Matches
TrackParam.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
18
19#include <iomanip>
20#include <iostream>
21
22#include <TMath.h>
23
24#include "Framework/Logger.h"
25
27
28namespace o2
29{
30namespace mch
31{
32
33using namespace std;
34
35//_________________________________________________________________________
36TrackParam::TrackParam(Double_t z, const Double_t param[5]) : mZ(z)
37{
40}
41
42//_________________________________________________________________________
43TrackParam::TrackParam(Double_t z, const Double_t param[5], const Double_t cov[15]) : mZ(z)
44{
47 setCovariances(cov);
48}
49
50//_________________________________________________________________________
52 : mZ(tp.mZ),
53 mParameters(tp.mParameters),
54 mClusterPtr(tp.mClusterPtr),
55 mRemovable(tp.mRemovable),
56 mTrackChi2(tp.mTrackChi2),
57 mLocalChi2(tp.mLocalChi2)
58{
60 if (tp.mCovariances) {
61 mCovariances = std::make_unique<TMatrixD>(*(tp.mCovariances));
62 }
63 if (tp.mPropagator) {
64 mPropagator = std::make_unique<TMatrixD>(*(tp.mPropagator));
65 }
66 if (tp.mExtrapParameters) {
67 mExtrapParameters = std::make_unique<TMatrixD>(*(tp.mExtrapParameters));
68 }
69 if (tp.mExtrapCovariances) {
70 mExtrapCovariances = std::make_unique<TMatrixD>(*(tp.mExtrapCovariances));
71 }
72 if (tp.mSmoothParameters) {
73 mSmoothParameters = std::make_unique<TMatrixD>(*(tp.mSmoothParameters));
74 }
75 if (tp.mSmoothCovariances) {
76 mSmoothCovariances = std::make_unique<TMatrixD>(*(tp.mSmoothCovariances));
77 }
78}
79
80//_________________________________________________________________________
82{
84 if (this == &tp) {
85 return *this;
86 }
87
88 mZ = tp.mZ;
89
90 mParameters = tp.mParameters;
91
92 if (tp.mCovariances) {
93 if (mCovariances) {
94 *mCovariances = *(tp.mCovariances);
95 } else {
96 mCovariances = std::make_unique<TMatrixD>(*(tp.mCovariances));
97 }
98 } else {
99 mCovariances.reset();
100 }
101
102 if (tp.mPropagator) {
103 if (mPropagator) {
104 *mPropagator = *(tp.mPropagator);
105 } else {
106 mPropagator = std::make_unique<TMatrixD>(*(tp.mPropagator));
107 }
108 } else {
109 mPropagator.reset();
110 }
111
112 if (tp.mExtrapParameters) {
113 if (mExtrapParameters) {
114 *mExtrapParameters = *(tp.mExtrapParameters);
115 } else {
116 mExtrapParameters = std::make_unique<TMatrixD>(*(tp.mExtrapParameters));
117 }
118 } else {
119 mExtrapParameters.reset();
120 }
121
122 if (tp.mExtrapCovariances) {
123 if (mExtrapCovariances) {
124 *mExtrapCovariances = *(tp.mExtrapCovariances);
125 } else {
126 mExtrapCovariances = std::make_unique<TMatrixD>(*(tp.mExtrapCovariances));
127 }
128 } else {
129 mExtrapCovariances.reset();
130 }
131
132 if (tp.mSmoothParameters) {
133 if (mSmoothParameters) {
134 *mSmoothParameters = *(tp.mSmoothParameters);
135 } else {
136 mSmoothParameters = std::make_unique<TMatrixD>(*(tp.mSmoothParameters));
137 }
138 } else {
139 mSmoothParameters.reset();
140 }
141
142 if (tp.mSmoothCovariances) {
143 if (mSmoothCovariances) {
144 *mSmoothCovariances = *(tp.mSmoothCovariances);
145 } else {
146 mSmoothCovariances = std::make_unique<TMatrixD>(*(tp.mSmoothCovariances));
147 }
148 } else {
149 mSmoothCovariances.reset();
150 }
151
152 mClusterPtr = tp.mClusterPtr;
153
154 mRemovable = tp.mRemovable;
155
156 mTrackChi2 = tp.mTrackChi2;
157 mLocalChi2 = tp.mLocalChi2;
158
159 return *this;
160}
161
162//__________________________________________________________________________
164{
167 mPropagator.reset();
168 mExtrapParameters.reset();
169 mExtrapCovariances.reset();
170 mSmoothParameters.reset();
171 mSmoothCovariances.reset();
172}
173
174//__________________________________________________________________________
175Double_t TrackParam::px() const
176{
178 Double_t pZ;
179 if (TMath::Abs(mParameters(4, 0)) > 0) {
180 Double_t pYZ = TMath::Abs(1.0 / mParameters(4, 0));
181 pZ = -pYZ / (TMath::Sqrt(1.0 + mParameters(3, 0) * mParameters(3, 0))); // spectro. (z<0)
182 } else {
183 pZ = -FLT_MAX / TMath::Sqrt(1.0 + mParameters(3, 0) * mParameters(3, 0) + mParameters(1, 0) * mParameters(1, 0));
184 }
185 return pZ * mParameters(1, 0);
186}
187
188//__________________________________________________________________________
189Double_t TrackParam::py() const
190{
192 Double_t pZ;
193 if (TMath::Abs(mParameters(4, 0)) > 0) {
194 Double_t pYZ = TMath::Abs(1.0 / mParameters(4, 0));
195 pZ = -pYZ / (TMath::Sqrt(1.0 + mParameters(3, 0) * mParameters(3, 0))); // spectro. (z<0)
196 } else {
197 pZ = -FLT_MAX / TMath::Sqrt(1.0 + mParameters(3, 0) * mParameters(3, 0) + mParameters(1, 0) * mParameters(1, 0));
198 }
199 return pZ * mParameters(3, 0);
200}
201
202//__________________________________________________________________________
203Double_t TrackParam::pz() const
204{
206 if (TMath::Abs(mParameters(4, 0)) > 0) {
207 Double_t pYZ = TMath::Abs(1.0 / mParameters(4, 0));
208 return -pYZ / (TMath::Sqrt(1.0 + mParameters(3, 0) * mParameters(3, 0))); // spectro. (z<0)
209 } else {
210 return -FLT_MAX / TMath::Sqrt(1.0 + mParameters(3, 0) * mParameters(3, 0) + mParameters(1, 0) * mParameters(1, 0));
211 }
212}
213
214//__________________________________________________________________________
215Double_t TrackParam::p() const
216{
218 if (TMath::Abs(mParameters(4, 0)) > 0) {
219 Double_t pYZ = TMath::Abs(1.0 / mParameters(4, 0));
220 Double_t pZ = -pYZ / (TMath::Sqrt(1.0 + mParameters(3, 0) * mParameters(3, 0))); // spectro. (z<0)
221 return -pZ * TMath::Sqrt(1.0 + mParameters(3, 0) * mParameters(3, 0) + mParameters(1, 0) * mParameters(1, 0));
222 } else {
223 return FLT_MAX;
224 }
225}
226
227//__________________________________________________________________________
228const TMatrixD& TrackParam::getCovariances() const
229{
231 if (!mCovariances) {
232 mCovariances = std::make_unique<TMatrixD>(5, 5);
233 mCovariances->Zero();
234 }
235 return *mCovariances;
236}
237
238//__________________________________________________________________________
239void TrackParam::setCovariances(const TMatrixD& covariances)
240{
242 if (mCovariances) {
243 *mCovariances = covariances;
244 } else {
245 mCovariances = std::make_unique<TMatrixD>(covariances);
246 }
247}
248
249//__________________________________________________________________________
250void TrackParam::setCovariances(const Double_t covariances[15])
251{
258 if (!mCovariances) {
259 mCovariances = std::make_unique<TMatrixD>(5, 5);
260 }
261 for (Int_t i = 0; i < 5; i++) {
262 for (Int_t j = 0; j <= i; j++) {
263 (*mCovariances)(i, j) = (*mCovariances)(j, i) = covariances[i * (i + 1) / 2 + j];
264 }
265 }
266}
267
268//__________________________________________________________________________
269void TrackParam::setVariances(const Double_t covariances[15])
270{
277 static constexpr int varIdx[5] = {0, 2, 5, 9, 14};
278 if (!mCovariances) {
279 mCovariances = std::make_unique<TMatrixD>(5, 5);
280 }
281 mCovariances->Zero();
282 for (Int_t i = 0; i < 5; i++) {
283 (*mCovariances)(i, i) = covariances[varIdx[i]];
284 }
285}
286
287//__________________________________________________________________________
289{
291 mCovariances.reset();
292}
293
294//__________________________________________________________________________
295const TMatrixD& TrackParam::getPropagator() const
296{
298 if (!mPropagator) {
299 mPropagator = std::make_unique<TMatrixD>(5, 5);
300 mPropagator->UnitMatrix();
301 }
302 return *mPropagator;
303}
304
305//__________________________________________________________________________
307{
309 if (mPropagator) {
310 mPropagator->UnitMatrix();
311 }
312}
313
314//__________________________________________________________________________
315void TrackParam::updatePropagator(const TMatrixD& propagator)
316{
318 if (mPropagator) {
319 *mPropagator = TMatrixD(propagator, TMatrixD::kMult, *mPropagator);
320 } else {
321 mPropagator = std::make_unique<TMatrixD>(propagator);
322 }
323}
324
325//__________________________________________________________________________
326const TMatrixD& TrackParam::getExtrapParameters() const
327{
329 if (!mExtrapParameters) {
330 mExtrapParameters = std::make_unique<TMatrixD>(5, 1);
331 mExtrapParameters->Zero();
332 }
333 return *mExtrapParameters;
334}
335
336//__________________________________________________________________________
337void TrackParam::setExtrapParameters(const TMatrixD& extrapParameters)
338{
340 if (mExtrapParameters) {
341 *mExtrapParameters = extrapParameters;
342 } else {
343 mExtrapParameters = std::make_unique<TMatrixD>(extrapParameters);
344 }
345}
346
347//__________________________________________________________________________
348const TMatrixD& TrackParam::getExtrapCovariances() const
349{
351 if (!mExtrapCovariances) {
352 mExtrapCovariances = std::make_unique<TMatrixD>(5, 5);
353 mExtrapCovariances->Zero();
354 }
355 return *mExtrapCovariances;
356}
357
358//__________________________________________________________________________
359void TrackParam::setExtrapCovariances(const TMatrixD& extrapCovariances)
360{
362 if (mExtrapCovariances) {
363 *mExtrapCovariances = extrapCovariances;
364 } else {
365 mExtrapCovariances = std::make_unique<TMatrixD>(extrapCovariances);
366 }
367}
368
369//__________________________________________________________________________
370const TMatrixD& TrackParam::getSmoothParameters() const
371{
373 if (!mSmoothParameters) {
374 mSmoothParameters = std::make_unique<TMatrixD>(5, 1);
375 mSmoothParameters->Zero();
376 }
377 return *mSmoothParameters;
378}
379
380//__________________________________________________________________________
381void TrackParam::setSmoothParameters(const TMatrixD& smoothParameters)
382{
384 if (mSmoothParameters) {
385 *mSmoothParameters = smoothParameters;
386 } else {
387 mSmoothParameters = std::make_unique<TMatrixD>(smoothParameters);
388 }
389}
390
391//__________________________________________________________________________
392const TMatrixD& TrackParam::getSmoothCovariances() const
393{
395 if (!mSmoothCovariances) {
396 mSmoothCovariances = std::make_unique<TMatrixD>(5, 5);
397 mSmoothCovariances->Zero();
398 }
399 return *mSmoothCovariances;
400}
401
402//__________________________________________________________________________
403void TrackParam::setSmoothCovariances(const TMatrixD& smoothCovariances)
404{
406 if (mSmoothCovariances) {
407 *mSmoothCovariances = smoothCovariances;
408 } else {
409 mSmoothCovariances = std::make_unique<TMatrixD>(smoothCovariances);
410 }
411}
412
413//__________________________________________________________________________
414Bool_t TrackParam::isCompatibleTrackParam(const TrackParam& trackParam, Double_t sigma2Cut, Double_t& chi2) const
415{
420
421 // reset chi2 value
422 chi2 = 0.;
423
424 // ckeck covariance matrices
425 if (!mCovariances && !trackParam.mCovariances) {
426 LOG(error) << "Covariance matrix must exist for at least one set of parameters";
427 return kFALSE;
428 }
429
430 Double_t maxChi2 = 5. * sigma2Cut * sigma2Cut; // 5 degrees of freedom
431
432 // check Z parameters
433 if (mZ != trackParam.mZ) {
434 LOG(warn) << "Parameters are given at different Z position (" << mZ << " : " << trackParam.mZ
435 << "): results are meaningless";
436 }
437
438 // compute the parameter residuals
439 TMatrixD deltaParam(mParameters, TMatrixD::kMinus, trackParam.mParameters);
440
441 // build the error matrix
442 TMatrixD weight(5, 5);
443 if (mCovariances) {
444 weight += *mCovariances;
445 }
446 if (trackParam.mCovariances) {
447 weight += *(trackParam.mCovariances);
448 }
449
450 // invert the error matrix to get the parameter weights if possible
451 if (weight.Determinant() == 0) {
452 LOG(error) << "Cannot compute the compatibility chi2";
453 return kFALSE;
454 }
455 weight.Invert();
456
457 // compute the compatibility chi2
458 TMatrixD tmp(deltaParam, TMatrixD::kTransposeMult, weight);
459 TMatrixD mChi2(tmp, TMatrixD::kMult, deltaParam);
460
461 // set chi2 value
462 chi2 = mChi2(0, 0);
463
464 // check compatibility
465 if (chi2 > maxChi2) {
466 return kFALSE;
467 }
468
469 return kTRUE;
470}
471
472//__________________________________________________________________________
474{
476
478
480 param.y = getBendingCoor();
481 param.z = getZ();
482 param.px = px();
483 param.py = py();
484 param.pz = pz();
485 param.sign = getCharge();
486
487 return param;
488}
489
490//__________________________________________________________________________
492{
494 cout << "<TrackParam> Bending P=" << setw(5) << setprecision(3) << 1. / mParameters(4, 0)
495 << ", NonBendSlope=" << setw(5) << setprecision(3) << mParameters(1, 0) * 180. / TMath::Pi()
496 << ", BendSlope=" << setw(5) << setprecision(3) << mParameters(3, 0) * 180. / TMath::Pi() << ", (x,y,z)_IP=("
497 << setw(5) << setprecision(3) << mParameters(0, 0) << "," << setw(5) << setprecision(3) << mParameters(2, 0)
498 << "," << setw(5) << setprecision(3) << mZ << ") cm, (px,py,pz)=(" << setw(5) << setprecision(3) << px() << ","
499 << setw(5) << setprecision(3) << py() << "," << setw(5) << setprecision(3) << pz() << ") GeV/c, "
500 << "local chi2=" << getLocalChi2() << endl;
501}
502
503} // namespace mch
504} // namespace o2
Definition of the MCH cluster minimal structure.
int32_t i
uint32_t j
Definition RawData.h:0
Definition of the MCH track parameters for internal use.
track parameters for internal use
Definition TrackParam.h:34
const TMatrixD & getExtrapCovariances() const
const TMatrixD & getSmoothCovariances() const
Double_t getLocalChi2() const
return the local chi2 of the associated cluster with respect to the track
Definition TrackParam.h:134
Double_t pz() const
TrackParam & operator=(const TrackParam &tp)
Double_t getNonBendingCoor() const
return non bending coordinate (cm)
Definition TrackParam.h:51
Double_t py() const
Bool_t isCompatibleTrackParam(const TrackParam &trackParam, Double_t sigma2Cut, Double_t &normChi2) const
void setVariances(const Double_t covariances[15])
void setExtrapCovariances(const TMatrixD &covariances)
void setSmoothCovariances(const TMatrixD &covariances)
Double_t getZ() const
return Z coordinate (cm)
Definition TrackParam.h:47
void setCovariances(const TMatrixD &covariances)
const TMatrixD & getPropagator() const
const TMatrixD & getCovariances() const
const TMatrixD & getExtrapParameters() const
Double_t getBendingCoor() const
return bending coordinate (cm)
Definition TrackParam.h:59
void setParameters(const TMatrixD &parameters)
set track parameters
Definition TrackParam.h:83
Double_t px() const
void updatePropagator(const TMatrixD &propagator)
Double_t p() const
const TMatrixD & getSmoothParameters() const
TrackParamStruct getTrackParamStruct() const
void setSmoothParameters(const TMatrixD &parameters)
void setExtrapParameters(const TMatrixD &parameters)
Double_t getCharge() const
return the charge (assumed forward motion)
Definition TrackParam.h:71
GLuint GLuint GLfloat weight
Definition glcorearb.h:5477
GLenum GLfloat param
Definition glcorearb.h:271
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
track parameters minimal structure
Definition TrackBlock.h:28
double x
track position along x
Definition TrackBlock.h:29
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"