]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGHF/hfe/AliAnalysisTaskHFECal.cxx
Updates for TRD HFE analysis
[u/mrichter/AliRoot.git] / PWGHF / hfe / AliAnalysisTaskHFECal.cxx
index 3ec3b26e99a955b6caa80397f4dafc5006cee6f7..111c1722ba7939d450cc6408e85a4ec090273654 100644 (file)
 #include "TChain.h"
 #include "TTree.h"
 #include "TH2F.h"
+#include "TF1.h"
 #include "TMath.h"
 #include "TCanvas.h"
 #include "THnSparse.h"
 #include "TLorentzVector.h"
 #include "TString.h"
 #include "TFile.h"
+#include "TGraphErrors.h"
 
 #include "AliAnalysisTask.h"
 #include "AliAnalysisManager.h"
@@ -80,6 +82,8 @@
 
 #include "AliCentrality.h"
 
+using namespace std;
+
 ClassImp(AliAnalysisTaskHFECal)
 //________________________________________________________________________
 AliAnalysisTaskHFECal::AliAnalysisTaskHFECal(const char *name) 
@@ -101,7 +105,8 @@ AliAnalysisTaskHFECal::AliAnalysisTaskHFECal(const char *name)
   ,fPID(0)
   ,fPIDqa(0)          
   ,fOpeningAngleCut(0.1)
-  ,fInvmassCut(0.01)   
+  ,fInvmassCut(0)       // no mass
+  ,fSetMassConstraint(kTRUE)
   ,fNoEvents(0)
   ,fEMCAccE(0)
   ,hEMCAccE(0)
@@ -116,6 +121,8 @@ AliAnalysisTaskHFECal::AliAnalysisTaskHFECal(const char *name)
   ,fInvmassULS(0)              
   ,fInvmassLSmc(0)             
   ,fInvmassULSmc(0)            
+  ,fInvmassLSreco(0)           
+  ,fInvmassULSreco(0)          
   ,fInvmassLSmc0(0)            
   ,fInvmassLSmc1(0)            
   ,fInvmassLSmc2(0)            
@@ -136,6 +143,7 @@ AliAnalysisTaskHFECal::AliAnalysisTaskHFECal(const char *name)
   ,fTPCnsigma(0)
   ,fCent(0)
   ,fEleInfo(0)
+  ,fElenSigma(0)
   /*
   ,fClsEBftTrigCut(0)   
   ,fClsEAftTrigCut(0)   
@@ -183,12 +191,25 @@ AliAnalysisTaskHFECal::AliAnalysisTaskHFECal(const char *name)
   ,fMomDtoE(0) 
   ,fLabelCheck(0)
   ,fgeoFake(0)
+  ,fFakeTrk0(0)
+  ,fFakeTrk1(0)
+  ,ftimingEle(0)
+  ,fIncMaxE(0)
+  ,fIncReco(0)
+  ,fPhoReco(0)
+  ,fSamReco(0) 
+  ,fIncRecoMaxE(0)
+  ,fPhoRecoMaxE(0)
+  ,fSamRecoMaxE(0) 
+  //,fnSigEtaCorr(NULL)
 {
   //Named constructor
   
   fPID = new AliHFEpid("hfePid");
   fTrackCuts = new AliESDtrackCuts();
   
+  for(int i=0; i<7; i++)fnSigEtaCorr[i] = 0;
+
   // Define input and output slots here
   // Input slot #0 works with a TChain
   DefineInput(0, TChain::Class());
@@ -219,7 +240,8 @@ AliAnalysisTaskHFECal::AliAnalysisTaskHFECal()
   ,fPID(0)       
   ,fPIDqa(0)          
   ,fOpeningAngleCut(0.1)
-  ,fInvmassCut(0.01)   
+  ,fInvmassCut(0)       // no mass
+  ,fSetMassConstraint(kTRUE)
   ,fNoEvents(0)
   ,fEMCAccE(0)
   ,hEMCAccE(0)
@@ -234,6 +256,8 @@ AliAnalysisTaskHFECal::AliAnalysisTaskHFECal()
   ,fInvmassULS(0)              
   ,fInvmassLSmc(0)             
   ,fInvmassULSmc(0)            
+  ,fInvmassLSreco(0)           
+  ,fInvmassULSreco(0)          
   ,fInvmassLSmc0(0)            
   ,fInvmassLSmc1(0)            
   ,fInvmassLSmc2(0)            
@@ -254,6 +278,7 @@ AliAnalysisTaskHFECal::AliAnalysisTaskHFECal()
   ,fTPCnsigma(0)
   ,fCent(0)
   ,fEleInfo(0)
+  ,fElenSigma(0)
   /*
   ,fClsEBftTrigCut(0)   
   ,fClsEAftTrigCut(0)   
@@ -301,12 +326,25 @@ AliAnalysisTaskHFECal::AliAnalysisTaskHFECal()
   ,fMomDtoE(0)
   ,fLabelCheck(0)
   ,fgeoFake(0)
+  ,fFakeTrk0(0)
+  ,fFakeTrk1(0)
+  ,ftimingEle(0)
+  ,fIncMaxE(0)
+  ,fIncReco(0)
+  ,fPhoReco(0)
+  ,fSamReco(0)
+  ,fIncRecoMaxE(0)
+  ,fPhoRecoMaxE(0)
+  ,fSamRecoMaxE(0)
+  //,fnSigEtaCorr(NULL)
 {
        //Default constructor
        fPID = new AliHFEpid("hfePid");
 
        fTrackCuts = new AliESDtrackCuts();
        
+       for(int i=0; i<7; i++)fnSigEtaCorr[i] = 0;
+
        // Constructor
        // Define input and output slots here
        // Input slot #0 works with a TChain
@@ -461,6 +499,7 @@ void AliAnalysisTaskHFECal::UserExec(Option_t*)
    FindTriggerClusters();
 
   // make EMCAL array 
+  double maxE = 0.0;
   for(Int_t iCluster=0; iCluster<fESD->GetNumberOfCaloClusters(); iCluster++)
      {
       AliESDCaloCluster *clust = fESD->GetCaloCluster(iCluster);
@@ -478,6 +517,7 @@ void AliAnalysisTaskHFECal::UserExec(Option_t*)
          //if(clustE>3.0)fEMCAccE->Fill(calInfo); 
          //if(fqahist==1 && clustE>1.5)fEMCAccE->Fill(calInfo); 
          hEMCAccE->Fill(cent,clustE); 
+         if(clustE>maxE)maxE = clustE; 
         }
    }
 
@@ -512,7 +552,7 @@ void AliAnalysisTaskHFECal::UserExec(Option_t*)
        Int_t label = TMath::Abs(track->GetLabel());
        mcLabel = track->GetLabel();
        
-       //if(mcLabel>-1)
+       if(mcLabel>-1)
        {
       
               Bool_t MChijing = fMC->IsFromBGEvent(label);
@@ -597,10 +637,33 @@ void AliAnalysisTaskHFECal::UserExec(Option_t*)
                       }
               }
 
+               //cout << "===================="<<endl;
+               //cout << "mcDtoE : " << mcDtoE << endl; 
+               //cout << "mcBtoE : " << mcBtoE << endl; 
+               //cout << "mcPho : " << mcPho << endl; 
+
+              if(fabs(mcpid)==11)mcele= 0.; 
+               //cout << "check e: " << mcele << endl; 
               if(fabs(mcpid)==11 && mcDtoE)mcele= 1.; 
+               //cout << "check D->e: " << mcele << endl; 
               if(fabs(mcpid)==11 && mcBtoE)mcele= 2.; 
+               //cout << "check B->e: " << mcele << endl; 
               if(fabs(mcpid)==11 && mcPho)mcele= 3.; 
+               //cout << "check Pho->e: " << mcele << endl; 
 
+               //cout << "check PID " << endl;
+               if(fabs(mcpid)!=11)
+                 {
+                  //cout << "!= 11" << endl;
+                  //cout << mcpid << endl;
+                 }
+               if(mcele==-1)
+                 {
+                  //cout << "mcele==-1" << endl;
+                  //cout << mcele << endl;
+                  //cout << mcpid << endl;
+                 }
        } // end of mcLabel>-1
 
       } // end of MC info.
@@ -630,7 +693,7 @@ void AliAnalysisTaskHFECal::UserExec(Option_t*)
     if(!ProcessCutStep(AliHFEcuts::kStepHFEcutsTPC, track)) continue;
 
     int nTPCcl = track->GetTPCNcls();
-    int nTPCclF = track->GetTPCNclsF();
+    //int nTPCclF = track->GetTPCNclsF(); // warnings
     int nITS = track->GetNcls(0);
     
     fTrackPtAftTrkCuts->Fill(track->Pt());             
@@ -641,19 +704,23 @@ void AliAnalysisTaskHFECal::UserExec(Option_t*)
     
     // Track extrapolation
     
-    Int_t charge = track->Charge();
+    //Int_t charge = track->Charge();
     fTrkpt->Fill(pt);
     mom = track->P();
     phi = track->Phi();
     eta = track->Eta();
     dEdx = track->GetTPCsignal();
     fTPCnSigma = fPID->GetPIDResponse() ? fPID->GetPIDResponse()->NumberOfSigmasTPC(track, AliPID::kElectron) : 1000;
-    if(mcLabel==-1) // nsigma mean correction
-      {
-       double mean_corr = NsigCorr(cent);
-       printf("correction %f\n",mean_corr);
-       fTPCnSigma -= mean_corr;
-      }    
+
+    //cout << "nSigma correctoon-----" << endl;
+    //cout << "org = " << fTPCnSigma << endl; 
+    if(!fmcData) // nsigma eta correction
+       {
+        double nSigexpCorr = NsigmaCorrection(eta,cent);
+        fTPCnSigma -= nSigexpCorr;
+       }
+
+    //cout << "correction = " << fTPCnSigma << endl; 
 
         double ncells = -1.0;
         double m20 = -1.0;
@@ -662,6 +729,8 @@ void AliAnalysisTaskHFECal::UserExec(Option_t*)
         double rmatch = -1.0;  
         double nmatch = -1.0;
         double oppstatus = 0.0;
+        double emctof = 0.0;
+        Bool_t MaxEmatch = kFALSE;
 
     Bool_t fFlagPhotonicElec = kFALSE;
     Bool_t fFlagConvinatElec = kFALSE;
@@ -672,7 +741,16 @@ void AliAnalysisTaskHFECal::UserExec(Option_t*)
       if(clust && clust->IsEMCAL()){
 
                double clustE = clust->E();
+                if(clustE==maxE)MaxEmatch = kTRUE;
                 eop = clustE/fabs(mom);
+                 //cout << "eop org = "<< eop << endl;
+                if(mcLabel>-1.0)
+                  {
+                   double mceopcorr = MCEopMeanCorrection(pt,cent);
+                   eop += mceopcorr;
+                  }
+                //cout << "eop corr = " << eop << endl;
+
                 //double clustT = clust->GetTOF();
                 ncells = clust->GetNCells();
                 m02 = clust->GetM02();
@@ -682,6 +760,8 @@ void AliAnalysisTaskHFECal::UserExec(Option_t*)
                double deleta = clust->GetTrackDz(); 
                rmatch = sqrt(pow(delphi,2)+pow(deleta,2));
                nmatch = clust->GetNTracksMatched();
+                emctof = clust->GetTOF();
+                //cout << "emctof = " << emctof << endl;
 
                if(fTPCnSigma>-1.5 && fTPCnSigma<3.0)
                {
@@ -693,15 +773,31 @@ void AliAnalysisTaskHFECal::UserExec(Option_t*)
 
                  double valdedx[16];
                  valdedx[0] = pt; valdedx[1] = nITS; valdedx[2] = phi; valdedx[3] = eta; valdedx[4] = fTPCnSigma;
-                 valdedx[5] = eop; valdedx[6] = rmatch; valdedx[7] = ncells,  valdedx[8] = nTPCclF; valdedx[9] = m20; valdedx[10] = mcpT;
-                 valdedx[11] = cent; valdedx[12] = charge; valdedx[13] = oppstatus; valdedx[14] = nTPCcl;
+                 //valdedx[5] = eop; valdedx[6] = rmatch; valdedx[7] = ncells,  valdedx[8] = nTPCclF; valdedx[9] = m20; valdedx[10] = mcpT;
+                 valdedx[5] = eop; valdedx[6] = rmatch; valdedx[7] = ncells,  valdedx[8] = nmatch; valdedx[9] = m20; valdedx[10] = mcpT;
+                 valdedx[11] = cent; valdedx[12] = dEdx; valdedx[13] = oppstatus; valdedx[14] = nTPCcl;
                   valdedx[15] = mcele;
-                  if(fqahist==1)fEleInfo->Fill(valdedx);
+                  //if(fqahist==1)fEleInfo->Fill(valdedx);
                  
 
       }
     }
-     
+
+    //Get Cal info PID response
+    double eop2;
+    double ss[4];
+    Double_t nSigmaEop = fPID->GetPIDResponse()->NumberOfSigmasEMCAL(track,AliPID::kElectron,eop2,ss);
+    if(fTPCnSigma>-1.5 && fTPCnSigma<3.0 && nITS>2.5 && nTPCcl>100)
+      {
+       double valEop[3];
+       valEop[0] = cent;
+       valEop[1] = pt;
+       valEop[2] = nSigmaEop;
+       fElenSigma->Fill(valEop);
+      }
+
+   // ============ PID
+
     if(nITS<2.5)continue;
     if(nTPCcl<100)continue;
    
@@ -723,7 +819,7 @@ void AliAnalysisTaskHFECal::UserExec(Option_t*)
     phoval[3] = iHijing;
     phoval[4] = mcMompT;
    
-    if((fTPCnSigma >= -1.0 && fTPCnSigma <= 3) && mcele>0 && mcPho && mcOrgPi0)
+    if((fTPCnSigma >= -1.0 && fTPCnSigma <= 3) && mcele>-1 && mcPho && mcOrgPi0)
       {
         if(iHijing==1)mcWeight = 1.0; 
         fIncpTMCpho_pi0e_TPC->Fill(phoval,mcWeight);    
@@ -764,11 +860,34 @@ void AliAnalysisTaskHFECal::UserExec(Option_t*)
 
     if(m20>0.0 && m20<0.3)
       { 
-       fIncpTM20->Fill(cent,pt);    
+       fIncpTM20->Fill(cent,pt);   
+       ftimingEle->Fill(pt,emctof); 
        if(fFlagPhotonicElec) fPhoElecPtM20->Fill(cent,pt);
        if(fFlagConvinatElec) fSameElecPtM20->Fill(cent,pt);
      }
     
+    //--------
+     
+    double recopT =  SumpT(iTracks,track);
+
+    if(m20>0.0 && m20<0.3)
+      {
+       if(MaxEmatch)fIncMaxE->Fill(cent,pt);
+       if(pt>5.0)
+         {
+          fIncReco->Fill(cent,recopT);
+          if(fFlagPhotonicElec) fPhoReco->Fill(cent,recopT);
+          if(fFlagConvinatElec) fSamReco->Fill(cent,recopT);
+          if(MaxEmatch)
+            {
+             fIncRecoMaxE->Fill(cent,recopT);
+             if(fFlagPhotonicElec) fPhoRecoMaxE->Fill(cent,recopT);
+             if(fFlagConvinatElec) fSamRecoMaxE->Fill(cent,recopT);
+            }
+         }
+     }
+
     // MC
     // check label for electron candidiates
 
@@ -777,11 +896,17 @@ void AliAnalysisTaskHFECal::UserExec(Option_t*)
     fLabelCheck->Fill(pt,idlabel);
     if(mcLabel==0)fgeoFake->Fill(phi,eta);
 
-    if(mcele>0) // select MC electrons
+    if(mcLabel<0 && m20>0.0 && m20<0.3 && fTPCnSigma>-1 && fTPCnSigma<3)
+       {
+        fFakeTrk0->Fill(cent,pt);
+       }
+
+    if(mcele>-1) // select MC electrons
       {
 
           fIncpTMChfeAll->Fill(cent,pt);    
           if(m20>0.0 && m20<0.3)fIncpTMCM20hfeAll->Fill(cent,pt);    
+          if(m20>0.0 && m20<0.3 && fTPCnSigma>-1 && fTPCnSigma<3)fFakeTrk1->Fill(cent,pt);
 
        if(mcBtoE || mcDtoE) // select B->e & D->e
          {
@@ -790,7 +915,7 @@ void AliAnalysisTaskHFECal::UserExec(Option_t*)
           //if(m20>0.0 && m20<0.3)fIncpTMCM20hfeCheck->Fill(cent,mcpT);    
           if(m20>0.0 && m20<0.3)
             {
-                cout << "MC label = " << mcLabel << endl;
+                //cout << "MC label = " << mcLabel << endl;
                 fIncpTMCM20hfe->Fill(cent,pt);    
                 fIncpTMCM20hfeCheck->Fill(cent,mcpT);    
                 fIncpTMCM20hfeCheck_weight->Fill(phoval);    
@@ -932,7 +1057,7 @@ void AliAnalysisTaskHFECal::UserCreateOutputObjects()
   Double_t xminE[5] = {1.0,  -1,   0.0,   0, -0.5}; 
   Double_t xmaxE[5] = {3.5,   1, 100.0, 100,  9.5}; 
   fEMCAccE = new THnSparseD("fEMCAccE","EMC acceptance & E;#eta;#phi;Energy;Centrality;trugCondition;",5,binsE,xminE,xmaxE);
-  if(fqahist==1)fOutputList->Add(fEMCAccE);
+  //if(fqahist==1)fOutputList->Add(fEMCAccE);
 
   hEMCAccE = new TH2F("hEMCAccE","Cluster Energy",200,0,100,100,0,20);
   fOutputList->Add(hEMCAccE);
@@ -967,9 +1092,9 @@ void AliAnalysisTaskHFECal::UserCreateOutputObjects()
   fIncpTM20 = new TH2F("fIncpTM20","HFE pid electro vs. centrality with M20",200,0,100,100,0,50);
   fOutputList->Add(fIncpTM20);
   
-  Int_t nBinspho[9] =  { 200, 100, 500, 12,   50,    4, 200,   8, 100};
-  Double_t minpho[9] = {  0.,  0.,  0., -2.5,  0, -0.5,   0,-1.5,   0};   
-  Double_t maxpho[9] = {100., 50., 0.5, 3.5,   1,  3.5,   2, 6.5,  50};   
+  Int_t nBinspho[9] =  { 10,  30,   600, 60,   50,    4,  40,   8,  30};
+  Double_t minpho[9] = {  0.,  0., -0.1, 40,  0, -0.5,   0,-1.5,   0};   
+  Double_t maxpho[9] = {100., 30.,  0.5, 100,   1,  3.5,   2, 6.5,  30};   
 
   fInvmassLS = new THnSparseD("fInvmassLS", "Inv mass of LS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2); nSigma; angle; m20cut; eop; Mcele;", 9, nBinspho,minpho, maxpho);
   if(fqahist==1)fOutputList->Add(fInvmassLS);
@@ -983,35 +1108,43 @@ void AliAnalysisTaskHFECal::UserCreateOutputObjects()
   fInvmassULSmc = new THnSparseD("fInvmassULSmc", "Inv mass of ULS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2); nSigma; angle; m20cut; eop; MCele", 9, nBinspho,minpho, maxpho);
   if(fqahist==1)fOutputList->Add(fInvmassULSmc);
 
-  fInvmassLSmc0 = new TH2D("fInvmassLSmc0", "Inv mass of LS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,500,0,0.5 );
+  fInvmassLSreco = new TH2D("fInvmassLSreco", "Inv mass of LS (e,e) reco; cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,600,-0.1,0.5 );
+  fInvmassLSreco->Sumw2();
+  fOutputList->Add(fInvmassLSreco);
+
+  fInvmassULSreco = new TH2D("fInvmassULSreco", "Inv mass of ULS (e,e) reco; cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,600,-0.1,0.5 );
+  fInvmassULSreco->Sumw2();
+  fOutputList->Add(fInvmassULSreco);
+
+  fInvmassLSmc0 = new TH2D("fInvmassLSmc0", "Inv mass of LS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,600,-0.1,0.5 );
   fInvmassLSmc0->Sumw2();
   fOutputList->Add(fInvmassLSmc0);
   
-  fInvmassLSmc1 = new TH2D("fInvmassLSmc1", "Inv mass of LS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,500,0,0.5 );
+  fInvmassLSmc1 = new TH2D("fInvmassLSmc1", "Inv mass of LS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,600,-0.1,0.5 );
   fInvmassLSmc1->Sumw2();
   fOutputList->Add(fInvmassLSmc1);
 
-  fInvmassLSmc2 = new TH2D("fInvmassLSmc2", "Inv mass of LS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,500,0,0.5 );
+  fInvmassLSmc2 = new TH2D("fInvmassLSmc2", "Inv mass of LS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,600,-0.1,0.5 );
   fInvmassLSmc2->Sumw2();
   fOutputList->Add(fInvmassLSmc2);
 
-  fInvmassLSmc3 = new TH2D("fInvmassLSmc3", "Inv mass of LS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,500,0,0.5 );
+  fInvmassLSmc3 = new TH2D("fInvmassLSmc3", "Inv mass of LS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,600,-0.1,0.5 );
   fInvmassLSmc3->Sumw2();
   fOutputList->Add(fInvmassLSmc3);
 
-  fInvmassULSmc0 = new TH2D("fInvmassULSmc0", "Inv mass of ULS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,500,0,0.5 );
+  fInvmassULSmc0 = new TH2D("fInvmassULSmc0", "Inv mass of ULS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,600,-0.1,0.5 );
   fInvmassULSmc0->Sumw2();
   fOutputList->Add(fInvmassULSmc0);
 
-  fInvmassULSmc1 = new TH2D("fInvmassULSmc1", "Inv mass of ULS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,500,0,0.5 );
+  fInvmassULSmc1 = new TH2D("fInvmassULSmc1", "Inv mass of ULS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,600,-0.1,0.5 );
   fInvmassULSmc1->Sumw2();
   fOutputList->Add(fInvmassULSmc1);
 
-  fInvmassULSmc2 = new TH2D("fInvmassULSmc2", "Inv mass of ULS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,500,0,0.5 );
+  fInvmassULSmc2 = new TH2D("fInvmassULSmc2", "Inv mass of ULS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,600,-0.1,0.5 );
   fInvmassULSmc2->Sumw2();
   fOutputList->Add(fInvmassULSmc2);
 
-  fInvmassULSmc3 = new TH2D("fInvmassULSmc3", "Inv mass of ULS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,500,0,0.5 );
+  fInvmassULSmc3 = new TH2D("fInvmassULSmc3", "Inv mass of ULS (e,e); cent; p_{T} (GeV/c); mass(GeV/c^2)",20,0,20,600,-0.1,0.5 );
   fInvmassULSmc3->Sumw2();
   fOutputList->Add(fInvmassULSmc3);
 
@@ -1041,17 +1174,23 @@ void AliAnalysisTaskHFECal::UserCreateOutputObjects()
  
   // Make common binning
   const Double_t kMinP = 0.;
-  const Double_t kMaxP = 50.;
-  //const Double_t kTPCSigMim = 40.;
-  //const Double_t kTPCSigMax = 140.;
+  const Double_t kMaxP = 20.;
 
   // 1st histogram: TPC dEdx with/without EMCAL (p, pT, TPC Signal, phi, eta,  Sig,  e/p,  ,match, cell, M02, M20, Disp, Centrality, select)
-  Int_t nBins[16] =  {  250,    10,   60,    20,   100,  300,  50,   40,   200, 200,  250, 200,    3,    5, 100,    8};
-  Double_t min[16] = {kMinP,  -0.5, 1.0,  -1.0,  -6.0,    0,   0,    0,   0.0, 0.0,  0.0,   0, -1.5, -0.5,  80, -1.5};
-  Double_t max[16] = {kMaxP,   9.5, 4.0,   1.0,   4.0,  3.0, 0.1,   40,   200, 2.0, 50.0, 100,  1.5,  4.5, 180,  6.5};
+  Int_t nBins[16] =  {  100,     7,  60,    20,    90,  250,   25,   40,   10, 200,  100, 100,  500,    5, 100,    8};
+  Double_t min[16] = {kMinP,  -0.5, 1.0,  -1.0,  -5.0,    0,    0,    0,  0.0, 0.0,  0.0,   0,    0, -0.5,  80, -1.5};
+  Double_t max[16] = {kMaxP,   6.5, 4.0,   1.0,   4.0,  2.5, 0.05,   40,   10, 2.0, 20.0, 100,  100,  4.5, 180,  6.5};
   fEleInfo = new THnSparseD("fEleInfo", "Electron Info; pT [GeV/c]; TPC signal;phi;eta;nSig; E/p;Rmatch;Ncell;clsF;M20;mcpT;Centrality;charge;opp;same;trigCond;MCele", 16, nBins, min, max);
   if(fqahist==1)fOutputList->Add(fEleInfo);
 
+  // Make common binning
+  Int_t nBinsEop[3] =  { 10, 50, 100};
+  Double_t minEop[3] = {  0,  0,  -5};
+  Double_t maxEop[3] = {100, 50,   5};
+  fElenSigma= new THnSparseD("fElenSigma", "Electron nSigma; cent; pT [GeV/c]; nSigma", 3, nBinsEop, minEop, maxEop);
+  fOutputList->Add(fElenSigma);
+
+
   //<---  Trigger info
   /*
   fClsEBftTrigCut = new TH1F("fClsEBftTrigCut","cluster E before trigger selection",1000,0,100);
@@ -1217,6 +1356,57 @@ void AliAnalysisTaskHFECal::UserCreateOutputObjects()
   fgeoFake = new TH2D("fgeoFake","Label==0 eta and phi",628,0,6.28,200,-1,1);
   fOutputList->Add(fgeoFake);
 
+  fFakeTrk0 = new TH2D("fFakeTrk0","fake trakcs",10,0,100,20,0,20);
+  fOutputList->Add(fFakeTrk0);
+
+  fFakeTrk1 = new TH2D("fFakeTrk1","true all e a.f. eID",10,0,100,20,0,20);
+  fOutputList->Add(fFakeTrk1);
+
+  ftimingEle = new TH2D("ftimingEle","electron TOF",100,0,20,100,1e-7,1e-6);
+  fOutputList->Add(ftimingEle);
+
+  // eta correction
+  // note: parameters 01/31new.TPCnSigmaEtaDep
+  // 70-90 delta_eta = 0.2
+
+  double etaval[12] = {-0.55,-0.45,-0.35,-0.25,-0.15,-0.05,0.05,0.15,0.25,0.35,0.45,0.55};
+  double corr0[12]= {-0.569177,-0.528844,-0.391979,-0.165494,0.0283495,0.156171,0.266353,0.13103,-0.0250842,-0.274089,-0.45481,-0.536291}; // 0-10 (done)
+  double corr1[12]= {-0.404742,-0.278953,-0.218069,0.00139927,0.191412,0.354403,0.524594,0.341778,0.244199,-0.112146,-0.160692,-0.352832}; // 10-20 (done)
+  double corr2[12] = {-0.306007,-0.16821,-0.0248635,0.202233,0.447051,0.497197,0.712251,0.433482,0.337907,0.168426,-0.0693229,-0.0728351}; // 20-30 (done)
+  double corr3[12] = {-0.13884,-0.0503553,0.104403,0.389773,0.50697,0.539048,0.751642,0.655636,0.518563,0.308156,0.0361159,-0.0491439}; // 30-40 (done)
+  double corr4[12] = {-0.0319431,0.0808711,0.208774,0.443217,0.557762,0.61453,0.889519,0.808282,0.620394,0.267092,0.15241,-0.0458664}; // 40-50 (done)
+  double corr5[12] = {-0.130625,0.0189124,0.190344,0.467431,0.546353,0.672251,0.731541,0.802101,0.437108,0.294081,0.193682,0.159074}; // 50-70(done)
+  double corr6[12] = {0.0600197,0.0600197,0.358366,0.358366,0.973734,0.973734,0.759812,0.759812,0.667861,0.667861,0.415635,0.415635}; // 70-90(done)
+  fnSigEtaCorr[0] = new TGraphErrors(12,etaval,corr0); // 0-10
+  fnSigEtaCorr[1] = new TGraphErrors(12,etaval,corr1); // 10-20
+  fnSigEtaCorr[2] = new TGraphErrors(12,etaval,corr2); // 20-30
+  fnSigEtaCorr[3] = new TGraphErrors(12,etaval,corr3); // 30-40 
+  fnSigEtaCorr[4] = new TGraphErrors(12,etaval,corr4); // 40-50
+  fnSigEtaCorr[5] = new TGraphErrors(12,etaval,corr5); // 50-70
+  fnSigEtaCorr[6] = new TGraphErrors(12,etaval,corr6); // 70-90
+
+  fIncMaxE = new TH2D("fIncMaxE","Inc",10,0,100,10,0,100);
+  fOutputList->Add(fIncMaxE);
+
+  fIncReco = new TH2D("fIncReco","Inc",10,0,100,100,0,500);
+  fOutputList->Add(fIncReco);
+
+  fPhoReco = new TH2D("fPhoReco","Pho",10,0,100,100,0,500);
+  fOutputList->Add(fPhoReco);
+
+  fSamReco = new TH2D("fSamReco","Same",10,0,100,100,0,500);
+  fOutputList->Add(fSamReco);
+
+  fIncRecoMaxE = new TH2D("fIncRecoMaxE","Inc",10,0,100,100,0,500);
+  fOutputList->Add(fIncRecoMaxE);
+
+  fPhoRecoMaxE = new TH2D("fPhoRecoMaxE","Pho",10,0,100,100,0,500);
+  fOutputList->Add(fPhoRecoMaxE);
+
+  fSamRecoMaxE = new TH2D("fSamRecoMaxE","Same",10,0,100,100,0,500);
+  fOutputList->Add(fSamRecoMaxE);
+
   PostData(1,fOutputList);
 }
 
@@ -1236,8 +1426,6 @@ Bool_t AliAnalysisTaskHFECal::ProcessCutStep(Int_t cutStep, AliVParticle *track)
   return kTRUE;
 }
 //_________________________________________
-//void AliAnalysisTaskHFECal::SelectPhotonicElectron(Int_t itrack, Double_t cent, AliESDtrack *track, Bool_t &fFlagPhotonicElec)
-//void AliAnalysisTaskHFECal::SelectPhotonicElectron(Int_t itrack, Double_t cent, AliESDtrack *track, Bool_t &fFlagPhotonicElec, Bool_t &fFlagConvinatElec, Double_t nSig)
 void AliAnalysisTaskHFECal::SelectPhotonicElectron(Int_t itrack, Double_t cent, AliESDtrack *track, Bool_t &fFlagPhotonicElec, Bool_t &fFlagConvinatElec, Double_t nSig, Double_t shower, Double_t ep, Double_t mce, Double_t w, Int_t ibgevent, Bool_t tagpi0, Bool_t tageta)
 {
   //Identify non-heavy flavour electrons using Invariant mass method
@@ -1318,30 +1506,35 @@ void AliAnalysisTaskHFECal::SelectPhotonicElectron(Int_t itrack, Double_t cent,
     
     //printf("fFlagLS = %d\n",fFlagLS);
     //printf("fFlagULS = %d\n",fFlagULS);
-    //printf("\n");
+    printf("\n");
 
     AliKFParticle ge1(*track, fPDGe1);
     AliKFParticle ge2(*trackAsso, fPDGe2);
     AliKFParticle recg(ge1, ge2);
     
-    if(recg.GetNDF()<1) continue;
-    Double_t chi2recg = recg.GetChi2()/recg.GetNDF();
-    if(TMath::Sqrt(TMath::Abs(chi2recg))>3.) continue;
-    
-    //  for v5-03-70-AN comment
+    // vertex 
     AliKFVertex primV(*pVtx);
     primV += recg;
     recg.SetProductionVertex(primV);
     
-    recg.SetMassConstraint(0,0.0001);
-    
+    // check chi2
+    if(recg.GetNDF()<1) continue;
+    Double_t chi2recg = recg.GetChi2()/recg.GetNDF();
+    Double_t chi2cut = 3.0;
+
+    // mass.
+    if(fSetMassConstraint)
+      {
+       recg.SetMassConstraint(0,0.0001);
+       chi2cut = 30.0;
+      }
+    recg.GetMass(mass,width);
+
+        // angle   
     openingAngle = ge1.GetAngle(ge2);
     if(fFlagLS) fOpeningAngleLS->Fill(openingAngle);
     if(fFlagULS) fOpeningAngleULS->Fill(openingAngle);
     
-    
-    recg.GetMass(mass,width);
-    
     double ishower = 0;
     if(shower>0.0 && shower<0.3)ishower = 1;
 
@@ -1350,6 +1543,7 @@ void AliAnalysisTaskHFECal::SelectPhotonicElectron(Int_t itrack, Double_t cent,
     phoinfo[1] = ptPrim;
     phoinfo[2] = mass;
     phoinfo[3] = nSig;
+    //phoinfo[3] = dEdxAsso;
     phoinfo[4] = openingAngle;
     phoinfo[5] = ishower;
     phoinfo[6] = ep;
@@ -1366,15 +1560,21 @@ void AliAnalysisTaskHFECal::SelectPhotonicElectron(Int_t itrack, Double_t cent,
     //printf("fInvmassCut %f\n",fInvmassCut);
     //printf("openingAngle %f\n",fOpeningAngleCut);
 
+    // angle cut
     if(openingAngle > fOpeningAngleCut) continue;
-    
+    // chi2 cut
+    //if(TMath::Sqrt(TMath::Abs(chi2recg))>chi2cut) continue;
+    if(chi2recg>chi2cut) continue;
+    if(fFlagLS ) fInvmassLSreco->Fill(ptPrim,mass);
+    if(fFlagULS) fInvmassULSreco->Fill(ptPrim,mass);
+  
     // for real data  
     //printf("mce =%f\n",mce);
     if(mce<-0.5) // mce==-1. is real
        {
          //printf("Real data\n");
         if(mass<fInvmassCut && fFlagULS && !flagPhotonicElec){
-        //if(mass<fInvmassCut && fFlagULS && !flagPhotonicElec && (p1==p2)){ <--- only MC train (55,56) v5-03-68-AN & 69 for check
               flagPhotonicElec = kTRUE;
              }
         if(mass<fInvmassCut && fFlagLS && !flagConvinatElec){
@@ -1389,15 +1589,16 @@ void AliAnalysisTaskHFECal::SelectPhotonicElectron(Int_t itrack, Double_t cent,
          if(w>0.0)
            {
            //cout << "tagpi0 = " << tagpi0 << " ; tageta = " << tageta << endl;
-           if(fFlagLS && ibgevent==0 && jbgevent==0 && tagpi0) fInvmassLSmc0->Fill(ptPrim,mass,w);
-           if(fFlagULS && ibgevent==0 && jbgevent==0 && tagpi0) fInvmassULSmc0->Fill(ptPrim,mass,w);
-           if(fFlagLS && ibgevent==0 && jbgevent==0 && tageta) fInvmassLSmc1->Fill(ptPrim,mass,w);
-           if(fFlagULS && ibgevent==0 && jbgevent==0 && tageta) fInvmassULSmc1->Fill(ptPrim,mass,w);
-           if(fFlagLS && ibgevent==0 && jbgevent==0 && (p1==p2) && tagpi0) fInvmassLSmc2->Fill(ptPrim,mass,w);
-           if(fFlagULS && ibgevent==0 && jbgevent==0 && (p1==p2) && tagpi0) fInvmassULSmc2->Fill(ptPrim,mass,w);
-           if(fFlagLS && ibgevent==0 && jbgevent==0 && (p1==p2) && tageta) fInvmassLSmc3->Fill(ptPrim,mass,w);
-           if(fFlagULS && ibgevent==0 && jbgevent==0 && (p1==p2) && tageta) fInvmassULSmc3->Fill(ptPrim,mass,w);
+           if(fFlagLS && ibgevent==0 && jbgevent==0 && tagpi0) fInvmassLSmc0->Fill(ptPrim,mass);
+           if(fFlagULS && ibgevent==0 && jbgevent==0 && tagpi0) fInvmassULSmc0->Fill(ptPrim,mass);
+           if(fFlagLS && ibgevent==0 && jbgevent==0 && tageta) fInvmassLSmc1->Fill(ptPrim,mass);
+           if(fFlagULS && ibgevent==0 && jbgevent==0 && tageta) fInvmassULSmc1->Fill(ptPrim,mass);
+           if(fFlagLS && ibgevent==0 && jbgevent==0 && (p1==p2) && tagpi0) fInvmassLSmc2->Fill(ptPrim,mass);
+           if(fFlagULS && ibgevent==0 && jbgevent==0 && (p1==p2) && tagpi0) fInvmassULSmc2->Fill(ptPrim,mass);
+           if(fFlagLS && ibgevent==0 && jbgevent==0 && (p1==p2) && tageta) fInvmassLSmc3->Fill(ptPrim,mass);
+           if(fFlagULS && ibgevent==0 && jbgevent==0 && (p1==p2) && tageta) fInvmassULSmc3->Fill(ptPrim,mass);
           }
+
         if(mass<fInvmassCut && fFlagULS && !flagPhotonicElec && (ibgevent==jbgevent)){
         //if(mass<fInvmassCut && fFlagULS && !flagPhotonicElec && (p1==p2)){ <--- only MC train (55,56) v5-03-68-AN & 69 for check
               flagPhotonicElec = kTRUE;
@@ -1549,7 +1750,8 @@ void AliAnalysisTaskHFECal::FindTriggerClusters()
   // part 2 go through the clusters here -----------------------------------
   //cout << " part 2 go through the clusters here ----------------------------------- " << endl; 
   Int_t nCluster=0, nCell=0, iCell=0, gCell=0;
-  Short_t cellAddr, nSACell, mclabel;
+  Short_t cellAddr, nSACell;
+  Int_t mclabel;
   //Int_t nSACell, iSACell, mclabel;
   Int_t iSACell;
   Double_t cellAmp=0, cellTimeT=0, clusterTime=0, efrac=0;
@@ -1706,18 +1908,138 @@ void AliAnalysisTaskHFECal::FindTriggerClusters()
   } // clusters
 }
 
-
-double AliAnalysisTaskHFECal::NsigCorr(int cent)
+// <-------- only MC correction
+double AliAnalysisTaskHFECal::MCEopMeanCorrection(double pTmc, float central)
 {
+  TF1 *fcorr0 = new TF1("fcorr0","[0]*tanh([1]+[2]*x)"); 
+  TF1 *fcorr1 = new TF1("fcorr1","[0]*tanh([1]+[2]*x)"); 
+
  double shift = 0.0;
- if(cent>=20 && cent<30)shift = 0.156;
- if(cent>=30 && cent<40)shift = 0.316;
- if(cent>=40 && cent<50)shift = 0.336;
- if(cent>=50 && cent<70)shift = 0.440;
- if(cent>=70 && cent<90)shift = 0.534;
+  
+ if(central>0 && central<=10)
+   {
+    fcorr0->SetParameters(1.045,1.288,3.18e-01); //
+    fcorr1->SetParameters(9.91e-01,3.466,2.344);
+   }
+ else if(central>10 && central<=20)
+   {
+    fcorr0->SetParameters(1.029,8.254e-01,4.07e-01);
+    fcorr1->SetParameters(0.975,2.276,1.501e-01);
+   }
+ else if(central>20 && central<=30)
+   {
+    fcorr0->SetParameters(1.01,8.795e-01,3.904e-01);
+    fcorr1->SetParameters(9.675e-01,1.654,2.583e-01);
+   }
+ else if(central>30 && central<=40)
+   {
+    fcorr0->SetParameters(1.00,1.466,2.305e-1);
+    fcorr1->SetParameters(9.637e-01,1.473,2.754e-01);
+   }
+ else if(central>40 && central<=50)
+   {
+    fcorr0->SetParameters(1.00,1.422,1.518e-01);
+    fcorr1->SetParameters(9.59e-01,1.421,2.931e-01);
+   }
+ else if(central>50 && central<=70)
+   {
+    fcorr0->SetParameters(0.989,2.495,2.167);
+    fcorr1->SetParameters(0.961,1.734,1.438e-01);
+   }
+ else if(central>70 && central<=100)
+   {
+    fcorr0->SetParameters(0.981,-3.373,3.93327);
+    fcorr1->SetParameters(9.574e-01,1.698,1.58e-01);
+   }
+
+ shift = fcorr0->Eval(pTmc)-fcorr1->Eval(pTmc);
+
  return shift;
 }
 
+// <-------- only Data correction
+double AliAnalysisTaskHFECal::NsigmaCorrection(double tmpeta, float central)
+{
+ int icent = 0;
 
+ if(central>=0 && central<10)
+   {
+    icent = 0;
+   }
+ else if(central>=10 && central<20)
+  {
+   icent = 1;
+  }
+ else if(central>=20 && central<30)
+  {
+   icent = 2;
+  }
+ else if(central>=30 && central<40)
+  {
+   icent = 3;
+  }
+ else if(central>=40 && central<50)
+  {
+   icent = 4;
+  }
+ else if(central>=50 && central<70)
+  {
+   icent = 5;
+  }
+ else
+  {
+   icent = 6;
+  }
+
+ double shift = fnSigEtaCorr[icent]->Eval(tmpeta);
+ //cout << "eta correction"<< endl;
+ //cout << "cent = "<< central<< endl;
+ //cout << "icent = "<< icent << endl;
+ //cout << "shift = "<< shift << endl;
+
+ return shift;
+
+}
+
+
+double AliAnalysisTaskHFECal::SumpT(Int_t itrack, AliESDtrack* track)
+{
+  fTrackCuts->SetAcceptKinkDaughters(kFALSE);
+  fTrackCuts->SetRequireTPCRefit(kTRUE);
+  fTrackCuts->SetRequireITSRefit(kTRUE);
+  fTrackCuts->SetEtaRange(-0.9,0.9);
+  //fTrackCuts->SetRequireSigmaToVertex(kTRUE);
+  fTrackCuts->SetMaxChi2PerClusterTPC(3.5);
+  fTrackCuts->SetMinNClustersTPC(90);
+  double pTrecp = track->Pt();
+  double phiorg = track->Phi();
+  double etaorg = track->Eta();
 
+  for(Int_t jTracks = 0; jTracks<fESD->GetNumberOfTracks(); jTracks++){
+    AliESDtrack* trackAsso = fESD->GetTrack(jTracks);
+    if (!trackAsso) {
+      printf("ERROR: Could not receive track %d\n", jTracks);
+      continue;
+    }
+    if(itrack==jTracks)continue;
+    double pTAss = trackAsso->Pt();
+    double etaAss = trackAsso->Eta();
+    double phiAss = trackAsso->Phi();
+
+    double delphi = phiorg - phiAss;
+    double deleta = etaorg - etaAss;
+
+    double R = sqrt(pow(deleta,2)+pow(delphi,2));
+    if(pTAss<0.5)continue;
+    if(R<0.4)pTrecp+=pTAss;
+
+    }
+   return pTrecp;
+}