]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDpidESD.cxx
new schema for config
[u/mrichter/AliRoot.git] / TRD / AliTRDpidESD.cxx
index bb017537b7f7e3728bb58c8991da8f732e4cfd42..5021833d0436710890090ba6bb8237e06bcd01c9 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 "Cal/AliTRDCalPIDLQ.h"
 
 ClassImp(AliTRDpidESD)
 
@@ -85,27 +91,50 @@ Int_t AliTRDpidESD::MakePID(AliESD *event)
   //
   //  This function calculates the "detector response" PID probabilities 
   //
+  
+  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;
+      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++) {
-      Double_t mass=AliPID::ParticleMass(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;
-    }
+      p[j]=1.;
+      for (Int_t ilayer=0; ilayer <6; ilayer++) {
+        Double_t dedx=t->GetTRDsignals(ilayer,1);
+        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++) {
+      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;
 }