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