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