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