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