]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackParam.cxx
Main changes:
[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 "AliESDMuonTrack.h"
28 #include "AliLog.h"
29
30 #include <TMath.h>
31
32 #include <Riostream.h>
33
34 /// \cond CLASSIMP
35 ClassImp(AliMUONTrackParam) // Class implementation in ROOT context
36 /// \endcond
37
38   //_________________________________________________________________________
39 AliMUONTrackParam::AliMUONTrackParam()
40   : TObject(),
41     fZ(0.),
42     fParameters(5,1),
43     fCovariances(0x0),
44     fPropagator(0x0),
45     fExtrapParameters(0x0),
46     fExtrapCovariances(0x0),
47     fSmoothParameters(0x0),
48     fSmoothCovariances(0x0),
49     fClusterPtr(0x0),
50     fOwnCluster(kFALSE),
51     fRemovable(kFALSE),
52     fAloneInChamber(kTRUE),
53     fTrackChi2(0.),
54     fLocalChi2(0.)
55 {
56   /// Constructor
57 }
58
59   //_________________________________________________________________________
60 AliMUONTrackParam::AliMUONTrackParam(const AliMUONTrackParam& theMUONTrackParam)
61   : TObject(theMUONTrackParam),
62     fZ(theMUONTrackParam.fZ),
63     fParameters(theMUONTrackParam.fParameters),
64     fCovariances(0x0),
65     fPropagator(0x0),
66     fExtrapParameters(0x0),
67     fExtrapCovariances(0x0),
68     fSmoothParameters(0x0),
69     fSmoothCovariances(0x0),
70     fClusterPtr(0x0),
71     fOwnCluster(theMUONTrackParam.fOwnCluster),
72     fRemovable(theMUONTrackParam.fRemovable),
73     fAloneInChamber(theMUONTrackParam.fAloneInChamber),
74     fTrackChi2(theMUONTrackParam.fTrackChi2),
75     fLocalChi2(theMUONTrackParam.fLocalChi2)
76 {
77   /// Copy constructor
78   if (theMUONTrackParam.fCovariances) fCovariances = new TMatrixD(*(theMUONTrackParam.fCovariances));
79   if (theMUONTrackParam.fPropagator) fPropagator = new TMatrixD(*(theMUONTrackParam.fPropagator));
80   if (theMUONTrackParam.fExtrapParameters) fExtrapParameters = new TMatrixD(*(theMUONTrackParam.fExtrapParameters));
81   if (theMUONTrackParam.fExtrapCovariances) fExtrapCovariances = new TMatrixD(*(theMUONTrackParam.fExtrapCovariances));
82   if (theMUONTrackParam.fSmoothParameters) fSmoothParameters = new TMatrixD(*(theMUONTrackParam.fSmoothParameters));
83   if (theMUONTrackParam.fSmoothCovariances) fSmoothCovariances = new TMatrixD(*(theMUONTrackParam.fSmoothCovariances));
84   
85   if(fOwnCluster) fClusterPtr = theMUONTrackParam.fClusterPtr->CreateCopy();
86   else fClusterPtr = theMUONTrackParam.fClusterPtr;
87 }
88
89   //_________________________________________________________________________
90 AliMUONTrackParam& AliMUONTrackParam::operator=(const AliMUONTrackParam& theMUONTrackParam)
91 {
92   /// Asignment operator
93   if (this == &theMUONTrackParam)
94     return *this;
95
96   // base class assignement
97   TObject::operator=(theMUONTrackParam);
98
99   fZ = theMUONTrackParam.fZ; 
100   
101   fParameters = theMUONTrackParam.fParameters;
102   
103   if (theMUONTrackParam.fCovariances) {
104     if (fCovariances) *fCovariances = *(theMUONTrackParam.fCovariances);
105     else fCovariances = new TMatrixD(*(theMUONTrackParam.fCovariances));
106   } else {
107     delete fCovariances;
108     fCovariances = 0x0;
109   }
110   
111   if (theMUONTrackParam.fPropagator) {
112     if (fPropagator) *fPropagator = *(theMUONTrackParam.fPropagator);
113     else fPropagator = new TMatrixD(*(theMUONTrackParam.fPropagator));
114   } else {
115     delete fPropagator;
116     fPropagator = 0x0;
117   }
118   
119   if (theMUONTrackParam.fExtrapParameters) {
120     if (fExtrapParameters) *fExtrapParameters = *(theMUONTrackParam.fExtrapParameters);
121     else fExtrapParameters = new TMatrixD(*(theMUONTrackParam.fExtrapParameters));
122   } else {
123     delete fExtrapParameters;
124     fExtrapParameters = 0x0;
125   }
126   
127   if (theMUONTrackParam.fExtrapCovariances) {
128     if (fExtrapCovariances) *fExtrapCovariances = *(theMUONTrackParam.fExtrapCovariances);
129     else fExtrapCovariances = new TMatrixD(*(theMUONTrackParam.fExtrapCovariances));
130   } else {
131     delete fExtrapCovariances;
132     fExtrapCovariances = 0x0;
133   }
134   
135   if (theMUONTrackParam.fSmoothParameters) {
136     if (fSmoothParameters) *fSmoothParameters = *(theMUONTrackParam.fSmoothParameters);
137     else fSmoothParameters = new TMatrixD(*(theMUONTrackParam.fSmoothParameters));
138   } else {
139     delete fSmoothParameters;
140     fSmoothParameters = 0x0;
141   }
142   
143   if (theMUONTrackParam.fSmoothCovariances) {
144     if (fSmoothCovariances) *fSmoothCovariances = *(theMUONTrackParam.fSmoothCovariances);
145     else fSmoothCovariances = new TMatrixD(*(theMUONTrackParam.fSmoothCovariances));
146   } else {
147     delete fSmoothCovariances;
148     fSmoothCovariances = 0x0;
149   }
150   
151   fOwnCluster = theMUONTrackParam.fOwnCluster;
152   if(fOwnCluster) fClusterPtr = theMUONTrackParam.fClusterPtr->CreateCopy();
153   else fClusterPtr = theMUONTrackParam.fClusterPtr;
154   
155   fRemovable = theMUONTrackParam.fRemovable;
156   
157   fAloneInChamber = theMUONTrackParam.fAloneInChamber;
158   
159   fTrackChi2 = theMUONTrackParam.fTrackChi2;
160   fLocalChi2 = theMUONTrackParam.fLocalChi2;
161   
162   return *this;
163 }
164
165   //__________________________________________________________________________
166 AliMUONTrackParam::~AliMUONTrackParam()
167 {
168 /// Destructor
169   DeleteCovariances();
170   delete fPropagator;
171   delete fExtrapParameters;
172   delete fExtrapCovariances;
173   delete fSmoothParameters;
174   delete fSmoothCovariances;
175   if(fOwnCluster) delete fClusterPtr;
176 }
177
178   //__________________________________________________________________________
179 void
180 AliMUONTrackParam::Clear(Option_t* /*opt*/)
181 {
182   /// clear memory
183   DeleteCovariances();
184   delete fPropagator; fPropagator = 0x0;
185   delete fExtrapParameters; fExtrapParameters = 0x0;
186   delete fExtrapCovariances; fExtrapCovariances = 0x0;
187   delete fSmoothParameters; fSmoothParameters = 0x0;
188   delete fSmoothCovariances; fSmoothCovariances = 0x0;
189   if(fOwnCluster) {
190     delete fClusterPtr; fClusterPtr = 0x0;
191   }
192 }
193
194   //_________________________________________________________________________
195 void AliMUONTrackParam::GetParamFrom(const AliESDMuonTrack& esdMuonTrack)
196 {
197   /// Get parameters from ESD track
198   fZ = esdMuonTrack.GetZ(); 
199   fParameters(0,0) = esdMuonTrack.GetNonBendingCoor();
200   fParameters(1,0) = TMath::Tan(esdMuonTrack.GetThetaX());
201   fParameters(2,0) = esdMuonTrack.GetBendingCoor(); 
202   fParameters(3,0) = TMath::Tan(esdMuonTrack.GetThetaY());
203   fParameters(4,0) = esdMuonTrack.GetInverseBendingMomentum();
204 }
205
206   //_________________________________________________________________________
207 void AliMUONTrackParam::SetParamFor(AliESDMuonTrack& esdMuonTrack) const
208 {
209   /// Set parameters in ESD track
210   esdMuonTrack.SetZ(fZ);
211   esdMuonTrack.SetNonBendingCoor(fParameters(0,0));
212   esdMuonTrack.SetThetaX(TMath::ATan(fParameters(1,0)));
213   esdMuonTrack.SetBendingCoor(fParameters(2,0)); 
214   esdMuonTrack.SetThetaY(TMath::ATan(fParameters(3,0)));
215   esdMuonTrack.SetInverseBendingMomentum(fParameters(4,0));
216 }
217
218   //_________________________________________________________________________
219 void AliMUONTrackParam::GetParamFromUncorrected(const AliESDMuonTrack& esdMuonTrack)
220 {
221   /// Get parameters from ESD track
222   fZ = esdMuonTrack.GetZUncorrected(); 
223   fParameters(0,0) = esdMuonTrack.GetNonBendingCoorUncorrected();
224   fParameters(1,0) = TMath::Tan(esdMuonTrack.GetThetaXUncorrected());
225   fParameters(2,0) = esdMuonTrack.GetBendingCoorUncorrected(); 
226   fParameters(3,0) = TMath::Tan(esdMuonTrack.GetThetaYUncorrected());
227   fParameters(4,0) = esdMuonTrack.GetInverseBendingMomentumUncorrected();
228 }
229
230   //_________________________________________________________________________
231 void AliMUONTrackParam::SetParamForUncorrected(AliESDMuonTrack& esdMuonTrack) const
232 {
233   /// Set parameters in ESD track
234   esdMuonTrack.SetZUncorrected(fZ);
235   esdMuonTrack.SetNonBendingCoorUncorrected(fParameters(0,0));
236   esdMuonTrack.SetThetaXUncorrected(TMath::ATan(fParameters(1,0)));
237   esdMuonTrack.SetBendingCoorUncorrected(fParameters(2,0)); 
238   esdMuonTrack.SetThetaYUncorrected(TMath::ATan(fParameters(3,0)));
239   esdMuonTrack.SetInverseBendingMomentumUncorrected(fParameters(4,0));
240 }
241
242   //_________________________________________________________________________
243 void AliMUONTrackParam::GetCovFrom(const AliESDMuonTrack& esdMuonTrack)
244 {
245   /// Get parameters covariances from ESD track
246   
247   // Get ESD covariance matrix
248   if (!fCovariances) fCovariances = new TMatrixD(5,5);
249   esdMuonTrack.GetCovariances(*fCovariances);
250
251   // compute Jacobian to change the coordinate system
252   // from (X,thetaX,Y,thetaY,c/pYZ) to (X,slopeX,Y,slopeY,c/pYZ)
253   Double_t cosThetaX = TMath::Cos(TMath::ATan(fParameters(1,0)));
254   Double_t cosThetaY = TMath::Cos(TMath::ATan(fParameters(3,0)));
255   TMatrixD jacob(5,5);
256   jacob.Zero();
257   jacob(0,0) = 1.;
258   jacob(1,1) = 1. / cosThetaX / cosThetaX;
259   jacob(2,2) = 1.;
260   jacob(3,3) = 1. / cosThetaY / cosThetaY;
261   jacob(4,4) = 1.;
262   
263   // compute covariance matrix in ESD coordinate system
264   TMatrixD tmp(*fCovariances,TMatrixD::kMultTranspose,jacob);
265   *fCovariances = TMatrixD(jacob,TMatrixD::kMult,tmp);
266   
267 }
268
269   //_________________________________________________________________________
270 void AliMUONTrackParam::SetCovFor(AliESDMuonTrack& esdMuonTrack) const
271 {
272   /// Set parameters covariances in ESD track
273   
274   // set null matrix if covariances does not exist
275   if (!fCovariances) {
276     TMatrixD tmp(5,5);
277     tmp.Zero();
278     esdMuonTrack.SetCovariances(tmp);
279     return;
280   }
281   
282   // compute Jacobian to change the coordinate system
283   // from (X,slopeX,Y,slopeY,c/pYZ) to (X,thetaX,Y,thetaY,c/pYZ)
284   Double_t cosThetaX = TMath::Cos(TMath::ATan(fParameters(1,0)));
285   Double_t cosThetaY = TMath::Cos(TMath::ATan(fParameters(3,0)));
286   TMatrixD jacob(5,5);
287   jacob.Zero();
288   jacob(0,0) = 1.;
289   jacob(1,1) = cosThetaX * cosThetaX;
290   jacob(2,2) = 1.;
291   jacob(3,3) = cosThetaY * cosThetaY;
292   jacob(4,4) = 1.;
293   
294   // compute covariance matrix in ESD coordinate system
295   TMatrixD tmp(*fCovariances,TMatrixD::kMultTranspose,jacob);
296   TMatrixD tmp2(jacob,TMatrixD::kMult,tmp);
297   esdMuonTrack.SetCovariances(tmp2);
298
299 }
300
301   //__________________________________________________________________________
302 Double_t AliMUONTrackParam::Px() const
303 {
304   /// return p_x from track parameters
305   Double_t pYZ, pZ, pX;
306   pYZ = 0;
307   if (  TMath::Abs(fParameters(4,0)) > 0 )
308     pYZ = TMath::Abs(1.0 / fParameters(4,0));
309   pZ = -pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0)));  // spectro. (z<0)
310   pX = pZ * fParameters(1,0); 
311   return pX;
312 }
313
314   //__________________________________________________________________________
315 Double_t AliMUONTrackParam::Py() const
316 {
317   /// return p_y from track parameters
318   Double_t pYZ, pZ, pY;
319   pYZ = 0;
320   if (  TMath::Abs(fParameters(4,0)) > 0 )
321     pYZ = TMath::Abs(1.0 / fParameters(4,0));
322   pZ = -pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0)));  // spectro. (z<0)
323   pY = pZ * fParameters(3,0); 
324   return pY;
325 }
326
327   //__________________________________________________________________________
328 Double_t AliMUONTrackParam::Pz() const
329 {
330   /// return p_z from track parameters
331   Double_t pYZ, pZ;
332   pYZ = 0;
333   if (  TMath::Abs(fParameters(4,0)) > 0 )
334     pYZ = TMath::Abs(1.0 / fParameters(4,0));
335   pZ = -pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0)));  // spectro. (z<0)
336   return pZ;
337 }
338
339   //__________________________________________________________________________
340 Double_t AliMUONTrackParam::P() const
341 {
342   /// return p from track parameters
343   Double_t  pYZ, pZ, p;
344   pYZ = 0;
345   if (  TMath::Abs(fParameters(4,0)) > 0 )
346     pYZ = TMath::Abs(1.0 / fParameters(4,0));
347   pZ = -pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0)));  // spectro. (z<0)
348   p = TMath::Abs(pZ) * 
349     TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0) + fParameters(1,0) * fParameters(1,0));
350   return p;
351   
352 }
353
354   //__________________________________________________________________________
355 const TMatrixD& AliMUONTrackParam::GetCovariances() const
356 {
357   /// Return the covariance matrix (create it before if needed)
358   if (!fCovariances) {
359     fCovariances = new TMatrixD(5,5);
360     fCovariances->Zero();
361   }
362   return *fCovariances;
363 }
364
365   //__________________________________________________________________________
366 void AliMUONTrackParam::SetCovariances(const TMatrixD& covariances)
367 {
368   /// Set the covariance matrix
369   if (fCovariances) *fCovariances = covariances;
370   else fCovariances = new TMatrixD(covariances);
371 }
372
373   //__________________________________________________________________________
374 void AliMUONTrackParam::SetCovariances(const Double_t matrix[5][5])
375 {
376   /// Set the covariance matrix
377   if (fCovariances) fCovariances->SetMatrixArray(&(matrix[0][0]));
378   else fCovariances = new TMatrixD(5,5,&(matrix[0][0]));
379 }
380
381   //__________________________________________________________________________
382 void AliMUONTrackParam::SetVariances(const Double_t matrix[5][5])
383 {
384   /// Set the diagonal terms of the covariance matrix (variances)
385   if (!fCovariances) fCovariances = new TMatrixD(5,5);
386   fCovariances->Zero();
387   for (Int_t i=0; i<5; i++) (*fCovariances)(i,i) = matrix[i][i];
388 }
389
390   //__________________________________________________________________________
391 void AliMUONTrackParam::DeleteCovariances()
392 {
393   /// Delete the covariance matrix
394   delete fCovariances;
395   fCovariances = 0x0;
396 }
397
398   //__________________________________________________________________________
399 const TMatrixD& AliMUONTrackParam::GetPropagator() const
400 {
401   /// Return the propagator (create it before if needed)
402   if (!fPropagator) {
403     fPropagator = new TMatrixD(5,5);
404     fPropagator->UnitMatrix();
405   }
406   return *fPropagator;
407 }
408
409   //__________________________________________________________________________
410 void AliMUONTrackParam::ResetPropagator()
411 {
412   /// Reset the propagator
413   if (fPropagator) fPropagator->UnitMatrix();
414 }
415
416   //__________________________________________________________________________
417 void AliMUONTrackParam::UpdatePropagator(const TMatrixD& propagator)
418 {
419   /// Update the propagator
420   if (fPropagator) *fPropagator = TMatrixD(propagator,TMatrixD::kMult,*fPropagator);
421   else fPropagator = new TMatrixD(propagator);
422 }
423
424   //__________________________________________________________________________
425 const TMatrixD& AliMUONTrackParam::GetExtrapParameters() const
426 {
427   /// Return extrapolated parameters (create it before if needed)
428   if (!fExtrapParameters) {
429     fExtrapParameters = new TMatrixD(5,1);
430     fExtrapParameters->Zero();
431   }
432   return *fExtrapParameters;
433   }
434
435   //__________________________________________________________________________
436 void AliMUONTrackParam::SetExtrapParameters(const TMatrixD& extrapParameters)
437 {
438   /// Set extrapolated parameters
439   if (fExtrapParameters) *fExtrapParameters = extrapParameters;
440   else fExtrapParameters = new TMatrixD(extrapParameters);
441 }
442
443   //__________________________________________________________________________
444 const TMatrixD& AliMUONTrackParam::GetExtrapCovariances() const
445 {
446   /// Return the extrapolated covariance matrix (create it before if needed)
447   if (!fExtrapCovariances) {
448     fExtrapCovariances = new TMatrixD(5,5);
449     fExtrapCovariances->Zero();
450   }
451   return *fExtrapCovariances;
452   }
453
454   //__________________________________________________________________________
455 void AliMUONTrackParam::SetExtrapCovariances(const TMatrixD& extrapCovariances)
456 {
457   /// Set the extrapolated covariance matrix
458   if (fExtrapCovariances) *fExtrapCovariances = extrapCovariances;
459   else fExtrapCovariances = new TMatrixD(extrapCovariances);
460 }
461
462   //__________________________________________________________________________
463 const TMatrixD& AliMUONTrackParam::GetSmoothParameters() const
464 {
465   /// Return the smoothed parameters (create it before if needed)
466   if (!fSmoothParameters) {
467     fSmoothParameters = new TMatrixD(5,1);
468     fSmoothParameters->Zero();
469   }
470   return *fSmoothParameters;
471   }
472
473   //__________________________________________________________________________
474 void AliMUONTrackParam::SetSmoothParameters(const TMatrixD& smoothParameters)
475 {
476   /// Set the smoothed parameters
477   if (fSmoothParameters) *fSmoothParameters = smoothParameters;
478   else fSmoothParameters = new TMatrixD(smoothParameters);
479 }
480
481   //__________________________________________________________________________
482 const TMatrixD& AliMUONTrackParam::GetSmoothCovariances() const
483 {
484   /// Return the smoothed covariance matrix (create it before if needed)
485   if (!fSmoothCovariances) {
486     fSmoothCovariances = new TMatrixD(5,5);
487     fSmoothCovariances->Zero();
488   }
489   return *fSmoothCovariances;
490   }
491
492   //__________________________________________________________________________
493 void AliMUONTrackParam::SetSmoothCovariances(const TMatrixD& smoothCovariances)
494 {
495   /// Set the smoothed covariance matrix
496   if (fSmoothCovariances) *fSmoothCovariances = smoothCovariances;
497   else fSmoothCovariances = new TMatrixD(smoothCovariances);
498 }
499
500   //__________________________________________________________________________
501 Int_t AliMUONTrackParam::Compare(const TObject* trackParam) const
502 {
503   /// "Compare" function to sort with decreasing Z (spectro. muon Z <0).
504   /// Returns 1 (0, -1) if the current Z
505   /// is smaller than (equal to, larger than) Z of trackParam
506   if (fZ < ((AliMUONTrackParam*)trackParam)->GetZ()) return(1);
507   else if (fZ == ((AliMUONTrackParam*)trackParam)->GetZ()) return(0);
508   else return(-1);
509 }
510
511 //_____________________________________________-
512 void AliMUONTrackParam::Print(Option_t* opt) const
513 {
514   /// Printing TrackParam information 
515   /// "full" option for printing all the information about the TrackParam
516   TString sopt(opt);
517   sopt.ToUpper();
518  
519   if ( sopt.Contains("FULL") ) { 
520     cout << "<AliMUONTrackParam> Bending P=" << setw(5) << setprecision(3)  << 1./fParameters(4,0) << 
521       ", NonBendSlope=" << setw(5) << setprecision(3)  << fParameters(1,0)*180./TMath::Pi() <<
522       ", BendSlope=" << setw(5) << setprecision(3)     << fParameters(3,0)*180./TMath::Pi()  << 
523       ", (x,y,z)_IP=(" <<  setw(5) << setprecision(3) << fParameters(0,0) <<
524       "," <<  setw(5) << setprecision(3) << fParameters(2,0) <<
525       "," <<  setw(5) << setprecision(3) << fZ <<
526       ") cm, (px,py,pz)=(" << setw(5) << setprecision(3) << Px() <<
527       "," << setw(5) << setprecision(3) << Py() <<
528       "," << setw(5) << setprecision(3) << Pz() << ") GeV/c" << endl;
529   }
530   else {
531     cout << "<AliMUONTrackParam>"  << endl;
532   }
533     
534 }