]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliKalmanTrack.cxx
Shortcut methods in AliRunLoader. AliHits2SDigits.C and AliSDigits2Digits.C adapted...
[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 #include "AliRunLoader.h"
29 #include "AliRun.h"
30 #include "AliMagF.h"
31
32 ClassImp(AliKalmanTrack)
33
34 Double_t AliKalmanTrack::fgConvConst;
35
36 //_______________________________________________________________________
37 AliKalmanTrack::AliKalmanTrack():
38   fLab(-3141593),
39   fChi2(0),
40   fMass(0.13957),
41   fN(0)
42 {
43   //
44   // Default constructor
45   //
46     if (fgConvConst==0) {
47       Warning("AliKalmanTrack()", "The magnetic field has not been set!");
48       SetConvConst();
49     }
50     
51     fStartTimeIntegral = kFALSE;
52     fIntegratedLength = 0;
53     for(Int_t i=0; i<5; i++) fIntegratedTime[i] = 0;
54 }
55
56 //_______________________________________________________________________
57 AliKalmanTrack::AliKalmanTrack(const AliKalmanTrack &t):
58   TObject(t),
59   fLab(t.fLab),
60   fChi2(t.fChi2),
61   fMass(t.fMass),
62   fN(t.fN)
63 {
64   //
65   // Copy constructor
66   //
67   if (fgConvConst==0) {
68     Warning("AliKalmanTrack(const AliKalmanTrack&)", 
69             "The magnetic field has not been set!");
70     SetConvConst();
71   }
72
73   fStartTimeIntegral = t.fStartTimeIntegral;
74   fIntegratedLength = t.fIntegratedLength;
75   
76   for (Int_t i=0; i<5; i++) 
77     fIntegratedTime[i] = t.fIntegratedTime[i];
78 }
79
80
81 //_______________________________________________________________________
82 void AliKalmanTrack::SetConvConst()
83 {
84   ::Info("SetConvConst()", "tryinig to get the magnetic field from the AliRun object..."); 
85   AliRunLoader* loader = AliRunLoader::GetRunLoader();
86   if (!loader) ::Fatal("SetConvConst()", "No run loader found"); 
87   if (!loader->GetAliRun()) loader->LoadgAlice();
88   AliRun* alirun = loader->GetAliRun();
89   if (!alirun) ::Fatal("SetConvConst()", "No AliRun object found");
90
91   Double_t field = alirun->Field()->SolenoidField();
92   SetConvConst(1000/0.299792458/field);
93   ::Info("SetConvConst()", "Magnetic field set to %f kGauss\n", field);
94 }
95
96 //_______________________________________________________________________
97 Double_t AliKalmanTrack::GetX() const
98 {
99   Warning("GetX()","Method must be overloaded !\n");
100   return 0.;
101 }
102 //_______________________________________________________________________
103 Double_t AliKalmanTrack::GetdEdx() const
104 {
105   Warning("GetdEdx()","Method must be overloaded !\n");
106   return 0.;
107 }
108
109 //_______________________________________________________________________
110 Double_t AliKalmanTrack::GetY() const
111 {
112   Double_t par[5];
113   Double_t localX = GetX();
114   GetExternalParameters(localX, par);
115   return par[0];
116 }
117 //_______________________________________________________________________
118 Double_t AliKalmanTrack::GetZ() const
119 {
120   Double_t par[5];
121   Double_t localX = GetX();
122   GetExternalParameters(localX, par);
123   return par[1];
124 }
125 //_______________________________________________________________________
126 Double_t AliKalmanTrack::GetSnp() const
127 {
128   Double_t par[5];
129   Double_t localX = GetX();
130   GetExternalParameters(localX, par);
131   return par[2];
132 }
133 //_______________________________________________________________________
134 Double_t AliKalmanTrack::GetTgl() const
135 {
136   Double_t par[5];
137   Double_t localX = GetX();
138   GetExternalParameters(localX, par);
139   return par[3];
140 }
141 //_______________________________________________________________________
142 Double_t AliKalmanTrack::Get1Pt() const
143 {
144   Double_t par[5];
145   Double_t localX = GetX();
146   GetExternalParameters(localX, par);
147   return par[4];
148 }
149
150 //_______________________________________________________________________
151 Double_t AliKalmanTrack::Phi() const
152 {
153 // return global phi of track
154
155   Double_t par[5];
156   Double_t localX = GetX();
157   GetExternalParameters(localX, par);
158   if (par[2] >  1.) par[2] =  1.;
159   if (par[2] < -1.) par[2] = -1.;
160   Double_t phi = TMath::ASin(par[2]) + GetAlpha();
161   while (phi < 0) phi += TMath::TwoPi();
162   while (phi > TMath::TwoPi()) phi -= TMath::TwoPi();
163   return phi;
164 }
165 //_______________________________________________________________________
166 Double_t AliKalmanTrack::SigmaPhi() const
167 {
168 // return error of global phi of track
169
170   Double_t par[5];
171   Double_t cov[15];
172   Double_t localX = GetX();
173   GetExternalParameters(localX, par);
174   GetExternalCovariance(cov);
175   return TMath::Sqrt(TMath::Abs(cov[5] / (1. - par[2]*par[2])));
176 }
177 //_______________________________________________________________________
178 Double_t AliKalmanTrack::Theta() const
179 {
180 // return global theta of track
181
182   Double_t par[5];
183   Double_t localX = GetX();
184   GetExternalParameters(localX, par);
185   return TMath::Pi()/2. - TMath::ATan(par[3]);
186 }
187 //_______________________________________________________________________
188 Double_t AliKalmanTrack::SigmaTheta() const
189 {
190 // return error of global theta of track
191
192   Double_t par[5];
193   Double_t cov[15];
194   Double_t localX = GetX();
195   GetExternalParameters(localX, par);
196   GetExternalCovariance(cov);
197   return TMath::Sqrt(TMath::Abs(cov[5])) / (1. + par[3]*par[3]);
198 }
199 //_______________________________________________________________________
200 Double_t AliKalmanTrack::Eta() const
201 {
202 // return global eta of track
203
204   return -TMath::Log(TMath::Tan(Theta()/2.));
205 }
206 //_______________________________________________________________________
207 Double_t AliKalmanTrack::Px() const
208 {
209 // return x component of track momentum
210
211   Double_t par[5];
212   Double_t localX = GetX();
213   GetExternalParameters(localX, par);
214   Double_t phi = TMath::ASin(par[2]) + GetAlpha();
215   return TMath::Cos(phi) / TMath::Abs(par[4]);
216 }
217 //_______________________________________________________________________
218 Double_t AliKalmanTrack::Py() const
219 {
220 // return y component of track momentum
221
222   Double_t par[5];
223   Double_t localX = GetX();
224   GetExternalParameters(localX, par);
225   Double_t phi = TMath::ASin(par[2]) + GetAlpha();
226   return TMath::Sin(phi) / TMath::Abs(par[4]);
227 }
228 //_______________________________________________________________________
229 Double_t AliKalmanTrack::Pz() const
230 {
231 // return z component of track momentum
232
233   Double_t par[5];
234   Double_t localX = GetX();
235   GetExternalParameters(localX, par);
236   return par[3] / TMath::Abs(par[4]);
237 }
238 //_______________________________________________________________________
239 Double_t AliKalmanTrack::Pt() const
240 {
241 // return transverse component of track momentum
242
243   Double_t par[5];
244   Double_t localX = GetX();
245   GetExternalParameters(localX, par);
246   return 1. / TMath::Abs(par[4]);
247 }
248 //_______________________________________________________________________
249 Double_t AliKalmanTrack::SigmaPt() const
250 {
251 // return error of transverse component of track momentum
252
253   Double_t par[5];
254   Double_t cov[15];
255   Double_t localX = GetX();
256   GetExternalParameters(localX, par);
257   GetExternalCovariance(cov);
258   return TMath::Sqrt(cov[14]) / TMath::Abs(par[4]);
259 }
260 //_______________________________________________________________________
261 Double_t AliKalmanTrack::P() const
262 {
263 // return total track momentum
264
265   Double_t par[5];
266   Double_t localX = GetX();
267   GetExternalParameters(localX, par);
268   return 1. / TMath::Abs(par[4] * TMath::Cos(TMath::ATan(par[3])));
269 }
270 //_______________________________________________________________________
271 void AliKalmanTrack::StartTimeIntegral() 
272 {
273   // Sylwester Radomski, GSI
274   // S.Radomski@gsi.de
275   //
276   // Start time integration
277   // To be called at Vertex by ITS tracker
278   //
279   
280   //if (fStartTimeIntegral) 
281   //  Warning("StartTimeIntegral", "Reseting Recorded Time.");
282
283   fStartTimeIntegral = kTRUE;
284   for(Int_t i=0; i<fgkTypes; i++) fIntegratedTime[i] = 0;  
285   fIntegratedLength = 0;
286 }
287 //_______________________________________________________________________
288 void AliKalmanTrack:: AddTimeStep(Double_t length) 
289 {
290   // 
291   // Add step to integrated time
292   // this method should be called by a sublasses at the end
293   // of the PropagateTo function or by a tracker
294   // each time step is made.
295   //
296   // If integration not started function does nothing
297   //
298   // Formula
299   // dt = dl * sqrt(p^2 + m^2) / p
300   // p = pT * (1 + tg^2 (lambda) )
301   //
302   // pt = 1/external parameter [4]
303   // tg lambda = external parameter [3]
304   //
305   //
306   // Sylwester Radomski, GSI
307   // S.Radomski@gsi.de
308   // 
309   
310   static const Double_t kcc = 2.99792458e-2;
311
312   if (!fStartTimeIntegral) return;
313   
314   fIntegratedLength += length;
315
316   static Int_t pdgCode[fgkTypes]  = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
317   TDatabasePDG *db = TDatabasePDG::Instance();
318
319   Double_t xr, param[5];
320   Double_t pt, tgl;
321   
322   GetExternalParameters(xr, param);
323   pt =  1/param[4] ;
324   tgl = param[3];
325
326   Double_t p = TMath::Abs(pt * TMath::Sqrt(1+tgl*tgl));
327
328   if (length > 100) return;
329
330   for (Int_t i=0; i<fgkTypes; i++) {
331     
332     Double_t mass = db->GetParticle(pdgCode[i])->Mass();
333     Double_t correction = TMath::Sqrt( pt*pt * (1 + tgl*tgl) + mass * mass ) / p;
334     Double_t time = length * correction / kcc;
335
336     //cout << mass << "\t" << pt << "\t" << p << "\t" 
337     //     << correction << endl;
338
339     fIntegratedTime[i] += time;
340   }
341 }
342
343 //_______________________________________________________________________
344
345 Double_t AliKalmanTrack::GetIntegratedTime(Int_t pdg) const 
346 {
347   // Sylwester Radomski, GSI
348   // S.Radomski@gsi.de
349   //
350   // Return integrated time hypothesis for a given particle
351   // type assumption.
352   //
353   // Input parameter:
354   // pdg - Pdg code of a particle type
355   //
356
357
358   if (!fStartTimeIntegral) {
359     Warning("GetIntegratedTime","Time integration not started");
360     return 0.;
361   }
362
363   static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
364
365   for (Int_t i=0; i<fgkTypes; i++)
366     if (pdgCode[i] == TMath::Abs(pdg)) return fIntegratedTime[i];
367
368   Warning(":GetIntegratedTime","Particle type [%d] not found", pdg);
369   return 0;
370 }
371
372 void AliKalmanTrack::GetIntegratedTimes(Double_t *times) const {
373   for (Int_t i=0; i<fgkTypes; i++) times[i]=fIntegratedTime[i];
374 }
375
376 void AliKalmanTrack::SetIntegratedTimes(const Double_t *times) {
377   for (Int_t i=0; i<fgkTypes; i++) fIntegratedTime[i]=times[i];
378 }
379
380 //_______________________________________________________________________
381
382 void AliKalmanTrack::PrintTime() const
383 {
384   // Sylwester Radomski, GSI
385   // S.Radomski@gsi.de
386   //
387   // For testing
388   // Prints time for all hypothesis
389   //
390
391   static Int_t pdgCode[fgkTypes] = {kElectron, kMuonMinus, kPiPlus, kKPlus, kProton};
392
393   for (Int_t i=0; i<fgkTypes; i++)
394     printf("%d: %.2f  ", pdgCode[i], fIntegratedTime[i]);
395   printf("\n");  
396 }
397
398 static void External2Helix(const AliKalmanTrack *t, Double_t helix[6]) { 
399   //--------------------------------------------------------------------
400   // External track parameters -> helix parameters 
401   //--------------------------------------------------------------------
402   Double_t alpha,x,cs,sn;
403   t->GetExternalParameters(x,helix); alpha=t->GetAlpha();
404
405   cs=TMath::Cos(alpha); sn=TMath::Sin(alpha);
406   helix[5]=x*cs - helix[0]*sn;            // x0
407   helix[0]=x*sn + helix[0]*cs;            // y0
408 //helix[1]=                               // z0
409   helix[2]=TMath::ASin(helix[2]) + alpha; // phi0
410 //helix[3]=                               // tgl
411   helix[4]=helix[4]/t->GetConvConst();    // C
412 }
413
414 static void Evaluate(const Double_t *h, Double_t t,
415                      Double_t r[3],  //radius vector
416                      Double_t g[3],  //first defivatives
417                      Double_t gg[3]) //second derivatives
418 {
419   //--------------------------------------------------------------------
420   // Calculate position of a point on a track and some derivatives
421   //--------------------------------------------------------------------
422   Double_t phase=h[4]*t+h[2];
423   Double_t sn=TMath::Sin(phase), cs=TMath::Cos(phase);
424
425   r[0] = h[5] + (sn - h[6])/h[4];
426   r[1] = h[0] - (cs - h[7])/h[4];  
427   r[2] = h[1] + h[3]*t;
428
429   g[0] = cs; g[1]=sn; g[2]=h[3];
430   
431   gg[0]=-h[4]*sn; gg[1]=h[4]*cs; gg[2]=0.;
432 }
433
434 Double_t AliKalmanTrack::
435 GetDCA(const AliKalmanTrack *p, Double_t &xthis, Double_t &xp) const {
436   //------------------------------------------------------------
437   // Returns the (weighed !) distance of closest approach between 
438   // this track and the track passed as the argument.
439   // Other returned values:
440   //   xthis, xt - coordinates of tracks' reference planes at the DCA 
441   //-----------------------------------------------------------
442   Double_t dy2=GetSigmaY2() + p->GetSigmaY2();
443   Double_t dz2=GetSigmaZ2() + p->GetSigmaZ2();
444   Double_t dx2=dy2; 
445
446   //dx2=dy2=dz2=1.;
447
448   Double_t p1[8]; External2Helix(this,p1);
449   p1[6]=TMath::Sin(p1[2]); p1[7]=TMath::Cos(p1[2]);
450   Double_t p2[8]; External2Helix(p,p2);
451   p2[6]=TMath::Sin(p2[2]); p2[7]=TMath::Cos(p2[2]);
452
453
454   Double_t r1[3],g1[3],gg1[3]; Double_t t1=0.;
455   Evaluate(p1,t1,r1,g1,gg1);
456   Double_t r2[3],g2[3],gg2[3]; Double_t t2=0.;
457   Evaluate(p2,t2,r2,g2,gg2);
458
459   Double_t dx=r2[0]-r1[0], dy=r2[1]-r1[1], dz=r2[2]-r1[2];
460   Double_t dm=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
461
462   Int_t max=27;
463   while (max--) {
464      Double_t gt1=-(dx*g1[0]/dx2 + dy*g1[1]/dy2 + dz*g1[2]/dz2);
465      Double_t gt2=+(dx*g2[0]/dx2 + dy*g2[1]/dy2 + dz*g2[2]/dz2);
466      Double_t h11=(g1[0]*g1[0] - dx*gg1[0])/dx2 + 
467                   (g1[1]*g1[1] - dy*gg1[1])/dy2 +
468                   (g1[2]*g1[2] - dz*gg1[2])/dz2;
469      Double_t h22=(g2[0]*g2[0] + dx*gg2[0])/dx2 + 
470                   (g2[1]*g2[1] + dy*gg2[1])/dy2 +
471                   (g2[2]*g2[2] + dz*gg2[2])/dz2;
472      Double_t h12=-(g1[0]*g2[0]/dx2 + g1[1]*g2[1]/dy2 + g1[2]*g2[2]/dz2);
473
474      Double_t det=h11*h22-h12*h12;
475
476      Double_t dt1,dt2;
477      if (TMath::Abs(det)<1.e-33) {
478         //(quasi)singular Hessian
479         dt1=-gt1; dt2=-gt2;
480      } else {
481         dt1=-(gt1*h22 - gt2*h12)/det; 
482         dt2=-(h11*gt2 - h12*gt1)/det;
483      }
484
485      if ((dt1*gt1+dt2*gt2)>0) {dt1=-dt1; dt2=-dt2;}
486
487      //check delta(phase1) ?
488      //check delta(phase2) ?
489
490      if (TMath::Abs(dt1)/(TMath::Abs(t1)+1.e-3) < 1.e-4)
491      if (TMath::Abs(dt2)/(TMath::Abs(t2)+1.e-3) < 1.e-4) {
492         if ((gt1*gt1+gt2*gt2) > 1.e-4/dy2/dy2) 
493           Warning("GetDCA"," stopped at not a stationary point !\n");
494         Double_t lmb=h11+h22; lmb=lmb-TMath::Sqrt(lmb*lmb-4*det);
495         if (lmb < 0.) 
496           Warning("GetDCA"," stopped at not a minimum !\n");
497         break;
498      }
499
500      Double_t dd=dm;
501      for (Int_t div=1 ; ; div*=2) {
502         Evaluate(p1,t1+dt1,r1,g1,gg1);
503         Evaluate(p2,t2+dt2,r2,g2,gg2);
504         dx=r2[0]-r1[0]; dy=r2[1]-r1[1]; dz=r2[2]-r1[2];
505         dd=dx*dx/dx2 + dy*dy/dy2 + dz*dz/dz2;
506         if (dd<dm) break;
507         dt1*=0.5; dt2*=0.5;
508         if (div>512) {
509            Warning("GetDCA"," overshoot !\n"); break;
510         }   
511      }
512      dm=dd;
513
514      t1+=dt1;
515      t2+=dt2;
516
517   }
518
519   if (max<=0) Warning("GetDCA"," too many iterations !\n");  
520
521   Double_t cs=TMath::Cos(GetAlpha());
522   Double_t sn=TMath::Sin(GetAlpha());
523   xthis=r1[0]*cs + r1[1]*sn;
524
525   cs=TMath::Cos(p->GetAlpha());
526   sn=TMath::Sin(p->GetAlpha());
527   xp=r2[0]*cs + r2[1]*sn;
528
529   return TMath::Sqrt(dm*TMath::Sqrt(dy2*dz2));
530 }
531
532 Double_t AliKalmanTrack::
533 PropagateToDCA(AliKalmanTrack *p, Double_t d, Double_t x0) {
534   //--------------------------------------------------------------
535   // Propagates this track and the argument track to the position of the
536   // distance of closest approach. 
537   // Returns the (weighed !) distance of closest approach.
538   //--------------------------------------------------------------
539   Double_t xthis,xp;
540   Double_t dca=GetDCA(p,xthis,xp);
541
542   if (!PropagateTo(xthis,d,x0)) {
543     //Warning("PropagateToDCA"," propagation failed !\n");
544     return 1e+33;
545   }  
546
547   if (!p->PropagateTo(xp,d,x0)) {
548     //Warning("PropagateToDCA"," propagation failed !\n";
549     return 1e+33;
550   }  
551
552   return dca;
553 }