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