]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGLF/SPECTRA/PiKaPr/TPCTOF/AliAnalysisCombinedHadronSpectra.cxx
Fixes for wrong use of const causing PW.CAST_TO_QUALIFIED_TYPE defect in Coverity
[u/mrichter/AliRoot.git] / PWGLF / SPECTRA / PiKaPr / TPCTOF / AliAnalysisCombinedHadronSpectra.cxx
index 2e1872b647b11d40467045434d62517d353b26f5..490619ab9ba9bda6fa2ecd9f034c818203cc5b8f 100644 (file)
@@ -69,7 +69,14 @@ AliAnalysisCombinedHadronSpectra::AliAnalysisCombinedHadronSpectra()
     fMCtrue(0),
     fOnlyQA(0),
     fUseHBTmultiplicity(0),
-       fUseTPConlyTracks(0),
+    fUseTPConlyTracks(0),
+    fSaveMotherPDG(0),
+  fSmallTHnSparse(0),
+  fTPCnSigmaCutLow(0),
+  fTPCnSigmaCutHigh(0),
+  fRapidityCutLow(0),
+  fRapidityCutHigh(0),
+  fEvenDCAbinning(0),
     fAlephParameters(),
     fHistRealTracks(0),
     fHistMCparticles(0),
@@ -92,14 +99,21 @@ AliAnalysisCombinedHadronSpectra::AliAnalysisCombinedHadronSpectra(const char *n
     fMCtrue(0),
     fOnlyQA(0),
     fUseHBTmultiplicity(0),
-       fUseTPConlyTracks(0),
+    fUseTPConlyTracks(0),
+    fSaveMotherPDG(0),
+  fSmallTHnSparse(0),
+  fTPCnSigmaCutLow(0),
+  fTPCnSigmaCutHigh(0),
+  fRapidityCutLow(0),
+  fRapidityCutHigh(0),
+  fEvenDCAbinning(0),
     fAlephParameters(),
     fHistRealTracks(0),
     fHistMCparticles(0),
     fHistPidQA(0),
     fHistMult(0),
     fHistCentrality(0)
-{
+    {
   //
   // standard constructur which should be used
   //
@@ -109,6 +123,14 @@ AliAnalysisCombinedHadronSpectra::AliAnalysisCombinedHadronSpectra(const char *n
   fOnlyQA = kFALSE;
   fUseHBTmultiplicity = kTRUE;
   fUseTPConlyTracks = kFALSE;
+
+  fSmallTHnSparse = kFALSE;
+  fTPCnSigmaCutLow = -3.;
+  fTPCnSigmaCutHigh = 3.;
+  fRapidityCutLow = -0.2;
+  fRapidityCutHigh = 0.2;
+  fEvenDCAbinning = kFALSE;
+
   /* real */
   fAlephParameters[0] = 0.0283086;
   fAlephParameters[1] = 2.63394e+01;
@@ -173,7 +195,7 @@ void AliAnalysisCombinedHadronSpectra::Initialize()
          fESDtrackCuts->SetAcceptKinkDaughters(kFALSE);
          fESDtrackCuts->SetRequireTPCRefit(kFALSE);
 
-         fESDtrackCuts->SetMaxDCAToVertexXY(30);
+         fESDtrackCuts->SetMaxDCAToVertexXY(15);
          fESDtrackCuts->SetMaxDCAToVertexZ(6);
          fESDtrackCuts->SetDCAToVertex2D(kFALSE);
          fESDtrackCuts->SetRequireSigmaToVertex(kFALSE);
@@ -201,16 +223,20 @@ void AliAnalysisCombinedHadronSpectra::UserCreateOutputObjects()
   //
   const Int_t kPtBins = 35;
   const Int_t kMultBins = 11;
-  const Int_t kDcaBins = 76;
-  const Float_t kDcaBinsTPConlyFactor = 10; //need to change binning of DCA plot for tpconly
+
+  Int_t kDcaBinsTemp = 76;
+  if (fEvenDCAbinning) kDcaBinsTemp = 150;
+  const Int_t kDcaBins = (const Int_t) kDcaBinsTemp;
+
+  const Float_t kDcaBinsTPConlyFactor = 5; //need to change binning of DCA plot for tpconly
   // sort pT-bins ..
-  Double_t binsPt[kPtBins+1] = {0., 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.2, 2.4, 2.6, 2.8, 3.0};
+  Double_t binsPt[77] = {0., 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.2, 2.4, 2.6, 2.8, 3.0};
 
-  Double_t binsDca[kDcaBins+1] =  {-3,-2.85,-2.7,-2.55,-2.4,-2.25,-2.1,-1.95,-1.8,-1.65,-1.5,-1.35,-1.2,-1.05,-0.9,-0.75,-0.6,-0.45,-0.3,-0.285,-0.27,-0.255,-0.24,-0.225,-0.21,-0.195,-0.18,-0.165,-0.15,-0.135,-0.12,-0.105,-0.09,-0.075,-0.06,-0.045,-0.03,-0.015,0,0.015,0.03,0.045,0.06,0.075,0.09,0.105,0.12,0.135,0.15,0.165,0.18,0.195,0.21,0.225,0.24,0.255,0.27,0.285,0.3,0.45,0.6,0.75,0.9,1.05,1.2,1.35,1.5,1.65,1.8,1.95,2.1,2.25,2.4,2.55,2.7,2.85,3};
+  Double_t binsDca[77] =  {-3,-2.85,-2.7,-2.55,-2.4,-2.25,-2.1,-1.95,-1.8,-1.65,-1.5,-1.35,-1.2,-1.05,-0.9,-0.75,-0.6,-0.45,-0.3,-0.285,-0.27,-0.255,-0.24,-0.225,-0.21,-0.195,-0.18,-0.165,-0.15,-0.135,-0.12,-0.105,-0.09,-0.075,-0.06,-0.045,-0.03,-0.015,0,0.015,0.03,0.045,0.06,0.075,0.09,0.105,0.12,0.135,0.15,0.165,0.18,0.195,0.21,0.225,0.24,0.255,0.27,0.285,0.3,0.45,0.6,0.75,0.9,1.05,1.2,1.35,1.5,1.65,1.8,1.95,2.1,2.25,2.4,2.55,2.7,2.85,3};
 
   // DCA bins borders get multiplied by constant factor for TPConlyTracks
-  Double_t binsDcaTPConly[kDcaBins+1];
-  for (Int_t i = 0; i< kDcaBins+1; i++) {
+  Double_t binsDcaTPConly[77];
+  for (Int_t i = 0; i< 77; i++) {
        binsDcaTPConly[i] = kDcaBinsTPConlyFactor * binsDca[i];
   }
 
@@ -226,36 +252,91 @@ void AliAnalysisCombinedHadronSpectra::UserCreateOutputObjects()
   // (6.) has valid TOF pid signal
   // (7.) nsigma TOF --> filled 4x
   // (8..) dca_xy
-  // (9.) CODE -- only MC 0-generated, 1-true rec. primaries, 2-misident, 3-second weak, 4-second material
-  //
-  //                              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};
-  fHistRealTracks = new THnSparseF("fHistRealTracks","real tracks",9,binsHistReal,xminHistReal,xmaxHistReal);
+  // (9.) CODE -- only MC 0-generated, 1-true rec. primaries, 2-misident prim, 3-second weak, 4-second material, 5-misident sec, 6-sec. K0, 7-sec. lambda, 8-sec sigma+
   //
+  
+  //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};
 
+  //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};
+
+  if (!fSmallTHnSparse) fHistRealTracks = new THnSparseF("fHistRealTracks","real tracks",9,binsHistReal,xminHistReal,xmaxHistReal);
+  else                  fHistRealTracks = new THnSparseF("fHistRealTracks","real tracks",7,binsHistRealSm,xminHistRealSm,xmaxHistRealSm);
+  //
   fHistRealTracks->GetAxis(2)->Set(kPtBins, binsPt);
 
-  if (!fUseTPConlyTracks) fHistRealTracks->GetAxis(8)->Set(kDcaBins, binsDca);
-  else  fHistRealTracks->GetAxis(8)->Set(kDcaBins, binsDcaTPConly);
+  //different DCAxy binning for TPConlyTracks
+
+  Int_t dcaAxisNumber = 8;
+  if (fSmallTHnSparse) dcaAxisNumber = 6;
 
+  if (!fUseTPConlyTracks){
+    if (fEvenDCAbinning) fHistRealTracks->GetAxis(dcaAxisNumber)->Set(kDcaBins,-3.,3.);
+    else fHistRealTracks->GetAxis(dcaAxisNumber)->Set(kDcaBins, binsDca);
+  }
+  else {
+    if (fEvenDCAbinning) fHistRealTracks->GetAxis(dcaAxisNumber)->Set(kDcaBins,-15.,15.);
+    else fHistRealTracks->GetAxis(dcaAxisNumber)->Set(kDcaBins, binsDcaTPConly);
+   }
   fListHist->Add(fHistRealTracks);
   //
   //                      0.ptot,1.tpcSig,2.hasTOF, 3. assumed part., 4. nclDedx, 5. nSigmaTPC (4x), 6. nSigmaTOF (4x), 7. centrality
   fHistPidQA = new TH3D("fHistPidQA","PID QA",500,0.1,10,1000,0,1000,2,-2,2);
   BinLogAxis(fHistPidQA);
   fListHist->Add(fHistPidQA);
-  //                            0,            1,           2,  3,      4,   5,    6,   7,        8,    9
-  Int_t    binsHistMC[10] = {   3,    kMultBins,     kPtBins,  2,     10,  50,    2,  80, kDcaBins,    5};
-  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,  4.5};
-  fHistMCparticles = new THnSparseF("fHistMCparticles","MC histogram",10,binsHistMC,xminHistMC,xmaxHistMC);
+  
+  // 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};
+
+  //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};
+
+  //different binning for CODE axis, if we want to save motherPDG
+  if (fSaveMotherPDG) {
+    binsHistMC[9] = 9;
+    xmaxHistMC[9] = 8.5;
+    binsHistMCSm[7] = 9;
+    xmaxHistMCSm[7] = 8.5;
+  }
+
+
+  if (!fSmallTHnSparse) fHistMCparticles = new THnSparseF("fHistMCparticles","MC histogram",10,binsHistMC,xminHistMC,xmaxHistMC);
+  else                  fHistMCparticles = new THnSparseF("fHistMCparticles","MC histogram",8,binsHistMCSm,xminHistMCSm,xmaxHistMCSm);
+
+
   fHistMCparticles->GetAxis(2)->Set(kPtBins, binsPt);
 
+  /*
   //different DCAxy binning for TPConlyTracks
-  if (!fUseTPConlyTracks) fHistMCparticles->GetAxis(8)->Set(kDcaBins, binsDca);
-  else fHistMCparticles->GetAxis(8)->Set(kDcaBins, binsDcaTPConly);
+  if (!fEvenDCAbinning){
+    if (!fUseTPConlyTracks) fHistMCparticles->GetAxis(dcaAxisNumber)->Set(kDcaBins, binsDca);
+    else fHistMCparticles->GetAxis(dcaAxisNumber)->Set(kDcaBins, binsDcaTPConly);
+  }
+  */
+
+  if (!fUseTPConlyTracks){
+    if (fEvenDCAbinning) fHistMCparticles->GetAxis(dcaAxisNumber)->Set(kDcaBins,-3.,3.);
+    else fHistMCparticles->GetAxis(dcaAxisNumber)->Set(kDcaBins, binsDca);
+  }
+  else {
+    if (fEvenDCAbinning) fHistMCparticles->GetAxis(dcaAxisNumber)->Set(kDcaBins,-15.,15.);
+    else fHistMCparticles->GetAxis(dcaAxisNumber)->Set(kDcaBins, binsDcaTPConly);
+   }
+
+
 
   fListHist->Add(fHistMCparticles);
   //
@@ -456,8 +537,7 @@ void AliAnalysisCombinedHadronSpectra::UserExec(Option_t *)
       Double_t rap = trackMC->Y();
       Double_t pT  = trackMC->Pt();
       Int_t sign = pdg < 0 ? -1 : 1; // only works for charged pi,K,p !!
-      Double_t transMass = TMath::Sqrt(trackMC->Pt()*trackMC->Pt() + trackMC->GetMass()*trackMC->GetMass()) 
-       - trackMC->GetMass();
+//      Double_t transMass = TMath::Sqrt(trackMC->Pt()*trackMC->Pt() + trackMC->GetMass()*trackMC->GetMass()) - trackMC->GetMass();
       //
       Int_t iPart = -1;
       if (TMath::Abs(pdg) == 211)  iPart = 0; // select Pi+/Pi- only
@@ -465,8 +545,17 @@ void AliAnalysisCombinedHadronSpectra::UserExec(Option_t *)
       if (TMath::Abs(pdg) == 2212) iPart = 2; // select p+/p- only
       if (iPart == -1) continue;
       //
-      Double_t vecHistMC[10] = {iPart, centrality,  pT, sign, rap, 0, 1, 0, dxy, 0};
-      if (!fOnlyQA) fHistMCparticles->Fill(vecHistMC);
+
+      if (!fSmallTHnSparse){
+       Double_t vecHistMC[10] = {iPart, centrality,  pT, 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};
+         if (!fOnlyQA) fHistMCparticles->Fill(vecHistMC);
+       }
+      }
     }
   }
   //
@@ -492,9 +581,11 @@ void AliAnalysisCombinedHadronSpectra::UserExec(Option_t *)
   //cout << "MULTIPLICITY " << trackCounter << " " << fESD->GetEventNumberInFile() <<endl;
   fHistMult->Fill(trackCounter, processCode);
   fHistCentrality->Fill(centrality);
-  //
+
+
+  //***************************************************
   // track loop
-  //
+  //***************************************************
   //const Float_t kNsigmaCut = 3;
   //const Float_t k2sigmaCorr = 1/(0.5*(TMath::Erf(kNsigmaCut/sqrt(2))-TMath::Erf(-kNsigmaCut/sqrt(2))))/*1/0.9545*/;
   //
@@ -503,6 +594,7 @@ void AliAnalysisCombinedHadronSpectra::UserExec(Option_t *)
   for (Int_t i=0;i<fESD->GetNumberOfTracks();++i) {
        
        AliESDtrack *track = 0;
+       AliESDtrack *trackForTOF = 0; //normal track for all TOF information needed when using tpconly-tracks
        
        //normal tracks, if tpconly flag is set, use tpconlytracks
        if (!fUseTPConlyTracks){
@@ -511,6 +603,7 @@ void AliAnalysisCombinedHadronSpectra::UserExec(Option_t *)
        else {
                track = fESDtrackCuts->GetTPCOnlyTrack(fESD,i);
                if (!track) continue;
+               trackForTOF = fESD->GetTrack(i);
        }
     //
     if (!track->GetInnerParam()) {
@@ -532,13 +625,18 @@ void AliAnalysisCombinedHadronSpectra::UserExec(Option_t *)
                continue;
        }
 
-    UInt_t status = track->GetStatus();
+       UInt_t status = 0;
+    if (!fUseTPConlyTracks) status = track->GetStatus();
+       else status = trackForTOF->GetStatus();
     Bool_t hasTOFout  = status&AliESDtrack::kTOFout; 
     Bool_t hasTOFtime = status&AliESDtrack::kTIME;
     Bool_t hasTOFpid  = status&AliESDtrack::kTOFpid;
     Bool_t hasTOF     = kFALSE;
     if (hasTOFout && hasTOFtime && hasTOFpid) hasTOF = kTRUE;
-    Float_t length = track->GetIntegratedLength();
+       Float_t length = 0.;
+    if (!fUseTPConlyTracks) length = track->GetIntegratedLength(); 
+    else length = trackForTOF->GetIntegratedLength();
+
     if (length < 350.) hasTOF = kFALSE;
     //
     // calculate rapidities and kinematics
@@ -556,14 +654,10 @@ void AliAnalysisCombinedHadronSpectra::UserExec(Option_t *)
     Double_t rapProton = 0.5*TMath::Log((energyProton + pvec[2])/(energyProton - pvec[2]));
     Double_t rapDeuteron = 0.5*TMath::Log((energyDeuteron + pvec[2])/(energyDeuteron - pvec[2]));
     //
-    Double_t transMassPion = TMath::Sqrt(track->Pt()*track->Pt() + AliPID::ParticleMass(AliPID::kPion)*AliPID::ParticleMass(AliPID::kPion)) 
-      -  AliPID::ParticleMass(AliPID::kPion);
-    Double_t transMassKaon = TMath::Sqrt(track->Pt()*track->Pt() + AliPID::ParticleMass(AliPID::kKaon)*AliPID::ParticleMass(AliPID::kKaon)) 
-      -  AliPID::ParticleMass(AliPID::kKaon);
-    Double_t transMassProton = TMath::Sqrt(track->Pt()*track->Pt() + AliPID::ParticleMass(AliPID::kProton)*AliPID::ParticleMass(AliPID::kProton)) 
-      -  AliPID::ParticleMass(AliPID::kProton);
-    Double_t transMassDeuteron = TMath::Sqrt(track->Pt()*track->Pt() + 4*AliPID::ParticleMass(AliPID::kProton)*AliPID::ParticleMass(AliPID::kProton))
-      -  2*AliPID::ParticleMass(AliPID::kProton);
+//    Double_t transMassPion = TMath::Sqrt(track->Pt()*track->Pt() + AliPID::ParticleMass(AliPID::kPion)*AliPID::ParticleMass(AliPID::kPion))      -  AliPID::ParticleMass(AliPID::kPion);
+//    Double_t transMassKaon = TMath::Sqrt(track->Pt()*track->Pt() + AliPID::ParticleMass(AliPID::kKaon)*AliPID::ParticleMass(AliPID::kKaon))     -  AliPID::ParticleMass(AliPID::kKaon);
+ //   Double_t transMassProton = TMath::Sqrt(track->Pt()*track->Pt() + AliPID::ParticleMass(AliPID::kProton)*AliPID::ParticleMass(AliPID::kProton))    -  AliPID::ParticleMass(AliPID::kProton);
+//    Double_t transMassDeuteron = TMath::Sqrt(track->Pt()*track->Pt() + 4*AliPID::ParticleMass(AliPID::kProton)*AliPID::ParticleMass(AliPID::kProton))    -  2*AliPID::ParticleMass(AliPID::kProton);
     //
     // 3. make the PID
     //
@@ -585,7 +679,7 @@ void AliAnalysisCombinedHadronSpectra::UserExec(Option_t *)
     // (8..) dca_xy
     // (9.) CODE -- only MC 0-generated, 1-true rec. primaries, 2-misident, 3-second weak, 4-second material
     //
-    Double_t transMass[4] = {transMassPion,transMassKaon,transMassProton,transMassDeuteron};
+//    Double_t transMass[4] = {transMassPion,transMassKaon,transMassProton,transMassDeuteron};
     Double_t rap[4] = {rapPion,rapKaon,rapProton,rapDeuteron};
     Double_t pullsTPC[4] = {fESDpid->NumberOfSigmasTPC(track,AliPID::kPion),
                            fESDpid->NumberOfSigmasTPC(track,AliPID::kKaon),
@@ -593,30 +687,62 @@ void AliAnalysisCombinedHadronSpectra::UserExec(Option_t *)
                            0}; // ASK FOR PUTTING THE DEUTERON TO AliPID !!!!!!!!!!!!!!
     Float_t time0 = fESDpid->GetTOFResponse().GetTimeZero();
     //fESDpid->GetTOFResponse().SetTimeResolution(130.);
-    Double_t pullsTOF[4] =  {fESDpid->NumberOfSigmasTOF(track,AliPID::kPion, time0),
-                            fESDpid->NumberOfSigmasTOF(track,AliPID::kKaon, time0),
-                            fESDpid->NumberOfSigmasTOF(track,AliPID::kProton, time0),
-                            0}; // ASK FOR PUTTING THE DEUTERON TO AliPID !!!!!!!!!!!!!!;
-    //
-    Double_t tpcQA[4] = {fESDpid->NumberOfSigmasTPC(track,AliPID::kElectron),
-                        fESDpid->NumberOfSigmasTPC(track,AliPID::kPion),
-                        fESDpid->NumberOfSigmasTPC(track,AliPID::kKaon),
-                        fESDpid->NumberOfSigmasTPC(track,AliPID::kProton)};
-    Double_t tofQA[4] = {fESDpid->NumberOfSigmasTOF(track,AliPID::kElectron, time0),
-                        fESDpid->NumberOfSigmasTOF(track,AliPID::kPion, time0),
-                        fESDpid->NumberOfSigmasTOF(track,AliPID::kKaon, time0),
-                        fESDpid->NumberOfSigmasTOF(track,AliPID::kProton, time0)};
+    Double_t pullsTOF[4] ={0.,0.,0.,0.};
+    if (!fUseTPConlyTracks) {
+      pullsTOF[0] = fESDpid->NumberOfSigmasTOF(track,AliPID::kPion, time0);
+      pullsTOF[1] = fESDpid->NumberOfSigmasTOF(track,AliPID::kKaon, time0);
+      pullsTOF[2] = fESDpid->NumberOfSigmasTOF(track,AliPID::kProton, time0);
+      pullsTOF[3] = 0; // ASK FOR PUTTING THE DEUTERON TO AliPID !!!!!!!!!!!!!!;
+    }
+    else {
+      pullsTOF[0] = fESDpid->NumberOfSigmasTOF(trackForTOF,AliPID::kPion, time0);
+      pullsTOF[1] = fESDpid->NumberOfSigmasTOF(trackForTOF,AliPID::kKaon, time0);
+      pullsTOF[2] = fESDpid->NumberOfSigmasTOF(trackForTOF,AliPID::kProton, time0);
+      pullsTOF[3] = 0; // ASK FOR PUTTING THE DEUTERON TO AliPID !!!!!!!!!!!!!!;
+    }
+
     //
-    for(Int_t iPart = 0; iPart < 3; iPart++) { // loop over assumed particle type
-      //                              0,           1,    2,    3,           4,               5,      6,              7,     8
-      Double_t vecHistReal[9]  = {iPart,  centrality,   pT, sign,  rap[iPart], pullsTPC[iPart], hasTOF, pullsTOF[iPart], dca[0]};
-      if (!fOnlyQA) fHistRealTracks->Fill(vecHistReal);
-      //
+//    Double_t tpcQA[4] = {fESDpid->NumberOfSigmasTPC(track,AliPID::kElectron),
+//                      fESDpid->NumberOfSigmasTPC(track,AliPID::kPion),
+//                      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);
+      tofQA[0] = fESDpid->NumberOfSigmasTOF(track,AliPID::kPion, time0);
+      tofQA[0] = fESDpid->NumberOfSigmasTOF(track,AliPID::kKaon, time0);
+      tofQA[0] = fESDpid->NumberOfSigmasTOF(track,AliPID::kProton, time0);
+    }
+    else{
+      tofQA[0] = fESDpid->NumberOfSigmasTOF(trackForTOF,AliPID::kElectron, time0);
+      tofQA[0] = fESDpid->NumberOfSigmasTOF(trackForTOF,AliPID::kPion, time0);
+      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]};
+       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]};
+         if (!fOnlyQA) fHistRealTracks->Fill(vecHistReal);
+       }
+      }
+
+
       // using MC truth for precise efficiencies...
       //
       if (fMCtrue && !fOnlyQA) {
-       Int_t code = 5; // code: 0-generated, 1-true rec. primaries, 2-misident, 3-second weak, 4-second material
+       Int_t code = 9; // code: 0-generated, 1-true rec. primaries, 2-misident, 3-second weak, 4-second material
        Int_t assumedPdg = 0;//2212(proton); 321(Kaon); 211(pion);
+       Int_t motherCode = -1;
        if (iPart == 0) assumedPdg = 211;
        if (iPart == 1) assumedPdg = 321;
        if (iPart == 2) assumedPdg = 2212;
@@ -625,10 +751,20 @@ void AliAnalysisCombinedHadronSpectra::UserExec(Option_t *)
        TParticle *trackMC = stack->Particle(TMath::Abs(track->GetLabel()));
        Int_t pdg = TMath::Abs(trackMC->GetPdgCode());
        //
-       if (pdg != assumedPdg) code = 2;
+       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 && stack->IsPhysicalPrimary(TMath::Abs(track->GetLabel()))) code = 1;
-       if (pdg == assumedPdg && stack->IsSecondaryFromWeakDecay(TMath::Abs(track->GetLabel()))) code = 3;
+       if (pdg == assumedPdg && stack->IsSecondaryFromWeakDecay(TMath::Abs(track->GetLabel()))) {
+         code = 3;
+         if (fSaveMotherPDG){
+           TParticle *trackMother =  stack->Particle(TMath::Abs(trackMC->GetFirstMother()));
+           if (trackMother->GetPdgCode() == 310) motherCode = 6; //K0
+           if (trackMother->GetPdgCode() == 3122) motherCode = 7; //Lambda
+           if (trackMother->GetPdgCode() == 3222) motherCode = 8; //Sigma+
+         }
+       }
        if (pdg == assumedPdg && stack->IsSecondaryFromMaterial(TMath::Abs(track->GetLabel()))) code = 4;
+       
        //
        // muons need special treatment, because they are indistinguishable from pions
        //
@@ -638,14 +774,35 @@ void AliAnalysisCombinedHadronSpectra::UserExec(Option_t *)
        // check TOF mismatch on MC basis with TOF label
        //
        Int_t tofLabel[3];
-       track->GetTOFLabel(tofLabel);
-       if (TMath::Abs(track->GetLabel()) != TMath::Abs(tofLabel[0])) hasTOF = kFALSE;
+       if (!fUseTPConlyTracks) track->GetTOFLabel(tofLabel);
+       else trackForTOF->GetTOFLabel(tofLabel);
+       if (TMath::Abs(track->GetLabel()) != TMath::Abs(tofLabel[0]) || tofLabel[1] > 0) hasTOF = kFALSE;
        //
        // IMPORTANT BIG PROBLEM HERE THE PROBABLILITY TO HAVE A PID SIGNAL MUST BE IN !!!!!!!!!!!!
        //
-       //                              0,           1,   2,    3,           4,               5,      6,               7,      8,   9
-       Double_t vectorHistMC[10] = {iPart,  centrality,  pT, sign,  rap[iPart], pullsTPC[iPart], hasTOF, pullsTOF[iPart], dca[0], code};
-       if (!fOnlyQA) fHistMCparticles->Fill(vectorHistMC);
+       if (!fSmallTHnSparse){
+         Double_t vectorHistMC[10] = {iPart,  centrality,  pT, sign,  rap[iPart], pullsTPC[iPart], hasTOF, pullsTOF[iPart], dca[0], 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};
+             fHistMCparticles->Fill(vectorHistMCmother);
+           }
+         }
+       }
+       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};
+           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};
+               fHistMCparticles->Fill(vectorHistMCmother);
+             }
+           }
+         }
+       }
       }
       //
       //
@@ -721,7 +878,7 @@ void AliAnalysisCombinedHadronSpectra::BinLogAxis(const TH1 *h) {
 
 
 //________________________________________________________________________
-Int_t AliAnalysisCombinedHadronSpectra::GetPythiaEventProcessType(const AliHeader* aHeader, const Bool_t adebug) const {
+Int_t AliAnalysisCombinedHadronSpectra::GetPythiaEventProcessType(const AliHeader* aHeader, Bool_t adebug) const {
   //
   // get the process type of the event.
   //