]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG3/hfe/AliHFEpid.cxx
compilation warning
[u/mrichter/AliRoot.git] / PWG3 / hfe / AliHFEpid.cxx
index ecdcc7be7ca23b5fdb2f6039e5c586f2ce10500c..4ba66efccb26a4c6d32020d934fcc30313f18e91 100644 (file)
 #include <TAxis.h>
 #include <TClass.h>
 #include <TF1.h>
-#include <THnSparse.h>
 #include <TIterator.h>
 #include <TList.h>
+#include <TMath.h>
 #include <TObjArray.h>
 #include <TObjString.h>
 #include <TString.h>
 
-#include "AliESDpid.h"
-#include "AliESDtrack.h"
 #include "AliLog.h"
 #include "AliPID.h"
+#include "AliVParticle.h"
 
+#include "AliHFEcontainer.h"
 #include "AliHFEpid.h"
-#include "AliHFEpidBase.h"
+#include "AliHFEpidQAmanager.h"
 #include "AliHFEpidITS.h"
 #include "AliHFEpidTPC.h"
 #include "AliHFEpidTRD.h"
 #include "AliHFEpidTOF.h"
+#include "AliHFEpidEMCAL.h"
 #include "AliHFEpidMC.h"
+#include "AliHFEpidBayes.h"
+#include "AliHFEvarManager.h"
 
 ClassImp(AliHFEpid)
 
+const Char_t* AliHFEpid::fgkDetectorName[AliHFEpid::kNdetectorPID + 1] = {
+  "MCPID",
+  "BAYESPID",
+  "ITSPID",
+  "TPCPID",
+  "TRDPID",
+  "TOFPID",
+  "EMCALPID",
+  "UndefinedPID"
+};
+
 //____________________________________________________________
 AliHFEpid::AliHFEpid():
   TNamed(),
   fEnabledDetectors(0),
-  fPIDstrategy(kUndefined),
-  fQAlist(0x0),
-  fDebugLevel(0),
+  fNPIDdetectors(0),
+  fVarManager(NULL),
   fCommonObjects(NULL)
 {
   //
   // Default constructor
   //
   memset(fDetectorPID, 0, sizeof(AliHFEpidBase *) * kNdetectorPID);
+  memset(fDetectorOrder, kUndefined, sizeof(UInt_t) * kNdetectorPID);
+  memset(fSortedOrder, 0, sizeof(UInt_t) * kNdetectorPID);
 }
 
 //____________________________________________________________
 AliHFEpid::AliHFEpid(const Char_t *name):
   TNamed(name, ""),
   fEnabledDetectors(0),
-  fPIDstrategy(kUndefined),
-  fQAlist(NULL),
-  fDebugLevel(0),
+  fNPIDdetectors(0),
+  fVarManager(NULL),
   fCommonObjects(NULL)
 {
   //
@@ -76,10 +90,15 @@ AliHFEpid::AliHFEpid(const Char_t *name):
   // Create PID objects for all detectors
   //
   memset(fDetectorPID, 0, sizeof(AliHFEpidBase *) * kNdetectorPID);
+  memset(fDetectorOrder, kUndefined, sizeof(UInt_t) * kNdetectorPID);
+  memset(fSortedOrder, 0, sizeof(UInt_t) * kNdetectorPID);
+
   fDetectorPID[kMCpid] = new AliHFEpidMC("MCPID");
-  fDetectorPID[kTPCpid] = new AliHFEpidTPC("TRDPID");
+  fDetectorPID[kBAYESpid] = new AliHFEpidBayes("BAYESPID");
+  fDetectorPID[kTPCpid] = new AliHFEpidTPC("TPCPID");
   fDetectorPID[kTRDpid] = new AliHFEpidTRD("TRDPID");
   fDetectorPID[kTOFpid] = new AliHFEpidTOF("TOFPID");
+  fDetectorPID[kEMCALpid] = new AliHFEpidEMCAL("EMCALPID");
 
 }
 
@@ -87,9 +106,8 @@ AliHFEpid::AliHFEpid(const Char_t *name):
 AliHFEpid::AliHFEpid(const AliHFEpid &c):
   TNamed(c),
   fEnabledDetectors(c.fEnabledDetectors),
-  fPIDstrategy(kUndefined),
-  fQAlist(NULL),
-  fDebugLevel(c.fDebugLevel),
+  fNPIDdetectors(c.fNPIDdetectors),
+  fVarManager(c.fVarManager),
   fCommonObjects(NULL)
 {
   //
@@ -115,7 +133,6 @@ AliHFEpid::~AliHFEpid(){
   //
   for(Int_t idet = 0; idet < kNdetectorPID; idet++)
     if(fDetectorPID[idet]) delete fDetectorPID[idet];
-  if(fQAlist) delete fQAlist; fQAlist = NULL;  // Each detector has to care about its Histograms
   ClearCommonObjects();
 }
 
@@ -130,13 +147,8 @@ void AliHFEpid::Copy(TObject &o) const{
   target.ClearCommonObjects();
 
   target.fEnabledDetectors = fEnabledDetectors;
-  target.fPIDstrategy = fPIDstrategy;
-  if(target.fQAlist){
-    delete target.fQAlist; target.fQAlist = NULL;
-  }
-  if(fQAlist) target.fQAlist = new TList;
-  target.fQAlist = 0x0;
-  target.fDebugLevel = fDebugLevel;
+  target.fNPIDdetectors = fNPIDdetectors;
+  target.fVarManager = fVarManager;
  
   // Copy detector PIDs
   for(Int_t idet = 0; idet < kNdetectorPID; idet++){
@@ -146,6 +158,8 @@ void AliHFEpid::Copy(TObject &o) const{
     if(fDetectorPID[idet]) 
       target.fDetectorPID[idet] = dynamic_cast<AliHFEpidBase *>(fDetectorPID[idet]->Clone());
   }
+  memcpy(target.fDetectorOrder, fDetectorOrder, sizeof(UInt_t) * kNdetectorPID);
+  memcpy(target.fSortedOrder, fSortedOrder, sizeof(UInt_t) * kNdetectorPID);
 }
 
 //____________________________________________________________
@@ -170,466 +184,250 @@ void AliHFEpid::ClearCommonObjects(){
 }
 
 //____________________________________________________________
-Bool_t AliHFEpid::InitializePID(TString arg){
+void AliHFEpid::AddDetector(TString detector, UInt_t position){
   //
-  // Initializes PID Object:
-  // + Defines which detectors to use
-  // + Initializes Detector PID objects
-  // + Handles QA
+  // Add Detector in position 
+  //
+  UInt_t detectorID = kUndefined;
+  detector.ToUpper();
+  if(!detector.CompareTo("MC")) detectorID = kMCpid;
+  else if(!detector.CompareTo("BAYES")) detectorID = kBAYESpid;
+  else if(!detector.CompareTo("TPC")) detectorID = kTPCpid;
+  else if(!detector.CompareTo("TRD")) detectorID = kTRDpid;
+  else if(!detector.CompareTo("TOF")) detectorID = kTOFpid;
+  else if(!detector.CompareTo("EMCAL")) detectorID = kEMCALpid;
+  else AliError("Detector not available");
+
+  if(detectorID == kUndefined) return;
+  if(IsDetectorOn(detectorID)) return;
+  SwitchOnDetector(detectorID);
+  fDetectorOrder[detectorID] = position;
+  fNPIDdetectors++;
+}
+
+//____________________________________________________________
+Bool_t AliHFEpid::InitializePID(Int_t run){
+  //
+  // Initializes the PID object
   //
-  
-  Bool_t initFail = kFALSE;
-  if(arg.BeginsWith("Strategy")){
-    // Initialize detector PIDs according to PID Strategies
-    arg.ReplaceAll("Strategy", "");
-    fPIDstrategy = arg.Atoi();
-    AliDebug(1, Form("%s - PID Strategy %d enabled", GetName(), fPIDstrategy));
-    switch(fPIDstrategy){
-      case 0: SwitchOnDetector(kMCpid); break;    // Pure MC PID - only valid in MC mode
-      case 1: InitStrategy1(); break;
-      case 2: InitStrategy2(); break;
-      case 3: InitStrategy3(); break;
-      case 4: InitStrategy4(); break;
-      case 5: InitStrategy5(); break;
-      case 6: InitStrategy6(); break;
-      case 7: InitStrategy7(); break;
-      case 8: InitStrategy8(); break;
-      default: initFail = kFALSE;
-    }
-  } else {
-    // No Strategy defined, Initialize according to detectors specified
-    AliDebug(1, Form("%s - Doing InitializePID for Detectors %s end", GetName(), arg.Data()));
-  
-    TObjArray *detsEnabled = arg.Tokenize(":");
-    TIterator *detIterator = detsEnabled->MakeIterator();
-    TObjString *det = NULL;
-    Int_t detector = -1;
-    TString detectors[kNdetectorPID] = {"MC", "ESD", "ITS", "TPC", "TRD", "TOF"};
-    Int_t nDetectors = 0;
-    while((det = dynamic_cast<TObjString *>(detIterator->Next()))){
-      TString &detstring = det->String();
-      detector = -1;
-      for(Int_t idet = 0; idet < kNdetectorPID; idet++){
-        if(!detstring.CompareTo(detectors[idet])){
-          detector = idet;
-          break;
-        }
-      }
-      if(detector > -1){
-        SwitchOnDetector(detector);
-        nDetectors++;
-      } else AliError(Form("Detector %s not implemented (yet)", detstring.Data()));
-    }
-    if(!nDetectors) initFail = kTRUE;
-  }
-  if(initFail){
-    AliError("Initializaion of the PID Failed");
-    return kFALSE;
-  }
 
-  // Initialize PID Objects
+  if(!TestBit(kDetectorsSorted)) SortDetectors();
   Bool_t status = kTRUE;
   for(Int_t idet = 0; idet < kNdetectorPID; idet++){
     if(!IsDetectorOn(idet)) continue;
     if(fDetectorPID[idet]){ 
-      status &= fDetectorPID[idet]->InitializePID();
-      if(IsQAOn() && status) fDetectorPID[idet]->SetQAOn(fQAlist);
+      status &= fDetectorPID[idet]->InitializePID(run);
       if(HasMCData() && status) fDetectorPID[idet]->SetHasMCData();
     }
   }
+  SetBit(kIsInit);
   PrintStatus();
   return status;
-  AliDebug(1, Form("%s - Done", GetName()));
 }
 
 //____________________________________________________________
-Bool_t AliHFEpid::IsSelected(AliHFEpidObject *track){
+Bool_t AliHFEpid::IsSelected(const AliHFEpidObject * const track, AliHFEcontainer *cont, const Char_t *contname, AliHFEpidQAmanager *pidqa){
   //
-  // Steers PID decision for single detectors respectively combined
-  // PID decision
+  // Select Tracks
   //
-  if(!track->fRecTrack){
-    // MC Event
-    return (TMath::Abs(fDetectorPID[kMCpid]->IsSelected(track)) == 11);
-  }
-  if(fPIDstrategy < 9){
-    AliDebug(1, Form("%s - PID Strategy %d", GetName(), fPIDstrategy));
-    Int_t pid = 0;
-    switch(fPIDstrategy){
-      case 0: pid = IdentifyStrategy0(track); break;
-      case 1: pid = IdentifyStrategy1(track); break;
-      case 2: pid = IdentifyStrategy2(track); break;
-      case 3: pid = IdentifyStrategy3(track); break;
-      case 4: pid = IdentifyStrategy4(track); break;
-      case 5: pid = IdentifyStrategy5(track); break;
-      case 6: pid = IdentifyStrategy6(track); break;
-      case 7: pid = IdentifyStrategy7(track); break;
-      case 8: pid = IdentifyStrategy8(track); break;
-      default: break;
+  Bool_t isSelected = kTRUE;
+  AliDebug(1, Form("Particle used for PID, QA available: %s", pidqa ? "Yes" : "No"));
+  for(UInt_t idet = 0; idet < fNPIDdetectors; idet++){
+    AliDebug(2, Form("Using Detector %s\n", SortedDetectorName(idet)));
+    if(TMath::Abs(fDetectorPID[fSortedOrder[idet]]->IsSelected(track, pidqa)) != 11){
+      isSelected = kFALSE;
+      break;
     }
-    return pid;
-  }
-  if(TESTBIT(fEnabledDetectors, kTPCpid)){
-    if(IsQAOn() && fDebugLevel > 1){ 
-      AliInfo("Filling QA plots");
-      MakePlotsItsTpc(track);  // First fill the QA histograms
+    AliDebug(2, "Particlae selected by detector");
+    if(fVarManager && cont){
+      TString reccontname = contname; reccontname += "Reco";
+      AliDebug(2, Form("Filling container %s", reccontname.Data()));
+      if(fVarManager->IsSignalTrack())
+        fVarManager->FillContainerStepname(cont, reccontname.Data(), SortedDetectorName(idet));
+      if(HasMCData()){
+        TString mccontname = contname; mccontname += "MC";
+        AliDebug(2, Form("MC Information available, Filling container %s", mccontname.Data()));
+        if(fVarManager->IsSignalTrack()) {
+          fVarManager->FillContainerStepname(cont, mccontname.Data(), SortedDetectorName(idet), kTRUE);
+               if(cont->GetCorrelationMatrix("correlationstepafterTOF")){
+                 TString tstept("TOFPID"); 
+                 if(!tstept.CompareTo(SortedDetectorName(idet))) {
+                   fVarManager->FillCorrelationMatrix(cont->GetCorrelationMatrix("correlationstepafterTOF"));
+                   //printf("Step %s\n",(const char*) SortedDetectorName(idet));
+                 }
+               }
+             }
+      }
+      // The PID will NOT fill the double counting information
     }
-    if(TESTBIT(fEnabledDetectors, kTOFpid)){
-      // case TPC-TOF
-      return MakePidTpcTof(track);
-    } else if(TESTBIT(fEnabledDetectors, kTRDpid)){
-      // case TPC-TRD with low level detector Signals
-      return MakePidTpcTrd(track);
-    } else
-      return (TMath::Abs(fDetectorPID[kTPCpid]->IsSelected(track)) ==11);
-  } else if(TESTBIT(fEnabledDetectors, kTRDpid)){
-    return (TMath::Abs(fDetectorPID[kTRDpid]->IsSelected(track)) ==11);
-  } else if(TESTBIT(fEnabledDetectors, kTOFpid)){
-    return (TMath::Abs(fDetectorPID[kTOFpid]->IsSelected(track)) ==11);
   }
-  
-  return kFALSE;
+  return isSelected;
 }
 
 //____________________________________________________________
-Bool_t AliHFEpid::MakePidTpcTof(AliHFEpidObject *track){
+void AliHFEpid::SortDetectors(){
   //
-  // Combines TPC and TOF PID decision
+  // Make sorted list of detectors
   //
-  if(track->fAnalysisType != AliHFEpidObject::kESDanalysis) return kFALSE;
-
-  AliHFEpidTOF *tofPID = dynamic_cast<AliHFEpidTOF*>(fDetectorPID[kTOFpid]);
-  if(!tofPID){
-    AliWarning("TOF pid object is NULL");
-    return kFALSE;
-  }
-
-  AliHFEpidTPC *tpcPID = dynamic_cast<AliHFEpidTPC*>(fDetectorPID[kTPCpid]);
-  if(!tpcPID){
-    AliWarning("TPC pid object is NULL");
-    return kFALSE;
-  }
-  
-  // Use TOF PID to select particles with a sigma to the electron line > defined in initialize PID
-  if(TMath::Abs(tofPID->IsSelected(track)) != 11) return kFALSE;
-  // request TOF PID information, reject if no TOF information is available or if TOF identified as Proton or Kaon
-  // apply cut only up to certain upper momentum cut
-  /*Int_t pidTOF = tofPID->IsSelected(track);
-  Bool_t isRejected = kFALSE;
-  switch(TMath::Abs(pidTOF)){
-    case 321:   if(track->fRecTrack->P() < 1.5) isRejected = kTRUE; break;
-    case 2212:  if(track->fRecTrack->P() < 3) isRejected = kTRUE; break;
-    case 0:     if(track->fRecTrack->P() < 3) isRejected = kTRUE; break;  // No TOF information available
-    default: break;
-  };
-  if(isRejected) return kFALSE;*/
-
-  // Particle passed TOF, let TPC decide, no line crossings defined anymore
-  // request the tpc PID information
-  return (TMath::Abs(tpcPID->IsSelected(track)) == 11);
-}
-
-//____________________________________________________________
-Bool_t AliHFEpid::MakePidTpcTrd(AliHFEpidObject *track){
-  //
-  // Combination of TPC and TRD PID
-  // Fills Histograms TPC Signal vs. TRD signal for different
-  // momentum slices
-  //
-  if(track->fAnalysisType != AliHFEpidObject::kESDanalysis) return kFALSE; //AOD based detector PID combination not yet implemented
-  AliDebug(1, "Analysis Type OK, do PID");
-  AliESDtrack *esdTrack = dynamic_cast<AliESDtrack *>(track->fRecTrack);
-  AliHFEpidTRD *trdPid = dynamic_cast<AliHFEpidTRD *>(fDetectorPID[kTRDpid]);
-  Int_t pdg = TMath::Abs(fDetectorPID[kMCpid]->IsSelected(track));
-  Int_t pid = -1;
-  switch(pdg){
-    case 11:    pid = AliPID::kElectron; break;
-    case 13:    pid = AliPID::kMuon; break;
-    case 211:   pid = AliPID::kPion; break;
-    case 321:   pid = AliPID::kKaon; break;
-    case 2212:  pid = AliPID::kProton; break;
-    default:    pid = -1;
-  };
-  Double_t content[10];
-  content[0] = pid;
-  content[1] = esdTrack->P();
-  content[2] = esdTrack->GetTPCsignal();
-  content[3] = trdPid->GetTRDSignalV1(esdTrack, pid);
-  if(IsQAOn() && fDebugLevel > 1){
-    content[4] = trdPid->GetTRDSignalV2(esdTrack, pid);
-    AliDebug(1, Form("Momentum: %f, TRD Signal: Method 1[%f], Method 2[%f]", content[1], content[3], content[4]));
-    (dynamic_cast<THnSparseF *>(fQAlist->At(kTRDSignal)))->Fill(content);
-  }
-  if(content[1] > 2){ // perform combined
-    AliDebug(1, "Momentum bigger 2 GeV/c, doing combined PID"); 
-    if(content[2] > 65 && content[3] > 500) return kTRUE;
-    else return kFALSE;
-  }
-  else {
-    AliDebug(1, "Momentum smaller 2GeV/c, doing TPC alone PID");
-    return fDetectorPID[kTPCpid]->IsSelected(track) == 11;
-  }
+  if(TestBit(kDetectorsSorted)) return; // Don't sort detectors when they are already sorted
+  TMath::Sort(static_cast<UInt_t>(kNdetectorPID), fDetectorOrder, fSortedOrder, kFALSE);
+  SetBit(kDetectorsSorted);
 }
 
 //____________________________________________________________
-void AliHFEpid::MakePlotsItsTpc(AliHFEpidObject *track){
-  //
-  // Make a plot ITS signal - TPC signal for several momentum bins
-  //
-  if(track->fAnalysisType != AliHFEpidObject::kESDanalysis) return; //AOD based detector PID combination not yet implemented
-  AliESDtrack * esdTrack = dynamic_cast<AliESDtrack *>(track->fRecTrack);
-   // Fill My Histograms for MC PID
-  Int_t pdg = TMath::Abs(fDetectorPID[kMCpid]->IsSelected(track));
-  Int_t pid = -1;
-  switch(pdg){
-    case 11:    pid = AliPID::kElectron; break;
-    case 13:    pid = AliPID::kMuon; break;
-    case 211:   pid = AliPID::kPion; break;
-    case 321:   pid = AliPID::kKaon; break;
-    case 2212:  pid = AliPID::kProton; break;
-    default:    pid = -1;
-  };
-  if(IsQAOn() && fDebugLevel > 0){
-    Double_t content[10];
-    content[0] = pid;
-    content[1] = esdTrack->GetTPCInnerParam() ? esdTrack->GetTPCInnerParam()->P() : esdTrack->P();
-    content[2] = (dynamic_cast<AliHFEpidITS *>(fDetectorPID[kITSpid]))->GetITSSignalV1(track->fRecTrack, pid);
-    content[3] = esdTrack->GetTPCsignal();
-    AliDebug(1, Form("Momentum %f, TPC Signal %f, ITS Signal %f", content[1], content[2], content[3]));
-    (dynamic_cast<THnSparseF *>(fQAlist->At(kITSSignal)))->Fill(content);
-  }
-}
-
-//____________________________________________________________
-void AliHFEpid::SetESDpid(AliESDpid *pid){
+void AliHFEpid::SetPIDResponse(const AliPIDResponse * const pid){
   //
   // Set ESD PID to the Detector PID objects
   //
   for(Int_t idet = 0; idet < kNdetectorPID; idet++){
-    if(fDetectorPID[idet]) fDetectorPID[idet]->SetESDpid(pid);
+    if(fDetectorPID[idet]) fDetectorPID[idet]->SetPIDResponse(pid);
   }
 }
 
 //____________________________________________________________
-void AliHFEpid::SetQAOn(){
-  //
-  // Switch on QA
-  //
-  SetBit(kIsQAOn, kTRUE);
-  AliInfo("QA switched on");
-  if(fQAlist) return;
-  fQAlist = new TList;
-  fQAlist->SetName("PIDqa");
-  THnSparseF *histo = NULL;
-
-  // Prepare axis for QA histograms
-  const Int_t kMomentumBins = 41;
-  const Double_t kPtMin = 0.1;
-  const Double_t kPtMax = 10.;
-  Double_t momentumBins[kMomentumBins];
-  for(Int_t ibin = 0; ibin < kMomentumBins; ibin++)
-    momentumBins[ibin] = static_cast<Double_t>(TMath::Power(10,TMath::Log10(kPtMin) + (TMath::Log10(kPtMax)-TMath::Log10(kPtMin))/(kMomentumBins-1)*static_cast<Double_t>(ibin)));
-
-  // Add Histogram for combined TPC-TRD PID
-  if(fDebugLevel > 1){
-    AliDebug(1, "Adding histogram for ITS-TPC investigation");
-    const Int_t kDimensionsTRDsig = 5;
-    Int_t kNbinsTRDsig[kDimensionsTRDsig] = {AliPID::kSPECIES + 1, kMomentumBins - 1, 200, 3000, 3000};
-    Double_t binMinTRDsig[kDimensionsTRDsig] = {-1., 0.1, 0, 0, 0};
-    Double_t binMaxTRDsig[kDimensionsTRDsig] = {AliPID::kSPECIES, 10., 200., 3000., 3000.};
-    fQAlist->AddAt((histo = new THnSparseF("fCombTPCTRDpid", "Combined TPC-TRD PID", kDimensionsTRDsig, kNbinsTRDsig, binMinTRDsig, binMaxTRDsig)), kTRDSignal);
-    histo->GetAxis(1)->Set(kMomentumBins - 1, momentumBins);
-    histo->GetAxis(0)->SetTitle("Particle Species");
-    histo->GetAxis(1)->SetTitle("p / GeV/c");
-    histo->GetAxis(2)->SetTitle("TPC Signal / a.u.");
-    histo->GetAxis(3)->SetTitle("TRD Signal / a.u.");
-    histo->GetAxis(4)->SetTitle("TRD Signal / a.u.");
-  }
-
-  // Add Histogram for combined TPC-ITS PID
-  if(fDebugLevel > 0){
-    AliDebug(1, "Adding histogram for TPC-TRD investigation");
-    const Int_t kDimensionsITSsig = 4;
-    Int_t kNbinsITSsig[kDimensionsITSsig] = {AliPID::kSPECIES + 1, kMomentumBins - 1, 300, 3000};
-    Double_t binMinITSsig[kDimensionsITSsig] = {-1., 0.1, 0., 0.};
-    Double_t binMaxITSsig[kDimensionsITSsig] = {AliPID::kSPECIES, 10., 300., 300.};
-    fQAlist->AddAt((histo = new THnSparseF("fCombTPCITSpid", "Combined TPC-ITS PID", kDimensionsITSsig, kNbinsITSsig, binMinITSsig, binMaxITSsig)), kITSSignal);
-    histo->GetAxis(1)->Set(kMomentumBins - 1, momentumBins);
-    histo->GetAxis(0)->SetTitle("Particle Species");
-    histo->GetAxis(1)->SetTitle("p / GeV/c");
-    histo->GetAxis(2)->SetTitle("ITS Signal / a.u.");
-    histo->GetAxis(3)->SetTitle("TPC Signal / a.u.");
-  }
-}
-
-//____________________________________________________________
-void AliHFEpid::InitStrategy1(){
+const AliPIDResponse *AliHFEpid::GetPIDResponse() const {
   //
-  // TPC alone, 3-sigma cut
+  // Return PID response function
   //
-  AliHFEpidTPC *pid = dynamic_cast<AliHFEpidTPC *>(fDetectorPID[kTPCpid]);
-  pid->SetTPCnSigma(1);
-  SwitchOnDetector(kTPCpid);
+  const AliPIDResponse *response = NULL;
+  for(Int_t idet = 0; idet < kNdetectorPID; idet++){
+    if(fDetectorPID[idet]){
+      response = fDetectorPID[idet]->GetPIDResponse();
+      break;
+    }
+  } 
+  return response;
 }
 
 //____________________________________________________________
-void AliHFEpid::InitStrategy2(){
+void AliHFEpid::ConfigureTPCasymmetric(Double_t pmin, Double_t pmax, Double_t sigmamin, Double_t sigmamax){
   //
   // TPC alone, symmetric 3 sigma cut and asymmetric sigma cut in the momentum region between 2GeV/c and 10 GeV/c and sigma between -1 and 100
   //
   AliHFEpidTPC *pid = dynamic_cast<AliHFEpidTPC *>(fDetectorPID[kTPCpid]);
-  pid->SetTPCnSigma(3);
-  pid->SetAsymmetricTPCsigmaCut(2., 10., 0., 4.);
-  SwitchOnDetector(kTPCpid);
+  if(pid){
+    pid->SetTPCnSigma(3);
+    pid->SetAsymmetricTPCsigmaCut(pmin, pmax, sigmamin, sigmamax);
+  }
 }
 
 //____________________________________________________________
-void AliHFEpid::InitStrategy3(){
+void AliHFEpid::ConfigureTPCrejectionSimple(){
   //
   // TPC alone, symmetric 3 sigma cut and 2 - -100 sigma pion rejection
   //   
   AliHFEpidTPC *pid = dynamic_cast<AliHFEpidTPC *>(fDetectorPID[kTPCpid]);
-  pid->SetTPCnSigma(3);
-  pid->SetRejectParticle(AliPID::kPion, 0., -100., 10., 1.);
-  SwitchOnDetector(kTPCpid);
+  if(pid){
+    pid->SetTPCnSigma(3);
+    pid->SetRejectParticle(AliPID::kPion, 0., -100., 10., 1.);
+  }
 }
 
 //____________________________________________________________
-void AliHFEpid::InitStrategy4(){
+void AliHFEpid::ConfigureTOF(Float_t TOFCut){
   //
-  // TPC and TRD combined, TPC 3 sigma cut and TRD NN 90% el efficiency level above 2 GeV/c
+  // Set Number of sigmas for TOF PID
   //
-  InitStrategy1();
-  AliHFEpidTRD *trdpid = dynamic_cast<AliHFEpidTRD *>(fDetectorPID[kTRDpid]);
-  trdpid->SetPIDMethod(AliHFEpidTRD::kLQ);
-  trdpid->SetElectronEfficiency(0.71);
-  SwitchOnDetector(kTRDpid);
+  AliHFEpidTOF *tofpid = dynamic_cast<AliHFEpidTOF *>(fDetectorPID[kTOFpid]);
+  if(tofpid) tofpid->SetTOFnSigma(TOFCut);
 }
 
 //____________________________________________________________
-void AliHFEpid::InitStrategy5(){
+void AliHFEpid::ConfigureTPCcentralityCut(Int_t centralityBin, const char *lowerCutParam, const Double_t * const params, Float_t upperTPCCut){
   //
-  // TPC and TRD combined, TPC 3 sigma cut and TRD NN 90% el efficiency level above 2 GeV/c
+  // Cofigure centrality dependent cut function for TPC PID 
   //
-  InitStrategy1();
-  SwitchOnDetector(kTRDpid);
+  ConfigureTPCcut(centralityBin, lowerCutParam, params, upperTPCCut);
 }
 
 //____________________________________________________________
-void AliHFEpid::InitStrategy6(){
+void AliHFEpid::ConfigureTPCdefaultCut(const char *lowerCutParam, const Double_t * const params, Float_t upperTPCCut){
   //
-  // Combined TPC-TOF PID, combination is discribed in the funtion MakePidTpcTof
+  // Cofigure default cut function for TPC PID 
   //
-  AliHFEpidTPC *tpcpid = dynamic_cast<AliHFEpidTPC *>(fDetectorPID[kTPCpid]);
-  AliHFEpidTOF *tofpid = dynamic_cast<AliHFEpidTOF *>(fDetectorPID[kTOFpid]);
-  tpcpid->SetTPCnSigma(2);
-  tofpid->SetTOFnSigma(3);
-  //TF1 *upperCut = new TF1("upperCut", "[0] * TMath::Exp([1]*x)", 0, 20);
-  TF1 *upperCut = new TF1("upperCut", "[0]", 0, 20); // Use constant upper cut
-  TF1 *lowerCut = new TF1("lowerCut", "[0] * TMath::Exp([1]*x) + [2]", 0, 20);
-  upperCut->SetParameter(0, 5.);
-  //upperCut->SetParameter(0, 2.7);
-  //upperCut->SetParameter(1, -0.4357);
-  lowerCut->SetParameter(0, -2.65);
-  lowerCut->SetParameter(1, -0.8757);
-//  lowerCut->SetParameter(2, -1);
-  if(HasMCData()) lowerCut->SetParameter(2, -0.9);
-  else lowerCut->SetParameter(2, 0);
-  tpcpid->SetUpperSigmaCut(upperCut);
-  tpcpid->SetLowerSigmaCut(lowerCut);
-  AddCommonObject(upperCut);
-  AddCommonObject(lowerCut);
-  SwitchOnDetector(kTPCpid);
-  SwitchOnDetector(kTOFpid);
+  ConfigureTPCcut(-1, lowerCutParam, params, upperTPCCut);
 }
 
 //____________________________________________________________
-void AliHFEpid::InitStrategy7(){
+void AliHFEpid::ConfigureTPCcut(Int_t centralityBin, const char *lowerCutParam, const Double_t * const params, Float_t upperTPCCut){
   //
-  // TPC alone, symmetric 3 sigma cut and 2 - -100 sigma pion rejection
-  //   
-  AliHFEpidTPC *pid = dynamic_cast<AliHFEpidTPC *>(fDetectorPID[kTPCpid]);
-  pid->SetTPCnSigma(2);
-  pid->SetRejectParticle(AliPID::kProton, 0., -3., 10., 3.);
-  pid->SetRejectParticle(AliPID::kKaon, 0., -3., 10., 3.);
-  SwitchOnDetector(kTPCpid);
-}
-
-//____________________________________________________________
-void AliHFEpid::InitStrategy8(){
+  // Cofigure cut function for TPC PID 
+  // if no function parameterizaion is given, then the default one (exponential) is chosen
   //
-  // TOF, TRD and TPC together
-  // 
+  
+  if(HasMCData()) AliInfo("Configuring TPC for MC\n");
   AliHFEpidTPC *tpcpid = dynamic_cast<AliHFEpidTPC *>(fDetectorPID[kTPCpid]);
-  AliHFEpidTOF *tofpid = dynamic_cast<AliHFEpidTOF *>(fDetectorPID[kTOFpid]);
-  AliHFEpidTRD *trdpid = dynamic_cast<AliHFEpidTRD *>(fDetectorPID[kTRDpid]);
-
-  tpcpid->SetTPCnSigma(3);
-  tofpid->SetTOFnSigma(3);
-  trdpid->SetPIDMethod(AliHFEpidTRD::kLQ);
-  trdpid->SetElectronEfficiency(0.71);
-  SwitchOnDetector(kTPCpid);
-  SwitchOnDetector(kTOFpid);
-  SwitchOnDetector(kTRDpid);
-}
+  //TF1 *upperCut = new TF1("upperCut", "[0] * TMath::Exp([1]*x)", 0, 20);
+  TF1 *upperCut = new TF1(Form("upperCut%s", centralityBin <  0 ? "Default" : Form("Bin%d", centralityBin)), "[0]", 0, 20); // Use constant upper cut
+  TF1 *lowerCut = new TF1(Form("lowerCut%s", centralityBin <  0 ? "Default" : Form("Bin%d", centralityBin)), lowerCutParam == NULL ? "[0] * TMath::Exp([1]*x) + [2]": lowerCutParam, 0, 20);
 
+  upperCut->SetParameter(0, upperTPCCut); // pp
 
-//____________________________________________________________
-Bool_t AliHFEpid::IdentifyStrategy0(AliHFEpidObject *track){
-  return TMath::Abs(fDetectorPID[kMCpid]->IsSelected(track)) == 11;
-}
-
-//____________________________________________________________
-Bool_t AliHFEpid::IdentifyStrategy1(AliHFEpidObject *track){
-  return TMath::Abs(fDetectorPID[kTPCpid]->IsSelected(track)) == 11;
-}
+  if(params){
+      for(Int_t ipar = 0; ipar < lowerCut->GetNpar(); ipar++)
+      {
+         lowerCut->SetParameter(ipar, params[ipar]);
+        //  printf("printout %i %s %f \n", centralityBin, lowerCutParam, params[ipar]);
+      }
+  } else {
+    // Set default parameterization
+    if(HasMCData()) lowerCut->SetParameter(0, -2.5);
+    else lowerCut->SetParameter(0, -4.03);  //pp
+    lowerCut->SetParameter(1, -0.22); // pp
+    
+    if(HasMCData()) lowerCut->SetParameter(2, -2.2);
+    else lowerCut->SetParameter(2, 0.92); //pp
+  }
 
-//____________________________________________________________
-Bool_t AliHFEpid::IdentifyStrategy2(AliHFEpidObject *track){
-  return TMath::Abs(fDetectorPID[kTPCpid]->IsSelected(track)) == 11;
-}
 
-//____________________________________________________________
-Bool_t AliHFEpid::IdentifyStrategy3(AliHFEpidObject *track){
-  return TMath::Abs(fDetectorPID[kTPCpid]->IsSelected(track)) == 11;
+  if(tpcpid){
+    tpcpid->SetTPCnSigma(2);
+    if(centralityBin < 0){
+      tpcpid->SetUpperSigmaCutDefault(upperCut);
+      tpcpid->SetLowerSigmaCutDefault(lowerCut);
+    } else {
+      tpcpid->SetUpperSigmaCutCentrality(upperCut, centralityBin);
+      tpcpid->SetLowerSigmaCutCentrality(lowerCut, centralityBin);
+    }
+  }
+  AddCommonObject(upperCut);
+  AddCommonObject(lowerCut);
 }
 
 //____________________________________________________________
-Bool_t AliHFEpid::IdentifyStrategy4(AliHFEpidObject *track){
-  Int_t trdpid = TMath::Abs(fDetectorPID[kTRDpid]->IsSelected(track));
-  return (trdpid == 0 || trdpid == 11) && (TMath::Abs(fDetectorPID[kTPCpid]->IsSelected(track)) == 11);
-}
+void AliHFEpid::ConfigureBayesDetectorMask(Int_t detmask){
+  //
+  // Configure detector mask for Bayes PID
+  // if no detector mask is set the default mask is chosen
+  //
+  
+  if(HasMCData()) AliInfo("Configuring Bayes for MC\n");
+  AliHFEpidBayes *bayespid = dynamic_cast<AliHFEpidBayes *>(fDetectorPID[kBAYESpid]);
 
-//____________________________________________________________
-Bool_t AliHFEpid::IdentifyStrategy5(AliHFEpidObject *track){
-  return MakePidTpcTrd(track);
-}
+  if(bayespid)
+  {
+      bayespid->SetBayesDetectorMask(detmask);
+      printf("detector mask in pid class %i \n",detmask);
+  }
 
-//____________________________________________________________
-Bool_t AliHFEpid::IdentifyStrategy6(AliHFEpidObject *track){
-  return MakePidTpcTof(track);
 }
 
 //____________________________________________________________
-Bool_t AliHFEpid::IdentifyStrategy7(AliHFEpidObject *track){
+void AliHFEpid::ConfigureBayesPIDThreshold(Float_t pidthres){
   //
-  // Do PID in strategy 7: Proton and Kaon rejection and 
-  // lower cut on TPC Signal
+  // Configure pid threshold for Bayes PID
+  // if no threshold is set the default threshold is chosen
   //
-  if(!(TMath::Abs(fDetectorPID[kTPCpid]->IsSelected(track)) == 11))
-    return kFALSE;
-  return kTRUE;
-}
+  
+  if(HasMCData()) AliInfo("Configuring Bayes for MC\n");
+  AliHFEpidBayes *bayespid = dynamic_cast<AliHFEpidBayes *>(fDetectorPID[kBAYESpid]);
+
+  if(bayespid)
+  {
+      bayespid->SetBayesPIDThreshold(pidthres);
+      printf("combined pidthreshold %f \n",pidthres);
+  }
 
-//____________________________________________________________
-Bool_t AliHFEpid::IdentifyStrategy8(AliHFEpidObject *track){
-  // 
-  // Identify TPC, TRD, TOF
-  //
-  if(TMath::Abs(fDetectorPID[kTOFpid]->IsSelected(track)) != 11) return kFALSE;
-  Int_t trdpid = TMath::Abs(fDetectorPID[kTRDpid]->IsSelected(track));
-  return (trdpid == 0 || trdpid == 11) && (TMath::Abs(fDetectorPID[kTPCpid]->IsSelected(track)) == 11);
 }
 
 //____________________________________________________________
@@ -639,10 +437,9 @@ void AliHFEpid::PrintStatus() const {
   //
   printf("\n%s: Printing configuration\n", GetName());
   printf("===============================================\n");
-  printf("PID Strategy: %d\n", fPIDstrategy);
   printf("PID Detectors: \n");
   Int_t npid = 0;
-  TString detectors[kNdetectorPID] = {"MC", "ESD", "ITS", "TPC", "TRD", "TOF"};
+  TString detectors[kNdetectorPID] = {"MC", "BAYES", "ITS", "TPC", "TRD", "TOF", "EMCAL"};
   for(Int_t idet = 0; idet < kNdetectorPID; idet++){
     if(IsDetectorOn(idet)){
       printf("\t%s\n", detectors[idet].Data());