]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGLF/SPECTRA/PiKaPr/TPCTOFpA/AliAnalysisTPCTOFpA.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGLF / SPECTRA / PiKaPr / TPCTOFpA / AliAnalysisTPCTOFpA.cxx
index f3cddfbba277be5afd093391da1c47c58d04ef2d..d1ec18ab124a9d58973d2136f768869b53b42f6d 100644 (file)
@@ -74,6 +74,13 @@ AliAnalysisTPCTOFpA::AliAnalysisTPCTOFpA()
   fSmallTHnSparse(0),
   fIspA(0),
   fRapCMS(0),
+  fCentEst(0),
+  fTOFmisMatch(0),
+  fTRDinReject(0),
+  fTOFwindow(0),
+  fDCAzCut(0),
+  fCrossedRows(0),
+  fRatioRowsClusters(0),
   fTPCnSigmaCutLow(0),
   fTPCnSigmaCutHigh(0),
   fRapidityCutLow(0),
@@ -84,7 +91,8 @@ AliAnalysisTPCTOFpA::AliAnalysisTPCTOFpA()
   fHistMCparticles(0),
   fHistPidQA(0),
   fHistMult(0),
-  fHistCentrality(0)
+  fHistCentrality(0),
+  fHistTOFwindow(0)
 {
   // default Constructor
   /* fast compilation test
@@ -106,6 +114,13 @@ AliAnalysisTPCTOFpA::AliAnalysisTPCTOFpA(const char *name)
     fSmallTHnSparse(0),
     fIspA(0),
     fRapCMS(0),
+    fCentEst(0),
+    fTOFmisMatch(0),
+    fTRDinReject(0),
+    fTOFwindow(0),
+    fDCAzCut(0),
+    fCrossedRows(0),
+    fRatioRowsClusters(0),
     fTPCnSigmaCutLow(0),
     fTPCnSigmaCutHigh(0),
     fRapidityCutLow(0),
@@ -116,7 +131,8 @@ AliAnalysisTPCTOFpA::AliAnalysisTPCTOFpA(const char *name)
     fHistMCparticles(0),
     fHistPidQA(0),
     fHistMult(0),
-    fHistCentrality(0)
+    fHistCentrality(0),
+    fHistTOFwindow(0)
     {
   //
   // standard constructur which should be used
@@ -128,12 +144,27 @@ AliAnalysisTPCTOFpA::AliAnalysisTPCTOFpA(const char *name)
   fUseHBTmultiplicity = kTRUE;
   fUseTPConlyTracks = kFALSE;
 
-  fSmallTHnSparse = kFALSE;
+
+  fUseTPConlyTracks =kFALSE;
+  fSaveMotherPDG = kFALSE;
+  fSmallTHnSparse = kTRUE;
   fTPCnSigmaCutLow = -3.;
   fTPCnSigmaCutHigh = 3.;
-  fRapidityCutLow = -0.2;
-  fRapidityCutHigh = 0.2;
+  fRapidityCutLow = 0.;
+  fRapidityCutHigh = 0.5;
+  fEvenDCAbinning = kFALSE;
+  fIspA = kTRUE;
+  fRapCMS = kTRUE;
+  fCentEst = "V0A";
   fEvenDCAbinning = kFALSE;
+  fTOFmisMatch = 2;
+  fTRDinReject = kFALSE;
+  fTOFwindow = 10.;
+  fDCAzCut = 2.;
+  fCrossedRows = 70;
+  fRatioRowsClusters = 0.8;
+
+
 
   /* real */
   fAlephParameters[0] = 0.0283086;
@@ -187,10 +218,10 @@ void AliAnalysisTPCTOFpA::Initialize()
 
 
   if (!fUseTPConlyTracks) {
-         fESDtrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2011(kFALSE);
+    fESDtrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2011(kFALSE,kTRUE);
          fESDtrackCuts->SetMaxDCAToVertexXY(3);
-         fESDtrackCuts->SetMaxDCAToVertexZ(3);
-         fESDtrackCuts->SetEtaRange(-0.9,0.9);
+         //fESDtrackCuts->SetMaxDCAToVertexZ(2);
+         fESDtrackCuts->SetEtaRange(-0.8,0.8);
   }
   else {
          //fESDtrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
@@ -206,6 +237,13 @@ void AliAnalysisTPCTOFpA::Initialize()
 
          fESDtrackCuts->SetEtaRange(-0.9,0.9);
   }
+
+
+  //change DCA z cut here with flags set before:
+  fESDtrackCuts->SetMaxDCAToVertexZ(fDCAzCut);
+  fESDtrackCuts->SetMinNCrossedRowsTPC(fCrossedRows);
+  fESDtrackCuts->SetMinRatioCrossedRowsOverFindableClustersTPC(fRatioRowsClusters);
+
   //
   //
   //
@@ -230,7 +268,7 @@ void AliAnalysisTPCTOFpA::UserCreateOutputObjects()
 
   Int_t kDcaBinsTemp = 76;
   if (fEvenDCAbinning) kDcaBinsTemp = 150;
-  const Int_t kDcaBins = (const Int_t) kDcaBinsTemp;
+  const Int_t kDcaBins = (Int_t) kDcaBinsTemp;
 
   const Float_t kDcaBinsTPConlyFactor = 5; //need to change binning of DCA plot for tpconly
   // sort pT-bins ..
@@ -261,15 +299,15 @@ void AliAnalysisTPCTOFpA::UserCreateOutputObjects()
   
   //dimensions of standard THnSparse
   //                              0,           1,           2,  3,       4,    5,     6,   7,     8
-  Int_t    binsHistReal[9] = {   3,   kMultBins,     kPtBins,  2,       10,    50,    2,  80,    kDcaBins};
-  Double_t xminHistReal[9] = {-0.5,        -0.5,           0, -2,      -0.5,   -5, -0.5,  -8,       -3};
-  Double_t xmaxHistReal[9] = { 2.5,        10.5,           3,  2,       0.5,    5,  1.5,   8,        3};
+  Int_t    binsHistReal[9] = {   3,   kMultBins,     kPtBins,  2,       20,    50,    2,  16,    kDcaBins};
+  Double_t xminHistReal[9] = {-0.5,        -1.5,           0, -2,      -1.0,   -5, -0.5,  -8,       -3};
+  Double_t xmaxHistReal[9] = { 2.5,         9.5,           3,  2,       1.0,    5,  1.5,   8,        3};
 
   //dimensions of small THnSparse
   //                              0,           1,           2,  3,                        4,   5,       6
   Int_t    binsHistRealSm[7] = {   3,   kMultBins,     kPtBins,  2,  /*    10,   50,*/    2,  80, kDcaBins};
-  Double_t xminHistRealSm[7] = {-0.5,        -0.5,           0, -2,  /*  -0.5,   -5,*/ -0.5,  -8,       -3};
-  Double_t xmaxHistRealSm[7] = { 2.5,        10.5,           3,  2,  /*   0.5,    5,*/  1.5,   8,        3};
+  Double_t xminHistRealSm[7] = {-0.5,        -1.5,           0, -2,  /*  -0.5,   -5,*/ -0.5,  -8,       -3};
+  Double_t xmaxHistRealSm[7] = { 2.5,         9.5,           3,  2,  /*   0.5,    5,*/  1.5,   8,        3};
 
   if (!fSmallTHnSparse) fHistRealTracks = new THnSparseF("fHistRealTracks","real tracks",9,binsHistReal,xminHistReal,xmaxHistReal);
   else                  fHistRealTracks = new THnSparseF("fHistRealTracks","real tracks",7,binsHistRealSm,xminHistRealSm,xmaxHistRealSm);
@@ -298,15 +336,15 @@ void AliAnalysisTPCTOFpA::UserCreateOutputObjects()
   
   // dimensions of standard THnSparse
   //                            0,            1,           2,  3,      4,   5,    6,   7,       8.,    9.
-  Int_t    binsHistMC[10] = {   3,    kMultBins,     kPtBins,  2,     10,  50,    2,  80, kDcaBins,    6};
-  Double_t xminHistMC[10] = {-0.5,         -0.5,           0, -2,   -0.5,  -5, -0.5,  -8,       -3, -0.5};
-  Double_t xmaxHistMC[10] = { 2.5,         10.5,           3,  2,    0.5,   5,  1.5,   8,        3,  5.5};
+  Int_t    binsHistMC[10] = {   3,    kMultBins,     kPtBins,  2,     20,  50,    2,  16, kDcaBins,    6};
+  Double_t xminHistMC[10] = {-0.5,         -1.5,           0, -2,   -1.0,  -5, -0.5,  -8,       -3, -0.5};
+  Double_t xmaxHistMC[10] = { 2.5,          9.5,           3,  2,    1.0,   5,  1.5,   8,        3,  5.5};
 
   //dimensions of small THnSparse
   //                              0,           1,           2,  3,                     4,   5,       6.,    7.
   Int_t    binsHistMCSm[8] = {   3,    kMultBins,     kPtBins,  2,  /*   10,  50,*/    2,  80, kDcaBins,    6};
-  Double_t xminHistMCSm[8] = {-0.5,         -0.5,           0, -2,  /* -0.5,  -5,*/ -0.5,  -8,       -3, -0.5};
-  Double_t xmaxHistMCSm[8] = { 2.5,         10.5,           3,  2,  /*  0.5,   5,*/  1.5,   8,        3,  5.5};
+  Double_t xminHistMCSm[8] = {-0.5,         -1.5,           0, -2,  /* -0.5,  -5,*/ -0.5,  -8,       -3, -0.5};
+  Double_t xmaxHistMCSm[8] = { 2.5,          9.5,           3,  2,  /*  0.5,   5,*/  1.5,   8,        3,  5.5};
 
   //different binning for CODE axis, if we want to save motherPDG
   if (fSaveMotherPDG) {
@@ -346,9 +384,15 @@ void AliAnalysisTPCTOFpA::UserCreateOutputObjects()
   //
   fHistMult = new TH2D("fHistMult", "control histogram to count number of events", 502, -2.5, 499.5,4,-0.5,3.5);
   fHistCentrality = new TH1D("fHistCentrality", "control histogram to count number of events", 22, -1.5, 20.5);
+  fHistTOFwindow = new TH2D("fHistTOFwindow", "control hisogram for TOF window",160,-10.,10.,160,-10.,10.);
+  fHistTOFwindow->GetXaxis()->SetTitle("dx");
+  fHistTOFwindow->GetYaxis()->SetTitle("dz");
   fListHist->Add(fHistMult);
   fListHist->Add(fHistCentrality);
-  
+  fListHist->Add(fHistTOFwindow);
+
+  PostData(1, fListHist);
+
 }
 
 //________________________________________________________________________
@@ -405,12 +449,22 @@ void AliAnalysisTPCTOFpA::UserExec(Option_t *)
   //
   // monitor vertex position
   //
+  Bool_t isVertexOk = kTRUE;
   const AliESDVertex *vertex = fESD->GetPrimaryVertexTracks();
   if(vertex->GetNContributors()<1) {
     // SPD vertex
     vertex = fESD->GetPrimaryVertexSPD();
-    if(vertex->GetNContributors()<1) vertex = 0x0;
+    /* quality checks on SPD-vertex */ 
+    if (!vertex) {
+      isVertexOk = kFALSE;
+    }
+    else {
+      TString vertexType = vertex->GetTitle();
+      if (vertexType.Contains("vertexer: Z") && (vertex->GetDispersion() > 0.04 || vertex->GetZRes() > 0.25))  isVertexOk = kFALSE; //vertex = 0x0; //
+      if (vertex->GetNContributors()<1)  isVertexOk = kFALSE; //vertex = 0x0; //
+    }
   }  
+
   //
   // small track loop to determine trigger Pt, multiplicity or centrality
   //
@@ -430,7 +484,7 @@ void AliAnalysisTPCTOFpA::UserExec(Option_t *)
   for(Int_t ilay=0; ilay<6; ilay++) nClusters[ilay] = (Float_t)mult->GetNumberOfITSClusters(ilay);
   if (vertex) spdCorr = AliESDUtils::GetCorrSPD2(nClusters[1],vertex->GetZ());
   //
-  Float_t centrality = -1;
+  Float_t centrality = -99;
   //
   // IMPORTANT CENTRALITY DEFINITION FOR pp
   //
@@ -476,9 +530,9 @@ void AliAnalysisTPCTOFpA::UserExec(Option_t *)
     */
   }
   //
-  Int_t rootS = fESD->GetBeamEnergy() < 1000 ? 0 : 1;
+  //Int_t rootS = fESD->GetBeamEnergy() < 1000 ? 0 : 1;
   if (fESD->GetEventSpecie() == 4) { // PbPb
-    rootS = 2;
+    //rootS = 2;
     AliCentrality *esdCentrality = fESD->GetCentrality();
     centrality = esdCentrality->GetCentralityClass10("V0M") + 1; // centrality percentile determined with V0
     if (TMath::Abs(centrality - 1) < 1e-5) {
@@ -488,44 +542,55 @@ void AliAnalysisTPCTOFpA::UserExec(Option_t *)
 
   if (fIspA) {
     AliCentrality *esdCentrality = fESD->GetCentrality();
-    Float_t pApercentile = esdCentrality->GetCentralityPercentile("V0M"); // centrality percentile determined with V0A
-    if (pApercentile >=  0. && pApercentile < 20.) centrality = 0; 
-    if (pApercentile >= 20. && pApercentile < 40.) centrality = 1;
-    if (pApercentile >= 40. && pApercentile < 60.) centrality = 2;
-    if (pApercentile >= 60. && pApercentile <= 100.) centrality = 3;
-    //if (pApercentile >= 80. && pApercentile <= 100.) centrality = 4;
-    //cout << "*****************ispA switch works***************************" << endl;
-    //cout << "centrality percentile is:  " << pApercentile << endl;
-    //cout << "*************************************************************" << endl;
+    Float_t pApercentile = esdCentrality->GetCentralityPercentile(fCentEst.Data()); // centrality percentile determined with V0M
+    if (pApercentile >=  0. && pApercentile <  5.) centrality = -1; 
+    else if (pApercentile >=  5. && pApercentile < 10.) centrality = 0; 
+    else if (pApercentile >= 10. && pApercentile < 20.) centrality = 1;
+    else if (pApercentile >= 20. && pApercentile < 30.) centrality = 2;
+    else if (pApercentile >= 30. && pApercentile < 40.) centrality = 3;
+    else if (pApercentile >= 40. && pApercentile < 50.) centrality = 4;
+    else if (pApercentile >= 50. && pApercentile < 60.) centrality = 5; 
+    else if (pApercentile >= 60. && pApercentile < 70.) centrality = 6;
+    else if (pApercentile >= 70. && pApercentile < 80.) centrality = 7;
+    else if (pApercentile >= 80. && pApercentile < 90.) centrality = 8;
+    else if (pApercentile >= 90. && pApercentile <= 100.) centrality = 9;
+    else centrality = -99;
+
+    /*
+    cout << "*****************ispA switch works***************************" << endl;
+    cout << "centrality estimator  is:  " << fCentEst.Data() << endl; 
+    cout << "centrality percentile is:  " << pApercentile << endl;
+    cout << "*************************************************************" << endl;
+    */
   }
 
 
 
   
-  Int_t nContributors = 0;
-  if (fESD->GetPrimaryVertexTPC()) nContributors = fESD->GetPrimaryVertexTPC()->GetNContributors();
+  //Int_t nContributors = 0;
+  //if (fESD->GetPrimaryVertexTPC()) nContributors = fESD->GetPrimaryVertexTPC()->GetNContributors();
   //
   
-  Int_t processtype = 0;
+  //  Int_t processtype = 0;
   Int_t processCode = 0;
   //
   // important change: fill generated only after vertex cut in case of heavy-ions
   //
 
-  /*
-  if (!vertex && fESD->GetEventSpecie() == 4) {
+  
+  if (!vertex || !isVertexOk) {
     fHistMult->Fill(-1, processCode);
     PostData(1, fListHist);
     return;
   } else {
-    if (TMath::Abs(vertex->GetZv()) > 10 && fESD->GetEventSpecie() == 4) {
+    if (TMath::Abs(vertex->GetZ()) > 10) {
       fHistMult->Fill(-1, processCode);
       PostData(1, fListHist);
       return;
     }
   }
   //
-  */
+  
   
 
   if (fMCtrue) {
@@ -550,11 +615,11 @@ void AliAnalysisTPCTOFpA::UserExec(Option_t *)
       //
       Double_t xv = trackMC->Vx();
       Double_t yv = trackMC->Vy();
-      Double_t zv = trackMC->Vz();
+      //Double_t zv = trackMC->Vz();
       Double_t dxy = 0;
       dxy = TMath::Sqrt(xv*xv + yv*yv); // so stupid to avoid warnings
-      Double_t dz = 0;
-      dz = TMath::Abs(zv); // so stupid to avoid warnings
+      //Double_t dz = 0;
+      //dz = TMath::Abs(zv); // so stupid to avoid warnings
       //
       // vertex cut - selection of primaries
       //
@@ -578,12 +643,12 @@ void AliAnalysisTPCTOFpA::UserExec(Option_t *)
       //
 
       if (!fSmallTHnSparse){
-       Double_t vecHistMC[10] = {iPart, centrality,  pT, sign, rap, 0, 1, 0, dxy, 0};
+       Double_t vecHistMC[10] = {static_cast<Double_t>(iPart), centrality,  pT, static_cast<Double_t>(sign), rap, 0, 1, 0, dxy, 0};
        if (!fOnlyQA) fHistMCparticles->Fill(vecHistMC);
       }
       else{
        if (rap>fRapidityCutLow && rap<fRapidityCutHigh){
-         Double_t vecHistMC[8] = {iPart, centrality,  pT, sign, 1, 0, dxy, 0};
+         Double_t vecHistMC[8] = {static_cast<Double_t>(iPart), centrality,  pT, static_cast<Double_t>(sign), 1, 0, dxy, 0};
          if (!fOnlyQA) fHistMCparticles->Fill(vecHistMC);
        }
       }
@@ -595,12 +660,12 @@ void AliAnalysisTPCTOFpA::UserExec(Option_t *)
     return;
   }
   //
-  if (!vertex) {
+  if (!vertex || !isVertexOk) {
     fHistMult->Fill(-1, processCode);
     PostData(1, fListHist);
     return;
   } else {
-    if (TMath::Abs(vertex->GetZv()) > 10) {
+    if (TMath::Abs(vertex->GetZ()) > 10) {
       fHistMult->Fill(-1, processCode);
       PostData(1, fListHist);
       return;
@@ -662,13 +727,40 @@ void AliAnalysisTPCTOFpA::UserExec(Option_t *)
     Bool_t hasTOFout  = status&AliESDtrack::kTOFout; 
     Bool_t hasTOFtime = status&AliESDtrack::kTIME;
     Bool_t hasTOFpid  = status&AliESDtrack::kTOFpid;
+    //Bool_t hasTOFmismatch  = status&AliESDtrack::kTOFmismatch;
     Bool_t hasTOF     = kFALSE;
     if (hasTOFout && hasTOFtime && hasTOFpid) hasTOF = kTRUE;
-       Float_t length = 0.;
+
+
+    //check if TRD contributed to tracking and throw track away if  fTRDinReject flag is set
+    Bool_t hasTRDin = status&AliESDtrack::kTRDin; 
+    if (hasTRDin && fTRDinReject) {
+      //hasTOF = kFALSE;
+      if (fUseTPConlyTracks) {delete track; track = 0;} //need to delete tpconlytrack
+      continue;
+    }
+
+
+    //check TOF window
+    Float_t dxTOF = track->GetTOFsignalDx();
+    Float_t dzTOF = track->GetTOFsignalDz();
+
+    if (hasTOF) fHistTOFwindow->Fill(dxTOF,dzTOF);
+
+    //******************************************
+    //*******NEEDS PROPER CUT SETTER************
+    //******************************************
+    //cut on TOF window here
+    if (TMath::Abs(dxTOF) > fTOFwindow || TMath::Abs(dzTOF) > fTOFwindow) hasTOF = kFALSE;
+
+    
+
+    Float_t length = 0.;
     if (!fUseTPConlyTracks) length = track->GetIntegratedLength(); 
     else length = trackForTOF->GetIntegratedLength();
 
     if (length < 350.) hasTOF = kFALSE;
+
     //
     // calculate rapidities and kinematics
     // 
@@ -725,7 +817,10 @@ void AliAnalysisTPCTOFpA::UserExec(Option_t *)
                            fESDpid->NumberOfSigmasTPC(track,AliPID::kKaon),
                            fESDpid->NumberOfSigmasTPC(track,AliPID::kProton),
                            0}; // ASK FOR PUTTING THE DEUTERON TO AliPID !!!!!!!!!!!!!!
-    Float_t time0 = fESDpid->GetTOFResponse().GetTimeZero();
+
+
+    Float_t time0 = fESDpid->GetTOFResponse().GetStartTime(track->P());
+    //Float_t time0 = fESDpid->GetTOFResponse().GetTimeZero(); //old way of getting time0
     //fESDpid->GetTOFResponse().SetTimeResolution(130.);
     Double_t pullsTOF[4] ={0.,0.,0.,0.};
     if (!fUseTPConlyTracks) {
@@ -747,6 +842,7 @@ void AliAnalysisTPCTOFpA::UserExec(Option_t *)
 //                      fESDpid->NumberOfSigmasTPC(track,AliPID::kKaon),
 //                      fESDpid->NumberOfSigmasTPC(track,AliPID::kProton)};
 
+/*
     Double_t tofQA[4] = {0.,0.,0.,0.}; 
     if (!fUseTPConlyTracks) {
       tofQA[0] = fESDpid->NumberOfSigmasTOF(track,AliPID::kElectron, time0);
@@ -760,18 +856,18 @@ void AliAnalysisTPCTOFpA::UserExec(Option_t *)
       tofQA[0] = fESDpid->NumberOfSigmasTOF(trackForTOF,AliPID::kKaon, time0);
       tofQA[0] = fESDpid->NumberOfSigmasTOF(trackForTOF,AliPID::kProton, time0);
     }
-
+*/
 
     //save information for every particle type  // loop over assumed particle type
     for(Int_t iPart = 0; iPart < 3; iPart++) {
 
       if (!fSmallTHnSparse) {
-       Double_t vecHistReal[9]  = {iPart,  centrality,   pT, sign,  rap[iPart], pullsTPC[iPart], hasTOF, pullsTOF[iPart], dca[0]};
+       Double_t vecHistReal[9]  = {static_cast<Double_t>(iPart),  centrality,   pT, static_cast<Double_t>(sign),  rap[iPart], pullsTPC[iPart], static_cast<Double_t>(hasTOF), pullsTOF[iPart], dca[0]};
        if (!fOnlyQA) fHistRealTracks->Fill(vecHistReal);
       }
       else {
        if (pullsTPC[iPart]>fTPCnSigmaCutLow && pullsTPC[iPart]<fTPCnSigmaCutHigh && rap[iPart]>fRapidityCutLow && rap[iPart]<fRapidityCutHigh) {
-         Double_t vecHistReal[7]  = {iPart,  centrality,   pT, sign, hasTOF, pullsTOF[iPart], dca[0]};
+         Double_t vecHistReal[7]  = {static_cast<Double_t>(iPart),  centrality,   pT, static_cast<Double_t>(sign), static_cast<Double_t>(hasTOF), pullsTOF[iPart], dca[0]};
          if (!fOnlyQA) fHistRealTracks->Fill(vecHistReal);
        }
       }
@@ -791,8 +887,8 @@ void AliAnalysisTPCTOFpA::UserExec(Option_t *)
        TParticle *trackMC = stack->Particle(TMath::Abs(track->GetLabel()));
        Int_t pdg = TMath::Abs(trackMC->GetPdgCode());
        //
-       if (pdg != assumedPdg && stack->IsPhysicalPrimary(TMath::Abs(track->GetLabel()))) code = 2;
-       if (pdg != assumedPdg && stack->IsSecondaryFromWeakDecay(TMath::Abs(track->GetLabel()))) code = 5;
+       if (pdg != assumedPdg) code = 2;
+       //if (pdg != assumedPdg && stack->IsSecondaryFromWeakDecay(TMath::Abs(track->GetLabel()))) code = 5;
        if (pdg == assumedPdg && stack->IsPhysicalPrimary(TMath::Abs(track->GetLabel()))) code = 1;
        if (pdg == assumedPdg && stack->IsSecondaryFromWeakDecay(TMath::Abs(track->GetLabel()))) {
          code = 3;
@@ -803,8 +899,17 @@ void AliAnalysisTPCTOFpA::UserExec(Option_t *)
            if (trackMother->GetPdgCode() == 3222) motherCode = 8; //Sigma+
          }
        }
-       if (pdg == assumedPdg && stack->IsSecondaryFromMaterial(TMath::Abs(track->GetLabel()))) code = 4;
-       
+
+
+       //FILL MATERIAL TEMPLATE FOR KAONS WITH ELECTRONS
+       if (iPart != 1){
+         if (pdg == assumedPdg && stack->IsSecondaryFromMaterial(TMath::Abs(track->GetLabel()))) code = 4;
+       }       
+       else {
+         if (pdg == 11) code = 4;
+         //cout << "got an electron for  kaons!" << endl;
+       }
+
        //
        // muons need special treatment, because they are indistinguishable from pions
        //
@@ -816,16 +921,36 @@ void AliAnalysisTPCTOFpA::UserExec(Option_t *)
        Int_t tofLabel[3];
        if (!fUseTPConlyTracks) track->GetTOFLabel(tofLabel);
        else trackForTOF->GetTOFLabel(tofLabel);
-       if (TMath::Abs(track->GetLabel()) != TMath::Abs(tofLabel[0]) || tofLabel[1] > 0) hasTOF = kFALSE;
-       //
+
+
+       //three options:
+       //0: do NOT check at all
+       //1: do check
+       //2: in case of decays, check if mother label matches --> if yes, assign hasTOF = kTRUE
+
+       if (fTOFmisMatch == 0) {
+         //if (TMath::Abs(track->GetLabel()) != TMath::Abs(tofLabel[0]) || tofLabel[1] > 0) hasTOF = kFALSE;
+       }
+       if (fTOFmisMatch == 1) {
+         if (TMath::Abs(track->GetLabel()) != TMath::Abs(tofLabel[0]) || tofLabel[1] > 0) hasTOF = kFALSE;
+       }
+       if (fTOFmisMatch == 2) {
+         if (TMath::Abs(track->GetLabel()) != TMath::Abs(tofLabel[0]) || tofLabel[1] > 0) hasTOF = kFALSE;
+         TParticle *matchedTrack = stack->Particle(TMath::Abs(tofLabel[0]));
+         if (TMath::Abs(matchedTrack->GetFirstMother()) == TMath::Abs(track->GetLabel())) hasTOF = kTRUE;
+       }
+
+         
+
+         //
        // IMPORTANT BIG PROBLEM HERE THE PROBABLILITY TO HAVE A PID SIGNAL MUST BE IN !!!!!!!!!!!!
        //
        if (!fSmallTHnSparse){
-         Double_t vectorHistMC[10] = {iPart,  centrality,  pT, sign,  rap[iPart], pullsTPC[iPart], hasTOF, pullsTOF[iPart], dca[0], code};
+         Double_t vectorHistMC[10] = {static_cast<Double_t>(iPart),  centrality,  pT, static_cast<Double_t>(sign),  rap[iPart], pullsTPC[iPart], static_cast<Double_t>(hasTOF), pullsTOF[iPart], dca[0], static_cast<Double_t>(code)};
          if (!fOnlyQA) { 
            fHistMCparticles->Fill(vectorHistMC);
            if (motherCode != -1 && fSaveMotherPDG) { //if mother of weak decay is K0, lambda or sigma+ add track again with this information
-             Double_t vectorHistMCmother[10] = {iPart,  centrality,  pT, sign,  rap[iPart], pullsTPC[iPart], hasTOF, pullsTOF[iPart], dca[0], motherCode};
+             Double_t vectorHistMCmother[10] = {static_cast<Double_t>(iPart),  centrality,  pT, static_cast<Double_t>(sign),  rap[iPart], pullsTPC[iPart], static_cast<Double_t>(hasTOF), pullsTOF[iPart], dca[0], static_cast<Double_t>(motherCode)};
              fHistMCparticles->Fill(vectorHistMCmother);
            }
          }
@@ -833,11 +958,11 @@ void AliAnalysisTPCTOFpA::UserExec(Option_t *)
        else{
          if (pullsTPC[iPart]>fTPCnSigmaCutLow && pullsTPC[iPart]<fTPCnSigmaCutHigh && rap[iPart]>fRapidityCutLow && rap[iPart]<fRapidityCutHigh) {
            //                              0,           1,   2,    3,           4,               5,      6,               7,      8,   9
-           Double_t vectorHistMC[8] = {iPart,  centrality,  pT, sign, hasTOF, pullsTOF[iPart], dca[0], code};
+           Double_t vectorHistMC[8] = {static_cast<Double_t>(iPart),  centrality,  pT, static_cast<Double_t>(sign), static_cast<Double_t>(hasTOF), pullsTOF[iPart], dca[0], static_cast<Double_t>(code)};
            if (!fOnlyQA) { 
              fHistMCparticles->Fill(vectorHistMC);
              if (motherCode != -1 && fSaveMotherPDG) { //if mother of weak decay is K0, lambda or sigma+ add track again with this information
-               Double_t vectorHistMCmother[8] = {iPart,  centrality,  pT, sign, hasTOF, pullsTOF[iPart], dca[0], motherCode};
+               Double_t vectorHistMCmother[8] = {static_cast<Double_t>(iPart),  centrality,  pT, static_cast<Double_t>(sign), static_cast<Double_t>(hasTOF), pullsTOF[iPart], dca[0], static_cast<Double_t>(motherCode)};
                fHistMCparticles->Fill(vectorHistMCmother);
              }
            }
@@ -898,7 +1023,7 @@ void AliAnalysisTPCTOFpA::BinLogAxis(const TH1 *h) {
   //
   // Method for the correct logarithmic binning of histograms
   //
-  TAxis *axis = h->GetXaxis();
+  TAxis *axis = const_cast<TAxis*>(h->GetXaxis());
   int bins = axis->GetNbins();
 
   Double_t from = axis->GetXmin();