]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG3/hfe/AliHFEelecbackground.cxx
Coverity fixes (Ivana, Markus)
[u/mrichter/AliRoot.git] / PWG3 / hfe / AliHFEelecbackground.cxx
index 74211b0997ad5f05f4923392967af03287731a7c..20fa73367249bc6d5962a3485d55ddcea345190f 100644 (file)
@@ -12,6 +12,9 @@
  * about the suitability of this software for any purpose. It is          *
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
+
+/* $Id$ */
+
 //
 //
 // First implementation of a class
@@ -52,6 +55,7 @@
 #include "AliCFContainer.h"
 #include "AliHFEpid.h"
 #include "AliESDpid.h"
+#include "AliLog.h"
 #include "AliITSPIDResponse.h"
 #include "AliTPCPIDResponse.h"
 
@@ -62,7 +66,10 @@ const Double_t    AliHFEelecbackground::fgkMe = 0.00051099892;
 
 //___________________________________________________________________________________________
 AliHFEelecbackground::AliHFEelecbackground():
-  fESD1(0x0)
+  fhtmp(0x0)
+  ,fhtmpf(0x0)
+  ,fhtmpp(0x0)
+  ,fESD1(0x0)
   ,fAOD1(0x0)
   ,fMCEvent(0x0)
   ,fBz(0)
@@ -98,12 +105,18 @@ AliHFEelecbackground::AliHFEelecbackground():
   //
   // Default constructor
   //
+  for(Int_t k =0; k < 10; k++) {
+    fCuts[k] = kFALSE;
+  }
   
 }
 
 //_______________________________________________________________________________________________
 AliHFEelecbackground::AliHFEelecbackground(const AliHFEelecbackground &p):
   TObject(p)
+  ,fhtmp(0x0)
+  ,fhtmpf(0x0)
+  ,fhtmpp(0x0)
   ,fESD1(0x0)
   ,fAOD1(0x0)
   ,fMCEvent(0x0)
@@ -140,6 +153,9 @@ AliHFEelecbackground::AliHFEelecbackground(const AliHFEelecbackground &p):
   //
   // Copy constructor
   //
+  for(Int_t k =0; k < 10; k++) {
+    fCuts[k] = kFALSE;
+  }
 }
 
 //_______________________________________________________________________________________________
@@ -163,15 +179,17 @@ AliHFEelecbackground::~AliHFEelecbackground()
   if(fPIDMethodPartner) delete fPIDMethodPartner;
   if(fPIDMethodPartnerITS) delete fPIDMethodPartnerITS;
 
-  if(fList){
-    fList->Clear();
-    delete fList;
-  }
-
   if(fListPostProcess){
-    fListPostProcess->Clear();
+    fListPostProcess->SetOwner(kTRUE);
     delete fListPostProcess;
   }
+
+/*
+  if(fhtmp) delete fhtmp;
+  if(fhtmpf) delete fhtmpf;
+  if(fhtmpp) delete fhtmpp;
+*/
+
 }
 //___________________________________________________________________________________________
 Bool_t AliHFEelecbackground::Load(const Char_t * filename)
@@ -624,8 +642,9 @@ void AliHFEelecbackground::PairAnalysis(AliESDtrack* const track, AliESDtrack* c
       cuteffect[0] = fPtESD;
       cuteffect[1] = 0.0;
       cuteffect[2] = fIsFrom;
-      if(!fCuts[0]) {
-       if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
+      if(!fCuts[0]){
+       if((fhtmp = dynamic_cast<THnSparseF *>(fList->At(kMCe)))) fhtmp->Fill(cuteffect);
+       //if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
        fCuts[0] = kTRUE;
       }
     }
@@ -640,7 +659,8 @@ void AliHFEelecbackground::PairAnalysis(AliESDtrack* const track, AliESDtrack* c
     if(HasMCData() && fIsPartner) {
       cuteffect[1] = 1.0;
       if(!fCuts[1]) {
-       if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
+       if((fhtmp = dynamic_cast<THnSparseF *>(fList->At(kMCe)))) fhtmp->Fill(cuteffect);
+       //if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
        fCuts[1] = kTRUE;
       }
     }
@@ -654,7 +674,8 @@ void AliHFEelecbackground::PairAnalysis(AliESDtrack* const track, AliESDtrack* c
     if(HasMCData() && fIsPartner && (sign == kOs)) {
       cuteffect[1] = 2.0;
       if(!fCuts[2]) {
-       if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
+       if((fhtmp = dynamic_cast<THnSparseF *>(fList->At(kMCe)))) fhtmp->Fill(cuteffect);
+       //if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
        fCuts[2] = kTRUE;
       }
     }
@@ -669,7 +690,8 @@ void AliHFEelecbackground::PairAnalysis(AliESDtrack* const track, AliESDtrack* c
     if(HasMCData() && fIsPartner && (sign==kOs)) {
       cuteffect[1] = 3.0;
       if(!fCuts[3]) {
-       if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
+       if((fhtmp = dynamic_cast<THnSparseF *>(fList->At(kMCe)))) fhtmp->Fill(cuteffect);
+       //if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
        fCuts[3] = kTRUE;
       }
     }
@@ -684,7 +706,8 @@ void AliHFEelecbackground::PairAnalysis(AliESDtrack* const track, AliESDtrack* c
     if(HasMCData() && fIsPartner && (sign==kOs)) {
       cuteffect[1] = 4.0;
       if(!fCuts[4]) {
-       if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
+       if((fhtmp = dynamic_cast<THnSparseF *>(fList->At(kMCe)))) fhtmp->Fill(cuteffect);
+       //if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
        fCuts[4] = kTRUE;
       }
     } 
@@ -699,7 +722,8 @@ void AliHFEelecbackground::PairAnalysis(AliESDtrack* const track, AliESDtrack* c
     if(HasMCData() && fIsPartner && (sign==kOs)) {
       cuteffect[1] = 5.0;
       if(!fCuts[5]) {
-       if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
+       if((fhtmp = dynamic_cast<THnSparseF *>(fList->At(kMCe)))) fhtmp->Fill(cuteffect);
+       //if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
        fCuts[5] = kTRUE;
       }
     }
@@ -712,22 +736,28 @@ void AliHFEelecbackground::PairAnalysis(AliESDtrack* const track, AliESDtrack* c
   
   Double_t xthis,xp;
   Double_t dca = track->GetDCA(trackPart,fBz,xthis,xp);
-  (dynamic_cast<TH1F *>(fList->At(kDatadca)))->Fill(dca);
+  if((fhtmpp = dynamic_cast<TH1F *>(fList->At(kDatadca)))) fhtmpp->Fill(dca);
   if(HasMCData()) {
     //printf("has MC data for DCA\n");
     //printf("IsPartner %d and isfrom %d\n",fIsPartner,fIsFrom);
-    if((fIsFrom==kElectronFromBackground) && (fList->At(kMCdca))) (dynamic_cast<TH2F *>(fList->At(kMCdca)))->Fill(dca,fIsFrom);
+    if(fIsFrom==kElectronFromBackground) {
+      if((fhtmpf = dynamic_cast<TH2F *>(fList->At(kMCdca)))) fhtmpf->Fill(dca,fIsFrom);
+    }
     else {
-      if(fIsPartner && (fList->At(kMCdca))) (dynamic_cast<TH2F *>(fList->At(kMCdca)))->Fill(dca,fIsFrom);
+      if(fIsPartner){
+       if((fhtmpf = dynamic_cast<TH2F *>(fList->At(kMCdca)))) fhtmpf->Fill(dca,fIsFrom);
+      }
     }
   }
+   
   if(TMath::Abs(dca) > 3.0) return;
-
+  
   if(fDebugLevel > 0) {  
     if(HasMCData() && fIsPartner && (sign==kOs)) {
       cuteffect[1] = 6.0;
       if(!fCuts[6]) {
-       if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
+       if((fhtmp = dynamic_cast<THnSparseF *>(fList->At(kMCe)))) fhtmp->Fill(cuteffect);
+       //if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
        fCuts[6] = kTRUE;
       }
     }
@@ -748,21 +778,21 @@ void AliHFEelecbackground::PairAnalysis(AliESDtrack* const track, AliESDtrack* c
     
     Double_t norradius = TMath::Sqrt(fkVertex->GetX()*fkVertex->GetX()+fkVertex->GetY()*fkVertex->GetY());
     
-    AliESDtrack *trackCopy = new AliESDtrack(*track);
-    AliESDtrack *trackPartCopy = new AliESDtrack(*trackPart);
+    AliESDtrack trackCopy = AliESDtrack(*track);
+    AliESDtrack trackPartCopy = AliESDtrack(*trackPart);
     Bool_t propagateok = kTRUE;
-    if((!(trackPartCopy->PropagateTo(norradius,fBz))) || (!(trackCopy->PropagateTo(norradius,fBz)))) propagateok = kFALSE;
+    if((!(trackPartCopy.PropagateTo(norradius,fBz))) || (!(trackCopy.PropagateTo(norradius,fBz)))) propagateok = kFALSE;
     if(!propagateok) {
-      if(trackCopy) delete trackCopy;
-      if(trackPartCopy) delete trackPartCopy;
+      //if(trackCopy) delete trackCopy;
+      //if(trackPartCopy) delete trackPartCopy;
       return;
     }  
   
-    CalculateMotherVariable(trackCopy,trackPartCopy,&results[0]);
-    CalculateMotherVariableR(trackCopy,trackPartCopy,&resultsr[0]);
+    CalculateMotherVariable(&trackCopy,&trackPartCopy,&results[0]);
+    CalculateMotherVariableR(&trackCopy,&trackPartCopy,&resultsr[0]);
     
-    if(trackCopy) delete trackCopy;
-    if(trackPartCopy) delete trackPartCopy;
+    //if(trackCopy) delete trackCopy;
+    //if(trackPartCopy) delete trackPartCopy;
     
   }
   else {
@@ -772,7 +802,8 @@ void AliHFEelecbackground::PairAnalysis(AliESDtrack* const track, AliESDtrack* c
       if(HasMCData() && fIsPartner && (sign==kOs)) {
        cuteffect[1] = 7.0;
        if(!fCuts[7]) {
-         if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
+         if((fhtmp = dynamic_cast<THnSparseF *>(fList->At(kMCe)))) fhtmp->Fill(cuteffect);
+         //if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
          fCuts[7] = kTRUE;
        }
       }
@@ -793,13 +824,15 @@ void AliHFEelecbackground::PairAnalysis(AliESDtrack* const track, AliESDtrack* c
        
        cuteffect[1] = 8.0;
        if(!fCuts[8]) {
-        if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
+         if((fhtmp = dynamic_cast<THnSparseF *>(fList->At(kMCe)))) fhtmp->Fill(cuteffect);
+         //if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
          fCuts[8] = kTRUE;
        }
        if(TMath::Abs(results[1]) < fInvMassCut) {
          cuteffect[1] = 9.0;
          if(!fCuts[9]) {
-           if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
+           if((fhtmp = dynamic_cast<THnSparseF *>(fList->At(kMCe)))) fhtmp->Fill(cuteffect);
+           //if(fList->At(kMCe)) (dynamic_cast<THnSparseF *>(fList->At(kMCe)))->Fill(cuteffect);
            fCuts[9] = kTRUE;
          }
        }
@@ -906,20 +939,31 @@ Bool_t AliHFEelecbackground::CalculateMotherVariable(AliESDtrack* const track, A
     results[4] = openingangle;
 
     // chi2Ndf cut
-    if(fList->At(kDatachi2Ndf)) (dynamic_cast<TH1F *>(fList->At(kDatachi2Ndf)))->Fill(chi2ndf);
+    if((fhtmpp = dynamic_cast<TH1F *>(fList->At(kDatachi2Ndf)))) fhtmpp->Fill(chi2ndf);
+    //if(fList->At(kDatachi2Ndf)) (dynamic_cast<TH1F *>(fList->At(kDatachi2Ndf)))->Fill(chi2ndf);
     if(HasMCData()){
-      if((fIsFrom==kElectronFromBackground) && (fList->At(kMCchi2Ndf))) (dynamic_cast<TH2F *>(fList->At(kMCchi2Ndf)))->Fill(chi2ndf,fIsFrom);
+      if(fIsFrom==kElectronFromBackground) {
+       if((fhtmpf = dynamic_cast<TH2F *>(fList->At(kMCchi2Ndf)))) fhtmpf->Fill(chi2ndf,fIsFrom); 
+      }
       else {
-       if(fIsPartner && (fList->At(kMCchi2Ndf))) (dynamic_cast<TH2F *>(fList->At(kMCchi2Ndf)))->Fill(chi2ndf,fIsFrom);
+       if(fIsPartner){
+         if((fhtmpf = dynamic_cast<TH2F *>(fList->At(kMCchi2Ndf)))) fhtmpf->Fill(chi2ndf,fIsFrom); 
+       }
       }
     }
     if(chi2ndf > fChi2NdfCut) return kFALSE;
     else {
-      if(fList->At(kDatar)) (dynamic_cast<TH1F *>(fList->At(kDatar)))->Fill(radius);
+      if((fhtmpp = dynamic_cast<TH1F *>(fList->At(kDatar)))) fhtmpp->Fill(radius); 
+      //if(fList->At(kDatar)) (dynamic_cast<TH1F *>(fList->At(kDatar)))->Fill(radius);
       if(HasMCData()) {
-       if((fIsFrom==kElectronFromBackground) && (fList->At(kMCr))) (dynamic_cast<TH2F *>(fList->At(kMCr)))->Fill(radius,fIsFrom);
+       if(fIsFrom==kElectronFromBackground) {
+         if((fhtmpf = dynamic_cast<TH2F *>(fList->At(kMCr)))) fhtmpf->Fill(radius,fIsFrom); 
+         //if(fList->At(kMCr))) (dynamic_cast<TH2F *>(fList->At(kMCr)))->Fill(radius,fIsFrom);
+       }
        else {
-         if(fIsPartner && (fList->At(kMCr))) (dynamic_cast<TH2F *>(fList->At(kMCr)))->Fill(radius,fIsFrom);
+         if(fIsPartner) {
+           if((fhtmpf = dynamic_cast<TH2F *>(fList->At(kMCr)))) fhtmpf->Fill(radius,fIsFrom); 
+         }
        }
       }
       return kTRUE;
@@ -1004,7 +1048,8 @@ void AliHFEelecbackground::FillOutput(Double_t *results, Double_t *resultsr, Int
   co[4] = sign;
   co[5] = 0.0;
 
-  if(fList->At(kDatai))(dynamic_cast<THnSparseF *>(fList->At(kDatai)))->Fill(co);
+  if((fhtmp = dynamic_cast<THnSparseF *>(fList->At(kDatai)))) fhtmp->Fill(co);
+  //if(fList->At(kDatai))(dynamic_cast<THnSparseF *>(fList->At(kDatai)))->Fill(co);
 
   if((sign==kOs) && (!fUseAliKFCode)) {
     
@@ -1014,7 +1059,8 @@ void AliHFEelecbackground::FillOutput(Double_t *results, Double_t *resultsr, Int
     co[4] = kR;
     co[5] = 0.0;
 
-    if(fList->At(kDatai)) (dynamic_cast<THnSparseF *>(fList->At(kDatai)))->Fill(co);
+    if((fhtmp = dynamic_cast<THnSparseF *>(fList->At(kDatai)))) fhtmp->Fill(co);
+    //if(fList->At(kDatai)) (dynamic_cast<THnSparseF *>(fList->At(kDatai)))->Fill(co);
     
   }
   
@@ -1040,7 +1086,8 @@ void AliHFEelecbackground::FillOutput(Double_t *results, Double_t *resultsr, Int
       }
     }
 
-    if(fList->At(kMCo)) (dynamic_cast<THnSparseF *>(fList->At(kMCo)))->Fill(co);
+    if((fhtmp = dynamic_cast<THnSparseF *>(fList->At(kMCo)))) fhtmp->Fill(co);
+    //if(fList->At(kMCo)) (dynamic_cast<THnSparseF *>(fList->At(kMCo)))->Fill(co);
 
   }
  
@@ -1122,8 +1169,9 @@ Bool_t AliHFEelecbackground::PIDTrackCut(AliESDtrack* const trackPart)
     Double_t itsSignal = trackPart->GetITSsignal();
     Double_t p = trackPart->P();
     
-    if(fDebugLevel > 1) {        
-      if(fList->At(kMCcutPart0)) (dynamic_cast<TH2F *>(fList->At(kMCcutPart0)))->Fill(p,itsSignal);
+    if(fDebugLevel > 1) {    
+      if((fhtmpf = dynamic_cast<TH2F *>(fList->At(kMCcutPart0)))) fhtmpf->Fill(p,itsSignal);     
+      //if(fList->At(kMCcutPart0)) (dynamic_cast<TH2F *>(fList->At(kMCcutPart0)))->Fill(p,itsSignal);
     }
 
     ///////////
@@ -1150,8 +1198,10 @@ Bool_t AliHFEelecbackground::PIDTrackCut(AliESDtrack* const trackPart)
        entries[3] = dEdxSamplesPart[2];
        entries[4] = dEdxSamplesPart[3];
 
-       if(fList->At(kMCcutPart1)) (dynamic_cast<TH2F *>(fList->At(kMCcutPart1)))->Fill(p,itsSignal);
-       if(fList->At(kMCcutPart2)) (dynamic_cast<THnSparseF *>(fList->At(kMCcutPart2)))->Fill(entries);
+       //if(fList->At(kMCcutPart1)) (dynamic_cast<TH2F *>(fList->At(kMCcutPart1)))->Fill(p,itsSignal);
+       if((fhtmpf = dynamic_cast<TH2F *>(fList->At(kMCcutPart1)))) fhtmpf->Fill(p,itsSignal); 
+       if((fhtmp = dynamic_cast<THnSparseF *>(fList->At(kMCcutPart2)))) fhtmp->Fill(entries);
+       //if(fList->At(kMCcutPart2)) (dynamic_cast<THnSparseF *>(fList->At(kMCcutPart2)))->Fill(entries);
        
       }
       
@@ -1169,20 +1219,22 @@ Bool_t AliHFEelecbackground::PIDTrackCut(AliESDtrack* const trackPart)
 
     if(fDebugLevel > 1) {        
       //printf("tpcSignal %f\n",tpcSignal);
-      if(fList->At(kMCcutPart0)) (dynamic_cast<TH2F *>(fList->At(kMCcutPart0)))->Fill(p,tpcSignal);
+      //if(fList->At(kMCcutPart0)) (dynamic_cast<TH2F *>(fList->At(kMCcutPart0)))->Fill(p,tpcSignal);
+      if((fhtmpf = dynamic_cast<TH2F *>(fList->At(kMCcutPart0)))) fhtmpf->Fill(p,tpcSignal); 
     }
 
     // PID
     if(fPIDPartner) {
       if(!fPIDMethodPartner) return kFALSE;
       AliHFEpidObject hfetrack;
-      hfetrack.fAnalysisType = AliHFEpidObject::kESDanalysis;
-      hfetrack.fRecTrack = trackPart;
+      hfetrack.SetAnalysisType(AliHFEpidObject::kESDanalysis);
+      hfetrack.SetRecTrack(trackPart);
       //if(HasMCData()) hfetrack.fMCtrack = mctrack;
       if(!fPIDMethodPartner->IsSelected(&hfetrack)) return kFALSE;
       
       if(fDebugLevel > 1) {  
-       if(fList->At(kMCcutPart1)) (dynamic_cast<TH2F *>(fList->At(kMCcutPart1)))->Fill(p,tpcSignal);
+       if((fhtmpf = dynamic_cast<TH2F *>(fList->At(kMCcutPart1)))) fhtmpf->Fill(p,tpcSignal); 
+       //if(fList->At(kMCcutPart1)) (dynamic_cast<TH2F *>(fList->At(kMCcutPart1)))->Fill(p,tpcSignal);
       }
     }   
     
@@ -1192,7 +1244,7 @@ Bool_t AliHFEelecbackground::PIDTrackCut(AliESDtrack* const trackPart)
 
 }
 //__________________________________________________________________________________________
-Bool_t AliHFEelecbackground::ShareCluster(AliESDtrack * const track1,AliESDtrack * const track2) const
+Bool_t AliHFEelecbackground::ShareCluster(AliESDtrack * const track1,AliESDtrack * const track2) 
 {
   //
   // Look if the two tracks shared clusters in the TPC or in the ITS depending on the method
@@ -1289,7 +1341,8 @@ Bool_t AliHFEelecbackground::ShareCluster(AliESDtrack * const track1,AliESDtrack
        }
        else entriesSplit[layer+1] = -100.0;
       }
-      if(fList->At(kMCcutPart3)) (dynamic_cast<THnSparseF *>(fList->At(kMCcutPart3)))->Fill(entriesSplit);
+      if((fhtmp = dynamic_cast<THnSparseF *>(fList->At(kMCcutPart3)))) fhtmp->Fill(entriesSplit);
+      //if(fList->At(kMCcutPart3)) (dynamic_cast<THnSparseF *>(fList->At(kMCcutPart3)))->Fill(entriesSplit);
     }
 
     // Return
@@ -1316,7 +1369,8 @@ void AliHFEelecbackground::SetPIDPartner() {
     
     if(!fPIDMethodPartner) {
       fPIDMethodPartner = new AliHFEpid();
-      fPIDMethodPartner->InitializePID("Strategy1");     // 3 sigma cut in TPC
+      fPIDMethodPartner->AddDetector("TPC", 0);
+      fPIDMethodPartner->InitializePID();     // 3 sigma cut in TPC
     }
 
   }
@@ -1537,6 +1591,7 @@ void AliHFEelecbackground::PostProcess()
   /////////////////////////////////
   // Cuts on the opening angle
   ////////////////////////////////
+  if(!hsSparseData) return;
   TAxis *axisOpeningAngleData = hsSparseData->GetAxis(2);
   Int_t binCutData = axisOpeningAngleData->FindBin(fOpeningAngleCut);
   hsSparseData->GetAxis(2)->SetRange(1,binCutData);
@@ -1663,10 +1718,10 @@ void AliHFEelecbackground::PostProcess()
     Double_t yieldf = invmassdiffptproj[k-1]->Integral();
     if(invmassetaptproj[k-1] && invmasspi0ptproj[k-1] && invmassgammaptproj[k-1] && invmassCptproj[k-1] && invmassBptproj[k-1]) {
       Double_t yieldg = invmassetaptproj[k-1]->Integral() + invmasspi0ptproj[k-1]->Integral() + invmassgammaptproj[k-1]->Integral();
-      yieldPtSourcesMC->SetBinContent(k,yieldg);
+      if(yieldPtSourcesMC) yieldPtSourcesMC->SetBinContent(k,yieldg);
       
       Double_t yieldsignal = invmassCptproj[k-1]->Integral() + invmassBptproj[k-1]->Integral();
-      yieldPtSignalCutMC->SetBinContent(k,yieldsignal);
+      if(yieldPtSignalCutMC) yieldPtSignalCutMC->SetBinContent(k,yieldsignal);
     }
 
     yieldPtFound->SetBinContent(k,yieldf);
@@ -1782,6 +1837,7 @@ void AliHFEelecbackground::Plot() const
   /////////////////////////
   THnSparseF *hsSparseData = dynamic_cast<THnSparseF *>(fList->FindObject("OpeningangleinvmassData")); 
   THnSparseF *hsSparseMC = dynamic_cast<THnSparseF *>(fList->FindObject("OpeningangleinvmassMC")); 
+  if(!hsSparseData) return;
   
   ////////////////////
   // Opening angle
@@ -2190,310 +2246,6 @@ void AliHFEelecbackground::Plot() const
   cinvmass2D->cd(12);
   if(invmassSplittedTrackosproj2D) invmassSplittedTrackosproj2D->Draw("lego");
 
-
-  ////////////////////////
-  // Cut efficiencies
-  ////////////////////////
-
-  THnSparseF *hsSparseMCe = dynamic_cast<THnSparseF *>(fList->FindObject("CutPassedMC"));
-  
-  if(hsSparseMCe) {
-
-    // init histos
-    TAxis *axissources = hsSparseMCe->GetAxis(2);
-    Int_t  nbsources = axissources->GetNbins(); 
-    TAxis *axiscuts = hsSparseMCe->GetAxis(1);
-    Int_t  nbcuts = axiscuts->GetNbins(); 
-    TH1D **histopassedcuts = new TH1D*[nbsources*nbcuts];  
-    Double_t *nbEntriesCuts = new Double_t[nbsources*nbcuts]; 
-
-    //printf("Number of cuts %d\n",nbcuts);
-
-    // canvas
-    TCanvas * chsSparseMCeeff =new TCanvas("hsSparseMCeeffDebug","hsSparseMCeeffDebug",800,800);
-    chsSparseMCeeff->Divide(3,1);
-    // histos
-    for(Int_t sourceid = 0; sourceid < nbsources; sourceid++) {
-      hsSparseMCe->GetAxis(2)->SetRange(sourceid+1,sourceid+1);  
-      for(Int_t cut = 0; cut < nbcuts; cut++){
-       hsSparseMCe->GetAxis(1)->SetRange(cut+1,cut+1); 
-       histopassedcuts[sourceid*nbcuts+cut] = hsSparseMCe->Projection(0);
-       hsSparseMCe->GetAxis(1)->SetRange(1,hsSparseMCe->GetAxis(1)->GetNbins()); 
-      }
-      hsSparseMCe->GetAxis(2)->SetRange(1,hsSparseMCe->GetAxis(2)->GetNbins());  
-    }
-
-    // calcul efficiencies
-    ///////////////////////
-    // histos
-    for(Int_t sourceid = 0; sourceid < nbsources; sourceid++) {
-      // Next is compared to the partner tracked
-      for(Int_t cut = 2; cut < nbcuts; cut++){
-       nbEntriesCuts[sourceid*nbcuts+cut] = histopassedcuts[sourceid*nbcuts+cut]->GetEntries();
-       if(histopassedcuts[sourceid*nbcuts+1]->GetEntries() > 0.0) histopassedcuts[sourceid*nbcuts+cut]->Divide(histopassedcuts[sourceid*nbcuts+1]);
-      }
-      // First one is if the partner is tracked.
-      nbEntriesCuts[sourceid*nbcuts+1] = histopassedcuts[sourceid*nbcuts+1]->GetEntries();
-      if(histopassedcuts[sourceid*nbcuts]->GetEntries() > 0.0) histopassedcuts[sourceid*nbcuts+1]->Divide(histopassedcuts[sourceid*nbcuts]);
-      // First one is input
-      nbEntriesCuts[sourceid*nbcuts] = histopassedcuts[sourceid*nbcuts]->GetEntries();
-    }
-    
-    /////////////
-    // ratios
-    ////////////
-    for(Int_t sourceid = 0; sourceid < nbsources; sourceid++) {
-      for(Int_t cut = 1; cut < nbcuts; cut++){
-       if(nbEntriesCuts[sourceid*nbcuts] > 0.0) nbEntriesCuts[sourceid*nbcuts+cut] = nbEntriesCuts[sourceid*nbcuts+cut]/nbEntriesCuts[sourceid*nbcuts]; 
-      }
-    }
-    TH1F *ratioHistoEntriesGamma = new TH1F("ratioHistoEntriesGamma","", nbcuts-1, 0.0, nbcuts-1.0);
-    TH1F *ratioHistoEntriesPi0 = new TH1F("ratioHistoEntriesPi0","", nbcuts-1, 0.0, nbcuts-1.0);
-    TH1F *ratioHistoEntriesC = new TH1F("ratioHistoEntriesC","", nbcuts-1, 0.0, nbcuts-1.0);
-    for(Int_t k = 1; k < nbcuts; k++){
-      ratioHistoEntriesGamma->SetBinContent(k,nbEntriesCuts[nbcuts+k]);
-      ratioHistoEntriesPi0->SetBinContent(k,nbEntriesCuts[2*nbcuts+k]);
-      ratioHistoEntriesC->SetBinContent(k,nbEntriesCuts[4*nbcuts+k]);
-    }     
-    //
-    TAxis *xAxisGamma = ratioHistoEntriesGamma->GetXaxis();
-    xAxisGamma->SetBinLabel(1,"Partner tracked");
-    xAxisGamma->SetBinLabel(2,"Opposite sign");
-    xAxisGamma->SetBinLabel(3,"Single Track Cut");
-    xAxisGamma->SetBinLabel(4,"Shared Clusters");
-    xAxisGamma->SetBinLabel(5,"PID");
-    xAxisGamma->SetBinLabel(6,"DCA");
-    xAxisGamma->SetBinLabel(7,"Chi^{2}/Ndf");
-    xAxisGamma->SetBinLabel(8,"Opening angle");
-    xAxisGamma->SetBinLabel(9,"Invariant mass");
-    //
-    TAxis *xAxisPi0 = ratioHistoEntriesPi0->GetXaxis();
-    xAxisPi0->SetBinLabel(1,"Partner tracked");
-    xAxisPi0->SetBinLabel(2,"Opposite sign");
-    xAxisPi0->SetBinLabel(3,"Single Track Cut");
-    xAxisPi0->SetBinLabel(4,"Shared Clusters");
-    xAxisPi0->SetBinLabel(5,"PID");
-    xAxisPi0->SetBinLabel(6,"DCA");
-    xAxisPi0->SetBinLabel(7,"Chi^{2}/Ndf");
-    xAxisPi0->SetBinLabel(8,"Opening angle");
-    xAxisPi0->SetBinLabel(9,"Invariant mass");
-    //
-    TAxis *xAxisC = ratioHistoEntriesC->GetXaxis();
-    xAxisC->SetBinLabel(1,"Partner tracked");
-    xAxisC->SetBinLabel(2,"Opposite sign");
-    xAxisC->SetBinLabel(3,"Single Track Cut");
-    xAxisC->SetBinLabel(4,"Shared Clusters");
-    xAxisC->SetBinLabel(5,"PID");
-    xAxisC->SetBinLabel(6,"DCA");
-    xAxisC->SetBinLabel(7,"Chi^{2}/Ndf");
-    xAxisC->SetBinLabel(8,"Opening angle");
-    xAxisC->SetBinLabel(9,"Invariant mass");
-    //
-    TCanvas * cRatioHistoEntries =new TCanvas("cRatioHistoEntries","cRatioHistoEntries",800,800);
-    cRatioHistoEntries->cd(1);
-    ratioHistoEntriesGamma->SetStats(0);
-    ratioHistoEntriesGamma->Draw();
-    ratioHistoEntriesPi0->SetStats(0);
-    ratioHistoEntriesPi0->Draw("same");
-    ratioHistoEntriesC->SetStats(0);
-    //ratioHistoEntriesC->Draw("same");
-    TLegend *legEntries = new TLegend(0.4,0.6,0.89,0.89);
-    legEntries->AddEntry(ratioHistoEntriesGamma,"#gamma","l");
-    legEntries->AddEntry(ratioHistoEntriesPi0,"#pi^{0}","l");
-    //legEntries->AddEntry(ratioHistoEntriesC,"c","p");
-    legEntries->Draw("same"); 
-
-    ////////////////////
-    // plot Debug
-    ///////////////////
-    Int_t source = 1;
-    chsSparseMCeeff->cd(1);
-    histopassedcuts[source*nbcuts+0]->SetTitle("#gamma");
-    histopassedcuts[source*nbcuts+1]->SetTitle("#gamma");
-    histopassedcuts[source*nbcuts+2]->SetTitle("#gamma");
-    histopassedcuts[source*nbcuts+3]->SetTitle("#gamma");
-    histopassedcuts[source*nbcuts+4]->SetTitle("#gamma");
-    histopassedcuts[source*nbcuts+5]->SetTitle("#gamma");
-    histopassedcuts[source*nbcuts+6]->SetTitle("#gamma");
-    histopassedcuts[source*nbcuts+7]->SetTitle("#gamma");
-    histopassedcuts[source*nbcuts+8]->SetTitle("#gamma");
-    histopassedcuts[source*nbcuts+9]->SetTitle("#gamma");
-    //histopassedcuts[source*nbcuts+0]->SetStats(0);
-    histopassedcuts[source*nbcuts+1]->SetStats(0);
-    histopassedcuts[source*nbcuts+2]->SetStats(0);
-    histopassedcuts[source*nbcuts+3]->SetStats(0);
-    histopassedcuts[source*nbcuts+4]->SetStats(0);
-    histopassedcuts[source*nbcuts+5]->SetStats(0);
-    histopassedcuts[source*nbcuts+6]->SetStats(0);
-    histopassedcuts[source*nbcuts+7]->SetStats(0);
-    histopassedcuts[source*nbcuts+8]->SetStats(0);
-    histopassedcuts[source*nbcuts+9]->SetStats(0);
-    //histopassedcuts[source*nbcuts+0]->Draw();
-    //histopassedcuts[source*nbcuts+1]->Draw("");
-    histopassedcuts[source*nbcuts+2]->Draw();
-    histopassedcuts[source*nbcuts+3]->Draw("same");
-    //histopassedcuts[source*nbcuts+4]->Draw("same");
-    histopassedcuts[source*nbcuts+5]->Draw("same");
-    histopassedcuts[source*nbcuts+6]->Draw("same");
-    //histopassedcuts[source*nbcuts+7]->Draw("same");
-    histopassedcuts[source*nbcuts+8]->Draw("same");
-    histopassedcuts[source*nbcuts+9]->Draw("same");
-    TLegend *legb = new TLegend(0.4,0.6,0.89,0.89);
-    //legb->AddEntry(histopassedcuts[source*nbcuts+0],"all","p");
-    //legb->AddEntry(histopassedcuts[source*nbcuts+1],"Partner tracked","p");
-    legb->AddEntry(histopassedcuts[source*nbcuts+2],"Opposite sign","p");
-    legb->AddEntry(histopassedcuts[source*nbcuts+3],"SingleTrackPart","p");
-    //legb->AddEntry(histopassedcuts[source*nbcuts+4],"SharedCluster","p");
-    legb->AddEntry(histopassedcuts[source*nbcuts+5],"PID","p");
-    legb->AddEntry(histopassedcuts[source*nbcuts+6],"DCA","p");
-    //legb->AddEntry(histopassedcuts[source*nbcuts+7],"Chi2Ndf","p");
-    legb->AddEntry(histopassedcuts[source*nbcuts+8],"OpeningAngle","p");
-    legb->AddEntry(histopassedcuts[source*nbcuts+9],"InvMass","p");
-    legb->Draw("same");
-
-    source = 2;
-    chsSparseMCeeff->cd(2);
-    histopassedcuts[source*nbcuts+0]->SetTitle("#pi^{0}");
-    histopassedcuts[source*nbcuts+1]->SetTitle("#pi^{0}");
-    histopassedcuts[source*nbcuts+2]->SetTitle("#pi^{0}");
-    histopassedcuts[source*nbcuts+3]->SetTitle("#pi^{0}");
-    histopassedcuts[source*nbcuts+4]->SetTitle("#pi^{0}");
-    histopassedcuts[source*nbcuts+5]->SetTitle("#pi^{0}");
-    histopassedcuts[source*nbcuts+6]->SetTitle("#pi^{0}");
-    histopassedcuts[source*nbcuts+7]->SetTitle("#pi^{0}");
-    histopassedcuts[source*nbcuts+8]->SetTitle("#pi^{0}");
-    histopassedcuts[source*nbcuts+9]->SetTitle("#pi^{0}");
-    //histopassedcuts[source*nbcuts+0]->SetStats(0);
-    histopassedcuts[source*nbcuts+1]->SetStats(0);
-    histopassedcuts[source*nbcuts+2]->SetStats(0);
-    histopassedcuts[source*nbcuts+3]->SetStats(0);
-    histopassedcuts[source*nbcuts+4]->SetStats(0);
-    histopassedcuts[source*nbcuts+5]->SetStats(0);
-    histopassedcuts[source*nbcuts+6]->SetStats(0);
-    histopassedcuts[source*nbcuts+7]->SetStats(0);
-    histopassedcuts[source*nbcuts+8]->SetStats(0);
-    histopassedcuts[source*nbcuts+9]->SetStats(0);
-    //histopassedcuts[source*nbcuts+0]->Draw();
-    //histopassedcuts[source*nbcuts+1]->Draw();
-    histopassedcuts[source*nbcuts+2]->Draw();
-    histopassedcuts[source*nbcuts+3]->Draw("same");
-    //histopassedcuts[source*nbcuts+4]->Draw("same");
-    histopassedcuts[source*nbcuts+5]->Draw("same");
-    histopassedcuts[source*nbcuts+6]->Draw("same");
-    //histopassedcuts[source*nbcuts+7]->Draw("same");
-    histopassedcuts[source*nbcuts+8]->Draw("same");
-    histopassedcuts[source*nbcuts+9]->Draw("same");
-    TLegend *legc = new TLegend(0.4,0.6,0.89,0.89);
-    //legc->AddEntry(histopassedcuts[source*nbcuts+0],"all","p");
-    //legc->AddEntry(histopassedcuts[source*nbcuts+1],"Partner tracked","p");
-    legc->AddEntry(histopassedcuts[source*nbcuts+2],"Opposite sign","p");
-    legc->AddEntry(histopassedcuts[source*nbcuts+3],"SingleTrackPart","p");
-    //legc->AddEntry(histopassedcuts[source*nbcuts+4],"SharedCluster","p");
-    legc->AddEntry(histopassedcuts[source*nbcuts+5],"PID","p");
-    legc->AddEntry(histopassedcuts[source*nbcuts+6],"DCA","p");
-    //legc->AddEntry(histopassedcuts[source*nbcuts+7],"Chi2Ndf","p");
-    legc->AddEntry(histopassedcuts[source*nbcuts+8],"OpeningAngle","p");
-    legc->AddEntry(histopassedcuts[source*nbcuts+9],"InvMass","p");
-    legc->Draw("same");
-
-    source = 4;
-    chsSparseMCeeff->cd(3);
-    histopassedcuts[source*nbcuts+0]->SetTitle("C");
-    histopassedcuts[source*nbcuts+1]->SetTitle("C");
-    histopassedcuts[source*nbcuts+2]->SetTitle("C");
-    histopassedcuts[source*nbcuts+3]->SetTitle("C");
-    histopassedcuts[source*nbcuts+4]->SetTitle("C");
-    histopassedcuts[source*nbcuts+5]->SetTitle("C");
-    histopassedcuts[source*nbcuts+6]->SetTitle("C");
-    histopassedcuts[source*nbcuts+7]->SetTitle("C");
-    histopassedcuts[source*nbcuts+8]->SetTitle("C");
-    histopassedcuts[source*nbcuts+9]->SetTitle("C");
-    //histopassedcuts[source*nbcuts+0]->SetStats(0);
-    histopassedcuts[source*nbcuts+1]->SetStats(0);
-    histopassedcuts[source*nbcuts+2]->SetStats(0);
-    histopassedcuts[source*nbcuts+3]->SetStats(0);
-    histopassedcuts[source*nbcuts+4]->SetStats(0);
-    histopassedcuts[source*nbcuts+5]->SetStats(0);
-    histopassedcuts[source*nbcuts+6]->SetStats(0);
-    histopassedcuts[source*nbcuts+7]->SetStats(0);
-    histopassedcuts[source*nbcuts+8]->SetStats(0);
-    histopassedcuts[source*nbcuts+9]->SetStats(0);
-    //histopassedcuts[source*nbcuts+0]->Draw();
-    //histopassedcuts[source*nbcuts+1]->Draw();
-    histopassedcuts[source*nbcuts+2]->Draw();
-    histopassedcuts[source*nbcuts+3]->Draw("same");
-    //histopassedcuts[source*nbcuts+4]->Draw("same");
-    histopassedcuts[source*nbcuts+5]->Draw("same");
-    histopassedcuts[source*nbcuts+6]->Draw("same");
-    //histopassedcuts[source*nbcuts+7]->Draw("same");
-    histopassedcuts[source*nbcuts+8]->Draw("same");
-    histopassedcuts[source*nbcuts+9]->Draw("same");
-    TLegend *lege = new TLegend(0.4,0.6,0.89,0.89);
-    //lege->AddEntry(histopassedcuts[source*nbcuts+0],"all","p");
-    //lege->AddEntry(histopassedcuts[source*nbcuts+1],"Partner tracked","p");
-    lege->AddEntry(histopassedcuts[source*nbcuts+2],"Opposite sign","p");
-    lege->AddEntry(histopassedcuts[source*nbcuts+3],"SingleTrackPart","p");
-    //lege->AddEntry(histopassedcuts[source*nbcuts+4],"SharedCluster","p");
-    lege->AddEntry(histopassedcuts[source*nbcuts+5],"PID","p");
-    lege->AddEntry(histopassedcuts[source*nbcuts+6],"DCA","p");
-    //lege->AddEntry(histopassedcuts[source*nbcuts+7],"Chi2Ndf","p");
-    lege->AddEntry(histopassedcuts[source*nbcuts+8],"OpeningAngle","p");
-    lege->AddEntry(histopassedcuts[source*nbcuts+9],"InvMass","p");
-    lege->Draw("same");
-
-    //////////////////////
-    // Input
-    //////////////////////
-
-    TCanvas * chsSparseMCein =new TCanvas("hsSparseMCeinput","hsSparseMCeinput",800,800);
-    chsSparseMCein->cd(1);
-    Double_t nbGamma = 0.0;
-    source = 1;
-    nbGamma = histopassedcuts[source*nbcuts+0]->GetEntries();
-    histopassedcuts[source*nbcuts+0]->SetStats(0);
-    histopassedcuts[source*nbcuts+0]->Draw();
-    TLegend *leginput = new TLegend(0.4,0.6,0.89,0.89);
-    leginput->AddEntry(histopassedcuts[source*nbcuts+0],"#gamma","p");
-    Double_t nbPi0 = 0.0;
-    source = 2;
-    nbPi0 = histopassedcuts[source*nbcuts+0]->GetEntries();
-    histopassedcuts[source*nbcuts+0]->SetStats(0);
-    histopassedcuts[source*nbcuts+0]->Draw("same");
-    leginput->AddEntry(histopassedcuts[source*nbcuts+0],"#pi^{0}","p");
-    Double_t nbEta = 0.0;
-    source = 3;
-    nbEta = histopassedcuts[source*nbcuts+0]->GetEntries();
-    histopassedcuts[source*nbcuts+0]->SetStats(0);
-    histopassedcuts[source*nbcuts+0]->Draw("same");
-    leginput->AddEntry(histopassedcuts[source*nbcuts+0],"#eta","p");
-    Double_t nbC = 0.0;
-    source = 4;
-    nbC = histopassedcuts[source*nbcuts+0]->GetEntries();
-    histopassedcuts[source*nbcuts+0]->SetStats(0);
-    histopassedcuts[source*nbcuts+0]->Draw("same");
-    leginput->AddEntry(histopassedcuts[source*nbcuts+0],"c","p");
-    leginput->Draw("same");
-
-    //printf("Gamma %f, pi^{0} %f and #eta %f, c %f\n",nbGamma,nbPi0,nbEta,nbC);
-
-    //////////////////////
-    // Tracked
-    //////////////////////
-
-    TCanvas * cTracked = new TCanvas("cTracked","cTracked",800,800);
-    cTracked->cd(1);
-    source = 1;
-    histopassedcuts[source*nbcuts+1]->Draw();
-    TLegend *legTracked = new TLegend(0.4,0.6,0.89,0.89);
-    legTracked->AddEntry(histopassedcuts[source*nbcuts+1],"#gamma","p");
-    source = 2;
-    histopassedcuts[source*nbcuts+1]->Draw("same");
-    legTracked->AddEntry(histopassedcuts[source*nbcuts+1],"#pi^{0}","p");
-    legTracked->Draw("same");
-  
-  }
-
   /////////////////////////////////////
   // Data Radius and chi2Ndf if AliKF
   ////////////////////////////////////
@@ -2739,8 +2491,371 @@ void AliHFEelecbackground::Plot() const
     legITS5->Draw("same");
 
   
-  }  
+  }
 
+  ////////////////////////
+  // Cut efficiencies
+  ////////////////////////
+  
+  THnSparseF *hsSparseMCe = dynamic_cast<THnSparseF *>(fList->FindObject("CutPassedMC"));
+  if(!hsSparseMCe) return;
+
+  // init histos
+  TAxis *axissources = hsSparseMCe->GetAxis(2);
+  Int_t  nbsources = axissources->GetNbins(); 
+  TAxis *axiscuts = hsSparseMCe->GetAxis(1);
+  Int_t  nbcuts = axiscuts->GetNbins(); 
+  TH1D **histopassedcuts = new TH1D*[nbsources*nbcuts];  
+  Double_t *nbEntriesCuts = new Double_t[nbsources*nbcuts]; 
+  for(Int_t k =0; k < nbsources*nbcuts; k++){
+    nbEntriesCuts[k] = 0.0;
+    histopassedcuts[k] = 0x0;
+  }
+  
+  //printf("Number of cuts %d\n",nbcuts);
+  
+  // canvas
+  TCanvas * chsSparseMCeeff =new TCanvas("hsSparseMCeeffDebug","hsSparseMCeeffDebug",800,800);
+  chsSparseMCeeff->Divide(3,1);
+  
+  // histos
+  for(Int_t sourceid = 0; sourceid < nbsources; sourceid++) {
+    hsSparseMCe->GetAxis(2)->SetRange(sourceid+1,sourceid+1);  
+    for(Int_t cut = 0; cut < nbcuts; cut++){
+      hsSparseMCe->GetAxis(1)->SetRange(cut+1,cut+1); 
+      histopassedcuts[sourceid*nbcuts+cut] = hsSparseMCe->Projection(0);
+      hsSparseMCe->GetAxis(1)->SetRange(1,hsSparseMCe->GetAxis(1)->GetNbins()); 
+    }
+    hsSparseMCe->GetAxis(2)->SetRange(1,hsSparseMCe->GetAxis(2)->GetNbins());  
+  }
+  
+  // calcul efficiencies
+  
+  // histos
+  for(Int_t sourceid = 0; sourceid < nbsources; sourceid++) {
+    // Next is compared to the partner tracked
+    for(Int_t cut = 2; cut < nbcuts; cut++){
+      nbEntriesCuts[sourceid*nbcuts+cut] = histopassedcuts[sourceid*nbcuts+cut]->GetEntries();
+      if(histopassedcuts[sourceid*nbcuts+1]->GetEntries() > 0.0) histopassedcuts[sourceid*nbcuts+cut]->Divide(histopassedcuts[sourceid*nbcuts+1]);
+    }
+    // First one is if the partner is tracked.
+    nbEntriesCuts[sourceid*nbcuts+1] = histopassedcuts[sourceid*nbcuts+1]->GetEntries();
+    if(histopassedcuts[sourceid*nbcuts]->GetEntries() > 0.0) histopassedcuts[sourceid*nbcuts+1]->Divide(histopassedcuts[sourceid*nbcuts]);
+    // First one is input
+    nbEntriesCuts[sourceid*nbcuts] = histopassedcuts[sourceid*nbcuts]->GetEntries();
+  }
+  
+  // ratios
+  for(Int_t sourceid = 0; sourceid < nbsources; sourceid++) {
+    for(Int_t cut = 1; cut < nbcuts; cut++){
+      if(nbEntriesCuts[sourceid*nbcuts] > 0.0) nbEntriesCuts[sourceid*nbcuts+cut] = nbEntriesCuts[sourceid*nbcuts+cut]/nbEntriesCuts[sourceid*nbcuts]; 
+    }
+  }
+  TH1F *ratioHistoEntriesGamma = new TH1F("ratioHistoEntriesGamma","", nbcuts-1, 0.0, nbcuts-1.0);
+  TH1F *ratioHistoEntriesPi0 = new TH1F("ratioHistoEntriesPi0","", nbcuts-1, 0.0, nbcuts-1.0);
+  TH1F *ratioHistoEntriesC = new TH1F("ratioHistoEntriesC","", nbcuts-1, 0.0, nbcuts-1.0);
+  for(Int_t k = 1; k < nbcuts; k++){
+    if((nbcuts+k) < (nbsources*nbcuts)) ratioHistoEntriesGamma->SetBinContent(k,nbEntriesCuts[nbcuts+k]);
+    if((2*nbcuts+k) < (nbsources*nbcuts)) ratioHistoEntriesPi0->SetBinContent(k,nbEntriesCuts[2*nbcuts+k]);
+    if((4*nbcuts+k) < (nbsources*nbcuts)) ratioHistoEntriesC->SetBinContent(k,nbEntriesCuts[4*nbcuts+k]);
+  }     
+  //
+  TAxis *xAxisGamma = ratioHistoEntriesGamma->GetXaxis();
+  xAxisGamma->SetBinLabel(1,"Partner tracked");
+  xAxisGamma->SetBinLabel(2,"Opposite sign");
+  xAxisGamma->SetBinLabel(3,"Single Track Cut");
+  xAxisGamma->SetBinLabel(4,"Shared Clusters");
+  xAxisGamma->SetBinLabel(5,"PID");
+  xAxisGamma->SetBinLabel(6,"DCA");
+  xAxisGamma->SetBinLabel(7,"Chi^{2}/Ndf");
+  xAxisGamma->SetBinLabel(8,"Opening angle");
+  xAxisGamma->SetBinLabel(9,"Invariant mass");
+  //
+  TAxis *xAxisPi0 = ratioHistoEntriesPi0->GetXaxis();
+  xAxisPi0->SetBinLabel(1,"Partner tracked");
+  xAxisPi0->SetBinLabel(2,"Opposite sign");
+  xAxisPi0->SetBinLabel(3,"Single Track Cut");
+  xAxisPi0->SetBinLabel(4,"Shared Clusters");
+  xAxisPi0->SetBinLabel(5,"PID");
+  xAxisPi0->SetBinLabel(6,"DCA");
+  xAxisPi0->SetBinLabel(7,"Chi^{2}/Ndf");
+  xAxisPi0->SetBinLabel(8,"Opening angle");
+  xAxisPi0->SetBinLabel(9,"Invariant mass");
+  //
+  TAxis *xAxisC = ratioHistoEntriesC->GetXaxis();
+  xAxisC->SetBinLabel(1,"Partner tracked");
+  xAxisC->SetBinLabel(2,"Opposite sign");
+  xAxisC->SetBinLabel(3,"Single Track Cut");
+  xAxisC->SetBinLabel(4,"Shared Clusters");
+  xAxisC->SetBinLabel(5,"PID");
+  xAxisC->SetBinLabel(6,"DCA");
+  xAxisC->SetBinLabel(7,"Chi^{2}/Ndf");
+  xAxisC->SetBinLabel(8,"Opening angle");
+  xAxisC->SetBinLabel(9,"Invariant mass");
+  //
+  TCanvas * cRatioHistoEntries =new TCanvas("cRatioHistoEntries","cRatioHistoEntries",800,800);
+  cRatioHistoEntries->cd(1);
+  ratioHistoEntriesGamma->SetStats(0);
+  ratioHistoEntriesGamma->Draw();
+  ratioHistoEntriesPi0->SetStats(0);
+  ratioHistoEntriesPi0->Draw("same");
+  ratioHistoEntriesC->SetStats(0);
+  //ratioHistoEntriesC->Draw("same");
+  TLegend *legEntries = new TLegend(0.4,0.6,0.89,0.89);
+  legEntries->AddEntry(ratioHistoEntriesGamma,"#gamma","l");
+  legEntries->AddEntry(ratioHistoEntriesPi0,"#pi^{0}","l");
+  //legEntries->AddEntry(ratioHistoEntriesC,"c","p");
+  legEntries->Draw("same"); 
+  
+  // plot Debug
+  Int_t source = 1;
+  chsSparseMCeeff->cd(1);
+  if(((source*nbcuts+0)> (nbsources*nbcuts-1)) || ((source*nbcuts+1)> (nbsources*nbcuts-1)) || ((source*nbcuts+2)> (nbsources*nbcuts-1)) || ((source*nbcuts+3)> (nbsources*nbcuts-1)) || ((source*nbcuts+4)> (nbsources*nbcuts-1)) || ((source*nbcuts+5)> (nbsources*nbcuts-1)) || ((source*nbcuts+6)> (nbsources*nbcuts-1)) || ((source*nbcuts+7)> (nbsources*nbcuts-1)) || ((source*nbcuts+8)> (nbsources*nbcuts-1)) || ((source*nbcuts+9)> (nbsources*nbcuts-1))) {
+    delete [] histopassedcuts;
+    delete [] nbEntriesCuts;
+    return;
+  }
+  if((!histopassedcuts[source*nbcuts+0]) || (!histopassedcuts[source*nbcuts+1]) || (!histopassedcuts[source*nbcuts+2]) || (!histopassedcuts[source*nbcuts+3]) || (!histopassedcuts[source*nbcuts+4]) || (!histopassedcuts[source*nbcuts+5]) || (!histopassedcuts[source*nbcuts+6]) || (!histopassedcuts[source*nbcuts+7]) || (!histopassedcuts[source*nbcuts+8]) || (!histopassedcuts[source*nbcuts+9])) {
+    delete [] histopassedcuts;
+    delete [] nbEntriesCuts;
+    return;
+  }
+  histopassedcuts[source*nbcuts+0]->SetTitle("#gamma");
+  histopassedcuts[source*nbcuts+1]->SetTitle("#gamma");
+  histopassedcuts[source*nbcuts+2]->SetTitle("#gamma");
+  histopassedcuts[source*nbcuts+3]->SetTitle("#gamma");
+  histopassedcuts[source*nbcuts+4]->SetTitle("#gamma");
+  histopassedcuts[source*nbcuts+5]->SetTitle("#gamma");
+  histopassedcuts[source*nbcuts+6]->SetTitle("#gamma");
+  histopassedcuts[source*nbcuts+7]->SetTitle("#gamma");
+  histopassedcuts[source*nbcuts+8]->SetTitle("#gamma");
+  histopassedcuts[source*nbcuts+9]->SetTitle("#gamma");
+  //histopassedcuts[source*nbcuts+0]->SetStats(0);
+  histopassedcuts[source*nbcuts+1]->SetStats(0);
+  histopassedcuts[source*nbcuts+2]->SetStats(0);
+  histopassedcuts[source*nbcuts+3]->SetStats(0);
+  histopassedcuts[source*nbcuts+4]->SetStats(0);
+  histopassedcuts[source*nbcuts+5]->SetStats(0);
+  histopassedcuts[source*nbcuts+6]->SetStats(0);
+  histopassedcuts[source*nbcuts+7]->SetStats(0);
+  histopassedcuts[source*nbcuts+8]->SetStats(0);
+  histopassedcuts[source*nbcuts+9]->SetStats(0);
+  //histopassedcuts[source*nbcuts+0]->Draw();
+  //histopassedcuts[source*nbcuts+1]->Draw("");
+  histopassedcuts[source*nbcuts+2]->Draw();
+  histopassedcuts[source*nbcuts+3]->Draw("same");
+  //histopassedcuts[source*nbcuts+4]->Draw("same");
+  histopassedcuts[source*nbcuts+5]->Draw("same");
+  histopassedcuts[source*nbcuts+6]->Draw("same");
+  //histopassedcuts[source*nbcuts+7]->Draw("same");
+  histopassedcuts[source*nbcuts+8]->Draw("same");
+  histopassedcuts[source*nbcuts+9]->Draw("same");
+  TLegend *legb = new TLegend(0.4,0.6,0.89,0.89);
+  //legb->AddEntry(histopassedcuts[source*nbcuts+0],"all","p");
+  //legb->AddEntry(histopassedcuts[source*nbcuts+1],"Partner tracked","p");
+  legb->AddEntry(histopassedcuts[source*nbcuts+2],"Opposite sign","p");
+  legb->AddEntry(histopassedcuts[source*nbcuts+3],"SingleTrackPart","p");
+  //legb->AddEntry(histopassedcuts[source*nbcuts+4],"SharedCluster","p");
+  legb->AddEntry(histopassedcuts[source*nbcuts+5],"PID","p");
+  legb->AddEntry(histopassedcuts[source*nbcuts+6],"DCA","p");
+  //legb->AddEntry(histopassedcuts[source*nbcuts+7],"Chi2Ndf","p");
+  legb->AddEntry(histopassedcuts[source*nbcuts+8],"OpeningAngle","p");
+  legb->AddEntry(histopassedcuts[source*nbcuts+9],"InvMass","p");
+  legb->Draw("same");
+  
+  source = 2;
+  if(((source*nbcuts+0)> (nbsources*nbcuts-1)) || ((source*nbcuts+1)> (nbsources*nbcuts-1)) || ((source*nbcuts+2)> (nbsources*nbcuts-1)) || ((source*nbcuts+3)> (nbsources*nbcuts-1)) || ((source*nbcuts+4)> (nbsources*nbcuts-1)) || ((source*nbcuts+5)> (nbsources*nbcuts-1)) || ((source*nbcuts+6)> (nbsources*nbcuts-1)) || ((source*nbcuts+7)> (nbsources*nbcuts-1)) || ((source*nbcuts+8)> (nbsources*nbcuts-1)) || ((source*nbcuts+9)> (nbsources*nbcuts-1))) {
+    delete [] histopassedcuts;
+    delete [] nbEntriesCuts;
+    return;
+  }
+  if((!histopassedcuts[source*nbcuts+0]) || (!histopassedcuts[source*nbcuts+1]) || (!histopassedcuts[source*nbcuts+2]) || (!histopassedcuts[source*nbcuts+3]) || (!histopassedcuts[source*nbcuts+4]) || (!histopassedcuts[source*nbcuts+5]) || (!histopassedcuts[source*nbcuts+6]) || (!histopassedcuts[source*nbcuts+7]) || (!histopassedcuts[source*nbcuts+8]) || (!histopassedcuts[source*nbcuts+9])) {
+    delete [] histopassedcuts;
+    delete [] nbEntriesCuts;
+    return;
+  }
+  chsSparseMCeeff->cd(2);
+  histopassedcuts[source*nbcuts+0]->SetTitle("#pi^{0}");
+  histopassedcuts[source*nbcuts+1]->SetTitle("#pi^{0}");
+  histopassedcuts[source*nbcuts+2]->SetTitle("#pi^{0}");
+  histopassedcuts[source*nbcuts+3]->SetTitle("#pi^{0}");
+  histopassedcuts[source*nbcuts+4]->SetTitle("#pi^{0}");
+  histopassedcuts[source*nbcuts+5]->SetTitle("#pi^{0}");
+  histopassedcuts[source*nbcuts+6]->SetTitle("#pi^{0}");
+  histopassedcuts[source*nbcuts+7]->SetTitle("#pi^{0}");
+  histopassedcuts[source*nbcuts+8]->SetTitle("#pi^{0}");
+  histopassedcuts[source*nbcuts+9]->SetTitle("#pi^{0}");
+  //histopassedcuts[source*nbcuts+0]->SetStats(0);
+  histopassedcuts[source*nbcuts+1]->SetStats(0);
+  histopassedcuts[source*nbcuts+2]->SetStats(0);
+  histopassedcuts[source*nbcuts+3]->SetStats(0);
+  histopassedcuts[source*nbcuts+4]->SetStats(0);
+  histopassedcuts[source*nbcuts+5]->SetStats(0);
+  histopassedcuts[source*nbcuts+6]->SetStats(0);
+  histopassedcuts[source*nbcuts+7]->SetStats(0);
+  histopassedcuts[source*nbcuts+8]->SetStats(0);
+  histopassedcuts[source*nbcuts+9]->SetStats(0);
+  //histopassedcuts[source*nbcuts+0]->Draw();
+  //histopassedcuts[source*nbcuts+1]->Draw();
+  histopassedcuts[source*nbcuts+2]->Draw();
+  histopassedcuts[source*nbcuts+3]->Draw("same");
+  //histopassedcuts[source*nbcuts+4]->Draw("same");
+  histopassedcuts[source*nbcuts+5]->Draw("same");
+  histopassedcuts[source*nbcuts+6]->Draw("same");
+  //histopassedcuts[source*nbcuts+7]->Draw("same");
+  histopassedcuts[source*nbcuts+8]->Draw("same");
+  histopassedcuts[source*nbcuts+9]->Draw("same");
+  TLegend *legc = new TLegend(0.4,0.6,0.89,0.89);
+  //legc->AddEntry(histopassedcuts[source*nbcuts+0],"all","p");
+  //legc->AddEntry(histopassedcuts[source*nbcuts+1],"Partner tracked","p");
+  legc->AddEntry(histopassedcuts[source*nbcuts+2],"Opposite sign","p");
+  legc->AddEntry(histopassedcuts[source*nbcuts+3],"SingleTrackPart","p");
+  //legc->AddEntry(histopassedcuts[source*nbcuts+4],"SharedCluster","p");
+  legc->AddEntry(histopassedcuts[source*nbcuts+5],"PID","p");
+  legc->AddEntry(histopassedcuts[source*nbcuts+6],"DCA","p");
+  //legc->AddEntry(histopassedcuts[source*nbcuts+7],"Chi2Ndf","p");
+  legc->AddEntry(histopassedcuts[source*nbcuts+8],"OpeningAngle","p");
+  legc->AddEntry(histopassedcuts[source*nbcuts+9],"InvMass","p");
+  legc->Draw("same");
+  
+  source = 4;
+  if(((source*nbcuts+0)> (nbsources*nbcuts-1)) || ((source*nbcuts+1)> (nbsources*nbcuts-1)) || ((source*nbcuts+2)> (nbsources*nbcuts-1)) || ((source*nbcuts+3)> (nbsources*nbcuts-1)) || ((source*nbcuts+4)> (nbsources*nbcuts-1)) || ((source*nbcuts+5)> (nbsources*nbcuts-1)) || ((source*nbcuts+6)> (nbsources*nbcuts-1)) || ((source*nbcuts+7)> (nbsources*nbcuts-1)) || ((source*nbcuts+8)> (nbsources*nbcuts-1)) || ((source*nbcuts+9)> (nbsources*nbcuts-1))) {
+    delete [] histopassedcuts;
+    delete [] nbEntriesCuts;
+    return;
+  }
+  if((!histopassedcuts[source*nbcuts+0]) || (!histopassedcuts[source*nbcuts+1]) || (!histopassedcuts[source*nbcuts+2]) || (!histopassedcuts[source*nbcuts+3]) || (!histopassedcuts[source*nbcuts+4]) || (!histopassedcuts[source*nbcuts+5]) || (!histopassedcuts[source*nbcuts+6]) || (!histopassedcuts[source*nbcuts+7]) || (!histopassedcuts[source*nbcuts+8]) || (!histopassedcuts[source*nbcuts+9])) {
+    delete [] histopassedcuts;
+    delete [] nbEntriesCuts;
+    return;
+  }
+  chsSparseMCeeff->cd(3);
+  histopassedcuts[source*nbcuts+0]->SetTitle("C");
+  histopassedcuts[source*nbcuts+1]->SetTitle("C");
+  histopassedcuts[source*nbcuts+2]->SetTitle("C");
+  histopassedcuts[source*nbcuts+3]->SetTitle("C");
+  histopassedcuts[source*nbcuts+4]->SetTitle("C");
+  histopassedcuts[source*nbcuts+5]->SetTitle("C");
+  histopassedcuts[source*nbcuts+6]->SetTitle("C");
+  histopassedcuts[source*nbcuts+7]->SetTitle("C");
+  histopassedcuts[source*nbcuts+8]->SetTitle("C");
+  histopassedcuts[source*nbcuts+9]->SetTitle("C");
+  //histopassedcuts[source*nbcuts+0]->SetStats(0);
+  histopassedcuts[source*nbcuts+1]->SetStats(0);
+  histopassedcuts[source*nbcuts+2]->SetStats(0);
+  histopassedcuts[source*nbcuts+3]->SetStats(0);
+  histopassedcuts[source*nbcuts+4]->SetStats(0);
+  histopassedcuts[source*nbcuts+5]->SetStats(0);
+  histopassedcuts[source*nbcuts+6]->SetStats(0);
+  histopassedcuts[source*nbcuts+7]->SetStats(0);
+  histopassedcuts[source*nbcuts+8]->SetStats(0);
+  histopassedcuts[source*nbcuts+9]->SetStats(0);
+  //histopassedcuts[source*nbcuts+0]->Draw();
+  //histopassedcuts[source*nbcuts+1]->Draw();
+  histopassedcuts[source*nbcuts+2]->Draw();
+  histopassedcuts[source*nbcuts+3]->Draw("same");
+  //histopassedcuts[source*nbcuts+4]->Draw("same");
+  histopassedcuts[source*nbcuts+5]->Draw("same");
+  histopassedcuts[source*nbcuts+6]->Draw("same");
+  //histopassedcuts[source*nbcuts+7]->Draw("same");
+  histopassedcuts[source*nbcuts+8]->Draw("same");
+  histopassedcuts[source*nbcuts+9]->Draw("same");
+  TLegend *lege = new TLegend(0.4,0.6,0.89,0.89);
+  //lege->AddEntry(histopassedcuts[source*nbcuts+0],"all","p");
+  //lege->AddEntry(histopassedcuts[source*nbcuts+1],"Partner tracked","p");
+  lege->AddEntry(histopassedcuts[source*nbcuts+2],"Opposite sign","p");
+  lege->AddEntry(histopassedcuts[source*nbcuts+3],"SingleTrackPart","p");
+  //lege->AddEntry(histopassedcuts[source*nbcuts+4],"SharedCluster","p");
+  lege->AddEntry(histopassedcuts[source*nbcuts+5],"PID","p");
+  lege->AddEntry(histopassedcuts[source*nbcuts+6],"DCA","p");
+  //lege->AddEntry(histopassedcuts[source*nbcuts+7],"Chi2Ndf","p");
+  lege->AddEntry(histopassedcuts[source*nbcuts+8],"OpeningAngle","p");
+  lege->AddEntry(histopassedcuts[source*nbcuts+9],"InvMass","p");
+  lege->Draw("same");
+  
+  //////////////////////
+  // Input
+  //////////////////////
+  
+  TCanvas * chsSparseMCein =new TCanvas("hsSparseMCeinput","hsSparseMCeinput",800,800);
+  chsSparseMCein->cd(1);
+  Double_t nbGamma = 0.0;
+  source = 1;
+  if(((source*nbcuts+0)> (nbsources*nbcuts-1)) || (!histopassedcuts[source*nbcuts+0])) {
+    delete [] histopassedcuts;
+    delete [] nbEntriesCuts;
+    return;
+  }
+  nbGamma = histopassedcuts[source*nbcuts+0]->GetEntries();
+  histopassedcuts[source*nbcuts+0]->SetStats(0);
+  histopassedcuts[source*nbcuts+0]->Draw();
+  TLegend *leginput = new TLegend(0.4,0.6,0.89,0.89);
+  leginput->AddEntry(histopassedcuts[source*nbcuts+0],"#gamma","p");
+  Double_t nbPi0 = 0.0;
+  source = 2;
+  if(((source*nbcuts+0)> (nbsources*nbcuts-1)) || (!histopassedcuts[source*nbcuts+0])) {
+    delete [] histopassedcuts;
+    delete [] nbEntriesCuts;
+    return;
+  }
+  nbPi0 = histopassedcuts[source*nbcuts+0]->GetEntries();
+  histopassedcuts[source*nbcuts+0]->SetStats(0);
+  histopassedcuts[source*nbcuts+0]->Draw("same");
+  leginput->AddEntry(histopassedcuts[source*nbcuts+0],"#pi^{0}","p");
+  Double_t nbEta = 0.0;
+  source = 3;
+  if(((source*nbcuts+0)> (nbsources*nbcuts-1)) || (!histopassedcuts[source*nbcuts+0])) {
+    delete [] histopassedcuts;
+    delete [] nbEntriesCuts;
+    return;
+  }
+  nbEta = histopassedcuts[source*nbcuts+0]->GetEntries();
+  histopassedcuts[source*nbcuts+0]->SetStats(0);
+  histopassedcuts[source*nbcuts+0]->Draw("same");
+  leginput->AddEntry(histopassedcuts[source*nbcuts+0],"#eta","p");
+  Double_t nbC = 0.0;
+  source = 4;
+  if(((source*nbcuts+0)> (nbsources*nbcuts-1)) || (!histopassedcuts[source*nbcuts+0])) {
+    delete [] histopassedcuts;
+    delete [] nbEntriesCuts;
+    return;
+  }
+  nbC = histopassedcuts[source*nbcuts+0]->GetEntries();
+  histopassedcuts[source*nbcuts+0]->SetStats(0);
+  histopassedcuts[source*nbcuts+0]->Draw("same");
+  leginput->AddEntry(histopassedcuts[source*nbcuts+0],"c","p");
+  leginput->Draw("same");
+  
+  //printf("Gamma %f, pi^{0} %f and #eta %f, c %f\n",nbGamma,nbPi0,nbEta,nbC);
+  
+  //////////////////////
+  // Tracked
+  //////////////////////
+  
+  TCanvas * cTracked = new TCanvas("cTracked","cTracked",800,800);
+  cTracked->cd(1);
+  source = 1;
+  if(((source*nbcuts+1)> (nbsources*nbcuts-1)) || (!histopassedcuts[source*nbcuts+1])) {
+    delete [] histopassedcuts;
+    delete [] nbEntriesCuts;
+    return;
+  }
+  histopassedcuts[source*nbcuts+1]->Draw();
+  TLegend *legTracked = new TLegend(0.4,0.6,0.89,0.89);
+  legTracked->AddEntry(histopassedcuts[source*nbcuts+1],"#gamma","p");
+  source = 2;
+  if(((source*nbcuts+1)> (nbsources*nbcuts-1)) || (!histopassedcuts[source*nbcuts+1])) {
+    delete [] histopassedcuts;
+    delete [] nbEntriesCuts;
+    return;
+  }
+  histopassedcuts[source*nbcuts+1]->Draw("same");
+  legTracked->AddEntry(histopassedcuts[source*nbcuts+1],"#pi^{0}","p");
+  legTracked->Draw("same");
+  
+  delete [] histopassedcuts;
+  delete [] nbEntriesCuts;
+  
 }
 //_____________________________________________________________________________
 Double_t AliHFEelecbackground::BetheBlochElectronITS(const Double_t *x, const Double_t * /*par*/)