]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliKalmanTrack.cxx
DCA calculation moved to the AliKalmanTrack (Yu.Belikov)
[u/mrichter/AliRoot.git] / STEER / AliKalmanTrack.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 //                Implementation of the AliKalmanTrack class
20 //   that is the base for AliTPCtrack, AliITStrackV2 and AliTRDtrack
21 //        Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
22 //-------------------------------------------------------------------------
23
24 #include "AliKalmanTrack.h"
25 #include "AliPDG.h"
26 #include "TPDGCode.h"
27 #include "TDatabasePDG.h"
28
29 ClassImp(AliKalmanTrack)
30
31 Double_t AliKalmanTrack::fgConvConst;
32
33 //_______________________________________________________________________
34 AliKalmanTrack::AliKalmanTrack():
35   fLab(-3141593),
36   fChi2(0),
37   fMass(0.13957),
38   fN(0)
39 {
40   //
41   // Default constructor
42   //
43     if (fgConvConst==0) 
44       Fatal("AliKalmanTrack()","The magnetic field has not been set !\n"); 
45     
46     fStartTimeIntegral = kFALSE;
47     fIntegratedLength = 0;
48     for(Int_t i=0; i<5; i++) fIntegratedTime[i] = 0;
49 }
50
51 //_______________________________________________________________________
52 AliKalmanTrack::AliKalmanTrack(const AliKalmanTrack &t):
53   TObject(t),
54   fLab(t.fLab),
55   fChi2(t.fChi2),
56   fMass(t.fMass),
57   fN(t.fN)
58 {
59   //
60   // Copy constructor
61   //
62   if (fgConvConst==0) 
63     Fatal("AliKalmanTrack(const AliKalmanTrack&)",
64           "The magnetic field has not been set !\n"); 
65
66   fStartTimeIntegral = t.fStartTimeIntegral;
67   fIntegratedLength = t.fIntegratedLength;
68   
69   for (Int_t i=0; i<5; i++) 
70     fIntegratedTime[i] = t.fIntegratedTime[i];
71 }
72 //_______________________________________________________________________
73 void AliKalmanTrack::StartTimeIntegral() 
74 {
75   // Sylwester Radomski, GSI
76   // S.Radomski@gsi.de
77   //
78   // Start time integration
79   // To be called at Vertex by ITS tracker
80   //
81   
82   //if (fStartTimeIntegral) 
83   //  Warning("StartTimeIntegral", "Reseting Recorded Time.");
84
85   fStartTimeIntegral = kTRUE;
86   for(Int_t i=0; i<fgkTypes; i++) fIntegratedTime[i] = 0;  
87   fIntegratedLength = 0;
88 }
89 //_______________________________________________________________________
90 void AliKalmanTrack:: AddTimeStep(Double_t length) 
91 {
92   // 
93   // Add step to integrated time
94   // this method should be called by a sublasses at the end
95   // of the PropagateTo function or by a tracker
96   // each time step is made.
97   //
98   // If integration not started function does nothing
99   //
100   // Formula
101   // dt = dl * sqrt(p^2 + m^2) / p
102   // p = pT * (1 + tg^2 (lambda) )
103   //
104   // pt = 1/external parameter [4]
105   // tg lambda = external parameter [3]
106   //
107   //
108   // Sylwester Radomski, GSI
109   // S.Radomski@gsi.de
110   // 
111   
112   static const Double_t kcc = 2.99792458e-2;
113
114   if (!fStartTimeIntegral) return;
115   
116   fIntegratedLength += length;
117
118   static Int_t pdgCode[fgkTypes]  = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
119   TDatabasePDG *db = TDatabasePDG::Instance();
120
121   Double_t xr, param[5];
122   Double_t pt, tgl;
123   
124   GetExternalParameters(xr, param);
125   pt =  1/param[4] ;
126   tgl = param[3];
127
128   Double_t p = TMath::Abs(pt * TMath::Sqrt(1+tgl*tgl));
129
130   if (length > 100) return;
131
132   for (Int_t i=0; i<fgkTypes; i++) {
133     
134     Double_t mass = db->GetParticle(pdgCode[i])->Mass();
135     Double_t correction = TMath::Sqrt( pt*pt * (1 + tgl*tgl) + mass * mass ) / p;
136     Double_t time = length * correction / kcc;
137
138     //cout << mass << "\t" << pt << "\t" << p << "\t" 
139     //     << correction << endl;
140
141     fIntegratedTime[i] += time;
142   }
143 }
144
145 //_______________________________________________________________________
146
147 Double_t AliKalmanTrack::GetIntegratedTime(Int_t pdg) const 
148 {
149   // Sylwester Radomski, GSI
150   // S.Radomski@gsi.de
151   //
152   // Return integrated time hypothesis for a given particle
153   // type assumption.
154   //
155   // Input parameter:
156   // pdg - Pdg code of a particle type
157   //
158
159
160   if (!fStartTimeIntegral) {
161     Warning("GetIntegratedTime","Time integration not started");
162     return 0.;
163   }
164
165   static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
166
167   for (Int_t i=0; i<fgkTypes; i++)
168     if (pdgCode[i] == TMath::Abs(pdg)) return fIntegratedTime[i];
169
170   Warning(":GetIntegratedTime","Particle type [%d] not found", pdg);
171   return 0;
172 }
173 //_______________________________________________________________________
174
175 void AliKalmanTrack::PrintTime() const
176 {
177   // Sylwester Radomski, GSI
178   // S.Radomski@gsi.de
179   //
180   // For testing
181   // Prints time for all hypothesis
182   //
183
184   static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
185
186   for (Int_t i=0; i<fgkTypes; i++)
187     printf("%d: %.2f  ", pdgCode[i], fIntegratedTime[i]);
188   printf("\n");  
189 }
190
191 static void External2Helix(const AliKalmanTrack *t, Double_t helix[6]) { 
192   //--------------------------------------------------------------------
193   // External track parameters -> helix parameters 
194   //--------------------------------------------------------------------
195   Double_t alpha,x,cs,sn;
196   t->GetExternalParameters(x,helix); alpha=t->GetAlpha();
197
198   cs=TMath::Cos(alpha); sn=TMath::Sin(alpha);
199   helix[5]=x*cs - helix[0]*sn;            // x0
200   helix[0]=x*sn + helix[0]*cs;            // y0
201 //helix[1]=                               // z0
202   helix[2]=TMath::ASin(helix[2]) + alpha; // phi0
203 //helix[3]=                               // tgl
204   helix[4]=helix[4]/t->GetConvConst();    // C
205 }
206
207 static void Evaluate(const Double_t *h, Double_t t,
208                      Double_t r[3],  //radius vector
209                      Double_t g[3],  //first defivatives
210                      Double_t gg[3]) //second derivatives
211 {
212   //--------------------------------------------------------------------
213   // Calculate position of a point on a track and some derivatives
214   //--------------------------------------------------------------------
215   Double_t phase=h[4]*t+h[2];
216   Double_t sn=TMath::Sin(phase), cs=TMath::Cos(phase);
217
218   r[0] = h[5] + (sn - h[6])/h[4];
219   r[1] = h[0] - (cs - h[7])/h[4];  
220   r[2] = h[1] + h[3]*t;
221
222   g[0] = cs; g[1]=sn; g[2]=h[3];
223   
224   gg[0]=-h[4]*sn; gg[1]=h[4]*cs; gg[2]=0.;
225 }
226
227 Double_t AliKalmanTrack::
228 GetDCA(const AliKalmanTrack *p, Double_t &xthis, Double_t &xp) const {
229   //------------------------------------------------------------
230   // Returns the (weighed !) distance of closest approach between 
231   // this track and the track passed as the argument.
232   // Other returned values:
233   //   xthis, xt - coordinates of tracks' reference planes at the DCA 
234   //-----------------------------------------------------------
235   Double_t dy2=GetSigmaY2() + p->GetSigmaY2();
236   Double_t dz2=GetSigmaZ2() + p->GetSigmaZ2();
237   Double_t dx2=dy2; 
238
239   //dx2=dy2=dz2=1.;
240
241   Double_t p1[8]; External2Helix(this,p1);
242   p1[6]=TMath::Sin(p1[2]); p1[7]=TMath::Cos(p1[2]);
243   Double_t p2[8]; External2Helix(p,p2);
244   p2[6]=TMath::Sin(p2[2]); p2[7]=TMath::Cos(p2[2]);
245
246
247   Double_t r1[3],g1[3],gg1[3]; Double_t t1=0.;
248   Evaluate(p1,t1,r1,g1,gg1);
249   Double_t r2[3],g2[3],gg2[3]; Double_t t2=0.;
250   Evaluate(p2,t2,r2,g2,gg2);
251
252   Double_t dx=r2[0]-r1[0], dy=r2[1]-r1[1], dz=r2[2]-r1[2];
253   Double_t dm=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
254
255   Int_t max=27;
256   while (max--) {
257      Double_t gt1=-(dx*g1[0]/dx2 + dy*g1[1]/dy2 + dz*g1[2]/dz2);
258      Double_t gt2=+(dx*g2[0]/dx2 + dy*g2[1]/dy2 + dz*g2[2]/dz2);
259      Double_t h11=(g1[0]*g1[0] - dx*gg1[0])/dx2 + 
260                   (g1[1]*g1[1] - dy*gg1[1])/dy2 +
261                   (g1[2]*g1[2] - dz*gg1[2])/dz2;
262      Double_t h22=(g2[0]*g2[0] + dx*gg2[0])/dx2 + 
263                   (g2[1]*g2[1] + dy*gg2[1])/dy2 +
264                   (g2[2]*g2[2] + dz*gg2[2])/dz2;
265      Double_t h12=-(g1[0]*g2[0]/dx2 + g1[1]*g2[1]/dy2 + g1[2]*g2[2]/dz2);
266
267      Double_t det=h11*h22-h12*h12;
268
269      Double_t dt1,dt2;
270      if (TMath::Abs(det)<1.e-33) {
271         //(quasi)singular Hessian
272         dt1=-gt1; dt2=-gt2;
273      } else {
274         dt1=-(gt1*h22 - gt2*h12)/det; 
275         dt2=-(h11*gt2 - h12*gt1)/det;
276      }
277
278      if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
279
280      //check delta(phase1) ?
281      //check delta(phase2) ?
282
283      if (TMath::Abs(dt1)/(TMath::Abs(t1)+1.e-3) < 1.e-4)
284      if (TMath::Abs(dt2)/(TMath::Abs(t2)+1.e-3) < 1.e-4) {
285         if ((gt1*gt1+gt2*gt2) > 1.e-4/dy2/dy2) 
286           Warning("GetDCA"," stopped at not a stationary point !\n");
287         Double_t lmb=h11+h22; lmb=lmb-TMath::Sqrt(lmb*lmb-4*det);
288         if (lmb < 0.) 
289           Warning("GetDCA"," stopped at not a minimum !\n");
290         break;
291      }
292
293      Double_t dd=dm;
294      for (Int_t div=1 ; ; div*=2) {
295         Evaluate(p1,t1+dt1,r1,g1,gg1);
296         Evaluate(p2,t2+dt2,r2,g2,gg2);
297         dx=r2[0]-r1[0]; dy=r2[1]-r1[1]; dz=r2[2]-r1[2];
298         dd=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
299         if (dd<dm) break;
300         dt1*=0.5; dt2*=0.5;
301         if (div>512) {
302            Warning("GetDCA"," overshoot !\n"); break;
303         }   
304      }
305      dm=dd;
306
307      t1+=dt1;
308      t2+=dt2;
309
310   }
311
312   if (max<=0) Warning("GetDCA"," too many iterations !\n");  
313
314   Double_t cs=TMath::Cos(GetAlpha());
315   Double_t sn=TMath::Sin(GetAlpha());
316   xthis=r1[0]*cs + r1[1]*sn;
317
318   cs=TMath::Cos(p->GetAlpha());
319   sn=TMath::Sin(p->GetAlpha());
320   xp=r2[0]*cs + r2[1]*sn;
321
322   return TMath::Sqrt(dm*TMath::Sqrt(dy2*dz2));
323 }
324
325 Double_t AliKalmanTrack::
326 PropagateToDCA(AliKalmanTrack *p, Double_t d, Double_t x0) {
327   //--------------------------------------------------------------
328   // Propagates this track and the argument track to the position of the
329   // distance of closest approach. 
330   // Returns the (weighed !) distance of closest approach.
331   //--------------------------------------------------------------
332   Double_t xthis,xp;
333   Double_t dca=GetDCA(p,xthis,xp);
334
335   if (!PropagateTo(xthis,d,x0)) {
336     //Warning("PropagateToDCA"," propagation failed !\n");
337     return 1e+33;
338   }  
339
340   if (!p->PropagateTo(xp,d,x0)) {
341     //Warning("PropagateToDCA"," propagation failed !\n";
342     return 1e+33;
343   }  
344
345   return dca;
346 }