]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackParam.cxx
+ Modifications of the standard tracking algorithm:
[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 <Riostream.h>
29 #include <TMatrixD.h>
30
31 #include "AliMUONTrackParam.h"
32 #include "AliESDMuonTrack.h"
33 #include "AliLog.h"
34 #include "AliMUONHitForRec.h"
35
36 /// \cond CLASSIMP
37 ClassImp(AliMUONTrackParam) // Class implementation in ROOT context
38 /// \endcond
39
40   //_________________________________________________________________________
41 AliMUONTrackParam::AliMUONTrackParam()
42   : TObject(),
43     fNonBendingCoor(0.),
44     fNonBendingSlope(0.),
45     fBendingCoor(0.),
46     fBendingSlope(0.),
47     fInverseBendingMomentum(0.),
48     fZ(0.),
49     fCovariances(0x0),
50     fHitForRecPtr(0x0)
51 {
52   /// Constructor
53 }
54
55   //_________________________________________________________________________
56 AliMUONTrackParam::AliMUONTrackParam(const AliMUONTrackParam& theMUONTrackParam)
57   : TObject(theMUONTrackParam),
58     fNonBendingCoor(theMUONTrackParam.fNonBendingCoor),
59     fNonBendingSlope(theMUONTrackParam.fNonBendingSlope),
60     fBendingCoor(theMUONTrackParam.fBendingCoor),
61     fBendingSlope(theMUONTrackParam.fBendingSlope),
62     fInverseBendingMomentum(theMUONTrackParam.fInverseBendingMomentum), 
63     fZ(theMUONTrackParam.fZ),
64     fCovariances(0x0),
65     fHitForRecPtr(theMUONTrackParam.fHitForRecPtr)
66 {
67   /// Copy constructor
68   if (theMUONTrackParam.fCovariances) fCovariances = new TMatrixD(*(theMUONTrackParam.fCovariances));
69 }
70
71   //_________________________________________________________________________
72 AliMUONTrackParam& AliMUONTrackParam::operator=(const AliMUONTrackParam& theMUONTrackParam)
73 {
74   /// Asignment operator
75   if (this == &theMUONTrackParam)
76     return *this;
77
78   // base class assignement
79   TObject::operator=(theMUONTrackParam);
80
81   fNonBendingCoor               =  theMUONTrackParam.fNonBendingCoor;
82   fNonBendingSlope              =  theMUONTrackParam.fNonBendingSlope; 
83   fBendingCoor                  =  theMUONTrackParam.fBendingCoor; 
84   fBendingSlope                 =  theMUONTrackParam.fBendingSlope; 
85   fInverseBendingMomentum       =  theMUONTrackParam.fInverseBendingMomentum; 
86   fZ                            =  theMUONTrackParam.fZ; 
87   
88   if (theMUONTrackParam.fCovariances) {
89     if (fCovariances) *fCovariances = *(theMUONTrackParam.fCovariances);
90     else fCovariances = new TMatrixD(*(theMUONTrackParam.fCovariances));
91   } else if (fCovariances) {
92     delete fCovariances;
93     fCovariances = 0x0;
94   }
95   
96   return *this;
97 }
98
99   //__________________________________________________________________________
100 AliMUONTrackParam::~AliMUONTrackParam()
101 {
102 /// Destructor
103 /// Update the number of TrackHit's connected to the attached HitForRec if any
104   if (fHitForRecPtr) fHitForRecPtr->SetNTrackHits(fHitForRecPtr->GetNTrackHits() - 1); // decrement NTrackHits of hit
105   DeleteCovariances();
106 }
107
108   //__________________________________________________________________________
109 void AliMUONTrackParam::SetTrackParam(AliMUONTrackParam& theMUONTrackParam)
110 {
111   /// Set track parameters from "TrackParam" leaving pointer to fHitForRecPtr and parameter covariances unchanged
112   fNonBendingCoor               =  theMUONTrackParam.fNonBendingCoor;
113   fNonBendingSlope              =  theMUONTrackParam.fNonBendingSlope; 
114   fBendingCoor                  =  theMUONTrackParam.fBendingCoor; 
115   fBendingSlope                 =  theMUONTrackParam.fBendingSlope; 
116   fInverseBendingMomentum       =  theMUONTrackParam.fInverseBendingMomentum; 
117   fZ                            =  theMUONTrackParam.fZ; 
118 }
119
120   //__________________________________________________________________________
121 AliMUONHitForRec* AliMUONTrackParam::GetHitForRecPtr(void) const
122 {
123 /// return pointer to HitForRec attached to the current TrackParam
124 /// this method should not be called when fHitForRecPtr == NULL
125   if (!fHitForRecPtr) AliWarning("fHitForRecPtr == NULL");
126   return fHitForRecPtr;
127 }
128
129   //__________________________________________________________________________
130 void AliMUONTrackParam::SetHitForRecPtr(AliMUONHitForRec* hitForRec)
131 {
132 /// set pointeur to associated HitForRec and update the number of TrackHit's connected to it
133   fHitForRecPtr = hitForRec;
134   fHitForRecPtr->SetNTrackHits(fHitForRecPtr->GetNTrackHits() + 1); // increment NTrackHits of hit
135 }
136
137   //_________________________________________________________________________
138 void AliMUONTrackParam::GetParamFrom(const AliESDMuonTrack& esdMuonTrack)
139 {
140   /// assigned value form ESD track.
141   fInverseBendingMomentum       =  esdMuonTrack.GetInverseBendingMomentum();
142   fBendingSlope                 =  TMath::Tan(esdMuonTrack.GetThetaY());
143   fNonBendingSlope              =  TMath::Tan(esdMuonTrack.GetThetaX());
144   fZ                            =  esdMuonTrack.GetZ(); 
145   fBendingCoor                  =  esdMuonTrack.GetBendingCoor(); 
146   fNonBendingCoor               =  esdMuonTrack.GetNonBendingCoor();
147 }
148
149   //_________________________________________________________________________
150 void AliMUONTrackParam::SetParamFor(AliESDMuonTrack& esdMuonTrack)
151 {
152   /// assigned value form ESD track.
153   esdMuonTrack.SetInverseBendingMomentum(fInverseBendingMomentum);
154   esdMuonTrack.SetThetaX(TMath::ATan(fNonBendingSlope));
155   esdMuonTrack.SetThetaY(TMath::ATan(fBendingSlope));
156   esdMuonTrack.SetZ(fZ); 
157   esdMuonTrack.SetBendingCoor(fBendingCoor); 
158   esdMuonTrack.SetNonBendingCoor(fNonBendingCoor);
159 }
160
161   //__________________________________________________________________________
162 Double_t AliMUONTrackParam::Px() const
163 {
164   /// return px from track paramaters
165   Double_t pYZ, pZ, pX;
166   pYZ = 0;
167   if (  TMath::Abs(fInverseBendingMomentum) > 0 )
168     pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
169   pZ = -pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope));  // spectro. (z<0)
170   pX = pZ * fNonBendingSlope; 
171   return pX;
172 }
173
174   //__________________________________________________________________________
175 Double_t AliMUONTrackParam::Py() const
176 {
177   /// return px from track paramaters
178   Double_t pYZ, pZ, pY;
179   pYZ = 0;
180   if (  TMath::Abs(fInverseBendingMomentum) > 0 )
181     pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
182   pZ = -pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope));  // spectro. (z<0)
183   pY = pZ * fBendingSlope; 
184   return pY;
185 }
186
187   //__________________________________________________________________________
188 Double_t AliMUONTrackParam::Pz() const
189 {
190   /// return px from track paramaters
191   Double_t pYZ, pZ;
192   pYZ = 0;
193   if (  TMath::Abs(fInverseBendingMomentum) > 0 )
194     pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
195   pZ = -pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope));  // spectro. (z<0)
196   return pZ;
197 }
198
199   //__________________________________________________________________________
200 Double_t AliMUONTrackParam::P() const
201 {
202   /// return p from track paramaters
203   Double_t  pYZ, pZ, p;
204   pYZ = 0;
205   if (  TMath::Abs(fInverseBendingMomentum) > 0 )
206     pYZ = TMath::Abs(1.0 / fInverseBendingMomentum);
207   pZ = -pYZ / (TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope));  // spectro. (z<0)
208   p = TMath::Abs(pZ) * 
209     TMath::Sqrt(1.0 + fBendingSlope * fBendingSlope + fNonBendingSlope * fNonBendingSlope);
210   return p;
211   
212 }
213
214   //__________________________________________________________________________
215 TMatrixD* AliMUONTrackParam::GetCovariances()
216 {
217   /// Return the covariance matrix (create it before if needed)
218   if (!fCovariances) {
219     fCovariances = new TMatrixD(5,5);
220     (*fCovariances) = 0;
221   }
222   return fCovariances;
223   }
224
225   //__________________________________________________________________________
226 void AliMUONTrackParam::SetCovariances(TMatrixD* covariances)
227 {
228   /// Set the covariance matrix
229   if (covariances == fCovariances) return; // nothing to be done
230   if (fCovariances) *fCovariances = *covariances;
231   else fCovariances = new TMatrixD(*covariances);
232 }
233
234   //__________________________________________________________________________
235 void AliMUONTrackParam::SetCovariances(Double_t matrix[5][5])
236 {
237   /// Set the covariance matrix
238   if (fCovariances) fCovariances->SetMatrixArray(&(matrix[0][0]));
239   else fCovariances = new TMatrixD(5,5,&(matrix[0][0]));
240 }
241
242   //__________________________________________________________________________
243 void AliMUONTrackParam::SetVariances(Double_t matrix[5][5])
244 {
245   /// Set the diagonal terms of the covariance matrix (variances)
246   if (!fCovariances) fCovariances = new TMatrixD(5,5);
247   (*fCovariances) = 0;
248   for (Int_t i=0; i<5; i++) (*fCovariances)(i,i) = matrix[i][i];
249 }
250
251   //__________________________________________________________________________
252 void AliMUONTrackParam::DeleteCovariances()
253 {
254   /// Delete the covariance matrix
255   if (fCovariances) delete fCovariances;
256   fCovariances = 0x0;
257 }
258
259   //__________________________________________________________________________
260 void AliMUONTrackParam::EvalCovariances(AliMUONHitForRec* hit2)
261 {
262   /// Evaluate covariances assuming the track is only a straight line
263   /// between the HitForRec attached to the current TrackParam and hit2.
264   /// Nothing can be done on fInverseBendingMomentum (-> 50% err).
265   
266   // Allocate memory if needed
267   if (!fCovariances) fCovariances = new TMatrixD(5,5);
268   
269   // Reset the covariance matrix
270   (*fCovariances) = 0;
271   
272   if (!fHitForRecPtr) {
273     AliWarning("fHitForRecPtr == NULL: cannot calculate TrackParam covariances");
274     return;
275   }
276   
277   Double_t dz = fHitForRecPtr->GetZ() - hit2->GetZ();
278   
279   // Non bending plane
280   (*fCovariances)(0,0) = fHitForRecPtr->GetNonBendingReso2();
281   (*fCovariances)(0,1) = fHitForRecPtr->GetNonBendingReso2() / dz;
282   (*fCovariances)(1,0) = (*fCovariances)(0,1);
283   (*fCovariances)(1,1) = ( fHitForRecPtr->GetNonBendingReso2() + hit2->GetNonBendingReso2() ) / dz / dz;
284   // Bending plane
285   (*fCovariances)(2,2) = fHitForRecPtr->GetBendingReso2();
286   (*fCovariances)(2,3) = fHitForRecPtr->GetBendingReso2() / dz;
287   (*fCovariances)(3,2) = (*fCovariances)(2,3);
288   (*fCovariances)(3,3) = ( fHitForRecPtr->GetBendingReso2() + hit2->GetBendingReso2() ) / dz / dz;
289   // Inverse bending momentum
290   (*fCovariances)(4,4) = 0.5*fInverseBendingMomentum * 0.5*fInverseBendingMomentum; // error 50%
291   
292 }
293
294   //__________________________________________________________________________
295 Int_t AliMUONTrackParam::Compare(const TObject* trackParam) const
296 {
297   /// "Compare" function to sort with decreasing Z (spectro. muon Z <0).
298   /// Returns 1 (0, -1) if Z of current TrackHit
299   /// is smaller than (equal to, larger than) Z of TrackHit
300   if (fHitForRecPtr->GetZ() < ((AliMUONTrackParam*)trackParam)->fHitForRecPtr->GetZ()) return(1);
301   else if (fHitForRecPtr->GetZ() == ((AliMUONTrackParam*)trackParam)->fHitForRecPtr->GetZ()) return(0);
302   else return(-1);
303 }
304
305 //_____________________________________________-
306 void AliMUONTrackParam::Print(Option_t* opt) const
307 {
308   /// Printing TrackParam information 
309   /// "full" option for printing all the information about the TrackParam
310   TString sopt(opt);
311   sopt.ToUpper();
312  
313   if ( sopt.Contains("FULL") ) { 
314     cout << "<AliMUONTrackParam> Bending P=" << setw(5) << setprecision(3)  << 1./GetInverseBendingMomentum() << 
315       ", NonBendSlope=" << setw(5) << setprecision(3)  << GetNonBendingSlope()*180./TMath::Pi() <<
316       ", BendSlope=" << setw(5) << setprecision(3)     << GetBendingSlope()*180./TMath::Pi()  << 
317       ", (x,y,z)_IP=(" <<  setw(5) << setprecision(3) << GetNonBendingCoor() <<
318       "," <<  setw(5) << setprecision(3) << GetBendingCoor() <<
319       "," <<  setw(5) << setprecision(3) << GetZ() <<
320       ") cm, (px,py,pz)=(" << setw(5) << setprecision(3) << Px() <<
321       "," << setw(5) << setprecision(3) << Py() <<
322       "," << setw(5) << setprecision(3) << Pz() << ") GeV/c" << endl;
323   }
324   else {
325     cout << "<AliMUONTrackParam>"  << endl;
326   }
327     
328 }