]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGHF/vertexingHF/AliCFTaskVertexingHF.cxx
consolidate zero-length arrays (aka struct hack)
[u/mrichter/AliRoot.git] / PWGHF / vertexingHF / AliCFTaskVertexingHF.cxx
old mode 100644 (file)
new mode 100755 (executable)
index d9712b7..2a94197
@@ -32,6 +32,7 @@
 #include <TCanvas.h>
 #include <TParticle.h>
 #include <TDatabasePDG.h>
+#include <TProfile.h>
 #include <TH1I.h>
 #include <TStyle.h>
 #include <TFile.h>
@@ -84,6 +85,7 @@ AliCFTaskVertexingHF::AliCFTaskVertexingHF() :
   fCFManager(0x0),
   fHistEventsProcessed(0x0),
   fCorrelation(0x0),
+  fListProfiles(0),
   fCountMC(0),
   fCountAcc(0),
   fCountVertex(0),
@@ -104,6 +106,7 @@ AliCFTaskVertexingHF::AliCFTaskVertexingHF() :
   fUseFlatPtWeight(kFALSE),
   fUseZWeight(kFALSE),
   fUseNchWeight(kFALSE),
+  fUseTrackletsWeight(kFALSE),
   fNvar(0),
   fPartName(""),
   fDauNames(""),
@@ -120,11 +123,19 @@ AliCFTaskVertexingHF::AliCFTaskVertexingHF() :
   fHistoMCNch(0x0),
   fResonantDecay(0),
   fLctoV0bachelorOption(1),
-  fGenLctoV0bachelorOption(0)
+  fGenLctoV0bachelorOption(0),
+  fUseSelectionBit(kTRUE),
+  fPDGcode(0),
+  fMultiplicityEstimator(kNtrk10),
+  fRefMult(9.26),
+  fZvtxCorrectedNtrkEstimator(kFALSE),
+  fIsPPData(kFALSE),
+  fIsPPbData(kFALSE)
 {
   //
   //Default ctor
   //
+  for(Int_t i=0; i<4; i++) fMultEstimatorAvg[i]=0;
 }
 //___________________________________________________________________________
 AliCFTaskVertexingHF::AliCFTaskVertexingHF(const Char_t* name, AliRDHFCuts* cuts, TF1* func) :
@@ -132,6 +143,7 @@ AliCFTaskVertexingHF::AliCFTaskVertexingHF(const Char_t* name, AliRDHFCuts* cuts
   fCFManager(0x0),
   fHistEventsProcessed(0x0),
   fCorrelation(0x0),
+  fListProfiles(0),
   fCountMC(0),
   fCountAcc(0),
   fCountVertex(0),
@@ -152,6 +164,7 @@ AliCFTaskVertexingHF::AliCFTaskVertexingHF(const Char_t* name, AliRDHFCuts* cuts
   fUseFlatPtWeight(kFALSE),
   fUseZWeight(kFALSE),
   fUseNchWeight(kFALSE),
+  fUseTrackletsWeight(kFALSE),
   fNvar(0),
   fPartName(""),
   fDauNames(""),
@@ -168,7 +181,14 @@ AliCFTaskVertexingHF::AliCFTaskVertexingHF(const Char_t* name, AliRDHFCuts* cuts
   fHistoMCNch(0x0),
   fResonantDecay(0),
   fLctoV0bachelorOption(1),
-  fGenLctoV0bachelorOption(0)
+  fGenLctoV0bachelorOption(0),
+  fUseSelectionBit(kTRUE),
+  fPDGcode(0),
+  fMultiplicityEstimator(kNtrk10),
+  fRefMult(9.26),
+  fZvtxCorrectedNtrkEstimator(kFALSE),
+  fIsPPData(kFALSE),
+  fIsPPbData(kFALSE)
 {
   //
   // Constructor. Initialization of Inputs and Outputs
@@ -181,6 +201,8 @@ AliCFTaskVertexingHF::AliCFTaskVertexingHF(const Char_t* name, AliRDHFCuts* cuts
   DefineOutput(2,AliCFContainer::Class());
   DefineOutput(3,THnSparseD::Class());
   DefineOutput(4,AliRDHFCuts::Class());
+  for(Int_t i=0; i<4; i++) fMultEstimatorAvg[i]=0;
+  DefineOutput(5,TList::Class()); // slot #5 keeps the zvtx Ntrakclets correction profiles
        
   fCuts->PrintAll();
 }
@@ -199,6 +221,7 @@ AliCFTaskVertexingHF& AliCFTaskVertexingHF::operator=(const AliCFTaskVertexingHF
     fFuncWeight = c.fFuncWeight;
     fHistoMeasNch = c.fHistoMeasNch;
     fHistoMCNch = c.fHistoMCNch;
+    for(Int_t i=0; i<4; i++) fMultEstimatorAvg[i]=c.fMultEstimatorAvg[i];
   }
   return *this;
 }
@@ -209,6 +232,7 @@ AliCFTaskVertexingHF::AliCFTaskVertexingHF(const AliCFTaskVertexingHF& c) :
   fCFManager(c.fCFManager),
   fHistEventsProcessed(c.fHistEventsProcessed),
   fCorrelation(c.fCorrelation),
+  fListProfiles(c.fListProfiles),
   fCountMC(c.fCountMC),
   fCountAcc(c.fCountAcc),
   fCountVertex(c.fCountVertex),
@@ -229,6 +253,7 @@ AliCFTaskVertexingHF::AliCFTaskVertexingHF(const AliCFTaskVertexingHF& c) :
   fUseFlatPtWeight(c.fUseFlatPtWeight),
   fUseZWeight(c.fUseZWeight),
   fUseNchWeight(c.fUseNchWeight),
+  fUseTrackletsWeight(c.fUseTrackletsWeight),
   fNvar(c.fNvar),
   fPartName(c.fPartName),
   fDauNames(c.fDauNames),
@@ -245,11 +270,19 @@ AliCFTaskVertexingHF::AliCFTaskVertexingHF(const AliCFTaskVertexingHF& c) :
   fHistoMCNch(c.fHistoMCNch),
   fResonantDecay(c.fResonantDecay),
   fLctoV0bachelorOption(c.fLctoV0bachelorOption),
-  fGenLctoV0bachelorOption(c.fGenLctoV0bachelorOption)
+  fGenLctoV0bachelorOption(c.fGenLctoV0bachelorOption),
+  fUseSelectionBit(c.fUseSelectionBit),
+  fPDGcode(c.fPDGcode),
+  fMultiplicityEstimator(c.fMultiplicityEstimator),
+  fRefMult(c.fRefMult),
+  fZvtxCorrectedNtrkEstimator(c.fZvtxCorrectedNtrkEstimator),
+  fIsPPData(c.fIsPPData),
+  fIsPPbData(c.fIsPPbData)
 {
   //
   // Copy Constructor
   //
+  for(Int_t i=0; i<4; i++) fMultEstimatorAvg[i]=c.fMultEstimatorAvg[i];
 }
 
 //___________________________________________________________________________
@@ -261,10 +294,12 @@ AliCFTaskVertexingHF::~AliCFTaskVertexingHF()
   if (fCFManager)           delete fCFManager ;
   if (fHistEventsProcessed) delete fHistEventsProcessed ;
   if (fCorrelation)      delete fCorrelation ;
+  if (fListProfiles)        delete fListProfiles;
   if (fCuts)                delete fCuts;
   if (fFuncWeight)          delete fFuncWeight;
   if (fHistoMeasNch)        delete fHistoMeasNch;
   if (fHistoMCNch)          delete fHistoMCNch;
+  for(Int_t i=0; i<4; i++) { if(fMultEstimatorAvg[i]) delete fMultEstimatorAvg[i]; }
 }
 
 //_________________________________________________________________________-
@@ -276,9 +311,9 @@ void AliCFTaskVertexingHF::Init()
        
   if (fDebug>1) printf("AliCFTaskVertexingHF::Init()");
   if(fUseWeight && fUseZWeight) { AliFatal("Can not use at the same time pt and z-vtx weights, please choose"); return; }
-  if(fUseWeight && fUseNchWeight) { AliFatal("Can not use at the same time pt and Nch weights, please choose"); return; }
+  if(fUseWeight && fUseNchWeight) { AliInfo("Beware, using at the same time pt and Nch weights, please check"); }
   if(fUseNchWeight && !fHistoMCNch) { AliFatal("Need to pass the MC Nch distribution to use Nch weights"); return; }
-  if(fUseNchWeight) CreateMeasuredNchHisto();
+  if(fUseNchWeight && !fHistoMeasNch) CreateMeasuredNchHisto();
 
   AliRDHFCuts *copyfCuts = 0x0;
   if (!fCuts){
@@ -288,6 +323,7 @@ void AliCFTaskVertexingHF::Init()
 
   switch (fDecayChannel){
   case 2:{
+    fPDGcode = 421;
     copyfCuts = new AliRDHFCutsD0toKpi(*(static_cast<AliRDHFCutsD0toKpi*>(fCuts)));
     switch (fConfiguration) {
     case kSnail:  // slow configuration: all variables in
@@ -302,6 +338,7 @@ void AliCFTaskVertexingHF::Init()
     break;
   }
   case 21:{ 
+    fPDGcode = 413;
     copyfCuts = new AliRDHFCutsDStartoKpipi(*(static_cast<AliRDHFCutsDStartoKpipi*>(fCuts)));
     switch (fConfiguration) {
     case kSnail:  // slow configuration: all variables in
@@ -316,6 +353,7 @@ void AliCFTaskVertexingHF::Init()
     break;
   }
   case 22:{
+    fPDGcode = 4122;
     copyfCuts = new AliRDHFCutsLctoV0(*(static_cast<AliRDHFCutsLctoV0*>(fCuts)));
     switch (fConfiguration) {
     case kSnail:  // slow configuration: all variables in
@@ -330,6 +368,7 @@ void AliCFTaskVertexingHF::Init()
     break;
   }
   case 31:{
+    fPDGcode = 411;
     copyfCuts = new AliRDHFCutsDplustoKpipi(*(static_cast<AliRDHFCutsDplustoKpipi*>(fCuts)));
     switch (fConfiguration) {
     case kSnail:  // slow configuration: all variables in
@@ -344,6 +383,7 @@ void AliCFTaskVertexingHF::Init()
     break;
   }
   case 32:{
+    fPDGcode = 4122;
     copyfCuts = new AliRDHFCutsLctopKpi(*(static_cast<AliRDHFCutsLctopKpi*>(fCuts)));
     switch (fConfiguration) {
     case kSnail:  // slow configuration: all variables in
@@ -358,6 +398,7 @@ void AliCFTaskVertexingHF::Init()
     break;
   }
   case 33:{
+    fPDGcode = 431;
     copyfCuts = new AliRDHFCutsDstoKKpi(*(static_cast<AliRDHFCutsDstoKKpi*>(fCuts)));
     switch (fConfiguration) {
     case kSnail:  // slow configuration: all variables in
@@ -372,6 +413,7 @@ void AliCFTaskVertexingHF::Init()
     break;
   }
   case 4:{
+    fPDGcode = 421;
     copyfCuts = new AliRDHFCutsD0toKpipipi(*(static_cast<AliRDHFCutsD0toKpipipi*>(fCuts)));
     switch (fConfiguration) {
     case kSnail:  // slow configuration: all variables in
@@ -399,7 +441,29 @@ void AliCFTaskVertexingHF::Init()
   }
   else{
     AliFatal("Failing initializing AliRDHFCuts object - Exiting...");
-  }    
+  }
+
+  fListProfiles = new TList();
+  fListProfiles->SetOwner();
+  TString period[4];
+  Int_t nProfiles=4;
+  
+  if (fIsPPbData) { //if pPb, use only two estimator histos
+     period[0] = "LHC13b"; period[1] = "LHC13c";
+     nProfiles = 2;
+  } else {        // else assume pp (four histos for LHC10)
+     period[0] = "LHC10b"; period[1] = "LHC10c"; period[2] = "LHC10d"; period[3] = "LHC10e";
+     nProfiles = 4;
+  }
+
+  for(Int_t i=0; i<nProfiles; i++){
+    if(fMultEstimatorAvg[i]){
+      TProfile* hprof=new TProfile(*fMultEstimatorAvg[i]);
+      hprof->SetName(Form("ProfileTrkVsZvtx%s\n",period[i].Data()));
+      fListProfiles->Add(hprof);
+    }
+  }
+  PostData(5,fListProfiles);
        
   return;
 }
@@ -536,6 +600,8 @@ void AliCFTaskVertexingHF::UserExec(Option_t *)
     return;
   }
 
+  fHistEventsProcessed->Fill(0.5);
+
   Double_t* containerInput = new Double_t[fNvar];
   Double_t* containerInputMC = new Double_t[fNvar]; 
        
@@ -583,18 +649,50 @@ void AliCFTaskVertexingHF::UserExec(Option_t *)
   Double_t zPrimVertex = aodVtx ->GetZ();
   Double_t zMCVertex = mcHeader->GetVtxZ();
   Int_t runnumber = aodEvent->GetRunNumber();
+
+  // Multiplicity definition with tracklets
+  Double_t nTracklets = 0;
+  Int_t nTrackletsEta10 = AliVertexingHFUtils::GetNumberOfTrackletsInEtaRange(aodEvent,-1.,1.);
+  Int_t nTrackletsEta16 = AliVertexingHFUtils::GetNumberOfTrackletsInEtaRange(aodEvent,-1.6,1.6);
+  nTracklets = (Double_t)nTrackletsEta10;
+  if(fMultiplicityEstimator==kNtrk10to16) { nTracklets = (Double_t)(nTrackletsEta16 - nTrackletsEta10); }
+
+  // Apply the Ntracklets z-vtx data driven correction
+  if(fZvtxCorrectedNtrkEstimator) {
+    TProfile* estimatorAvg = GetEstimatorHistogram(aodEvent);
+    if(estimatorAvg) {
+      Int_t nTrackletsEta10Corr = AliVertexingHFUtils::GetCorrectedNtracklets(estimatorAvg,nTrackletsEta10,zPrimVertex,fRefMult); 
+      Int_t nTrackletsEta16Corr = AliVertexingHFUtils::GetCorrectedNtracklets(estimatorAvg,nTrackletsEta16,zPrimVertex,fRefMult); 
+      nTracklets = (Double_t)nTrackletsEta10Corr;
+      if(fMultiplicityEstimator==kNtrk10to16) { nTracklets = (Double_t)(nTrackletsEta16Corr - nTrackletsEta10Corr); }
+    }
+  }
+
+
   fWeight=1.;
   if(fUseZWeight) fWeight *= GetZWeight(zMCVertex,runnumber);
   if(fUseNchWeight){
     Int_t nChargedMCPhysicalPrimary=AliVertexingHFUtils::GetGeneratedPhysicalPrimariesInEtaRange(mcArray,-1.0,1.0);
-    fWeight *= GetNchWeight(nChargedMCPhysicalPrimary);
-    AliDebug(2,Form("Using Nch weights, Mult=%d Weight=%f\n",nChargedMCPhysicalPrimary,fWeight));      
+    if(!fUseTrackletsWeight) fWeight *= GetNchWeight(nChargedMCPhysicalPrimary);
+    else fWeight *= GetNchWeight(nTracklets);
+    AliDebug(2,Form("Using Nch weights, Mult=%d Weight=%f\n",nChargedMCPhysicalPrimary,fWeight));
   }
+  Double_t eventWeight=fWeight;
 
   if (TMath::Abs(zMCVertex) > fCuts->GetMaxVtxZ()){
     AliDebug(3,Form("z coordinate of MC vertex = %f, it was required to be within [-%f, +%f], skipping event", zMCVertex, fCuts->GetMaxVtxZ(), fCuts->GetMaxVtxZ()));
     delete[] containerInput;
     delete[] containerInputMC;
+    delete cfVtxHF;
+    return;
+  }
+
+  if(aodEvent->GetTriggerMask()==0 && 
+     (runnumber>=195344 && runnumber<=195677)){
+    AliDebug(3,"Event rejected because of null trigger mask");
+    delete[] containerInput;
+    delete[] containerInputMC;
+    delete cfVtxHF;
     return;
   }
 
@@ -638,6 +736,7 @@ void AliCFTaskVertexingHF::UserExec(Option_t *)
       delete[] containerInput;
       delete[] containerInputMC;
       delete [] trackCuts;
+      delete cfVtxHF;
       return;
     }    
   }  else { // keep all centralities
@@ -645,12 +744,22 @@ void AliCFTaskVertexingHF::UserExec(Option_t *)
     fCuts->SetMaxCentrality(100.);
   }
        
-  Float_t centValue = fCuts->GetCentrality(aodEvent);
+  Float_t centValue = 0.;
+  if(!fIsPPData) centValue = fCuts->GetCentrality(aodEvent);
   cfVtxHF->SetCentralityValue(centValue);  
        
-  // number of tracklets - multiplicity estimator
-  Double_t multiplicity = (Double_t)(aodEvent->GetTracklets()->GetNumberOfTracklets()); // casted to double because the CF is filled with doubles
+  // multiplicity estimator with VZERO
+  Double_t vzeroMult=0;
+  AliAODVZERO *vzeroAOD = (AliAODVZERO*)aodEvent->GetVZEROData();
+  if(vzeroAOD) vzeroMult = vzeroAOD->GetMTotV0A() +  vzeroAOD->GetMTotV0C();
+
+  Double_t multiplicity = nTracklets; // set to the Ntracklet estimator
+  if(fMultiplicityEstimator==kVZERO) { multiplicity = vzeroMult; }
+
+
   cfVtxHF->SetMultiplicity(multiplicity);
+
+  //  printf("Multiplicity estimator %d, value %2.2f\n",fMultiplicityEstimator,multiplicity);
        
   for (Int_t iPart=0; iPart<mcArray->GetEntriesFast(); iPart++) { 
     AliAODMCParticle* mcPart = dynamic_cast<AliAODMCParticle*>(mcArray->At(iPart));
@@ -658,6 +767,10 @@ void AliCFTaskVertexingHF::UserExec(Option_t *)
       AliError("Failed casting particle from MC array!, Skipping particle");
       continue;
     }
+
+    //counting c quarks
+    cquarks += cfVtxHF->MCcquarkCounting(mcPart);
+
     // check the MC-level cuts, must be the desidered particle
     if (!fCFManager->CheckParticleCuts(0, mcPart)) {
       AliDebug(2,"Check the MC-level cuts - not desidered particle");
@@ -665,8 +778,6 @@ void AliCFTaskVertexingHF::UserExec(Option_t *)
     }
     cfVtxHF->SetMCCandidateParam(iPart);
         
-    //counting c quarks
-    cquarks += cfVtxHF->MCcquarkCounting(mcPart);
          
     if (!(cfVtxHF->SetLabelArray())){
       AliDebug(2,Form("Impossible to set the label array (decaychannel = %d)",fDecayChannel));
@@ -679,7 +790,7 @@ void AliCFTaskVertexingHF::UserExec(Option_t *)
       continue;
     }
     else{
-      AliInfo(Form("Check on the family OK!!! (decaychannel = %d)",fDecayChannel));
+      AliDebug(2,Form("Check on the family OK!!! (decaychannel = %d)",fDecayChannel));
     }
                
     //Fill the MC container
@@ -689,11 +800,11 @@ void AliCFTaskVertexingHF::UserExec(Option_t *)
       if (fUseWeight){
        if (fFuncWeight){ // using user-defined function
          AliDebug(2,"Using function");
-         fWeight = fFuncWeight->Eval(containerInputMC[0]);                                  
+         fWeight = eventWeight*fFuncWeight->Eval(containerInputMC[0]);                              
        }
        else{ // using FONLL
          AliDebug(2,"Using FONLL");
-         fWeight = GetWeight(containerInputMC[0]);
+         fWeight = eventWeight*GetWeight(containerInputMC[0]);
        }
        AliDebug(2,Form("pt = %f, weight = %f",containerInputMC[0], fWeight));
       }
@@ -819,11 +930,11 @@ void AliCFTaskVertexingHF::UserExec(Option_t *)
       if (fUseWeight){
        if (fFuncWeight){ // using user-defined function
          AliDebug(2, "Using function");
-         fWeight = fFuncWeight->Eval(containerInput[0]);
+         fWeight = eventWeight*fFuncWeight->Eval(containerInput[0]);
        }
        else{ // using FONLL
          AliDebug(2, "Using FONLL");
-         fWeight = GetWeight(containerInput[0]);
+         fWeight = eventWeight*GetWeight(containerInput[0]);
        }
        AliDebug(2, Form("pt = %f, weight = %f",containerInput[0], fWeight));
       }
@@ -835,6 +946,19 @@ void AliCFTaskVertexingHF::UserExec(Option_t *)
       Bool_t vtxCheck = fCuts->IsEventSelected(aodEvent);
                        
 
+      // Selection on the filtering bit
+      Bool_t isBitSelected = kTRUE;
+      if(fDecayChannel==2) {
+       if(fUseSelectionBit && !charmCandidate->HasSelectionBit(AliRDHFCuts::kD0toKpiCuts)) isBitSelected = kFALSE;
+      }else if(fDecayChannel==31){
+       if(fUseSelectionBit && !charmCandidate->HasSelectionBit(AliRDHFCuts::kDplusCuts)) isBitSelected = kFALSE;
+      }else if(fDecayChannel==33){
+       if(fUseSelectionBit && !charmCandidate->HasSelectionBit(AliRDHFCuts::kDsCuts)) isBitSelected = kFALSE;
+      }
+      if(!isBitSelected) continue;
+
+
+
       if (recoStep && recoContFilled && vtxCheck){
        fCFManager->GetParticleContainer()->Fill(containerInput,kStepReconstructed, fWeight) ;   
        icountReco++;
@@ -849,7 +973,7 @@ void AliCFTaskVertexingHF::UserExec(Option_t *)
                                  
          if(fAcceptanceUnf){
            Double_t fill[4]; //fill response matrix
-           Bool_t bUnfolding = cfVtxHF -> FillUnfoldingMatrix(fill);
+           Bool_t bUnfolding = cfVtxHF -> FillUnfoldingMatrix(fPDGcode,fill);
            if (bUnfolding) fCorrelation->Fill(fill);
          }
                                        
@@ -893,8 +1017,8 @@ void AliCFTaskVertexingHF::UserExec(Option_t *)
                Bool_t keepDs=ProcessDs(recoPidSelection);
                if(keepDs) recoPidSelection=3;                                                    
              } else if (fDecayChannel==22){ // Lc->V0+bachelor case, where more possibilities are considered
-               Bool_t keepLctoV0bachelor=ProcessLctoV0Bachelor(recoAnalysisCuts);
-               if (keepLctoV0bachelor) recoAnalysisCuts=3;
+               Bool_t keepLctoV0bachelor=ProcessLctoV0Bachelor(recoPidSelection);
+               if (keepLctoV0bachelor) recoPidSelection=3;
              }
 
              Bool_t tempPid=(recoPidSelection == 3 || recoPidSelection == isPartOrAntipart);
@@ -906,7 +1030,7 @@ void AliCFTaskVertexingHF::UserExec(Option_t *)
                AliDebug(3,"Reco PID cuts passed and container filled \n");
                if(!fAcceptanceUnf){
                  Double_t fill[4]; //fill response matrix
-                 Bool_t bUnfolding = cfVtxHF -> FillUnfoldingMatrix(fill);
+                 Bool_t bUnfolding = cfVtxHF -> FillUnfoldingMatrix(fPDGcode,fill);
                  if (bUnfolding) fCorrelation->Fill(fill);
                }
              }
@@ -945,7 +1069,7 @@ void AliCFTaskVertexingHF::UserExec(Option_t *)
   fCountRecoPPR+= icountRecoPPR;
   fCountRecoPID+= icountRecoPID;
        
-  fHistEventsProcessed->Fill(0);
+  fHistEventsProcessed->Fill(1.5);
 
   delete[] containerInput;
   delete[] containerInputMC;
@@ -1045,22 +1169,25 @@ void AliCFTaskVertexingHF::Terminate(Option_t*)
     } else if (fDecayChannel==22) {
       //nvarToPlot = 16;
       titles = new TString[nvarToPlot];
-      titles[0]="pT_Lc (GeV/c)";
-      titles[1]="rapidity";
-      titles[2]="phi (rad)";
-      titles[3]="cosPAV0";
-      titles[4]="onTheFlyStatusV0";
+      titles[0]="p_{T}(#Lambda_{c}) [GeV/c]";
+      titles[1]="y(#Lambda_{c})";
+      titles[2]="#varphi(#Lambda_{c}) [rad]";
+      titles[3]="onTheFlyStatusV0";
+      titles[4]="z_{vtx} [cm]";
       titles[5]="centrality";
       titles[6]="fake";
       titles[7]="multiplicity";
-      titles[8]="pT_bachelor (GeV/c)";
-      titles[9]="pT_V0pos (GeV/c)";
-      titles[10]="pT_V0neg (GeV/c)";
-      titles[11]="invMassV0 (GeV/c2)";
-      titles[12]="dcaV0 (nSigma)";
-      titles[13]="c#tauV0 (#mum)";
-      titles[14]="c#tau (#mum)";
-      titles[15]="cosPA";
+      //titles[8]="pT(bachelor) [GeV/c]";
+      titles[8]="p(bachelor) [GeV/c]";
+      titles[9]="p_{T}(V0) [GeV/c]";
+      titles[10]="y(V0)";
+      titles[11]="#varphi(V0) [rad]";
+      titles[12]="m_{inv}(#pi^{+}#pi^{+}) [GeV/c^{2}]";
+      titles[13]="dcaV0 (nSigma)";
+      titles[14]="cosine pointing angle (V0)";
+      titles[15]="cosine pointing angle (#Lambda_{c})";
+      //titles[16]="c#tauV0 (#mum)";
+      //titles[17]="c#tau (#mum)";
     } else {
       //nvarToPlot = 12;
       titles = new TString[nvarToPlot];
@@ -1082,11 +1209,11 @@ void AliCFTaskVertexingHF::Terminate(Option_t*)
     //nvarToPlot = 8;
     titles = new TString[nvarToPlot];
     if (fDecayChannel==22) {
-      titles[0]="pT_candidate (GeV/c)";
-      titles[1]="rapidity";
-      titles[2]="phi (rad)";
-      titles[3]="cosPAV0";
-      titles[4]="onTheFlyStatusV0";
+      titles[0]="p_{T}(#Lambda_{c}) [GeV/c]";
+      titles[1]="y(#Lambda_{c})";
+      titles[2]="#varphi(#Lambda_{c}) [rad]";
+      titles[3]="onTheFlyStatusV0";
+      titles[4]="z_{vtx} [cm]";
       titles[5]="centrality";
       titles[6]="fake";
       titles[7]="multiplicity";
@@ -1200,7 +1327,7 @@ void AliCFTaskVertexingHF::Terminate(Option_t*)
   file_projection->Close();
   for (Int_t ih = 0; ih<3; ih++) delete [] h[ih];
   delete [] h;
-
+  delete [] titles;
        
 }
 
@@ -1211,25 +1338,13 @@ void AliCFTaskVertexingHF::UserCreateOutputObjects()
   //TO BE SET BEFORE THE EXECUTION OF THE TASK
   //
   Info("UserCreateOutputObjects","CreateOutputObjects of task %s\n", GetName());
-       
-  AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
-  AliInputEventHandler* inputHandler = (AliInputEventHandler*) (man->GetInputEventHandler());
-  AliPIDResponse *localPIDResponse = (AliPIDResponse*)inputHandler->GetPIDResponse();
-
-  if (fCuts->GetIsUsePID() && fDecayChannel==22) {
-         
-    fCuts->GetPidHF()->SetPidResponse(localPIDResponse);
-    (dynamic_cast<AliRDHFCutsLctoV0*>(fCuts))->GetPidV0pos()->SetPidResponse(localPIDResponse);
-    (dynamic_cast<AliRDHFCutsLctoV0*>(fCuts))->GetPidV0neg()->SetPidResponse(localPIDResponse);
-    fCuts->GetPidHF()->SetOldPid(kFALSE);
-    (dynamic_cast<AliRDHFCutsLctoV0*>(fCuts))->GetPidV0pos()->SetOldPid(kFALSE);
-    (dynamic_cast<AliRDHFCutsLctoV0*>(fCuts))->GetPidV0neg()->SetOldPid(kFALSE);
-  }
 
   //slot #1
   OpenFile(1);
   const char* nameoutput=GetOutputSlot(1)->GetContainer()->GetName();
-  fHistEventsProcessed = new TH1I(nameoutput,"",1,0,1) ;
+  fHistEventsProcessed = new TH1I(nameoutput,"",2,0,2) ;
+  fHistEventsProcessed->GetXaxis()->SetBinLabel(1,"Events processed (all)");
+  fHistEventsProcessed->GetXaxis()->SetBinLabel(2,"Events analyzed (after selection)");
 
   PostData(1,fHistEventsProcessed) ;
   PostData(2,fCFManager->GetParticleContainer()) ;
@@ -1238,6 +1353,122 @@ void AliCFTaskVertexingHF::UserCreateOutputObjects()
 }
 
 
+//_________________________________________________________________________
+void AliCFTaskVertexingHF::SetPtWeightsFromFONLL276overLHC12a17a(){
+  // ad-hoc weight function from ratio of 
+  // pt spectra from FONLL 2.76 TeV and
+  // pt spectra from MC production LHC12a17a (PYTHIA Perugia0 with pthard bins)
+  if(fFuncWeight) delete fFuncWeight;
+  fFuncWeight=new TF1("funcWeight","[0]+[1]*TMath::Exp(-[2]*x)",0.,50.);
+  fFuncWeight->SetParameter(0,4.63891e-02);
+  fFuncWeight->SetParameter(1,1.51674e+01);
+  fFuncWeight->SetParameter(2,4.09941e-01);
+  fUseWeight=kTRUE;
+}
+//_________________________________________________________________________
+void AliCFTaskVertexingHF::SetPtWeightsFromDataPbPb276overLHC12a17a(){
+  // ad-hoc weight function from ratio of 
+  // D0 pt spectra in PbPb 2011 0-10% centrality and
+ // pt spectra from MC production LHC12a17a (PYTHIA Perugia0 with pthard bins)
+  if(fFuncWeight) delete fFuncWeight;
+  fFuncWeight=new TF1("funcWeight","[0]+[1]/TMath::Power(x,[2])",0.05,50.);
+  fFuncWeight->SetParameter(0,1.43116e-02);
+  fFuncWeight->SetParameter(1,4.37758e+02);
+  fFuncWeight->SetParameter(2,3.08583);
+  fUseWeight=kTRUE;
+}
+
+//_________________________________________________________________________
+void AliCFTaskVertexingHF::SetPtWeightsFromFONLL276overLHC12a17b(){
+  // weight function from the ratio of the LHC12a17b MC
+  // and FONLL calculations for pp data
+  if(fFuncWeight) delete fFuncWeight;
+  fFuncWeight=new TF1("funcWeight","([0]*x)/TMath::Power([2],(1+TMath::Power([3],x/[1])))+[4]*TMath::Exp([5]+[6]*x)+[7]*TMath::Exp([8]*x)",0.15,50.);
+  fFuncWeight->SetParameters(1.92381e+01, 5.05055e+00, 1.05314e+01, 2.5, 1.88214e-03, 3.44871e+00, -9.74325e-02, 1.97671e+00, -3.21278e-01);
+  fUseWeight=kTRUE;
+}
+
+//_________________________________________________________________________
+void AliCFTaskVertexingHF::SetPtWeightsFromFONLL276andBAMPSoverLHC12a17b(){
+  // weight function from the ratio of the LHC12a17b MC
+  // and FONLL calculations for pp data
+  // corrected by the BAMPS Raa calculation for 30-50% CC
+  if(fFuncWeight) delete fFuncWeight;
+  fFuncWeight=new TF1("funcWeight","([0]*x)/TMath::Power([2],(1+TMath::Power([3],x/[1])))+[4]*TMath::Exp([5]+[6]*x)+[7]*TMath::Exp([8]*x)",0.15,50.);
+  fFuncWeight->SetParameters(6.10443e+00, 1.53487e+00, 1.99474e+00, 2.5, 5.51172e-03, 5.86590e+00, -5.46963e-01, 9.41201e-02, -1.64323e-01);
+  fUseWeight=kTRUE;
+}
+
+//_________________________________________________________________________
+void AliCFTaskVertexingHF::SetPtWeightsFromFONLL5overLHC13d3(){
+  // weight function from the ratio of the LHC13d3 MC
+  // and FONLL calculations for pp data
+  if(fFuncWeight) delete fFuncWeight;
+  fFuncWeight=new TF1("funcWeight","([0]*x)/TMath::Power([2],(1+TMath::Power([3],x/[1])))+[4]*TMath::Exp([5]+[6]*x)+[7]*TMath::Exp([8]*x)",0.15,30.);
+  fFuncWeight->SetParameters(2.94999e+00,3.47032e+00,2.81278e+00,2.5,1.93370e-02,3.86865e+00,-1.54113e-01,8.86944e-02,2.56267e-02);
+  fUseWeight=kTRUE;
+}
+
+//_________________________________________________________________________
+void AliCFTaskVertexingHF::SetPtWeightsFromFONLL7overLHC10f6a(){
+  // weight function from the ratio of the LHC10f6a MC
+  // and FONLL calculations for pp data
+  if(fFuncWeight) delete fFuncWeight;
+  fFuncWeight=new TF1("funcWeight","([0]*x)/TMath::Power([2],(1+TMath::Power([3],x/[1])))+[4]*TMath::Exp([5]+[6]*x)+[7]*TMath::Exp([8]*x)",0.15,40.);
+  fFuncWeight->SetParameters(2.41522e+01,4.92146e+00,6.72495e+00,2.5,6.15361e-03,4.78995e+00,-4.29135e-01,3.99421e-01,-1.57220e-02);
+  fUseWeight=kTRUE;
+}
+
+//_________________________________________________________________________
+void AliCFTaskVertexingHF::SetPtWeightsFromFONLL7overLHC12a12(){
+  // weight function from the ratio of the LHC12a12 MC
+  // and FONLL calculations for pp data
+  if(fFuncWeight) delete fFuncWeight;
+  fFuncWeight=new TF1("funcWeight","([0]*x)/TMath::Power([2],(1+TMath::Power([3],x/[1])))+[4]*TMath::Exp([5]+[6]*x)+[7]*TMath::Exp([8]*x+[9])",0.15,50.);
+  fFuncWeight->SetParameters(1.31497e+01,3.30503e+00,3.45594e+00,2.5,2.28642e-02,1.42372e+00,2.32892e-04,5.21986e-02,-2.14236e-01,3.86200e+00);
+  fUseWeight=kTRUE;
+}
+
+//_________________________________________________________________________
+void AliCFTaskVertexingHF::SetPtWeightsFromFONLL7overLHC12a12bis(){
+  // weight function from the ratio of the LHC12a12bis MC
+  // and FONLL calculations for pp data
+  if(fFuncWeight) delete fFuncWeight;
+  fFuncWeight=new TF1("funcWeight","([0]*x)/TMath::Power([2],(1+TMath::Power([3],x/[1])))+[4]*TMath::Exp([5]+[6]*x)+[7]*TMath::Exp([8]*x+[9])",0.15,50.);
+  fFuncWeight->SetParameters(6.54519e+00,2.74007e+00,2.48325e+00,2.5,1.61113e-01,-5.32546e-01,-3.75916e-04,2.38189e-01,-2.17561e-01,2.35975e+00);
+  fUseWeight=kTRUE;
+}
+
+//_________________________________________________________________________
+void AliCFTaskVertexingHF::SetPtWeightsFromFONLL7overLHC13e2fix(){
+  // weight function from the ratio of the LHC13e2fix MC
+  // and FONLL calculations for pp data
+  if(fFuncWeight) delete fFuncWeight;
+  fFuncWeight=new TF1("funcWeight","([0]*x)/TMath::Power([2],(1+TMath::Power([3],x/[1])))+[4]*TMath::Exp([5]+[6]*x)+[7]*TMath::Exp([8]*x+[9])",0.15,50.);
+  fFuncWeight->SetParameters(1.85862e+01,2.48171e+00,3.39356e+00,2.5,1.70426e-02,2.28453e+00,-4.57749e-02,5.84585e-02,-3.19719e-01,4.16789e+00);
+  fUseWeight=kTRUE;
+}
+
+//________________________________________________________________
+void AliCFTaskVertexingHF::SetPtWeightsFromFONLL5overLHC10f6a(){
+  // weight function from the ratio of the LHC10f6a MC
+  // and FONLL calculations for pp data
+  if(fFuncWeight) delete fFuncWeight;
+  fFuncWeight=new TF1("funcWeight","([0]*x)/TMath::Power([2],(1+TMath::Power([3],x/[1])))+[4]*TMath::Exp([5]+[6]*x)+[7]*TMath::Exp([8]*x)",0.15,40.);
+  fFuncWeight->SetParameters(2.77730e+01,4.78942e+00,7.45378e+00,2.5,9.86255e-02,2.30120e+00,-4.16435e-01,3.43770e-01,-2.29380e-02);
+  fUseWeight=kTRUE;
+}
+
+//________________________________________________________________
+void AliCFTaskVertexingHF::SetPtWeightsFromFONLL276overLHC10f6a(){
+  // weight function from the ratio of the LHC10f6a MC
+  // and FONLL calculations for pp data
+  if(fFuncWeight) delete fFuncWeight;
+  fFuncWeight=new TF1("funcWeight","([0]*x)/TMath::Power([2],(1+TMath::Power([3],x/[1])))+[4]*TMath::Exp([5]+[6]*x)+[7]*TMath::Exp([8]*x+[9])",0.15,40.);
+  fFuncWeight->SetParameters(1.34412e+01,3.20068e+00,5.14481e+00,2.5,7.59405e-04,7.51821e+00,-3.93811e-01,2.16849e-02,-3.37768e-02,2.40308e+00);
+  fUseWeight=kTRUE;
+}
+
 //_________________________________________________________________________
 Double_t AliCFTaskVertexingHF::GetWeight(Float_t pt)
 {
@@ -1315,31 +1546,44 @@ Double_t AliCFTaskVertexingHF::GetNchWeight(Int_t nch){
   //  calculates the Nch weight using the measured and generateed Nch distributions
   //
   if(nch<=0) return 0.;
+  if(!fHistoMeasNch || !fHistoMCNch) { AliError("Input histos to evaluate Nch weights missing"); return 0.; }
   Double_t pMeas=fHistoMeasNch->GetBinContent(fHistoMeasNch->FindBin(nch));
   Double_t pMC=fHistoMCNch->GetBinContent(fHistoMCNch->FindBin(nch));
-  return pMeas/pMC;
+  Double_t weight = pMC>0 ? pMeas/pMC : 0.;
+  if(fUseTrackletsWeight)  weight = pMC;
+  return weight;
 }
 //__________________________________________________________________________________________________
 void AliCFTaskVertexingHF::CreateMeasuredNchHisto(){
   // creates historgam with measured multiplcity distribution in pp 7 TeV collisions (from Eur. Phys. J. C (2010) 68: 345–354)
-  Double_t nchbins[66]={0.50,1.50,2.50,3.50,4.50,5.50,6.50,7.50,8.50,9.50,
+  //
+  // for Nch  > 70 the points were obtained with a double NBD distribution fit
+  // TF1 *fit1 = new TF1("fit1","[0]*(TMath::Gamma(x+[1])/(TMath::Gamma(x+1)*TMath::Gamma([1])))*(TMath::Power(([2]/[1]),x))*(TMath::Power((1+([2]/[1])),-x-[1]))"); fit1->SetParameter(0,1.);// normalization constant
+  // fit1->SetParameter(1,1.63); // k parameter
+  // fit1->SetParameter(2,12.8); // mean multiplicity
+  //
+  Double_t nchbins[82]={0.50,1.50,2.50,3.50,4.50,5.50,6.50,7.50,8.50,9.50,
                        10.50,11.50,12.50,13.50,14.50,15.50,16.50,17.50,18.50,19.50,
                        20.50,21.50,22.50,23.50,24.50,25.50,26.50,27.50,28.50,29.50,
                        30.50,31.50,32.50,33.50,34.50,35.50,36.50,37.50,38.50,39.50,
                        40.50,41.50,42.50,43.50,44.50,45.50,46.50,47.50,48.50,49.50,
                        50.50,51.50,52.50,53.50,54.50,55.50,56.50,57.50,58.50,59.50,
-                       60.50,62.50,64.50,66.50,68.50,70.50};
-  Double_t pch[65]={0.062011,0.072943,0.070771,0.067245,0.062834,0.057383,0.051499,0.04591,0.041109,0.036954,
+                       60.50,62.50,64.50,66.50,68.50,70.50,72.50,74.50,76.50,78.50,
+                       80.50,82.50,84.50,86.50,88.50,90.50,92.50,94.50,96.50,98.50, 
+                       100.50,102.50};
+  Double_t pch[81]={0.062011,0.072943,0.070771,0.067245,0.062834,0.057383,0.051499,0.04591,0.041109,0.036954,
                    0.03359,0.030729,0.028539,0.026575,0.024653,0.0229,0.021325,0.019768,0.018561,0.017187,
                    0.01604,0.014836,0.013726,0.012576,0.011481,0.010393,0.009502,0.008776,0.008024,0.007452,
                    0.006851,0.006428,0.00594,0.005515,0.005102,0.00469,0.004162,0.003811,0.003389,0.003071,
                    0.002708,0.002422,0.002184,0.001968,0.00186,0.00165,0.001577,0.001387,0.001254,0.001118,
                    0.001037,0.000942,0.000823,0.000736,0.000654,0.000579,0.000512,0.00049,0.00045,0.000355,
-                   0.000296,0.000265,0.000193,0.00016,0.000126};
+                   0.000296,0.000265,0.000193,0.00016,0.000126,0.0000851, 0.0000676,0.0000537,0.0000426, 0.0000338,
+                   0.0000268,0.0000213,0.0000166,0.0000133,0.0000106,0.00000837,0.00000662, 0.00000524,0.00000414, 0.00000327,
+                   0.00000258};
 
   if(fHistoMeasNch) delete fHistoMeasNch;
-  fHistoMeasNch=new TH1F("hMeaseNch","",65,nchbins);
-  for(Int_t i=0; i<65; i++){
+  fHistoMeasNch=new TH1F("hMeaseNch","",81,nchbins);
+  for(Int_t i=0; i<81; i++){
     fHistoMeasNch->SetBinContent(i+1,pch[i]);
     fHistoMeasNch->SetBinError(i+1,0.);
   }
@@ -1393,3 +1637,29 @@ Bool_t AliCFTaskVertexingHF::ProcessLctoV0Bachelor(Int_t recoAnalysisCuts) const
   }
   return keep;
 }
+
+//____________________________________________________________________________
+TProfile* AliCFTaskVertexingHF::GetEstimatorHistogram(const AliVEvent* event){
+  // Get Estimator Histogram from period event->GetRunNumber();
+  //
+  // If you select SPD tracklets in |eta|<1 you should use type == 1
+  //
+
+  Int_t runNo  = event->GetRunNumber();
+  Int_t period = -1;   // pp:  0-LHC10b, 1-LHC10c, 2-LHC10d, 3-LHC10e
+                       // pPb: 0-LHC13b, 1-LHC13c
+
+  if (fIsPPbData) {    // setting run numbers for LHC13 if pPb
+      if (runNo>195343 && runNo<195484) period = 0;
+      if (runNo>195528 && runNo<195678) period = 1;
+      if (period<0 || period>1) return 0;
+  } else {             //else assume pp 2010                 
+      if(runNo>114930 && runNo<117223) period = 0;
+      if(runNo>119158 && runNo<120830) period = 1;
+      if(runNo>122373 && runNo<126438) period = 2;
+      if(runNo>127711 && runNo<130841) period = 3;
+      if(period<0 || period>3) return 0;
+  }
+
+  return fMultEstimatorAvg[period];
+}