]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDtrackV1.cxx
- fixing bug in cluster analyser
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackV1.cxx
index 8e988a10b38201efb2c4b125cb9819dd392c8bfb..baf5286bb1905ddd7ce97537b9a14fda373103c1 100644 (file)
@@ -41,11 +41,12 @@ ClassImp(AliTRDtrackV1)
 //_______________________________________________________________
 AliTRDtrackV1::AliTRDtrackV1() : AliKalmanTrack()
   ,fStatus(0)
+  ,fESDid(0)
   ,fDE(0.)
-  ,fReconstructor(0x0)
-  ,fBackupTrack(0x0)
-  ,fTrackLow(0x0)
-  ,fTrackHigh(0x0)
+  ,fkReconstructor(NULL)
+  ,fBackupTrack(NULL)
+  ,fTrackLow(NULL)
+  ,fTrackHigh(NULL)
 {
   //
   // Default constructor
@@ -58,19 +59,20 @@ AliTRDtrackV1::AliTRDtrackV1() : AliKalmanTrack()
   for(int is =0; is<AliPID::kSPECIES; is++) fPID[is] = pid;
 
   for(int ip=0; ip<kNplane; ip++){
-    fTrackletIndex[ip] = 0xffff;
-    fTracklet[ip]      = 0x0;
+    fTrackletIndex[ip] = -1;
+    fTracklet[ip]      = NULL;
   }
 }
 
 //_______________________________________________________________
 AliTRDtrackV1::AliTRDtrackV1(const AliTRDtrackV1 &ref) : AliKalmanTrack(ref)
   ,fStatus(ref.fStatus)
+  ,fESDid(ref.fESDid)
   ,fDE(ref.fDE)
-  ,fReconstructor(ref.fReconstructor)
-  ,fBackupTrack(0x0)
-  ,fTrackLow(0x0)
-  ,fTrackHigh(0x0)
+  ,fkReconstructor(ref.fkReconstructor)
+  ,fBackupTrack(NULL)
+  ,fTrackLow(NULL)
+  ,fTrackHigh(NULL)
 {
   //
   // Copy constructor
@@ -95,25 +97,27 @@ AliTRDtrackV1::AliTRDtrackV1(const AliTRDtrackV1 &ref) : AliKalmanTrack(ref)
 //_______________________________________________________________
 AliTRDtrackV1::AliTRDtrackV1(const AliESDtrack &t) : AliKalmanTrack()
   ,fStatus(0)
+  ,fESDid(0)
   ,fDE(0.)
-  ,fReconstructor(0x0)
-  ,fBackupTrack(0x0)
-  ,fTrackLow(0x0)
-  ,fTrackHigh(0x0)
+  ,fkReconstructor(NULL)
+  ,fBackupTrack(NULL)
+  ,fTrackLow(NULL)
+  ,fTrackHigh(NULL)
 {
   //
   // Constructor from AliESDtrack
   //
 
+  SetESDid(t.GetID());
   SetLabel(t.GetLabel());
   SetChi2(0.0);
 
   SetMass(t.GetMass()/*0.000510*/);
   AliKalmanTrack::SetNumberOfClusters(t.GetTRDncls()); 
-  Int_t ti[kNplane]; t.GetTRDtracklets(&ti[0]);
+  Int_t ti[]={-1, -1, -1, -1, -1, -1}; t.GetTRDtracklets(&ti[0]);
   for(int ip=0; ip<kNplane; ip++){ 
-    fTrackletIndex[ip] = ti[ip] < 0 ? 0xffff : ti[ip];
-    fTracklet[ip]      = 0x0;
+    fTrackletIndex[ip] = ti[ip];
+    fTracklet[ip]      = NULL;
   }
   for(int i =0; i<3; i++) fBudget[i] = 0.;
   
@@ -143,14 +147,15 @@ AliTRDtrackV1::AliTRDtrackV1(const AliESDtrack &t) : AliKalmanTrack()
 }
 
 //_______________________________________________________________
-AliTRDtrackV1::AliTRDtrackV1(AliTRDseedV1 *trklts, const Double_t p[5], const Double_t cov[15]
+AliTRDtrackV1::AliTRDtrackV1(AliTRDseedV1 * const trklts, const Double_t p[5], const Double_t cov[15]
              , Double_t x, Double_t alpha) : AliKalmanTrack()
   ,fStatus(0)
+  ,fESDid(0)
   ,fDE(0.)
-  ,fReconstructor(0x0)
-  ,fBackupTrack(0x0)
-  ,fTrackLow(0x0)
-  ,fTrackHigh(0x0)
+  ,fkReconstructor(NULL)
+  ,fBackupTrack(NULL)
+  ,fTrackLow(NULL)
+  ,fTrackHigh(NULL)
 {
   //
   // The stand alone tracking constructor
@@ -184,14 +189,18 @@ AliTRDtrackV1::AliTRDtrackV1(AliTRDseedV1 *trklts, const Double_t p[5], const Do
   Double_t mostProbablePt=AliExternalTrackParam::GetMostProbablePt();
   Double_t p0=TMath::Sign(1/mostProbablePt,pp[4]);
   Double_t w0=cc[14]/(cc[14] + p0*p0), w1=p0*p0/(cc[14] + p0*p0);
+  AliDebug(4, Form("Pt mixing : w0[%4.2f] 1/pt0[%5.3f] w1[%4.2f] 1/pt[%5.3f]", w0, 1./p0, w1, 1./pp[4]));
   pp[4] = w0*p0 + w1*pp[4];
+
+
   cc[10]*=w1; cc[11]*=w1; cc[12]*=w1; cc[13]*=w1; cc[14]*=w1;
 
        Set(x,alpha,pp,cc);
+  AliDebug(2, Form("Init @ x[%6.2f] pt[%5.3f]", x, 1./pp[4]));
   Int_t ncls = 0;
        for(int iplane=0; iplane<kNplane; iplane++){
-    fTrackletIndex[iplane] = 0xffff;
-               if(!trklts[iplane].IsOK()) fTracklet[iplane] = 0x0;
+    fTrackletIndex[iplane] = -1;
+               if(!trklts[iplane].IsOK()) fTracklet[iplane] = NULL;
     else{ 
       fTracklet[iplane] = &trklts[iplane];
       ncls += fTracklet[iplane]->GetN();
@@ -211,15 +220,15 @@ AliTRDtrackV1::~AliTRDtrackV1()
   //AliInfo("");
   //printf("I-AliTRDtrackV1::~AliTRDtrackV1() : Owner[%s]\n", TestBit(kOwner)?"YES":"NO");
 
-  if(fBackupTrack) delete fBackupTrack; fBackupTrack = 0x0;
+  if(fBackupTrack) delete fBackupTrack; fBackupTrack = NULL;
 
-  if(fTrackLow) delete fTrackLow; fTrackLow = 0x0;
-  if(fTrackHigh) delete fTrackHigh; fTrackHigh = 0x0;
+  if(fTrackLow) delete fTrackLow; fTrackLow = NULL;
+  if(fTrackHigh) delete fTrackHigh; fTrackHigh = NULL;
 
   for(Int_t ip=0; ip<kNplane; ip++){
     if(TestBit(kOwner) && fTracklet[ip]) delete fTracklet[ip];
-    fTracklet[ip] = 0x0;
-    fTrackletIndex[ip] = 0xffff;
+    fTracklet[ip] = NULL;
+    fTrackletIndex[ip] = -1;
   }
 }
        
@@ -237,9 +246,9 @@ Bool_t AliTRDtrackV1::CookLabel(Float_t wrong)
   
   Bool_t labelAdded;
   Int_t label;
-  AliTRDcluster *c    = 0x0;
+  AliTRDcluster *c    = NULL;
   for (Int_t ip = 0; ip < kNplane; ip++) {
-    if(fTrackletIndex[ip] == 0xffff) continue;
+    if(fTrackletIndex[ip] == -1) continue;
     for (Int_t ic = 0; ic < AliTRDseedV1::kNclusters; ic++) {
       if(!(c = fTracklet[ip]->GetClusters(ic))) continue;
       for (Int_t k = 0; k < 3; k++) { 
@@ -322,9 +331,9 @@ UChar_t AliTRDtrackV1::GetNumberOfTrackletsPID() const
 // Retrieve number of tracklets used for PID calculation. 
 
   UChar_t nPID = 0;
-  Float_t *prob = 0x0;
+  Float_t *prob = NULL;
   for(int ip=0; ip<kNplane; ip++){
-    if(fTrackletIndex[ip] == 0xffff) continue;
+    if(fTrackletIndex[ip] == -1) continue;
     if(!fTracklet[ip]->IsOK()) continue;
     if(!(prob = fTracklet[ip]->GetProbability(kFALSE))) continue;
     
@@ -349,9 +358,9 @@ UChar_t AliTRDtrackV1::SetNumberOfTrackletsPID(Bool_t recalc)
   UChar_t fPIDquality = 0;
   
   // steer PID calculation @ tracklet level
-  Float_t *prob = 0x0;
+  Float_t *prob = NULL;
   for(int ip=0; ip<kNplane; ip++){
-    if(fTrackletIndex[ip] == 0xffff) continue;
+    if(fTrackletIndex[ip] == -1) continue;
     if(!fTracklet[ip]->IsOK()) continue;
     if(!(prob = fTracklet[ip]->GetProbability(recalc))) return 0;
     
@@ -371,6 +380,7 @@ UChar_t AliTRDtrackV1::SetNumberOfTrackletsPID(Bool_t recalc)
 //_______________________________________________________________
 AliTRDcluster* AliTRDtrackV1::GetCluster(Int_t id)
 {
+  // Get the cluster at a certain position in the track
   Int_t n = 0;
   for(Int_t ip=0; ip<kNplane; ip++){
     if(!fTracklet[ip]) continue;
@@ -378,7 +388,7 @@ AliTRDcluster* AliTRDtrackV1::GetCluster(Int_t id)
       n+=fTracklet[ip]->GetN();
       continue;
     }
-    AliTRDcluster *c = 0x0;
+    AliTRDcluster *c = NULL;
     for(Int_t ic=AliTRDseedV1::kNclusters; ic--;){
       if(!(c = fTracklet[ip]->GetClusters(ic))) continue;
 
@@ -386,12 +396,13 @@ AliTRDcluster* AliTRDtrackV1::GetCluster(Int_t id)
       return c;
     }
   }
-  return 0x0;
+  return NULL;
 }
 
 //_______________________________________________________________
 Int_t  AliTRDtrackV1::GetClusterIndex(Int_t id) const
 {
+  // Get the cluster index at a certain position in the track
   Int_t n = 0;
   for(Int_t ip=0; ip<kNplane; ip++){
     if(!fTracklet[ip]) continue;
@@ -399,7 +410,7 @@ Int_t  AliTRDtrackV1::GetClusterIndex(Int_t id) const
       n+=fTracklet[ip]->GetN();
       continue;
     }
-    AliTRDcluster *c = 0x0;
+    AliTRDcluster *c = NULL;
     for(Int_t ic=AliTRDseedV1::kNclusters; ic--;){
       if(!(c = fTracklet[ip]->GetClusters(ic))) continue;
 
@@ -437,6 +448,7 @@ Int_t AliTRDtrackV1::GetSector() const
 //_______________________________________________________________
 Bool_t AliTRDtrackV1::IsEqual(const TObject *o) const
 {
+  // Checks whether two tracks are equal
   if (!o) return kFALSE;
   const AliTRDtrackV1 *inTrack = dynamic_cast<const AliTRDtrackV1*>(o);
   if (!inTrack) return kFALSE;
@@ -493,7 +505,7 @@ Bool_t AliTRDtrackV1::IsEqual(const TObject *o) const
 //_______________________________________________________________
 Bool_t AliTRDtrackV1::IsElectron() const
 {
-  if(GetPID(0) > fReconstructor->GetRecoParam()->GetPIDThreshold(GetP())) return kTRUE;
+  if(GetPID(0) > fkReconstructor->GetRecoParam()->GetPIDThreshold(GetP())) return kTRUE;
   return kFALSE;
 }
 
@@ -540,37 +552,28 @@ Bool_t AliTRDtrackV1::PropagateTo(Double_t xk, Double_t xx0, Double_t xrho)
   // "xrho" - thickness*density    [g/cm^2] 
   // 
 
-  if (xk == GetX()) {
-    return kTRUE;
-  }
-
-  Double_t oldX = GetX();
-  Double_t oldY = GetY();
-  Double_t oldZ = GetZ();
-
-  Double_t bz   = GetBz();
-
-  if (!AliExternalTrackParam::PropagateTo(xk,bz)) {
-    return kFALSE;
-  }
-
-  Double_t x = GetX();
-  Double_t y = GetY();
-  Double_t z = GetZ();
+  if (xk == GetX()) return kTRUE;
 
-  if (oldX < xk) {
+  Double_t xyz0[3] = {GetX(), GetY(), GetZ()}, // track position BEFORE propagation 
+           b[3];    // magnetic field 
+  GetBxByBz(b);
+  if(!AliExternalTrackParam::PropagateToBxByBz(xk,b)) return kFALSE;
+  // local track position AFTER propagation 
+  Double_t xyz1[3] = {GetX(), GetY(), GetZ()};
+  if(xyz0[0] < xk) {
     xrho = -xrho;
     if (IsStartedTimeIntegral()) {
-      Double_t l2  = TMath::Sqrt((x-oldX)*(x-oldX
-                               + (y-oldY)*(y-oldY
-                               + (z-oldZ)*(z-oldZ));
-      Double_t crv = AliExternalTrackParam::GetC(bz);
+      Double_t l2  = TMath::Sqrt((xyz1[0]-xyz0[0])*(xyz1[0]-xyz0[0]
+                               + (xyz1[1]-xyz0[1])*(xyz1[1]-xyz0[1]
+                               + (xyz1[2]-xyz0[2])*(xyz1[2]-xyz0[2]));
+      Double_t crv = AliExternalTrackParam::GetC(b[2]);
       if (TMath::Abs(l2*crv) > 0.0001) {
         // Make correction for curvature if neccesary
-        l2 = 0.5 * TMath::Sqrt((x-oldX)*(x-oldX
-                             + (y-oldY)*(y-oldY));
+        l2 = 0.5 * TMath::Sqrt((xyz1[0]-xyz0[0])*(xyz1[0]-xyz0[0]
+                             + (xyz1[1]-xyz0[1])*(xyz1[1]-xyz0[1]));
         l2 = 2.0 * TMath::ASin(l2 * crv) / crv;
-        l2 = TMath::Sqrt(l2*l2 + (z-oldZ)*(z-oldZ));
+        l2 = TMath::Sqrt(l2*l2 + (xyz1[2]-xyz0[2])*(xyz1[2]-xyz0[2]));
       }
       AddTimeStep(l2);
     }
@@ -675,13 +678,13 @@ Int_t   AliTRDtrackV1::PropagateToR(Double_t r,Double_t step)
 //_____________________________________________________________________________
 void AliTRDtrackV1::Print(Option_t *o) const
 {
+  // Print track status
   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]));
   AliInfo(Form("Material[%5.2f %5.2f %5.2f]", fBudget[0], fBudget[1], fBudget[2]));
 
   AliInfo(Form("x[%7.2f] t[%7.4f] alpha[%f] mass[%f]", GetX(), GetIntegratedLength(), GetAlpha(), fMass));
   AliInfo(Form("Ntr[%1d] NtrPID[%1d] Ncl[%3d] lab[%3d]", GetNumberOfTracklets(), GetNumberOfTrackletsPID(), fN, fLab));
 
-  if(strcmp(o, "a")!=0) return;
   printf("|X| = (");
   const Double_t *curP = GetParameter();
   for (Int_t i = 0; i < 5; i++) printf("%7.2f ", curP[i]);
@@ -696,6 +699,7 @@ void AliTRDtrackV1::Print(Option_t *o) const
       k=-1; j--;
     }
   }
+  if(strcmp(o, "a")!=0) return;
 
   for(Int_t ip=0; ip<kNplane; ip++){
     if(!fTracklet[ip]) continue;
@@ -726,7 +730,7 @@ void AliTRDtrackV1::SetNumberOfClusters()
        
   Int_t ncls = 0;
   for(int ip=0; ip<kNplane; ip++){
-    if(fTracklet[ip] && fTrackletIndex[ip] != 0xffff) ncls += fTracklet[ip]->GetN();
+    if(fTracklet[ip] && fTrackletIndex[ip] != -1) ncls += fTracklet[ip]->GetN();
   }
   AliKalmanTrack::SetNumberOfClusters(ncls);   
 }
@@ -741,7 +745,7 @@ void AliTRDtrackV1::SetOwner()
 
   if(TestBit(kOwner)) return;
   for (Int_t ip = 0; ip < kNplane; ip++) {
-    if(fTrackletIndex[ip] == 0xffff) continue;
+    if(fTrackletIndex[ip] == -1) continue;
     fTracklet[ip] = new AliTRDseedV1(*fTracklet[ip]);
     fTracklet[ip]->SetOwner();
   }
@@ -749,7 +753,7 @@ void AliTRDtrackV1::SetOwner()
 }
 
 //_______________________________________________________________
-void AliTRDtrackV1::SetTracklet(AliTRDseedV1 *trklt, Int_t index)
+void AliTRDtrackV1::SetTracklet(AliTRDseedV1 *const trklt, Int_t index)
 {
   //
   // Set the tracklets
@@ -778,18 +782,19 @@ void AliTRDtrackV1::SetTrackHigh(const AliExternalTrackParam *op)
 void AliTRDtrackV1::UnsetTracklet(Int_t plane)
 {
   if(plane<0 && plane >= kNplane) return;
-  fTrackletIndex[plane] = 0xffff;
-  fTracklet[plane] = 0x0;
+  fTrackletIndex[plane] = -1;
+  fTracklet[plane] = NULL;
 }
 
 
 //_______________________________________________________________
-Bool_t  AliTRDtrackV1::Update(Double_t *p, Double_t *cov, Double_t chi2)
+Bool_t  AliTRDtrackV1::Update(Double_t *p, Double_t *cov, Double_t chi2, Bool_t use)
 {
   //
   // Update track 
   //
-  if(!AliExternalTrackParam::Update(p, cov)) return kFALSE;
+  AliDebug(2, Form("Point:\n  p=[%6.2f %6.2f]\n  V=[%6.2f %6.2f]\n    [%6.2f %6.2f]", p[0], p[1], cov[0], cov[1], cov[1], cov[2]));
+  if(use && !AliExternalTrackParam::Update(p, cov)) return kFALSE;
 
   // Register info to track
   SetNumberOfClusters();
@@ -804,7 +809,7 @@ void AliTRDtrackV1::UpdateESDtrack(AliESDtrack *track)
   // Update the TRD PID information in the ESD track
   //
 
-  Int_t nslices = fReconstructor->IsEightSlices() ? (Int_t)AliTRDpidUtil::kNNslices : (Int_t)AliTRDpidUtil::kLQslices;
+  Int_t nslices = fkReconstructor->GetRecoParam()->IsEightSlices() ? (Int_t)AliTRDpidUtil::kNNslices : (Int_t)AliTRDpidUtil::kLQslices;
   // number of tracklets used for PID calculation
   UChar_t nPID = GetNumberOfTrackletsPID();
   // number of tracklets attached to the track
@@ -816,9 +821,9 @@ void AliTRDtrackV1::UpdateESDtrack(AliESDtrack *track)
   // store raw signals
   Float_t p, sp; Double_t spd;
   for (Int_t ip = 0; ip < kNplane; ip++) {
-    if(fTrackletIndex[ip] == 0xffff) continue;
+    if(fTrackletIndex[ip] == -1) continue;
     if(!fTracklet[ip]->HasPID()) continue;
-    Float_t *dedx = fTracklet[ip]->GetdEdx();
+    const Float_t *dedx = fTracklet[ip]->GetdEdx();
     for (Int_t js = 0; js < nslices; js++, dedx++) track->SetTRDslice(*dedx, ip, js);
     p = fTracklet[ip]->GetMomentum(&sp); spd = sp;
     track->SetTRDmomentum(p, ip, &spd);