AliPhysics  master (3d17d9d)
EstimateSingleTrackPIDsyst.C
Go to the documentation of this file.
1 #if !defined (__CINT__) || defined (__CLING__)
2 
3 #include <Riostream.h>
4 #include <TFile.h>
5 #include <TDirectoryFile.h>
6 #include <TCanvas.h>
7 #include <TH1F.h>
8 #include <TH2F.h>
9 #include <TF1.h>
10 #include <TStyle.h>
11 #include <TString.h>
12 #include <TList.h>
13 #include <TTree.h>
14 #include <TMath.h>
15 #include <TFractionFitter.h>
16 #include <TObjArray.h>
17 #include <TDatabasePDG.h>
18 #include <TGaxis.h>
19 #include <TLegend.h>
20 #include <TLatex.h>
21 #include <TProfile.h>
22 #include <vector>
23 #include <string>
24 #include <sstream>
25 #include <fstream>
26 
28 
29 #endif
30 
32 // \brief macro for estimation of PID Systematic uncertainty of the single track (pions/kaons/protons) //
33 // \main function: EstimateSingleTrackPIDsyst //
34 // \author: F. Grosa, fabrizio.grosa@cern.ch //
36 
37 using namespace std;
38 
39 //_____________________________________________________
40 //GLOBAL VARIABLES
41 //NOT TO EDIT
42 enum vars {kPt,kP};
44 const int nPDGcodes = 6;
45 const int pdgcodes[nPDGcodes]={11,13,211,321,2212,-100};
46 const int pdgcolors[nPDGcodes]={kOrange+7,kGray,kRed,kBlue,kGreen+2,kBlack};
47 const int pdgfillcolors[nPDGcodes]={kOrange+7,kGray,kRed,kBlue,kGreen+2,kWhite};
48 const TString pdgnames[nPDGcodes]={"Electron","Muon","Pion","Kaon","Proton","All"};
49 //TO EDIT
50 const double binlims[] = {0.3,0.5,0.75,1.,1.5,2.,3.,5.,10.};
51 const TString infileNameData = "/AnalysisResults_data.root";
52 const TString indirNameData = "PWGHF_D2H_SystNsigmaPID";
53 const TString inlistNameData = "coutputPIDhistos";
54 const TString infileNameMC = "AnalysisResults_MC.root";
55 const TString indirNameMC = "PWGHF_D2H_SystNsigmaPID";
56 const TString inlistNameMC = "coutputPIDhistos";
57 const TString outputdirName = "outputs/";
58 //applied only to data
59 double absetamin = 0.;
60 double absetamax = 1.;
61 
62 //_____________________________________________________
63 //METHOD PROTOTYPES
64 int EstimateSingleTrackPIDsyst(int maxEntries=1e9, int var4proj=kP);
65 int GetHistoParticleIndex(short pdgcode);
66 int FindPtbin(float pt, const double binlims[], int nBins);
67 void ComputeEfficiency(double num, double den, double &eff, double &effunc);
68 void GetTOFFractionsFromData(int whichpart, int iBin, TH1F* hFractionMC[nPDGcodes-1], TH1F* hFractionData[nPDGcodes-1], TH1F* hNsigmaMC[nPDGcodes], TH1F* hNsigmaData, TFractionFitter *&fNsigmaFitter, vector<int> &templUsed);
69 double PDFnsigmaTPCtot(double* nsigma, double* pars);
70 void PlotQAhistos(TList* listMC, TList* listData);
71 void DivideCanvas(TCanvas* c, int nBins);
72 void SetStyle();
73 void SetTH1Style(TH1F* histo, int markerstyle, int markercolor, float markersize, int linewidth, int linecolor, int fillcolor, float labelsize=-1, float titlesize=-1);
74 
75 //_____________________________________________________
76 //METHOD IMPLEMENTATIONS
77 int EstimateSingleTrackPIDsyst(int maxEntries, int var4proj) {
78 
79  SetStyle();
80 
81  TString varname = "";
82  if(var4proj==kPt)
83  varname = "#it{p}_{T}";
84  else if(var4proj==kP)
85  varname = "#it{p}";
86  else {
87  cerr << "You can chose to project the Nsigma distributions vs. pT or p only. Exit" << endl;
88  return -1;
89  }
90 
91  //********************************************************************************************************************************************//
92  //get pt bins
93  const int nBins = sizeof(binlims)/sizeof(binlims[0])-1;
94 
95  cout << "\n\n********************\n" << endl;
96  cout << nBins << " bins (GeV/c):" << endl;
97  for(int iBin=0; iBin<nBins; iBin++) {
98  cout << binlims[iBin]<<"-"<< binlims[iBin+1] <<endl;
99  }
100 
101  //********************************************************************************************************************************************//
102  //define histos
103 
104  //MC truth
105  TH2F *hNsigmaTPCPionVsPtMCTrue, *hNsigmaTPCKaonVsPtMCTrue, *hNsigmaTPCProtonVsPtMCTrue;
106  TH2F *hNsigmaTOFPionVsPtMCTrue, *hNsigmaTOFKaonVsPtMCTrue, *hNsigmaTOFProtonVsPtMCTrue;
107 
108  TH1F *hNsigmaTPCPionMCTrue[nBins], *hNsigmaTPCKaonMCTrue[nBins], *hNsigmaTPCProtonMCTrue[nBins];
109  TH1F *hNsigmaTOFPionMCTrue[nBins], *hNsigmaTOFKaonMCTrue[nBins], *hNsigmaTOFProtonMCTrue[nBins];
110 
111  //MC tagged
112  TH1F *hNsigmaTPCPionMCV0tag[nBins][nPDGcodes], *hNsigmaTPCKaonMCKinktag[nBins][nPDGcodes], *hNsigmaTPCKaonMCTOFtag[nBins][nPDGcodes], *hNsigmaTPCProtonMCV0tag[nBins][nPDGcodes];
113  TH1F *hNsigmaTOFPionMCV0tag[nBins][nPDGcodes], *hNsigmaTOFKaonMCKinktag[nBins][nPDGcodes], *hNsigmaTOFKaonMCTPCtag[nBins][nPDGcodes], *hNsigmaTOFProtonMCV0tag[nBins][nPDGcodes];
114 
115  //data tagged
116  TH1F *hNsigmaTPCPionDataV0tag[nBins], *hNsigmaTPCKaonDataKinktag[nBins], *hNsigmaTPCKaonDataTOFtag[nBins], *hNsigmaTPCProtonDataV0tag[nBins];
117  TH1F *hNsigmaTOFPionDataV0tag[nBins], *hNsigmaTOFKaonDataKinktag[nBins], *hNsigmaTOFKaonDataTPCtag[nBins], *hNsigmaTOFProtonDataV0tag[nBins];
118 
119  for(int iBin=0; iBin<nBins; iBin++) {
120  for(int iPart=0; iPart<nPDGcodes; iPart++) {
121  hNsigmaTPCPionMCV0tag[iBin][iPart] = new TH1F(Form("hNsigmaTPCPionMCV0tag_%s_p%0.f_%0.f",pdgnames[iPart].Data(),binlims[iBin]*10,binlims[iBin+1]*10),Form("%0.2f < %s < %0.2f GeV/#it{c};N_{#sigma}^{TPC}(#pi);Normalised entries",binlims[iBin],varname.Data(),binlims[iBin+1]),1000,-50,50);
122  hNsigmaTPCKaonMCKinktag[iBin][iPart] = new TH1F(Form("hNsigmaTPCKaonMCKinktag_%s_p%0.f_%0.f",pdgnames[iPart].Data(),binlims[iBin]*10,binlims[iBin+1]*10),Form("%0.2f < %s < %0.2f GeV/#it{c};N_{#sigma}^{TPC}(K);Normalised entries",binlims[iBin],varname.Data(),binlims[iBin+1]),1000,-50,50);
123  hNsigmaTPCKaonMCTOFtag[iBin][iPart] = new TH1F(Form("hNsigmaTPCKaonMCTOFtag_%s_p%0.f_%0.f",pdgnames[iPart].Data(),binlims[iBin]*10,binlims[iBin+1]*10),Form("%0.2f < %s < %0.2f GeV/#it{c};N_{#sigma}^{TPC}(K);Normalised entries",binlims[iBin],varname.Data(),binlims[iBin+1]),1000,-50,50);
124  hNsigmaTPCProtonMCV0tag[iBin][iPart] = new TH1F(Form("hNsigmaTPCProtonMCV0tag_%s_p%0.f_%0.f",pdgnames[iPart].Data(),binlims[iBin]*10,binlims[iBin+1]*10),Form("%0.2f < %s < %0.2f GeV/#it{c};N_{#sigma}^{TPC}(p);Normalised entries",binlims[iBin],varname.Data(),binlims[iBin+1]),1000,-50,50);
125 
126  hNsigmaTOFPionMCV0tag[iBin][iPart] = new TH1F(Form("hNsigmaTOFPionMCV0tag_%s_p%0.f_%0.f",pdgnames[iPart].Data(),binlims[iBin]*10,binlims[iBin+1]*10),Form("%0.2f < %s < %0.2f GeV/#it{c};N_{#sigma}^{TOF}(#pi);Normalised entries",binlims[iBin],varname.Data(),binlims[iBin+1]),1000,-50,50);
127  hNsigmaTOFKaonMCKinktag[iBin][iPart] = new TH1F(Form("hNsigmaTOFKaonMCKinktag_%s_p%0.f_%0.f",pdgnames[iPart].Data(),binlims[iBin]*10,binlims[iBin+1]*10),Form("%0.2f < %s < %0.2f GeV/#it{c};N_{#sigma}^{TOF}(K);Normalised entries",binlims[iBin],varname.Data(),binlims[iBin+1]),1000,-50,50);
128  hNsigmaTOFKaonMCTPCtag[iBin][iPart] = new TH1F(Form("hNsigmaTOFKaonMCTPCtag_%s_p%0.f_%0.f",pdgnames[iPart].Data(),binlims[iBin]*10,binlims[iBin+1]*10),Form("%0.2f < %s < %0.2f GeV/#it{c};N_{#sigma}^{TOF}(K);Normalised entries",binlims[iBin],varname.Data(),binlims[iBin+1]),1000,-50,50);
129  hNsigmaTOFProtonMCV0tag[iBin][iPart] = new TH1F(Form("hNsigmaTOFProtonMCV0tag_%s_p%0.f_%0.f",pdgnames[iPart].Data(),binlims[iBin]*10,binlims[iBin+1]*10),Form("%0.2f < %s < %0.2f GeV/#it{c};N_{#sigma}^{TOF}(p);Normalised entries",binlims[iBin],varname.Data(),binlims[iBin+1]),1000,-50,50);
130 
131  SetTH1Style(hNsigmaTPCPionMCV0tag[iBin][iPart],kFullCircle,pdgcolors[iPart],0.6,2,pdgcolors[iPart],pdgfillcolors[iPart],0.055,0.06);
132  SetTH1Style(hNsigmaTPCKaonMCKinktag[iBin][iPart],kFullCircle,pdgcolors[iPart],0.6,2,pdgcolors[iPart],pdgfillcolors[iPart],0.055,0.06);
133  SetTH1Style(hNsigmaTPCKaonMCTOFtag[iBin][iPart],kFullCircle,pdgcolors[iPart],0.6,2,pdgcolors[iPart],pdgfillcolors[iPart],0.055,0.06);
134  SetTH1Style(hNsigmaTPCProtonMCV0tag[iBin][iPart],kFullCircle,pdgcolors[iPart],0.6,2,pdgcolors[iPart],pdgfillcolors[iPart],0.055,0.06);
135  SetTH1Style(hNsigmaTOFPionMCV0tag[iBin][iPart],kFullCircle,pdgcolors[iPart],0.6,2,pdgcolors[iPart],pdgfillcolors[iPart],0.055,0.06);
136  SetTH1Style(hNsigmaTOFKaonMCKinktag[iBin][iPart],kFullCircle,pdgcolors[iPart],0.6,2,pdgcolors[iPart],pdgfillcolors[iPart],0.055,0.06);
137  SetTH1Style(hNsigmaTOFKaonMCTPCtag[iBin][iPart],kFullCircle,pdgcolors[iPart],0.6,2,pdgcolors[iPart],pdgfillcolors[iPart],0.055,0.06);
138  SetTH1Style(hNsigmaTOFProtonMCV0tag[iBin][iPart],kFullCircle,pdgcolors[iPart],0.6,2,pdgcolors[iPart],pdgfillcolors[iPart],0.055,0.06);
139  }
140 
141  hNsigmaTPCPionDataV0tag[iBin] = new TH1F(Form("hNsigmaTPCPionDataV0tag_p%0.f_%0.f",binlims[iBin]*10,binlims[iBin+1]*10),Form("%0.2f < %s < %0.2f GeV/#it{c};N_{#sigma}^{TPC}(#pi);Normalised entries",binlims[iBin],varname.Data(),binlims[iBin+1]),1000,-50,50);
142  hNsigmaTPCKaonDataKinktag[iBin] = new TH1F(Form("hNsigmaTPCKaonDataKinktag_p%0.f_%0.f",binlims[iBin]*10,binlims[iBin+1]*10),Form("%0.2f < %s < %0.2f GeV/#it{c};N_{#sigma}^{TPC}(K);Normalised entries",binlims[iBin],varname.Data(),binlims[iBin+1]),1000,-50,50);
143  hNsigmaTPCKaonDataTOFtag[iBin] = new TH1F(Form("hNsigmaTPCKaonDataTOFtag_p%0.f_%0.f",binlims[iBin]*10,binlims[iBin+1]*10),Form("%0.2f < %s < %0.2f GeV/#it{c};N_{#sigma}^{TPC}(K);Normalised entries",binlims[iBin],varname.Data(),binlims[iBin+1]),1000,-50,50);
144  hNsigmaTPCProtonDataV0tag[iBin] = new TH1F(Form("hNsigmaTPCProtonDataV0tag_p%0.f_%0.f",binlims[iBin]*10,binlims[iBin+1]*10),Form("%0.2f < %s < %0.2f GeV/#it{c};N_{#sigma}^{TPC}(p);Normalised entries",binlims[iBin],varname.Data(),binlims[iBin+1]),1000,-50,50);
145 
146  hNsigmaTOFPionDataV0tag[iBin] = new TH1F(Form("hNsigmaTOFPionDataV0tag_p%0.f_%0.f",binlims[iBin]*10,binlims[iBin+1]*10),Form("%0.2f < %s < %0.2f GeV/#it{c};N_{#sigma}^{TOF}(#pi);Normalised entries",binlims[iBin],varname.Data(),binlims[iBin+1]),1000,-50,50);
147  hNsigmaTOFKaonDataKinktag[iBin] = new TH1F(Form("hNsigmaTOFKaonDataKinktag_p%0.f_%0.f",binlims[iBin]*10,binlims[iBin+1]*10),Form("%0.2f < %s < %0.2f GeV/#it{c};N_{#sigma}^{TOF}(K);Normalised entries",binlims[iBin],varname.Data(),binlims[iBin+1]),1000,-50,50);
148  hNsigmaTOFKaonDataTPCtag[iBin] = new TH1F(Form("hNsigmaTOFKaonDataTPCtag_p%0.f_%0.f",binlims[iBin]*10,binlims[iBin+1]*10),Form("%0.2f < %s < %0.2f GeV/#it{c};N_{#sigma}^{TOF}(K);Normalised entries",binlims[iBin],varname.Data(),binlims[iBin+1]),1000,-50,50);
149  hNsigmaTOFProtonDataV0tag[iBin] = new TH1F(Form("hNsigmaTOFProtonDataV0tag_p%0.f_%0.f",binlims[iBin]*10,binlims[iBin+1]*10),Form("%0.2f < %s < %0.2f GeV/#it{c};N_{#sigma}^{TOF}(p);Normalised entries",binlims[iBin],varname.Data(),binlims[iBin+1]),1000,-50,50);
150 
151  SetTH1Style(hNsigmaTPCPionDataV0tag[iBin],kFullCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],kWhite,0.055,0.06);
152  SetTH1Style(hNsigmaTPCKaonDataKinktag[iBin],kFullCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],kWhite,0.055,0.06);
153  SetTH1Style(hNsigmaTPCKaonDataTOFtag[iBin],kFullCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],kWhite,0.055,0.06);
154  SetTH1Style(hNsigmaTPCProtonDataV0tag[iBin],kFullCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],kWhite,0.055,0.06);
155  SetTH1Style(hNsigmaTOFPionDataV0tag[iBin],kFullCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],kWhite,0.055,0.06);
156  SetTH1Style(hNsigmaTOFKaonDataKinktag[iBin],kFullCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],kWhite,0.055,0.06);
157  SetTH1Style(hNsigmaTOFKaonDataTPCtag[iBin],kFullCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],kWhite,0.055,0.06);
158  SetTH1Style(hNsigmaTOFProtonDataV0tag[iBin],kFullCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],kWhite,0.055,0.06);
159  }
160 
161  //********************************************************************************************************************************************//
162  //load MC inputs
163 
164  TFile* infileMC = TFile::Open(infileNameMC.Data());
165  if(!infileMC || !infileMC->IsOpen()) return 2;
166  TDirectoryFile* indirMC = (TDirectoryFile*)infileMC->Get(indirNameMC.Data());
167  if(!indirMC) return 3;
168  TList* listMC = (TList*)indirMC->Get(inlistNameMC.Data());
169  hNsigmaTPCPionVsPtMCTrue = (TH2F*)listMC->FindObject("fHistNsigmaTPCvsPt_Pion");
170  hNsigmaTPCKaonVsPtMCTrue = (TH2F*)listMC->FindObject("fHistNsigmaTPCvsPt_Kaon");
171  hNsigmaTPCProtonVsPtMCTrue = (TH2F*)listMC->FindObject("fHistNsigmaTPCvsPt_Proton");
172  hNsigmaTOFPionVsPtMCTrue = (TH2F*)listMC->FindObject("fHistNsigmaTOFvsPt_Pion");
173  hNsigmaTOFKaonVsPtMCTrue = (TH2F*)listMC->FindObject("fHistNsigmaTOFvsPt_Kaon");
174  hNsigmaTOFProtonVsPtMCTrue = (TH2F*)listMC->FindObject("fHistNsigmaTOFvsPt_Proton");
175  TTree* treePIDMC = (TTree*)indirMC->Get("fPIDtree");
176  if(!treePIDMC) return 4;
177  treePIDMC->SetName("treePIDMC");
178 
179  for(int iBin=0; iBin<nBins; iBin++) {
180  int ptbinmin = hNsigmaTPCPionVsPtMCTrue->GetXaxis()->FindBin(binlims[iBin]*1.0001);
181  int ptbinmax = hNsigmaTPCPionVsPtMCTrue->GetXaxis()->FindBin(binlims[iBin+1]*0.9999);
182 
183  hNsigmaTPCPionMCTrue[iBin] = (TH1F*)hNsigmaTPCPionVsPtMCTrue->ProjectionY(Form("hNsigmaTPCPionMCTrue_p%0.f_%0.f",binlims[iBin]*10,binlims[iBin+1]*10),ptbinmin,ptbinmax);
184  hNsigmaTPCKaonMCTrue[iBin] = (TH1F*)hNsigmaTPCKaonVsPtMCTrue->ProjectionY(Form("hNsigmaTPCKaonMCTrue_p%0.f_%0.f",binlims[iBin]*10,binlims[iBin+1]*10),ptbinmin,ptbinmax);
185  hNsigmaTPCProtonMCTrue[iBin] = (TH1F*)hNsigmaTPCProtonVsPtMCTrue->ProjectionY(Form("hNsigmaTPCProtonMCTrue_p%0.f_%0.f",binlims[iBin]*10,binlims[iBin+1]*10),ptbinmin,ptbinmax);
186 
187  hNsigmaTOFPionMCTrue[iBin] = (TH1F*)hNsigmaTOFPionVsPtMCTrue->ProjectionY(Form("hNsigmaTOFPionMCTrue_p%0.f_%0.f",binlims[iBin]*10,binlims[iBin+1]*10),ptbinmin,ptbinmax);
188  hNsigmaTOFKaonMCTrue[iBin] = (TH1F*)hNsigmaTOFKaonVsPtMCTrue->ProjectionY(Form("hNsigmaTOFKaonMCTrue_p%0.f_%0.f",binlims[iBin]*10,binlims[iBin+1]*10),ptbinmin,ptbinmax);
189  hNsigmaTOFProtonMCTrue[iBin] = (TH1F*)hNsigmaTOFProtonVsPtMCTrue->ProjectionY(Form("hNsigmaTOFProtonMCTrue_p%0.f_%0.f",binlims[iBin]*10,binlims[iBin+1]*10),ptbinmin,ptbinmax);
190 
191  SetTH1Style(hNsigmaTPCPionMCTrue[iBin],kFullCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],kWhite,0.055,0.06);
192  SetTH1Style(hNsigmaTPCKaonMCTrue[iBin],kFullCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],kWhite,0.055,0.06);
193  SetTH1Style(hNsigmaTPCProtonMCTrue[iBin],kFullCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],kWhite,0.055,0.06);
194  SetTH1Style(hNsigmaTOFPionMCTrue[iBin],kFullCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],kWhite,0.055,0.06);
195  SetTH1Style(hNsigmaTOFKaonMCTrue[iBin],kFullCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],kWhite,0.055,0.06);
196  SetTH1Style(hNsigmaTOFProtonMCTrue[iBin],kFullCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],kWhite,0.055,0.06);
197  }
198 
199  short pdgMC = -1;
200  unsigned short tagMC = 0;
201  short n_sigma_TPC_pi_MC = -999;
202  short n_sigma_TPC_K_MC = -999;
203  short n_sigma_TPC_p_MC = -999;
204  short n_sigma_TOF_pi_MC = -999;
205  short n_sigma_TOF_K_MC = -999;
206  short n_sigma_TOF_p_MC = -999;
207  unsigned short pT_MC = 0;
208  unsigned short pTPC_MC = 0;
209  unsigned short pTOF_MC = 0;
210 
211  treePIDMC->SetBranchAddress("PDGcode",&pdgMC);
212  treePIDMC->SetBranchAddress("tag",&tagMC);
213  treePIDMC->SetBranchAddress("n_sigma_TPC_pi",&n_sigma_TPC_pi_MC);
214  treePIDMC->SetBranchAddress("n_sigma_TPC_K",&n_sigma_TPC_K_MC);
215  treePIDMC->SetBranchAddress("n_sigma_TPC_p",&n_sigma_TPC_p_MC);
216  treePIDMC->SetBranchAddress("n_sigma_TOF_pi",&n_sigma_TOF_pi_MC);
217  treePIDMC->SetBranchAddress("n_sigma_TOF_K",&n_sigma_TOF_K_MC);
218  treePIDMC->SetBranchAddress("n_sigma_TOF_p",&n_sigma_TOF_p_MC);
219  treePIDMC->SetBranchAddress("pT",&pT_MC);
220  treePIDMC->SetBranchAddress("pTPC",&pTPC_MC);
221  treePIDMC->SetBranchAddress("pTOF",&pTOF_MC);
222 
223  cout << "\n********** Loop on MC tracks **********\n" << endl;
224 
225  for(int iEntry=0; iEntry<treePIDMC->GetEntriesFast(); iEntry++) {
226 
227  if(iEntry>maxEntries) break;
228 
229  if(iEntry%1000000==0 || iEntry==treePIDMC->GetEntriesFast()-1) cout << Form("MC Track %010d",iEntry) << endl;
230 
231  treePIDMC->GetEntry(iEntry);
232  int iBin = -1;
233  if(var4proj==kPt)
234  iBin = FindPtbin(static_cast<float>(pT_MC)/1000,binlims,nBins);
235  else if(var4proj==kP)
236  iBin = FindPtbin(static_cast<float>(pTPC_MC)/1000,binlims,nBins);
237  if(iBin<0 || iBin>=static_cast<int>(nBins)) continue;
238 
240  hNsigmaTPCPionMCV0tag[iBin][kAll]->Fill(static_cast<float>(n_sigma_TPC_pi_MC)/100);
241  hNsigmaTOFPionMCV0tag[iBin][kAll]->Fill(static_cast<float>(n_sigma_TOF_pi_MC)/100);
242  }
244  hNsigmaTPCKaonMCKinktag[iBin][kAll]->Fill(static_cast<float>(n_sigma_TPC_K_MC)/100);
245  hNsigmaTOFKaonMCKinktag[iBin][kAll]->Fill(static_cast<float>(n_sigma_TOF_K_MC)/100);
246  }
248  hNsigmaTPCKaonMCTOFtag[iBin][kAll]->Fill(static_cast<float>(n_sigma_TPC_K_MC)/100);
249  }
251  hNsigmaTOFKaonMCTPCtag[iBin][kAll]->Fill(static_cast<float>(n_sigma_TOF_K_MC)/100);
252  }
254  hNsigmaTPCProtonMCV0tag[iBin][kAll]->Fill(static_cast<float>(n_sigma_TPC_p_MC)/100);
255  hNsigmaTOFProtonMCV0tag[iBin][kAll]->Fill(static_cast<float>(n_sigma_TOF_p_MC)/100);
256  }
257 
258  int iHisto = GetHistoParticleIndex(pdgMC);
259  if(iHisto>=kElectron && iHisto<kAll) {
260  if((tagMC&AliAnalysisTaskSEHFSystPID::kIsPionFromK0s || tagMC&AliAnalysisTaskSEHFSystPID::kIsPionFromL)) {
261  hNsigmaTPCPionMCV0tag[iBin][iHisto]->Fill(static_cast<float>(n_sigma_TPC_pi_MC)/100);
262  hNsigmaTOFPionMCV0tag[iBin][iHisto]->Fill(static_cast<float>(n_sigma_TOF_pi_MC)/100);
263  }
264  if(tagMC&AliAnalysisTaskSEHFSystPID::kIsKaonFromKinks) {
265  hNsigmaTPCKaonMCKinktag[iBin][iHisto]->Fill(static_cast<float>(n_sigma_TPC_K_MC)/100);
266  hNsigmaTOFKaonMCKinktag[iBin][iHisto]->Fill(static_cast<float>(n_sigma_TOF_K_MC)/100);
267  }
268  if(tagMC&AliAnalysisTaskSEHFSystPID::kIsKaonFromTOF) {
269  hNsigmaTPCKaonMCTOFtag[iBin][iHisto]->Fill(static_cast<float>(n_sigma_TPC_K_MC)/100);
270  }
271  if(tagMC&AliAnalysisTaskSEHFSystPID::kIsKaonFromTPC) {
272  hNsigmaTOFKaonMCTPCtag[iBin][iHisto]->Fill(static_cast<float>(n_sigma_TOF_K_MC)/100);
273  }
274  if(tagMC&AliAnalysisTaskSEHFSystPID::kIsProtonFromL) {
275  hNsigmaTPCProtonMCV0tag[iBin][iHisto]->Fill(static_cast<float>(n_sigma_TPC_p_MC)/100);
276  hNsigmaTOFProtonMCV0tag[iBin][iHisto]->Fill(static_cast<float>(n_sigma_TOF_p_MC)/100);
277  }
278  }
279  }
280 
281  //********************************************************************************************************************************************//
282  //load data inputs
283 
284  TFile* infileData = TFile::Open(infileNameData.Data());
285  if(!infileData || !infileData->IsOpen()) return 5;
286  TDirectoryFile* indirData = (TDirectoryFile*)infileData->Get(indirNameData.Data());
287  if(!indirData) return 6;
288  TList* listData = (TList*)indirData->Get(inlistNameData.Data());
289  TTree* treePIDData = (TTree*)indirData->Get("fPIDtree");
290  if(!treePIDData) return 7;
291  treePIDData->SetName("treePIDData");
292 
293  unsigned short tagData = 0;
294  short n_sigma_TPC_pi_Data = -999;
295  short n_sigma_TPC_K_Data = -999;
296  short n_sigma_TPC_p_Data = -999;
297  short n_sigma_TOF_pi_Data = -999;
298  short n_sigma_TOF_K_Data = -999;
299  short n_sigma_TOF_p_Data = -999;
300  unsigned short pT_Data = 0;
301  unsigned short pTPC_Data = 0;
302  unsigned short pTOF_Data = 0;
303  short eta_Data = 9;
304 
305  treePIDData->SetBranchAddress("tag",&tagData);
306  treePIDData->SetBranchAddress("n_sigma_TPC_pi",&n_sigma_TPC_pi_Data);
307  treePIDData->SetBranchAddress("n_sigma_TPC_K",&n_sigma_TPC_K_Data);
308  treePIDData->SetBranchAddress("n_sigma_TPC_p",&n_sigma_TPC_p_Data);
309  treePIDData->SetBranchAddress("n_sigma_TOF_pi",&n_sigma_TOF_pi_Data);
310  treePIDData->SetBranchAddress("n_sigma_TOF_K",&n_sigma_TOF_K_Data);
311  treePIDData->SetBranchAddress("n_sigma_TOF_p",&n_sigma_TOF_p_Data);
312  treePIDData->SetBranchAddress("pT",&pT_Data);
313  treePIDData->SetBranchAddress("pTPC",&pTPC_Data);
314  treePIDData->SetBranchAddress("pTOF",&pTOF_Data);
315  treePIDData->SetBranchAddress("eta",&eta_Data);
316 
317  cout << "\n********** Loop on data tracks **********\n" << endl;
318 
319  TH2F* hNsigmaTPCKaonTPCtagged = new TH2F("hNsigmaTPCKaonTPCtagged",Form(";%s (GeV/#it{c});N_{#sigma}(K)",varname.Data()),100,0.,10.,1000,-50,50);
320  hNsigmaTPCKaonTPCtagged->SetMarkerColor(kBlue);
321  TH2F* hNsigmaTPCKaon = new TH2F("hNsigmaTPCKaon",Form(";%s (GeV/#it{c});N_{#sigma}^{TPC}(K)",varname.Data()),100,0.,10.,1000,-50,50);
322  hNsigmaTPCKaon->SetMarkerColor(kBlack);
323  TH2F* hNsigmaTOFKaonTOFtagged = new TH2F("hNsigmaTOFKaonTOFtagged",Form(";%s (GeV/#it{c});N_{#sigma}(K)",varname.Data()),100,0.,10.,1000,-50,50);
324  hNsigmaTOFKaonTOFtagged->SetMarkerColor(kBlue);
325  TH2F* hNsigmaTOFKaon = new TH2F("hNsigmaTOFKaon",Form(";%s (GeV/#it{c});N_{#sigma}^{TOF}(K)",varname.Data()),100,0.,10.,1000,-50,50);
326  hNsigmaTOFKaon->SetMarkerColor(kBlack);
327 
328  TH2F* hNsigmaTPCPionDataV0tagVsEta = new TH2F("hNsigmaTPCPionDataV0tagVsEta",Form("#pi V0 tag %0.2f < %s < %0.2f GeV/#it{c};#eta;N_{#sigma}^{TPC}(#pi)",binlims[0],varname.Data(),binlims[nBins]),100,-1,1,100,-5,5);
329  TH2F* hNsigmaTPCKaonDataKinktagVsEta = new TH2F("hNsigmaTPCKaonDataKinktagVsEta",Form("K kinks V0 tag %0.2f < %s < %0.2f GeV/#it{c};#eta;N_{#sigma}^{TPC}(K)",binlims[0],varname.Data(),binlims[nBins]),100,-1,1,100,-5,5);
330  TH2F* hNsigmaTPCKaonDataTOFtagVsEta = new TH2F("hNsigmaTPCKaonDataTOFtagVsEta",Form("K TOF tag %0.2f < %s < %0.2f GeV/#it{c};#eta;N_{#sigma}^{TPC}(K)",binlims[0],varname.Data(),binlims[nBins]),100,-1,1,100,-5,5);
331  TH2F* hNsigmaTPCProtonDataV0tagVsEta = new TH2F("hNsigmaTPCProtonDataV0tagVsEta",Form("p V0 tag %0.2f < %s < %0.2f GeV/#it{c};#eta;N_{#sigma}^{TPC}(p)",binlims[0],varname.Data(),binlims[nBins]),100,-1,1,100,-5,5);
332 
333  TH2F* hNsigmaTOFPionDataV0tagVsEta = new TH2F("hNsigmaTOFPionDataV0tagVsEta",Form("#pi V0 tag %0.2f < %s < %0.2f GeV/#it{c};#eta;N_{#sigma}^{TOF}(#pi)",binlims[0],varname.Data(),binlims[nBins]),100,-1,1,100,-5,5);
334  TH2F* hNsigmaTOFKaonDataKinktagVsEta = new TH2F("hNsigmaTOFKaonDataKinktagVsEta",Form("K kinks tag %0.2f < %s < %0.2f GeV/#it{c};#eta;N_{#sigma}^{TOF}(K)",binlims[0],varname.Data(),binlims[nBins]),100,-1,1,100,-5,5);
335  TH2F* hNsigmaTOFKaonDataTPCtagVsEta = new TH2F("hNsigmaTOFKaonDataTPCtagVsEta",Form("K TPC tag %0.2f < %s < %0.2f GeV/#it{c};#eta;N_{#sigma}^{TOF}(K)",binlims[0],varname.Data(),binlims[nBins]),100,-1,1,100,-5,5);
336  TH2F* hNsigmaTOFProtonDataV0tagVsEta = new TH2F("hNsigmaTOFProtonDataV0tagVsEta",Form("p V0 tag %0.2f < %s < %0.2f GeV/#it{c};#eta;N_{#sigma}^{TOF}(p)",binlims[0],varname.Data(),binlims[nBins]),100,-1,1,100,-5,5);
337 
338  for(int iEntry=0; iEntry<treePIDData->GetEntriesFast(); iEntry++) {
339 
340  if(iEntry>maxEntries) break;
341 
342  if(iEntry%1000000==0 || iEntry==treePIDData->GetEntriesFast()-1) cout << Form("Data Track %010d",iEntry) << endl;
343 
344  treePIDData->GetEntry(iEntry);
345  float etaf = static_cast<float>(eta_Data)/1000;
346  if(TMath::Abs(etaf)<absetamin || TMath::Abs(etaf)>absetamax) continue;
347  int iBin = -1;
348  float xvar = -1.;
349  if(var4proj==kPt) {
350  xvar = static_cast<float>(pT_Data)/1000;
351  iBin = FindPtbin(xvar,binlims,nBins);
352  }
353  else if(var4proj==kP) {
354  xvar = static_cast<float>(pTPC_Data)/1000;
355  iBin = FindPtbin(xvar,binlims,nBins);
356  }
357  if(iBin<0 || iBin>=static_cast<int>(nBins)) continue;
358 
359  hNsigmaTPCKaon->Fill(xvar,static_cast<float>(n_sigma_TPC_K_Data)/100);
360  hNsigmaTOFKaon->Fill(xvar,static_cast<float>(n_sigma_TOF_K_Data)/100);
362  hNsigmaTPCPionDataV0tag[iBin]->Fill(static_cast<float>(n_sigma_TPC_pi_Data)/100);
363  hNsigmaTOFPionDataV0tag[iBin]->Fill(static_cast<float>(n_sigma_TOF_pi_Data)/100);
364  hNsigmaTPCPionDataV0tagVsEta->Fill(etaf,static_cast<float>(n_sigma_TPC_pi_Data)/100);
365  hNsigmaTOFPionDataV0tagVsEta->Fill(etaf,static_cast<float>(n_sigma_TOF_pi_Data)/100);
366  }
368  hNsigmaTPCKaonDataKinktag[iBin]->Fill(static_cast<float>(n_sigma_TPC_K_Data)/100);
369  hNsigmaTOFKaonDataKinktag[iBin]->Fill(static_cast<float>(n_sigma_TOF_K_Data)/100);
370  hNsigmaTPCKaonDataKinktagVsEta->Fill(etaf,static_cast<float>(n_sigma_TPC_K_Data)/100);
371  hNsigmaTOFKaonDataKinktagVsEta->Fill(etaf,static_cast<float>(n_sigma_TOF_K_Data)/100);
372  }
374  hNsigmaTPCKaonDataTOFtag[iBin]->Fill(static_cast<float>(n_sigma_TPC_K_Data)/100);
375  hNsigmaTOFKaonTOFtagged->Fill(xvar,static_cast<float>(n_sigma_TOF_K_Data)/100);
376  hNsigmaTPCKaonDataTOFtagVsEta->Fill(etaf,static_cast<float>(n_sigma_TPC_K_Data)/100);
377  }
379  hNsigmaTOFKaonDataTPCtag[iBin]->Fill(static_cast<float>(n_sigma_TOF_K_Data)/100);
380  hNsigmaTPCKaonTPCtagged->Fill(xvar,static_cast<float>(n_sigma_TPC_K_Data)/100);
381  hNsigmaTOFKaonDataTPCtagVsEta->Fill(etaf,static_cast<float>(n_sigma_TOF_K_Data)/100);
382  }
384  hNsigmaTPCProtonDataV0tag[iBin]->Fill(static_cast<float>(n_sigma_TPC_p_Data)/100);
385  hNsigmaTOFProtonDataV0tag[iBin]->Fill(static_cast<float>(n_sigma_TOF_p_Data)/100);
386  hNsigmaTPCProtonDataV0tagVsEta->Fill(etaf,static_cast<float>(n_sigma_TPC_p_Data)/100);
387  hNsigmaTOFProtonDataV0tagVsEta->Fill(etaf,static_cast<float>(n_sigma_TOF_p_Data)/100);
388  }
389  }
390  cout << "\n********************\n" << endl;
391 
392  //********************************************************************************************************************************************//
393  //check QA plots
394  PlotQAhistos(listMC,listData);
395 
396  TLatex* latAll = new TLatex();
397  latAll->SetNDC();
398  latAll->SetTextFont(42);
399  latAll->SetTextColor(kBlack);
400  latAll->SetTextSize(0.045);
401  TLatex* latTag = new TLatex();
402  latTag->SetNDC();
403  latTag->SetTextFont(42);
404  latTag->SetTextColor(kBlue);
405  latTag->SetTextSize(0.045);
406 
407  TCanvas* cNsigmaTag = new TCanvas("cNsigmaTag","",1920,1080);
408  cNsigmaTag->Divide(2,1);
409  cNsigmaTag->cd(1);
410  hNsigmaTPCKaon->SetMarkerStyle(kFullCircle);
411  hNsigmaTPCKaonTPCtagged->SetMarkerStyle(kFullCircle);
412  hNsigmaTPCKaon->SetMarkerSize(0.5);
413  hNsigmaTPCKaonTPCtagged->SetMarkerSize(0.5);
414  hNsigmaTPCKaon->DrawCopy("");
415  hNsigmaTPCKaonTPCtagged->DrawCopy("same");
416  latAll->DrawLatex(0.65,0.25,"All tags");
417  latTag->DrawLatex(0.65,0.2,"TPC tag");
418  cNsigmaTag->cd(2);
419  hNsigmaTOFKaon->SetMarkerStyle(kFullCircle);
420  hNsigmaTOFKaonTOFtagged->SetMarkerStyle(kFullCircle);
421  hNsigmaTOFKaon->SetMarkerSize(0.5);
422  hNsigmaTOFKaonTOFtagged->SetMarkerSize(0.5);
423  hNsigmaTOFKaon->DrawCopy("");
424  hNsigmaTOFKaonTOFtagged->DrawCopy("same");
425  latAll->DrawLatex(0.65,0.25,"All tags");
426  latTag->DrawLatex(0.65,0.2,"TOF tag");
427 
428  cNsigmaTag->SaveAs(Form("%s/TPC_TOF_tag.pdf",outputdirName.Data()));
429  cNsigmaTag->SaveAs(Form("%s/TPC_TOF_tag.png",outputdirName.Data()));
430 
431  TProfile* hProfileNsigmaTPCPionDataV0tagVsEta = hNsigmaTPCPionDataV0tagVsEta->ProfileX("hProfileNsigmaTPCPionDataV0tagVsEta");
432  hProfileNsigmaTPCPionDataV0tagVsEta->SetLineColor(kRed);
433  hProfileNsigmaTPCPionDataV0tagVsEta->SetLineWidth(2);
434  TProfile* hProfileNsigmaTPCProtonDataV0tagVsEta = hNsigmaTPCProtonDataV0tagVsEta->ProfileX("hProfileNsigmaTPCProtonDataV0tagVsEta");
435  hProfileNsigmaTPCProtonDataV0tagVsEta->SetLineColor(kRed);
436  hProfileNsigmaTPCProtonDataV0tagVsEta->SetLineWidth(2);
437  TProfile* hProfileNsigmaTPCKaonDataTOFtagVsEta = hNsigmaTPCKaonDataTOFtagVsEta->ProfileX("hProfileNsigmaTPCKaonDataTOFtagVsEta");
438  hProfileNsigmaTPCKaonDataTOFtagVsEta->SetLineColor(kRed);
439  hProfileNsigmaTPCKaonDataTOFtagVsEta->SetLineWidth(2);
440  TProfile* hProfileNsigmaTPCKaonDataKinktagVsEta = hNsigmaTPCKaonDataKinktagVsEta->ProfileX("hProfileNsigmaTPCKaonDataKinktagVsEta");
441  hProfileNsigmaTPCKaonDataKinktagVsEta->SetLineColor(kRed);
442  hProfileNsigmaTPCKaonDataKinktagVsEta->SetLineWidth(2);
443 
444  TProfile* hProfileNsigmaTOFPionDataV0tagVsEta = hNsigmaTOFPionDataV0tagVsEta->ProfileX("hProfileNsigmaTOFPionDataV0tagVsEta");
445  hProfileNsigmaTOFPionDataV0tagVsEta->SetLineColor(kRed);
446  hProfileNsigmaTOFPionDataV0tagVsEta->SetLineWidth(2);
447  TProfile* hProfileNsigmaTOFProtonDataV0tagVsEta = hNsigmaTOFProtonDataV0tagVsEta->ProfileX("hProfileNsigmaTOFProtonDataV0tagVsEta");
448  hProfileNsigmaTOFProtonDataV0tagVsEta->SetLineColor(kRed);
449  hProfileNsigmaTOFProtonDataV0tagVsEta->SetLineWidth(2);
450  TProfile* hProfileNsigmaTOFKaonDataTPCtagVsEta = hNsigmaTOFKaonDataTPCtagVsEta->ProfileX("hProfileNsigmaTOFKaonDataTPCtagVsEta");
451  hProfileNsigmaTOFKaonDataTPCtagVsEta->SetLineColor(kRed);
452  hProfileNsigmaTOFKaonDataTPCtagVsEta->SetLineWidth(2);
453  TProfile* hProfileNsigmaTOFKaonDataKinktagVsEta = hNsigmaTOFKaonDataKinktagVsEta->ProfileX("hProfileNsigmaTOFKaonDataKinktagVsEta");
454  hProfileNsigmaTOFKaonDataKinktagVsEta->SetLineColor(kRed);
455  hProfileNsigmaTOFKaonDataKinktagVsEta->SetLineWidth(2);
456 
457  TCanvas* cNsigmaTPCVsEta = new TCanvas("cNsigmaTPCVsEta","",1920,1080);
458  cNsigmaTPCVsEta->Divide(2,2);
459  cNsigmaTPCVsEta->cd(1)->SetLogz();
460  hNsigmaTPCPionDataV0tagVsEta->Draw("colz");
461  hProfileNsigmaTPCPionDataV0tagVsEta->Draw("same");
462  cNsigmaTPCVsEta->cd(2)->SetLogz();
463  hNsigmaTPCProtonDataV0tagVsEta->Draw("colz");
464  hProfileNsigmaTPCProtonDataV0tagVsEta->Draw("same");
465  cNsigmaTPCVsEta->cd(3)->SetLogz();
466  hNsigmaTPCKaonDataTOFtagVsEta->Draw("colz");
467  hProfileNsigmaTPCKaonDataTOFtagVsEta->Draw("same");
468  cNsigmaTPCVsEta->cd(4)->SetLogz();
469  hNsigmaTPCKaonDataKinktagVsEta->Draw("colz");
470  hProfileNsigmaTPCKaonDataKinktagVsEta->Draw("same");
471 
472  TCanvas* cNsigmaTOFVsEta = new TCanvas("cNsigmaTOFVsEta","",1920,1080);
473  cNsigmaTOFVsEta->Divide(2,2);
474  cNsigmaTOFVsEta->cd(1)->SetLogz();
475  hNsigmaTOFPionDataV0tagVsEta->Draw("colz");
476  hProfileNsigmaTOFPionDataV0tagVsEta->Draw("same");
477  cNsigmaTOFVsEta->cd(2)->SetLogz();
478  hNsigmaTOFProtonDataV0tagVsEta->Draw("colz");
479  hProfileNsigmaTOFProtonDataV0tagVsEta->Draw("same");
480  cNsigmaTOFVsEta->cd(3)->SetLogz();
481  hNsigmaTOFKaonDataTPCtagVsEta->Draw("colz");
482  hProfileNsigmaTOFKaonDataTPCtagVsEta->Draw("same");
483  cNsigmaTOFVsEta->cd(4)->SetLogz();
484  hNsigmaTOFKaonDataKinktagVsEta->Draw("colz");
485  hProfileNsigmaTOFKaonDataKinktagVsEta->Draw("same");
486 
487  cNsigmaTPCVsEta->SaveAs(Form("%s/NsigmaTPCvsEta.pdf",outputdirName.Data()));
488  cNsigmaTOFVsEta->SaveAs(Form("%s/NsigmaTOFvsEta.pdf",outputdirName.Data()));
489 
490  //********************************************************************************************************************************************//
491  //compute Fraction and contamination in MC
492  double intNsigmaTPCPionMCV0tag[nBins][nPDGcodes];
493  double intNsigmaTPCKaonMCKinktag[nBins][nPDGcodes];
494  double intNsigmaTPCKaonMCTOFtag[nBins][nPDGcodes];
495  double intNsigmaTPCProtonMCV0tag[nBins][nPDGcodes];
496  double intNsigmaTOFPionMCV0tag[nBins][nPDGcodes];
497  double intNsigmaTOFKaonMCKinktag[nBins][nPDGcodes];
498  double intNsigmaTOFKaonMCTPCtag[nBins][nPDGcodes];
499  double intNsigmaTOFProtonMCV0tag[nBins][nPDGcodes];
500 
501  double intNsigmaTPCPionDataV0tag[nBins];
502  double intNsigmaTPCKaonDataKinktag[nBins];
503  double intNsigmaTPCKaonDataTOFtag[nBins];
504  double intNsigmaTPCProtonDataV0tag[nBins];
505  double intNsigmaTOFPionDataV0tag[nBins];
506  double intNsigmaTOFKaonDataKinktag[nBins];
507  double intNsigmaTOFKaonDataTPCtag[nBins];
508  double intNsigmaTOFProtonDataV0tag[nBins];
509 
510  for(int iBin=0; iBin<nBins; iBin++) {
511  for(int iPart=kElectron; iPart<=kAll; iPart++) {
512  intNsigmaTPCPionMCV0tag[iBin][iPart] = hNsigmaTPCPionMCV0tag[iBin][iPart]->Integral() / hNsigmaTPCPionMCV0tag[iBin][iPart]->GetBinWidth(1);
513  intNsigmaTPCKaonMCKinktag[iBin][iPart] = hNsigmaTPCKaonMCKinktag[iBin][iPart]->Integral() / hNsigmaTPCKaonMCKinktag[iBin][iPart]->GetBinWidth(1);
514  intNsigmaTPCKaonMCTOFtag[iBin][iPart] = hNsigmaTPCKaonMCTOFtag[iBin][iPart]->Integral() / hNsigmaTPCKaonMCTOFtag[iBin][iPart]->GetBinWidth(1);
515  intNsigmaTPCProtonMCV0tag[iBin][iPart] = hNsigmaTPCProtonMCV0tag[iBin][iPart]->Integral() / hNsigmaTPCProtonMCV0tag[iBin][iPart]->GetBinWidth(1);
516  intNsigmaTOFPionMCV0tag[iBin][iPart] = hNsigmaTOFPionMCV0tag[iBin][iPart]->Integral() / hNsigmaTOFPionMCV0tag[iBin][iPart]->GetBinWidth(1);
517  intNsigmaTOFKaonMCKinktag[iBin][iPart] = hNsigmaTOFKaonMCKinktag[iBin][iPart]->Integral() / hNsigmaTOFKaonMCKinktag[iBin][iPart]->GetBinWidth(1);
518  intNsigmaTOFKaonMCTPCtag[iBin][iPart] = hNsigmaTOFKaonMCTPCtag[iBin][iPart]->Integral() / hNsigmaTOFKaonMCTPCtag[iBin][iPart]->GetBinWidth(1);
519  intNsigmaTOFProtonMCV0tag[iBin][iPart] = hNsigmaTOFProtonMCV0tag[iBin][iPart]->Integral() / hNsigmaTOFProtonMCV0tag[iBin][iPart]->GetBinWidth(1);
520  }
521 
522  intNsigmaTPCPionDataV0tag[iBin] = hNsigmaTPCPionDataV0tag[iBin]->Integral() / hNsigmaTPCPionDataV0tag[iBin]->GetBinWidth(1);
523  intNsigmaTPCKaonDataKinktag[iBin] = hNsigmaTPCKaonDataKinktag[iBin]->Integral() / hNsigmaTPCKaonDataKinktag[iBin]->GetBinWidth(1);
524  intNsigmaTPCKaonDataTOFtag[iBin] = hNsigmaTPCKaonDataTOFtag[iBin]->Integral() / hNsigmaTPCKaonDataTOFtag[iBin]->GetBinWidth(1);
525  intNsigmaTPCProtonDataV0tag[iBin] = hNsigmaTPCProtonDataV0tag[iBin]->Integral() / hNsigmaTPCProtonDataV0tag[iBin]->GetBinWidth(1);
526  intNsigmaTOFPionDataV0tag[iBin] = hNsigmaTOFPionDataV0tag[iBin]->Integral() / hNsigmaTOFPionDataV0tag[iBin]->GetBinWidth(1);
527  intNsigmaTOFKaonDataKinktag[iBin] = hNsigmaTOFKaonDataKinktag[iBin]->Integral() / hNsigmaTOFKaonDataKinktag[iBin]->GetBinWidth(1);
528  intNsigmaTOFKaonDataTPCtag[iBin] = hNsigmaTOFKaonDataTPCtag[iBin]->Integral() / hNsigmaTOFKaonDataTPCtag[iBin]->GetBinWidth(1);
529  intNsigmaTOFProtonDataV0tag[iBin] = hNsigmaTOFProtonDataV0tag[iBin]->Integral() / hNsigmaTOFProtonDataV0tag[iBin]->GetBinWidth(1);
530  }
531 
532  TH1F *hFractionTPCPionMCV0tag[nPDGcodes-1], *hFractionTPCKaonMCKinktag[nPDGcodes-1], *hFractionTPCKaonMCTOFtag[nPDGcodes-1], *hFractionTPCProtonMCV0tag[nPDGcodes-1];
533  TH1F *hFractionTOFPionMCV0tag[nPDGcodes-1], *hFractionTOFKaonMCKinktag[nPDGcodes-1], *hFractionTOFKaonMCTPCtag[nPDGcodes-1], *hFractionTOFProtonMCV0tag[nPDGcodes-1];
534 
535  for(int iPart=kElectron; iPart<=kProton; iPart++) {
536  hFractionTPCPionMCV0tag[iPart] = new TH1F(Form("hFractionTPCPionMCV0tag_%s",pdgnames[iPart].Data()),Form(";%s (GeV/#it{c});Contamination",varname.Data()),nBins,binlims);
537  hFractionTOFPionMCV0tag[iPart] = new TH1F(Form("hFractionTOFPionMCV0tag_%s",pdgnames[iPart].Data()),Form(";%s (GeV/#it{c});Contamination",varname.Data()),nBins,binlims);
538  hFractionTPCKaonMCKinktag[iPart] = new TH1F(Form("hFractionTPCKaonMCKinktag_%s",pdgnames[iPart].Data()),Form(";%s (GeV/#it{c});Contamination",varname.Data()),nBins,binlims);
539  hFractionTPCKaonMCTOFtag[iPart] = new TH1F(Form("hFractionTPCKaonMCTOFtag_%s",pdgnames[iPart].Data()),Form(";%s (GeV/#it{c});Contamination",varname.Data()),nBins,binlims);
540  hFractionTOFKaonMCKinktag[iPart] = new TH1F(Form("hFractionTOFKaonMCKinktag_%s",pdgnames[iPart].Data()),Form(";%s (GeV/#it{c});Contamination",varname.Data()),nBins,binlims);
541  hFractionTOFKaonMCTPCtag[iPart] = new TH1F(Form("hFractionTOFKaonMCTPCtag_%s",pdgnames[iPart].Data()),Form(";%s (GeV/#it{c});Contamination",varname.Data()),nBins,binlims);
542  hFractionTPCProtonMCV0tag[iPart] = new TH1F(Form("hFractionTPCProtonMCV0tag_%s",pdgnames[iPart].Data()),Form(";%s (GeV/#it{c});Contamination",varname.Data()),nBins,binlims);
543  hFractionTOFProtonMCV0tag[iPart] = new TH1F(Form("hFractionTOFProtonMCV0tag_%s",pdgnames[iPart].Data()),Form(";%s (GeV/#it{c});Contamination",varname.Data()),nBins,binlims);
544 
545  SetTH1Style(hFractionTPCPionMCV0tag[iPart],kFullCircle,pdgcolors[iPart],1.,2,pdgcolors[iPart],kWhite,0.045,0.05);
546  SetTH1Style(hFractionTOFPionMCV0tag[iPart],kFullCircle,pdgcolors[iPart],1.,2,pdgcolors[iPart],kWhite,0.045,0.05);
547  SetTH1Style(hFractionTPCKaonMCKinktag[iPart],kFullCircle,pdgcolors[iPart],1.,2,pdgcolors[iPart],kWhite,0.045,0.05);
548  SetTH1Style(hFractionTPCKaonMCTOFtag[iPart],kFullCircle,pdgcolors[iPart],1.,2,pdgcolors[iPart],kWhite,0.045,0.05);
549  SetTH1Style(hFractionTOFKaonMCKinktag[iPart],kFullCircle,pdgcolors[iPart],1.,2,pdgcolors[iPart],kWhite,0.045,0.05);
550  SetTH1Style(hFractionTOFKaonMCTPCtag[iPart],kFullCircle,pdgcolors[iPart],1.,2,pdgcolors[iPart],kWhite,0.045,0.05);
551  SetTH1Style(hFractionTPCProtonMCV0tag[iPart],kFullCircle,pdgcolors[iPart],1.,2,pdgcolors[iPart],kWhite,0.045,0.05);
552  SetTH1Style(hFractionTOFProtonMCV0tag[iPart],kFullCircle,pdgcolors[iPart],1.,2,pdgcolors[iPart],kWhite,0.045,0.05);
553  }
554 
555  for(int iBin=0; iBin<nBins; iBin++) {
556  double eff=-1, unc=-1;
557  for(int iPart=kElectron; iPart<=kProton; iPart++) {
558  ComputeEfficiency(intNsigmaTPCPionMCV0tag[iBin][iPart],intNsigmaTPCPionMCV0tag[iBin][kAll],eff,unc);
559  hFractionTPCPionMCV0tag[iPart]->SetBinContent(iBin+1,eff);
560  hFractionTPCPionMCV0tag[iPart]->SetBinError(iBin+1,unc);
561 
562  ComputeEfficiency(intNsigmaTOFPionMCV0tag[iBin][iPart],intNsigmaTOFPionMCV0tag[iBin][kAll],eff,unc);
563  hFractionTOFPionMCV0tag[iPart]->SetBinContent(iBin+1,eff);
564  hFractionTOFPionMCV0tag[iPart]->SetBinError(iBin+1,unc);
565 
566  ComputeEfficiency(intNsigmaTPCKaonMCKinktag[iBin][iPart],intNsigmaTPCKaonMCKinktag[iBin][kAll],eff,unc);
567  hFractionTPCKaonMCKinktag[iPart]->SetBinContent(iBin+1,eff);
568  hFractionTPCKaonMCKinktag[iPart]->SetBinError(iBin+1,unc);
569 
570  ComputeEfficiency(intNsigmaTPCKaonMCTOFtag[iBin][iPart],intNsigmaTPCKaonMCTOFtag[iBin][kAll],eff,unc);
571  hFractionTPCKaonMCTOFtag[iPart]->SetBinContent(iBin+1,eff);
572  hFractionTPCKaonMCTOFtag[iPart]->SetBinError(iBin+1,unc);
573 
574  ComputeEfficiency(intNsigmaTOFKaonMCKinktag[iBin][iPart],intNsigmaTOFKaonMCKinktag[iBin][kAll],eff,unc);
575  hFractionTOFKaonMCKinktag[iPart]->SetBinContent(iBin+1,eff);
576  hFractionTOFKaonMCKinktag[iPart]->SetBinError(iBin+1,unc);
577 
578  ComputeEfficiency(intNsigmaTOFKaonMCTPCtag[iBin][iPart],intNsigmaTOFKaonMCTPCtag[iBin][kAll],eff,unc);
579  hFractionTOFKaonMCTPCtag[iPart]->SetBinContent(iBin+1,eff);
580  hFractionTOFKaonMCTPCtag[iPart]->SetBinError(iBin+1,unc);
581 
582  ComputeEfficiency(intNsigmaTPCProtonMCV0tag[iBin][iPart],intNsigmaTPCProtonMCV0tag[iBin][kAll],eff,unc);
583  hFractionTPCProtonMCV0tag[iPart]->SetBinContent(iBin+1,eff);
584  hFractionTPCProtonMCV0tag[iPart]->SetBinError(iBin+1,unc);
585 
586  ComputeEfficiency(intNsigmaTOFProtonMCV0tag[iBin][iPart],intNsigmaTOFProtonMCV0tag[iBin][kAll],eff,unc);
587  hFractionTOFProtonMCV0tag[iPart]->SetBinContent(iBin+1,eff);
588  hFractionTOFProtonMCV0tag[iPart]->SetBinError(iBin+1,unc);
589  }
590  }
591 
592  TLegend* legFracMC = new TLegend(0.2,0.4,0.45,0.7);
593  legFracMC->SetTextSize(0.05);
594  for(int iPart=kElectron; iPart<=kProton; iPart++) {
595  legFracMC->AddEntry(hFractionTOFProtonMCV0tag[iPart],pdgnames[iPart].Data(),"lpe");
596  }
597 
598  TCanvas* cFractionTPCMC = new TCanvas("cFractionTPCMC","cFractionTPCMC",1920,1080);
599  cFractionTPCMC->Divide(2,2);
600  cFractionTPCMC->cd(1)->DrawFrame(binlims[0],1.e-5,binlims[nBins],10.,Form("TPC #pi from K_{s}^{0};%s (GeV/#it{c});Purity / Contamination",varname.Data()));
601  cFractionTPCMC->cd(1)->SetLogy();
602  cFractionTPCMC->cd(1)->SetLogx();
603  for(int iPart=kElectron; iPart<=kProton; iPart++) hFractionTPCPionMCV0tag[iPart]->Draw("same");
604  legFracMC->Draw("same");
605 
606  cFractionTPCMC->cd(2)->DrawFrame(binlims[0],1.e-5,binlims[nBins],10.,Form("TPC K from kinks;%s (GeV/#it{c});Purity / Contamination",varname.Data()));
607  cFractionTPCMC->cd(2)->SetLogy();
608  cFractionTPCMC->cd(2)->SetLogx();
609  for(int iPart=kElectron; iPart<=kProton; iPart++) hFractionTPCKaonMCKinktag[iPart]->Draw("same");
610 
611  cFractionTPCMC->cd(3)->DrawFrame(binlims[0],1.e-5,binlims[nBins],10.,Form("TPC K TOF tagged;%s (GeV/#it{c});Purity / Contamination",varname.Data()));
612  cFractionTPCMC->cd(3)->SetLogy();
613  cFractionTPCMC->cd(3)->SetLogx();
614  for(int iPart=kElectron; iPart<=kProton; iPart++) hFractionTPCKaonMCTOFtag[iPart]->Draw("same");
615 
616  cFractionTPCMC->cd(4)->DrawFrame(binlims[0],1.e-5,binlims[nBins],10.,Form("TPC p from #Lambda;%s (GeV/#it{c});Purity / Contamination",varname.Data()));
617  cFractionTPCMC->cd(4)->SetLogy();
618  cFractionTPCMC->cd(4)->SetLogx();
619  for(int iPart=kElectron; iPart<=kProton; iPart++) hFractionTPCProtonMCV0tag[iPart]->Draw("same");
620 
621  TCanvas* cFractionTOFMC = new TCanvas("cFractionTOFMC","cFractionTOFMC",1920,1080);
622  cFractionTOFMC->Divide(2,2);
623  cFractionTOFMC->cd(1)->DrawFrame(binlims[0],1.e-5,binlims[nBins],10.,Form("TOF #pi from K_{s}^{0};%s (GeV/#it{c});Purity / Contamination",varname.Data()));
624  cFractionTOFMC->cd(1)->SetLogy();
625  cFractionTOFMC->cd(1)->SetLogx();
626  for(int iPart=kElectron; iPart<=kProton; iPart++) hFractionTOFPionMCV0tag[iPart]->Draw("same");
627  legFracMC->Draw("same");
628 
629  cFractionTOFMC->cd(2)->DrawFrame(binlims[0],1.e-5,binlims[nBins],10.,Form("TOF K from kinks;%s (GeV/#it{c});Purity / Contamination",varname.Data()));
630  cFractionTOFMC->cd(2)->SetLogy();
631  cFractionTOFMC->cd(2)->SetLogx();
632  for(int iPart=kElectron; iPart<=kProton; iPart++) hFractionTOFKaonMCKinktag[iPart]->Draw("same");
633 
634  cFractionTOFMC->cd(3)->DrawFrame(binlims[0],1.e-5,binlims[nBins],10.,Form("TOF K TPC tag;%s (GeV/#it{c});Purity / Contamination",varname.Data()));
635  cFractionTOFMC->cd(3)->SetLogy();
636  cFractionTOFMC->cd(3)->SetLogx();
637  for(int iPart=kElectron; iPart<=kProton; iPart++) hFractionTOFKaonMCTPCtag[iPart]->Draw("same");
638 
639  cFractionTOFMC->cd(4)->DrawFrame(binlims[0],1.e-5,binlims[nBins],10.,Form("TOF p from #Lambda;%s (GeV/#it{c});Purity / Contamination",varname.Data()));
640  cFractionTOFMC->cd(4)->SetLogy();
641  cFractionTOFMC->cd(45)->SetLogx();
642  for(int iPart=kElectron; iPart<=kProton; iPart++) hFractionTOFProtonMCV0tag[iPart]->Draw("same");
643 
644  //********************************************************************************************************************************************//
645  //compute fractions in data (only TOF)
646 
647  TFractionFitter *fNsigmaTOFKaonTPCtagFitter[nBins];
648  TFractionFitter *fNsigmaTOFProtonV0tagFitter[nBins];
649  TH1F *hFractionTOFKaonDataTPCtag[nPDGcodes-1];
650  TH1F *hFractionTOFProtonDataV0tag[nPDGcodes-1];
651  TH1F *hNsigmaTOFKaonDataTPCtag_Fit[nBins][nPDGcodes];
652  TH1F *hNsigmaTOFProtonDataV0tag_Fit[nBins][nPDGcodes];
653  for(int iPart=kElectron; iPart<=kProton; iPart++) {
654  hFractionTOFKaonDataTPCtag[iPart] = new TH1F(Form("hFractionTOFKaonDataTPCtag_%s",pdgnames[iPart].Data()),Form(";%s (GeV/#it{c});Fraction",varname.Data()),nBins,binlims);
655  hFractionTOFProtonDataV0tag[iPart] = new TH1F(Form("hFractionTOFProtonDataV0tag_%s",pdgnames[iPart].Data()),Form(";%s (GeV/#it{c});Fraction",varname.Data()),nBins,binlims);
656  SetTH1Style(hFractionTOFKaonDataTPCtag[iPart],kOpenSquare,pdgcolors[iPart]+1,1.,2,pdgcolors[iPart],kWhite,0.045,0.05);
657  SetTH1Style(hFractionTOFProtonDataV0tag[iPart],kOpenSquare,pdgcolors[iPart]+1,1.,2,pdgcolors[iPart],kWhite,0.045,0.05);
658  }
659 
660  TCanvas* cFitResultTOFKaonFromTPCtag = new TCanvas("cFitResultTOFKaonFromTPCtag","cFitResultTOFKaonFromTPCtag",1920,1080);
661  DivideCanvas(cFitResultTOFKaonFromTPCtag,nBins);
662  TCanvas* cFitResultTOFProtonFromV0tag = new TCanvas("cFitResultTOFProtonFromV0tag","cFitResultTOFProtonFromV0tag",1920,1080);
663  DivideCanvas(cFitResultTOFProtonFromV0tag,nBins);
664  TCanvas* cTOFFractionData = new TCanvas("cTOFFractionData","cTOFFractionData",1920,1080);
665  cTOFFractionData->Divide(3,1);
666 
667  TLegend* legTOFFitter = new TLegend(0.14,0.62,0.52,0.86);
668  legTOFFitter->SetTextSize(0.04);
669  legTOFFitter->AddEntry(hNsigmaTOFKaonDataTPCtag[0],"Data","p");
670  for(int iPart=kElectron; iPart<=kProton; iPart++) {
671  legTOFFitter->AddEntry(hNsigmaTOFKaonMCTPCtag[0][iPart],Form("Templ %s",pdgnames[iPart].Data()),"l");
672  }
673 
674  for(int iBin=0; iBin<nBins; iBin++) {
675 
676  vector<int> templUsedTOFKaonMCTPCtag;
677  GetTOFFractionsFromData(kKaon,iBin,hFractionTOFKaonMCTPCtag,hFractionTOFKaonDataTPCtag,hNsigmaTOFKaonMCTPCtag[iBin],hNsigmaTOFKaonDataTPCtag[iBin],fNsigmaTOFKaonTPCtagFitter[iBin],templUsedTOFKaonMCTPCtag);
678 
679  if(templUsedTOFKaonMCTPCtag.size()>1) {
680  hNsigmaTOFKaonDataTPCtag_Fit[iBin][kAll] = (TH1F*)fNsigmaTOFKaonTPCtagFitter[iBin]->GetPlot();
681  hNsigmaTOFKaonDataTPCtag_Fit[iBin][kAll]->SetLineColor(kRed);
682  hNsigmaTOFKaonDataTPCtag_Fit[iBin][kAll]->SetFillStyle(0);
683  hNsigmaTOFKaonDataTPCtag_Fit[iBin][kAll]->SetFillColor(kWhite);
684 
685  for(unsigned int iTempl=0; iTempl<templUsedTOFKaonMCTPCtag.size(); iTempl++) {
686  double frac, err;
687  fNsigmaTOFKaonTPCtagFitter[iBin]->GetResult(iTempl, frac, err);
688  hNsigmaTOFKaonDataTPCtag_Fit[iBin][templUsedTOFKaonMCTPCtag[iTempl]] = (TH1F*)fNsigmaTOFKaonTPCtagFitter[iBin]->GetMCPrediction(iTempl);
689  hNsigmaTOFKaonDataTPCtag_Fit[iBin][templUsedTOFKaonMCTPCtag[iTempl]]->Scale(frac/hNsigmaTOFKaonDataTPCtag_Fit[iBin][templUsedTOFKaonMCTPCtag[iTempl]]->Integral()*hNsigmaTOFKaonDataTPCtag_Fit[iBin][kAll]->Integral());
690  hNsigmaTOFKaonDataTPCtag_Fit[iBin][templUsedTOFKaonMCTPCtag[iTempl]]->SetFillColor(kWhite);
691  hNsigmaTOFKaonDataTPCtag_Fit[iBin][templUsedTOFKaonMCTPCtag[iTempl]]->SetFillStyle(0);
692  }
693  }
694  else {
695  hNsigmaTOFKaonDataTPCtag_Fit[iBin][kAll] = (TH1F*)hNsigmaTOFKaonDataTPCtag[iBin]->Clone();
696  hNsigmaTOFKaonDataTPCtag_Fit[iBin][kAll]->SetLineColor(kRed);
697  hNsigmaTOFKaonDataTPCtag_Fit[iBin][kAll]->SetFillStyle(0);
698  hNsigmaTOFKaonDataTPCtag_Fit[iBin][kAll]->SetFillColor(kWhite);
699  hNsigmaTOFKaonDataTPCtag_Fit[iBin][kKaon] = (TH1F*)hNsigmaTOFKaonDataTPCtag[iBin]->Clone();
700  hNsigmaTOFKaonDataTPCtag_Fit[iBin][kKaon]->SetFillColor(kWhite);
701  hNsigmaTOFKaonDataTPCtag_Fit[iBin][kKaon]->SetFillStyle(0);
702  }
703  cFitResultTOFKaonFromTPCtag->cd(iBin+1)->SetLogy();
704  hNsigmaTOFKaonDataTPCtag[iBin]->DrawCopy("E");
705  for(int iPart=kElectron; iPart<=kProton; iPart++) {
706  vector<int>::iterator it = find(templUsedTOFKaonMCTPCtag.begin(),templUsedTOFKaonMCTPCtag.end(),iPart);
707  if(it!=templUsedTOFKaonMCTPCtag.end()) {
708  hNsigmaTOFKaonDataTPCtag_Fit[iBin][iPart]->DrawCopy("hist same");
709  }
710  else {
711  hNsigmaTOFKaonDataTPCtag_Fit[iBin][iPart]=nullptr;
712  }
713  }
714  legTOFFitter->Draw("same");
715 
716  vector<int> templUsedTOFProtonMCV0tag;
717  GetTOFFractionsFromData(kProton,iBin,hFractionTOFProtonMCV0tag,hFractionTOFProtonDataV0tag,hNsigmaTOFProtonMCV0tag[iBin],hNsigmaTOFProtonDataV0tag[iBin],fNsigmaTOFProtonV0tagFitter[iBin],templUsedTOFProtonMCV0tag);
718 
719  if(templUsedTOFProtonMCV0tag.size()>1) {
720  hNsigmaTOFProtonDataV0tag_Fit[iBin][kAll] = (TH1F*)fNsigmaTOFProtonV0tagFitter[iBin]->GetPlot();
721  hNsigmaTOFProtonDataV0tag_Fit[iBin][kAll]->SetLineColor(kRed);
722  hNsigmaTOFProtonDataV0tag_Fit[iBin][kAll]->SetFillStyle(0);
723  hNsigmaTOFProtonDataV0tag_Fit[iBin][kAll]->SetFillColor(kWhite);
724 
725  for(unsigned int iTempl=0; iTempl<templUsedTOFProtonMCV0tag.size(); iTempl++) {
726  double frac, err;
727  fNsigmaTOFProtonV0tagFitter[iBin]->GetResult(iTempl, frac, err);
728  hNsigmaTOFProtonDataV0tag_Fit[iBin][templUsedTOFProtonMCV0tag[iTempl]] = (TH1F*)fNsigmaTOFProtonV0tagFitter[iBin]->GetMCPrediction(iTempl);
729  hNsigmaTOFProtonDataV0tag_Fit[iBin][templUsedTOFProtonMCV0tag[iTempl]]->Scale(frac/hNsigmaTOFProtonDataV0tag_Fit[iBin][templUsedTOFProtonMCV0tag[iTempl]]->Integral()*hNsigmaTOFProtonDataV0tag_Fit[iBin][kAll]->Integral());
730  hNsigmaTOFProtonDataV0tag_Fit[iBin][templUsedTOFProtonMCV0tag[iTempl]]->SetFillColor(kWhite);
731  hNsigmaTOFProtonDataV0tag_Fit[iBin][templUsedTOFProtonMCV0tag[iTempl]]->SetFillStyle(0);
732  }
733  }
734  else {
735  hNsigmaTOFProtonDataV0tag_Fit[iBin][kAll] = (TH1F*)hNsigmaTOFProtonDataV0tag[iBin]->Clone();
736  hNsigmaTOFProtonDataV0tag_Fit[iBin][kAll]->SetLineColor(kRed);
737  hNsigmaTOFProtonDataV0tag_Fit[iBin][kAll]->SetFillStyle(0);
738  hNsigmaTOFProtonDataV0tag_Fit[iBin][kAll]->SetFillColor(kWhite);
739  hNsigmaTOFProtonDataV0tag_Fit[iBin][kProton] = (TH1F*)hNsigmaTOFProtonDataV0tag[iBin]->Clone();
740  hNsigmaTOFProtonDataV0tag_Fit[iBin][kProton]->SetFillColor(kWhite);
741  hNsigmaTOFProtonDataV0tag_Fit[iBin][kProton]->SetFillStyle(0);
742  }
743  cFitResultTOFProtonFromV0tag->cd(iBin+1)->SetLogy();
744  hNsigmaTOFProtonDataV0tag[iBin]->DrawCopy("E");
745  for(int iPart=kElectron; iPart<=kProton; iPart++) {
746  vector<int>::iterator it = find(templUsedTOFProtonMCV0tag.begin(),templUsedTOFProtonMCV0tag.end(),iPart);
747  if(it!=templUsedTOFProtonMCV0tag.end()) {
748  hNsigmaTOFProtonDataV0tag_Fit[iBin][iPart]->DrawCopy("hist same");
749  }
750  else {
751  hNsigmaTOFProtonDataV0tag_Fit[iBin][iPart]=nullptr;
752  }
753  }
754  legTOFFitter->Draw("same");
755  }
756 
757  cTOFFractionData->cd(1)->DrawFrame(binlims[0],1.e-5,binlims[nBins],10.,Form("TOF K TPC tag;%s (GeV/#it{c});Purity / Contamination",varname.Data()));
758  cTOFFractionData->cd(1)->SetLogy();
759  cTOFFractionData->cd(1)->SetLogx();
760  for(int iPart=0; iPart<=kProton; iPart++) {
761  hFractionTOFKaonDataTPCtag[iPart]->DrawCopy("same");
762  }
763  cTOFFractionData->cd(2)->DrawFrame(binlims[0],1.e-5,binlims[nBins],10.,Form("TOF p from #Lambda;%s (GeV/#it{c});Purity / Contamination",varname.Data()));
764  cTOFFractionData->cd(2)->SetLogy();
765  cTOFFractionData->cd(2)->SetLogx();
766  for(int iPart=0; iPart<=kProton; iPart++) {
767  hFractionTOFProtonDataV0tag[iPart]->DrawCopy("same");
768  }
769  TLegend* legFracData = new TLegend(0.3,0.3,0.8,0.8);
770  legFracData->SetTextSize(0.05);
771  for(int iPart=kElectron; iPart<=kProton; iPart++) {
772  legFracData->AddEntry(hFractionTOFProtonDataV0tag[iPart],pdgnames[iPart].Data(),"lpe");
773  }
774  cTOFFractionData->cd(3);
775  legFracData->Draw("same");
776 
777  //********************************************************************************************************************************************//
778  //normalise histograms
779 
780  for(int iBin=0; iBin<nBins; iBin++) {
781  for(int iPart=kElectron; iPart<=kAll; iPart++) {
782  hNsigmaTPCPionMCV0tag[iBin][iPart]->Scale(1./hNsigmaTPCPionMCV0tag[iBin][kAll]->Integral());
783  hNsigmaTPCKaonMCKinktag[iBin][iPart]->Scale(1./hNsigmaTPCKaonMCKinktag[iBin][kAll]->Integral());
784  hNsigmaTPCKaonMCTOFtag[iBin][iPart]->Scale(1./hNsigmaTPCKaonMCTOFtag[iBin][kAll]->Integral());
785  hNsigmaTPCProtonMCV0tag[iBin][iPart]->Scale(1./hNsigmaTPCProtonMCV0tag[iBin][kAll]->Integral());
786  hNsigmaTOFPionMCV0tag[iBin][iPart]->Scale(1./hNsigmaTOFPionMCV0tag[iBin][kAll]->Integral());
787  hNsigmaTOFKaonMCKinktag[iBin][iPart]->Scale(1./hNsigmaTOFKaonMCKinktag[iBin][kAll]->Integral());
788  hNsigmaTOFKaonMCTPCtag[iBin][iPart]->Scale(1./hNsigmaTOFKaonMCTPCtag[iBin][kAll]->Integral());
789  hNsigmaTOFProtonMCV0tag[iBin][iPart]->Scale(1./hNsigmaTOFProtonMCV0tag[iBin][kAll]->Integral());
790 
791  if(iPart==kAll || hFractionTOFKaonDataTPCtag[iPart]->GetBinContent(iBin+1)>0) hNsigmaTOFKaonDataTPCtag_Fit[iBin][iPart]->Scale(1./hNsigmaTOFKaonDataTPCtag[iBin]->Integral());
792  if(iPart==kAll || hFractionTOFProtonDataV0tag[iPart]->GetBinContent(iBin+1)>0) hNsigmaTOFProtonDataV0tag_Fit[iBin][iPart]->Scale(1./hNsigmaTOFProtonDataV0tag[iBin]->Integral());
793  }
794 
795  hNsigmaTPCPionDataV0tag[iBin]->Scale(1./hNsigmaTPCPionDataV0tag[iBin]->Integral());
796  hNsigmaTPCKaonDataKinktag[iBin]->Scale(1./hNsigmaTPCKaonDataKinktag[iBin]->Integral());
797  hNsigmaTPCKaonDataTOFtag[iBin]->Scale(1./hNsigmaTPCKaonDataTOFtag[iBin]->Integral());
798  hNsigmaTPCProtonDataV0tag[iBin]->Scale(1./hNsigmaTPCProtonDataV0tag[iBin]->Integral());
799  hNsigmaTOFPionDataV0tag[iBin]->Scale(1./hNsigmaTOFPionDataV0tag[iBin]->Integral());
800  hNsigmaTOFKaonDataKinktag[iBin]->Scale(1./hNsigmaTOFKaonDataKinktag[iBin]->Integral());
801  hNsigmaTOFKaonDataTPCtag[iBin]->Scale(1./hNsigmaTOFKaonDataTPCtag[iBin]->Integral());
802  hNsigmaTOFProtonDataV0tag[iBin]->Scale(1./hNsigmaTOFProtonDataV0tag[iBin]->Integral());
803  }
804 
805  //********************************************************************************************************************************************//
806  //draw and fit distributions
807 
808  TCanvas* cPionMCV0tagTPC = new TCanvas("cPionMCV0tagTPC","cPionMCV0tagTPC",1920,1080);
809  DivideCanvas(cPionMCV0tagTPC,nBins);
810  TCanvas* cKaonMCKinkstagTPC = new TCanvas("cKaonMCKinkstagTPC","cKaonMCKinkstagTPC",1920,1080);
811  DivideCanvas(cKaonMCKinkstagTPC,nBins);
812  TCanvas* cKaonMCTOFtagTPC = new TCanvas("cKaonMCTOFtagTPC","cKaonMCTOFtagTPC",1920,1080);
813  DivideCanvas(cKaonMCTOFtagTPC,nBins);
814  TCanvas* cProtonMCV0tagTPC = new TCanvas("cProtonMCV0tagTPC","cProtonMCV0tagTPC",1920,1080);
815  DivideCanvas(cProtonMCV0tagTPC,nBins);
816  TCanvas* cPionMCV0tagTOF = new TCanvas("cPionMCV0tagTOF","cPionMCV0tagTOF",1920,1080);
817  DivideCanvas(cPionMCV0tagTOF,nBins);
818  TCanvas* cKaonMCKinkstagTOF = new TCanvas("cKaonMCKinkstagTOF","cKaonMCKinkstagTOF",1920,1080);
819  DivideCanvas(cKaonMCKinkstagTOF,nBins);
820  TCanvas* cKaonMCTPCtagTOF = new TCanvas("cKaonMCTPCtagTOF","cKaonMCTPCtagTOF",1920,1080);
821  DivideCanvas(cKaonMCTPCtagTOF,nBins);
822  TCanvas* cProtonMCV0tagTOF = new TCanvas("cProtonMCV0tagTOF","cProtonMCV0tagTOF",1920,1080);
823  DivideCanvas(cProtonMCV0tagTOF,nBins);
824 
825  TCanvas* cPionDataV0tagTPC = new TCanvas("cPionDataV0tagTPC","cPionDataV0tagTPC",1920,1080);
826  DivideCanvas(cPionDataV0tagTPC,nBins);
827  TCanvas* cKaonDataKinkstagTPC = new TCanvas("cKaonDataKinkstagTPC","cKaonDataKinkstagTPC",1920,1080);
828  DivideCanvas(cKaonDataKinkstagTPC,nBins);
829  TCanvas* cKaonDataTOFtagTPC = new TCanvas("cKaonDataTOFtagTPC","cKaonDataTOFtagTPC",1920,1080);
830  DivideCanvas(cKaonDataTOFtagTPC,nBins);
831  TCanvas* cProtonDataV0tagTPC = new TCanvas("cProtonDataV0tagTPC","cProtonDataV0tagTPC",1920,1080);
832  DivideCanvas(cProtonDataV0tagTPC,nBins);
833  TCanvas* cPionDataV0tagTOF = new TCanvas("cPionDataV0tagTOF","cPionDataV0tagTOF",1920,1080);
834  DivideCanvas(cPionDataV0tagTOF,nBins);
835  TCanvas* cKaonDataKinkstagTOF = new TCanvas("cKaonDataKinkstagTOF","cKaonDataKinkstagTOF",1920,1080);
836  DivideCanvas(cKaonDataKinkstagTOF,nBins);
837  TCanvas* cKaonDataTPCtagTOF = new TCanvas("cKaonDataTPCtagTOF","cKaonDataTPCtagTOF",1920,1080);
838  DivideCanvas(cKaonDataTPCtagTOF,nBins);
839  TCanvas* cProtonDataV0tagTOF = new TCanvas("cProtonDataV0tagTOF","cProtonDataV0tagTOF",1920,1080);
840  DivideCanvas(cProtonDataV0tagTOF,nBins);
841 
842  //fit TPC nsigma
843  TF1 *fNsigmaTPCPionMCV0tag[nBins][nPDGcodes-1], *fNsigmaTPCKaonMCKinktag[nBins][nPDGcodes-1], *fNsigmaTPCKaonMCTOFtag[nBins][nPDGcodes-1], *fNsigmaTPCProtonMCV0tag[nBins][nPDGcodes-1];
844  TF1* fNsigmaTPCPionDataV0tag[nBins][nPDGcodes], *fNsigmaTPCKaonDataKinktag[nBins][nPDGcodes], *fNsigmaTPCKaonDataTOFtag[nBins][nPDGcodes], *fNsigmaTPCProtonDataV0tag[nBins][nPDGcodes];
845 
846  //subtract bkg template for TOF nsigma
847  TH1F *hNsigmaTOFPionDataV0tag_sub[nBins], *hNsigmaTOFKaonDataKinktag_sub[nBins], *hNsigmaTOFKaonDataTPCtag_sub[nBins], *hNsigmaTOFProtonDataV0tag_sub[nBins];
848 
849  TLegend* legMCdist = new TLegend(0.14,0.62,0.44,0.86);
850  legMCdist->SetTextSize(0.04);
851  legMCdist->AddEntry(hNsigmaTPCPionMCV0tag[0][kAll],"MC All","p");
852  for(int iPart=kElectron; iPart<=kProton; iPart++) {
853  legMCdist->AddEntry(hNsigmaTPCPionMCV0tag[0][iPart],Form("MC %s",pdgnames[iPart].Data()),"f");
854  }
855 
856  TLegend* legTPCFitter = new TLegend(0.14,0.62,0.48,0.86);
857  legTPCFitter->SetTextSize(0.04);
858  legTPCFitter->AddEntry(hNsigmaTPCPionDataV0tag[0],"Data","p");
859 
860  TLegend* legTOFPionDataV0tag = new TLegend(0.14,0.7,0.48,0.8);
861  legTOFPionDataV0tag->SetTextSize(0.05);
862 
863  TLegend* legTOFKaonDataKinkstag = new TLegend(0.14,0.7,0.48,0.8);
864  legTOFKaonDataKinkstag->SetTextSize(0.05);
865 
866  TLegend* legTOFKaonDataTPCtag = new TLegend(0.14,0.7,0.48,0.8);
867  legTOFKaonDataTPCtag->SetTextSize(0.05);
868 
869  TLegend* legTOFProtonDataV0tag = new TLegend(0.14,0.7,0.48,0.8);
870  legTOFProtonDataV0tag->SetTextSize(0.05);
871 
872  TString fitopt="ML0R";
873  for(int iBin=0; iBin<nBins; iBin++) {
874 
875  for(int iPart=kElectron; iPart<=kProton; iPart++) {
876  fNsigmaTPCPionMCV0tag[iBin][iPart] = new TF1(Form("fNsigmaTPCPionMCV0tag_%s_p%0.f_%0.f",pdgnames[iPart].Data(),binlims[iBin]*10,binlims[iBin+1]*10),"gaus",-50,50);
877  fNsigmaTPCKaonMCKinktag[iBin][iPart] = new TF1(Form("fNsigmaTPCKaonMCKinktag_%s_p%0.f_%0.f",pdgnames[iPart].Data(),binlims[iBin]*10,binlims[iBin+1]*10),"gaus",-50,50);
878  fNsigmaTPCKaonMCTOFtag[iBin][iPart] = new TF1(Form("fNsigmaTPCKaonMCTOFtag_%s_p%0.f_%0.f",pdgnames[iPart].Data(),binlims[iBin]*10,binlims[iBin+1]*10),"gaus",-50,50);
879  fNsigmaTPCProtonMCV0tag[iBin][iPart] = new TF1(Form("fNsigmaTPCProtonMCV0tag_%s_p%0.f_%0.f",pdgnames[iPart].Data(),binlims[iBin]*10,binlims[iBin+1]*10),"gaus",-50,50);
880  }
881 
882  cPionMCV0tagTPC->cd(iBin+1)->SetLogy();
883  hNsigmaTPCPionMCV0tag[iBin][nPDGcodes-1]->DrawCopy("E");
884  for(int iPart=kElectron; iPart<=kProton; iPart++) {
885  hNsigmaTPCPionMCV0tag[iBin][iPart]->DrawCopy("hist same");
886  if(iPart==kPion || hFractionTPCPionMCV0tag[iPart]->GetBinContent(iBin+1)>1.e-5) hNsigmaTPCPionMCV0tag[iBin][iPart]->Fit(fNsigmaTPCPionMCV0tag[iBin][iPart],fitopt.Data());
887  else fNsigmaTPCPionMCV0tag[iBin][iPart]->SetParameter(0,0);
888  }
889  hNsigmaTPCPionMCV0tag[iBin][nPDGcodes-1]->DrawCopy("Esame");
890  legMCdist->Draw("same");
891  cKaonMCKinkstagTPC->cd(iBin+1)->SetLogy();
892  hNsigmaTPCKaonMCKinktag[iBin][nPDGcodes-1]->DrawCopy("E");
893  for(int iPart=kElectron; iPart<=kProton; iPart++) {
894  hNsigmaTPCKaonMCKinktag[iBin][iPart]->DrawCopy("hist same");
895  if(iPart==kKaon || hFractionTPCKaonMCKinktag[iPart]->GetBinContent(iBin+1)>1.e-5) hNsigmaTPCKaonMCKinktag[iBin][iPart]->Fit(fNsigmaTPCKaonMCKinktag[iBin][iPart],fitopt.Data());
896  else fNsigmaTPCKaonMCKinktag[iBin][iPart]->SetParameter(0,0);
897  }
898  hNsigmaTPCKaonMCKinktag[iBin][nPDGcodes-1]->DrawCopy("Esame");
899  legMCdist->Draw("same");
900  cKaonMCTOFtagTPC->cd(iBin+1)->SetLogy();
901  hNsigmaTPCKaonMCTOFtag[iBin][nPDGcodes-1]->DrawCopy("E");
902  for(int iPart=kElectron; iPart<=kProton; iPart++) {
903  hNsigmaTPCKaonMCTOFtag[iBin][iPart]->DrawCopy("hist same");
904  if(iPart==kKaon || hFractionTPCKaonMCTOFtag[iPart]->GetBinContent(iBin+1)>1.e-5) hNsigmaTPCKaonMCTOFtag[iBin][iPart]->Fit(fNsigmaTPCKaonMCTOFtag[iBin][iPart],fitopt.Data());
905  else fNsigmaTPCKaonMCTOFtag[iBin][iPart]->SetParameter(0,0);
906  }
907  hNsigmaTPCKaonMCTOFtag[iBin][nPDGcodes-1]->DrawCopy("Esame");
908  legMCdist->Draw("same");
909  cProtonMCV0tagTPC->cd(iBin+1)->SetLogy();
910  hNsigmaTPCProtonMCV0tag[iBin][nPDGcodes-1]->DrawCopy("E");
911  for(int iPart=kElectron; iPart<=kProton; iPart++) {
912  hNsigmaTPCProtonMCV0tag[iBin][iPart]->DrawCopy("hist same");
913  if(iPart==kProton || hFractionTPCProtonMCV0tag[iPart]->GetBinContent(iBin+1)>1.e-5) hNsigmaTPCProtonMCV0tag[iBin][iPart]->Fit(fNsigmaTPCProtonMCV0tag[iBin][iPart],fitopt.Data());
914  else fNsigmaTPCProtonMCV0tag[iBin][iPart]->SetParameter(0,0);
915  }
916  hNsigmaTPCProtonMCV0tag[iBin][nPDGcodes-1]->DrawCopy("Esame");
917  legMCdist->Draw("same");
918 
919  cPionMCV0tagTOF->cd(iBin+1)->SetLogy();
920  hNsigmaTOFPionMCV0tag[iBin][nPDGcodes-1]->DrawCopy("E");
921  for(int iPart=kElectron; iPart<=kProton; iPart++) hNsigmaTOFPionMCV0tag[iBin][iPart]->DrawCopy("hist same");
922  hNsigmaTOFPionMCV0tag[iBin][nPDGcodes-1]->DrawCopy("Esame");
923  legMCdist->Draw("same");
924  cKaonMCKinkstagTOF->cd(iBin+1)->SetLogy();
925  hNsigmaTOFKaonMCKinktag[iBin][nPDGcodes-1]->DrawCopy("E");
926  for(int iPart=kElectron; iPart<=kProton; iPart++) hNsigmaTOFKaonMCKinktag[iBin][iPart]->DrawCopy("hist same");
927  hNsigmaTOFKaonMCKinktag[iBin][nPDGcodes-1]->DrawCopy("Esame");
928  legMCdist->Draw("same");
929  cKaonMCTPCtagTOF->cd(iBin+1)->SetLogy();
930  hNsigmaTOFKaonMCTPCtag[iBin][nPDGcodes-1]->DrawCopy("E");
931  for(int iPart=kElectron; iPart<=kProton; iPart++) hNsigmaTOFKaonMCTPCtag[iBin][iPart]->DrawCopy("hist same");
932  hNsigmaTOFKaonMCTPCtag[iBin][nPDGcodes-1]->DrawCopy("Esame");
933  legMCdist->Draw("same");
934  cProtonMCV0tagTOF->cd(iBin+1)->SetLogy();
935  hNsigmaTOFProtonMCV0tag[iBin][nPDGcodes-1]->DrawCopy("E");
936  for(int iPart=kElectron; iPart<=kProton; iPart++) hNsigmaTOFProtonMCV0tag[iBin][iPart]->DrawCopy("hist same");
937  hNsigmaTOFProtonMCV0tag[iBin][nPDGcodes-1]->DrawCopy("Esame");
938  legMCdist->Draw("same");
939 
940  fNsigmaTPCPionDataV0tag[iBin][kAll] = new TF1(Form("fNsigmaTPCPionDataV0tag_%s_p%0.f_%0.f",pdgnames[kAll].Data(),binlims[iBin]*10,binlims[iBin+1]*10),PDFnsigmaTPCtot,-50,50,(nPDGcodes-1)*3);
941  fNsigmaTPCKaonDataKinktag[iBin][kAll] = new TF1(Form("fNsigmaTPCKaonDataKinktag_%s_p%0.f_%0.f",pdgnames[kAll].Data(),binlims[iBin]*10,binlims[iBin+1]*10),PDFnsigmaTPCtot,-50,50,(nPDGcodes-1)*3);
942  fNsigmaTPCKaonDataTOFtag[iBin][kAll] = new TF1(Form("fNsigmaTPCKaonDataTOFtag_%s_p%0.f_%0.f",pdgnames[kAll].Data(),binlims[iBin]*10,binlims[iBin+1]*10),PDFnsigmaTPCtot,-50,50,(nPDGcodes-1)*3);
943  fNsigmaTPCProtonDataV0tag[iBin][kAll] = new TF1(Form("fNsigmaTPCProtonDataV0tag_%s_p%0.f_%0.f",pdgnames[kAll].Data(),binlims[iBin]*10,binlims[iBin+1]*10),PDFnsigmaTPCtot,-50,50,(nPDGcodes-1)*3);
944 
945  for(int iPart=kElectron; iPart<=kProton; iPart++) {
946 
947  double toll = 100.;
948  for(int iPar=0; iPar<3; iPar++) {
949  if(iPar==0)
950  toll=5.;
951  else
952  toll=0.5;
953  fNsigmaTPCPionDataV0tag[iBin][kAll]->SetParameter(iPart*3+iPar,fNsigmaTPCPionMCV0tag[iBin][iPart]->GetParameter(iPar));
954  fNsigmaTPCKaonDataKinktag[iBin][kAll]->SetParameter(iPart*3+iPar,fNsigmaTPCKaonMCKinktag[iBin][iPart]->GetParameter(iPar));
955  fNsigmaTPCKaonDataTOFtag[iBin][kAll]->SetParameter(iPart*3+iPar,fNsigmaTPCKaonMCTOFtag[iBin][iPart]->GetParameter(iPar));
956  fNsigmaTPCProtonDataV0tag[iBin][kAll]->SetParameter(iPart*3+iPar,fNsigmaTPCProtonMCV0tag[iBin][iPart]->GetParameter(iPar));
957 
958  if(iPart*3+iPar!=kPion*3+1) {
959  fNsigmaTPCPionDataV0tag[iBin][kAll]->SetParLimits(iPart*3+iPar,fNsigmaTPCPionMCV0tag[iBin][iPart]->GetParameter(iPar)-TMath::Abs(fNsigmaTPCPionMCV0tag[iBin][iPart]->GetParameter(iPar))*toll,fNsigmaTPCPionMCV0tag[iBin][iPart]->GetParameter(iPar)+TMath::Abs(fNsigmaTPCPionMCV0tag[iBin][iPart]->GetParameter(iPar))*toll);
960  }
961  if(iPart*3+iPar!=kKaon*3+1) {
962  fNsigmaTPCKaonDataKinktag[iBin][kAll]->SetParLimits(iPart*3+iPar,fNsigmaTPCKaonMCKinktag[iBin][iPart]->GetParameter(iPar)-TMath::Abs(fNsigmaTPCKaonMCKinktag[iBin][iPart]->GetParameter(iPar))*toll,fNsigmaTPCKaonMCKinktag[iBin][iPart]->GetParameter(iPar)+TMath::Abs(fNsigmaTPCKaonMCKinktag[iBin][iPart]->GetParameter(iPar))*toll);
963 
964  fNsigmaTPCKaonDataTOFtag[iBin][kAll]->SetParLimits(iPart*3+iPar,fNsigmaTPCKaonMCTOFtag[iBin][iPart]->GetParameter(iPar)-TMath::Abs(fNsigmaTPCKaonMCTOFtag[iBin][iPart]->GetParameter(iPar))*toll,fNsigmaTPCKaonMCTOFtag[iBin][iPart]->GetParameter(iPar)+TMath::Abs(fNsigmaTPCKaonMCTOFtag[iBin][iPart]->GetParameter(iPar))*toll);
965  }
966  if(iPart*3+iPar!=kProton*3+1) {
967  fNsigmaTPCProtonDataV0tag[iBin][kAll]->SetParLimits(iPart*3+iPar,fNsigmaTPCProtonMCV0tag[iBin][iPart]->GetParameter(iPar)-TMath::Abs(fNsigmaTPCProtonMCV0tag[iBin][iPart]->GetParameter(iPar))*toll,fNsigmaTPCProtonMCV0tag[iBin][iPart]->GetParameter(iPar)+TMath::Abs(fNsigmaTPCProtonMCV0tag[iBin][iPart]->GetParameter(iPar))*toll);
968  }
969  }
970  }
971 
972  hNsigmaTPCPionDataV0tag[iBin]->Fit(fNsigmaTPCPionDataV0tag[iBin][kAll],fitopt.Data());
973  hNsigmaTPCKaonDataKinktag[iBin]->Fit(fNsigmaTPCKaonDataKinktag[iBin][kAll],fitopt.Data());
974  hNsigmaTPCKaonDataTOFtag[iBin]->Fit(fNsigmaTPCKaonDataTOFtag[iBin][kAll],fitopt.Data());
975  hNsigmaTPCProtonDataV0tag[iBin]->Fit(fNsigmaTPCProtonDataV0tag[iBin][kAll],fitopt.Data());
976 
977  for(int iPart=kElectron; iPart<=kProton; iPart++) {
978  fNsigmaTPCPionDataV0tag[iBin][iPart] = new TF1(Form("fNsigmaTPCPionDataV0tag_%s_p%0.f_%0.f",pdgnames[iPart].Data(),binlims[iBin]*10,binlims[iBin+1]*10),"gaus",-50,50);
979  fNsigmaTPCKaonDataKinktag[iBin][iPart] = new TF1(Form("fNsigmaTPCKaonDataKinktag_%s_p%0.f_%0.f",pdgnames[iPart].Data(),binlims[iBin]*10,binlims[iBin+1]*10),"gaus",-50,50);
980  fNsigmaTPCKaonDataTOFtag[iBin][iPart] = new TF1(Form("fNsigmaTPCKaonDataTOFtag_%s_p%0.f_%0.f",pdgnames[iPart].Data(),binlims[iBin]*10,binlims[iBin+1]*10),"gaus",-50,50);
981  fNsigmaTPCProtonDataV0tag[iBin][iPart] = new TF1(Form("fNsigmaTPCProtonDataV0tag_%s_p%0.f_%0.f",pdgnames[iPart].Data(),binlims[iBin]*10,binlims[iBin+1]*10),"gaus",-50,50);
982 
983  for(int iPar=0; iPar<3; iPar++) {
984  fNsigmaTPCPionDataV0tag[iBin][iPart]->SetParameter(iPar,fNsigmaTPCPionDataV0tag[iBin][kAll]->GetParameter(iPart*3+iPar));
985  fNsigmaTPCKaonDataKinktag[iBin][iPart]->SetParameter(iPar,fNsigmaTPCKaonDataKinktag[iBin][kAll]->GetParameter(iPart*3+iPar));
986  fNsigmaTPCKaonDataTOFtag[iBin][iPart]->SetParameter(iPar,fNsigmaTPCKaonDataTOFtag[iBin][kAll]->GetParameter(iPart*3+iPar));
987  fNsigmaTPCProtonDataV0tag[iBin][iPart]->SetParameter(iPar,fNsigmaTPCProtonDataV0tag[iBin][kAll]->GetParameter(iPart*3+iPar));
988  fNsigmaTPCPionDataV0tag[iBin][iPart]->SetParError(iPar,fNsigmaTPCPionDataV0tag[iBin][kAll]->GetParError(iPart*3+iPar));
989  fNsigmaTPCKaonDataKinktag[iBin][iPart]->SetParError(iPar,fNsigmaTPCKaonDataKinktag[iBin][kAll]->GetParError(iPart*3+iPar));
990  fNsigmaTPCKaonDataTOFtag[iBin][iPart]->SetParError(iPar,fNsigmaTPCKaonDataTOFtag[iBin][kAll]->GetParError(iPart*3+iPar));
991  fNsigmaTPCProtonDataV0tag[iBin][iPart]->SetParError(iPar,fNsigmaTPCProtonDataV0tag[iBin][kAll]->GetParError(iPart*3+iPar));
992  }
993  fNsigmaTPCPionDataV0tag[iBin][iPart]->SetLineColor(pdgcolors[iPart]);
994  fNsigmaTPCKaonDataKinktag[iBin][iPart]->SetLineColor(pdgcolors[iPart]);
995  fNsigmaTPCKaonDataTOFtag[iBin][iPart]->SetLineColor(pdgcolors[iPart]);
996  fNsigmaTPCProtonDataV0tag[iBin][iPart]->SetLineColor(pdgcolors[iPart]);
997  if(iBin==0) legTPCFitter->AddEntry(fNsigmaTPCProtonDataV0tag[iBin][iPart],Form("Func %s",pdgnames[iPart].Data()),"l");
998  }
999 
1000  cPionDataV0tagTPC->cd(iBin+1)->SetLogy();
1001  hNsigmaTPCPionDataV0tag[iBin]->DrawCopy("E");
1002  for(int iPart=kElectron; iPart<=kProton; iPart++) fNsigmaTPCPionDataV0tag[iBin][iPart]->Draw("same");
1003  legTPCFitter->Draw("same");
1004  cKaonDataKinkstagTPC->cd(iBin+1)->SetLogy();
1005  hNsigmaTPCKaonDataKinktag[iBin]->DrawCopy("E");
1006  for(int iPart=kElectron; iPart<=kProton; iPart++) fNsigmaTPCKaonDataKinktag[iBin][iPart]->Draw("same");
1007  legTPCFitter->Draw("same");
1008  cKaonDataTOFtagTPC->cd(iBin+1)->SetLogy();
1009  hNsigmaTPCKaonDataTOFtag[iBin]->DrawCopy("E");
1010  for(int iPart=kElectron; iPart<=kProton; iPart++) fNsigmaTPCKaonDataTOFtag[iBin][iPart]->Draw("same");
1011  legTPCFitter->Draw("same");
1012  cProtonDataV0tagTPC->cd(iBin+1)->SetLogy();
1013  hNsigmaTPCProtonDataV0tag[iBin]->DrawCopy("E");
1014  for(int iPart=kElectron; iPart<=kProton; iPart++) fNsigmaTPCProtonDataV0tag[iBin][iPart]->Draw("same");
1015  legTPCFitter->Draw("same");
1016 
1017  //subtract bkg template for TOF nsigma
1018  TString name = hNsigmaTOFPionDataV0tag[iBin]->GetName();
1019  name.ReplaceAll("hNsigmaTOFPionDataV0tag","hNsigmaTOFPionDataV0tag_sub");
1020  hNsigmaTOFPionDataV0tag_sub[iBin] = (TH1F*)hNsigmaTOFPionDataV0tag[iBin]->Clone(name.Data());
1021 
1022  name = hNsigmaTOFKaonDataKinktag[iBin]->GetName();
1023  name.ReplaceAll("hNsigmaTOFKaonDataKinktag","hNsigmaTOFKaonDataKinktag_sub");
1024  hNsigmaTOFKaonDataKinktag_sub[iBin] = (TH1F*)hNsigmaTOFKaonDataKinktag[iBin]->Clone(name.Data());
1025 
1026  name = hNsigmaTOFKaonDataTPCtag[iBin]->GetName();
1027  name.ReplaceAll("hNsigmaTOFKaonDataTPCtag","hNsigmaTOFKaonDataTPCtag_sub");
1028  hNsigmaTOFKaonDataTPCtag_sub[iBin] = (TH1F*)hNsigmaTOFKaonDataTPCtag[iBin]->Clone(name.Data());
1029 
1030  name = hNsigmaTOFProtonDataV0tag[iBin]->GetName();
1031  name.ReplaceAll("hNsigmaTOFProtonDataV0tag","hNsigmaTOFProtonDataV0tag_sub");
1032  hNsigmaTOFProtonDataV0tag_sub[iBin] = (TH1F*)hNsigmaTOFProtonDataV0tag[iBin]->Clone(name.Data());
1033 
1034  for(int iPart=kElectron; iPart<=kProton; iPart++) {
1035  if(iPart!=kPion) hNsigmaTOFPionDataV0tag_sub[iBin]->Add(hNsigmaTOFPionMCV0tag[iBin][iPart],-1.);
1036  if(iPart!=kKaon) {
1037  hNsigmaTOFKaonDataKinktag_sub[iBin]->Add(hNsigmaTOFKaonMCKinktag[iBin][iPart],-1.);
1038  if(hFractionTOFKaonDataTPCtag[iPart]->GetBinContent(iBin+1)>0) {
1039  hNsigmaTOFKaonDataTPCtag_sub[iBin]->Add(hNsigmaTOFKaonDataTPCtag_Fit[iBin][iPart],-1.);
1040  }
1041  else {
1042  hNsigmaTOFKaonDataTPCtag_sub[iBin]->Add(hNsigmaTOFKaonMCTPCtag[iBin][iPart],-1.);
1043  }
1044  }
1045  if(iPart!=kProton) {
1046  if(hFractionTOFProtonDataV0tag[iPart]->GetBinContent(iBin+1)>0) {
1047  hNsigmaTOFProtonDataV0tag_sub[iBin]->Add(hNsigmaTOFProtonDataV0tag_Fit[iBin][iPart],-1.);
1048  }
1049  else {
1050  hNsigmaTOFProtonDataV0tag_sub[iBin]->Add(hNsigmaTOFProtonMCV0tag[iBin][iPart],-1.);
1051  }
1052  }
1053  }
1054 
1055  SetTH1Style(hNsigmaTOFPionDataV0tag_sub[iBin],kOpenCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],pdgfillcolors[kAll],0.055,0.06);
1056  SetTH1Style(hNsigmaTOFKaonDataKinktag_sub[iBin],kOpenCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],pdgfillcolors[kAll],0.055,0.06);
1057  SetTH1Style(hNsigmaTOFKaonDataTPCtag_sub[iBin],kOpenCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],pdgfillcolors[kAll],0.055,0.06);
1058  SetTH1Style(hNsigmaTOFProtonDataV0tag_sub[iBin],kOpenCircle,pdgcolors[kAll],0.6,2,pdgcolors[kAll],pdgfillcolors[kAll],0.055,0.06);
1059  if(iBin==0) {
1060  legTOFPionDataV0tag->AddEntry(hNsigmaTOFPionDataV0tag_sub[iBin],"Data","p");
1061  legTOFPionDataV0tag->AddEntry(hNsigmaTOFPionMCV0tag[iBin][kPion],"MC Pion","p");
1062  legTOFKaonDataKinkstag->AddEntry(hNsigmaTOFKaonDataKinktag_sub[iBin],"Data","p");
1063  legTOFKaonDataKinkstag->AddEntry(hNsigmaTOFKaonMCKinktag[iBin][kKaon],"MC Kaon","p");
1064  legTOFKaonDataTPCtag->AddEntry(hNsigmaTOFKaonDataTPCtag_sub[iBin],"Data","p");
1065  legTOFKaonDataTPCtag->AddEntry(hNsigmaTOFKaonMCTPCtag[iBin][kKaon],"MC Kaon","p");
1066  legTOFProtonDataV0tag->AddEntry(hNsigmaTOFProtonDataV0tag_sub[iBin],"Data","p");
1067  legTOFProtonDataV0tag->AddEntry(hNsigmaTOFKaonMCTPCtag[iBin][kProton],"MC Proton","p");
1068  }
1069 
1070  cPionDataV0tagTOF->cd(iBin+1)->SetLogy();
1071  hNsigmaTOFPionDataV0tag_sub[iBin]->DrawCopy("E");
1072  hNsigmaTOFPionMCV0tag[iBin][kPion]->DrawCopy("hist same");
1073  legTOFPionDataV0tag->Draw("same");
1074  cKaonDataKinkstagTOF->cd(iBin+1)->SetLogy();
1075  hNsigmaTOFKaonDataKinktag_sub[iBin]->DrawCopy("E");
1076  hNsigmaTOFKaonMCKinktag[iBin][kKaon]->DrawCopy("hist same");
1077  legTOFKaonDataKinkstag->Draw("same");
1078  cKaonDataTPCtagTOF->cd(iBin+1)->SetLogy();
1079  hNsigmaTOFKaonDataTPCtag_sub[iBin]->DrawCopy("E");
1080  hNsigmaTOFKaonMCTPCtag[iBin][kKaon]->DrawCopy("hist same");
1081  legTOFKaonDataTPCtag->Draw("same");
1082  cProtonDataV0tagTOF->cd(iBin+1)->SetLogy();
1083  hNsigmaTOFProtonDataV0tag_sub[iBin]->DrawCopy("E");
1084  hNsigmaTOFProtonMCV0tag[iBin][kProton]->DrawCopy("hist same");
1085  legTOFProtonDataV0tag->Draw("same");
1086  }
1087 
1088  //********************************************************************************************************************************************//
1089  //compute efficiencies
1090 
1091  const int nEff = 3;
1092  int nSigma[nEff] = {3,2,1};
1093  int markersMC[nEff] = {kFullCircle,kFullSquare,kFullDiamond};
1094  int markersData[nEff] = {kOpenCircle,kOpenSquare,kOpenDiamond};
1095  TH1F *hEffPionTPCMCtrue[nEff], *hEffPionTOFMCtrue[nEff], *hEffKaonTPCMCtrue[nEff], *hEffKaonTOFMCtrue[nEff],*hEffProtonTPCMCtrue[nEff], *hEffProtonTOFMCtrue[nEff];
1096  TH1F *hEffPionTPCDataV0tag[nEff], *hEffPionTOFDataV0tag[nEff], *hEffKaonTPCDataKinktag[nEff], *hEffKaonTOFDataKinktag[nEff], *hEffKaonTPCDataTOFtag[nEff], *hEffKaonTOFDataTPCtag[nEff],*hEffProtonTPCDataV0tag[nEff], *hEffProtonTOFDataV0tag[nEff];
1097  TH1F *hRatioEffPionTPCDataV0tag[nEff], *hRatioEffPionTOFDataV0tag[nEff], *hRatioEffKaonTPCDataKinktag[nEff], *hRatioEffKaonTOFDataKinktag[nEff], *hRatioEffKaonTPCDataTOFtag[nEff], *hRatioEffKaonTOFDataTPCtag[nEff],*hRatioEffProtonTPCDataV0tag[nEff], *hRatioEffProtonTOFDataV0tag[nEff];
1098 
1099  TLegend* legEffPion = new TLegend(0.18,0.15,0.925,0.38);
1100  legEffPion->SetTextSize(0.045);
1101  legEffPion->SetNColumns(2);
1102  legEffPion->AddEntry("","MC","");
1103  legEffPion->AddEntry("","V0 tag","");
1104  TLegend* legEffKaonTPC = new TLegend(0.18,0.15,0.925,0.38);
1105  legEffKaonTPC->SetTextSize(0.045);
1106  legEffKaonTPC->SetNColumns(3);
1107  legEffKaonTPC->AddEntry("","MC","");
1108  legEffKaonTPC->AddEntry("","TOF tag","");
1109  legEffKaonTPC->AddEntry("","kink tag","");
1110  TLegend* legEffKaonTOF = new TLegend(0.18,0.15,0.925,0.38);
1111  legEffKaonTOF->SetTextSize(0.045);
1112  legEffKaonTOF->SetNColumns(2);
1113  legEffKaonTOF->AddEntry("","MC","");
1114  legEffKaonTOF->AddEntry("","TPC tag","");
1115  TLegend* legEffProton = new TLegend(0.18,0.15,0.925,0.38);
1116  legEffProton->SetTextSize(0.045);
1117  legEffProton->SetNColumns(2);
1118  legEffProton->AddEntry("","MC","");
1119  legEffProton->AddEntry("","V0 tag","");
1120 
1121  for(int iEff=0; iEff<nEff; iEff++) {
1122  hEffPionTPCMCtrue[iEff] = new TH1F(Form("hEffPionTPCMCtrue_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TPC #pi efficiency",varname.Data()),nBins,binlims);
1123  hEffPionTOFMCtrue[iEff] = new TH1F(Form("hEffPionTOFMCtrue_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TOF #pi efficiency",varname.Data()),nBins,binlims);
1124 
1125  hEffKaonTPCMCtrue[iEff] = new TH1F(Form("hEffKaonTPCMCtrue_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TPC K efficiency",varname.Data()),nBins,binlims);
1126  hEffKaonTOFMCtrue[iEff] = new TH1F(Form("hEffKaonTOFMCtrue_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TOF K efficiency",varname.Data()),nBins,binlims);
1127 
1128  hEffProtonTPCMCtrue[iEff] = new TH1F(Form("hEffProtonTPCMCtrue_%dsigma;",nSigma[iEff]),Form(";%s (GeV/#it{c});TPC p efficiency",varname.Data()),nBins,binlims);
1129  hEffProtonTOFMCtrue[iEff] = new TH1F(Form("hEffProtonTOFMCtrue_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TOF p efficiency",varname.Data()),nBins,binlims);
1130 
1131  hEffPionTPCDataV0tag[iEff] = new TH1F(Form("hEffPionTPCDataV0tag_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TPC #pi efficiency",varname.Data()),nBins,binlims);
1132  hEffPionTOFDataV0tag[iEff] = new TH1F(Form("hEffPionTOFDataV0tag_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TOF #pi efficiency",varname.Data()),nBins,binlims);
1133 
1134  hEffKaonTPCDataKinktag[iEff] = new TH1F(Form("hEffKaonTPCDataKinktag_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TPC K efficiency",varname.Data()),nBins,binlims);
1135  hEffKaonTOFDataKinktag[iEff] = new TH1F(Form("hEffKaonTOFDataKinktag_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TOF K efficiency",varname.Data()),nBins,binlims);
1136 
1137  hEffKaonTPCDataTOFtag[iEff] = new TH1F(Form("hEffKaonTPCDataTOFtag_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TPC K efficiency",varname.Data()),nBins,binlims);
1138  hEffKaonTOFDataTPCtag[iEff] = new TH1F(Form("hEffKaonTOFDataTPCtag_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TOF K efficiency",varname.Data()),nBins,binlims);
1139 
1140  hEffProtonTPCDataV0tag[iEff] = new TH1F(Form("hEffProtonTPCDataV0tag_%dsigma;",nSigma[iEff]),Form(";%s (GeV/#it{c});TPC p efficiency",varname.Data()),nBins,binlims);
1141  hEffProtonTOFDataV0tag[iEff] = new TH1F(Form("hEffProtonTOFDataV0tag_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TOF p efficiency",varname.Data()),nBins,binlims);
1142 
1143  hRatioEffPionTPCDataV0tag[iEff] = new TH1F(Form("hRatioEffPionTPCDataV0tag_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TPC #pi efficiency",varname.Data()),nBins,binlims);
1144  hRatioEffPionTOFDataV0tag[iEff] = new TH1F(Form("hRatioEffPionTOFDataV0tag_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TOF #pi efficiency",varname.Data()),nBins,binlims);
1145 
1146  hRatioEffKaonTPCDataKinktag[iEff] = new TH1F(Form("hRatioEffKaonTPCDataKinktag_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TPC K efficiency",varname.Data()),nBins,binlims);
1147  hRatioEffKaonTOFDataKinktag[iEff] = new TH1F(Form("hRatioEffKaonTOFDataKinktag_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TOF K efficiency",varname.Data()),nBins,binlims);
1148 
1149  hRatioEffKaonTPCDataTOFtag[iEff] = new TH1F(Form("hRatioEffKaonTPCDataTOFtag_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TPC K efficiency",varname.Data()),nBins,binlims);
1150  hRatioEffKaonTOFDataTPCtag[iEff] = new TH1F(Form("hRatioEffKaonTOFDataTPCtag_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TOF K efficiency",varname.Data()),nBins,binlims);
1151 
1152  hRatioEffProtonTPCDataV0tag[iEff] = new TH1F(Form("hRatioEffProtonTPCDataV0tag_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TPC #pi efficiency",varname.Data()),nBins,binlims);
1153  hRatioEffProtonTOFDataV0tag[iEff] = new TH1F(Form("hRatioEffProtonTOFDataV0tag_%dsigma",nSigma[iEff]),Form(";%s (GeV/#it{c});TOF #pi efficiency",varname.Data()),nBins,binlims);
1154 
1155  int nsigmabinlow = hNsigmaTOFPionMCTrue[0]->GetXaxis()->FindBin(-nSigma[iEff]+1.e-5);
1156  int nsigmabinhigh = hNsigmaTOFPionMCTrue[0]->GetXaxis()->FindBin(nSigma[iEff]-1.e-5);
1157 
1158  legEffPion->AddEntry(hEffPionTPCMCtrue[iEff],Form("|N_{#sigma}(#pi)| < %d",nSigma[iEff]),"p");
1159  legEffPion->AddEntry(hEffPionTPCDataV0tag[iEff],Form("|N_{#sigma}(#pi)| < %d",nSigma[iEff]),"p");
1160  legEffKaonTPC->AddEntry(hEffKaonTPCMCtrue[iEff],Form("|N_{#sigma}(K)| < %d",nSigma[iEff]),"p");
1161  legEffKaonTPC->AddEntry(hEffKaonTPCDataTOFtag[iEff],Form("|N_{#sigma}(K)| < %d",nSigma[iEff]),"p");
1162  legEffKaonTPC->AddEntry(hEffKaonTPCDataKinktag[iEff],Form("|N_{#sigma}(K)| < %d",nSigma[iEff]),"p");
1163  legEffKaonTOF->AddEntry(hEffKaonTPCMCtrue[iEff],Form("|N_{#sigma}(K)| < %d",nSigma[iEff]),"p");
1164  legEffKaonTOF->AddEntry(hEffKaonTPCDataTOFtag[iEff],Form("|N_{#sigma}(K)| < %d",nSigma[iEff]),"p");
1165  legEffProton->AddEntry(hEffProtonTPCMCtrue[iEff],Form("|N_{#sigma}(p)| < %d",nSigma[iEff]),"p");
1166  legEffProton->AddEntry(hEffProtonTOFDataV0tag[iEff],Form("|N_{#sigma}(p)| < %d",nSigma[iEff]),"p");
1167 
1168  for(int iBin=0; iBin<nBins; iBin++) {
1169  double eff=-1, unc=-1;
1170  ComputeEfficiency(hNsigmaTPCPionMCTrue[iBin]->Integral(nsigmabinlow,nsigmabinhigh),hNsigmaTPCPionMCTrue[iBin]->Integral(),eff,unc);
1171  hEffPionTPCMCtrue[iEff]->SetBinContent(iBin+1,eff);
1172  hEffPionTPCMCtrue[iEff]->SetBinError(iBin+1,unc);
1173 
1174  ComputeEfficiency(hNsigmaTOFPionMCTrue[iBin]->Integral(nsigmabinlow,nsigmabinhigh),hNsigmaTOFPionMCTrue[iBin]->Integral(),eff,unc);
1175  hEffPionTOFMCtrue[iEff]->SetBinContent(iBin+1,eff);
1176  hEffPionTOFMCtrue[iEff]->SetBinError(iBin+1,unc);
1177 
1178  ComputeEfficiency(hNsigmaTPCKaonMCTrue[iBin]->Integral(nsigmabinlow,nsigmabinhigh),hNsigmaTPCKaonMCTrue[iBin]->Integral(),eff,unc);
1179  hEffKaonTPCMCtrue[iEff]->SetBinContent(iBin+1,eff);
1180  hEffKaonTPCMCtrue[iEff]->SetBinError(iBin+1,unc);
1181 
1182  ComputeEfficiency(hNsigmaTOFKaonMCTrue[iBin]->Integral(nsigmabinlow,nsigmabinhigh),hNsigmaTOFKaonMCTrue[iBin]->Integral(),eff,unc);
1183  hEffKaonTOFMCtrue[iEff]->SetBinContent(iBin+1,eff);
1184  hEffKaonTOFMCtrue[iEff]->SetBinError(iBin+1,unc);
1185 
1186  ComputeEfficiency(hNsigmaTPCProtonMCTrue[iBin]->Integral(nsigmabinlow,nsigmabinhigh),hNsigmaTPCProtonMCTrue[iBin]->Integral(),eff,unc);
1187  hEffProtonTPCMCtrue[iEff]->SetBinContent(iBin+1,eff);
1188  hEffProtonTPCMCtrue[iEff]->SetBinError(iBin+1,unc);
1189 
1190  ComputeEfficiency(hNsigmaTOFProtonMCTrue[iBin]->Integral(nsigmabinlow,nsigmabinhigh),hNsigmaTOFProtonMCTrue[iBin]->Integral(),eff,unc);
1191  hEffProtonTOFMCtrue[iEff]->SetBinContent(iBin+1,eff);
1192  hEffProtonTOFMCtrue[iEff]->SetBinError(iBin+1,unc);
1193 
1194  ComputeEfficiency(fNsigmaTPCPionDataV0tag[iBin][kPion]->Integral(-nSigma[iEff],nSigma[iEff])*intNsigmaTPCPionDataV0tag[iBin],fNsigmaTPCPionDataV0tag[iBin][kPion]->Integral(-50,50)*intNsigmaTPCPionDataV0tag[iBin],eff,unc);
1195  hEffPionTPCDataV0tag[iEff]->SetBinContent(iBin+1,eff);
1196  hEffPionTPCDataV0tag[iEff]->SetBinError(iBin+1,unc);
1197 
1198  ComputeEfficiency(fNsigmaTPCKaonDataKinktag[iBin][kKaon]->Integral(-nSigma[iEff],nSigma[iEff])*intNsigmaTPCKaonDataKinktag[iBin],fNsigmaTPCKaonDataKinktag[iBin][kKaon]->Integral(-50,50)*intNsigmaTPCKaonDataKinktag[iBin],eff,unc);
1199  hEffKaonTPCDataKinktag[iEff]->SetBinContent(iBin+1,eff);
1200  hEffKaonTPCDataKinktag[iEff]->SetBinError(iBin+1,unc);
1201 
1202  ComputeEfficiency(fNsigmaTPCKaonDataTOFtag[iBin][kKaon]->Integral(-nSigma[iEff],nSigma[iEff])*intNsigmaTPCKaonDataTOFtag[iBin],fNsigmaTPCKaonDataTOFtag[iBin][kKaon]->Integral(-50,50)*intNsigmaTPCKaonDataTOFtag[iBin],eff,unc);
1203  hEffKaonTPCDataTOFtag[iEff]->SetBinContent(iBin+1,eff);
1204  hEffKaonTPCDataTOFtag[iEff]->SetBinError(iBin+1,unc);
1205 
1206  ComputeEfficiency(fNsigmaTPCProtonDataV0tag[iBin][kProton]->Integral(-nSigma[iEff],nSigma[iEff])*intNsigmaTPCProtonDataV0tag[iBin],fNsigmaTPCProtonDataV0tag[iBin][kProton]->Integral(-50,50)*intNsigmaTPCProtonDataV0tag[iBin],eff,unc);
1207  hEffProtonTPCDataV0tag[iEff]->SetBinContent(iBin+1,eff);
1208  hEffProtonTPCDataV0tag[iEff]->SetBinError(iBin+1,unc);
1209 
1210  ComputeEfficiency(hNsigmaTOFPionDataV0tag_sub[iBin]->Integral(nsigmabinlow,nsigmabinhigh)*intNsigmaTOFPionDataV0tag[iBin],hNsigmaTOFPionDataV0tag_sub[iBin]->Integral()*intNsigmaTOFPionDataV0tag[iBin],eff,unc);
1211  hEffPionTOFDataV0tag[iEff]->SetBinContent(iBin+1,eff);
1212  hEffPionTOFDataV0tag[iEff]->SetBinError(iBin+1,unc);
1213 
1214  ComputeEfficiency(hNsigmaTOFKaonDataTPCtag_sub[iBin]->Integral(nsigmabinlow,nsigmabinhigh)*intNsigmaTOFKaonDataTPCtag[iBin],hNsigmaTOFKaonDataTPCtag_sub[iBin]->Integral()*intNsigmaTOFKaonDataTPCtag[iBin],eff,unc);
1215  hEffKaonTOFDataTPCtag[iEff]->SetBinContent(iBin+1,eff);
1216  hEffKaonTOFDataTPCtag[iEff]->SetBinError(iBin+1,unc);
1217 
1218  ComputeEfficiency(hNsigmaTOFProtonDataV0tag_sub[iBin]->Integral(nsigmabinlow,nsigmabinhigh)*intNsigmaTOFProtonDataV0tag[iBin],hNsigmaTOFProtonDataV0tag_sub[iBin]->Integral()*intNsigmaTOFProtonDataV0tag[iBin],eff,unc);
1219  hEffProtonTOFDataV0tag[iEff]->SetBinContent(iBin+1,eff);
1220  hEffProtonTOFDataV0tag[iEff]->SetBinError(iBin+1,unc);
1221  }
1222 
1223  hRatioEffPionTPCDataV0tag[iEff]->Divide(hEffPionTPCDataV0tag[iEff],hEffPionTPCMCtrue[iEff],1.,1.,"");
1224  hRatioEffPionTOFDataV0tag[iEff]->Divide(hEffPionTOFDataV0tag[iEff],hEffPionTOFMCtrue[iEff],1.,1.,"");
1225  hRatioEffKaonTPCDataKinktag[iEff]->Divide(hEffKaonTPCDataKinktag[iEff],hEffKaonTPCMCtrue[iEff],1.,1.,"");
1226  hRatioEffKaonTPCDataTOFtag[iEff]->Divide(hEffKaonTPCDataTOFtag[iEff],hEffKaonTPCMCtrue[iEff],1.,1.,"");
1227  hRatioEffKaonTOFDataTPCtag[iEff]->Divide(hEffKaonTOFDataTPCtag[iEff],hEffKaonTOFMCtrue[iEff],1.,1.,"");
1228  hRatioEffProtonTPCDataV0tag[iEff]->Divide(hEffProtonTPCDataV0tag[iEff],hEffProtonTPCMCtrue[iEff],1.,1.,"");
1229  hRatioEffProtonTOFDataV0tag[iEff]->Divide(hEffProtonTOFDataV0tag[iEff],hEffProtonTOFMCtrue[iEff],1.,1.,"");
1230 
1231  SetTH1Style(hEffPionTPCMCtrue[iEff],markersMC[iEff],pdgcolors[kPion],1.,2,pdgcolors[kPion],kWhite,0.045,0.055);
1232  SetTH1Style(hEffPionTOFMCtrue[iEff],markersMC[iEff],pdgcolors[kPion],1.,2,pdgcolors[kPion],kWhite,0.045,0.055);
1233  SetTH1Style(hEffKaonTPCMCtrue[iEff],markersMC[iEff],pdgcolors[kKaon],1.,2,pdgcolors[kKaon],kWhite,0.045,0.055);
1234  SetTH1Style(hEffKaonTOFMCtrue[iEff],markersMC[iEff],pdgcolors[kKaon],1.,2,pdgcolors[kKaon],kWhite,0.045,0.055);
1235  SetTH1Style(hEffProtonTPCMCtrue[iEff],markersMC[iEff],pdgcolors[kProton],1.,2,pdgcolors[kProton],kWhite,0.045,0.055);
1236  SetTH1Style(hEffProtonTOFMCtrue[iEff],markersMC[iEff],pdgcolors[kProton],1.,2,pdgcolors[kProton],kWhite,0.045,0.055);
1237 
1238  SetTH1Style(hEffPionTPCDataV0tag[iEff],markersData[iEff],pdgcolors[kPion]+1,1.,2,pdgcolors[kPion]+1,kWhite,0.045,0.055);
1239  SetTH1Style(hEffPionTOFDataV0tag[iEff],markersData[iEff],pdgcolors[kPion]+1,1.,2,pdgcolors[kPion]+1,kWhite,0.045,0.055);
1240  SetTH1Style(hEffKaonTPCDataKinktag[iEff],markersData[iEff],pdgcolors[kKaon]+1,1.,2,pdgcolors[kKaon]+1,kWhite,0.045,0.055);
1241  SetTH1Style(hEffKaonTPCDataTOFtag[iEff],markersData[iEff],pdgcolors[kKaon]+3,1.,2,pdgcolors[kKaon]+3,kWhite,0.045,0.055);
1242  SetTH1Style(hEffKaonTOFDataTPCtag[iEff],markersData[iEff],pdgcolors[kKaon]+3,1.,2,pdgcolors[kKaon]+3,kWhite,0.045,0.055);
1243  SetTH1Style(hEffProtonTPCDataV0tag[iEff],markersData[iEff],pdgcolors[kProton]+1,1.,2,pdgcolors[kProton]+1,kWhite,0.045,0.055);
1244  SetTH1Style(hEffProtonTOFDataV0tag[iEff],markersData[iEff],pdgcolors[kProton]+1,1.,2,pdgcolors[kProton]+1,kWhite,0.045,0.055);
1245 
1246  SetTH1Style(hRatioEffPionTPCDataV0tag[iEff],markersData[iEff],pdgcolors[kPion]+1,1.,2,pdgcolors[kPion]+1,kWhite,0.045,0.055);
1247  SetTH1Style(hRatioEffPionTOFDataV0tag[iEff],markersData[iEff],pdgcolors[kPion]+1,1.,2,pdgcolors[kPion]+1,kWhite,0.045,0.055);
1248  SetTH1Style(hRatioEffKaonTPCDataKinktag[iEff],markersData[iEff],pdgcolors[kKaon]+1,1.,2,pdgcolors[kKaon]+1,kWhite,0.045,0.055);
1249  SetTH1Style(hRatioEffKaonTPCDataTOFtag[iEff],markersData[iEff],pdgcolors[kKaon]+3,1.,2,pdgcolors[kKaon]+3,kWhite,0.045,0.055);
1250  SetTH1Style(hRatioEffKaonTOFDataTPCtag[iEff],markersData[iEff],pdgcolors[kKaon]+3,1.,2,pdgcolors[kKaon]+3,kWhite,0.045,0.055);
1251  SetTH1Style(hRatioEffProtonTPCDataV0tag[iEff],markersData[iEff],pdgcolors[kProton]+1,1.,2,pdgcolors[kProton]+1,kWhite,0.045,0.055);
1252  SetTH1Style(hRatioEffProtonTOFDataV0tag[iEff],markersData[iEff],pdgcolors[kProton]+1,1.,2,pdgcolors[kProton]+1,kWhite,0.045,0.055);
1253  }
1254 
1255  TCanvas* cEffPion = new TCanvas("cEffPion","cEffPion",800,800);
1256  TCanvas* cEffKaon = new TCanvas("cEffKaon","cEffKaon",800,800);
1257  TCanvas* cEffProton = new TCanvas("cEffProton","cEffProton",800,800);
1258  cEffPion->Divide(2,2);
1259  cEffPion->cd(1)->DrawFrame(binlims[0],0.,binlims[nBins],1.,Form(";%s (GeV/#it{c});pion TPC PID efficiency",varname.Data()));
1260  cEffPion->cd(2)->DrawFrame(binlims[0],0.,binlims[nBins],1.,Form(";%s (GeV/#it{c});pion TOF PID efficiency",varname.Data()));
1261  cEffPion->cd(3)->DrawFrame(binlims[0],0.5,binlims[nBins],1.15,Form(";%s (GeV/#it{c}); pion data / MC TPC PID efficiency",varname.Data()));
1262  cEffPion->cd(4)->DrawFrame(binlims[0],0.5,binlims[nBins],1.15,Form(";%s (GeV/#it{c});pion data / MC TOF PID efficiency",varname.Data()));
1263  cEffKaon->Divide(2,2);
1264  cEffKaon->cd(1)->DrawFrame(binlims[0],0.,binlims[nBins],1.,Form(";%s (GeV/#it{c});kaon TPC PID efficiency",varname.Data()));
1265  cEffKaon->cd(2)->DrawFrame(binlims[0],0.,binlims[nBins],1.,Form(";%s (GeV/#it{c});kaon TOF PID efficiency",varname.Data()));
1266  cEffKaon->cd(3)->DrawFrame(binlims[0],0.5,binlims[nBins],1.15,Form(";%s (GeV/#it{c});kaon data / MC TPC PID efficiency",varname.Data()));
1267  cEffKaon->cd(4)->DrawFrame(binlims[0],0.5,binlims[nBins],1.15,Form(";%s (GeV/#it{c});kaon data / MC TOF PID efficiency",varname.Data()));
1268  cEffProton->Divide(2,2);
1269  cEffProton->cd(1)->DrawFrame(binlims[0],0.,binlims[nBins],1.,Form(";%s (GeV/#it{c});proton TPC PID efficiency",varname.Data()));
1270  cEffProton->cd(2)->DrawFrame(binlims[0],0.,binlims[nBins],1.,Form(";%s (GeV/#it{c});proton TOF PID efficiency",varname.Data()));
1271  cEffProton->cd(3)->DrawFrame(binlims[0],0.5,binlims[nBins],1.15,Form(";%s (GeV/#it{c});proton data / MC TPC PID efficiency",varname.Data()));
1272  cEffProton->cd(4)->DrawFrame(binlims[0],0.5,binlims[nBins],1.15,Form(";%s (GeV/#it{c});proton data / MC TOF PID efficiency",varname.Data()));
1273 
1274  for(int iEff=0; iEff<nEff; iEff++) {
1275  cEffPion->cd(1)->SetLogx();
1276  cEffPion->cd(1)->SetTopMargin(0.035);
1277  cEffPion->cd(1)->SetBottomMargin(0.12);
1278  cEffPion->cd(1)->SetRightMargin(0.035);
1279  hEffPionTPCMCtrue[iEff]->Draw("same");
1280  hEffPionTPCDataV0tag[iEff]->Draw("same");
1281  legEffPion->Draw("same");
1282 
1283  cEffPion->cd(2)->SetLogx();
1284  cEffPion->cd(2)->SetTopMargin(0.035);
1285  cEffPion->cd(2)->SetBottomMargin(0.12);
1286  cEffPion->cd(2)->SetRightMargin(0.035);
1287  hEffPionTOFMCtrue[iEff]->Draw("same");
1288  hEffPionTOFDataV0tag[iEff]->Draw("same");
1289  legEffPion->Draw("same");
1290 
1291  cEffPion->cd(3)->SetLogx();
1292  cEffPion->cd(3)->SetTopMargin(0.035);
1293  cEffPion->cd(3)->SetBottomMargin(0.12);
1294  cEffPion->cd(3)->SetRightMargin(0.035);
1295  hRatioEffPionTPCDataV0tag[iEff]->Draw("same");
1296 
1297  cEffPion->cd(4)->SetLogx();
1298  cEffPion->cd(4)->SetTopMargin(0.035);
1299  cEffPion->cd(4)->SetBottomMargin(0.12);
1300  cEffPion->cd(4)->SetRightMargin(0.035);
1301  hRatioEffPionTOFDataV0tag[iEff]->Draw("same");
1302 
1303  cEffKaon->cd(1)->SetLogx();
1304  cEffKaon->cd(1)->SetTopMargin(0.035);
1305  cEffKaon->cd(1)->SetBottomMargin(0.12);
1306  cEffKaon->cd(1)->SetRightMargin(0.035);
1307  hEffKaonTPCMCtrue[iEff]->Draw("same");
1308  hEffKaonTPCDataKinktag[iEff]->Draw("same");
1309  hEffKaonTPCDataTOFtag[iEff]->Draw("same");
1310  legEffKaonTPC->Draw("same");
1311 
1312  cEffKaon->cd(2)->SetLogx();
1313  cEffKaon->cd(2)->SetTopMargin(0.035);
1314  cEffKaon->cd(2)->SetBottomMargin(0.12);
1315  cEffKaon->cd(2)->SetRightMargin(0.035);
1316  hEffKaonTOFMCtrue[iEff]->Draw("same");
1317  hEffKaonTOFDataTPCtag[iEff]->Draw("same");
1318  legEffKaonTOF->Draw("same");
1319 
1320  cEffKaon->cd(3)->SetLogx();
1321  cEffKaon->cd(3)->SetTopMargin(0.035);
1322  cEffKaon->cd(3)->SetBottomMargin(0.12);
1323  cEffKaon->cd(3)->SetRightMargin(0.035);
1324  hRatioEffKaonTPCDataKinktag[iEff]->Draw("same");
1325  hRatioEffKaonTPCDataTOFtag[iEff]->Draw("same");
1326 
1327  cEffKaon->cd(4)->SetLogx();
1328  cEffKaon->cd(4)->SetTopMargin(0.035);
1329  cEffKaon->cd(4)->SetBottomMargin(0.12);
1330  cEffKaon->cd(4)->SetRightMargin(0.035);
1331  hRatioEffKaonTOFDataTPCtag[iEff]->Draw("same");
1332 
1333  cEffProton->cd(1)->SetLogx();
1334  cEffProton->cd(1)->SetTopMargin(0.035);
1335  cEffProton->cd(1)->SetBottomMargin(0.12);
1336  cEffProton->cd(1)->SetRightMargin(0.035);
1337  hEffProtonTPCMCtrue[iEff]->Draw("same");
1338  hEffProtonTPCDataV0tag[iEff]->Draw("same");
1339  legEffProton->Draw("same");
1340 
1341  cEffProton->cd(2)->SetLogx();
1342  cEffProton->cd(2)->SetTopMargin(0.035);
1343  cEffProton->cd(2)->SetBottomMargin(0.12);
1344  cEffProton->cd(2)->SetRightMargin(0.035);
1345  hEffProtonTOFMCtrue[iEff]->Draw("same");
1346  hEffProtonTOFDataV0tag[iEff]->Draw("same");
1347  legEffProton->Draw("same");
1348 
1349  cEffProton->cd(3)->SetLogx();
1350  cEffProton->cd(3)->SetTopMargin(0.035);
1351  cEffProton->cd(3)->SetBottomMargin(0.12);
1352  cEffProton->cd(3)->SetRightMargin(0.035);
1353  hRatioEffProtonTPCDataV0tag[iEff]->Draw("same");
1354 
1355  cEffProton->cd(4)->SetLogx();
1356  cEffProton->cd(4)->SetTopMargin(0.035);
1357  cEffProton->cd(4)->SetBottomMargin(0.12);
1358  cEffProton->cd(4)->SetRightMargin(0.035);
1359  hRatioEffProtonTOFDataV0tag[iEff]->Draw("same");
1360  }
1361 
1362  //mean and width of Nsigma distributions
1363  TH1F* hMeanPionTPCMCV0tag = new TH1F("hMeanPionTPCMCV0tag",Form(";%s (GeV/#it{c});Mean(#pi)",varname.Data()),nBins,binlims);
1364  TH1F* hSigmaPionTPCMCV0tag = new TH1F("hSigmaPionTPCMCV0tag",Form(";%s (GeV/#it{c});Sigma(#pi)",varname.Data()),nBins,binlims);
1365  TH1F* hMeanPionTPCDataV0tag = new TH1F("hMeanPionTPCDataV0tag",Form(";%s (GeV/#it{c});Mean(#pi)",varname.Data()),nBins,binlims);
1366  TH1F* hSigmaPionTPCDataV0tag = new TH1F("hSigmaPionTPCDataV0tag",Form(";%s (GeV/#it{c});Sigma(#pi)",varname.Data()),nBins,binlims);
1367  SetTH1Style(hMeanPionTPCMCV0tag,markersMC[0],pdgcolors[kPion],1.,2,pdgcolors[kPion],kWhite,0.045,0.055);
1368  SetTH1Style(hSigmaPionTPCMCV0tag,markersMC[0],pdgcolors[kPion],1.,2,pdgcolors[kPion],kWhite,0.045,0.055);
1369  SetTH1Style(hMeanPionTPCDataV0tag,markersData[0],pdgcolors[kPion]+1,1.,2,pdgcolors[kPion]+1,kWhite,0.045,0.055);
1370  SetTH1Style(hSigmaPionTPCDataV0tag,markersData[0],pdgcolors[kPion]+1,1.,2,pdgcolors[kPion]+1,kWhite,0.045,0.055);
1371 
1372  TH1F* hMeanKaonTPCMCTOFtag = new TH1F("hMeanKaonTPCMCTOFtag",Form(";%s (GeV/#it{c});Mean(#pi)",varname.Data()),nBins,binlims);
1373  TH1F* hSigmaKaonTPCMCTOFtag = new TH1F("hSigmaKaonTPCMCTOFtag",Form(";%s (GeV/#it{c});Sigma(#pi)",varname.Data()),nBins,binlims);
1374  TH1F* hMeanKaonTPCDataTOFtag = new TH1F("hMeanKaonTPCDataTOFtag",Form(";%s (GeV/#it{c});Mean(#pi)",varname.Data()),nBins,binlims);
1375  TH1F* hSigmaKaonTPCDataTOFtag = new TH1F("hSigmaKaonTPCDataTOFtag",Form(";%s (GeV/#it{c});Sigma(#pi)",varname.Data()),nBins,binlims);
1376  SetTH1Style(hMeanKaonTPCMCTOFtag,markersMC[0],pdgcolors[kKaon],1.,2,pdgcolors[kKaon],kWhite,0.045,0.055);
1377  SetTH1Style(hSigmaKaonTPCMCTOFtag,markersMC[0],pdgcolors[kKaon],1.,2,pdgcolors[kKaon],kWhite,0.045,0.055);
1378  SetTH1Style(hMeanKaonTPCDataTOFtag,markersData[0],pdgcolors[kKaon]+1,1.,2,pdgcolors[kKaon]+1,kWhite,0.045,0.055);
1379  SetTH1Style(hSigmaKaonTPCDataTOFtag,markersData[0],pdgcolors[kKaon]+1,1.,2,pdgcolors[kKaon]+1,kWhite,0.045,0.055);
1380 
1381  TH1F* hMeanProtonTPCMCV0tag = new TH1F("hMeanProtonTPCMCV0tag",Form(";%s (GeV/#it{c});Mean(#pi)",varname.Data()),nBins,binlims);
1382  TH1F* hSigmaProtonTPCMCV0tag = new TH1F("hSigmaProtonTPCMCV0tag",Form(";%s (GeV/#it{c});Sigma(#pi)",varname.Data()),nBins,binlims);
1383  TH1F* hMeanProtonTPCDataV0tag = new TH1F("hMeanProtonTPCDataV0tag",Form(";%s (GeV/#it{c});Mean(#pi)",varname.Data()),nBins,binlims);
1384  TH1F* hSigmaProtonTPCDataV0tag = new TH1F("hSigmaProtonTPCDataV0tag",Form(";%s (GeV/#it{c});Sigma(#pi)",varname.Data()),nBins,binlims);
1385  SetTH1Style(hMeanProtonTPCMCV0tag,markersMC[0],pdgcolors[kProton],1.,2,pdgcolors[kProton],kWhite,0.045,0.055);
1386  SetTH1Style(hSigmaProtonTPCMCV0tag,markersMC[0],pdgcolors[kProton],1.,2,pdgcolors[kProton],kWhite,0.045,0.055);
1387  SetTH1Style(hMeanProtonTPCDataV0tag,markersData[0],pdgcolors[kProton]+1,1.,2,pdgcolors[kProton]+1,kWhite,0.045,0.055);
1388  SetTH1Style(hSigmaProtonTPCDataV0tag,markersData[0],pdgcolors[kProton]+1,1.,2,pdgcolors[kProton]+1,kWhite,0.045,0.055);
1389 
1390  TLegend* legPionPars = new TLegend(0.8,0.7,0.99,0.89);
1391  legPionPars->SetTextSize(0.045);
1392  legPionPars->AddEntry(hMeanPionTPCMCV0tag,"MC","p");
1393  legPionPars->AddEntry(hMeanPionTPCDataV0tag,"V0 tag","p");
1394  TLegend* legKaonPars = new TLegend(0.8,0.7,0.99,0.89);
1395  legKaonPars->SetTextSize(0.045);
1396  legKaonPars->AddEntry(hMeanKaonTPCMCTOFtag,"MC","p");
1397  legKaonPars->AddEntry(hMeanKaonTPCDataTOFtag,"TOF tag","p");
1398  TLegend* legProtonPars = new TLegend(0.8,0.7,0.99,0.89);
1399  legProtonPars->SetTextSize(0.045);
1400  legProtonPars->AddEntry(hMeanProtonTPCMCV0tag,"MC","p");
1401  legProtonPars->AddEntry(hMeanProtonTPCDataV0tag,"V0 tag","p");
1402 
1403  for(int iBin=0; iBin<nBins; iBin++) {
1404  hMeanPionTPCMCV0tag->SetBinContent(iBin+1,fNsigmaTPCPionMCV0tag[iBin][kPion]->GetParameter(1));
1405  hMeanPionTPCMCV0tag->SetBinError(iBin+1,1.e-20);
1406  hSigmaPionTPCMCV0tag->SetBinContent(iBin+1,fNsigmaTPCPionMCV0tag[iBin][kPion]->GetParameter(2));
1407  hSigmaPionTPCMCV0tag->SetBinError(iBin+1,1.e-20);
1408  hMeanPionTPCDataV0tag->SetBinContent(iBin+1,fNsigmaTPCPionDataV0tag[iBin][kPion]->GetParameter(1));
1409  hMeanPionTPCDataV0tag->SetBinError(iBin+1,1.e-20);
1410  hSigmaPionTPCDataV0tag->SetBinContent(iBin+1,fNsigmaTPCPionDataV0tag[iBin][kPion]->GetParameter(2));
1411  hSigmaPionTPCDataV0tag->SetBinError(iBin+1,1.e-20);
1412 
1413  hMeanKaonTPCMCTOFtag->SetBinContent(iBin+1,fNsigmaTPCKaonMCTOFtag[iBin][kKaon]->GetParameter(1));
1414  hMeanKaonTPCMCTOFtag->SetBinError(iBin+1,1.e-20);
1415  hSigmaKaonTPCMCTOFtag->SetBinContent(iBin+1,fNsigmaTPCKaonMCTOFtag[iBin][kKaon]->GetParameter(2));
1416  hSigmaKaonTPCMCTOFtag->SetBinError(iBin+1,1.e-20);
1417  hMeanKaonTPCDataTOFtag->SetBinContent(iBin+1,fNsigmaTPCKaonDataTOFtag[iBin][kKaon]->GetParameter(1));
1418  hMeanKaonTPCDataTOFtag->SetBinError(iBin+1,1.e-20);
1419  hSigmaKaonTPCDataTOFtag->SetBinContent(iBin+1,fNsigmaTPCKaonDataTOFtag[iBin][kKaon]->GetParameter(2));
1420  hSigmaKaonTPCDataTOFtag->SetBinError(iBin+1,1.e-20);
1421 
1422  hMeanProtonTPCMCV0tag->SetBinContent(iBin+1,fNsigmaTPCProtonMCV0tag[iBin][kProton]->GetParameter(1));
1423  hMeanProtonTPCMCV0tag->SetBinError(iBin+1,1.e-20);
1424  hSigmaProtonTPCMCV0tag->SetBinContent(iBin+1,fNsigmaTPCProtonMCV0tag[iBin][kProton]->GetParameter(2));
1425  hSigmaProtonTPCMCV0tag->SetBinError(iBin+1,1.e-20);
1426  hMeanProtonTPCDataV0tag->SetBinContent(iBin+1,fNsigmaTPCProtonDataV0tag[iBin][kProton]->GetParameter(1));
1427  hMeanProtonTPCDataV0tag->SetBinError(iBin+1,1.e-20);
1428  hSigmaProtonTPCDataV0tag->SetBinContent(iBin+1,fNsigmaTPCProtonDataV0tag[iBin][kProton]->GetParameter(2));
1429  hSigmaProtonTPCDataV0tag->SetBinError(iBin+1,1.e-20);
1430  }
1431 
1432  TCanvas* cMeanSigma = new TCanvas("cMeanSigma","",1920,1080);
1433  cMeanSigma->Divide(3,2);
1434  cMeanSigma->cd(1)->DrawFrame(binlims[0],-3.,binlims[nBins],3.,Form(";%s (GeV/#it{c});mean #it{N}_{#sigma}(#pi)",varname.Data()));
1435  hMeanPionTPCMCV0tag->Draw("same");
1436  hMeanPionTPCDataV0tag->Draw("same");
1437  legPionPars->Draw();
1438  cMeanSigma->cd(2)->DrawFrame(binlims[0],-3.,binlims[nBins],3.,Form(";%s (GeV/#it{c});mean #it{N}_{#sigma}(K)",varname.Data()));
1439  hMeanKaonTPCMCTOFtag->Draw("same");
1440  hMeanKaonTPCDataTOFtag->Draw("same");
1441  legKaonPars->Draw();
1442  cMeanSigma->cd(3)->DrawFrame(binlims[0],-3.,binlims[nBins],3.,Form(";%s (GeV/#it{c});mean #it{N}_{#sigma}(p)",varname.Data()));
1443  hMeanProtonTPCMCV0tag->Draw("same");
1444  hMeanProtonTPCDataV0tag->Draw("same");
1445  legProtonPars->Draw();
1446  cMeanSigma->cd(4)->DrawFrame(binlims[0],0.,binlims[nBins],3.,Form(";%s (GeV/#it{c});width #it{N}_{#sigma}(#pi)",varname.Data()));
1447  hSigmaPionTPCMCV0tag->Draw("same");
1448  hSigmaPionTPCDataV0tag->Draw("same");
1449  legPionPars->Draw();
1450  cMeanSigma->cd(5)->DrawFrame(binlims[0],0.,binlims[nBins],3.,Form(";%s (GeV/#it{c});width #it{N}_{#sigma}(K)",varname.Data()));
1451  hSigmaKaonTPCMCTOFtag->Draw("same");
1452  hSigmaKaonTPCDataTOFtag->Draw("same");
1453  legKaonPars->Draw();
1454  cMeanSigma->cd(6)->DrawFrame(binlims[0],0.,binlims[nBins],3.,Form(";%s (GeV/#it{c});width #it{N}_{#sigma}(p)",varname.Data()));
1455  hSigmaProtonTPCMCV0tag->Draw("same");
1456  hSigmaProtonTPCDataV0tag->Draw("same");
1457  legProtonPars->Draw();
1458 
1459  //********************************************************************************************************************************************//
1460  //output files
1461  TFile outfile(Form("%s/PIDSystSingleTrack.root",outputdirName.Data()),"RECREATE");
1462  for(int iEff=0; iEff<nEff; iEff++) {
1463  hEffPionTPCMCtrue[iEff]->Write();
1464  hEffPionTOFMCtrue[iEff]->Write();
1465  hEffKaonTPCMCtrue[iEff]->Write();
1466  hEffKaonTOFMCtrue[iEff]->Write();
1467  hEffProtonTPCMCtrue[iEff]->Write();
1468  hEffProtonTOFMCtrue[iEff]->Write();
1469  hEffPionTPCDataV0tag[iEff]->Write();
1470  hEffPionTOFDataV0tag[iEff]->Write();
1471  hEffKaonTPCDataKinktag[iEff]->Write();
1472  hEffKaonTPCDataTOFtag[iEff]->Write();
1473  hEffKaonTOFDataTPCtag[iEff]->Write();
1474  hEffProtonTPCDataV0tag[iEff]->Write();
1475  hEffProtonTOFDataV0tag[iEff]->Write();
1476  hRatioEffPionTPCDataV0tag[iEff]->Write();
1477  hRatioEffPionTOFDataV0tag[iEff]->Write();
1478  hRatioEffKaonTPCDataKinktag[iEff]->Write();
1479  hRatioEffKaonTPCDataTOFtag[iEff]->Write();
1480  hRatioEffKaonTOFDataTPCtag[iEff]->Write();
1481  hRatioEffProtonTPCDataV0tag[iEff]->Write();
1482  hRatioEffProtonTOFDataV0tag[iEff]->Write();
1483  }
1484  outfile.Close();
1485 
1486  TFile outfiledist(Form("%s/NsigmaPIDdist.root",outputdirName.Data()),"RECREATE");
1487  hMeanPionTPCMCV0tag->Write();
1488  hMeanPionTPCDataV0tag->Write();
1489  hMeanKaonTPCMCTOFtag->Write();
1490  hMeanKaonTPCDataTOFtag->Write();
1491  hMeanProtonTPCMCV0tag->Write();
1492  hMeanProtonTPCDataV0tag->Write();
1493  hSigmaPionTPCMCV0tag->Write();
1494  hSigmaPionTPCDataV0tag->Write();
1495  hSigmaKaonTPCMCTOFtag->Write();
1496  hSigmaKaonTPCDataTOFtag->Write();
1497  hSigmaProtonTPCMCV0tag->Write();
1498  hSigmaProtonTPCDataV0tag->Write();
1499 
1500  for(int iBin=0; iBin<nBins; iBin++) {
1501  hNsigmaTPCPionMCTrue[iBin]->Write();
1502  hNsigmaTPCKaonMCTrue[iBin]->Write();
1503  hNsigmaTPCProtonMCTrue[iBin]->Write();
1504  hNsigmaTOFPionMCTrue[iBin]->Write();
1505  hNsigmaTOFKaonMCTrue[iBin]->Write();
1506  hNsigmaTOFProtonMCTrue[iBin]->Write();
1507  }
1508  for(int iBin=0; iBin<nBins; iBin++) {
1509  for(int iPart=kElectron; iPart<=kAll; iPart++) {
1510  hNsigmaTPCPionMCV0tag[iBin][iPart]->Write();
1511  hNsigmaTPCKaonMCKinktag[iBin][iPart]->Write();
1512  hNsigmaTPCKaonMCTOFtag[iBin][iPart]->Write();
1513  hNsigmaTPCProtonMCV0tag[iBin][iPart]->Write();
1514  hNsigmaTOFPionMCV0tag[iBin][iPart]->Write();
1515  hNsigmaTOFKaonMCKinktag[iBin][iPart]->Write();
1516  hNsigmaTOFKaonMCTPCtag[iBin][iPart]->Write();
1517  hNsigmaTOFProtonMCV0tag[iBin][iPart]->Write();
1518 
1519  }
1520  }
1521  for(int iBin=0; iBin<nBins; iBin++) {
1522  hNsigmaTPCPionDataV0tag[iBin]->Write();
1523  hNsigmaTPCKaonDataKinktag[iBin]->Write();
1524  hNsigmaTPCKaonDataTOFtag[iBin]->Write();
1525  hNsigmaTPCProtonDataV0tag[iBin]->Write();
1526  hNsigmaTOFPionDataV0tag[iBin]->Write();
1527  hNsigmaTOFKaonDataKinktag[iBin]->Write();
1528  hNsigmaTOFKaonDataTPCtag[iBin]->Write();
1529  hNsigmaTOFProtonDataV0tag[iBin]->Write();
1530  }
1531  for(int iBin=0; iBin<nBins; iBin++) {
1532  hNsigmaTOFPionDataV0tag_sub[iBin]->Write();
1533  hNsigmaTOFKaonDataKinktag_sub[iBin]->Write();
1534  hNsigmaTOFKaonDataTPCtag_sub[iBin]->Write();
1535  hNsigmaTOFProtonDataV0tag_sub[iBin]->Write();
1536  }
1537  for(int iBin=0; iBin<nBins; iBin++) {
1538  for(int iPart=kElectron; iPart<=kProton; iPart++) {
1539  fNsigmaTPCPionMCV0tag[iBin][iPart]->Write();
1540  fNsigmaTPCKaonMCKinktag[iBin][iPart]->Write();
1541  fNsigmaTPCKaonMCTOFtag[iBin][iPart]->Write();
1542  fNsigmaTPCProtonMCV0tag[iBin][iPart]->Write();
1543  }
1544  }
1545  for(int iBin=0; iBin<nBins; iBin++) {
1546  for(int iPart=kElectron; iPart<=kAll; iPart++) {
1547  fNsigmaTPCPionDataV0tag[iBin][iPart]->Write();
1548  fNsigmaTPCKaonDataKinktag[iBin][iPart]->Write();
1549  fNsigmaTPCKaonDataTOFtag[iBin][iPart]->Write();
1550  fNsigmaTPCProtonDataV0tag[iBin][iPart]->Write();
1551  }
1552  }
1553  for(int iBin=0; iBin<nBins; iBin++) {
1554  for(int iPart=kElectron; iPart<=kAll; iPart++) {
1555  if(hNsigmaTOFKaonDataTPCtag_Fit[iBin][iPart]) hNsigmaTOFKaonDataTPCtag_Fit[iBin][iPart]->Write();
1556  if(hNsigmaTOFProtonDataV0tag_Fit[iBin][iPart]) hNsigmaTOFProtonDataV0tag_Fit[iBin][iPart]->Write();
1557  }
1558  }
1559  for(int iPart=kElectron; iPart<=kProton; iPart++) {
1560  hFractionTPCPionMCV0tag[iPart]->Write();
1561  hFractionTPCKaonMCKinktag[iPart]->Write();
1562  hFractionTPCKaonMCTOFtag[iPart]->Write();
1563  hFractionTPCProtonMCV0tag[iPart]->Write();
1564  hFractionTOFPionMCV0tag[iPart]->Write();
1565  hFractionTOFKaonMCKinktag[iPart]->Write();
1566  hFractionTOFKaonMCTPCtag[iPart]->Write();
1567  hFractionTOFProtonMCV0tag[iPart]->Write();
1568  }
1569  for(int iPart=kElectron; iPart<=kProton; iPart++) {
1570  hFractionTOFKaonDataTPCtag[iPart]->Write();
1571  hFractionTOFProtonDataV0tag[iPart]->Write();
1572  }
1573  outfiledist.Close();
1574 
1575  cFractionTPCMC->SaveAs(Form("%s/ParticleFractionsTPCMC.pdf",outputdirName.Data()));
1576  cFractionTOFMC->SaveAs(Form("%s/ParticleFractionsTOFMC.pdf",outputdirName.Data()));
1577  cTOFFractionData->SaveAs(Form("%s/ParticleFractionsTOFdata.pdf",outputdirName.Data()));
1578 
1579  cFitResultTOFKaonFromTPCtag->SaveAs(Form("%s/TFractionFitterResultTOFKaonFromTPCtag.pdf",outputdirName.Data()));
1580  cFitResultTOFProtonFromV0tag->SaveAs(Form("%s/TFractionFitterResultTOFProtonFromV0tag.pdf",outputdirName.Data()));
1581 
1582  cPionMCV0tagTPC->SaveAs(Form("%s/PionMCV0tagTPC.pdf",outputdirName.Data()));
1583  cKaonMCKinkstagTPC->SaveAs(Form("%s/KaonMCKinkstagTPC.pdf",outputdirName.Data()));
1584  cKaonMCTOFtagTPC->SaveAs(Form("%s/KaonMCTOFtagTPC.pdf",outputdirName.Data()));
1585  cProtonMCV0tagTPC->SaveAs(Form("%s/ProtonMCV0tagTPC.pdf",outputdirName.Data()));
1586  cPionMCV0tagTOF->SaveAs(Form("%s/PionMCV0tagTOF.pdf",outputdirName.Data()));
1587  cKaonMCKinkstagTOF->SaveAs(Form("%s/KaonMCKinkstagTOF.pdf",outputdirName.Data()));
1588  cKaonMCTPCtagTOF->SaveAs(Form("%s/KaonMCTPCtagTOF.pdf",outputdirName.Data()));
1589  cProtonMCV0tagTOF->SaveAs(Form("%s/ProtonMCV0tagTOF.pdf",outputdirName.Data()));
1590 
1591  cPionDataV0tagTPC->SaveAs(Form("%s/PionDataV0tagTPC.pdf",outputdirName.Data()));
1592  cKaonDataKinkstagTPC->SaveAs(Form("%s/KaonDataKinkstagTPC.pdf",outputdirName.Data()));
1593  cKaonDataTOFtagTPC->SaveAs(Form("%s/KaonDataTOFtagTPC.pdf",outputdirName.Data()));
1594  cProtonDataV0tagTPC->SaveAs(Form("%s/ProtonDataV0tagTPC.pdf",outputdirName.Data()));
1595  cPionDataV0tagTOF->SaveAs(Form("%s/PionDataV0tagTOF.pdf",outputdirName.Data()));
1596  cKaonDataKinkstagTOF->SaveAs(Form("%s/KaonDataKinkstagTOF.pdf",outputdirName.Data()));
1597  cKaonDataTPCtagTOF->SaveAs(Form("%s/KaonDataTPCtagTOF.pdf",outputdirName.Data()));
1598  cProtonDataV0tagTOF->SaveAs(Form("%s/ProtonDataV0tagTOF.pdf",outputdirName.Data()));
1599 
1600  cEffPion->SaveAs(Form("%s/PionPIDefficiency_data_MC.pdf",outputdirName.Data()));
1601  cEffKaon->SaveAs(Form("%s/KaonPIDefficiency_data_MC.pdf",outputdirName.Data()));
1602  cEffProton->SaveAs(Form("%s/ProtonPIDefficiency_data_MC.pdf",outputdirName.Data()));
1603 
1604  cMeanSigma->SaveAs(Form("%s/NsigmaTPCDistrPars_data_MC.pdf",outputdirName.Data()));
1605  return 0;
1606 }
1607 
1608 //_____________________________________________________
1609 int GetHistoParticleIndex(short pdgcode) {
1610  switch(pdgcode) {
1611  case 11:
1612  return kElectron;
1613  break;
1614  case 13:
1615  return kMuon;
1616  break;
1617  case 211:
1618  return kPion;
1619  break;
1620  case 321:
1621  return kKaon;
1622  break;
1623  case 2212:
1624  return kProton;
1625  break;
1626  }
1627  return -1;
1628 }
1629 
1630 //_____________________________________________________
1631 int FindPtbin(float pt, const double binlims[], int nBins) {
1632 
1633  int ptbin=-1;
1634  for(int iBin=0; iBin<nBins; iBin++) {
1635  if(pt>binlims[iBin] && pt<binlims[iBin+1]) {
1636  ptbin=iBin;
1637  break;
1638  }
1639  }
1640 
1641  return ptbin;
1642 }
1643 
1644 //______________________________________________________
1645 void ComputeEfficiency(double num, double den, double &eff, double &effunc) {
1646 
1647  TH1F htmpnum("htmpnum","",1,0,1);
1648  TH1F htmpden("htmpden","",1,0,1);
1649  TH1F htmpratio("htmpratio","",1,0,1);
1650 
1651  htmpnum.SetBinContent(1,num);
1652  htmpden.SetBinContent(1,den);
1653  htmpnum.SetBinError(1,TMath::Sqrt(num));
1654  htmpden.SetBinError(1,TMath::Sqrt(den));
1655  htmpratio.Divide(&htmpnum,&htmpden,1.,1.,"B");
1656  eff=htmpratio.GetBinContent(1);
1657  effunc=htmpratio.GetBinError(1);
1658 }
1659 
1660 //______________________________________________________
1661 void GetTOFFractionsFromData(int whichpart, int iBin, TH1F* hFractionMC[nPDGcodes-1], TH1F* hFractionData[nPDGcodes-1], TH1F* hNsigmaMC[nPDGcodes], TH1F* hNsigmaData, TFractionFitter *&fNsigmaFitter, vector<int> &templUsed) {
1662 
1663  TObjArray* oNsigmaMC = new TObjArray(0);
1664 
1665  for(int iPart=kElectron; iPart<=kProton; iPart++) {
1666  if(iPart==whichpart || hFractionMC[iPart]->GetBinContent(iBin+1)>1.e-5) {
1667  TH1F* hMC = (TH1F*)hNsigmaMC[iPart]->Clone(Form("hMC_%d_%s",iBin,pdgnames[iPart].Data()));
1668  oNsigmaMC->AddLast(hMC);
1669  templUsed.push_back(iPart);
1670  }
1671  }
1672 
1673  if(templUsed.size()==1) {
1674  for(int iPart=kElectron; iPart<=kProton; iPart++) {
1675  if(iPart==whichpart) {
1676  hFractionData[iPart]->SetBinContent(iBin+1,1.);
1677  }
1678  else {
1679  hFractionData[iPart]->SetBinContent(iBin+1,0.);
1680  }
1681  }
1682  return;
1683  }
1684 
1685  if(oNsigmaMC->GetEntries()>1) {
1686 
1687  fNsigmaFitter = new TFractionFitter(hNsigmaData,oNsigmaMC);
1688  for(int iEntry=0; iEntry<oNsigmaMC->GetEntries(); iEntry++) {
1689  fNsigmaFitter->Constrain(iEntry,hFractionMC[templUsed[iEntry]]->GetBinContent(iBin+1)*0.5,hFractionMC[templUsed[iEntry]]->GetBinContent(iBin+1)*2);
1690  }
1691  fNsigmaFitter->Fit();
1692 
1693  for(int iPart=kElectron; iPart<=kProton; iPart++) {
1694 
1695  vector<int>::iterator it = find(templUsed.begin(), templUsed.end(), iPart);
1696  if(it!=templUsed.end()) {
1697  double frac, err;
1698  int iEntry = static_cast<int>(distance(templUsed.begin(),it));
1699 
1700  fNsigmaFitter->GetResult(iEntry, frac, err);
1701  hFractionData[iPart]->SetBinContent(iBin+1,frac);
1702  hFractionData[iPart]->SetBinError(iBin+1,err);
1703  }
1704  else {
1705  hFractionData[iPart]->SetBinContent(iBin+1,0);
1706  hFractionData[iPart]->SetBinError(iBin+1,0);
1707  }
1708  }
1709  }
1710  else {
1711  for(int iPart=kElectron; iPart<=kProton; iPart++) {
1712  if(iPart!=whichpart) {
1713  hFractionData[iPart]->SetBinContent(iBin+1,1);
1714  hFractionData[iPart]->SetBinError(iBin+1,1);
1715  }
1716  else {
1717  hFractionData[iPart]->SetBinContent(iBin+1,0);
1718  hFractionData[iPart]->SetBinError(iBin+1,0);
1719  }
1720  }
1721  }
1722 
1723 }
1724 
1725 //______________________________________________________
1726 double PDFnsigmaTPCtot(double* nsigma, double* pars) {
1727 
1728  double partpdf[nPDGcodes-1];
1729  double totalpdf = 0;
1730  for(int iPart=kElectron; iPart<=kProton; iPart++) {
1731  partpdf[iPart] = pars[3*iPart]*TMath::Gaus(nsigma[0],pars[3*iPart+1],pars[3*iPart+2]);
1732  totalpdf += partpdf[iPart];
1733  }
1734 
1735  return totalpdf;
1736 }
1737 
1738 //_____________________________________________________
1739 void PlotQAhistos(TList* listMC, TList* listData) {
1740 
1741  //V0 QA histos
1742  TString ArmenterosName[5] = {"All","K0s","Lambda","AntiLambda","Gamma"};
1743  TString legV0name[4] = {"K_{s}^{0} #rightarrow #pi^{+}#pi^{-}","#Lambda #rightarrow p#pi^{-}","#bar{#Lambda} #rightarrow #bar{p}#pi^{+}","#gamma #rightarrow e^{+}e^{-}"};
1744  int ArmenterosColor[5] = {kBlack,kOrange+7,kRed,kBlue,kGreen+3};
1745  TH2F* hArmenterosMC[5];
1746  TH2F* hArmenterosData[5];
1747 
1748  //kinks QA histos
1749  TString KinksName[5] = {"QtVsMassKinks","PDaughterVsMotherKink","OpeningAngleVsPMotherKink","dEdxVsPMotherKink","NTPCclsVsRadius"};
1750  TH2F* hKinksMC[5];
1751  TH2F* hKinksData[5];
1752 
1753  TCanvas* cArmentero = new TCanvas("cArmenteros","cArmenteros",1920,1080);
1754  TCanvas* cKinks = new TCanvas("cKinks","cKinks",1920,1080);
1755  cArmentero->Divide(2,1);
1756  cKinks->Divide(5,2);
1757  TLatex* latV0[5];
1758 
1759  for(int iHisto=0; iHisto<5; iHisto++) {
1760  hArmenterosMC[iHisto] = (TH2F*)listMC->FindObject(Form("fHistArmenteroPlot%s",ArmenterosName[iHisto].Data()));
1761  hArmenterosData[iHisto] = (TH2F*)listData->FindObject(Form("fHistArmenteroPlot%s",ArmenterosName[iHisto].Data()));
1762  hArmenterosMC[iHisto]->SetDirectory(0);
1763  hArmenterosData[iHisto]->SetDirectory(0);
1764  hArmenterosData[iHisto]->SetMarkerColor(ArmenterosColor[iHisto]);
1765  hArmenterosMC[iHisto]->SetMarkerColor(ArmenterosColor[iHisto]);
1766  hArmenterosData[iHisto]->GetYaxis()->SetTitleOffset(1.4);
1767  hArmenterosMC[iHisto]->GetYaxis()->SetTitleOffset(1.4);
1768  hArmenterosData[iHisto]->SetMarkerStyle(kFullCircle);
1769  hArmenterosMC[iHisto]->SetMarkerStyle(kFullCircle);
1770  hArmenterosData[iHisto]->SetMarkerSize(0.5);
1771  hArmenterosMC[iHisto]->SetMarkerSize(0.5);
1772  latV0[iHisto] = new TLatex();
1773  latV0[iHisto]->SetNDC();
1774  latV0[iHisto]->SetTextFont(42);
1775  latV0[iHisto]->SetTextColor(ArmenterosColor[iHisto]);
1776  latV0[iHisto]->SetTextSize(0.045);
1777  cArmentero->cd(1);
1778  hArmenterosMC[iHisto]->Draw("same");
1779  cArmentero->cd(2);
1780  hArmenterosData[iHisto]->Draw("same");
1781  if(iHisto!=0) {
1782  cArmentero->cd(1);
1783  latV0[iHisto]->DrawLatex(0.6,0.8-0.05*iHisto,legV0name[iHisto-1].Data());
1784  cArmentero->cd(2);
1785  latV0[iHisto]->DrawLatex(0.6,0.8-0.05*iHisto,legV0name[iHisto-1].Data());
1786  }
1787 
1788  hKinksMC[iHisto] = (TH2F*)listMC->FindObject(Form("fHist%s",KinksName[iHisto].Data()));
1789  hKinksData[iHisto] = (TH2F*)listData->FindObject(Form("fHist%s",KinksName[iHisto].Data()));
1790  hKinksMC[iHisto]->SetTitle("MC");
1791  hKinksData[iHisto]->SetTitle("Data");
1792 
1793  cKinks->cd(1+iHisto)->SetLogz();
1794  hKinksMC[iHisto]->Draw("colz");
1795  cKinks->cd(6+iHisto)->SetLogz();
1796  hKinksData[iHisto]->Draw("colz");
1797  }
1798 
1799  TH1F* hKinksMassMC = (TH1F*)hKinksMC[0]->ProjectionX("hKinksMassMC");
1800  hKinksMassMC->Scale(1./hKinksMassMC->Integral());
1801  hKinksMassMC->SetLineColor(kBlue);
1802  hKinksMassMC->SetLineWidth(2);
1803  hKinksMassMC->SetMarkerColor(kBlue);
1804  hKinksMassMC->SetMarkerStyle(kFullSquare);
1805  hKinksMassMC->SetTitle("");
1806  hKinksMassMC->GetYaxis()->SetTitle("Normalised entries");
1807  hKinksMassMC->GetYaxis()->SetTitleSize(0.045);
1808  hKinksMassMC->GetYaxis()->SetLabelSize(0.04);
1809  hKinksMassMC->GetXaxis()->SetTitleSize(0.045);
1810  hKinksMassMC->GetXaxis()->SetLabelSize(0.04);
1811 
1812  TH1F* hKinksMassData = (TH1F*)hKinksData[0]->ProjectionX("hKinksMassData");
1813  hKinksMassData->Scale(1./hKinksMassData->Integral());
1814  hKinksMassData->SetLineColor(kRed);
1815  hKinksMassData->SetLineWidth(2);
1816  hKinksMassData->SetMarkerColor(kRed);
1817  hKinksMassData->SetMarkerStyle(kFullDiamond);
1818  hKinksMassData->SetTitle("");
1819  hKinksMassData->GetYaxis()->SetTitle("Normalised entries");
1820  hKinksMassData->GetYaxis()->SetTitleSize(0.045);
1821  hKinksMassData->GetYaxis()->SetLabelSize(0.04);
1822  hKinksMassData->GetXaxis()->SetTitleSize(0.045);
1823  hKinksMassData->GetXaxis()->SetLabelSize(0.04);
1824 
1825  TLegend* leg = new TLegend(0.2,0.7,0.4,0.8);
1826  leg->SetTextSize(0.045);
1827  leg->AddEntry(hKinksMassMC,"MC","lpe");
1828  leg->AddEntry(hKinksMassData,"Data","lpe");
1829  TCanvas* cKinksMass = new TCanvas("cKinksMass","",800,800);
1830  cKinksMass->SetTopMargin(0.1);
1831  hKinksMassMC->Draw();
1832  hKinksMassData->Draw("same");
1833  leg->Draw("same");
1834 
1835  cArmentero->SaveAs(Form("%s/V0QAplots.pdf",outputdirName.Data()));
1836  cKinks->SaveAs(Form("%s/KinksQAplots.pdf",outputdirName.Data()));
1837  cKinksMass->SaveAs(Form("%s/KinksMass.pdf",outputdirName.Data()));
1838  cArmentero->SaveAs(Form("%s/V0QAplots.png",outputdirName.Data()));
1839  cKinks->SaveAs(Form("%s/KinksQAplots.png",outputdirName.Data()));
1840 }
1841 
1842 //_____________________________________________________
1843 void DivideCanvas(TCanvas* c, int nBins) {
1844  if(nBins<2)
1845  c->cd();
1846  else if(nBins==2 || nBins==3)
1847  c->Divide(nBins,1);
1848  else if(nBins==4 || nBins==6 || nBins==8)
1849  c->Divide(nBins/2,2);
1850  else if(nBins==5 || nBins==7)
1851  c->Divide((nBins+1)/2,2);
1852  else if(nBins==9 || nBins==12 || nBins==15)
1853  c->Divide(nBins/3,3);
1854  else if(nBins==10 || nBins==11)
1855  c->Divide(4,3);
1856  else if(nBins==13 || nBins==14)
1857  c->Divide(5,3);
1858  else if(nBins>15 && nBins<=20 && nBins%4==0)
1859  c->Divide(nBins/4,4);
1860  else if(nBins>15 && nBins<=20 && nBins%4!=0)
1861  c->Divide(5,4);
1862  else if(nBins==21)
1863  c->Divide(7,3);
1864  else if(nBins>21 && nBins<=25)
1865  c->Divide(5,5);
1866  else if(nBins>25 && nBins%2==0)
1867  c->Divide(nBins/2,2);
1868  else
1869  c->Divide((nBins+1)/2,2);
1870 }
1871 
1872 //_____________________________________________________
1873 void SetStyle() {
1874  gStyle->SetLegendBorderSize(1);
1875  gStyle->SetTitleOffset(1.4,"y");
1876  gStyle->SetTitleOffset(1.2,"x");
1877  gStyle->SetPadTopMargin(0.14);
1878  gStyle->SetPadRightMargin(0.035);
1879  gStyle->SetPadLeftMargin(0.14);
1880  gStyle->SetPadBottomMargin(0.14);
1881  gStyle->SetTitleSize(0.05,"xyzt");
1882  gStyle->SetLabelSize(0.045,"xyz");
1883 
1884  gStyle->SetPadTickX(1);
1885  gStyle->SetPadTickY(1);
1886  gStyle->SetOptStat(0);
1887 
1888  TGaxis::SetMaxDigits(3);
1889 }
1890 
1891 //_____________________________________________________
1892 void SetTH1Style(TH1F* histo, int markerstyle, int markercolor, float markersize, int linewidth, int linecolor, int fillcolor, float labelsize, float titlesize) {
1893 
1894  histo->SetMarkerStyle(markerstyle);
1895  histo->SetMarkerSize(markersize);
1896  histo->SetMarkerColor(markercolor);
1897  histo->SetLineWidth(linewidth);
1898  histo->SetLineColor(linecolor);
1899  histo->SetFillColorAlpha(fillcolor,0.25);
1900 
1901  if(labelsize>0) {
1902  histo->GetXaxis()->SetLabelSize(labelsize);
1903  histo->GetYaxis()->SetLabelSize(labelsize);
1904  }
1905  if(titlesize>0) {
1906  histo->GetXaxis()->SetTitleSize(labelsize);
1907  histo->GetYaxis()->SetTitleSize(labelsize);
1908  histo->SetTitleSize(labelsize);
1909  }
1910 }
const TString indirNameData
void Draw(const char *filename, const char *title="", const char *others="ALL", const char *options="DEFAULT", const char *outFlg="ALL", UShort_t rebin=5, Float_t eff=0, const char *base="")
Definition: DrawdNdeta.C:3603
Definition: External.C:236
const TString pdgnames[nPDGcodes]
const TString infileNameData
int EstimateSingleTrackPIDsyst(int maxEntries=1e9, int var4proj=kP)
double PDFnsigmaTPCtot(double *nsigma, double *pars)
TCanvas * c
Definition: TestFitELoss.C:172
const TString inlistNameMC
void SetTH1Style(TH1F *histo, int markerstyle, int markercolor, float markersize, int linewidth, int linecolor, int fillcolor, float labelsize=-1, float titlesize=-1)
const int pdgcodes[nPDGcodes]
void ComputeEfficiency(double num, double den, double &eff, double &effunc)
const TString indirNameMC
const int pdgcolors[nPDGcodes]
const TString inlistNameData
double absetamax
Double_t nsigma
const double binlims[]
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
double absetamin
void GetTOFFractionsFromData(int whichpart, int iBin, TH1F *hFractionMC[nPDGcodes-1], TH1F *hFractionData[nPDGcodes-1], TH1F *hNsigmaMC[nPDGcodes], TH1F *hNsigmaData, TFractionFitter *&fNsigmaFitter, vector< int > &templUsed)
void PlotQAhistos(TList *listMC, TList *listData)
const TString outputdirName
const int nPDGcodes
const TString infileNameMC
int FindPtbin(float pt, const double binlims[], int nBins)
void DivideCanvas(TCanvas *c, int nBins)
TList * listMC
int GetHistoParticleIndex(short pdgcode)
const int pdgfillcolors[nPDGcodes]