1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 /* $Id: AliTrackerBase.cxx 38069 2009-12-24 16:56:18Z belikov $ */
18 //-------------------------------------------------------------------------
19 // Implementation of the AliTrackerBase class
20 // that is the base for the AliTracker class
21 // Origin: Marian.Ivanov@cern.ch
22 //-------------------------------------------------------------------------
25 #include <TGeoManager.h>
28 #include "AliTrackerBase.h"
29 #include "AliExternalTrackParam.h"
30 #include "AliTrackPointArray.h"
33 extern TGeoManager *gGeoManager;
35 ClassImp(AliTrackerBase)
37 AliTrackerBase::AliTrackerBase():
46 //--------------------------------------------------------------------
47 // The default constructor.
48 //--------------------------------------------------------------------
49 if (!TGeoGlobalMagField::Instance()->GetField())
50 AliWarning("Field map is not set.");
53 //__________________________________________________________________________
54 AliTrackerBase::AliTrackerBase(const AliTrackerBase &atr):
63 //--------------------------------------------------------------------
64 // The default constructor.
65 //--------------------------------------------------------------------
66 if (!TGeoGlobalMagField::Instance()->GetField())
67 AliWarning("Field map is not set.");
70 //__________________________________________________________________________
71 Double_t AliTrackerBase::GetBz()
73 AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
74 if (!fld) return 0.5*kAlmost0Field;
75 Double_t bz = fld->SolenoidField();
76 return TMath::Sign(0.5*kAlmost0Field,bz) + bz;
79 //__________________________________________________________________________
80 Double_t AliTrackerBase::GetBz(const Double_t *r) {
81 //------------------------------------------------------------------
82 // Returns Bz (kG) at the point "r" .
83 //------------------------------------------------------------------
84 AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
85 if (!fld) return 0.5*kAlmost0Field;
86 Double_t bz = fld->GetBz(r);
87 return TMath::Sign(0.5*kAlmost0Field,bz) + bz;
90 //__________________________________________________________________________
91 void AliTrackerBase::GetBxByBz(const Double_t r[3], Double_t b[3]) {
92 //------------------------------------------------------------------
93 // Returns Bx, By and Bz (kG) at the point "r" .
94 //------------------------------------------------------------------
95 AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
98 b[2] = 0.5*kAlmost0Field;
102 if (fld->IsUniform()) {
104 b[2] = fld->SolenoidField();
108 b[2] = (TMath::Sign(0.5*kAlmost0Field,b[2]) + b[2]);
112 Double_t AliTrackerBase::MeanMaterialBudget(const Double_t *start, const Double_t *end, Double_t *mparam)
115 // Calculate mean material budget and material properties between
116 // the points "start" and "end".
118 // "mparam" - parameters used for the energy and multiple scattering
121 // mparam[0] - mean density: sum(x_i*rho_i)/sum(x_i) [g/cm3]
122 // mparam[1] - equivalent rad length fraction: sum(x_i/X0_i) [adimensional]
123 // mparam[2] - mean A: sum(x_i*A_i)/sum(x_i) [adimensional]
124 // mparam[3] - mean Z: sum(x_i*Z_i)/sum(x_i) [adimensional]
125 // mparam[4] - length: sum(x_i) [cm]
126 // mparam[5] - Z/A mean: sum(x_i*Z_i/A_i)/sum(x_i) [adimensional]
127 // mparam[6] - number of boundary crosses
129 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
131 // Corrections and improvements by
132 // Andrea Dainese, Andrea.Dainese@lnl.infn.it,
133 // Andrei Gheata, Andrei.Gheata@cern.ch
136 mparam[0]=0; mparam[1]=1; mparam[2] =0; mparam[3] =0;
137 mparam[4]=0; mparam[5]=0; mparam[6]=0;
139 Double_t bparam[6]; // total parameters
140 Double_t lparam[6]; // local parameters
142 for (Int_t i=0;i<6;i++) bparam[i]=0;
145 AliErrorClass("No TGeo\n");
151 length = TMath::Sqrt((end[0]-start[0])*(end[0]-start[0])+
152 (end[1]-start[1])*(end[1]-start[1])+
153 (end[2]-start[2])*(end[2]-start[2]));
155 if (length<TGeoShape::Tolerance()) return 0.0;
156 Double_t invlen = 1./length;
157 dir[0] = (end[0]-start[0])*invlen;
158 dir[1] = (end[1]-start[1])*invlen;
159 dir[2] = (end[2]-start[2])*invlen;
161 // Initialize start point and direction
162 TGeoNode *currentnode = 0;
163 TGeoNode *startnode = gGeoManager->InitTrack(start, dir);
165 AliErrorClass(Form("start point out of geometry: x %f, y %f, z %f",
166 start[0],start[1],start[2]));
169 TGeoMaterial *material = startnode->GetVolume()->GetMedium()->GetMaterial();
170 lparam[0] = material->GetDensity();
171 lparam[1] = material->GetRadLen();
172 lparam[2] = material->GetA();
173 lparam[3] = material->GetZ();
175 lparam[5] = lparam[3]/lparam[2];
176 if (material->IsMixture()) {
177 TGeoMixture * mixture = (TGeoMixture*)material;
180 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
181 sum += mixture->GetWmixt()[iel];
182 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
187 // Locate next boundary within length without computing safety.
188 // Propagate either with length (if no boundary found) or just cross boundary
189 gGeoManager->FindNextBoundaryAndStep(length, kFALSE);
190 Double_t step = 0.0; // Step made
191 Double_t snext = gGeoManager->GetStep();
192 // If no boundary within proposed length, return current density
193 if (!gGeoManager->IsOnBoundary()) {
194 mparam[0] = lparam[0];
195 mparam[1] = lparam[4]/lparam[1];
196 mparam[2] = lparam[2];
197 mparam[3] = lparam[3];
198 mparam[4] = lparam[4];
201 // Try to cross the boundary and see what is next
203 while (length>TGeoShape::Tolerance()) {
204 currentnode = gGeoManager->GetCurrentNode();
205 if (snext<2.*TGeoShape::Tolerance()) nzero++;
208 // This means navigation has problems on one boundary
209 // Try to cross by making a small step
210 AliErrorClass("Cannot cross boundary\n");
211 mparam[0] = bparam[0]/step;
212 mparam[1] = bparam[1];
213 mparam[2] = bparam[2]/step;
214 mparam[3] = bparam[3]/step;
215 mparam[5] = bparam[5]/step;
217 mparam[0] = 0.; // if crash of navigation take mean density 0
218 mparam[1] = 1000000; // and infinite rad length
219 return bparam[0]/step;
223 bparam[1] += snext/lparam[1];
224 bparam[2] += snext*lparam[2];
225 bparam[3] += snext*lparam[3];
226 bparam[5] += snext*lparam[5];
227 bparam[0] += snext*lparam[0];
229 if (snext>=length) break;
230 if (!currentnode) break;
232 material = currentnode->GetVolume()->GetMedium()->GetMaterial();
233 lparam[0] = material->GetDensity();
234 lparam[1] = material->GetRadLen();
235 lparam[2] = material->GetA();
236 lparam[3] = material->GetZ();
237 lparam[5] = lparam[3]/lparam[2];
238 if (material->IsMixture()) {
239 TGeoMixture * mixture = (TGeoMixture*)material;
242 for (Int_t iel=0;iel<mixture->GetNelements();iel++){
243 sum+= mixture->GetWmixt()[iel];
244 lparam[5]+= mixture->GetZmixt()[iel]*mixture->GetWmixt()[iel]/mixture->GetAmixt()[iel];
248 gGeoManager->FindNextBoundaryAndStep(length, kFALSE);
249 snext = gGeoManager->GetStep();
251 mparam[0] = bparam[0]/step;
252 mparam[1] = bparam[1];
253 mparam[2] = bparam[2]/step;
254 mparam[3] = bparam[3]/step;
255 mparam[5] = bparam[5]/step;
256 return bparam[0]/step;
261 AliTrackerBase::PropagateTrackTo(AliExternalTrackParam *track, Double_t xToGo,
262 Double_t mass, Double_t maxStep, Bool_t rotateTo, Double_t maxSnp, Int_t sign, Bool_t addTimeStep, Bool_t correctMaterialBudget){
263 //----------------------------------------------------------------
265 // Propagates the track to the plane X=xk (cm) using the magnetic field map
266 // and correcting for the crossed material.
268 // mass - mass used in propagation - used for energy loss correction
269 // maxStep - maximal step for propagation
271 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
273 //----------------------------------------------------------------
274 const Double_t kEpsilon = 0.00001;
275 Double_t xpos = track->GetX();
276 Int_t dir = (xpos<xToGo) ? 1:-1;
278 while ( (xToGo-xpos)*dir > kEpsilon){
279 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
280 Double_t x = xpos+step;
281 Double_t xyz0[3],xyz1[3],param[7];
282 track->GetXYZ(xyz0); //starting global position
284 Double_t bz=GetBz(xyz0); // getting the local Bz
285 if (!track->GetXYZAt(x,bz,xyz1)) return kFALSE; // no prolongation
286 xyz1[2]+=kEpsilon; // waiting for bug correction in geo
288 if (maxSnp>0 && TMath::Abs(track->GetSnpAt(x,bz)) >= maxSnp) return kFALSE;
289 if (!track->PropagateTo(x,bz)) return kFALSE;
291 if (correctMaterialBudget){
292 MeanMaterialBudget(xyz0,xyz1,param);
293 Double_t xrho=param[0]*param[4], xx0=param[1];
294 if (sign) {if (sign<0) xrho = -xrho;} // sign is imposed
295 else { // determine automatically the sign from direction
296 if (dir>0) xrho = -xrho; // outward should be negative
299 if (!track->CorrectForMeanMaterial(xx0,xrho,mass)) return kFALSE;
303 track->GetXYZ(xyz1); // global position
304 Double_t alphan = TMath::ATan2(xyz1[1], xyz1[0]);
306 if (TMath::Abs(track->GetSnp()) >= maxSnp) return kFALSE;
309 Double_t ca=TMath::Cos(alphan-track->GetAlpha()), sa=TMath::Sin(alphan-track->GetAlpha());
310 Double_t sf=track->GetSnp(), cf=TMath::Sqrt((1.-sf)*(1.+sf));
311 Double_t sinNew = sf*ca - cf*sa;
312 if (TMath::Abs(sinNew) >= maxSnp) return kFALSE;
315 if (!track->AliExternalTrackParam::Rotate(alphan)) return kFALSE;
318 xpos = track->GetX();
319 if (addTimeStep && track->IsStartedTimeIntegral()) {
320 if (!rotateTo) track->GetXYZ(xyz1); // if rotateTo==kTRUE, then xyz1 is already extracted
321 Double_t dX=xyz0[0]-xyz1[0],dY=xyz0[1]-xyz1[1],dZ=xyz0[2]-xyz1[2];
322 Double_t d=TMath::Sqrt(dX*dX + dY*dY + dZ*dZ);
323 if (sign) {if (sign>0) d = -d;} // step sign is imposed, positive means inward direction
324 else { // determine automatically the sign from direction
327 track->AddTimeStep(d);
333 Int_t AliTrackerBase::PropagateTrackTo2(AliExternalTrackParam *track, Double_t xToGo,
334 Double_t mass, Double_t maxStep, Bool_t rotateTo, Double_t maxSnp, Int_t sign, Bool_t addTimeStep, Bool_t correctMaterialBudget){
335 //----------------------------------------------------------------
337 // Propagates the track to the plane X=xk (cm) using the magnetic field map
338 // and correcting for the crossed material.
340 // mass - mass used in propagation - used for energy loss correction
341 // maxStep - maximal step for propagation
343 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
345 //----------------------------------------------------------------
346 const Double_t kEpsilon = 0.00001;
347 Double_t xpos = track->GetX();
348 Int_t dir = (xpos<xToGo) ? 1:-1;
350 while ( (xToGo-xpos)*dir > kEpsilon){
351 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
352 Double_t x = xpos+step;
353 Double_t xyz0[3],xyz1[3],param[7];
354 track->GetXYZ(xyz0); //starting global position
356 Double_t bz=GetBz(xyz0); // getting the local Bz
357 if (!track->GetXYZAt(x,bz,xyz1)) return -1; // no prolongation
358 xyz1[2]+=kEpsilon; // waiting for bug correction in geo
360 if (maxSnp>0 && TMath::Abs(track->GetSnpAt(x,bz)) >= maxSnp) return -2;
361 if (!track->PropagateTo(x,bz)) return -3;
363 if (correctMaterialBudget){
364 MeanMaterialBudget(xyz0,xyz1,param);
365 Double_t xrho=param[0]*param[4], xx0=param[1];
366 if (sign) {if (sign<0) xrho = -xrho;} // sign is imposed
367 else { // determine automatically the sign from direction
368 if (dir>0) xrho = -xrho; // outward should be negative
371 if (!track->CorrectForMeanMaterial(xx0,xrho,mass)) return -4;
375 track->GetXYZ(xyz1); // global position
376 Double_t alphan = TMath::ATan2(xyz1[1], xyz1[0]);
378 if (TMath::Abs(track->GetSnp()) >= maxSnp) return -5;
381 Double_t ca=TMath::Cos(alphan-track->GetAlpha()), sa=TMath::Sin(alphan-track->GetAlpha());
382 Double_t sf=track->GetSnp(), cf=TMath::Sqrt((1.-sf)*(1.+sf));
383 Double_t sinNew = sf*ca - cf*sa;
384 if (TMath::Abs(sinNew) >= maxSnp) return -6;
387 if (!track->AliExternalTrackParam::Rotate(alphan)) return -7;
390 xpos = track->GetX();
391 if (addTimeStep && track->IsStartedTimeIntegral()) {
392 if (!rotateTo) track->GetXYZ(xyz1); // if rotateTo==kTRUE, then xyz1 is already extracted
393 Double_t dX=xyz0[0]-xyz1[0],dY=xyz0[1]-xyz1[1],dZ=xyz0[2]-xyz1[2];
394 Double_t d=TMath::Sqrt(dX*dX + dY*dY + dZ*dZ);
395 if (sign) {if (sign>0) d = -d;} // step sign is imposed, positive means inward direction
396 else { // determine automatically the sign from direction
399 track->AddTimeStep(d);
406 AliTrackerBase::PropagateTrackToBxByBz(AliExternalTrackParam *track,
407 Double_t xToGo,Double_t mass, Double_t maxStep, Bool_t rotateTo, Double_t maxSnp,Int_t sign, Bool_t addTimeStep){
408 //----------------------------------------------------------------
410 // Propagates the track to the plane X=xk (cm)
411 // taking into account all the three components of the magnetic field
412 // and correcting for the crossed material.
414 // mass - mass used in propagation - used for energy loss correction
415 // maxStep - maximal step for propagation
417 // Origin: Marian Ivanov, Marian.Ivanov@cern.ch
419 //----------------------------------------------------------------
420 const Double_t kEpsilon = 0.00001;
421 Double_t xpos = track->GetX();
422 Int_t dir = (xpos<xToGo) ? 1:-1;
424 while ( (xToGo-xpos)*dir > kEpsilon){
425 Double_t step = dir*TMath::Min(TMath::Abs(xToGo-xpos), maxStep);
426 Double_t x = xpos+step;
427 Double_t xyz0[3],xyz1[3],param[7];
428 track->GetXYZ(xyz0); //starting global position
430 Double_t b[3]; GetBxByBz(xyz0,b); // getting the local Bx, By and Bz
432 if (!track->GetXYZAt(x,b[2],xyz1)) return kFALSE; // no prolongation
433 xyz1[2]+=kEpsilon; // waiting for bug correction in geo
435 if (maxSnp>0 && TMath::Abs(track->GetSnpAt(x,b[2])) >= maxSnp) return kFALSE;
436 if (!track->PropagateToBxByBz(x,b)) return kFALSE;
438 MeanMaterialBudget(xyz0,xyz1,param);
439 Double_t xrho=param[0]*param[4], xx0=param[1];
440 if (sign) {if (sign<0) xrho = -xrho;} // sign is imposed
441 else { // determine automatically the sign from direction
442 if (dir>0) xrho = -xrho; // outward should be negative
445 if (!track->CorrectForMeanMaterial(xx0,xrho,mass)) return kFALSE;
447 track->GetXYZ(xyz1); // global position
448 Double_t alphan = TMath::ATan2(xyz1[1], xyz1[0]);
450 if (TMath::Abs(track->GetSnp()) >= maxSnp) return kFALSE;
451 Double_t ca=TMath::Cos(alphan-track->GetAlpha()), sa=TMath::Sin(alphan-track->GetAlpha());
452 Double_t sf=track->GetSnp(), cf=TMath::Sqrt((1.-sf)*(1.+sf));
453 Double_t sinNew = sf*ca - cf*sa;
454 if (TMath::Abs(sinNew) >= maxSnp) return kFALSE;
456 if (!track->AliExternalTrackParam::Rotate(alphan)) return kFALSE;
458 xpos = track->GetX();
459 if (addTimeStep && track->IsStartedTimeIntegral()) {
460 if (!rotateTo) track->GetXYZ(xyz1); // if rotateTo==kTRUE, then xyz1 is already extracted
461 Double_t dX=xyz0[0]-xyz1[0],dY=xyz0[1]-xyz1[1],dZ=xyz0[2]-xyz1[2];
462 Double_t d=TMath::Sqrt(dX*dX + dY*dY + dZ*dZ);
463 if (sign) {if (sign>0) d = -d;} // step sign is imposed, positive means inward direction
464 else { // determine automatically the sign from direction
467 track->AddTimeStep(d);
473 Double_t AliTrackerBase::GetTrackPredictedChi2(AliExternalTrackParam *track,
474 Double_t mass, Double_t step,
475 const AliExternalTrackParam *backup) {
477 // This function brings the "track" with particle "mass" [GeV]
478 // to the same local coord. system and the same reference plane as
479 // of the "backup", doing it in "steps" [cm].
480 // Then, it calculates the 5D predicted Chi2 for these two tracks
482 Double_t chi2=kVeryBig;
483 Double_t alpha=backup->GetAlpha();
484 if (!track->Rotate(alpha)) return chi2;
486 Double_t xb=backup->GetX();
487 Double_t sign=(xb < track->GetX()) ? 1. : -1.;
488 if (!PropagateTrackTo(track,xb,mass,step,kFALSE,kAlmost1,sign)) return chi2;
490 chi2=track->GetPredictedChi2(backup);
498 Double_t AliTrackerBase::MakeC(Double_t x1,Double_t y1,
499 Double_t x2,Double_t y2,
500 Double_t x3,Double_t y3)
502 //-----------------------------------------------------------------
503 // Initial approximation of the track curvature
504 //-----------------------------------------------------------------
510 Double_t det = x3*y2-x2*y3;
511 if (TMath::Abs(det)<1e-10) {
515 Double_t u = 0.5* (x2*(x2-x3)+y2*(y2-y3))/det;
516 Double_t x0 = x3*0.5-y3*u;
517 Double_t y0 = y3*0.5+x3*u;
518 Double_t c2 = 1/TMath::Sqrt(x0*x0+y0*y0);
523 Double_t AliTrackerBase::MakeSnp(Double_t x1,Double_t y1,
524 Double_t x2,Double_t y2,
525 Double_t x3,Double_t y3)
527 //-----------------------------------------------------------------
528 // Initial approximation of the track snp
529 //-----------------------------------------------------------------
535 Double_t det = x3*y2-x2*y3;
536 if (TMath::Abs(det)<1e-10) {
540 Double_t u = 0.5* (x2*(x2-x3)+y2*(y2-y3))/det;
541 Double_t x0 = x3*0.5-y3*u;
542 Double_t y0 = y3*0.5+x3*u;
543 Double_t c2 = 1./TMath::Sqrt(x0*x0+y0*y0);
546 if (y2*x2<0.) x0*=-1;
550 Double_t AliTrackerBase::MakeTgl(Double_t x1,Double_t y1,
551 Double_t x2,Double_t y2,
552 Double_t z1,Double_t z2, Double_t c)
554 //-----------------------------------------------------------------
555 // Initial approximation of the tangent of the track dip angle
556 //-----------------------------------------------------------------
558 const Double_t kEpsilon =0.00001;
562 Double_t d = TMath::Sqrt(x2*x2+y2*y2); // distance straight line
563 if (TMath::Abs(d*c*0.5)>1) return 0;
564 Double_t angle2 = TMath::ASin(d*c*0.5);
565 if (TMath::Abs(angle2)>kEpsilon) {
566 angle2 = z2*TMath::Abs(c/(angle2*2.));
574 Double_t AliTrackerBase::MakeTgl(Double_t x1,Double_t y1,
575 Double_t x2,Double_t y2,
576 Double_t z1,Double_t z2)
578 //-----------------------------------------------------------------
579 // Initial approximation of the tangent of the track dip angle
580 //-----------------------------------------------------------------
581 return (z1 - z2)/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
585 AliExternalTrackParam * AliTrackerBase::MakeSeed( AliTrackPoint &point0, AliTrackPoint &point1, AliTrackPoint &point2){
587 // Make Seed - AliExternalTrackParam from input 3 points
588 // returning seed in local frame of point0
590 Double_t xyz0[3]={0,0,0};
591 Double_t xyz1[3]={0,0,0};
592 Double_t xyz2[3]={0,0,0};
593 Double_t alpha=point0.GetAngle();
594 Double_t xyz[3]={point0.GetX(),point0.GetY(),point0.GetZ()};
595 Double_t bxyz[3]; GetBxByBz(xyz,bxyz);
596 Double_t bz = bxyz[2];
598 // get points in frame of point 0
600 AliTrackPoint p0r = point0.Rotate(alpha);
601 AliTrackPoint p1r = point1.Rotate(alpha);
602 AliTrackPoint p2r = point2.Rotate(alpha);
613 // make covariance estimate
616 Double_t param[5]={0,0,0,0,0};
617 for (Int_t m=0; m<15; m++) covar[m]=0;
619 // calculate intitial param
622 param[2]=MakeSnp(xyz0[0],xyz0[1],xyz1[0],xyz1[1],xyz2[0],xyz2[1]);
623 param[4]=MakeC(xyz0[0],xyz0[1],xyz1[0],xyz1[1],xyz2[0],xyz2[1]);
624 param[3]=MakeTgl(xyz0[0],xyz0[1],xyz1[0],xyz1[1],xyz0[2],xyz1[2],param[4]);
626 //covariance matrix - only diagonal elements
627 //Double_t dist=p0r.GetX()-p2r.GetX();
629 covar[0]= p0r.GetCov()[3];
630 covar[2]= p0r.GetCov()[5];
632 deltaP= (MakeSnp(xyz0[0],xyz0[1]+TMath::Sqrt(p0r.GetCov()[3]),xyz1[0],xyz1[1],xyz2[0],xyz2[1])-param[2]);
633 covar[5]+= deltaP*deltaP;
634 deltaP= (MakeSnp(xyz0[0],xyz0[1],xyz1[0],xyz1[1]+TMath::Sqrt(p1r.GetCov()[3]),xyz2[0],xyz2[1])-param[2]);
635 covar[5]+= deltaP*deltaP;
636 deltaP= (MakeSnp(xyz0[0],xyz0[1],xyz1[0],xyz1[1],xyz2[0],xyz2[1]+TMath::Sqrt(p1r.GetCov()[3]))-param[2]);
637 covar[5]+= deltaP*deltaP;
640 deltaP=MakeTgl(xyz0[0],xyz0[1],xyz1[0],xyz1[1],xyz0[2]+TMath::Sqrt(p1r.GetCov()[5]),xyz1[2],param[4])-param[3];
641 covar[9]+= deltaP*deltaP;
642 deltaP=MakeTgl(xyz0[0],xyz0[1],xyz1[0],xyz1[1],xyz0[2],xyz1[2]+TMath::Sqrt(p1r.GetCov()[5]),param[4])-param[3];
643 covar[9]+= deltaP*deltaP;
646 deltaP=MakeC(xyz0[0],xyz0[1]+TMath::Sqrt(p0r.GetCov()[3]),xyz1[0],xyz1[1],xyz2[0],xyz2[1])-param[4];
647 covar[14]+= deltaP*deltaP;
648 deltaP=MakeC(xyz0[0],xyz0[1],xyz1[0],xyz1[1]+TMath::Sqrt(p1r.GetCov()[3]),xyz2[0],xyz2[1])-param[4];
649 covar[14]+= deltaP*deltaP;
650 deltaP=MakeC(xyz0[0],xyz0[1],xyz1[0],xyz1[1],xyz2[0],xyz2[1]+TMath::Sqrt(p2r.GetCov()[3]))-param[4];
651 covar[14]+= deltaP*deltaP;
653 covar[14]/=(bz*kB2C)*(bz*kB2C);
654 param[4]/=(bz*kB2C); // transform to 1/pt
655 AliExternalTrackParam * trackParam = new AliExternalTrackParam(xyz0[0],alpha,param, covar);
657 // consistency check -to put warnings here
658 // small disagrement once Track extrapolation used
659 // nice agreement in seeds with MC track parameters - problem in extrapoloation - to be fixed
661 Double_t y1,y2,z1,z2;
662 trackParam->GetYAt(xyz1[0],bz,y1);
663 trackParam->GetZAt(xyz1[0],bz,z1);
664 trackParam->GetYAt(xyz2[0],bz,y2);
665 trackParam->GetZAt(xyz2[0],bz,z2);
666 if (TMath::Abs(y1-xyz1[1])> TMath::Sqrt(p1r.GetCov()[3]*5)){
667 AliWarningClass("Seeding problem y1\n");
669 if (TMath::Abs(y2-xyz2[1])> TMath::Sqrt(p2r.GetCov()[3]*5)){
670 AliWarningClass("Seeding problem y2\n");
672 if (TMath::Abs(z1-xyz1[2])> TMath::Sqrt(p1r.GetCov()[5]*5)){
673 AliWarningClass("Seeding problem z1\n");
679 Double_t AliTrackerBase::FitTrack(AliExternalTrackParam * trackParam, AliTrackPointArray *pointArray, Double_t mass, Double_t maxStep){
681 // refit the track - trackParam using the points in point array
683 const Double_t kMaxSnp=0.99;
684 if (!trackParam) return 0;
685 Int_t npoints=pointArray->GetNPoints();
686 AliTrackPoint point,point2;
687 Double_t pointPos[2]={0,0};
688 Double_t pointCov[3]={0,0,0};
689 // choose coordinate frame
690 // in standard way the coordinate frame should be changed point by point
691 // Some problems with rotation observed
692 // rotate method of AliExternalTrackParam should be revisited
693 pointArray->GetPoint(point,0);
694 pointArray->GetPoint(point2,npoints-1);
695 Double_t alpha=TMath::ATan2(point.GetY()-point2.GetY(), point.GetX()-point2.GetX());
697 for (Int_t ipoint=npoints-1; ipoint>0; ipoint-=1){
698 pointArray->GetPoint(point,ipoint);
699 AliTrackPoint pr = point.Rotate(alpha);
700 trackParam->Rotate(alpha);
701 Bool_t status = PropagateTrackTo(trackParam,pr.GetX(),mass,maxStep,kFALSE,kMaxSnp);
703 AliWarningClass("Problem to propagate\n");
706 if (TMath::Abs(trackParam->GetSnp())>kMaxSnp){
707 AliWarningClass("sin(phi) > kMaxSnp \n");
710 pointPos[0]=pr.GetY();//local y
711 pointPos[1]=pr.GetZ();//local z
712 pointCov[0]=pr.GetCov()[3];//simay^2
713 pointCov[1]=pr.GetCov()[4];//sigmayz
714 pointCov[2]=pr.GetCov()[5];//sigmaz^2
715 trackParam->Update(pointPos,pointCov);
722 void AliTrackerBase::UpdateTrack(AliExternalTrackParam &track1, const AliExternalTrackParam &track2){
724 // Update track 1 with track 2
728 TMatrixD vecXk(5,1); // X vector
729 TMatrixD covXk(5,5); // X covariance
730 TMatrixD matHk(5,5); // vector to mesurement
731 TMatrixD measR(5,5); // measurement error
732 TMatrixD vecZk(5,1); // measurement
734 TMatrixD vecYk(5,1); // Innovation or measurement residual
735 TMatrixD matHkT(5,5);
736 TMatrixD matSk(5,5); // Innovation (or residual) covariance
737 TMatrixD matKk(5,5); // Optimal Kalman gain
738 TMatrixD mat1(5,5); // update covariance matrix
739 TMatrixD covXk2(5,5); //
740 TMatrixD covOut(5,5);
742 Double_t *param1=(Double_t*) track1.GetParameter();
743 Double_t *covar1=(Double_t*) track1.GetCovariance();
744 Double_t *param2=(Double_t*) track2.GetParameter();
745 Double_t *covar2=(Double_t*) track2.GetCovariance();
747 // copy data to the matrix
748 for (Int_t ipar=0; ipar<5; ipar++){
749 for (Int_t jpar=0; jpar<5; jpar++){
750 covXk(ipar,jpar) = covar1[track1.GetIndex(ipar, jpar)];
751 measR(ipar,jpar) = covar2[track2.GetIndex(ipar, jpar)];
755 vecXk(ipar,0) = param1[ipar];
756 vecZk(ipar,0) = param2[ipar];
765 vecYk = vecZk-matHk*vecXk; // Innovation or measurement residual
766 matHkT=matHk.T(); matHk.T();
767 matSk = (matHk*(covXk*matHkT))+measR; // Innovation (or residual) covariance
769 matKk = (covXk*matHkT)*matSk; // Optimal Kalman gain
770 vecXk += matKk*vecYk; // updated vector
771 covXk2 = (mat1-(matKk*matHk));
772 covOut = covXk2*covXk;
776 // copy from matrix to parameters
789 for (Int_t ipar=0; ipar<5; ipar++){
790 param1[ipar]= vecXk(ipar,0) ;
791 for (Int_t jpar=0; jpar<5; jpar++){
792 covar1[track1.GetIndex(ipar, jpar)]=covOut(ipar,jpar);