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