]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDpidESD.cxx
New Calibration and Trigger classes included
[u/mrichter/AliRoot.git] / TRD / AliTRDpidESD.cxx
index 77c6b8b8e9650b738320871142508c04e834b008..eb4f888c967cedfe10b94286eaa53cfaad716fad 100644 (file)
 
 //-----------------------------------------------------------------
 //           Implementation of the TRD PID class
-// Very naive one... And the implementation is even poorer... 
-// Should be made better by the detector experts...
+// Assigns the electron and pion liklihoods for each ESD track.
+// The function MakePID(AliESD *event) calculates the probability
+// of having dedx and the probability of having timbin at a given 
+// momentum (mom) and particle type k (0 for e) and (2 for pi)
+// from the precalculated timbin distributions. 
+// Prashant Shukla <shukla@pi0.physi.uni-heidelberg.de>
 //-----------------------------------------------------------------
 
 #include "AliTRDpidESD.h"
 #include "AliESD.h"
 #include "AliESDtrack.h"
+#include "AliTRDcalibDB.h"
+#include "AliTRDCalPIDLQ.h"
 
 ClassImp(AliTRDpidESD)
 
@@ -36,17 +42,47 @@ AliTRDpidESD::AliTRDpidESD(Double_t *param)
   fRange=param[2]; // PID "range" (in sigmas)
 }
 
-Double_t AliTRDpidESD::Bethe(Double_t bg) {
+Double_t AliTRDpidESD::Bethe(Double_t bg) 
+{
   //
-  // This is the Bethe-Bloch function normalised to 1 at the minimum
+  // Parametrization of the Bethe-Bloch-curve
+  // The parametrization is the same as for the TPC and is taken from Lehrhaus.
   //
-  Double_t bg2=bg*bg;
-  Double_t bethe;
-  if (bg<3.5e1) 
-      bethe=(1.+ bg2)/bg2*(log(5940*bg2) - bg2/(1.+ bg2));
-  else // Density effect ( approximately :) 
-      bethe=(1.+ bg2)/bg2*(log(3.5*5940*bg) - bg2/(1.+ bg2));
-  return bethe/11.091;
+
+  // This parameters have been adjusted to averaged values from GEANT
+  const Double_t kP1 = 7.17960e-02;
+  const Double_t kP2 = 8.54196;
+  const Double_t kP3 = 1.38065e-06;
+  const Double_t kP4 = 5.30972;
+  const Double_t kP5 = 2.83798;
+
+  // This parameters have been adjusted to Xe-data found in:
+  // Allison & Cobb, Ann. Rev. Nucl. Sci. (1980), 30, 253
+  //const Double_t kP1 = 0.76176E-1;
+  //const Double_t kP2 = 10.632;
+  //const Double_t kP3 = 3.17983E-6;
+  //const Double_t kP4 = 1.8631;
+  //const Double_t kP5 = 1.9479;
+
+  // Lower cutoff of the Bethe-Bloch-curve to limit step sizes
+  const Double_t kBgMin = 0.8;
+  const Double_t kBBMax = 6.83298;
+  //const Double_t kBgMin = 0.6;
+  //const Double_t kBBMax = 17.2809;
+  //const Double_t kBgMin = 0.4;
+  //const Double_t kBBMax = 82.0;
+
+  if (bg > kBgMin) {
+    Double_t yy = bg / TMath::Sqrt(1. + bg*bg);
+    Double_t aa = TMath::Power(yy,kP4);
+    Double_t bb = TMath::Power((1./bg),kP5);
+             bb = TMath::Log(kP3 + bb);
+    return ((kP2 - aa - bb)*kP1 / aa);
+  }
+  else {
+    return kBBMax;
+  }
+
 }
 
 //_________________________________________________________________________
@@ -55,30 +91,50 @@ Int_t AliTRDpidESD::MakePID(AliESD *event)
   //
   //  This function calculates the "detector response" PID probabilities 
   //
-  static const Double_t masses[]={
-    0.000511, 0.105658, 0.139570, 0.493677, 0.938272, 1.875613
-  };
+  
+  AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
+  if (!calibration)
+    return -1;
+  
+  // The class AliTRDCalPIDLQ contains precalculated prob dis.
+  const AliTRDCalPIDLQ *pd = calibration->GetPIDLQObject();
+  if (!pd) return -1;
+
+  //  Example to get mean for particle 2 (pi) and momentum number 4 (2 GeV)
+  //  printf("%.2f \n", pd->GetMean(2, 4));
+  //  Example of use of Copy Constructor 
+  //  AliTRDCalPIDLQ *pd1 = new AliTRDCalPIDLQ(*pd);
+
   Int_t ntrk=event->GetNumberOfTracks();
   for (Int_t i=0; i<ntrk; i++) {
     AliESDtrack *t=event->GetTrack(i);
     if ((t->GetStatus()&AliESDtrack::kTRDin)==0)
-       if ((t->GetStatus()&AliESDtrack::kTRDout)==0)
-          if ((t->GetStatus()&AliESDtrack::kTRDrefit)==0) continue;
-    Int_t ns=AliESDtrack::kSPECIES;
+      if ((t->GetStatus()&AliESDtrack::kTRDout)==0)
+       if ((t->GetStatus()&AliESDtrack::kTRDrefit)==0) continue;
+    if(t->GetTRDsignal()==0) continue;
+    //    Int_t ns=AliESDtrack::kSPECIES;
+    Int_t ns=AliPID::kSPECIES;
     Double_t p[10];
+    Double_t mom=t->GetP();
+    Double_t probTotal=0.0;
+    for (Int_t j=0; j<ns; j++) {
+      p[j]=1.;
+      for (Int_t ilayer=0; ilayer <6; ilayer++) {
+        Double_t dedx=t->GetTRDsignals(ilayer);
+        Int_t timbin=t->GetTRDTimBin(ilayer);
+       p[j]*= pd->GetProbability(j,mom,dedx);
+       p[j]*= pd->GetProbabilityT(j,mom,timbin);
+       p[j]*= 100;
+      } // loop over layers
+      probTotal+=p[j];
+    } //loop over particle species
+    //  printf(" %f  %d  %f  %f  %f \n", mom, timbin, p[0], p[1], p[2]);
     for (Int_t j=0; j<ns; j++) {
-      Double_t mass=masses[j];
-      Double_t mom=t->GetP();
-      Double_t dedx=t->GetTRDsignal()/fMIP;
-      Double_t bethe=Bethe(mom/mass); 
-      Double_t sigma=fRes*bethe;
-      if (TMath::Abs(dedx-bethe) > fRange*sigma) {
-       p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
-        continue;
-      }
-      p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
-    }
+      if(probTotal) p[j]/= probTotal;
+      else p[j]=1.0;
+      //      p[j]=1.;
+    } //loop over particle species
     t->SetTRDpid(p);
-  }
+  } //loop over tracks
   return 0;
 }