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