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