]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - MUON/AliMUONTrackParam.cxx
Fix coverity defect
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackParam.cxx
... / ...
CommitLineData
1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17
18//-----------------------------------------------------------------------------
19// Class AliMUONTrackParam
20//-------------------------
21// Track parameters in ALICE dimuon spectrometer
22//-----------------------------------------------------------------------------
23
24#include "AliMUONTrackParam.h"
25#include "AliMUONVCluster.h"
26
27#include "AliLog.h"
28
29#include <TMath.h>
30
31#include <Riostream.h>
32
33/// \cond CLASSIMP
34ClassImp(AliMUONTrackParam) // Class implementation in ROOT context
35/// \endcond
36
37 //_________________________________________________________________________
38AliMUONTrackParam::AliMUONTrackParam()
39 : TObject(),
40 fZ(0.),
41 fParameters(5,1),
42 fCovariances(0x0),
43 fPropagator(0x0),
44 fExtrapParameters(0x0),
45 fExtrapCovariances(0x0),
46 fSmoothParameters(0x0),
47 fSmoothCovariances(0x0),
48 fClusterPtr(0x0),
49 fOwnCluster(kFALSE),
50 fRemovable(kFALSE),
51 fTrackChi2(0.),
52 fLocalChi2(0.)
53{
54 /// Constructor
55 fParameters.Zero();
56}
57
58 //_________________________________________________________________________
59AliMUONTrackParam::AliMUONTrackParam(const AliMUONTrackParam& theMUONTrackParam)
60 : TObject(theMUONTrackParam),
61 fZ(theMUONTrackParam.fZ),
62 fParameters(theMUONTrackParam.fParameters),
63 fCovariances(0x0),
64 fPropagator(0x0),
65 fExtrapParameters(0x0),
66 fExtrapCovariances(0x0),
67 fSmoothParameters(0x0),
68 fSmoothCovariances(0x0),
69 fClusterPtr(0x0),
70 fOwnCluster(theMUONTrackParam.fOwnCluster),
71 fRemovable(theMUONTrackParam.fRemovable),
72 fTrackChi2(theMUONTrackParam.fTrackChi2),
73 fLocalChi2(theMUONTrackParam.fLocalChi2)
74{
75 /// Copy constructor
76 if (theMUONTrackParam.fCovariances) fCovariances = new TMatrixD(*(theMUONTrackParam.fCovariances));
77 if (theMUONTrackParam.fPropagator) fPropagator = new TMatrixD(*(theMUONTrackParam.fPropagator));
78 if (theMUONTrackParam.fExtrapParameters) fExtrapParameters = new TMatrixD(*(theMUONTrackParam.fExtrapParameters));
79 if (theMUONTrackParam.fExtrapCovariances) fExtrapCovariances = new TMatrixD(*(theMUONTrackParam.fExtrapCovariances));
80 if (theMUONTrackParam.fSmoothParameters) fSmoothParameters = new TMatrixD(*(theMUONTrackParam.fSmoothParameters));
81 if (theMUONTrackParam.fSmoothCovariances) fSmoothCovariances = new TMatrixD(*(theMUONTrackParam.fSmoothCovariances));
82
83 if(fOwnCluster) fClusterPtr = static_cast<AliMUONVCluster*>(theMUONTrackParam.fClusterPtr->Clone());
84 else fClusterPtr = theMUONTrackParam.fClusterPtr;
85}
86
87 //_________________________________________________________________________
88AliMUONTrackParam& AliMUONTrackParam::operator=(const AliMUONTrackParam& theMUONTrackParam)
89{
90 /// Asignment operator
91 if (this == &theMUONTrackParam)
92 return *this;
93
94 // base class assignement
95 TObject::operator=(theMUONTrackParam);
96
97 fZ = theMUONTrackParam.fZ;
98
99 fParameters = theMUONTrackParam.fParameters;
100
101 if (theMUONTrackParam.fCovariances) {
102 if (fCovariances) *fCovariances = *(theMUONTrackParam.fCovariances);
103 else fCovariances = new TMatrixD(*(theMUONTrackParam.fCovariances));
104 } else {
105 delete fCovariances;
106 fCovariances = 0x0;
107 }
108
109 if (theMUONTrackParam.fPropagator) {
110 if (fPropagator) *fPropagator = *(theMUONTrackParam.fPropagator);
111 else fPropagator = new TMatrixD(*(theMUONTrackParam.fPropagator));
112 } else {
113 delete fPropagator;
114 fPropagator = 0x0;
115 }
116
117 if (theMUONTrackParam.fExtrapParameters) {
118 if (fExtrapParameters) *fExtrapParameters = *(theMUONTrackParam.fExtrapParameters);
119 else fExtrapParameters = new TMatrixD(*(theMUONTrackParam.fExtrapParameters));
120 } else {
121 delete fExtrapParameters;
122 fExtrapParameters = 0x0;
123 }
124
125 if (theMUONTrackParam.fExtrapCovariances) {
126 if (fExtrapCovariances) *fExtrapCovariances = *(theMUONTrackParam.fExtrapCovariances);
127 else fExtrapCovariances = new TMatrixD(*(theMUONTrackParam.fExtrapCovariances));
128 } else {
129 delete fExtrapCovariances;
130 fExtrapCovariances = 0x0;
131 }
132
133 if (theMUONTrackParam.fSmoothParameters) {
134 if (fSmoothParameters) *fSmoothParameters = *(theMUONTrackParam.fSmoothParameters);
135 else fSmoothParameters = new TMatrixD(*(theMUONTrackParam.fSmoothParameters));
136 } else {
137 delete fSmoothParameters;
138 fSmoothParameters = 0x0;
139 }
140
141 if (theMUONTrackParam.fSmoothCovariances) {
142 if (fSmoothCovariances) *fSmoothCovariances = *(theMUONTrackParam.fSmoothCovariances);
143 else fSmoothCovariances = new TMatrixD(*(theMUONTrackParam.fSmoothCovariances));
144 } else {
145 delete fSmoothCovariances;
146 fSmoothCovariances = 0x0;
147 }
148
149 if (fOwnCluster) delete fClusterPtr;
150 fOwnCluster = theMUONTrackParam.fOwnCluster;
151 if(fOwnCluster) fClusterPtr = static_cast<AliMUONVCluster*>(theMUONTrackParam.fClusterPtr->Clone());
152 else fClusterPtr = theMUONTrackParam.fClusterPtr;
153
154 fRemovable = theMUONTrackParam.fRemovable;
155
156 fTrackChi2 = theMUONTrackParam.fTrackChi2;
157 fLocalChi2 = theMUONTrackParam.fLocalChi2;
158
159 return *this;
160}
161
162 //__________________________________________________________________________
163AliMUONTrackParam::~AliMUONTrackParam()
164{
165/// Destructor
166 DeleteCovariances();
167 delete fPropagator;
168 delete fExtrapParameters;
169 delete fExtrapCovariances;
170 delete fSmoothParameters;
171 delete fSmoothCovariances;
172 if(fOwnCluster) delete fClusterPtr;
173}
174
175 //__________________________________________________________________________
176void
177AliMUONTrackParam::Clear(Option_t* /*opt*/)
178{
179 /// clear memory
180 DeleteCovariances();
181 delete fPropagator; fPropagator = 0x0;
182 delete fExtrapParameters; fExtrapParameters = 0x0;
183 delete fExtrapCovariances; fExtrapCovariances = 0x0;
184 delete fSmoothParameters; fSmoothParameters = 0x0;
185 delete fSmoothCovariances; fSmoothCovariances = 0x0;
186 if(fOwnCluster) {
187 delete fClusterPtr; fClusterPtr = 0x0;
188 }
189}
190
191 //__________________________________________________________________________
192Double_t AliMUONTrackParam::Px() const
193{
194 /// return p_x from track parameters
195 Double_t pZ;
196 if (TMath::Abs(fParameters(4,0)) > 0) {
197 Double_t pYZ = (TMath::Abs(fParameters(4,0)) > 0) ? TMath::Abs(1.0 / fParameters(4,0)) : FLT_MAX;
198 pZ = - pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0))); // spectro. (z<0)
199 } else {
200 pZ = - FLT_MAX / TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0) + fParameters(1,0) * fParameters(1,0));
201 }
202 return pZ * fParameters(1,0);
203}
204
205 //__________________________________________________________________________
206Double_t AliMUONTrackParam::Py() const
207{
208 /// return p_y from track parameters
209 Double_t pZ;
210 if (TMath::Abs(fParameters(4,0)) > 0) {
211 Double_t pYZ = (TMath::Abs(fParameters(4,0)) > 0) ? TMath::Abs(1.0 / fParameters(4,0)) : FLT_MAX;
212 pZ = - pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0))); // spectro. (z<0)
213 } else {
214 pZ = - FLT_MAX / TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0) + fParameters(1,0) * fParameters(1,0));
215 }
216 return pZ * fParameters(3,0);
217}
218
219 //__________________________________________________________________________
220Double_t AliMUONTrackParam::Pz() const
221{
222 /// return p_z from track parameters
223 if (TMath::Abs(fParameters(4,0)) > 0) {
224 Double_t pYZ = TMath::Abs(1.0 / fParameters(4,0));
225 return - pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0))); // spectro. (z<0)
226 } else return - FLT_MAX / TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0) + fParameters(1,0) * fParameters(1,0));
227}
228
229 //__________________________________________________________________________
230Double_t AliMUONTrackParam::P() const
231{
232 /// return p from track parameters
233 if (TMath::Abs(fParameters(4,0)) > 0) {
234 Double_t pYZ = TMath::Abs(1.0 / fParameters(4,0));
235 Double_t pZ = - pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0))); // spectro. (z<0)
236 return - pZ * TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0) + fParameters(1,0) * fParameters(1,0));
237 } else return FLT_MAX;
238}
239
240 //__________________________________________________________________________
241const TMatrixD& AliMUONTrackParam::GetCovariances() const
242{
243 /// Return the covariance matrix (create it before if needed)
244 if (!fCovariances) {
245 fCovariances = new TMatrixD(5,5);
246 fCovariances->Zero();
247 }
248 return *fCovariances;
249}
250
251 //__________________________________________________________________________
252void AliMUONTrackParam::SetCovariances(const TMatrixD& covariances)
253{
254 /// Set the covariance matrix
255 if (fCovariances) *fCovariances = covariances;
256 else fCovariances = new TMatrixD(covariances);
257}
258
259 //__________________________________________________________________________
260void AliMUONTrackParam::SetCovariances(const Double_t matrix[5][5])
261{
262 /// Set the covariance matrix
263 if (fCovariances) fCovariances->SetMatrixArray(&(matrix[0][0]));
264 else fCovariances = new TMatrixD(5,5,&(matrix[0][0]));
265}
266
267 //__________________________________________________________________________
268void AliMUONTrackParam::SetVariances(const Double_t matrix[5][5])
269{
270 /// Set the diagonal terms of the covariance matrix (variances)
271 if (!fCovariances) fCovariances = new TMatrixD(5,5);
272 fCovariances->Zero();
273 for (Int_t i=0; i<5; i++) (*fCovariances)(i,i) = matrix[i][i];
274}
275
276 //__________________________________________________________________________
277void AliMUONTrackParam::DeleteCovariances()
278{
279 /// Delete the covariance matrix
280 delete fCovariances;
281 fCovariances = 0x0;
282}
283
284 //__________________________________________________________________________
285const TMatrixD& AliMUONTrackParam::GetPropagator() const
286{
287 /// Return the propagator (create it before if needed)
288 if (!fPropagator) {
289 fPropagator = new TMatrixD(5,5);
290 fPropagator->UnitMatrix();
291 }
292 return *fPropagator;
293}
294
295 //__________________________________________________________________________
296void AliMUONTrackParam::ResetPropagator()
297{
298 /// Reset the propagator
299 if (fPropagator) fPropagator->UnitMatrix();
300}
301
302 //__________________________________________________________________________
303void AliMUONTrackParam::UpdatePropagator(const TMatrixD& propagator)
304{
305 /// Update the propagator
306 if (fPropagator) *fPropagator = TMatrixD(propagator,TMatrixD::kMult,*fPropagator);
307 else fPropagator = new TMatrixD(propagator);
308}
309
310 //__________________________________________________________________________
311const TMatrixD& AliMUONTrackParam::GetExtrapParameters() const
312{
313 /// Return extrapolated parameters (create it before if needed)
314 if (!fExtrapParameters) {
315 fExtrapParameters = new TMatrixD(5,1);
316 fExtrapParameters->Zero();
317 }
318 return *fExtrapParameters;
319 }
320
321 //__________________________________________________________________________
322void AliMUONTrackParam::SetExtrapParameters(const TMatrixD& extrapParameters)
323{
324 /// Set extrapolated parameters
325 if (fExtrapParameters) *fExtrapParameters = extrapParameters;
326 else fExtrapParameters = new TMatrixD(extrapParameters);
327}
328
329 //__________________________________________________________________________
330const TMatrixD& AliMUONTrackParam::GetExtrapCovariances() const
331{
332 /// Return the extrapolated covariance matrix (create it before if needed)
333 if (!fExtrapCovariances) {
334 fExtrapCovariances = new TMatrixD(5,5);
335 fExtrapCovariances->Zero();
336 }
337 return *fExtrapCovariances;
338 }
339
340 //__________________________________________________________________________
341void AliMUONTrackParam::SetExtrapCovariances(const TMatrixD& extrapCovariances)
342{
343 /// Set the extrapolated covariance matrix
344 if (fExtrapCovariances) *fExtrapCovariances = extrapCovariances;
345 else fExtrapCovariances = new TMatrixD(extrapCovariances);
346}
347
348 //__________________________________________________________________________
349const TMatrixD& AliMUONTrackParam::GetSmoothParameters() const
350{
351 /// Return the smoothed parameters (create it before if needed)
352 if (!fSmoothParameters) {
353 fSmoothParameters = new TMatrixD(5,1);
354 fSmoothParameters->Zero();
355 }
356 return *fSmoothParameters;
357 }
358
359 //__________________________________________________________________________
360void AliMUONTrackParam::SetSmoothParameters(const TMatrixD& smoothParameters)
361{
362 /// Set the smoothed parameters
363 if (fSmoothParameters) *fSmoothParameters = smoothParameters;
364 else fSmoothParameters = new TMatrixD(smoothParameters);
365}
366
367 //__________________________________________________________________________
368const TMatrixD& AliMUONTrackParam::GetSmoothCovariances() const
369{
370 /// Return the smoothed covariance matrix (create it before if needed)
371 if (!fSmoothCovariances) {
372 fSmoothCovariances = new TMatrixD(5,5);
373 fSmoothCovariances->Zero();
374 }
375 return *fSmoothCovariances;
376 }
377
378 //__________________________________________________________________________
379void AliMUONTrackParam::SetSmoothCovariances(const TMatrixD& smoothCovariances)
380{
381 /// Set the smoothed covariance matrix
382 if (fSmoothCovariances) *fSmoothCovariances = smoothCovariances;
383 else fSmoothCovariances = new TMatrixD(smoothCovariances);
384}
385
386//__________________________________________________________________________
387void AliMUONTrackParam::SetClusterPtr(AliMUONVCluster* cluster, Bool_t owner)
388{
389 /// set pointeur to associated cluster
390 if (fOwnCluster) delete fClusterPtr;
391 fClusterPtr = cluster;
392 fOwnCluster = owner;
393}
394
395 //__________________________________________________________________________
396Int_t AliMUONTrackParam::Compare(const TObject* trackParam) const
397{
398 /// "Compare" function to sort with decreasing Z (spectro. muon Z <0).
399 /// Returns 1 (0, -1) if the current Z
400 /// is smaller than (equal to, larger than) Z of trackParam
401 if (fZ < ((AliMUONTrackParam*)trackParam)->GetZ()) return(1);
402 else if (fZ == ((AliMUONTrackParam*)trackParam)->GetZ()) return(0);
403 else return(-1);
404}
405
406 //__________________________________________________________________________
407Bool_t AliMUONTrackParam::CompatibleTrackParam(const AliMUONTrackParam &trackParam, Double_t sigma2Cut, Double_t &chi2) const
408{
409 /// Return kTRUE if the two set of track parameters are compatible within sigma2Cut
410 /// Set chi2 to the compatible chi2 value
411 /// Note that parameter covariances must exist for at least one set of parameters
412 /// Note also that if parameters are not given at the same Z, results will be meaningless
413
414 // reset chi2 value
415 chi2 = 0.;
416
417 // ckeck covariance matrices
418 if (!fCovariances && !trackParam.fCovariances) {
419 AliError("Covariance matrix must exist for at least one set of parameters");
420 return kFALSE;
421 }
422
423 Double_t maxChi2 = 5. * sigma2Cut * sigma2Cut; // 5 degrees of freedom
424
425 // check Z parameters
426 if (fZ != trackParam.fZ)
427 AliWarning(Form("Parameters are given at different Z position (%e : %e): results are meaningless", fZ, trackParam.fZ));
428
429 // compute the parameter residuals
430 TMatrixD deltaParam(fParameters, TMatrixD::kMinus, trackParam.fParameters);
431
432 // build the error matrix
433 TMatrixD weight(5,5);
434 if (fCovariances) weight += *fCovariances;
435 if (trackParam.fCovariances) weight += *(trackParam.fCovariances);
436
437 // invert the error matrix to get the parameter weights if possible
438 if (weight.Determinant() == 0) {
439 AliError("Cannot compute the compatibility chi2");
440 return kFALSE;
441 }
442 weight.Invert();
443
444 // compute the compatibility chi2
445 TMatrixD tmp(deltaParam, TMatrixD::kTransposeMult, weight);
446 TMatrixD mChi2(tmp, TMatrixD::kMult, deltaParam);
447
448 // set chi2 value
449 chi2 = mChi2(0,0);
450
451 // check compatibility
452 if (chi2 > maxChi2) return kFALSE;
453
454 return kTRUE;
455}
456
457 //__________________________________________________________________________
458void AliMUONTrackParam::Print(Option_t* opt) const
459{
460 /// Printing TrackParam information
461 /// "full" option for printing all the information about the TrackParam
462 TString sopt(opt);
463 sopt.ToUpper();
464
465 if ( sopt.Contains("FULL") ) {
466 cout << "<AliMUONTrackParam> Bending P=" << setw(5) << setprecision(3) << 1./fParameters(4,0) <<
467 ", NonBendSlope=" << setw(5) << setprecision(3) << fParameters(1,0)*180./TMath::Pi() <<
468 ", BendSlope=" << setw(5) << setprecision(3) << fParameters(3,0)*180./TMath::Pi() <<
469 ", (x,y,z)_IP=(" << setw(5) << setprecision(3) << fParameters(0,0) <<
470 "," << setw(5) << setprecision(3) << fParameters(2,0) <<
471 "," << setw(5) << setprecision(3) << fZ <<
472 ") cm, (px,py,pz)=(" << setw(5) << setprecision(3) << Px() <<
473 "," << setw(5) << setprecision(3) << Py() <<
474 "," << setw(5) << setprecision(3) << Pz() << ") GeV/c"
475 "," << "local chi2=" << GetLocalChi2() << endl;
476 }
477 else {
478 cout << "<AliMUONTrackParam>" << endl;
479 }
480
481}