-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_SysTpcAndPid.C
362 lines (337 loc) · 13.5 KB
/
make_SysTpcAndPid.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#include "TStyle.h"
#include "TROOT.h"
#include "TDatime.h"
#include "TRandom3.h"
#include "TFile.h"
#include "TCanvas.h"
#include "TH1F.h"
#include "TH1D.h"
#include "TH2F.h"
#include "TH3F.h"
#include "TLorentzVector.h"
#include "THnSparse.h"
#include "TF1.h"
#include "TPaveText.h"
#include "TLine.h"
#include "TMath.h"
#include "TGraphErrors.h"
#include "TLegend.h"
#include <cmath>
using namespace std;
void getJpsiEff(const int savePlot, const int saveHisto);
TLorentzVector myBoost(TLorentzVector parent, TLorentzVector daughter);
TLorentzVector twoBodyDecay(TLorentzVector parent, double dmass);
void getJpsiEff(const double mass, const int nExpr, TH1F *hInputPt, TF1 *funcTpcTrkEff, TH1F *hMcJpsiPt, TH1F *hRcJpsiPt, int debug = 0);
TPaveText *GetTitleText(TString title, const Float_t size = 0.04, const Int_t font = 62);
TPaveText *GetPaveText(Double_t xl, Double_t xh, Double_t yl, Double_t yh, Double_t size = 0.04, const Int_t font = 42);
TCanvas *draw1D(TH1 *h, TString hTitle = "",Bool_t setLog = kFALSE, Bool_t drawP = kTRUE, const Float_t size = 0.04, const TString drawOpt = "", const Int_t titleFont = 62,
const Int_t wh = 800, const Int_t ww = 600);
const int year = 2014;
const char *run_type = "Run14_AuAu200";
const double jpsi_rapidity = 0.5;
const double pt1_cut = 1.5, pt2_cut = 1.3;
const int nPtBins_pt = 9;
const double xPtBins_pt[nPtBins_pt+1] = {0,1,2,3,4,5,6,8,10,15};
const int nCentBins_pt = 5;
const char *cent_Name_pt[nCentBins_pt] = {"0-80","0-20","20-40","40-60","60-80"};
const char *cent_Title_pt[nCentBins_pt] = {"0080","0020","2040","4060","6080"};
const int nPtBins_npart = 2;
const double ptBins_low_npart[nPtBins_npart] = {0,5};
const double ptBins_high_npart[nPtBins_npart] = {15,15};
const char *pt_Name_npart[nPtBins_npart] = {"0-15","5-15"};
const int nCentBins_npart[nPtBins_npart] = {9,8};
const char *cent_Name_npart[18] = {"0-80","0-10","10-20","20-30","30-40","40-50","50-60","60-70","70-80","0-80","0-10","10-20","20-30","30-40","40-50","50-60","60-80","60-70"};
const char *cent_Title_npart[18] = {"0080","0010","1020","2030","3040","4050","5060","6070","7080","0080","0010","1020","2030","3040","4050","5060","6080","6070"};
const TString sysType = "TpcTracking";
// const int nSys = 12;
// const TString sysName[nSys] = {"default",
// "dcaUp","dcaDown","NHitsUp","NDedxUp",
// "dcaUp_NHitsUp", "dcaUp_NDedxUp", "dcaUp_NHitsUp_NDedxUp",
// "dcaDown_NHitsUp", "dcaDown_NDedxUp", "dcaDown_NHitsUp_NDedxUp",
// "NHitsUp_NDedxUp"};
const int nSys = 5;
const TString sysName[nSys] = {"default", "dcaUp","dcaDown","NHitsUp","NDedxUp",};
// const TString sysType = "MuonPid";
// const int nSys = 27;
// const TString sysName[nSys] = {"default",
// "dzUp","dzDown","dyUp","dyDown","nSigPiUp","nSigPiDown",
// "dzUp_dyUp","dzUp_dyDown","dzUp_nSigPiUp","dzUp_nSigPiDown","dzUp_dyUp_nSigPiUp","dzUp_dyUp_nSigPiDown","dzUp_dyDown_nSigPiUp","dzUp_dyDown_nSigPiDown",
// "dzDown_dyUp","dzDown_dyDown","dzDown_nSigPiUp","dzDown_nSigPiDown","dzDown_dyUp_nSigPiUp","dzDown_dyUp_nSigPiDown","dzDown_dyDown_nSigPiUp","dzDown_dyDown_nSigPiDown",
// "dyUp_nSigPiUp","dyUp_nSigPiDown",
// "dyDown_nSigPiUp","dyDown_nSigPiDown"};
const double muMass = 0.1057;
const double jpsiMass = 3.906;
const double pi = 3.1415926;
TFile *f;
TCanvas *c;
TRandom3 *myRandom;
//================================================
void make_SysTpcAndPid()
{
gStyle->SetOptStat(0);
gStyle->SetOptFit(1);
gStyle->SetStatY(0.9);
gStyle->SetStatX(0.9);
gStyle->SetStatW(0.2);
gStyle->SetStatH(0.2);
myRandom = new TRandom3();
myRandom->SetSeed(0);
getJpsiEff(1,0);
}
//================================================
void getJpsiEff(const int savePlot, const int saveHisto)
{
const int nCentBins = 13;
const char* cent_Name[nCentBins] = {"00-80","00-20","20-40","40-60","60-80","00-10","10-20","20-30","30-40","40-50","50-60","60-70","70-80"};
const char* cent_Title[nCentBins] = {"0080","0020","2040","4060","6080","0010","1020","2030","3040","4050","5060","6070","7080"};
if(saveHisto) f = TFile::Open(Form("Rootfiles/%s.Sys.%s.root",run_type,sysType.Data()),"update");
else f = TFile::Open(Form("Rootfiles/%s.Sys.%s.root",run_type,sysType.Data()),"read");
const int nTrkPtBins = 13;
const double xTrkPtBins[14] = {0,0.2,0.4,0.6,0.8,1.0,1.2,1.5,2.0,2.5,3.0,5.0,10,20};
TString embed_name[2] = {"Mc","Tpc"};
if(sysType=="MuonPid") embed_name[1] = "Pid";
TH1F *hTrkPt[nCentBins][nSys][2];
TH1F *hTrkEffVsPt[nCentBins][nSys];
for(int k=0; k<nCentBins; k++)
{
for(int s=0; s<nSys; s++)
{
for(int i=0; i<2; i++)
{
TH1F *h1tmp = (TH1F*)f->Get(Form("Sys%s_TrkEffVsPtEmb_%s_cent%s",sysName[s].Data(),embed_name[i].Data(),cent_Title[k]));
hTrkPt[k][s][i] = (TH1F*)h1tmp->Rebin(nTrkPtBins, Form("%s_rebin",h1tmp->GetName()), xTrkPtBins);
}
hTrkEffVsPt[k][s] = (TH1F*)hTrkPt[k][s][1]->Clone(Form("Sys%s_TrkEffVsPtEmb_cent%s",sysName[s].Data(),cent_Title[k]));
hTrkEffVsPt[k][s]->Divide(hTrkPt[k][s][0]);
}
}
TF1 *funcTrkEff[nCentBins][nSys];
for(int k=0; k<nCentBins; k++)
{
c = new TCanvas(Form("TpcTrkEff_cent%s",cent_Title[k]),Form("TpcTrkEff_cent%s",cent_Title[k]),1100,700);
if(sysType=="TpcTracking") c->Divide(3,2);
if(sysType=="MuonPid") c->Divide(7,4);
for(int s=0; s<nSys; s++)
{
funcTrkEff[k][s] = new TF1(Form("Sys%s_TrkEffVsPtEmb_cent%s_FitFunc",sysName[s].Data(),cent_Title[k]),"[0]-exp([1]+[2]*x+[3]*x*x)",1,20);
if(k==0) funcTrkEff[k][s]->SetParameters(0.7,-2,0.2);
else
{
funcTrkEff[k][s]->FixParameter(1, funcTrkEff[0][0]->GetParameter(1));
funcTrkEff[k][s]->FixParameter(2, funcTrkEff[0][0]->GetParameter(2));
}
hTrkEffVsPt[k][s]->Fit(funcTrkEff[k][s], "R0Q");
hTrkEffVsPt[k][s]->SetMarkerStyle(20);
hTrkEffVsPt[k][s]->GetXaxis()->SetRangeUser(0.2, 10);
if(sysType=="TpcTracking")
{
if(k==4 || k>=10) hTrkEffVsPt[k][s]->GetYaxis()->SetRangeUser(0.3,1.2);
else hTrkEffVsPt[k][s]->GetYaxis()->SetRangeUser(0.5,0.8);
}
else if(sysType=="MuonPid")
{
hTrkEffVsPt[k][s]->GetYaxis()->SetRangeUser(0,0.5);
}
hTrkEffVsPt[k][s]->SetTitle(";p_{T} (GeV/c);TPC efficiency");
c->cd(s+1);
hTrkEffVsPt[k][s]->Draw();
funcTrkEff[k][s]->SetLineColor(4);
funcTrkEff[k][s]->SetLineStyle(2);
funcTrkEff[k][s]->SetLineWidth(2);
funcTrkEff[k][s]->Draw("sames");
TPaveText *t1 = GetTitleText(sysName[s].Data(),0.06);
t1->Draw();
t1 = GetPaveText(0.6,0.7,0.75,0.8,0.07);
t1->AddText(Form("p0 = %2.2f",funcTrkEff[k][s]->GetParameter(0)));
t1->SetTextColor(4);
t1->Draw();
}
c->cd(1);
TLegend *leg0 = new TLegend(0.2,0.2,0.7,0.4);
leg0->SetBorderSize(0);
leg0->SetFillColor(0);
leg0->SetTextSize(0.06);
leg0->SetHeader(Form("%s: %s%%",run_type,cent_Name[k]));
leg0->AddEntry(hTrkEffVsPt[0][k], "Embedding", "P");
leg0->AddEntry(funcTrkEff[0][k], "Fit function: p0-e^{p1*(x-p2)}", "L");
leg0->Draw();
if(savePlot) c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/sys_TpcAndPid/%s_FitTrkEffVsPtEmb_cent%s.pdf",run_type,sysType.Data(),cent_Title[k]));
}
return;
// get J/psi efficiency
const int nExpr = 1e6;
TFile *fWeight = TFile::Open("Rootfiles/models.root","read");
TH1F *hInputJpsi = (TH1F*)fWeight->Get("TBW_JpsiYield_AuAu200_cent0060");
TH1F *hMcJpsiPt[nCentBins][nSys];
TH1F *hRcJpsiPt[nCentBins][nSys];
for(int k=0; k<nCentBins; k++)
{
for(int s=0; s<nSys; s++)
{
hMcJpsiPt[k][s] = new TH1F(Form("Sys%s_JpsiPtMc_cent%s",sysName[s].Data(),cent_Title[k]),";p_{T} (GeV/c)",nPtBins_pt,xPtBins_pt);
hMcJpsiPt[k][s]->Sumw2();
hRcJpsiPt[k][s] = new TH1F(Form("Sys%s_JpsiPtRc_cent%s",sysName[s].Data(),cent_Title[k]),";p_{T} (GeV/c)",nPtBins_pt,xPtBins_pt);
hRcJpsiPt[k][s]->Sumw2();
}
}
for(int k=0; k<nCentBins; k++)
{
for(int s=0; s<nSys; s++)
{
printf("[i] %s, centrality %s%%,\n",sysName[s].Data(), cent_Name[k]);
getJpsiEff(jpsiMass, nExpr, hInputJpsi, funcTrkEff[k][s], hMcJpsiPt[k][s], hRcJpsiPt[k][s], 0);
}
}
// efficeincy vs. pT
TH1F *hJpsiEffVsPt[nCentBins_pt][nSys];
for(int k=0; k<nCentBins_pt; k++)
{
for(int s=0; s<nSys; s++)
{
hJpsiEffVsPt[k][s] = (TH1F*)hRcJpsiPt[k][s]->Clone(Form("Sys%s_JpsiEffVsPtEmb_cent%s",sysName[s].Data(),cent_Title_pt[k]));
hJpsiEffVsPt[k][s]->Divide(hMcJpsiPt[k][s]);
}
}
c = draw1D(hJpsiEffVsPt[0][0]);
// efficicy vs. centrality
TH1F *hJpsiEffVsCent[nPtBins_npart][nSys];
for(int i=0; i<nPtBins_npart; i++)
{
for(int s=0; s<nSys; s++)
{
hJpsiEffVsCent[i][s] = new TH1F(Form("Sys%s_JpsiEffVsCentEmb_Pt%1.0f",sysName[s].Data(),ptBins_low_npart[i]),"",nCentBins_npart[i],0,nCentBins_npart[i]);
for(int k=0; k<nCentBins_npart[i]; k++)
{
int index;
if(k==0) index = 0;
else index = k+nCentBins_pt -1;
if(i==1 && k==nCentBins_npart[i]-1) index = 4;
int low_bin = hMcJpsiPt[index][s]->FindFixBin(ptBins_low_npart[i]+1e-4);
int up_bin = hMcJpsiPt[index][s]->FindFixBin(ptBins_high_npart[i]-1e-4);
double nMcJpsi_err, nRcJpsi_err;
double nMcJpsi = hMcJpsiPt[index][s]->IntegralAndError(low_bin, up_bin, nMcJpsi_err);
double nRcJpsi = hRcJpsiPt[index][s]->IntegralAndError(low_bin, up_bin, nRcJpsi_err);
double eff = nRcJpsi/nMcJpsi;
hJpsiEffVsCent[i][s]->SetBinContent(k+1, eff);
hJpsiEffVsCent[i][s]->SetBinError(k+1, eff*nRcJpsi_err/nRcJpsi);
}
}
}
c = draw1D(hJpsiEffVsCent[1][0]);
if(saveHisto)
{
f->cd();
for(int k=0; k<nCentBins_pt; k++)
{
for(int s=0; s<nSys; s++)
{
hJpsiEffVsPt[k][s]->Write("",TObject::kOverwrite);
}
}
for(int i=0; i<nPtBins_npart; i++)
{
for(int s=0; s<nSys; s++)
{
hJpsiEffVsCent[i][s]->Write("",TObject::kOverwrite);
}
}
}
}
//-------------------------------------------------------
void getJpsiEff(const double mass, const int nExpr, TH1F *hInputPt, TF1 *funcTpcTrkEff, TH1F *hMcJpsiPt, TH1F *hRcJpsiPt, int debug)
{
for(int i=0; i<nExpr; i++)
{
double mc_pt = myRandom->Uniform(0,15);
double weight = hInputPt->GetBinContent(hInputPt->FindFixBin(mc_pt));
double mc_phi = myRandom->Uniform(-1*pi, pi);
double mc_y = myRandom->Uniform(-0.5, 0.5);
double mc_px = mc_pt * TMath::Cos(mc_phi);
double mc_py = mc_pt * TMath::Sin(mc_phi);
double mc_pz = sqrt(mc_pt*mc_pt+mass*mass) * TMath::SinH(mc_y);
TLorentzVector parent;
parent.SetXYZM(mc_px,mc_py,mc_pz,mass);
if(debug) printf("parent: pt = %3.2f eta = %3.2f phi = %3.2f\n",parent.Pt(),parent.Eta(),parent.Phi());
TLorentzVector daughter1 = twoBodyDecay(parent,muMass);
TLorentzVector daughter2 = parent - daughter1;
double pt1 = daughter1.Pt();
double eta1 = daughter1.Eta();
double phi1 = daughter1.Phi();
if(debug) printf("daugther 1: pt = %3.2f eta = %3.2f phi = %3.2f\n",pt1,eta1,phi1);
double pt2 = daughter2.Pt();
double eta2 = daughter2.Eta();
double phi2 = daughter2.Phi();
if(debug) printf("daugther 2: pt = %3.2f eta = %3.2f phi = %3.2f\n",pt2,eta2,phi2);
hMcJpsiPt->Fill(parent.Pt(), weight);
if(fabs(eta1) > 0.5 || fabs(eta2) > 0.5) continue;
if(pt1<1.3 || pt2<1.3) continue;
if(pt1<1.5 && pt2<1.5) continue;
double eff1 = funcTpcTrkEff->Eval(pt1);
double eff2 = funcTpcTrkEff->Eval(pt2);
hRcJpsiPt->Fill(parent.Pt(), weight*eff1*eff2);
}
}
//-------------------------------------------------------
TLorentzVector myBoost(TLorentzVector parent, TLorentzVector daughter)
{
float betax = parent.Px()/parent.E();
float betay = parent.Py()/parent.E();
float betaz = parent.Pz()/parent.E();
daughter.Boost(betax,betay,betaz);
return daughter;
}
//-------------------------------------------------------
TLorentzVector twoBodyDecay(TLorentzVector parent, Double_t dmass)
{
Double_t e = parent.M()/2.;
Double_t p = sqrt(e*e-dmass*dmass);
Double_t costheta = myRandom->Uniform(-1.,1.);
Double_t phi = myRandom->Uniform(0,TMath::Pi()*2);
Double_t pz = p*costheta;
Double_t px = p*sqrt(1.-costheta*costheta)*cos(phi);
Double_t py = p*sqrt(1.-costheta*costheta)*sin(phi);
TLorentzVector daughter(px,py,pz,e);
return myBoost(parent,daughter);
}
//-----------------------------------------
TPaveText *GetPaveText(Double_t xl, Double_t xh, Double_t yl, Double_t yh, Double_t size, const Int_t font)
{
TPaveText* t1=new TPaveText(xl,yl,xh,yh,"brNDC");
t1->SetFillStyle(0);
t1->SetBorderSize(0);
t1->SetTextSize(size);
t1->SetTextFont(font);
return t1;
}
//-----------------------------------------
TPaveText *GetTitleText(TString title, const Float_t size, const Int_t font)
{
TPaveText* t1=new TPaveText(0.3530151,0.8968531,0.6532663,0.9965035,"brNDC");
t1->SetFillStyle(0);
t1->SetBorderSize(0);
t1->AddText(0.,0.,title.Data());
t1->SetTextSize(size);
t1->SetTextFont(font);
return t1;
}
//-----------------------------------------
TCanvas *draw1D(TH1 *h, TString hTitle, Bool_t setLog, Bool_t drawP, const Float_t size, const TString drawOpt, const Int_t titleFont,
const Int_t wh, const Int_t ww)
{
TCanvas *c = new TCanvas(h->GetName(),h->GetName(),wh,ww);
if(setLog) gPad->SetLogy();
if(hTitle.Length()>0) h->SetTitle(hTitle);
TPaveText *t1 = GetTitleText(h->GetTitle(),size,titleFont);
h->SetTitle("");
if(drawOpt.Length()>0)
h->DrawCopy(drawOpt.Data());
else
{
if(drawP)
h->DrawCopy("PE");
else
h->DrawCopy("HIST");
}
t1->Draw();
return c;
}