1 #include "sPhenixStyle.h"
2 #include "sPhenixStyle.C"
15 TGraphErrors *lin[
nIso];
18 TCanvas *c1 =
new TCanvas(
"linearity",
"linearity");
19 TCanvas *cUnity =
new TCanvas(
"UnityDiff",
"UnityDiff");
20 TCanvas *cDiff =
new TCanvas(
"fitDiff",
"FitDiff");
23 if(!is10GeV) fitEnd = 60;
25 TLegend *
leg =
new TLegend(0.6,0.2,0.9,0.5);
29 int colors[] = {1, 2, 4, kGreen +2, kViolet, kCyan, kOrange, kMagenta+2, kAzure-2};
31 TH2F *pt_true_matched[
nIso];
32 TF1 *unity =
new TF1(
"unity",
"x",0,80);
35 TGraphErrors *unityDiff[
nIso];
36 TGraphErrors *chi2NDF[
nIso];
37 TGraphErrors *fitDiff[
nIso][3];
41 linFit[
i] =
new TF1(Form(
"linFit_iso%d",
i),
"[0] + [1]*x",fitStart,fitEnd);
43 fin[
i] =
new TFile(Form(
"hists_R04_dR%g_Corr0_isLin1.root",
isoParams[i]));
44 pt_true_matched[
i] = (TH2F*)fin[i] ->
Get(
"h_pt_true_matched");
46 lin[
i] = (TGraphErrors*)fin[i] ->
Get(
"g_jes_cent0");
48 lin[
i] ->
GetYaxis() -> SetRangeUser(0,70);
50 lin[
i] ->
SetTitle(
";p_{T,truth} [GeV/c];#LTp_{T,reco}#GT [GeV/c]");
52 if(i == 0) lin[
i] ->
Draw(
"ap");
53 else lin[
i] ->
Draw(
"samep");
54 unityDiff[
i] =
new TGraphErrors();
55 for(
int j = 0;
j < lin[
i] -> GetN();
j++)
58 lin[
i] -> GetPoint(
j,x,y);
62 lin[
i] -> Fit(linFit[i],
"RQ");
63 fitDiff[
i][0] =
new TGraphErrors();
64 for(
int n = 0;
n < lin[
i] -> GetN();
n++)
67 lin[
i] -> GetPoint(
n,x,y);
71 fitDiff[
i][0] ->
SetPoint(
n, x, (y - linFit[i] -> Eval(x))/y);
74 fitDiff[
i][0] ->
SetTitle(
";p_{T,truth} [GeV/c];#frac{(Data - Fit)}{Data}");
76 fitDiff[
i][0] ->
GetYaxis() -> SetRangeUser(-1,1);
78 unityDiff[
i] ->
SetTitle(
";p_{T,truth} [GeV/c];#LTp_{T,reco}#GT - p_{T,Truth} [GeV/c]");
79 unityDiff[
i] ->
GetYaxis() -> SetRangeUser(-30,5);
81 if(i == 0)unityDiff[
i] ->
Draw(
"ap");
82 else unityDiff[
i] ->
Draw(
"samep");
86 if(i == 0) fitDiff[
i][0] ->
Draw(
"ap");
87 else fitDiff[
i][0] ->
Draw(
"samep");
90 c1 ->
cd(); leg ->
Draw(
"same"); unity ->
Draw(
"same");
91 cUnity ->
cd(); leg ->
Draw(
"same");
92 cDiff ->
cd(); leg ->
Draw(
"same");
95 c1 -> SaveAs(
"plots/lin_isoStack.pdf");
96 cUnity -> SaveAs(
"plots/unityDiff.pdf");
97 cDiff -> SaveAs(
"plots/fitDiff0.pdf");
103 TGraphErrors *r_lin[
nIso];
104 const int nPoints = lin[0] -> GetN();
106 TCanvas *cChi2 =
new TCanvas(
"chi2",
"resolution");
107 TCanvas *
c2 =
new TCanvas(
"resolution",
"resolution");
108 int bestIter[
nIso] = {-1};
109 TLine *bestIterLn[
nIso];
113 r_lin[
i] =
new TGraphErrors();
116 for(
int j = 0;
j < nPoints;
j++)
118 Double_t
x,
y, erry, errx;
119 lin[
i] -> GetPoint(
j, x, y);
120 erry = lin[
i] -> GetErrorY(
j);
121 errx = lin[
i] -> GetErrorX(
j);
122 TH1F *pt_true_proj = (TH1F*)pt_true_matched[
i] -> ProjectionX();
123 pt_true_proj ->
GetXaxis() -> SetRangeUser(x - errx, x + errx);
124 x = pt_true_proj -> GetMean();
127 float err = y/x * sqrt(pow(erry/y,2) );
132 r_lin[
i] ->
SetTitle(
";p_{T,truth} [GeV/c];#LTp_{T,reco}#GT/#LTp_{T,truth}#GT");
133 r_lin[
i] ->
GetYaxis() -> SetRangeUser(0.5,1);
136 chi2NDF[
i] =
new TGraphErrors();
137 chi2NDF[
i] ->
SetTitle(
";Iterations;chi2/NDF");
139 float minChi2NDF = 9999;
142 for(
int l = 0; l <
nIter; l++)
144 rFit[
i][l] =
new TF1(
"polyFitBase",fit.c_str(),fitStart,fitEnd);
147 r_lin[
i] -> Fit(rFit[i][l],
"Q0",
"0",fitStart,fitEnd);
148 r_lin[
i] ->
GetYaxis() -> SetRangeUser(0.5,1);
150 chi2 = rFit[
i][l] -> GetChisquare();
153 if(chi2/ndf < minChi2NDF)
155 minChi2NDF = chi2/ndf;
163 fitDiff[
i][1] =
new TGraphErrors();
164 for(
int n = 0;
n < r_lin[
i] -> GetN();
n++)
167 r_lin[
i] -> GetPoint(
n,x,y);
170 fitDiff[
i][1] ->
SetPoint(
n, x, (y - rFit[i][bestIter[i]] -> Eval(x))/y);
174 fitDiff[
i][1] ->
SetTitle(
";p_{T,truth} [GeV/c];#frac{(Data - Fit)}{Data}");
175 fitDiff[
i][1] ->
GetYaxis() -> SetRangeUser(-1,1);
177 bestIterLn[
i] =
new TLine(bestIter[i],0,bestIter[i],20);
185 r_lin[
i] ->
GetXaxis() -> SetLimits(0,80);
186 r_lin[
i] ->
Draw(
"ap");
188 else r_lin[
i] ->
Draw(
"samep");
189 rFit[
i][bestIter[
i]] ->
Draw(
"same");
194 chi2NDF[
i] ->
GetYaxis() -> SetRangeUser(0,20);
195 chi2NDF[
i] ->
Draw(
"ap");
198 else chi2NDF[
i] ->
Draw(
"samep");
199 bestIterLn[
i] ->
Draw(
"same");
202 if(i == 0)fitDiff[
i][1] ->
Draw(
"ap");
203 else fitDiff[
i][1] ->
Draw(
"samep");
205 TLine *thirty =
new TLine(30,0.5,30,1);
209 thirty ->
Draw(
"same");
214 cDiff ->
cd(); leg ->
Draw(
"same");
218 c2 -> SaveAs(
"plots/fMeanScaled.pdf");
219 cChi2 -> SaveAs(
"plots/chi2NdffMean.pdf");
220 cDiff -> SaveAs(
"plots/fitDiff1.pdf");
225 TGraphErrors *rTilde[
nIso];
226 TGraphErrors *gfInv[
nIso];
228 TCanvas *c3 =
new TCanvas();
229 TCanvas *c4 =
new TCanvas();
230 TCanvas *cChi22 =
new TCanvas();
234 rTilde[
i] =
new TGraphErrors();
235 gfInv[
i] =
new TGraphErrors();
238 for(
int j = 0;
j < nPoints;
j++)
241 lin[
i] -> GetPoint(
j, x, y);
242 if(x < fitStart || x > fitEnd)
continue;
243 float fInv = linFit[
i] ->
GetX(y);
246 float R = rFit[
i][bestIter[
i]] -> Eval(fInv);
253 rTilde[
i] ->
SetTitle(
";#LTp_{T,reco}#GT [GeV/c];1/#tilde{R}(p_{T,reco})");
254 gfInv[
i] ->
SetTitle(
";#LTp_{T,reco}#GT [GeV/c];p_{T,truth} [GeV/c]");
256 rTilde[
i] ->
GetYaxis() -> SetRangeUser(0,2);
258 chi2NDF[
i] =
new TGraphErrors();
259 chi2NDF[
i] ->
SetTitle(
";Iterations;chi2/NDF");
261 float minChi2NDF = 9999;
262 for(
int l = 0; l <
nIter; l++)
264 correctionFit[
i][l] =
new TF1(
"polyFitBas2",fit.c_str(),fitStart,52);
266 rTilde[
i] -> Fit(correctionFit[i][l],
"Q0",
"",5,70);
268 chi2 = correctionFit[
i][l] -> GetChisquare();
269 ndf = correctionFit[
i][l] ->
GetNDF();
271 if(chi2/ndf < minChi2NDF)
273 minChi2NDF = chi2/ndf;
281 fitDiff[
i][2] =
new TGraphErrors();
282 for(
int n = 0;
n < rTilde[
i] -> GetN();
n++)
285 rTilde[
i] -> GetPoint(
n,x,y);
288 fitDiff[
i][2] ->
SetPoint(
n, x, (y - correctionFit[i][bestIter[i]] -> Eval(x))/y);
292 fitDiff[
i][2] ->
SetTitle(
";p_{T,reco} [GeV/c];#frac{(Data - Fit)}{Data}");
294 fitDiff[
i][2] ->
GetYaxis() -> SetRangeUser(-1,1);
297 if(i == 0)rTilde[
i] ->
Draw(
"ap");
298 else rTilde[
i] ->
Draw(
"samep");
299 correctionFit[
i][bestIter[
i]] ->
Draw(
"same");
302 if(i == 0)gfInv[
i] ->
Draw(
"ap");
303 else gfInv[
i] ->
Draw(
"samep");
305 bestIterLn[
i] =
new TLine(bestIter[i],-0.005,bestIter[i],0.03);
312 chi2NDF[
i] ->
GetYaxis() -> SetRangeUser(-0.005,0.03);
313 chi2NDF[
i] ->
GetXaxis() -> SetLimits(-1,14.5);
315 chi2NDF[
i] ->
Draw(
"ap");
317 else chi2NDF[
i] ->
Draw(
"samep");
318 bestIterLn[
i] ->
Draw(
"same");
321 if(i == 0)fitDiff[
i][2] ->
Draw(
"ap");
322 else fitDiff[
i][2] ->
Draw(
"samep");
332 c3 -> SaveAs(
"plots/jesCorrection.pdf");
333 c4 -> SaveAs(
"plots/jesInv.pdf");
334 cChi22 -> SaveAs(
"plots/chi2NdfCorrFit.pdf");
335 cDiff -> SaveAs(
"plots/fitDiff2.pdf");
337 TFile *corrOut =
new TFile(
"JES_IsoCorr_NumInv.root",
"RECREATE");
342 correctionFit[
i][bestIter[
i]] ->
Write();
350 string nextTerm = Form(
"+ [%d]*pow(log(x),%d)", order, order);
352 function += nextTerm;