]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackParam.cxx
No more misaligned_geometry
[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 //
20 // Track parameters
21 // in
22 // ALICE
23 // dimuon
24 // spectrometer
25 //
26 ///////////////////////////////////////////////////
27
28 #include "AliMUONTrackParam.h"
29 #include "AliMUONHitForRec.h"
30
31 #include "AliESDMuonTrack.h"
32 #include "AliLog.h"
33
34 #include <TMath.h>
35
36 #include <Riostream.h>
37
38 /// \cond CLASSIMP
39 ClassImp(AliMUONTrackParam) // Class implementation in ROOT context
40 /// \endcond
41
42   //_________________________________________________________________________
43 AliMUONTrackParam::AliMUONTrackParam()
44   : TObject(),
45     fZ(0.),
46     fParameters(5,1),
47     fCovariances(0x0),
48     fPropagator(0x0),
49     fExtrapParameters(0x0),
50     fExtrapCovariances(0x0),
51     fSmoothParameters(0x0),
52     fSmoothCovariances(0x0),
53     fHitForRecPtr(0x0),
54     fRemovable(kFALSE),
55     fTrackChi2(0.),
56     fLocalChi2(0.)
57 {
58   /// Constructor
59 }
60
61   //_________________________________________________________________________
62 AliMUONTrackParam::AliMUONTrackParam(const AliMUONTrackParam& theMUONTrackParam)
63   : TObject(theMUONTrackParam),
64     fZ(theMUONTrackParam.fZ),
65     fParameters(theMUONTrackParam.fParameters),
66     fCovariances(0x0),
67     fPropagator(0x0),
68     fExtrapParameters(0x0),
69     fExtrapCovariances(0x0),
70     fSmoothParameters(0x0),
71     fSmoothCovariances(0x0),
72     fHitForRecPtr(theMUONTrackParam.fHitForRecPtr),
73     fRemovable(theMUONTrackParam.fRemovable),
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
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 if (fCovariances) {
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 if (fPropagator) {
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 if (fExtrapParameters) {
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 if (fExtrapCovariances) {
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 if (fSmoothParameters) {
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 if (fSmoothCovariances) {
144     delete fSmoothCovariances;
145     fSmoothCovariances = 0x0;
146   }
147   
148   fHitForRecPtr = theMUONTrackParam.fHitForRecPtr;
149   
150   fRemovable = theMUONTrackParam.fRemovable;
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   /// assigned value form 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   /// assigned value form 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   /// assigned value form 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   /// assigned value form 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 Double_t AliMUONTrackParam::Px() const
242 {
243   /// return p_x from track parameters
244   Double_t pYZ, pZ, pX;
245   pYZ = 0;
246   if (  TMath::Abs(fParameters(4,0)) > 0 )
247     pYZ = TMath::Abs(1.0 / fParameters(4,0));
248   pZ = -pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0)));  // spectro. (z<0)
249   pX = pZ * fParameters(1,0); 
250   return pX;
251 }
252
253   //__________________________________________________________________________
254 Double_t AliMUONTrackParam::Py() const
255 {
256   /// return p_y from track parameters
257   Double_t pYZ, pZ, pY;
258   pYZ = 0;
259   if (  TMath::Abs(fParameters(4,0)) > 0 )
260     pYZ = TMath::Abs(1.0 / fParameters(4,0));
261   pZ = -pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0)));  // spectro. (z<0)
262   pY = pZ * fParameters(3,0); 
263   return pY;
264 }
265
266   //__________________________________________________________________________
267 Double_t AliMUONTrackParam::Pz() const
268 {
269   /// return p_z from track parameters
270   Double_t pYZ, pZ;
271   pYZ = 0;
272   if (  TMath::Abs(fParameters(4,0)) > 0 )
273     pYZ = TMath::Abs(1.0 / fParameters(4,0));
274   pZ = -pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0)));  // spectro. (z<0)
275   return pZ;
276 }
277
278   //__________________________________________________________________________
279 Double_t AliMUONTrackParam::P() const
280 {
281   /// return p from track parameters
282   Double_t  pYZ, pZ, p;
283   pYZ = 0;
284   if (  TMath::Abs(fParameters(4,0)) > 0 )
285     pYZ = TMath::Abs(1.0 / fParameters(4,0));
286   pZ = -pYZ / (TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0)));  // spectro. (z<0)
287   p = TMath::Abs(pZ) * 
288     TMath::Sqrt(1.0 + fParameters(3,0) * fParameters(3,0) + fParameters(1,0) * fParameters(1,0));
289   return p;
290   
291 }
292
293   //__________________________________________________________________________
294 const TMatrixD& AliMUONTrackParam::GetCovariances() const
295 {
296   /// Return the covariance matrix (create it before if needed)
297   if (!fCovariances) {
298     fCovariances = new TMatrixD(5,5);
299     fCovariances->Zero();
300   }
301   return *fCovariances;
302 }
303
304   //__________________________________________________________________________
305 void AliMUONTrackParam::SetCovariances(const TMatrixD& covariances)
306 {
307   /// Set the covariance matrix
308   if (&covariances == fCovariances) return; // nothing to be done
309   if (fCovariances) *fCovariances = covariances;
310   else fCovariances = new TMatrixD(covariances);
311 }
312
313   //__________________________________________________________________________
314 void AliMUONTrackParam::SetCovariances(const Double_t matrix[5][5])
315 {
316   /// Set the covariance matrix
317   if (fCovariances) fCovariances->SetMatrixArray(&(matrix[0][0]));
318   else fCovariances = new TMatrixD(5,5,&(matrix[0][0]));
319 }
320
321   //__________________________________________________________________________
322 void AliMUONTrackParam::SetVariances(const Double_t matrix[5][5])
323 {
324   /// Set the diagonal terms of the covariance matrix (variances)
325   if (!fCovariances) fCovariances = new TMatrixD(5,5);
326   fCovariances->Zero();
327   for (Int_t i=0; i<5; i++) (*fCovariances)(i,i) = matrix[i][i];
328 }
329
330   //__________________________________________________________________________
331 void AliMUONTrackParam::DeleteCovariances()
332 {
333   /// Delete the covariance matrix
334   delete fCovariances;
335   fCovariances = 0x0;
336 }
337
338   //__________________________________________________________________________
339 const TMatrixD& AliMUONTrackParam::GetPropagator() const
340 {
341   /// Return the propagator (create it before if needed)
342   if (!fPropagator) {
343     fPropagator = new TMatrixD(5,5);
344     fPropagator->Zero();
345   }
346   return *fPropagator;
347   }
348
349   //__________________________________________________________________________
350 void AliMUONTrackParam::ResetPropagator()
351 {
352   /// Reset the propagator
353   if (!fPropagator) fPropagator = new TMatrixD(5,5);
354   fPropagator->UnitMatrix();
355 }
356
357   //__________________________________________________________________________
358 void AliMUONTrackParam::UpdatePropagator(const TMatrixD& propagator)
359 {
360   /// Update the propagator
361   if (&propagator == fPropagator) return; // nothing to be done
362   if (fPropagator) *fPropagator = TMatrixD(propagator,TMatrixD::kMult,*fPropagator);
363   else fPropagator = new TMatrixD(propagator);
364 }
365
366   //__________________________________________________________________________
367 const TMatrixD& AliMUONTrackParam::GetExtrapParameters() const
368 {
369   /// Return extrapolated parameters (create it before if needed)
370   if (!fExtrapParameters) {
371     fExtrapParameters = new TMatrixD(5,1);
372     fExtrapParameters->Zero();
373   }
374   return *fExtrapParameters;
375   }
376
377   //__________________________________________________________________________
378 void AliMUONTrackParam::SetExtrapParameters(const TMatrixD& extrapParameters)
379 {
380   /// Set extrapolated parameters
381   if (&extrapParameters == fExtrapParameters) return; // nothing to be done
382   if (fExtrapParameters) *fExtrapParameters = extrapParameters;
383   else fExtrapParameters = new TMatrixD(extrapParameters);
384 }
385
386   //__________________________________________________________________________
387 const TMatrixD& AliMUONTrackParam::GetExtrapCovariances() const
388 {
389   /// Return the extrapolated covariance matrix (create it before if needed)
390   if (!fExtrapCovariances) {
391     fExtrapCovariances = new TMatrixD(5,5);
392     fExtrapCovariances->Zero();
393   }
394   return *fExtrapCovariances;
395   }
396
397   //__________________________________________________________________________
398 void AliMUONTrackParam::SetExtrapCovariances(const TMatrixD& extrapCovariances)
399 {
400   /// Set the extrapolated covariance matrix
401   if (&extrapCovariances == fExtrapCovariances) return; // nothing to be done
402   if (fExtrapCovariances) *fExtrapCovariances = extrapCovariances;
403   else fExtrapCovariances = new TMatrixD(extrapCovariances);
404 }
405
406   //__________________________________________________________________________
407 const TMatrixD& AliMUONTrackParam::GetSmoothParameters() const
408 {
409   /// Return the smoothed parameters (create it before if needed)
410   if (!fSmoothParameters) {
411     fSmoothParameters = new TMatrixD(5,1);
412     fSmoothParameters->Zero();
413   }
414   return *fSmoothParameters;
415   }
416
417   //__________________________________________________________________________
418 void AliMUONTrackParam::SetSmoothParameters(const TMatrixD& smoothParameters)
419 {
420   /// Set the smoothed parameters
421   if (&smoothParameters == fSmoothParameters) return; // nothing to be done
422   if (fSmoothParameters) *fSmoothParameters = smoothParameters;
423   else fSmoothParameters = new TMatrixD(smoothParameters);
424 }
425
426   //__________________________________________________________________________
427 const TMatrixD& AliMUONTrackParam::GetSmoothCovariances() const
428 {
429   /// Return the smoothed covariance matrix (create it before if needed)
430   if (!fSmoothCovariances) {
431     fSmoothCovariances = new TMatrixD(5,5);
432     fSmoothCovariances->Zero();
433   }
434   return *fSmoothCovariances;
435   }
436
437   //__________________________________________________________________________
438 void AliMUONTrackParam::SetSmoothCovariances(const TMatrixD& smoothCovariances)
439 {
440   /// Set the smoothed covariance matrix
441   if (&smoothCovariances == fSmoothCovariances) return; // nothing to be done
442   if (fSmoothCovariances) *fSmoothCovariances = smoothCovariances;
443   else fSmoothCovariances = new TMatrixD(smoothCovariances);
444 }
445
446   //__________________________________________________________________________
447 Int_t AliMUONTrackParam::Compare(const TObject* trackParam) const
448 {
449   /// "Compare" function to sort with decreasing Z (spectro. muon Z <0).
450   /// Returns 1 (0, -1) if Z of current TrackHit
451   /// is smaller than (equal to, larger than) Z of TrackHit
452   if (fHitForRecPtr) {
453     if (fHitForRecPtr->GetZ() != fZ)
454       AliWarning("track parameters are given at a different z position than the one of the corresponding hit");
455   }
456   if (fZ < ((AliMUONTrackParam*)trackParam)->GetZ()) return(1);
457   else if (fZ == ((AliMUONTrackParam*)trackParam)->GetZ()) return(0);
458   else return(-1);
459 }
460
461 //_____________________________________________-
462 void AliMUONTrackParam::Print(Option_t* opt) const
463 {
464   /// Printing TrackParam information 
465   /// "full" option for printing all the information about the TrackParam
466   TString sopt(opt);
467   sopt.ToUpper();
468  
469   if ( sopt.Contains("FULL") ) { 
470     cout << "<AliMUONTrackParam> Bending P=" << setw(5) << setprecision(3)  << 1./fParameters(4,0) << 
471       ", NonBendSlope=" << setw(5) << setprecision(3)  << fParameters(1,0)*180./TMath::Pi() <<
472       ", BendSlope=" << setw(5) << setprecision(3)     << fParameters(3,0)*180./TMath::Pi()  << 
473       ", (x,y,z)_IP=(" <<  setw(5) << setprecision(3) << fParameters(0,0) <<
474       "," <<  setw(5) << setprecision(3) << fParameters(2,0) <<
475       "," <<  setw(5) << setprecision(3) << fZ <<
476       ") cm, (px,py,pz)=(" << setw(5) << setprecision(3) << Px() <<
477       "," << setw(5) << setprecision(3) << Py() <<
478       "," << setw(5) << setprecision(3) << Pz() << ") GeV/c" << endl;
479   }
480   else {
481     cout << "<AliMUONTrackParam>"  << endl;
482   }
483     
484 }