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