Fix coverity defect
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackV1.cxx
CommitLineData
d9950a5a 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
203967fc 18#include "AliLog.h"
eb38ed55 19#include "AliESDtrack.h"
41880fac 20#include "AliTracker.h"
eb38ed55 21
d9950a5a 22#include "AliTRDtrackV1.h"
23#include "AliTRDcluster.h"
24#include "AliTRDcalibDB.h"
3afdab72 25#include "AliTRDReconstructor.h"
d9950a5a 26#include "AliTRDrecoParam.h"
27
d9950a5a 28ClassImp(AliTRDtrackV1)
29
0906e73e 30///////////////////////////////////////////////////////////////////////////////
31// //
32// Represents a reconstructed TRD track //
33// Local TRD Kalman track //
34// //
35// Authors: //
36// Alex Bercuci <A.Bercuci@gsi.de> //
37// Markus Fasel <M.Fasel@gsi.de> //
38// //
39///////////////////////////////////////////////////////////////////////////////
d9950a5a 40
41//_______________________________________________________________
3b57a3f7 42AliTRDtrackV1::AliTRDtrackV1() : AliKalmanTrack()
eb2b4f91 43 ,fStatus(0)
352cef8f 44 ,fESDid(0)
3b57a3f7 45 ,fDE(0.)
4d6aee34 46 ,fkReconstructor(NULL)
47 ,fBackupTrack(NULL)
48 ,fTrackLow(NULL)
49 ,fTrackHigh(NULL)
0906e73e 50{
d9950a5a 51 //
52 // Default constructor
53 //
6e49cfdb 54 //printf("AliTRDtrackV1::AliTRDtrackV1()\n");
e44586fb 55
3b57a3f7 56 for(int i =0; i<3; i++) fBudget[i] = 0.;
57
58 Float_t pid = 1./AliPID::kSPECIES;
59 for(int is =0; is<AliPID::kSPECIES; is++) fPID[is] = pid;
60
61 for(int ip=0; ip<kNplane; ip++){
17896e82 62 fTrackletIndex[ip] = -1;
4d6aee34 63 fTracklet[ip] = NULL;
3b57a3f7 64 }
d9950a5a 65}
66
67//_______________________________________________________________
3b57a3f7 68AliTRDtrackV1::AliTRDtrackV1(const AliTRDtrackV1 &ref) : AliKalmanTrack(ref)
eb2b4f91 69 ,fStatus(ref.fStatus)
352cef8f 70 ,fESDid(ref.fESDid)
3b57a3f7 71 ,fDE(ref.fDE)
4d6aee34 72 ,fkReconstructor(ref.fkReconstructor)
73 ,fBackupTrack(NULL)
74 ,fTrackLow(NULL)
75 ,fTrackHigh(NULL)
d9950a5a 76{
77 //
3b57a3f7 78 // Copy constructor
d9950a5a 79 //
80
6e49cfdb 81 //printf("AliTRDtrackV1::AliTRDtrackV1(const AliTRDtrackV1 &)\n");
29b87567 82 SetBit(kOwner, kFALSE);
3b57a3f7 83 for(int ip=0; ip<kNplane; ip++){
84 fTrackletIndex[ip] = ref.fTrackletIndex[ip];
85 fTracklet[ip] = ref.fTracklet[ip];
86 }
e3cf3d02 87 if(ref.fTrackLow) fTrackLow = new AliExternalTrackParam(*ref.fTrackLow);
88 if(ref.fTrackHigh) fTrackHigh = new AliExternalTrackParam(*ref.fTrackHigh);
89
3b57a3f7 90 for (Int_t i = 0; i < 3;i++) fBudget[i] = ref.fBudget[i];
91
92 for(Int_t is = 0; is<AliPID::kSPECIES; is++) fPID[is] = ref.fPID[is];
93
94 AliKalmanTrack::SetNumberOfClusters(ref.GetNumberOfClusters());
d9950a5a 95}
96
97//_______________________________________________________________
3b57a3f7 98AliTRDtrackV1::AliTRDtrackV1(const AliESDtrack &t) : AliKalmanTrack()
eb2b4f91 99 ,fStatus(0)
352cef8f 100 ,fESDid(0)
3b57a3f7 101 ,fDE(0.)
4d6aee34 102 ,fkReconstructor(NULL)
103 ,fBackupTrack(NULL)
104 ,fTrackLow(NULL)
105 ,fTrackHigh(NULL)
d9950a5a 106{
107 //
3b57a3f7 108 // Constructor from AliESDtrack
d9950a5a 109 //
110
352cef8f 111 SetESDid(t.GetID());
3b57a3f7 112 SetLabel(t.GetLabel());
113 SetChi2(0.0);
0b433f72 114
115 SetMass(t.GetMass()/*0.000510*/);
3b57a3f7 116 AliKalmanTrack::SetNumberOfClusters(t.GetTRDncls());
17896e82 117 Int_t ti[]={-1, -1, -1, -1, -1, -1}; t.GetTRDtracklets(&ti[0]);
3b57a3f7 118 for(int ip=0; ip<kNplane; ip++){
17896e82 119 fTrackletIndex[ip] = ti[ip];
4d6aee34 120 fTracklet[ip] = NULL;
3b57a3f7 121 }
122 for(int i =0; i<3; i++) fBudget[i] = 0.;
123
124 Float_t pid = 1./AliPID::kSPECIES;
125 for(int is =0; is<AliPID::kSPECIES; is++) fPID[is] = pid;
126
127 const AliExternalTrackParam *par = &t;
128 if (t.GetStatus() & AliESDtrack::kTRDbackup) {
129 par = t.GetOuterParam();
130 if (!par) {
131 AliError("No backup info!");
132 par = &t;
133 }
134 }
135 Set(par->GetX()
136 ,par->GetAlpha()
137 ,par->GetParameter()
138 ,par->GetCovariance());
139
140 if(t.GetStatus() & AliESDtrack::kTIME) {
141 StartTimeIntegral();
142 Double_t times[10];
143 t.GetIntegratedTimes(times);
144 SetIntegratedTimes(times);
145 SetIntegratedLength(t.GetIntegratedLength());
146 }
d9950a5a 147}
148
149//_______________________________________________________________
e17f4785 150AliTRDtrackV1::AliTRDtrackV1(AliTRDseedV1 * const trklts, const Double_t p[5], const Double_t cov[15]
3b57a3f7 151 , Double_t x, Double_t alpha) : AliKalmanTrack()
eb2b4f91 152 ,fStatus(0)
352cef8f 153 ,fESDid(0)
3b57a3f7 154 ,fDE(0.)
4d6aee34 155 ,fkReconstructor(NULL)
156 ,fBackupTrack(NULL)
157 ,fTrackLow(NULL)
158 ,fTrackHigh(NULL)
d9950a5a 159{
0906e73e 160 //
161 // The stand alone tracking constructor
162 // TEMPORARY !!!!!!!!!!!
163 // to check :
164 // 1. covariance matrix
165 // 2. dQdl calculation
166 //
d9950a5a 167
68f9b6bd 168 Double_t b(GetBz());
169 Double_t cnv = (TMath::Abs(b) < 1.e-5) ? 1.e5 : 1./GetBz()/kB2C;
170
d9950a5a 171 Double_t pp[5] = { p[0]
68f9b6bd 172 , p[1]
173 , p[2]
174 , p[3]
175 , p[4]*cnv };
176
d9950a5a 177 Double_t c22 = x*x*cov[14] - 2*x*cov[12] + cov[ 5];
178 Double_t c32 = x*cov[13] - cov[ 8];
179 Double_t c20 = x*cov[10] - cov[ 3];
180 Double_t c21 = x*cov[11] - cov[ 4];
181 Double_t c42 = x*cov[14] - cov[12];
68f9b6bd 182
d9950a5a 183 Double_t cc[15] = { cov[ 0]
184 , cov[ 1], cov[ 2]
185 , c20, c21, c22
186 , cov[ 6], cov[ 7], c32, cov[ 9]
187 , cov[10]*cnv, cov[11]*cnv, c42*cnv, cov[13]*cnv, cov[14]*cnv*cnv };
68f9b6bd 188
ae3fbe1f 189 Double_t mostProbablePt=AliExternalTrackParam::GetMostProbablePt();
190 Double_t p0=TMath::Sign(1/mostProbablePt,pp[4]);
191 Double_t w0=cc[14]/(cc[14] + p0*p0), w1=p0*p0/(cc[14] + p0*p0);
68f9b6bd 192 AliDebug(3, Form("Pt mixing : w0[%4.2f] pt0[%5.3f] w1[%4.2f] pt[%5.3f]", w0, 1./p0, w1, 1./pp[4]));
193
ae3fbe1f 194 pp[4] = w0*p0 + w1*pp[4];
195 cc[10]*=w1; cc[11]*=w1; cc[12]*=w1; cc[13]*=w1; cc[14]*=w1;
68f9b6bd 196 Set(x,alpha,pp,cc);
0217fcd0 197 AliDebug(2, Form("Init @ x[%6.2f] pt[%5.3f]", x, 1./pp[4]));
41702fec 198 Int_t ncls = 0;
68f9b6bd 199 for(int iplane=0; iplane<kNplane; iplane++){
17896e82 200 fTrackletIndex[iplane] = -1;
68f9b6bd 201 if(!trklts[iplane].IsOK()) fTracklet[iplane] = NULL;
41702fec 202 else{
e17f4785 203 fTracklet[iplane] = &trklts[iplane];
41702fec 204 ncls += fTracklet[iplane]->GetN();
205 }
68f9b6bd 206 }
41702fec 207 AliKalmanTrack::SetNumberOfClusters(ncls);
208 for(int i =0; i<3; i++) fBudget[i] = 0.;
209
210 Float_t pid = 1./AliPID::kSPECIES;
211 for(int is =0; is<AliPID::kSPECIES; is++) fPID[is] = pid;
d9950a5a 212}
213
214//_______________________________________________________________
3b57a3f7 215AliTRDtrackV1::~AliTRDtrackV1()
bb56afff 216{
4d8f1bd9 217 // Clean up all objects allocated by the track during its lifetime.
218 AliDebug(2, Form("Deleting track[%d]\n fBackupTrack[%p] fTrackLow[%p] fTrackHigh[%p] Owner[%c].", fESDid, (void*)fBackupTrack, (void*)fTrackLow, (void*)fTrackHigh, TestBit(kOwner)?'y':'n'));
76b60503 219
4d6aee34 220 if(fBackupTrack) delete fBackupTrack; fBackupTrack = NULL;
e3cf3d02 221
4d6aee34 222 if(fTrackLow) delete fTrackLow; fTrackLow = NULL;
223 if(fTrackHigh) delete fTrackHigh; fTrackHigh = NULL;
bb56afff 224
76b60503 225 for(Int_t ip=0; ip<kNplane; ip++){
226 if(TestBit(kOwner) && fTracklet[ip]) delete fTracklet[ip];
4d6aee34 227 fTracklet[ip] = NULL;
17896e82 228 fTrackletIndex[ip] = -1;
3b57a3f7 229 }
230}
231
232//_______________________________________________________________
e08a5492 233AliTRDtrackV1 &AliTRDtrackV1::operator=(const AliTRDtrackV1 &t)
234{
235 //
236 // Assignment operator
237 //
238
239 if (this != &t) {
240 ((AliTRDtrackV1 &) t).Copy(*this);
241 }
242
243 return *this;
244
245}
246
247//_____________________________________________________________________________
248void AliTRDtrackV1::Copy(TObject &t) const
249{
250 //
251 // Copy function
252 //
253
254 ((AliTRDtrackV1 &) t).fStatus = fStatus;
255 ((AliTRDtrackV1 &) t).fESDid = fESDid;
256 ((AliTRDtrackV1 &) t).fDE = fDE;
257 ((AliTRDtrackV1 &) t).fkReconstructor = fkReconstructor;
258 ((AliTRDtrackV1 &) t).fBackupTrack = 0x0;
259 ((AliTRDtrackV1 &) t).fTrackLow = 0x0;
260 ((AliTRDtrackV1 &) t).fTrackHigh = 0x0;
261
262 for(Int_t ip = 0; ip < kNplane; ip++) {
263 ((AliTRDtrackV1 &) t).fTrackletIndex[ip] = fTrackletIndex[ip];
264 ((AliTRDtrackV1 &) t).fTracklet[ip] = fTracklet[ip];
265 }
266 if (fTrackLow) {
267 ((AliTRDtrackV1 &) t).fTrackLow = new AliExternalTrackParam(*fTrackLow);
268 }
269 if (fTrackHigh){
270 ((AliTRDtrackV1 &) t).fTrackHigh = new AliExternalTrackParam(*fTrackHigh);
271 }
272
273 for (Int_t i = 0; i < 3; i++) {
274 ((AliTRDtrackV1 &) t).fBudget[i] = fBudget[i];
275 }
276 for (Int_t is = 0; is < AliPID::kSPECIES; is++) {
277 ((AliTRDtrackV1 &) t).fPID[is] = fPID[is];
278 }
279
280}
281
282//_______________________________________________________________
3b57a3f7 283Bool_t AliTRDtrackV1::CookLabel(Float_t wrong)
284{
285 // set MC label for this track
bb2db46c 286 if(!GetNumberOfClusters()) return kFALSE;
287
bb56afff 288 Int_t s[kMAXCLUSTERSPERTRACK][2];
289 for (Int_t i = 0; i < kMAXCLUSTERSPERTRACK; i++) {
290 s[i][0] = -1;
291 s[i][1] = 0;
292 }
3b57a3f7 293
bb56afff 294 Bool_t labelAdded;
3b57a3f7 295 Int_t label;
4d6aee34 296 AliTRDcluster *c = NULL;
3b57a3f7 297 for (Int_t ip = 0; ip < kNplane; ip++) {
68f9b6bd 298 if(fTrackletIndex[ip]<0 || !fTracklet[ip]) continue;
8d2bec9e 299 for (Int_t ic = 0; ic < AliTRDseedV1::kNclusters; ic++) {
3b57a3f7 300 if(!(c = fTracklet[ip]->GetClusters(ic))) continue;
301 for (Int_t k = 0; k < 3; k++) {
302 label = c->GetLabel(k);
303 labelAdded = kFALSE;
304 Int_t j = 0;
305 if (label >= 0) {
306 while ((!labelAdded) && (j < kMAXCLUSTERSPERTRACK)) {
307 if ((s[j][0] == label) ||
308 (s[j][1] == 0)) {
309 s[j][0] = label;
310 s[j][1]++;
311 labelAdded = kTRUE;
312 }
313 j++;
314 }
315 }
316 }
317 }
318 }
319
bb56afff 320 Int_t max = 0;
321 label = -123456789;
322 for (Int_t i = 0; i < kMAXCLUSTERSPERTRACK; i++) {
323 if (s[i][1] <= max) continue;
3b57a3f7 324 max = s[i][1];
325 label = s[i][0];
bb56afff 326 }
bb56afff 327 if ((1. - Float_t(max)/GetNumberOfClusters()) > wrong) label = -label;
3b57a3f7 328
bb56afff 329 SetLabel(label);
3b57a3f7 330
331 return kTRUE;
bb56afff 332}
333
334//_______________________________________________________________
d9950a5a 335Bool_t AliTRDtrackV1::CookPID()
336{
2a3191bb 337//
338// Cook the PID information for the track by delegating the omonim function of the tracklets.
339// Computes the number of tracklets used. The tracklet information are considered independent.
340// For the moment no global track measurement of PID is performed as for example to estimate
341// bremsstrahlung probability based on global chi2 of the track.
342//
343// The status bit AliESDtrack::kTRDpid is set during the call of AliTRDtrackV1::UpdateESDtrack().The PID performance of the
344//TRD for tracks with 6 tacklets is displayed below.
345//Begin_Html
346//<img src="TRD/trackPID.gif">
347//End_Html
348//
3b57a3f7 349
2a3191bb 350 /*Reset the a priori probabilities*/
3b57a3f7 351 Double_t pid = 1. / AliPID::kSPECIES;
eb2b4f91 352 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++) fPID[ispec] = pid;
353
354 UChar_t fPIDquality = SetNumberOfTrackletsPID(kTRUE);
355 // no tracklet found for PID calculations
356 if(!fPIDquality) return kFALSE;
357
2a3191bb 358 // slot for PID calculation @ track level for bremsstrahlung TODO
eb2b4f91 359
360 // normalize probabilities
361 Double_t probTotal = 0.0;
362 for (Int_t is = 0; is < AliPID::kSPECIES; is++) probTotal += fPID[is];
363
364
365 if (probTotal <= 0.0) {
366 AliWarning("The total probability over all species <= 0. This may be caused by some error in the reference data.");
367 return kFALSE;
3b57a3f7 368 }
3b57a3f7 369
eb2b4f91 370 for (Int_t iSpecies = 0; iSpecies < AliPID::kSPECIES; iSpecies++) fPID[iSpecies] /= probTotal;
371
372 return kTRUE;
373}
374
375//___________________________________________________________
376UChar_t AliTRDtrackV1::GetNumberOfTrackletsPID() const
377{
378// Retrieve number of tracklets used for PID calculation.
379
e20bef2b 380 UChar_t nPID = 0;
4d6aee34 381 Float_t *prob = NULL;
3b57a3f7 382 for(int ip=0; ip<kNplane; ip++){
68f9b6bd 383 if(fTrackletIndex[ip]<0 || !fTracklet[ip]) continue;
3b57a3f7 384 if(!fTracklet[ip]->IsOK()) continue;
e20bef2b 385 if(!(prob = fTracklet[ip]->GetProbability(kFALSE))) continue;
68f9b6bd 386
3b57a3f7 387 Int_t nspec = 0; // quality check of tracklet dEdx
388 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++){
389 if(prob[ispec] < 0.) continue;
3b57a3f7 390 nspec++;
391 }
392 if(!nspec) continue;
393
e20bef2b 394 fTracklet[ip]->SetPID();
395 nPID++;
0906e73e 396 }
e20bef2b 397 return nPID;
eb2b4f91 398}
399
400//___________________________________________________________
401UChar_t AliTRDtrackV1::SetNumberOfTrackletsPID(Bool_t recalc)
402{
403// Retrieve number of tracklets used for PID calculation. // Recalculated PID at tracklet level by quering the PID DB.
404
68f9b6bd 405 UChar_t fPIDquality(0);
0906e73e 406
eb2b4f91 407 // steer PID calculation @ tracklet level
68f9b6bd 408 Float_t *prob(NULL);
eb2b4f91 409 for(int ip=0; ip<kNplane; ip++){
68f9b6bd 410 if(fTrackletIndex[ip]<0 || !fTracklet[ip]) continue;
eb2b4f91 411 if(!fTracklet[ip]->IsOK()) continue;
412 if(!(prob = fTracklet[ip]->GetProbability(recalc))) return 0;
68f9b6bd 413
eb2b4f91 414 Int_t nspec = 0; // quality check of tracklet dEdx
415 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++){
416 if(prob[ispec] < 0.) continue;
417 fPID[ispec] *= prob[ispec];
418 nspec++;
419 }
420 if(!nspec) continue;
421
422 fPIDquality++;
d9950a5a 423 }
eb2b4f91 424 return fPIDquality;
d9950a5a 425}
426
3b57a3f7 427//_______________________________________________________________
0349cc67 428AliTRDcluster* AliTRDtrackV1::GetCluster(Int_t id)
429{
4d6aee34 430 // Get the cluster at a certain position in the track
0349cc67 431 Int_t n = 0;
432 for(Int_t ip=0; ip<kNplane; ip++){
433 if(!fTracklet[ip]) continue;
434 if(n+fTracklet[ip]->GetN() <= id){
435 n+=fTracklet[ip]->GetN();
436 continue;
437 }
4d6aee34 438 AliTRDcluster *c = NULL;
8d2bec9e 439 for(Int_t ic=AliTRDseedV1::kNclusters; ic--;){
0349cc67 440 if(!(c = fTracklet[ip]->GetClusters(ic))) continue;
441
442 if(n<id){n++; continue;}
443 return c;
444 }
445 }
4d6aee34 446 return NULL;
0349cc67 447}
448
449//_______________________________________________________________
3b57a3f7 450Int_t AliTRDtrackV1::GetClusterIndex(Int_t id) const
451{
4d6aee34 452 // Get the cluster index at a certain position in the track
3b57a3f7 453 Int_t n = 0;
454 for(Int_t ip=0; ip<kNplane; ip++){
455 if(!fTracklet[ip]) continue;
76b60503 456 if(n+fTracklet[ip]->GetN() <= id){
3b57a3f7 457 n+=fTracklet[ip]->GetN();
458 continue;
459 }
8d2bec9e 460 for(Int_t ic=AliTRDseedV1::kNclusters; ic--;){
87f70a90 461 if(!(fTracklet[ip]->GetClusters(ic))) continue;
76b60503 462 if(n<id){n++; continue;}
3b57a3f7 463 return fTracklet[ip]->GetIndexes(ic);
464 }
465 }
466 return -1;
0906e73e 467}
d9950a5a 468
469//_______________________________________________________________
b72f4eaf 470Double_t AliTRDtrackV1::GetPredictedChi2(const AliTRDseedV1 *trklt, Double_t *cov) const
d9950a5a 471{
ed15ef4f 472// Compute chi2 between tracklet and track. The value is calculated at the radial position of the track
473// equal to the reference radial position of the tracklet (see AliTRDseedV1)
474//
475// The chi2 estimator is computed according to the following formula
476// BEGIN_LATEX
477// #chi^{2}=(X_{trklt}-X_{track})(C_{trklt}+C_{track})^{-1}(X_{trklt}-X_{track})^{T}
478// END_LATEX
479// where X=(y z), the position of the track/tracklet in the yz plane
480//
481
b72f4eaf 482 Double_t p[2] = { trklt->GetY(), trklt->GetZ()};
483 trklt->GetCovAt(trklt->GetX(), cov);
ed15ef4f 484 return AliExternalTrackParam::GetPredictedChi2(p, cov);
3b57a3f7 485}
d9950a5a 486
22a4ab0c 487//_______________________________________________________________
eb2b4f91 488Int_t AliTRDtrackV1::GetSector() const
489{
490 return Int_t(GetAlpha()/AliTRDgeometry::GetAlpha() + (GetAlpha()>0. ? 0 : AliTRDgeometry::kNsector));
491}
492
493//_______________________________________________________________
203967fc 494Bool_t AliTRDtrackV1::IsEqual(const TObject *o) const
495{
4d6aee34 496 // Checks whether two tracks are equal
203967fc 497 if (!o) return kFALSE;
498 const AliTRDtrackV1 *inTrack = dynamic_cast<const AliTRDtrackV1*>(o);
499 if (!inTrack) return kFALSE;
500
eb2b4f91 501 //if ( fPIDquality != inTrack->GetPIDquality() ) return kFALSE;
203967fc 502
d8069611 503 if(memcmp(fPID, inTrack->fPID, AliPID::kSPECIES*sizeof(Double32_t))) return kFALSE;
504 if(memcmp(fBudget, inTrack->fBudget, 3*sizeof(Double32_t))) return kFALSE;
505 if(memcmp(&fDE, &inTrack->fDE, sizeof(Double32_t))) return kFALSE;
506 if(memcmp(&fFakeRatio, &inTrack->fFakeRatio, sizeof(Double32_t))) return kFALSE;
507 if(memcmp(&fChi2, &inTrack->fChi2, sizeof(Double32_t))) return kFALSE;
508 if(memcmp(&fMass, &inTrack->fMass, sizeof(Double32_t))) return kFALSE;
509 if( fLab != inTrack->fLab ) return kFALSE;
510 if( fN != inTrack->fN ) return kFALSE;
511 Double32_t l(0.), in(0.);
512 l = GetIntegratedLength(); in = inTrack->GetIntegratedLength();
513 if(memcmp(&l, &in, sizeof(Double32_t))) return kFALSE;
514 l=GetX(); in=inTrack->GetX();
515 if(memcmp(&l, &in, sizeof(Double32_t))) return kFALSE;
516 l = GetAlpha(); in = inTrack->GetAlpha();
517 if(memcmp(&l, &in, sizeof(Double32_t))) return kFALSE;
518 if(memcmp(GetParameter(), inTrack->GetParameter(), 5*sizeof(Double32_t))) return kFALSE;
519 if(memcmp(GetCovariance(), inTrack->GetCovariance(), 15*sizeof(Double32_t))) return kFALSE;
203967fc 520
521 for (Int_t iTracklet = 0; iTracklet < kNplane; iTracklet++){
522 AliTRDseedV1 *curTracklet = fTracklet[iTracklet];
523 AliTRDseedV1 *inTracklet = inTrack->GetTracklet(iTracklet);
524 if (curTracklet && inTracklet){
525 if (! curTracklet->IsEqual(inTracklet) ) {
526 curTracklet->Print();
527 inTracklet->Print();
528 return kFALSE;
529 }
530 } else {
531 // if one tracklet exists, and corresponding
532 // in other track doesn't - return kFALSE
533 if(inTracklet || curTracklet) return kFALSE;
534 }
535 }
536
537 return kTRUE;
538}
539
540//_______________________________________________________________
22a4ab0c 541Bool_t AliTRDtrackV1::IsElectron() const
542{
4d6aee34 543 if(GetPID(0) > fkReconstructor->GetRecoParam()->GetPIDThreshold(GetP())) return kTRUE;
22a4ab0c 544 return kFALSE;
545}
546
3b57a3f7 547
548//_____________________________________________________________________________
b453ef55 549Int_t AliTRDtrackV1::MakeBackupTrack()
3b57a3f7 550{
b453ef55 551//
552// Creates a backup track
553// TO DO update quality check of the track.
554//
555
556 Float_t occupancy(0.); Int_t n(0), ncls(0);
557 for(Int_t il(AliTRDgeometry::kNlayer); il--;){
558 if(!fTracklet[il]) continue;
559 n++;
560 occupancy+=fTracklet[il]->GetOccupancyTB();
561 ncls += fTracklet[il]->GetN();
562 }
563 if(!n) return -1;
564 occupancy/=n;
565
566 //Float_t ratio1 = Float_t(t.GetNumberOfClusters()+1) / Float_t(t.GetNExpected()+1);
567
568 Int_t failedCutId(0);
569 if(GetChi2()/n > 5.0) failedCutId=1;
570 if(occupancy < 0.7) failedCutId=2;
571 //if(ratio1 > 0.6) &&
572 //if(ratio0+ratio1 > 1.5) &&
573 if(GetNCross() != 0) failedCutId=3;
574 if(TMath::Abs(GetSnp()) > 0.85) failedCutId=4;
575 if(ncls < 20) failedCutId=5;
576
577 if(failedCutId){
578 AliDebug(2, Form("\n"
579 "chi2/tracklet < 5.0 [%c] %5.2f\n"
580 "occupancy > 0.7 [%c] %4.2f\n"
581 "NCross == 0 [%c] %d\n"
582 "Abs(snp) < 0.85 [%c] %4.2f\n"
583 "NClusters > 20 [%c] %d"
584 ,(GetChi2()/n<5.0)?'y':'n', GetChi2()/n
585 ,(occupancy>0.7)?'y':'n', occupancy
586 ,(GetNCross()==0)?'y':'n', GetNCross()
587 ,(TMath::Abs(GetSnp())<0.85)?'y':'n', TMath::Abs(GetSnp())
588 ,(ncls>20)?'y':'n', ncls
589 ));
590 return failedCutId;
591 }
3b57a3f7 592
593 if(fBackupTrack) {
594 fBackupTrack->~AliTRDtrackV1();
595 new(fBackupTrack) AliTRDtrackV1((AliTRDtrackV1&)(*this));
b453ef55 596 return 0;
3b57a3f7 597 }
598 fBackupTrack = new AliTRDtrackV1((AliTRDtrackV1&)(*this));
b453ef55 599 return 0;
d9950a5a 600}
601
3b57a3f7 602//_____________________________________________________________________________
f8a9723f 603Int_t AliTRDtrackV1::GetProlongation(Double_t xk, Double_t &y, Double_t &z) const
3b57a3f7 604{
605 //
606 // Find a prolongation at given x
530fb4e2 607 // Return -1 if it does not exist
3b57a3f7 608 //
609
610 Double_t bz = GetBz();
530fb4e2 611 if (!AliExternalTrackParam::GetYAt(xk,bz,y)) return -1;
612 if (!AliExternalTrackParam::GetZAt(xk,bz,z)) return -1;
3b57a3f7 613
614 return 1;
615
616}
617
618//_____________________________________________________________________________
619Bool_t AliTRDtrackV1::PropagateTo(Double_t xk, Double_t xx0, Double_t xrho)
0906e73e 620{
621 //
3b57a3f7 622 // Propagates this track to a reference plane defined by "xk" [cm]
623 // correcting for the mean crossed material.
0906e73e 624 //
3b57a3f7 625 // "xx0" - thickness/rad.length [units of the radiation length]
626 // "xrho" - thickness*density [g/cm^2]
627 //
0906e73e 628
952051c5 629 if (TMath::Abs(xk - GetX())<AliTRDReconstructor::GetEpsilon()*0.1) return kTRUE; // 10% of the tracker precision
dc5e390a 630
307aac71 631 Double_t xyz0[3] = {GetX(), GetY(), GetZ()}, // track position BEFORE propagation
dc5e390a 632 b[3]; // magnetic field
307aac71 633 GetBxByBz(b);
dc5e390a 634 if(!AliExternalTrackParam::PropagateToBxByBz(xk,b)) return kFALSE;
635
307aac71 636 // local track position AFTER propagation
637 Double_t xyz1[3] = {GetX(), GetY(), GetZ()};
dc5e390a 638 if(xyz0[0] < xk) {
3b57a3f7 639 xrho = -xrho;
640 if (IsStartedTimeIntegral()) {
dc5e390a 641 Double_t l2 = TMath::Sqrt((xyz1[0]-xyz0[0])*(xyz1[0]-xyz0[0])
642 + (xyz1[1]-xyz0[1])*(xyz1[1]-xyz0[1])
643 + (xyz1[2]-xyz0[2])*(xyz1[2]-xyz0[2]));
6790f7d7 644 Double_t crv = AliExternalTrackParam::GetC(b[2]);
3b57a3f7 645 if (TMath::Abs(l2*crv) > 0.0001) {
646 // Make correction for curvature if neccesary
dc5e390a 647 l2 = 0.5 * TMath::Sqrt((xyz1[0]-xyz0[0])*(xyz1[0]-xyz0[0])
648 + (xyz1[1]-xyz0[1])*(xyz1[1]-xyz0[1]));
3b57a3f7 649 l2 = 2.0 * TMath::ASin(l2 * crv) / crv;
dc5e390a 650 l2 = TMath::Sqrt(l2*l2 + (xyz1[2]-xyz0[2])*(xyz1[2]-xyz0[2]));
3b57a3f7 651 }
652 AddTimeStep(l2);
653 }
654 }
655
fd40f855 656 if (!AliExternalTrackParam::CorrectForMeanMaterial(xx0, xrho, GetMass())) return kFALSE;
657
3b57a3f7 658
659 {
660
661 // Energy losses
662 Double_t p2 = (1.0 + GetTgl()*GetTgl()) / (GetSigned1Pt()*GetSigned1Pt());
663 Double_t beta2 = p2 / (p2 + GetMass()*GetMass());
664 if ((beta2 < 1.0e-10) ||
665 ((5940.0 * beta2/(1.0 - beta2 + 1.0e-10) - beta2) < 0.0)) {
666 return kFALSE;
667 }
668
669 Double_t dE = 0.153e-3 / beta2
670 * (TMath::Log(5940.0 * beta2/(1.0 - beta2 + 1.0e-10)) - beta2)
671 * xrho;
672 fBudget[0] += xrho;
673
674 /*
675 // Suspicious part - think about it ?
676 Double_t kinE = TMath::Sqrt(p2);
677 if (dE > 0.8*kinE) dE = 0.8 * kinE; //
678 if (dE < 0) dE = 0.0; // Not valid region for Bethe bloch
679 */
680
681 fDE += dE;
682
683 /*
684 // Suspicious ! I.B.
685 Double_t sigmade = 0.07 * TMath::Sqrt(TMath::Abs(dE)); // Energy loss fluctuation
686 Double_t sigmac2 = sigmade*sigmade*fC*fC*(p2+GetMass()*GetMass())/(p2*p2);
687 fCcc += sigmac2;
688 fCee += fX*fX * sigmac2;
689 */
690
691 }
692
693 return kTRUE;
0906e73e 694}
3b57a3f7 695
87a7fa94 696//_____________________________________________________________________________
3b57a3f7 697Int_t AliTRDtrackV1::PropagateToR(Double_t r,Double_t step)
87a7fa94 698{
699 //
3b57a3f7 700 // Propagate track to the radial position
701 // Rotation always connected to the last track position
87a7fa94 702 //
703
3b57a3f7 704 Double_t xyz0[3];
705 Double_t xyz1[3];
706 Double_t y;
707 Double_t z;
708
709 Double_t radius = TMath::Sqrt(GetX()*GetX() + GetY()*GetY());
710 // Direction +-
711 Double_t dir = (radius > r) ? -1.0 : 1.0;
712
713 for (Double_t x = radius+dir*step; dir*x < dir*r; x += dir*step) {
714
715 GetXYZ(xyz0);
716 Double_t alpha = TMath::ATan2(xyz0[1],xyz0[0]);
717 Rotate(alpha,kTRUE);
718 GetXYZ(xyz0);
e20bef2b 719 if(GetProlongation(x,y,z)<0) return -1;
3b57a3f7 720 xyz1[0] = x * TMath::Cos(alpha) + y * TMath::Sin(alpha);
721 xyz1[1] = x * TMath::Sin(alpha) - y * TMath::Cos(alpha);
722 xyz1[2] = z;
723 Double_t param[7];
83dea92e 724 if(AliTracker::MeanMaterialBudget(xyz0,xyz1,param)<=0.) return -1;
3b57a3f7 725 if (param[1] <= 0) {
726 param[1] = 100000000;
727 }
728 PropagateTo(x,param[1],param[0]*param[4]);
729
730 }
731
732 GetXYZ(xyz0);
733 Double_t alpha = TMath::ATan2(xyz0[1],xyz0[0]);
734 Rotate(alpha,kTRUE);
735 GetXYZ(xyz0);
530fb4e2 736 if(GetProlongation(r,y,z)<0) return -1;
3b57a3f7 737 xyz1[0] = r * TMath::Cos(alpha) + y * TMath::Sin(alpha);
738 xyz1[1] = r * TMath::Sin(alpha) - y * TMath::Cos(alpha);
739 xyz1[2] = z;
740 Double_t param[7];
83dea92e 741 if(AliTracker::MeanMaterialBudget(xyz0,xyz1,param) <= 0.) return -1;
3b57a3f7 742
743 if (param[1] <= 0) {
744 param[1] = 100000000;
87a7fa94 745 }
3b57a3f7 746 PropagateTo(r,param[1],param[0]*param[4]);
747
748 return 0;
749
87a7fa94 750}
751
3b57a3f7 752//_____________________________________________________________________________
203967fc 753void AliTRDtrackV1::Print(Option_t *o) const
754{
4d6aee34 755 // Print track status
eb2b4f91 756 AliInfo(Form("PID [%4.1f %4.1f %4.1f %4.1f %4.1f]", 1.E2*fPID[0], 1.E2*fPID[1], 1.E2*fPID[2], 1.E2*fPID[3], 1.E2*fPID[4]));
203967fc 757 AliInfo(Form("Material[%5.2f %5.2f %5.2f]", fBudget[0], fBudget[1], fBudget[2]));
758
759 AliInfo(Form("x[%7.2f] t[%7.4f] alpha[%f] mass[%f]", GetX(), GetIntegratedLength(), GetAlpha(), fMass));
eb2b4f91 760 AliInfo(Form("Ntr[%1d] NtrPID[%1d] Ncl[%3d] lab[%3d]", GetNumberOfTracklets(), GetNumberOfTrackletsPID(), fN, fLab));
203967fc 761
203967fc 762 printf("|X| = (");
763 const Double_t *curP = GetParameter();
764 for (Int_t i = 0; i < 5; i++) printf("%7.2f ", curP[i]);
765 printf(")\n");
766
767 printf("|V| = \n");
768 const Double_t *curC = GetCovariance();
769 for (Int_t i = 0, j=4, k=0; i<15; i++, k++){
770 printf("%7.2f ", curC[i]);
771 if(k==j){
772 printf("\n");
773 k=-1; j--;
774 }
775 }
0217fcd0 776 if(strcmp(o, "a")!=0) return;
203967fc 777
778 for(Int_t ip=0; ip<kNplane; ip++){
779 if(!fTracklet[ip]) continue;
780 fTracklet[ip]->Print(o);
781 }
782}
783
784
785//_____________________________________________________________________________
3b57a3f7 786Bool_t AliTRDtrackV1::Rotate(Double_t alpha, Bool_t absolute)
787{
788 //
789 // Rotates track parameters in R*phi plane
790 // if absolute rotation alpha is in global system
791 // otherwise alpha rotation is relative to the current rotation angle
792 //
793
794 if (absolute) alpha -= GetAlpha();
795 //else fNRotate++;
796
797 return AliExternalTrackParam::Rotate(GetAlpha()+alpha);
798}
87a7fa94 799
eb38ed55 800//___________________________________________________________
801void AliTRDtrackV1::SetNumberOfClusters()
802{
803// Calculate the number of clusters attached to this track
804
3b57a3f7 805 Int_t ncls = 0;
806 for(int ip=0; ip<kNplane; ip++){
68f9b6bd 807 if(fTracklet[ip] && fTrackletIndex[ip] >= 0) ncls += fTracklet[ip]->GetN();
3b57a3f7 808 }
809 AliKalmanTrack::SetNumberOfClusters(ncls);
eb38ed55 810}
811
812
0906e73e 813//_______________________________________________________________
3b57a3f7 814void AliTRDtrackV1::SetOwner()
0906e73e 815{
816 //
817 // Toggle ownership of tracklets
818 //
819
e44586fb 820 if(TestBit(kOwner)) return;
3b57a3f7 821 for (Int_t ip = 0; ip < kNplane; ip++) {
68f9b6bd 822 if(fTrackletIndex[ip]<0 || !fTracklet[ip]) continue;
3b57a3f7 823 fTracklet[ip] = new AliTRDseedV1(*fTracklet[ip]);
824 fTracklet[ip]->SetOwner();
825 }
e44586fb 826 SetBit(kOwner);
0906e73e 827}
828
829//_______________________________________________________________
4d6aee34 830void AliTRDtrackV1::SetTracklet(AliTRDseedV1 *const trklt, Int_t index)
d9950a5a 831{
832 //
0906e73e 833 // Set the tracklets
d9950a5a 834 //
3b57a3f7 835 Int_t plane = trklt->GetPlane();
76b60503 836
3b57a3f7 837 fTracklet[plane] = trklt;
838 fTrackletIndex[plane] = index;
d9950a5a 839}
840
841//_______________________________________________________________
a310e49b 842void AliTRDtrackV1::SetTrackIn()
e3cf3d02 843{
fc6d4c2d 844// Save location of birth for the TRD track
845// If the pointer is not valid allocate memory
846//
e3cf3d02 847 const AliExternalTrackParam *op = dynamic_cast<const AliExternalTrackParam*>(this);
fc6d4c2d 848
5d4510fe 849 //printf("SetTrackIn() : fTrackLow[%p]\n", (void*)fTrackLow);
fc6d4c2d 850 if(fTrackLow){
851 fTrackLow->~AliExternalTrackParam();
852 new(fTrackLow) AliExternalTrackParam(*op);
853 } else fTrackLow = new AliExternalTrackParam(*op);
e3cf3d02 854}
855
856//_______________________________________________________________
a310e49b 857void AliTRDtrackV1::SetTrackOut(const AliExternalTrackParam *op)
e3cf3d02 858{
fc6d4c2d 859// Save location of death for the TRD track
860// If the pointer is not valid allocate memory
861//
e3cf3d02 862 if(!op) op = dynamic_cast<const AliExternalTrackParam*>(this);
fc6d4c2d 863 if(fTrackHigh){
864 fTrackHigh->~AliExternalTrackParam();
865 new(fTrackHigh) AliExternalTrackParam(*op);
866 } else fTrackHigh = new AliExternalTrackParam(*op);
e3cf3d02 867}
868
869//_______________________________________________________________
181d2c97 870void AliTRDtrackV1::UnsetTracklet(Int_t plane)
871{
87f70a90 872 if(plane<0) return;
17896e82 873 fTrackletIndex[plane] = -1;
4d6aee34 874 fTracklet[plane] = NULL;
181d2c97 875}
876
877
878//_______________________________________________________________
ef867f55 879void AliTRDtrackV1::UpdateChi2(Float_t chi2)
d9950a5a 880{
ef867f55 881// Update chi2/track with one tracklet contribution
b72f4eaf 882 SetChi2(GetChi2() + chi2);
d9950a5a 883}
884
885//_______________________________________________________________
0906e73e 886void AliTRDtrackV1::UpdateESDtrack(AliESDtrack *track)
d9950a5a 887{
888 //
6984f7c1 889 // Update the TRD PID information in the ESD track
d9950a5a 890 //
6984f7c1 891
a2fbb6ec 892 Int_t nslices = fkReconstructor->GetRecoParam()->IsEightSlices() ? (Int_t)AliTRDpidUtil::kNNslices : (Int_t)AliTRDpidUtil::kLQslices;
e20bef2b 893 // number of tracklets used for PID calculation
894 UChar_t nPID = GetNumberOfTrackletsPID();
895 // number of tracklets attached to the track
896 UChar_t nTrk = GetNumberOfTracklets();
897 // pack the two numbers together and store them in the ESD
898 track->SetTRDntracklets(nPID | (nTrk<<3));
899 // allocate space to store raw PID signals dEdx & momentum
b48e9cbb 900 track->SetNumberOfTRDslices((nslices+2)*AliTRDgeometry::kNlayer);
e20bef2b 901 // store raw signals
7b23a4e1 902 Float_t p, sp; Double_t spd;
6984f7c1 903 for (Int_t ip = 0; ip < kNplane; ip++) {
68f9b6bd 904 if(fTrackletIndex[ip]<0 || !fTracklet[ip]) continue;
e20bef2b 905 if(!fTracklet[ip]->HasPID()) continue;
4d6aee34 906 const Float_t *dedx = fTracklet[ip]->GetdEdx();
215f7116 907 for (Int_t js = 0; js < nslices; js++, dedx++) track->SetTRDslice(*dedx, ip, js);
7b23a4e1 908 p = fTracklet[ip]->GetMomentum(&sp); spd = sp;
909 track->SetTRDmomentum(p, ip, &spd);
6984f7c1 910 }
e20bef2b 911 // store PID probabilities
912 track->SetTRDpid(fPID);
d9950a5a 913}