2 /**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
21 #include "AliESDtrack.h"
22 #include "AliTracker.h"
24 #include "AliTRDtrackV1.h"
25 #include "AliTRDcluster.h"
26 #include "AliTRDcalibDB.h"
27 #include "AliTRDReconstructor.h"
28 #include "AliTRDPIDResponse.h"
29 #include "AliTRDrecoParam.h"
30 #include "AliTRDdEdxBaseUtils.h"
31 #include "AliTRDdEdxCalibHistArray.h"
32 #include "AliTRDdEdxCalibUtils.h"
33 #include "AliTRDdEdxReconUtils.h"
35 ClassImp(AliTRDtrackV1)
37 ///////////////////////////////////////////////////////////////////////////////
39 // Represents a reconstructed TRD track //
40 // Local TRD Kalman track //
43 // Alex Bercuci <A.Bercuci@gsi.de> //
44 // Markus Fasel <M.Fasel@gsi.de> //
46 ///////////////////////////////////////////////////////////////////////////////
48 //_______________________________________________________________
49 AliTRDtrackV1::AliTRDtrackV1() : AliKalmanTrack()
57 ,fkReconstructor(NULL)
63 // Default constructor
65 //printf("AliTRDtrackV1::AliTRDtrackV1()\n");
67 for(int i =0; i<3; i++) fBudget[i] = 0.;
69 Float_t pid = 1./AliPID::kSPECIES;
70 for(int is =0; is<AliPID::kSPECIES; is++) fPID[is] = pid;
72 for(int ip=0; ip<kNplane; ip++){
73 fTrackletIndex[ip] = -1;
76 SetLabel(-123456789); // reset label
79 //_______________________________________________________________
80 AliTRDtrackV1::AliTRDtrackV1(const AliTRDtrackV1 &ref) : AliKalmanTrack(ref)
84 ,fTruncatedMean(ref.fTruncatedMean)
85 ,fNchamberdEdx(ref.fNchamberdEdx)
86 ,fNclusterdEdx(ref.fNclusterdEdx)
87 ,fNdEdxSlices(ref.fNdEdxSlices)
88 ,fkReconstructor(ref.fkReconstructor)
97 //printf("AliTRDtrackV1::AliTRDtrackV1(const AliTRDtrackV1 &)\n");
98 SetBit(kOwner, kFALSE);
99 for(int ip=0; ip<kNplane; ip++){
100 fTrackletIndex[ip] = ref.fTrackletIndex[ip];
101 fTracklet[ip] = ref.fTracklet[ip];
103 if(ref.fTrackLow) fTrackLow = new AliExternalTrackParam(*ref.fTrackLow);
104 if(ref.fTrackHigh) fTrackHigh = new AliExternalTrackParam(*ref.fTrackHigh);
106 for (Int_t i = 0; i < 3;i++) fBudget[i] = ref.fBudget[i];
108 for(Int_t is = 0; is<AliPID::kSPECIES; is++) fPID[is] = ref.fPID[is];
110 AliKalmanTrack::SetNumberOfClusters(ref.GetNumberOfClusters());
113 //_______________________________________________________________
114 AliTRDtrackV1::AliTRDtrackV1(const AliESDtrack &t) : AliKalmanTrack()
122 ,fkReconstructor(NULL)
128 // Constructor from AliESDtrack
132 SetLabel(t.GetLabel());
135 SetMass(t.GetMassForTracking());
136 AliKalmanTrack::SetNumberOfClusters(t.GetTRDncls());
137 Int_t ti[]={-1, -1, -1, -1, -1, -1}; t.GetTRDtracklets(&ti[0]);
138 for(int ip=0; ip<kNplane; ip++){
139 fTrackletIndex[ip] = ti[ip];
140 fTracklet[ip] = NULL;
142 for(int i =0; i<3; i++) fBudget[i] = 0.;
144 Float_t pid = 1./AliPID::kSPECIES;
145 for(int is =0; is<AliPID::kSPECIES; is++) fPID[is] = pid;
147 const AliExternalTrackParam *par = &t;
148 if (t.GetStatus() & AliESDtrack::kTRDbackup) {
149 par = t.GetOuterParam();
151 AliError("No backup info!");
158 ,par->GetCovariance());
160 if(t.GetStatus() & AliESDtrack::kTIME) {
162 Double_t times[AliPID::kSPECIESC];
163 t.GetIntegratedTimes(times,AliPID::kSPECIESC);
164 SetIntegratedTimes(times);
165 SetIntegratedLength(t.GetIntegratedLength());
169 //_______________________________________________________________
170 AliTRDtrackV1::AliTRDtrackV1(AliTRDseedV1 * const trklts, const Double_t p[5], const Double_t cov[15]
171 , Double_t x, Double_t alpha) : AliKalmanTrack()
179 ,fkReconstructor(NULL)
185 // The stand alone tracking constructor
186 // TEMPORARY !!!!!!!!!!!
188 // 1. covariance matrix
189 // 2. dQdl calculation
193 Double_t cnv = (TMath::Abs(b) < 1.e-5) ? 1.e5 : 1./GetBz()/kB2C;
195 Double_t pp[5] = { p[0]
201 Double_t c22 = x*x*cov[14] - 2*x*cov[12] + cov[ 5];
202 Double_t c32 = x*cov[13] - cov[ 8];
203 Double_t c20 = x*cov[10] - cov[ 3];
204 Double_t c21 = x*cov[11] - cov[ 4];
205 Double_t c42 = x*cov[14] - cov[12];
207 Double_t cc[15] = { cov[ 0]
210 , cov[ 6], cov[ 7], c32, cov[ 9]
211 , cov[10]*cnv, cov[11]*cnv, c42*cnv, cov[13]*cnv, cov[14]*cnv*cnv };
213 Double_t mostProbablePt=AliExternalTrackParam::GetMostProbablePt();
214 Double_t p0=TMath::Sign(1/mostProbablePt,pp[4]);
215 Double_t w0=cc[14]/(cc[14] + p0*p0), w1=p0*p0/(cc[14] + p0*p0);
216 AliDebug(3, Form("Pt mixing : w0[%4.2f] pt0[%5.3f] w1[%4.2f] pt[%5.3f]", w0, 1./p0, w1, 1./pp[4]));
218 pp[4] = w0*p0 + w1*pp[4];
219 cc[10]*=w1; cc[11]*=w1; cc[12]*=w1; cc[13]*=w1; cc[14]*=w1;
221 AliDebug(2, Form("Init @ x[%6.2f] pt[%5.3f]", x, 1./pp[4]));
223 for(int iplane=0; iplane<kNplane; iplane++){
224 fTrackletIndex[iplane] = -1;
225 if(!trklts[iplane].IsOK()) fTracklet[iplane] = NULL;
227 fTracklet[iplane] = &trklts[iplane];
228 ncls += fTracklet[iplane]->GetN();
231 AliKalmanTrack::SetNumberOfClusters(ncls);
232 for(int i =0; i<3; i++) fBudget[i] = 0.;
234 Float_t pid = 1./AliPID::kSPECIES;
235 for(int is =0; is<AliPID::kSPECIES; is++) fPID[is] = pid;
236 SetLabel(-123456789); // reset label
239 //_______________________________________________________________
240 AliTRDtrackV1::~AliTRDtrackV1()
242 // Clean up all objects allocated by the track during its lifetime.
243 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'));
245 if(fBackupTrack) delete fBackupTrack; fBackupTrack = NULL;
247 if(fTrackLow) delete fTrackLow; fTrackLow = NULL;
248 if(fTrackHigh) delete fTrackHigh; fTrackHigh = NULL;
250 for(Int_t ip=0; ip<kNplane; ip++){
251 if(TestBit(kOwner) && fTracklet[ip]) delete fTracklet[ip];
252 fTracklet[ip] = NULL;
253 fTrackletIndex[ip] = -1;
257 //_______________________________________________________________
258 AliTRDtrackV1 &AliTRDtrackV1::operator=(const AliTRDtrackV1 &t)
261 // Assignment operator
265 AliKalmanTrack::operator=(t);
266 ((AliTRDtrackV1 &) t).Copy(*this);
273 //_____________________________________________________________________________
274 void AliTRDtrackV1::Copy(TObject &t) const
280 ((AliTRDtrackV1 &) t).fStatus = fStatus;
281 ((AliTRDtrackV1 &) t).fESDid = fESDid;
282 ((AliTRDtrackV1 &) t).fDE = fDE;
283 ((AliTRDtrackV1 &) t).fkReconstructor = fkReconstructor;
284 ((AliTRDtrackV1 &) t).fBackupTrack = 0x0;
285 ((AliTRDtrackV1 &) t).fTrackLow = 0x0;
286 ((AliTRDtrackV1 &) t).fTrackHigh = 0x0;
288 for(Int_t ip = 0; ip < kNplane; ip++) {
289 ((AliTRDtrackV1 &) t).fTrackletIndex[ip] = fTrackletIndex[ip];
290 ((AliTRDtrackV1 &) t).fTracklet[ip] = fTracklet[ip];
293 ((AliTRDtrackV1 &) t).fTrackLow = new AliExternalTrackParam(*fTrackLow);
296 ((AliTRDtrackV1 &) t).fTrackHigh = new AliExternalTrackParam(*fTrackHigh);
299 for (Int_t i = 0; i < 3; i++) {
300 ((AliTRDtrackV1 &) t).fBudget[i] = fBudget[i];
302 for (Int_t is = 0; is < AliPID::kSPECIES; is++) {
303 ((AliTRDtrackV1 &) t).fPID[is] = fPID[is];
308 //_______________________________________________________________
309 Int_t AliTRDtrackV1::CookLabel(Float_t wrong, Int_t *labs, Float_t *freq)
311 // Set MC label for this track
312 // On demand i.e. if arrays "labs" and "freq" are allocated by user returns :
313 // nlabs = the no of distinct labels
314 // labs = array of distinct labels in decreasing order of frequency
315 // freq = frequency of each label in decreasing order
318 if(!(ncl = GetNumberOfClusters())) return 0;
320 Int_t s[2][kMAXCLUSTERSPERTRACK];
321 for (Int_t i = 0; i < kMAXCLUSTERSPERTRACK; i++) {
326 Int_t label(-123456789), nlabels(0);
327 AliTRDcluster *c(NULL);
328 for (Int_t ip(0); ip < AliTRDgeometry::kNlayer; ip++) {
329 if(fTrackletIndex[ip]<0 || !fTracklet[ip]) continue;
330 for (Int_t ic(0); ic < AliTRDseedV1::kNclusters; ic++) {
331 if(!(c = fTracklet[ip]->GetClusters(ic))) continue;
332 for (Int_t k(0); k < 3; k++) {
333 if ((label = c->GetLabel(k)) < 0) continue;
335 while(j < kMAXCLUSTERSPERTRACK){
336 if(s[0][j]!=label && s[1][j]!=0){j++; continue;}
337 if(!s[1][j]) nlabels++;
338 s[0][j] = label; s[1][j]++;
344 //printf(" Found %4d labels\n", nlabels);
347 AliError(Form("No MC labels found for track %d.", fESDid));
349 } else if(nlabels==1) {
351 if(labs && freq){labs[0]=label; freq[0]=1.;}
353 Int_t idx[kMAXCLUSTERSPERTRACK];
354 TMath::Sort(nlabels, s[1], idx);
355 label = s[0][idx[0]]; prob = s[1][idx[0]]/Float_t(ncl);
357 for (Int_t i(0); i<nlabels; i++){
358 labs[i] = s[0][idx[i]];
359 freq[i] = s[1][idx[i]]/Float_t(ncl);
363 SetLabel((1.-prob > wrong)?-label:label);
367 //_______________________________________________________________
368 Bool_t AliTRDtrackV1::CookPID()
371 // Cook the PID information for the track by delegating the omonim function of the tracklets.
372 // Computes the number of tracklets used. The tracklet information are considered independent.
373 // For the moment no global track measurement of PID is performed as for example to estimate
374 // bremsstrahlung probability based on global chi2 of the track.
376 // The status bit AliESDtrack::kTRDpid is set during the call of AliTRDtrackV1::UpdateESDtrack().The PID performance of the
377 //TRD for tracks with 6 tacklets is displayed below.
379 //<img src="TRD/trackPID.gif">
382 const AliTRDPIDResponse *pidResponse = AliTRDcalibDB::Instance()->GetPIDResponse(fkReconstructor->GetRecoParam()->GetPIDmethod());
384 AliError("PID Response not available");
387 Double_t dEdx[kNplane * (Int_t)AliTRDseedV1::kNdEdxSlices] = {0.};
388 Float_t trackletP[kNplane] = {0.};
390 fNdEdxSlices = pidResponse->GetNumberOfSlices();
391 for(Int_t iseed = 0; iseed < kNplane; iseed++){
392 if(!fTracklet[iseed]) continue;
393 trackletP[iseed] = fTracklet[iseed]->GetMomentum();
394 // if(pidResponse->GetPIDmethod() == AliTRDPIDResponse::kLQ1D){
395 dEdx[iseed] = fTracklet[iseed]->GetdQdl();
397 fTracklet[iseed]->CookdEdx(fNdEdxSlices);
398 const Float_t *trackletdEdx = fTracklet[iseed]->GetdEdx();
399 for(Int_t islice = 0; islice < fNdEdxSlices; islice++){
400 dEdx[iseed*fNdEdxSlices + islice] = trackletdEdx[islice];
404 pidResponse->GetResponse(fNdEdxSlices, dEdx, trackletP, fPID);
406 static Int_t nprint = 0;
408 AliTRDdEdxBaseUtils::PrintControl();
413 AliTRDdEdxCalibUtils::SetObjArray(AliTRDcalibDB::Instance()->GetPHQ());
414 const Double_t mag = AliTRDdEdxBaseUtils::IsExBOn() ? GetBz() : -1;
415 const Double_t charge = AliTRDdEdxBaseUtils::IsExBOn() ? Charge() : -1;
416 fTruncatedMean = CookTruncatedMean(0, mag, charge, kTRUE, fNchamberdEdx, fNclusterdEdx);
421 //___________________________________________________________
422 UChar_t AliTRDtrackV1::GetNumberOfTrackletsPID() const
424 // Retrieve number of tracklets used for PID calculation.
427 for(int ip=0; ip<kNplane; ip++){
428 if(fTrackletIndex[ip]<0 || !fTracklet[ip]) continue;
429 if(!fTracklet[ip]->IsOK()) continue;
436 //_______________________________________________________________
437 AliTRDcluster* AliTRDtrackV1::GetCluster(Int_t id)
439 // Get the cluster at a certain position in the track
441 for(Int_t ip=0; ip<kNplane; ip++){
442 if(!fTracklet[ip]) continue;
443 if(n+fTracklet[ip]->GetN() <= id){
444 n+=fTracklet[ip]->GetN();
447 AliTRDcluster *c = NULL;
448 for(Int_t ic=AliTRDseedV1::kNclusters; ic--;){
449 if(!(c = fTracklet[ip]->GetClusters(ic))) continue;
451 if(n<id){n++; continue;}
458 //_______________________________________________________________
459 Int_t AliTRDtrackV1::GetClusterIndex(Int_t id) const
461 // Get the cluster index at a certain position in the track
463 for(Int_t ip=0; ip<kNplane; ip++){
464 if(!fTracklet[ip]) continue;
465 if(n+fTracklet[ip]->GetN() <= id){
466 n+=fTracklet[ip]->GetN();
469 for(Int_t ic=AliTRDseedV1::kNclusters; ic--;){
470 if(!(fTracklet[ip]->GetClusters(ic))) continue;
471 if(n<id){n++; continue;}
472 return fTracklet[ip]->GetIndexes(ic);
478 //_______________________________________________________________
479 Double_t AliTRDtrackV1::GetPredictedChi2(const AliTRDseedV1 *trklt, Double_t *cov) const
481 // Compute chi2 between tracklet and track. The value is calculated at the radial position of the track
482 // equal to the reference radial position of the tracklet (see AliTRDseedV1)
484 // The chi2 estimator is computed according to the following formula
486 // #chi^{2}=(X_{trklt}-X_{track})(C_{trklt}+C_{track})^{-1}(X_{trklt}-X_{track})^{T}
488 // where X=(y z), the position of the track/tracklet in the yz plane
491 Double_t p[2] = { trklt->GetY(), trklt->GetZ()};
492 trklt->GetCovAt(trklt->GetX(), cov);
493 return AliExternalTrackParam::GetPredictedChi2(p, cov);
496 //_______________________________________________________________
497 Int_t AliTRDtrackV1::GetSector() const
499 return Int_t(GetAlpha()/AliTRDgeometry::GetAlpha() + (GetAlpha()>0. ? 0 : AliTRDgeometry::kNsector));
502 //_______________________________________________________________
503 Bool_t AliTRDtrackV1::IsEqual(const TObject *o) const
505 // Checks whether two tracks are equal
506 if (!o) return kFALSE;
507 const AliTRDtrackV1 *inTrack = dynamic_cast<const AliTRDtrackV1*>(o);
508 if (!inTrack) return kFALSE;
510 //if ( fPIDquality != inTrack->GetPIDquality() ) return kFALSE;
512 if(memcmp(fPID, inTrack->fPID, AliPID::kSPECIES*sizeof(Double32_t))) return kFALSE;
513 if(memcmp(fBudget, inTrack->fBudget, 3*sizeof(Double32_t))) return kFALSE;
514 if(memcmp(&fDE, &inTrack->fDE, sizeof(Double32_t))) return kFALSE;
515 if(memcmp(&fFakeRatio, &inTrack->fFakeRatio, sizeof(Double32_t))) return kFALSE;
516 if(memcmp(&fChi2, &inTrack->fChi2, sizeof(Double32_t))) return kFALSE;
517 if(memcmp(&fMass, &inTrack->fMass, sizeof(Double32_t))) return kFALSE;
518 if( fLab != inTrack->fLab ) return kFALSE;
519 if( fN != inTrack->fN ) return kFALSE;
520 Double32_t l(0.), in(0.);
521 l = GetIntegratedLength(); in = inTrack->GetIntegratedLength();
522 if(memcmp(&l, &in, sizeof(Double32_t))) return kFALSE;
523 l=GetX(); in=inTrack->GetX();
524 if(memcmp(&l, &in, sizeof(Double32_t))) return kFALSE;
525 l = GetAlpha(); in = inTrack->GetAlpha();
526 if(memcmp(&l, &in, sizeof(Double32_t))) return kFALSE;
527 if(memcmp(GetParameter(), inTrack->GetParameter(), 5*sizeof(Double32_t))) return kFALSE;
528 if(memcmp(GetCovariance(), inTrack->GetCovariance(), 15*sizeof(Double32_t))) return kFALSE;
530 for (Int_t iTracklet = 0; iTracklet < kNplane; iTracklet++){
531 AliTRDseedV1 *curTracklet = fTracklet[iTracklet];
532 AliTRDseedV1 *inTracklet = inTrack->GetTracklet(iTracklet);
533 if (curTracklet && inTracklet){
534 if (! curTracklet->IsEqual(inTracklet) ) {
535 curTracklet->Print();
540 // if one tracklet exists, and corresponding
541 // in other track doesn't - return kFALSE
542 if(inTracklet || curTracklet) return kFALSE;
549 //_______________________________________________________________
550 Bool_t AliTRDtrackV1::IsElectron() const
552 if(GetPID(0) > fkReconstructor->GetRecoParam()->GetPIDThreshold(GetP())) return kTRUE;
557 //_____________________________________________________________________________
558 Int_t AliTRDtrackV1::MakeBackupTrack()
561 // Creates a backup track
562 // TO DO update quality check of the track.
565 Float_t occupancy(0.); Int_t n(0), ncls(0);
566 for(Int_t il(AliTRDgeometry::kNlayer); il--;){
567 if(!fTracklet[il]) continue;
569 occupancy+=fTracklet[il]->GetTBoccupancy()/AliTRDseedV1::kNtb;
570 ncls += fTracklet[il]->GetN();
575 //Float_t ratio1 = Float_t(t.GetNumberOfClusters()+1) / Float_t(t.GetNExpected()+1);
577 Int_t failedCutId(0);
578 if(GetChi2()/n > 5.0) failedCutId=1;
579 if(occupancy < 0.7) failedCutId=2;
580 //if(ratio1 > 0.6) &&
581 //if(ratio0+ratio1 > 1.5) &&
582 if(GetNCross() != 0) failedCutId=3;
583 if(TMath::Abs(GetSnp()) > 0.85) failedCutId=4;
584 if(ncls < 20) failedCutId=5;
587 AliDebug(2, Form("\n"
588 "chi2/tracklet < 5.0 [%c] %5.2f\n"
589 "occupancy > 0.7 [%c] %4.2f\n"
590 "NCross == 0 [%c] %d\n"
591 "Abs(snp) < 0.85 [%c] %4.2f\n"
592 "NClusters > 20 [%c] %d"
593 ,(GetChi2()/n<5.0)?'y':'n', GetChi2()/n
594 ,(occupancy>0.7)?'y':'n', occupancy
595 ,(GetNCross()==0)?'y':'n', GetNCross()
596 ,(TMath::Abs(GetSnp())<0.85)?'y':'n', TMath::Abs(GetSnp())
597 ,(ncls>20)?'y':'n', ncls
603 fBackupTrack->~AliTRDtrackV1();
604 new(fBackupTrack) AliTRDtrackV1((AliTRDtrackV1&)(*this));
607 fBackupTrack = new AliTRDtrackV1((AliTRDtrackV1&)(*this));
611 //_____________________________________________________________________________
612 Int_t AliTRDtrackV1::GetProlongation(Double_t xk, Double_t &y, Double_t &z) const
615 // Find a prolongation at given x
616 // Return -1 if it does not exist
619 Double_t bz = GetBz();
620 if (!AliExternalTrackParam::GetYAt(xk,bz,y)) return -1;
621 if (!AliExternalTrackParam::GetZAt(xk,bz,z)) return -1;
627 //_____________________________________________________________________________
628 Bool_t AliTRDtrackV1::PropagateTo(Double_t xk, Double_t xx0, Double_t xrho)
631 // Propagates this track to a reference plane defined by "xk" [cm]
632 // correcting for the mean crossed material.
634 // "xx0" - thickness/rad.length [units of the radiation length]
635 // "xrho" - thickness*density [g/cm^2]
638 if (TMath::Abs(xk - GetX())<AliTRDReconstructor::GetEpsilon()*0.1) return kTRUE; // 10% of the tracker precision
640 Double_t xyz0[3] = {GetX(), GetY(), GetZ()}, // track position BEFORE propagation
641 b[3]; // magnetic field
643 if(!AliExternalTrackParam::PropagateToBxByBz(xk,b)) return kFALSE;
645 // local track position AFTER propagation
646 Double_t xyz1[3] = {GetX(), GetY(), GetZ()};
647 // 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));
650 if (IsStartedTimeIntegral()) {
651 Double_t l2 = TMath::Sqrt((xyz1[0]-xyz0[0])*(xyz1[0]-xyz0[0])
652 + (xyz1[1]-xyz0[1])*(xyz1[1]-xyz0[1])
653 + (xyz1[2]-xyz0[2])*(xyz1[2]-xyz0[2]));
654 Double_t crv = AliExternalTrackParam::GetC(b[2]);
655 if (TMath::Abs(l2*crv) > 0.0001) {
656 // Make correction for curvature if neccesary
657 l2 = 0.5 * TMath::Sqrt((xyz1[0]-xyz0[0])*(xyz1[0]-xyz0[0])
658 + (xyz1[1]-xyz0[1])*(xyz1[1]-xyz0[1]));
659 l2 = 2.0 * TMath::ASin(l2 * crv) / crv;
660 l2 = TMath::Sqrt(l2*l2 + (xyz1[2]-xyz0[2])*(xyz1[2]-xyz0[2]));
665 if (!AliExternalTrackParam::CorrectForMeanMaterial(xx0, xrho, fMass)) return kFALSE;
671 Double_t p2 = (1.0 + GetTgl()*GetTgl()) / (GetSigned1Pt()*GetSigned1Pt());
672 if (fMass<0) p2 *= 4; // q=2
673 Double_t beta2 = p2 / (p2 + fMass*fMass);
674 if ((beta2 < 1.0e-10) ||
675 ((5940.0 * beta2/(1.0 - beta2 + 1.0e-10) - beta2) < 0.0)) {
679 Double_t dE = 0.153e-3 / beta2
680 * (TMath::Log(5940.0 * beta2/(1.0 - beta2 + 1.0e-10)) - beta2)
682 if (fMass<0) dE *= 4; // q=2
686 // Suspicious part - think about it ?
687 Double_t kinE = TMath::Sqrt(p2);
688 if (dE > 0.8*kinE) dE = 0.8 * kinE; //
689 if (dE < 0) dE = 0.0; // Not valid region for Bethe bloch
696 Double_t sigmade = 0.07 * TMath::Sqrt(TMath::Abs(dE)); // Energy loss fluctuation
697 Double_t sigmac2 = sigmade*sigmade*fC*fC*(p2+fMass*fMass)/(p2*p2);
699 fCee += fX*fX * sigmac2;
707 //_____________________________________________________________________________
708 Int_t AliTRDtrackV1::PropagateToR(Double_t r,Double_t step)
711 // Propagate track to the radial position
712 // Rotation always connected to the last track position
720 Double_t radius = TMath::Sqrt(GetX()*GetX() + GetY()*GetY());
722 Double_t dir = (radius > r) ? -1.0 : 1.0;
724 for (Double_t x = radius+dir*step; dir*x < dir*r; x += dir*step) {
727 Double_t alpha = TMath::ATan2(xyz0[1],xyz0[0]);
730 if(GetProlongation(x,y,z)<0) return -1;
731 xyz1[0] = x * TMath::Cos(alpha) + y * TMath::Sin(alpha);
732 xyz1[1] = x * TMath::Sin(alpha) - y * TMath::Cos(alpha);
735 if(AliTracker::MeanMaterialBudget(xyz0,xyz1,param)<=0.) return -1;
737 param[1] = 100000000;
739 PropagateTo(x,param[1],param[0]*param[4]);
744 Double_t alpha = TMath::ATan2(xyz0[1],xyz0[0]);
747 if(GetProlongation(r,y,z)<0) return -1;
748 xyz1[0] = r * TMath::Cos(alpha) + y * TMath::Sin(alpha);
749 xyz1[1] = r * TMath::Sin(alpha) - y * TMath::Cos(alpha);
752 if(AliTracker::MeanMaterialBudget(xyz0,xyz1,param) <= 0.) return -1;
755 param[1] = 100000000;
757 PropagateTo(r,param[1],param[0]*param[4]);
763 //_____________________________________________________________________________
764 void AliTRDtrackV1::Print(Option_t *o) const
766 // Print track status
767 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]));
768 AliInfo(Form("Material[%5.2f %5.2f %5.2f]", fBudget[0], fBudget[1], fBudget[2]));
770 AliInfo(Form("x[%7.2f] t[%7.4f] alpha[%f] mass[%f]", GetX(), GetIntegratedLength(), GetAlpha(), fMass));
771 AliInfo(Form("Ntr[%1d] NtrPID[%1d] Ncl[%3d] lab[%3d]", GetNumberOfTracklets(), GetNumberOfTrackletsPID(), fN, fLab));
774 const Double_t *curP = GetParameter();
775 for (Int_t i = 0; i < 5; i++) printf("%7.2f ", curP[i]);
779 const Double_t *curC = GetCovariance();
780 for (Int_t i = 0, j=4, k=0; i<15; i++, k++){
781 printf("%7.2f ", curC[i]);
787 if(strcmp(o, "a")!=0) return;
789 for(Int_t ip=0; ip<kNplane; ip++){
790 if(!fTracklet[ip]) continue;
791 fTracklet[ip]->Print(o);
796 //_____________________________________________________________________________
797 Bool_t AliTRDtrackV1::Rotate(Double_t alpha, Bool_t absolute)
800 // Rotates track parameters in R*phi plane
801 // if absolute rotation alpha is in global system
802 // otherwise alpha rotation is relative to the current rotation angle
805 if (absolute) alpha -= GetAlpha();
808 return AliExternalTrackParam::Rotate(GetAlpha()+alpha);
811 //___________________________________________________________
812 void AliTRDtrackV1::SetNumberOfClusters()
814 // Calculate the number of clusters attached to this track
817 for(int ip=0; ip<kNplane; ip++){
818 if(fTracklet[ip] && fTrackletIndex[ip] >= 0) ncls += fTracklet[ip]->GetN();
820 AliKalmanTrack::SetNumberOfClusters(ncls);
824 //_______________________________________________________________
825 void AliTRDtrackV1::SetOwner()
828 // Toggle ownership of tracklets
831 if(TestBit(kOwner)) return;
832 for (Int_t ip = 0; ip < kNplane; ip++) {
833 if(fTrackletIndex[ip]<0 || !fTracklet[ip]) continue;
834 fTracklet[ip] = new AliTRDseedV1(*fTracklet[ip]);
835 fTracklet[ip]->SetOwner();
840 //_______________________________________________________________
841 void AliTRDtrackV1::SetTracklet(AliTRDseedV1 *const trklt, Int_t index)
846 Int_t plane = trklt->GetPlane();
848 fTracklet[plane] = trklt;
849 fTrackletIndex[plane] = index;
852 //_______________________________________________________________
853 void AliTRDtrackV1::SetTrackIn()
855 // Save location of birth for the TRD track
856 // If the pointer is not valid allocate memory
858 const AliExternalTrackParam *op = dynamic_cast<const AliExternalTrackParam*>(this);
860 //printf("SetTrackIn() : fTrackLow[%p]\n", (void*)fTrackLow);
862 fTrackLow->~AliExternalTrackParam();
863 new(fTrackLow) AliExternalTrackParam(*op);
864 } else fTrackLow = new AliExternalTrackParam(*op);
867 //_______________________________________________________________
868 void AliTRDtrackV1::SetTrackOut(const AliExternalTrackParam *op)
870 // Save location of death for the TRD track
871 // If the pointer is not valid allocate memory
873 if(!op) op = dynamic_cast<const AliExternalTrackParam*>(this);
875 fTrackHigh->~AliExternalTrackParam();
876 new(fTrackHigh) AliExternalTrackParam(*op);
877 } else fTrackHigh = new AliExternalTrackParam(*op);
880 //_______________________________________________________________
881 void AliTRDtrackV1::UnsetTracklet(Int_t plane)
884 fTrackletIndex[plane] = -1;
885 fTracklet[plane] = NULL;
889 //_______________________________________________________________
890 void AliTRDtrackV1::UpdateChi2(Float_t chi2)
892 // Update chi2/track with one tracklet contribution
893 SetChi2(GetChi2() + chi2);
896 //_______________________________________________________________
897 void AliTRDtrackV1::UpdateESDtrack(AliESDtrack *track)
900 // Update the TRD PID information in the ESD track
903 // Int_t nslices = AliTRDcalibDB::Instance()->GetPIDResponse(fkReconstructor->GetRecoParam()->GetPIDmethod())->GetNumberOfSlices();
904 // number of tracklets used for PID calculation
905 UChar_t nPID = GetNumberOfTrackletsPID();
906 // number of tracklets attached to the track
907 UChar_t nTrk = GetNumberOfTracklets();
908 // pack the two numbers together and store them in the ESD
909 track->SetTRDntracklets(nPID | (nTrk<<3));
910 // allocate space to store raw PID signals dEdx & momentum
911 // independent of the method used to calculate PID (see below AliTRDPIDResponse)
912 track->SetNumberOfTRDslices((AliTRDseedV1::kNdEdxSlices+2)*AliTRDgeometry::kNlayer);
914 Float_t p, sp; Double_t spd;
915 for (Int_t ip = 0; ip < kNplane; ip++) {
916 if(fTrackletIndex[ip]<0 || !fTracklet[ip]) continue;
917 // Fill TRD dEdx info into ESD track
918 // a. Set Summed dEdx into the first slice
919 track->SetTRDslice(fTracklet[ip]->GetdQdl(), ip, 0);
920 // b. Set NN dEdx slices
921 fTracklet[ip]->CookdEdx(AliTRDPIDResponse::kNslicesNN);
922 const Float_t *dedx = fTracklet[ip]->GetdEdx();
923 for (Int_t js(0), ks(1); js < AliTRDPIDResponse::kNslicesNN; js++, ks++, dedx++){
924 if(ks>=AliTRDseedV1::kNdEdxSlices){
925 AliError(Form("Exceed allocated space for dEdx slices."));
928 track->SetTRDslice(*dedx, ip, ks);
930 // fill TRD momentum info into ESD track
931 p = fTracklet[ip]->GetMomentum(&sp); spd = sp;
932 track->SetTRDmomentum(p, ip, &spd);
933 // store global quality per tracklet instead of momentum error
934 // 26.09.11 A.Bercuci
935 // first implementation store no. of time bins filled in tracklet (5bits see "y" bits) and
936 // no. of double clusters in case of pad row cross (4bits see "x" bits)
937 // bit map for tracklet quality xxxxyyyyy
938 // 27.10.11 A.Bercuci
939 // add chamber status bit "z" bit
940 // bit map for tracklet quality zxxxxyyyyy
941 // 12.11.11 A.Bercuci
942 // fit tracklet quality into the field fTRDTimeBin [Char_t]
943 // bit map for tracklet quality zxxyyyyy
944 // The information should be retrieved by the following functions of AliESDtrack for each TRD layer
945 // GetTRDtrkltOccupancy(layer) -> no of TB filled in tracklet
946 // GetTRDtrkltClCross(layer) -> no of TB filled in crossing pad rows
947 // IsTRDtrkltChmbGood(layer) -> status of the chamber from which the tracklet is found
948 Int_t nCross(fTracklet[ip]->IsRowCross()?fTracklet[ip]->GetTBcross():0); if(nCross>3) nCross = 3;
949 Char_t trackletQ = Char_t(fTracklet[ip]->GetTBoccupancy() | (nCross<<5) | (fTracklet[ip]->IsChmbGood()<<7));
950 track->SetTRDTimBin(trackletQ, ip);
952 // store PID probabilities
953 track->SetTRDpid(fPID);
955 //store truncated mean
956 track->SetTRDsignal(fTruncatedMean);
957 track->SetTRDNchamberdEdx(fNchamberdEdx);
958 track->SetTRDNclusterdEdx(fNclusterdEdx);
961 //_______________________________________________________________
962 Double_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
965 //Origin: Xianguo Lu <xianguo.lu@cern.ch>, Marian Ivanov <marian.ivanov@cern.ch>
968 TVectorD arrayQ(200), arrayX(200);
969 ncls = AliTRDdEdxReconUtils::GetArrayClusterQ(kinvq, &arrayQ, &arrayX, this, timeBin0, timeBin1, tstep);
971 const TObjArray *cobj = kcalib ? AliTRDdEdxCalibUtils::GetObj(kinvq, mag, charge) : NULL;
973 const Double_t tmean = AliTRDdEdxReconUtils::ToyCook(kinvq, ncls, &arrayQ, &arrayX, cobj);
975 nch = AliTRDdEdxReconUtils::UpdateArrayX(ncls, &arrayX);
982 //printf("\ntest %.10f %d %d\n", tmean, nch, ncls);
987 //_______________________________________________________________
988 TObject* AliTRDtrackV1::Clone(const char* newname) const
990 // temporary override TObject::Clone to avoid crashes in reco
991 AliTRDtrackV1* src = (AliTRDtrackV1*)this;
992 Bool_t isown = src->IsOwner();
993 AliInfo(Form("src_owner %d",isown));
994 AliTRDtrackV1* dst = new AliTRDtrackV1(*src);