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