Return the most probable momentum if the magnetic field is too weak and the momentum...
[u/mrichter/AliRoot.git] / TRD / AliTRDtrack.cxx
CommitLineData
46d29e70 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
0fa7dfa7 16/* $Id$ */
46d29e70 17
a2cb5b3d 18#include <Riostream.h>
53c17fbf 19#include <TMath.h>
e1e6896f 20#include <TVector2.h>
46d29e70 21
53c17fbf 22#include "AliESDtrack.h"
46d29e70 23#include "AliTRDgeometry.h"
24#include "AliTRDcluster.h"
25#include "AliTRDtrack.h"
53c17fbf 26#include "AliTRDtracklet.h"
b3a5a838 27
46d29e70 28ClassImp(AliTRDtrack)
29
53c17fbf 30///////////////////////////////////////////////////////////////////////////////
31// //
32// Represents a reconstructed TRD track //
33// Local TRD Kalman track //
34// //
35///////////////////////////////////////////////////////////////////////////////
7ad19338 36
f146da82 37AliTRDtrack::AliTRDtrack():
38 AliKalmanTrack(),
39 fSeedLab(-1),
40 fdEdx(0),
41 fdEdxT(0),
42 fDE(0),
43 fAlpha(0),
44 fX(0),
45 fStopped(kFALSE),
46 fY(0),
47 fZ(0),
48 fE(0),
49 fT(0),
50 fC(0),
51 fCyy(1e10),
52 fCzy(0),
53 fCzz(1e10),
54 fCey(0),
55 fCez(0),
56 fCee(1e10),
57 fCty(0),
58 fCtz(0),
59 fCte(0),
60 fCtt(1e10),
61 fCcy(0),
62 fCcz(0),
63 fCce(0),
64 fCct(0),
65 fCcc(1e10),
66 fLhElectron(0),
67 fNWrong(0),
68 fNRotate(0),
69 fNCross(0),
70 fNExpected(0),
71 fNLast(0),
72 fNExpectedLast(0),
73 fNdedx(0),
74 fChi2Last(1e10),
75 fBackupTrack(0x0)
76
77{
78 for (Int_t i=0; i<kNplane; i++) {
6d45eaef 79 for (Int_t j=0; j<kNslice; j++) {
80 fdEdxPlane[i][j] = 0;
81 }
f146da82 82 fTimBinPlane[i] = -1;
83 }
84 for (UInt_t i=0; i<kMAXCLUSTERSPERTRACK; i++) {
85 fIndex[i] = 0;
86 fIndexBackup[i] = 0;
87 fdQdl[i] = 0;
88 }
89 for (Int_t i=0; i<3; i++) fBudget[i] = 0;
90}
6d45eaef 91
46d29e70 92//_____________________________________________________________________________
a819a5f7 93AliTRDtrack::AliTRDtrack(const AliTRDcluster *c, UInt_t index,
5443e65e 94 const Double_t xx[5], const Double_t cc[15],
7ad19338 95 Double_t xref, Double_t alpha) : AliKalmanTrack() {
46d29e70 96 //-----------------------------------------------------------------
97 // This is the main track constructor.
98 //-----------------------------------------------------------------
5443e65e 99
100 fSeedLab = -1;
46d29e70 101
102 fAlpha=alpha;
5443e65e 103 if (fAlpha<-TMath::Pi()) fAlpha += 2*TMath::Pi();
104 if (fAlpha>=TMath::Pi()) fAlpha -= 2*TMath::Pi();
105
46d29e70 106 fX=xref;
107
b3a5a838 108 fY=xx[0]; fZ=xx[1]; fE=xx[2]; fT=xx[3]; fC=xx[4];
c84a5e9e 109
110 SaveLocalConvConst();
46d29e70 111
112 fCyy=cc[0];
113 fCzy=cc[1]; fCzz=cc[2];
b3a5a838 114 fCey=cc[3]; fCez=cc[4]; fCee=cc[5];
115 fCty=cc[6]; fCtz=cc[7]; fCte=cc[8]; fCtt=cc[9];
b8dc2353 116 fCcy=cc[10]; fCcz=cc[11]; fCce=cc[12]; fCct=cc[13]; fCcc=cc[14];
117
5443e65e 118 fIndex[0]=index;
119 SetNumberOfClusters(1);
120
121 fdEdx=0.;
03b0452e 122 fdEdxT=0.;
3fad3d32 123 fDE=0.;
53c17fbf 124 for (Int_t i=0;i<kNplane;i++){
6d45eaef 125 for (Int_t j=0; j<kNslice; j++) {
126 fdEdxPlane[i][j] = 0;
127 }
128 fTimBinPlane[i] = -1;
eab5961e 129 }
a2b90f83 130
b3a5a838 131 fLhElectron = 0.0;
9c9d2487 132 fNWrong = 0;
133 fNRotate = 0;
3c625a9b 134 fStopped = 0;
4f1c04d3 135 fNCross =0;
136 fNLast =0;
137 fChi2Last=0;
138 fNExpected=0;
139 fNExpectedLast=0;
140 fNdedx=0;
5443e65e 141 Double_t q = TMath::Abs(c->GetQ());
a819a5f7 142 Double_t s = fX*fC - fE, t=fT;
5443e65e 143 if(s*s < 1) q *= TMath::Sqrt((1-s*s)/(1+t*t));
144
145 fdQdl[0] = q;
0d5b5c27 146
147 // initialisation [SR, GSI 18.02.2003] (i startd for 1)
53c17fbf 148 for(UInt_t i=1; i<kMAXCLUSTERSPERTRACK; i++) {
0d5b5c27 149 fdQdl[i] = 0;
150 fIndex[i] = 0;
53c17fbf 151 fIndexBackup[i] = 0; //backup indexes MI
0d5b5c27 152 }
03b0452e 153 for (Int_t i=0;i<3;i++) { fBudget[i]=0;};
53c17fbf 154
155 fBackupTrack = 0;
156
46d29e70 157}
158
159//_____________________________________________________________________________
53c17fbf 160AliTRDtrack::AliTRDtrack(const AliTRDtrack& t) : AliKalmanTrack(t)
161{
46d29e70 162 //
163 // Copy constructor.
164 //
b8dc2353 165
5443e65e 166 SetLabel(t.GetLabel());
167 fSeedLab=t.GetSeedLabel();
46d29e70 168
5443e65e 169 SetChi2(t.GetChi2());
46d29e70 170 fdEdx=t.fdEdx;
03b0452e 171 fdEdxT=t.fdEdxT;
3fad3d32 172 fDE=t.fDE;
53c17fbf 173 for (Int_t i=0;i<kNplane;i++){
6d45eaef 174 for (Int_t j=0; j<kNslice; j++) {
175 fdEdxPlane[i][j] = t.fdEdxPlane[i][j];
176 }
177 fTimBinPlane[i] = t.fTimBinPlane[i];
178 fTracklets[i] = t.fTracklets[i];
eab5961e 179 }
46d29e70 180
b3a5a838 181 fLhElectron = 0.0;
9c9d2487 182 fNWrong = t.fNWrong;
183 fNRotate = t.fNRotate;
3c625a9b 184 fStopped = t.fStopped;
4f1c04d3 185 fNCross = t.fNCross;
186 fNExpected = t.fNExpected;
187 fNExpectedLast = t.fNExpectedLast;
188 fNdedx = t.fNdedx;
189 fNLast = t.fNLast;
190 fChi2Last = t.fChi2Last;
191 fBackupTrack =0;
46d29e70 192 fAlpha=t.fAlpha;
193 fX=t.fX;
194
4f1c04d3 195
b8dc2353 196 fY=t.fY; fZ=t.fZ; fE=t.fE; fT=t.fT; fC=t.fC;
46d29e70 197
198 fCyy=t.fCyy;
199 fCzy=t.fCzy; fCzz=t.fCzz;
b3a5a838 200 fCey=t.fCey; fCez=t.fCez; fCee=t.fCee;
201 fCty=t.fCty; fCtz=t.fCtz; fCte=t.fCte; fCtt=t.fCtt;
b8dc2353 202 fCcy=t.fCcy; fCcz=t.fCcz; fCce=t.fCce; fCct=t.fCct; fCcc=t.fCcc;
46d29e70 203
5443e65e 204 Int_t n=t.GetNumberOfClusters();
205 SetNumberOfClusters(n);
206 for (Int_t i=0; i<n; i++) {
a819a5f7 207 fIndex[i]=t.fIndex[i];
46e2d86c 208 fIndexBackup[i]=t.fIndex[i]; // MI - backup indexes
a819a5f7 209 fdQdl[i]=t.fdQdl[i];
210 }
b8dc2353 211
0d5b5c27 212 // initialisation (i starts from n) [SR, GSI, 18.02.2003]
53c17fbf 213 for(UInt_t i=n; i<kMAXCLUSTERSPERTRACK; i++) {
0d5b5c27 214 fdQdl[i] = 0;
215 fIndex[i] = 0;
46e2d86c 216 fIndexBackup[i] = 0; //MI backup indexes
0d5b5c27 217 }
03b0452e 218 for (Int_t i=0;i<6;i++){
219 fTracklets[i] = t.fTracklets[i];
220 }
221 for (Int_t i=0;i<3;i++) { fBudget[i]=t.fBudget[i];};
5443e65e 222}
223
224//_____________________________________________________________________________
b3a5a838 225AliTRDtrack::AliTRDtrack(const AliKalmanTrack& t, Double_t alpha)
53c17fbf 226 :AliKalmanTrack(t)
227{
5443e65e 228 //
229 // Constructor from AliTPCtrack or AliITStrack .
230 //
231
232 SetLabel(t.GetLabel());
233 SetChi2(0.);
b8dc2353 234 SetMass(t.GetMass());
5443e65e 235 SetNumberOfClusters(0);
236
bbc6cd2c 237 fdEdx=t.GetPIDsignal();
aa504dc7 238 fDE = 0;
53c17fbf 239 for (Int_t i=0;i<kNplane;i++){
6d45eaef 240 for (Int_t j=0;j<kNslice;j++){
241 fdEdxPlane[i][j] = 0.0;
242 }
eab5961e 243 fTimBinPlane[i] = -1;
244 }
5443e65e 245
b3a5a838 246 fLhElectron = 0.0;
9c9d2487 247 fNWrong = 0;
248 fNRotate = 0;
3c625a9b 249 fStopped = 0;
4f1c04d3 250 fNExpected=0;
251 fNExpectedLast=0;
252 fNdedx =0;
253 fNCross =0;
254 fNLast =0;
255 fChi2Last =0;
256 fBackupTrack =0;
b3a5a838 257
5443e65e 258 fAlpha = alpha;
259 if (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
260 else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();
261
262 Double_t x, p[5]; t.GetExternalParameters(x,p);
263
264 fX=x;
265
b8dc2353 266 fY=p[0];
267 fZ=p[1];
c84a5e9e 268 fT=p[3]; x=GetLocalConvConst();
b3a5a838 269 fC=p[4]/x;
b8dc2353 270 fE=fC*fX - p[2];
5443e65e 271
272 //Conversion of the covariance matrix
273 Double_t c[15]; t.GetExternalCovariance(c);
79e94bf8 274
275 c[10]/=x; c[11]/=x; c[12]/=x; c[13]/=x; c[14]/=x*x;
276
277 Double_t c22=fX*fX*c[14] - 2*fX*c[12] + c[5];
278 Double_t c32=fX*c[13] - c[8];
279 Double_t c20=fX*c[10] - c[3], c21=fX*c[11] - c[4], c42=fX*c[14] - c[12];
280
281 fCyy=c[0 ];
282 fCzy=c[1 ]; fCzz=c[2 ];
283 fCey=c20; fCez=c21; fCee=c22;
284 fCty=c[6 ]; fCtz=c[7 ]; fCte=c32; fCtt=c[9 ];
285 fCcy=c[10]; fCcz=c[11]; fCce=c42; fCct=c[13]; fCcc=c[14];
286
287 // Initialization [SR, GSI, 18.02.2003]
53c17fbf 288 for(UInt_t i=0; i<kMAXCLUSTERSPERTRACK; i++) {
79e94bf8 289 fdQdl[i] = 0;
290 fIndex[i] = 0;
46e2d86c 291 fIndexBackup[i] = 0; // MI backup indexes
79e94bf8 292 }
4f1c04d3 293
03b0452e 294 for (Int_t i=0;i<3;i++) { fBudget[i]=0;};
79e94bf8 295}
53c17fbf 296
79e94bf8 297//_____________________________________________________________________________
298AliTRDtrack::AliTRDtrack(const AliESDtrack& t)
53c17fbf 299 :AliKalmanTrack()
300{
79e94bf8 301 //
302 // Constructor from AliESDtrack
303 //
53c17fbf 304
79e94bf8 305 SetLabel(t.GetLabel());
306 SetChi2(0.);
307 SetMass(t.GetMass());
1e9bb598 308 SetNumberOfClusters(t.GetTRDclusters(fIndex));
46e2d86c 309 Int_t ncl = t.GetTRDclusters(fIndexBackup);
53c17fbf 310 for (UInt_t i=ncl;i<kMAXCLUSTERSPERTRACK;i++) {
46e2d86c 311 fIndexBackup[i]=0;
312 fIndex[i] = 0; //MI store indexes
313 }
aa504dc7 314 fdEdx=t.GetTRDsignal();
315 fDE =0;
53c17fbf 316 for (Int_t i=0;i<kNplane;i++){
6d45eaef 317 for (Int_t j=0;j<kNslice;j++){
318 fdEdxPlane[i][j] = t.GetTRDsignals(i,j);
319 }
eab5961e 320 fTimBinPlane[i] = t.GetTRDTimBin(i);
321 }
79e94bf8 322
323 fLhElectron = 0.0;
324 fNWrong = 0;
3c625a9b 325 fStopped = 0;
79e94bf8 326 fNRotate = 0;
4f1c04d3 327 fNExpected =0;
328 fNExpectedLast=0;
329 fNdedx = 0;
330 fNCross =0;
331 fNLast =0;
332 fChi2Last =0;
333 fBackupTrack =0;
79e94bf8 334
335 fAlpha = t.GetAlpha();
336 if (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
337 else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();
338
339 Double_t x, p[5]; t.GetExternalParameters(x,p);
c5a8e3df 340 //Conversion of the covariance matrix
341 Double_t c[15]; t.GetExternalCovariance(c);
25cde026 342 if (t.GetStatus()&AliESDtrack::kTRDbackup){
c0b978f0 343 t.GetOuterExternalParameters(fAlpha,x,p);
c9ec41e8 344 t.GetOuterExternalCovariance(c);
f4e9508c 345 if (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
346 else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();
c5a8e3df 347 }
79e94bf8 348
349 fX=x;
350
79e94bf8 351 fY=p[0];
c84a5e9e 352 fZ=p[1]; SaveLocalConvConst();
353 fT=p[3]; x=GetLocalConvConst();
79e94bf8 354 fC=p[4]/x;
355 fE=fC*fX - p[2];
356
5443e65e 357
358 c[10]/=x; c[11]/=x; c[12]/=x; c[13]/=x; c[14]/=x*x;
359
360 Double_t c22=fX*fX*c[14] - 2*fX*c[12] + c[5];
361 Double_t c32=fX*c[13] - c[8];
362 Double_t c20=fX*c[10] - c[3], c21=fX*c[11] - c[4], c42=fX*c[14] - c[12];
363
b8dc2353 364 fCyy=c[0 ];
365 fCzy=c[1 ]; fCzz=c[2 ];
366 fCey=c20; fCez=c21; fCee=c22;
367 fCty=c[6 ]; fCtz=c[7 ]; fCte=c32; fCtt=c[9 ];
368 fCcy=c[10]; fCcz=c[11]; fCce=c42; fCct=c[13]; fCcc=c[14];
5443e65e 369
0d5b5c27 370 // Initialization [SR, GSI, 18.02.2003]
53c17fbf 371 for(UInt_t i=0; i<kMAXCLUSTERSPERTRACK; i++) {
0d5b5c27 372 fdQdl[i] = 0;
46e2d86c 373 // fIndex[i] = 0; //MI store indexes
0d5b5c27 374 }
c630aafd 375
03b0452e 376 for (Int_t i=0;i<3;i++) { fBudget[i]=0;};
c630aafd 377 if ((t.GetStatus()&AliESDtrack::kTIME) == 0) return;
378 StartTimeIntegral();
379 Double_t times[10]; t.GetIntegratedTimes(times); SetIntegratedTimes(times);
380 SetIntegratedLength(t.GetIntegratedLength());
381
16d9fbba 382}
383
53c17fbf 384//____________________________________________________________________________
385AliTRDtrack::~AliTRDtrack()
3fad3d32 386{
387 //
53c17fbf 388 // Destructor
389 //
3fad3d32 390
53c17fbf 391 if (fBackupTrack) delete fBackupTrack;
392 fBackupTrack = 0;
3fad3d32 393
53c17fbf 394}
395
396//____________________________________________________________________________
397AliTRDtrack &AliTRDtrack::operator=(const AliTRDtrack &t)
16d9fbba 398{
399 //
53c17fbf 400 // Assignment operator
16d9fbba 401 //
eab5961e 402
53c17fbf 403 fLhElectron = 0.0;
404 fNWrong = 0;
405 fStopped = 0;
406 fNRotate = 0;
407 fNExpected =0;
408 fNExpectedLast=0;
409 fNdedx = 0;
410 fNCross =0;
411 fNLast =0;
412 fChi2Last =0;
413 fBackupTrack =0;
414
415 fAlpha = t.GetAlpha();
416 if (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
417 else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();
418
419 return *this;
eab5961e 420
16d9fbba 421}
9c9d2487 422
53c17fbf 423//____________________________________________________________________________
424Float_t AliTRDtrack::StatusForTOF()
7ad19338 425{
53c17fbf 426 //
427 // Defines the status of the TOF extrapolation
428 //
03b0452e 429
430 Float_t res = (0.2 + 0.8*(fN/(fNExpected+5.)))*(0.4+0.6*fTracklets[5].GetN()/20.);
431 res *= (0.25+0.8*40./(40.+fBudget[2]));
432 return res;
433
4f1c04d3 434 Int_t status=0;
435 if (GetNumberOfClusters()<20) return 0; //
c84a5e9e 436 if (fN>110&&fChi2/(Float_t(fN))<3) return 3; //gold
437 if (fNLast>30&&fChi2Last/(Float_t(fNLast))<3) return 3; //gold
438 if (fNLast>20&&fChi2Last/(Float_t(fNLast))<2) return 3; //gold
439 if (fNLast/(fNExpectedLast+3.)>0.8 && fChi2Last/Float_t(fNLast)<5&&fNLast>20) return 2; //silber
440 if (fNLast>5 &&((fNLast+1.)/(fNExpectedLast+1.))>0.8&&fChi2Last/(fNLast-5.)<6) return 1;
53c17fbf 441
4f1c04d3 442 return status;
53c17fbf 443
4f1c04d3 444}
445
5443e65e 446//_____________________________________________________________________________
53c17fbf 447void AliTRDtrack::GetExternalCovariance(Double_t cc[15]) const
448{
5443e65e 449 //
450 // This function returns external representation of the covriance matrix.
451 //
53c17fbf 452
c84a5e9e 453 Double_t a=GetLocalConvConst();
5443e65e 454
b3a5a838 455 Double_t c22=fX*fX*fCcc-2*fX*fCce+fCee;
456 Double_t c32=fX*fCct-fCte;
457 Double_t c20=fX*fCcy-fCey, c21=fX*fCcz-fCez, c42=fX*fCcc-fCce;
5443e65e 458
459 cc[0 ]=fCyy;
460 cc[1 ]=fCzy; cc[2 ]=fCzz;
461 cc[3 ]=c20; cc[4 ]=c21; cc[5 ]=c22;
462 cc[6 ]=fCty; cc[7 ]=fCtz; cc[8 ]=c32; cc[9 ]=fCtt;
b8dc2353 463 cc[10]=fCcy*a; cc[11]=fCcz*a; cc[12]=c42*a; cc[13]=fCct*a; cc[14]=fCcc*a*a;
464
5443e65e 465}
466
46d29e70 467//_____________________________________________________________________________
53c17fbf 468void AliTRDtrack::GetCovariance(Double_t cc[15]) const
469{
470 //
471 // Returns the track covariance matrix
472 //
b8dc2353 473
46d29e70 474 cc[0]=fCyy;
475 cc[1]=fCzy; cc[2]=fCzz;
b3a5a838 476 cc[3]=fCey; cc[4]=fCez; cc[5]=fCee;
477 cc[6]=fCcy; cc[7]=fCcz; cc[8]=fCce; cc[9]=fCcc;
478 cc[10]=fCty; cc[11]=fCtz; cc[12]=fCte; cc[13]=fCct; cc[14]=fCtt;
b8dc2353 479
46d29e70 480}
481
482//_____________________________________________________________________________
53c17fbf 483Int_t AliTRDtrack::Compare(const TObject *o) const
484{
485 //
486 // Compares tracks according to their Y2 or curvature
487 //
46d29e70 488
489 AliTRDtrack *t=(AliTRDtrack*)o;
490 // Double_t co=t->GetSigmaY2();
491 // Double_t c =GetSigmaY2();
492
493 Double_t co=TMath::Abs(t->GetC());
494 Double_t c =TMath::Abs(GetC());
495
53c17fbf 496 if (c>co) return 1;
46d29e70 497 else if (c<co) return -1;
498 return 0;
53c17fbf 499
46d29e70 500}
501
a819a5f7 502//_____________________________________________________________________________
503void AliTRDtrack::CookdEdx(Double_t low, Double_t up) {
504 //-----------------------------------------------------------------
505 // Calculates dE/dX within the "low" and "up" cuts.
506 //-----------------------------------------------------------------
5443e65e 507
a819a5f7 508 Int_t i;
4f1c04d3 509 //Int_t nc=GetNumberOfClusters();
510 Int_t nc=fNdedx;
511 if (nc<10) {
512 SetdEdx(0);
513 return;
514 }
a819a5f7 515
53c17fbf 516 Float_t sorted[kMAXCLUSTERSPERTRACK];
5443e65e 517 for (i=0; i < nc; i++) {
c84a5e9e 518 sorted[i]=fdQdl[i];
5443e65e 519 }
a819a5f7 520 Int_t nl=Int_t(low*nc), nu=Int_t(up*nc);
521 Float_t dedx=0;
c84a5e9e 522 //for (i=nl; i<=nu; i++) dedx += sorted[i];
523 //dedx /= (nu-nl+1);
524 for (i=0; i<nc; i++) dedx += sorted[i]; // ADDED by PS
525 if((nu-nl)) dedx /= (nu-nl); // ADDED by PS
5443e65e 526
3551db50 527 //SetdEdx(dedx);
03b0452e 528 //
529 // now real truncated mean
530 for (i=0; i < nc; i++) {
531 sorted[i]=TMath::Abs(fdQdl[i]);
532 }
533 Int_t * index = new Int_t[nc];
534 TMath::Sort(nc, sorted, index,kFALSE);
535 dedx=0;
536 for (i=nl; i<=nu; i++) dedx += sorted[index[i]];
537 dedx /= (nu-nl+1);
538 fdEdxT = dedx;
539 delete [] index;
3551db50 540 SetdEdx(dedx);
541
a819a5f7 542}
543
46d29e70 544//_____________________________________________________________________________
b3a5a838 545Int_t AliTRDtrack::PropagateTo(Double_t xk,Double_t x0,Double_t rho)
46d29e70 546{
547 // Propagates a track of particle with mass=pm to a reference plane
548 // defined by x=xk through media of density=rho and radiationLength=x0
549
9c9d2487 550 if (xk == fX) return 1;
551
3c625a9b 552 if (TMath::Abs(fC*xk - fE) >= 0.90000) {
553 // Int_t n=GetNumberOfClusters();
554 //if (n>4) cerr << n << " AliTRDtrack: Propagation failed, \tPt = "
555 // << GetPt() << "\t" << GetLabel() << "\t" << GetMass() << endl;
46d29e70 556 return 0;
557 }
c84a5e9e 558 Double_t lcc=GetLocalConvConst();
46d29e70 559
0d5b5c27 560 // track Length measurement [SR, GSI, 17.02.2003]
561 Double_t oldX = fX, oldY = fY, oldZ = fZ;
562
46d29e70 563 Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=fY, z1=fZ;
5443e65e 564 Double_t c1=fC*x1 - fE;
565 if((c1*c1) > 1) return 0;
566 Double_t r1=sqrt(1.- c1*c1);
b8dc2353 567 Double_t c2=fC*x2 - fE;
5443e65e 568 if((c2*c2) > 1) return 0;
569 Double_t r2=sqrt(1.- c2*c2);
46d29e70 570
571 fY += dx*(c1+c2)/(r1+r2);
572 fZ += dx*(c1+c2)/(c1*r2 + c2*r1)*fT;
573
574 //f = F - 1
575 Double_t rr=r1+r2, cc=c1+c2, xx=x1+x2;
b3a5a838 576 Double_t f02=-dx*(2*rr + cc*(c1/r1 + c2/r2))/(rr*rr);
577 Double_t f04= dx*(rr*xx + cc*(c1*x1/r1+c2*x2/r2))/(rr*rr);
46d29e70 578 Double_t cr=c1*r2+c2*r1;
b3a5a838 579 Double_t f12=-dx*fT*(2*cr + cc*(c2*c1/r1-r1 + c1*c2/r2-r2))/(cr*cr);
580 Double_t f13= dx*cc/cr;
b8dc2353 581 Double_t f14=dx*fT*(cr*xx-cc*(r1*x2-c2*c1*x1/r1+r2*x1-c1*c2*x2/r2))/(cr*cr);
46d29e70 582
583 //b = C*ft
b3a5a838 584 Double_t b00=f02*fCey + f04*fCcy, b01=f12*fCey + f14*fCcy + f13*fCty;
585 Double_t b10=f02*fCez + f04*fCcz, b11=f12*fCez + f14*fCcz + f13*fCtz;
586 Double_t b20=f02*fCee + f04*fCce, b21=f12*fCee + f14*fCce + f13*fCte;
587 Double_t b30=f02*fCte + f04*fCct, b31=f12*fCte + f14*fCct + f13*fCtt;
588 Double_t b40=f02*fCce + f04*fCcc, b41=f12*fCce + f14*fCcc + f13*fCct;
46d29e70 589
590 //a = f*b = f*C*ft
b3a5a838 591 Double_t a00=f02*b20+f04*b40,a01=f02*b21+f04*b41,a11=f12*b21+f14*b41+f13*b31;
46d29e70 592
593 //F*C*Ft = C + (a + b + bt)
594 fCyy += a00 + 2*b00;
595 fCzy += a01 + b01 + b10;
b3a5a838 596 fCey += b20;
597 fCty += b30;
598 fCcy += b40;
46d29e70 599 fCzz += a11 + 2*b11;
b3a5a838 600 fCez += b21;
601 fCtz += b31;
b8dc2353 602 fCcz += b41;
46d29e70 603
b8dc2353 604 fX=x2;
46d29e70 605
c84a5e9e 606 //Change of the magnetic field *************
607 SaveLocalConvConst();
608 cc=fC;
609 fC*=lcc/GetLocalConvConst();
610 fE+=fX*(fC-cc);
611
46d29e70 612 //Multiple scattering ******************
46d29e70 613 Double_t d=sqrt((x1-fX)*(x1-fX)+(y1-fY)*(y1-fY)+(z1-fZ)*(z1-fZ));
b8dc2353 614 Double_t p2=(1.+ GetTgl()*GetTgl())/(Get1Pt()*Get1Pt());
b3a5a838 615 Double_t beta2=p2/(p2 + GetMass()*GetMass());
b8dc2353 616 Double_t theta2=14.1*14.1/(beta2*p2*1e6)*d/x0*rho;
c84a5e9e 617
46d29e70 618 Double_t ey=fC*fX - fE, ez=fT;
619 Double_t xz=fC*ez, zz1=ez*ez+1, xy=fE+ey;
3c625a9b 620
46d29e70 621 fCee += (2*ey*ez*ez*fE+1-ey*ey+ez*ez+fE*fE*ez*ez)*theta2;
622 fCte += ez*zz1*xy*theta2;
623 fCtt += zz1*zz1*theta2;
b3a5a838 624 fCce += xz*ez*xy*theta2;
625 fCct += xz*zz1*theta2;
626 fCcc += xz*xz*theta2;
3c625a9b 627 /*
628 Double_t dc22 = (1-ey*ey+xz*xz*fX*fX)*theta2;
629 Double_t dc32 = (xz*fX*zz1)*theta2;
630 Double_t dc33 = (zz1*zz1)*theta2;
631 Double_t dc42 = (xz*fX*xz)*theta2;
632 Double_t dc43 = (zz1*xz)*theta2;
633 Double_t dc44 = (xz*xz)*theta2;
634 fCee += dc22;
635 fCte += dc32;
636 fCtt += dc33;
637 fCce += dc42;
638 fCct += dc43;
639 fCcc += dc44;
640 */
46d29e70 641 //Energy losses************************
b8dc2353 642 if((5940*beta2/(1-beta2+1e-10) - beta2) < 0) return 0;
5443e65e 643
c84a5e9e 644 Double_t dE=0.153e-3/beta2*(log(5940*beta2/(1-beta2+1e-10)) - beta2)*d*rho;
2276b464 645 Float_t budget = d* rho;
646 fBudget[0] +=budget;
96c3a73c 647 //
648 // suspicious part - think about it ?
649 Double_t kinE = TMath::Sqrt(p2);
650 if (dE>0.8*kinE) dE = 0.8*kinE; //
651 if (dE<0) dE = 0.0; // not valid region for Bethe bloch
652 //
653 //
3fad3d32 654 fDE+=dE;
b8dc2353 655 if (x1 < x2) dE=-dE;
656 cc=fC;
b3a5a838 657 fC*=(1.- sqrt(p2+GetMass()*GetMass())/p2*dE);
b8dc2353 658 fE+=fX*(fC-cc);
3fad3d32 659 // Double_t sigmade = 0.1*dE*TMath::Sqrt(TMath::Sqrt(1+fT*fT)*90./(d+0.0001)); // 20 percent fluctuation - normalized to some length
03b0452e 660 Double_t sigmade = 0.07*TMath::Sqrt(TMath::Abs(dE)); // energy loss fluctuation
3fad3d32 661 Double_t sigmac2 = sigmade*sigmade*fC*fC*(p2+GetMass()*GetMass())/(p2*p2);
662 fCcc += sigmac2;
663 fCee += fX*fX*sigmac2;
c84a5e9e 664
0d5b5c27 665 // track time measurement [SR, GSI 17.02.2002]
0fa7dfa7 666 if (x1 < x2)
0d5b5c27 667 if (IsStartedTimeIntegral()) {
03b0452e 668 Double_t l2 = TMath::Sqrt((fX-oldX)*(fX-oldX) + (fY-oldY)*(fY-oldY) + (fZ-oldZ)*(fZ-oldZ));
669 if (TMath::Abs(l2*fC)>0.0001){
670 // make correction for curvature if neccesary
671 l2 = 0.5*TMath::Sqrt((fX-oldX)*(fX-oldX) + (fY-oldY)*(fY-oldY));
672 l2 = 2*TMath::ASin(l2*fC)/fC;
673 l2 = TMath::Sqrt(l2*l2+(fZ-oldZ)*(fZ-oldZ));
674 }
675 AddTimeStep(l2);
0d5b5c27 676 }
677
b8dc2353 678 return 1;
6d45eaef 679
46d29e70 680}
681
46d29e70 682//_____________________________________________________________________________
53c17fbf 683Int_t AliTRDtrack::Update(const AliTRDcluster *c, Double_t chisq, UInt_t index
684 , Double_t h01)
46d29e70 685{
686 // Assignes found cluster to the track and updates track information
687
b8dc2353 688 Bool_t fNoTilt = kTRUE;
689 if(TMath::Abs(h01) > 0.003) fNoTilt = kFALSE;
46e2d86c 690 // add angular effect to the error contribution - MI
3c625a9b 691 Float_t tangent2 = (fC*fX-fE)*(fC*fX-fE);
692 if (tangent2 < 0.90000){
46e2d86c 693 tangent2 = tangent2/(1.-tangent2);
694 }
695 Float_t errang = tangent2*0.04; //
696 Float_t padlength = TMath::Sqrt(c->GetSigmaZ2()*12.);
fd621f36 697
46e2d86c 698 Double_t r00=c->GetSigmaY2() +errang, r01=0., r11=c->GetSigmaZ2()*100.;
b8dc2353 699 r00+=fCyy; r01+=fCzy; r11+=fCzz;
46d29e70 700 Double_t det=r00*r11 - r01*r01;
701 Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
702
b8dc2353 703 Double_t k00=fCyy*r00+fCzy*r01, k01=fCyy*r01+fCzy*r11;
704 Double_t k10=fCzy*r00+fCzz*r01, k11=fCzy*r01+fCzz*r11;
705 Double_t k20=fCey*r00+fCez*r01, k21=fCey*r01+fCez*r11;
706 Double_t k30=fCty*r00+fCtz*r01, k31=fCty*r01+fCtz*r11;
707 Double_t k40=fCcy*r00+fCcz*r01, k41=fCcy*r01+fCcz*r11;
46d29e70 708
709 Double_t dy=c->GetY() - fY, dz=c->GetZ() - fZ;
b3a5a838 710 Double_t cur=fC + k40*dy + k41*dz, eta=fE + k20*dy + k21*dz;
fd621f36 711
46d29e70 712
b8dc2353 713 if(fNoTilt) {
3c625a9b 714 if (TMath::Abs(cur*fX-eta) >= 0.90000) {
715 // Int_t n=GetNumberOfClusters();
716 //if (n>4) cerr<<n<<" AliTRDtrack warning: Filtering failed !\n";
b8dc2353 717 return 0;
718 }
719 fY += k00*dy + k01*dz;
720 fZ += k10*dy + k11*dz;
721 fE = eta;
9c9d2487 722 //fT += k30*dy + k31*dz;
b8dc2353 723 fC = cur;
724 }
725 else {
53c17fbf 726 Double_t xuFactor = 100.; // empirical factor set by C.Xu
b8dc2353 727 // in the first tilt version
46e2d86c 728 dy=c->GetY() - fY; dz=c->GetZ() - fZ;
729 dy=dy+h01*dz;
730 Float_t add=0;
731 if (TMath::Abs(dz)>padlength/2.){
3c625a9b 732 Float_t dy2 = c->GetY() - fY;
733 Float_t sign = (dz>0) ? -1.: 1.;
734 dy2+=h01*sign*padlength/2.;
735 dy = dy2;
736 add = 0;
46e2d86c 737 }
738
739
740
53c17fbf 741 r00=c->GetSigmaY2()+errang+add, r01=0., r11=c->GetSigmaZ2()*xuFactor;
b8dc2353 742 r00+=(fCyy+2.0*h01*fCzy+h01*h01*fCzz);
1299b231 743 r01+=(fCzy+h01*fCzz);
744 r11+=fCzz;
46e2d86c 745
b8dc2353 746 det=r00*r11 - r01*r01;
747 tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
748
749 k00=fCyy*r00+fCzy*(r01+h01*r00),k01=fCyy*r01+fCzy*(r11+h01*r01);
750 k10=fCzy*r00+fCzz*(r01+h01*r00),k11=fCzy*r01+fCzz*(r11+h01*r01);
751 k20=fCey*r00+fCez*(r01+h01*r00),k21=fCey*r01+fCez*(r11+h01*r01);
752 k30=fCty*r00+fCtz*(r01+h01*r00),k31=fCty*r01+fCtz*(r11+h01*r01);
753 k40=fCcy*r00+fCcz*(r01+h01*r00),k41=fCcy*r01+fCcz*(r11+h01*r01);
754
b8dc2353 755
756 cur=fC + k40*dy + k41*dz; eta=fE + k20*dy + k21*dz;
3c625a9b 757 if (TMath::Abs(cur*fX-eta) >= 0.90000) {
758 // Int_t n=GetNumberOfClusters();
759 //if (n>4) cerr<<n<<" AliTRDtrack warning: Filtering failed !\n";
b8dc2353 760 return 0;
761 }
762 fY += k00*dy + k01*dz;
763 fZ += k10*dy + k11*dz;
764 fE = eta;
46e2d86c 765 fT += k30*dy + k31*dz;
b8dc2353 766 fC = cur;
767
768 k01+=h01*k00;
769 k11+=h01*k10;
770 k21+=h01*k20;
771 k31+=h01*k30;
772 k41+=h01*k40;
46e2d86c 773
b8dc2353 774 }
46e2d86c 775 Double_t c01=fCzy, c02=fCey, c03=fCty, c04=fCcy;
776 Double_t c12=fCez, c13=fCtz, c14=fCcz;
777
b8dc2353 778
46d29e70 779 fCyy-=k00*fCyy+k01*fCzy; fCzy-=k00*c01+k01*fCzz;
b3a5a838 780 fCey-=k00*c02+k01*c12; fCty-=k00*c03+k01*c13;
781 fCcy-=k00*c04+k01*c14;
b8dc2353 782
46d29e70 783 fCzz-=k10*c01+k11*fCzz;
b3a5a838 784 fCez-=k10*c02+k11*c12; fCtz-=k10*c03+k11*c13;
785 fCcz-=k10*c04+k11*c14;
b8dc2353 786
b3a5a838 787 fCee-=k20*c02+k21*c12; fCte-=k20*c03+k21*c13;
788 fCce-=k20*c04+k21*c14;
b8dc2353 789
b3a5a838 790 fCtt-=k30*c03+k31*c13;
46e2d86c 791 fCct-=k40*c03+k41*c13;
792 //fCct-=k30*c04+k31*c14; // symmetric formula MI
b8dc2353 793
794 fCcc-=k40*c04+k41*c14;
46d29e70 795
b8dc2353 796 Int_t n=GetNumberOfClusters();
5443e65e 797 fIndex[n]=index;
b8dc2353 798 SetNumberOfClusters(n+1);
fd621f36 799
b8dc2353 800 SetChi2(GetChi2()+chisq);
46d29e70 801 // cerr<<"in update: fIndex["<<fN<<"] = "<<index<<endl;
5443e65e 802
b8dc2353 803 return 1;
53c17fbf 804
46d29e70 805}
53c17fbf 806
46e2d86c 807//_____________________________________________________________________________
3c625a9b 808Int_t AliTRDtrack::UpdateMI(const AliTRDcluster *c, Double_t chisq, UInt_t index, Double_t h01,
4f1c04d3 809 Int_t /*plane*/)
46e2d86c 810{
811 // Assignes found cluster to the track and updates track information
812
813 Bool_t fNoTilt = kTRUE;
814 if(TMath::Abs(h01) > 0.003) fNoTilt = kFALSE;
3c625a9b 815 // add angular effect to the error contribution and make correction - MI
c5a8e3df 816 //AliTRDclusterCorrection *corrector = AliTRDclusterCorrection::GetCorrection();
3c625a9b 817 //
818 Double_t tangent2 = (fC*fX-fE)*(fC*fX-fE);
819 if (tangent2 < 0.90000){
46e2d86c 820 tangent2 = tangent2/(1.-tangent2);
821 }
3c625a9b 822 Double_t tangent = TMath::Sqrt(tangent2);
823 if ((fC*fX-fE)<0) tangent*=-1;
c84a5e9e 824 // Double_t correction = 0*plane;
825 Double_t errang = tangent2*0.04; //
826 Double_t errsys =0.025*0.025*20; //systematic error part
827 Float_t extend =1;
828 if (c->GetNPads()==4) extend=2;
829 //if (c->GetNPads()==5) extend=3;
830 //if (c->GetNPads()==6) extend=3;
831 //if (c->GetQ()<15) return 1;
4f1c04d3 832
c5a8e3df 833 /*
3c625a9b 834 if (corrector!=0){
835 //if (0){
836 correction = corrector->GetCorrection(plane,c->GetLocalTimeBin(),tangent);
837 if (TMath::Abs(correction)>0){
838 //if we have info
839 errang = corrector->GetSigma(plane,c->GetLocalTimeBin(),tangent);
840 errang *= errang;
841 errang += tangent2*0.04;
842 }
843 }
c5a8e3df 844 */
3c625a9b 845 //
c84a5e9e 846 // Double_t padlength = TMath::Sqrt(c->GetSigmaZ2()*12.);
847
848 Double_t r00=(c->GetSigmaY2() +errang+errsys)*extend, r01=0., r11=c->GetSigmaZ2()*10000.;
46e2d86c 849 r00+=fCyy; r01+=fCzy; r11+=fCzz;
850 Double_t det=r00*r11 - r01*r01;
851 Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
852
853 Double_t k00=fCyy*r00+fCzy*r01, k01=fCyy*r01+fCzy*r11;
854 Double_t k10=fCzy*r00+fCzz*r01, k11=fCzy*r01+fCzz*r11;
855 Double_t k20=fCey*r00+fCez*r01, k21=fCey*r01+fCez*r11;
856 Double_t k30=fCty*r00+fCtz*r01, k31=fCty*r01+fCtz*r11;
857 Double_t k40=fCcy*r00+fCcz*r01, k41=fCcy*r01+fCcz*r11;
858
859 Double_t dy=c->GetY() - fY, dz=c->GetZ() - fZ;
860 Double_t cur=fC + k40*dy + k41*dz, eta=fE + k20*dy + k21*dz;
861
862
863 if(fNoTilt) {
3c625a9b 864 if (TMath::Abs(cur*fX-eta) >= 0.90000) {
865 // Int_t n=GetNumberOfClusters();
866 //if (n>4) cerr<<n<<" AliTRDtrack warning: Filtering failed !\n";
46e2d86c 867 return 0;
868 }
869 fY += k00*dy + k01*dz;
870 fZ += k10*dy + k11*dz;
871 fE = eta;
872 //fT += k30*dy + k31*dz;
873 fC = cur;
874 }
875 else {
c84a5e9e 876 Double_t padlength = TMath::Sqrt(c->GetSigmaZ2()*12);
4f1c04d3 877
53c17fbf 878 Double_t xuFactor = 1000.; // empirical factor set by C.Xu
46e2d86c 879 // in the first tilt version
880 dy=c->GetY() - fY; dz=c->GetZ() - fZ;
c84a5e9e 881 //dy=dy+h01*dz+correction;
4f1c04d3 882
883 Double_t tiltdz = dz;
c84a5e9e 884 if (TMath::Abs(tiltdz)>padlength/2.) {
885 tiltdz = TMath::Sign(padlength/2,dz);
886 }
887 // dy=dy+h01*dz;
4f1c04d3 888 dy=dy+h01*tiltdz;
889
c84a5e9e 890 Double_t add=0;
891 if (TMath::Abs(dz)>padlength/2.){
892 //Double_t dy2 = c->GetY() - fY;
893 //Double_t sign = (dz>0) ? -1.: 1.;
894 //dy2-=h01*sign*padlength/2.;
895 //dy = dy2;
896 add =1;
897 }
898 Double_t s00 = (c->GetSigmaY2()+errang)*extend+errsys+add; // error pad
53c17fbf 899 Double_t s11 = c->GetSigmaZ2()*xuFactor; // error pad-row
46e2d86c 900 //
901 r00 = fCyy + 2*fCzy*h01 + fCzz*h01*h01+s00;
902 r01 = fCzy + fCzz*h01;
903 r11 = fCzz + s11;
904 det = r00*r11 - r01*r01;
905 // inverse matrix
906 tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
907
908 // K matrix
909 k00=fCyy*r00+fCzy*(r01+h01*r00),k01=fCyy*r01+fCzy*(r11+h01*r01);
910 k10=fCzy*r00+fCzz*(r01+h01*r00),k11=fCzy*r01+fCzz*(r11+h01*r01);
911 k20=fCey*r00+fCez*(r01+h01*r00),k21=fCey*r01+fCez*(r11+h01*r01);
912 k30=fCty*r00+fCtz*(r01+h01*r00),k31=fCty*r01+fCtz*(r11+h01*r01);
913 k40=fCcy*r00+fCcz*(r01+h01*r00),k41=fCcy*r01+fCcz*(r11+h01*r01);
914 //
915 //Update measurement
916 cur=fC + k40*dy + k41*dz; eta=fE + k20*dy + k21*dz;
3c625a9b 917 if (TMath::Abs(cur*fX-eta) >= 0.90000) {
918 //Int_t n=GetNumberOfClusters();
919 // if (n>4) cerr<<n<<" AliTRDtrack warning: Filtering failed !\n";
46e2d86c 920 return 0;
921 }
922 fY += k00*dy + k01*dz;
923 fZ += k10*dy + k11*dz;
924 fE = eta;
925 fT += k30*dy + k31*dz;
926 fC = cur;
927
928 k01+=h01*k00;
929 k11+=h01*k10;
930 k21+=h01*k20;
931 k31+=h01*k30;
932 k41+=h01*k40;
933
934 }
935 //Update covariance
936 //
937 //
938 Double_t oldyy = fCyy, oldzz = fCzz; //, oldee=fCee, oldcc =fCcc;
939 Double_t oldzy = fCzy, oldey = fCey, oldty=fCty, oldcy =fCcy;
940 Double_t oldez = fCez, oldtz = fCtz, oldcz=fCcz;
941 //Double_t oldte = fCte, oldce = fCce;
942 //Double_t oldct = fCct;
943
944 fCyy-=k00*oldyy+k01*oldzy;
945 fCzy-=k10*oldyy+k11*oldzy;
946 fCey-=k20*oldyy+k21*oldzy;
947 fCty-=k30*oldyy+k31*oldzy;
948 fCcy-=k40*oldyy+k41*oldzy;
949 //
950 fCzz-=k10*oldzy+k11*oldzz;
951 fCez-=k20*oldzy+k21*oldzz;
952 fCtz-=k30*oldzy+k31*oldzz;
953 fCcz-=k40*oldzy+k41*oldzz;
954 //
955 fCee-=k20*oldey+k21*oldez;
956 fCte-=k30*oldey+k31*oldez;
957 fCce-=k40*oldey+k41*oldez;
958 //
959 fCtt-=k30*oldty+k31*oldtz;
960 fCct-=k40*oldty+k41*oldtz;
961 //
962 fCcc-=k40*oldcy+k41*oldcz;
963 //
964
965 Int_t n=GetNumberOfClusters();
966 fIndex[n]=index;
967 SetNumberOfClusters(n+1);
968
969 SetChi2(GetChi2()+chisq);
970 // cerr<<"in update: fIndex["<<fN<<"] = "<<index<<endl;
971
972 return 1;
7ad19338 973
53c17fbf 974}
7ad19338 975
7ad19338 976//_____________________________________________________________________________
977Int_t AliTRDtrack::UpdateMI(const AliTRDtracklet &tracklet)
978{
979 //
980 // Assignes found tracklet to the track and updates track information
981 //
982 //
983 Double_t r00=(tracklet.GetTrackletSigma2()), r01=0., r11= 10000.;
984 r00+=fCyy; r01+=fCzy; r11+=fCzz;
985 //
986 Double_t det=r00*r11 - r01*r01;
987 Double_t tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
988 //
989
990 Double_t dy=tracklet.GetY() - fY, dz=tracklet.GetZ() - fZ;
991
992
993 Double_t s00 = tracklet.GetTrackletSigma2(); // error pad
994 Double_t s11 = 100000; // error pad-row
995 Float_t h01 = tracklet.GetTilt();
996 //
997 // r00 = fCyy + 2*fCzy*h01 + fCzz*h01*h01+s00;
998 r00 = fCyy + fCzz*h01*h01+s00;
999 // r01 = fCzy + fCzz*h01;
1000 r01 = fCzy ;
1001 r11 = fCzz + s11;
1002 det = r00*r11 - r01*r01;
1003 // inverse matrix
1004 tmp=r00; r00=r11/det; r11=tmp/det; r01=-r01/det;
1005
1006 Double_t k00=fCyy*r00+fCzy*r01, k01=fCyy*r01+fCzy*r11;
1007 Double_t k10=fCzy*r00+fCzz*r01, k11=fCzy*r01+fCzz*r11;
1008 Double_t k20=fCey*r00+fCez*r01, k21=fCey*r01+fCez*r11;
1009 Double_t k30=fCty*r00+fCtz*r01, k31=fCty*r01+fCtz*r11;
1010 Double_t k40=fCcy*r00+fCcz*r01, k41=fCcy*r01+fCcz*r11;
1011
1012 // K matrix
1013// k00=fCyy*r00+fCzy*(r01+h01*r00),k01=fCyy*r01+fCzy*(r11+h01*r01);
1014// k10=fCzy*r00+fCzz*(r01+h01*r00),k11=fCzy*r01+fCzz*(r11+h01*r01);
1015// k20=fCey*r00+fCez*(r01+h01*r00),k21=fCey*r01+fCez*(r11+h01*r01);
1016// k30=fCty*r00+fCtz*(r01+h01*r00),k31=fCty*r01+fCtz*(r11+h01*r01);
1017// k40=fCcy*r00+fCcz*(r01+h01*r00),k41=fCcy*r01+fCcz*(r11+h01*r01);
1018 //
1019 //Update measurement
1020 Double_t cur=fC + k40*dy + k41*dz, eta=fE + k20*dy + k21*dz;
1021 // cur=fC + k40*dy + k41*dz; eta=fE + k20*dy + k21*dz;
1022 if (TMath::Abs(cur*fX-eta) >= 0.90000) {
1023 //Int_t n=GetNumberOfClusters();
1024 // if (n>4) cerr<<n<<" AliTRDtrack warning: Filtering failed !\n";
1025 return 0;
1026 }
1027// k01+=h01*k00;
1028// k11+=h01*k10;
1029// k21+=h01*k20;
1030// k31+=h01*k30;
1031// k41+=h01*k40;
1032
1033
1034 fY += k00*dy + k01*dz;
1035 fZ += k10*dy + k11*dz;
1036 fE = eta;
1037 fT += k30*dy + k31*dz;
1038 fC = cur;
1039
1040
1041 //Update covariance
1042 //
1043 //
1044 Double_t oldyy = fCyy, oldzz = fCzz; //, oldee=fCee, oldcc =fCcc;
1045 Double_t oldzy = fCzy, oldey = fCey, oldty=fCty, oldcy =fCcy;
1046 Double_t oldez = fCez, oldtz = fCtz, oldcz=fCcz;
1047 //Double_t oldte = fCte, oldce = fCce;
1048 //Double_t oldct = fCct;
1049
1050 fCyy-=k00*oldyy+k01*oldzy;
1051 fCzy-=k10*oldyy+k11*oldzy;
1052 fCey-=k20*oldyy+k21*oldzy;
1053 fCty-=k30*oldyy+k31*oldzy;
1054 fCcy-=k40*oldyy+k41*oldzy;
1055 //
1056 fCzz-=k10*oldzy+k11*oldzz;
1057 fCez-=k20*oldzy+k21*oldzz;
1058 fCtz-=k30*oldzy+k31*oldzz;
1059 fCcz-=k40*oldzy+k41*oldzz;
1060 //
1061 fCee-=k20*oldey+k21*oldez;
1062 fCte-=k30*oldey+k31*oldez;
1063 fCce-=k40*oldey+k41*oldez;
1064 //
1065 fCtt-=k30*oldty+k31*oldtz;
1066 fCct-=k40*oldty+k41*oldtz;
1067 //
1068 fCcc-=k40*oldcy+k41*oldcz;
1069 //
1070 /*
1071 Int_t n=GetNumberOfClusters();
1072 fIndex[n]=index;
1073 SetNumberOfClusters(n+1);
1074
1075 SetChi2(GetChi2()+chisq);
1076 // cerr<<"in update: fIndex["<<fN<<"] = "<<index<<endl;
1077 */
7ad19338 1078
53c17fbf 1079 return 1;
7ad19338 1080
53c17fbf 1081}
c84a5e9e 1082
46d29e70 1083//_____________________________________________________________________________
3fad3d32 1084Int_t AliTRDtrack::Rotate(Double_t alpha, Bool_t absolute)
46d29e70 1085{
1086 // Rotates track parameters in R*phi plane
3fad3d32 1087 // if absolute rotation alpha is in global system
1088 // otherwise alpha rotation is relative to the current rotation angle
9c9d2487 1089
3fad3d32 1090 if (absolute) {
1091 alpha -= fAlpha;
1092 }
1093 else{
1094 fNRotate++;
1095 }
46d29e70 1096
1097 fAlpha += alpha;
b3a5a838 1098 if (fAlpha<-TMath::Pi()) fAlpha += 2*TMath::Pi();
b8dc2353 1099 if (fAlpha>=TMath::Pi()) fAlpha -= 2*TMath::Pi();
46d29e70 1100
1101 Double_t x1=fX, y1=fY;
1102 Double_t ca=cos(alpha), sa=sin(alpha);
1103 Double_t r1=fC*fX - fE;
1104
1105 fX = x1*ca + y1*sa;
b8dc2353 1106 fY =-x1*sa + y1*ca;
1107 if((r1*r1) > 1) return 0;
46d29e70 1108 fE=fE*ca + (fC*y1 + sqrt(1.- r1*r1))*sa;
1109
1110 Double_t r2=fC*fX - fE;
3c625a9b 1111 if (TMath::Abs(r2) >= 0.90000) {
b8dc2353 1112 Int_t n=GetNumberOfClusters();
5443e65e 1113 if (n>4) cerr<<n<<" AliTRDtrack warning: Rotation failed !\n";
46d29e70 1114 return 0;
1115 }
1116
b8dc2353 1117 if((r2*r2) > 1) return 0;
46d29e70 1118 Double_t y0=fY + sqrt(1.- r2*r2)/fC;
1119 if ((fY-y0)*fC >= 0.) {
b8dc2353 1120 Int_t n=GetNumberOfClusters();
5443e65e 1121 if (n>4) cerr<<n<<" AliTRDtrack warning: Rotation failed !!!\n";
46d29e70 1122 return 0;
1123 }
1124
1125 //f = F - 1
b3a5a838 1126 Double_t f00=ca-1, f24=(y1 - r1*x1/sqrt(1.- r1*r1))*sa,
b8dc2353 1127 f20=fC*sa, f22=(ca + sa*r1/sqrt(1.- r1*r1))-1;
46d29e70 1128
1129 //b = C*ft
b3a5a838 1130 Double_t b00=fCyy*f00, b02=fCyy*f20+fCcy*f24+fCey*f22;
1131 Double_t b10=fCzy*f00, b12=fCzy*f20+fCcz*f24+fCez*f22;
1132 Double_t b20=fCey*f00, b22=fCey*f20+fCce*f24+fCee*f22;
1133 Double_t b30=fCty*f00, b32=fCty*f20+fCct*f24+fCte*f22;
1134 Double_t b40=fCcy*f00, b42=fCcy*f20+fCcc*f24+fCce*f22;
46d29e70 1135
1136 //a = f*b = f*C*ft
b3a5a838 1137 Double_t a00=f00*b00, a02=f00*b02, a22=f20*b02+f24*b42+f22*b22;
46d29e70 1138
46d29e70 1139 //F*C*Ft = C + (a + b + bt)
1140 fCyy += a00 + 2*b00;
1141 fCzy += b10;
b3a5a838 1142 fCey += a02+b20+b02;
1143 fCty += b30;
1144 fCcy += b40;
1145 fCez += b12;
1146 fCte += b32;
1147 fCee += a22 + 2*b22;
1148 fCce += b42;
46d29e70 1149
b8dc2353 1150 return 1;
46d29e70 1151
53c17fbf 1152}
7ad19338 1153
46d29e70 1154//_____________________________________________________________________________
fd621f36 1155Double_t AliTRDtrack::GetPredictedChi2(const AliTRDcluster *c, Double_t h01) const
46d29e70 1156{
53c17fbf 1157 //
1158 // Returns the track chi2
1159 //
1160
b8dc2353 1161 Bool_t fNoTilt = kTRUE;
1162 if(TMath::Abs(h01) > 0.003) fNoTilt = kFALSE;
1163 Double_t chi2, dy, r00, r01, r11;
1164
1165 if(fNoTilt) {
1166 dy=c->GetY() - fY;
1167 r00=c->GetSigmaY2();
1168 chi2 = (dy*dy)/r00;
46d29e70 1169 }
b8dc2353 1170 else {
4f1c04d3 1171 Double_t padlength = TMath::Sqrt(c->GetSigmaZ2()*12);
1172 //
b8dc2353 1173 r00=c->GetSigmaY2(); r01=0.; r11=c->GetSigmaZ2();
1174 r00+=fCyy; r01+=fCzy; r11+=fCzz;
1175
1176 Double_t det=r00*r11 - r01*r01;
1177 if (TMath::Abs(det) < 1.e-10) {
1178 Int_t n=GetNumberOfClusters();
1179 if (n>4) cerr<<n<<" AliTRDtrack warning: Singular matrix !\n";
1180 return 1e10;
1181 }
1182 Double_t tmp=r00; r00=r11; r11=tmp; r01=-r01;
1183 Double_t dy=c->GetY() - fY, dz=c->GetZ() - fZ;
4f1c04d3 1184 Double_t tiltdz = dz;
1185 if (TMath::Abs(tiltdz)>padlength/2.) {
1186 tiltdz = TMath::Sign(padlength/2,dz);
1187 }
1188 // dy=dy+h01*dz;
1189 dy=dy+h01*tiltdz;
a819a5f7 1190
b8dc2353 1191 chi2 = (dy*r00*dy + 2*r01*dy*dz + dz*r11*dz)/det;
1192 }
53c17fbf 1193
b8dc2353 1194 return chi2;
46d29e70 1195
53c17fbf 1196}
7ad19338 1197
46d29e70 1198//_________________________________________________________________________
1199void AliTRDtrack::GetPxPyPz(Double_t& px, Double_t& py, Double_t& pz) const
1200{
1201 // Returns reconstructed track momentum in the global system.
1202
1203 Double_t pt=TMath::Abs(GetPt()); // GeV/c
1204 Double_t r=fC*fX-fE;
5443e65e 1205
1206 Double_t y0;
1207 if(r > 1) { py = pt; px = 0; }
1208 else if(r < -1) { py = -pt; px = 0; }
1209 else {
1210 y0=fY + sqrt(1.- r*r)/fC;
1211 px=-pt*(fY-y0)*fC; //cos(phi);
1212 py=-pt*(fE-fX*fC); //sin(phi);
1213 }
46d29e70 1214 pz=pt*fT;
1215 Double_t tmp=px*TMath::Cos(fAlpha) - py*TMath::Sin(fAlpha);
1216 py=px*TMath::Sin(fAlpha) + py*TMath::Cos(fAlpha);
1217 px=tmp;
1218
1219}
1220
5443e65e 1221//_________________________________________________________________________
1222void AliTRDtrack::GetGlobalXYZ(Double_t& x, Double_t& y, Double_t& z) const
46d29e70 1223{
5443e65e 1224 // Returns reconstructed track coordinates in the global system.
1225
1226 x = fX; y = fY; z = fZ;
1227 Double_t tmp=x*TMath::Cos(fAlpha) - y*TMath::Sin(fAlpha);
1228 y=x*TMath::Sin(fAlpha) + y*TMath::Cos(fAlpha);
1229 x=tmp;
1230
1231}
3ab6f951 1232
5443e65e 1233//_________________________________________________________________________
53c17fbf 1234void AliTRDtrack::ResetCovariance()
1235{
5443e65e 1236 //
1237 // Resets covariance matrix
1238 //
46d29e70 1239
5443e65e 1240 fCyy*=10.;
b8dc2353 1241 fCzy=0.; fCzz*=10.;
1242 fCey=0.; fCez=0.; fCee*=10.;
1243 fCty=0.; fCtz=0.; fCte=0.; fCtt*=10.;
1244 fCcy=0.; fCcz=0.; fCce=0.; fCct=0.; fCcc*=10.;
53c17fbf 1245
5443e65e 1246}
b8dc2353 1247
53c17fbf 1248//_____________________________________________________________________________
1249void AliTRDtrack::ResetCovariance(Float_t mult)
1250{
46e2d86c 1251 //
1252 // Resets covariance matrix
1253 //
1254
1255 fCyy*=mult;
4f1c04d3 1256 fCzy*=0.; fCzz*=1.;
3c625a9b 1257 fCey*=0.; fCez*=0.; fCee*=mult;
4f1c04d3 1258 fCty*=0.; fCtz*=0.; fCte*=0.; fCtt*=1.;
3c625a9b 1259 fCcy*=0.; fCcz*=0.; fCce*=0.; fCct*=0.; fCcc*=mult;
7ad19338 1260
53c17fbf 1261}
7ad19338 1262
53c17fbf 1263//_____________________________________________________________________________
16d9fbba 1264void AliTRDtrack::MakeBackupTrack()
1265{
1266 //
53c17fbf 1267 // Creates a backup track
16d9fbba 1268 //
53c17fbf 1269
16d9fbba 1270 if (fBackupTrack) delete fBackupTrack;
1271 fBackupTrack = new AliTRDtrack(*this);
4f1c04d3 1272
1273}
1274
53c17fbf 1275//_____________________________________________________________________________
1276Int_t AliTRDtrack::GetProlongation(Double_t xk, Double_t &y, Double_t &z)
1277{
4f1c04d3 1278 //
1279 // Find prolongation at given x
1280 // return 0 if not exist
1281
1282 Double_t c1=fC*fX - fE;
c84a5e9e 1283 if (TMath::Abs(c1)>1.) return 0;
4f1c04d3 1284 Double_t r1=TMath::Sqrt(1.- c1*c1);
1285 Double_t c2=fC*xk - fE;
c84a5e9e 1286 if (TMath::Abs(c2)>1.) return 0;
4f1c04d3 1287 Double_t r2=TMath::Sqrt(1.- c2*c2);
1288 y =fY + (xk-fX)*(c1+c2)/(r1+r2);
1289 z =fZ + (xk-fX)*(c1+c2)/(c1*r2 + c2*r1)*fT;
1290
1291 return 1;
1292
16d9fbba 1293}
3fad3d32 1294
53c17fbf 1295//_____________________________________________________________________________
3fad3d32 1296Int_t AliTRDtrack::PropagateToX(Double_t xr, Double_t step)
1297{
1298 //
1299 // Propagate track to given x position
1300 // works inside of the 20 degree segmentation (local cooordinate frame for TRD , TPC, TOF)
1301 //
1302 // material budget from geo manager
1303 //
1304 Double_t xyz0[3], xyz1[3],y,z;
53c17fbf 1305 const Double_t kAlphac = TMath::Pi()/9.;
1306 const Double_t kTalphac = TMath::Tan(kAlphac*0.5);
3fad3d32 1307 // critical alpha - cross sector indication
1308 //
1309 Double_t dir = (fX>xr) ? -1.:1.;
1310 // direction +-
1311 for (Double_t x=fX+dir*step;dir*x<dir*xr;x+=dir*step){
1312 //
1313 GetGlobalXYZ(xyz0[0],xyz0[1],xyz0[2]);
1314 GetProlongation(x,y,z);
1315 xyz1[0] = x*TMath::Cos(fAlpha)+y*TMath::Sin(fAlpha);
1316 xyz1[1] = x*TMath::Sin(fAlpha)-y*TMath::Cos(fAlpha);
1317 xyz1[2] = z;
1318 Double_t param[7];
1319 AliKalmanTrack::MeanMaterialBudget(xyz0,xyz1,param);
1320 //
1321 if (param[0]>0&&param[1]>0) PropagateTo(x,param[1],param[0]);
53c17fbf 1322 if (fY>fX*kTalphac){
1323 Rotate(-kAlphac);
3fad3d32 1324 }
53c17fbf 1325 if (fY<-fX*kTalphac){
1326 Rotate(kAlphac);
3fad3d32 1327 }
1328 }
1329 //
1330 PropagateTo(xr);
53c17fbf 1331
3fad3d32 1332 return 0;
3fad3d32 1333
53c17fbf 1334}
3fad3d32 1335
53c17fbf 1336//_____________________________________________________________________________
3fad3d32 1337Int_t AliTRDtrack::PropagateToR(Double_t r,Double_t step)
1338{
1339 //
1340 // propagate track to the radial position
1341 // rotation always connected to the last track position
1342 //
1343 Double_t xyz0[3], xyz1[3],y,z;
1344 Double_t radius = TMath::Sqrt(fX*fX+fY*fY);
1345 Double_t dir = (radius>r) ? -1.:1.; // direction +-
1346 //
1347 for (Double_t x=radius+dir*step;dir*x<dir*r;x+=dir*step){
1348 GetGlobalXYZ(xyz0[0],xyz0[1],xyz0[2]);
1349 Double_t alpha = TMath::ATan2(xyz0[1],xyz0[0]);
1350 Rotate(alpha,kTRUE);
1351 GetGlobalXYZ(xyz0[0],xyz0[1],xyz0[2]);
1352 GetProlongation(x,y,z);
1353 xyz1[0] = x*TMath::Cos(alpha)+y*TMath::Sin(alpha);
1354 xyz1[1] = x*TMath::Sin(alpha)-y*TMath::Cos(alpha);
1355 xyz1[2] = z;
1356 Double_t param[7];
1357 AliKalmanTrack::MeanMaterialBudget(xyz0,xyz1,param);
1358 if (param[1]<=0) param[1] =100000000;
1359 PropagateTo(x,param[1],param[0]);
1360 }
1361 GetGlobalXYZ(xyz0[0],xyz0[1],xyz0[2]);
1362 Double_t alpha = TMath::ATan2(xyz0[1],xyz0[0]);
1363 Rotate(alpha,kTRUE);
1364 GetGlobalXYZ(xyz0[0],xyz0[1],xyz0[2]);
1365 GetProlongation(r,y,z);
1366 xyz1[0] = r*TMath::Cos(alpha)+y*TMath::Sin(alpha);
1367 xyz1[1] = r*TMath::Sin(alpha)-y*TMath::Cos(alpha);
1368 xyz1[2] = z;
1369 Double_t param[7];
1370 AliKalmanTrack::MeanMaterialBudget(xyz0,xyz1,param);
1371 //
1372 if (param[1]<=0) param[1] =100000000;
1373 PropagateTo(r,param[1],param[0]);
53c17fbf 1374
3fad3d32 1375 return 0;
53c17fbf 1376
1377}
1378
1379//_____________________________________________________________________________
4e28c495 1380Int_t AliTRDtrack::GetSector() const
53c17fbf 1381{
1382 //
1383 // Return the current sector
1384 //
1385
1386 return Int_t(TVector2::Phi_0_2pi(fAlpha)
1387 / AliTRDgeometry::GetAlpha())
1388 % AliTRDgeometry::kNsect;
1389
3fad3d32 1390}
1391
53c17fbf 1392//_____________________________________________________________________________
4e28c495 1393Double_t AliTRDtrack::Get1Pt() const
53c17fbf 1394{
5773defd 1395 //--------------------------------------------------------------
1396 // Returns the inverse Pt (1/GeV/c)
1397 // (or 1/"most probable pt", if the field is too weak)
1398 //--------------------------------------------------------------
1399 if (TMath::Abs(GetLocalConvConst()) > kVeryBigConvConst)
1400 return 1./kMostProbableMomentum/TMath::Sqrt(1.+ GetTgl()*GetTgl());
1401 return (TMath::Sign(1e-9,fC) + fC)*GetLocalConvConst();
53c17fbf 1402}
1403
1404//_____________________________________________________________________________
4e28c495 1405Double_t AliTRDtrack::GetP() const
53c17fbf 1406{
1407 //
1408 // Returns the total momentum
1409 //
1410
1411 return TMath::Abs(GetPt())*sqrt(1.+GetTgl()*GetTgl());
1412
1413}
1414
1415//_____________________________________________________________________________
4e28c495 1416Double_t AliTRDtrack::GetYat(Double_t xk) const
53c17fbf 1417{
1418 //
1419 // This function calculates the Y-coordinate of a track at
1420 // the plane x = xk.
1421 // Needed for matching with the TOF (I.Belikov)
1422 //
1423
1424 Double_t c1 = fC*fX - fE;
1425 Double_t r1 = TMath::Sqrt(1.0 - c1*c1);
1426 Double_t c2 = fC*xk - fE;
1427 Double_t r2 = TMath::Sqrt(1.0- c2*c2);
1428 return fY + (xk-fX)*(c1+c2)/(r1+r2);
1429
1430}
1431
1432//_____________________________________________________________________________
4e28c495 1433void AliTRDtrack::SetSampledEdx(Float_t q, Int_t i)
53c17fbf 1434{
1435 //
1436 // The sampled energy loss
1437 //
1438
1439 Double_t s = GetSnp();
1440 Double_t t = GetTgl();
1441 q *= TMath::Sqrt((1-s*s)/(1+t*t));
1442 fdQdl[i] = q;
1443
1444}
1445
1446 //_____________________________________________________________________________
4e28c495 1447void AliTRDtrack::SetSampledEdx(Float_t q)
53c17fbf 1448{
1449 //
1450 // The sampled energy loss
1451 //
1452
1453 Double_t s = GetSnp();
1454 Double_t t = GetTgl();
1455 q*= TMath::Sqrt((1-s*s)/(1+t*t));
1456 fdQdl[fNdedx] = q;
1457 fNdedx++;
1458
1459}
1460
1461//_____________________________________________________________________________
4e28c495 1462void AliTRDtrack::GetXYZ(Float_t r[3]) const
53c17fbf 1463{
1464
1465 //---------------------------------------------------------------------
1466 // Returns the position of the track in the global coord. system
1467 //---------------------------------------------------------------------
1468
1469 Double_t cs = TMath::Cos(fAlpha);
1470 Double_t sn = TMath::Sin(fAlpha);
1471 r[0] = fX*cs - fY*sn;
1472 r[1] = fX*sn + fY*cs;
1473 r[2] = fZ;
1474
1475}