1 #include "sPhenixStyle.h"
2 #include "sPhenixStyle.C"
4 bool isIso(
int thisRjet,
int thisTjet, vector<float> *rJetpT, vector<float> *tJetpT, vector<float> *rJetEta, vector<float> *tJetEta, vector<float> *rJetPhi, vector<float> *tJetPhi,
float minDr, TH1F *&rDist, TH1F *&
tDist);
11 void Jet_reso_Iso(
float jetR = 4,
float isoParam = 1,
int applyCorr = 0,
int isLin = 0)
21 float minDist = .1*(jetR*isoParam);
22 if(minDist)std::cout <<
"isolation requirement: dR > " << minDist <<
" [rad]" << std::endl;
25 TH1::SetDefaultSumw2();
26 TH2::SetDefaultSumw2();
27 TH3::SetDefaultSumw2();
29 TChain * ct =
new TChain(
"T");
31 ct->Add(
"run40_30GeV_10GeV_Spliced_RecoJets.root");
37 TH1F *recoDist =
new TH1F(
"recoDist",
"distance between reco jets",200,0,5);
38 TH1F *truthDist =
new TH1F(
"truthDist",
"distance between truth jets",200,0,5);
40 TFile *f_out =
new TFile(Form(
"hists_R0%g_dR%g_Corr%d_isLin%d.root",jetR,isoParam,applyCorr,isLin),
"RECREATE");
42 vector<float> *
eta = 0;
43 vector<float> *
phi = 0;
44 vector<float> *
pt = 0;
47 vector<float> *truthEta = 0;
48 vector<float> *truthPhi = 0;
49 vector<float> *truthPt = 0;
52 vector<float> *subseedEta = 0;
53 vector<float> *subseedPhi = 0;
54 vector<float> *subseedPt = 0;
55 vector<float> *subseedE = 0;
56 vector<int> *subseedCut = 0;
57 vector<float> *rawseedEta = 0;
58 vector<float> *rawseedPhi = 0;
59 vector<float> *rawseedPt = 0;
64 Float_t rWeight, tWeight, RawWeight, SubWeight;
67 ct->SetBranchAddress(
"eta",&eta);
68 ct->SetBranchAddress(
"phi",&phi);
69 ct->SetBranchAddress(
"pt",&pt);
72 ct->SetBranchAddress(
"truthEta",&truthEta);
73 ct->SetBranchAddress(
"truthPhi",&truthPhi);
74 ct->SetBranchAddress(
"truthPt",&truthPt);
78 ct->SetBranchAddress(
"rawseedEta", &rawseedEta);
79 ct->SetBranchAddress(
"rawseedPhi", &rawseedPhi);
80 ct->SetBranchAddress(
"rawseedPt", &rawseedPt);
83 ct->SetBranchAddress(
"subseedEta", &subseedEta);
84 ct->SetBranchAddress(
"subseedPhi", &subseedPhi);
85 ct->SetBranchAddress(
"subseedPt", &subseedPt);
89 ct->SetBranchAddress(
"tWeight",&tWeight);
90 ct->SetBranchAddress(
"rWeight",&rWeight);
91 ct->SetBranchAddress(
"RawWeight",&RawWeight);
92 ct->SetBranchAddress(
"SubWeight",&SubWeight);
95 const Float_t pt_range[] = {15,20,25,30,35,40,45,50,60,80};
100 const int pt_N =
sizeof(pt_range)/
sizeof(
float) - 1;
102 const int pt_N_truth = 37;
103 const int resp_N = 100;
104 Float_t resp_bins[resp_N];
105 for(
int i = 0;
i < resp_N + 1;
i++){
107 resp_bins[
i] = 2./resp_N *
i;
117 vector<Float_t> pt_range_reco1;
129 pt_range_reco1.push_back(ptBin);
133 const int pt_N_reco = pt_range_reco1.size();
134 Float_t pt_range_reco[pt_N_reco];
135 for(
int i = 0;
i < pt_N_reco+1;
i++)
137 if(
i < pt_N_reco)pt_range_reco[
i] = pt_range_reco1.at(
i);
138 else pt_range_reco[
i] = 79.9;
140 Float_t pt_range_truth[pt_N_truth];
141 Float_t rebin[pt_N_truth];
142 for(
int i = 0;
i < pt_N_truth+1;
i++)
146 pt_range_truth[
i] = 15+1.5*
i;
148 if(pt_range_truth[
i] >= 15 && pt_range_truth[
i] < 30) rebin[
i] = 4;
149 else if(pt_range_truth[
i] >= 30 && pt_range_truth[
i] < 40) rebin[
i] = 1;
154 const int eta_N = 40;
156 for(
int i = 0;
i < eta_N+1;
i++){
157 eta_bins[
i] = -1.1 + 2.2/eta_N *
i;
159 const int phi_N = 40;
161 for(
int i = 0;
i < phi_N+1;
i++){
162 phi_bins[
i] = -TMath::Pi() + 2*TMath::Pi()/phi_N *
i;
164 const int subet_N = 400;
165 Float_t subet_bins[subet_N];
166 for(
int i = 0;
i < subet_N+1;
i++){
167 subet_bins[
i] =
i*0.2;
169 const float cent_bins[] = {-1, 0, 10, 30, 50, 80};
170 const int cent_N = 1;
172 TH3F *h_MC_Reso_pt = 0;
173 if(isLin) h_MC_Reso_pt=
new TH3F(
"h_MC_Reso",
"" , pt_N_truth, pt_range_truth, pt_N_reco, pt_range_reco, cent_N, cent_bins);
174 else h_MC_Reso_pt=
new TH3F(
"h_MC_Reso",
"" , pt_N, pt_range, resp_N, resp_bins, cent_N, cent_bins);
176 h_MC_Reso_pt ->
GetXaxis()->SetTitle(
"p_{T}^{truth} [GeV]");
177 if(isLin) h_MC_Reso_pt->GetYaxis()->SetTitle(
"p_{T}^{reco}");
178 else h_MC_Reso_pt->GetYaxis()->SetTitle(
"p_{T}^{reco}/p_{T}^{truth}");
179 TH2F *h_pt_reco =
new TH2F(
"h_pt_reco",
"",subet_N,subet_bins, cent_N, cent_bins);
180 h_pt_reco->GetXaxis()->SetTitle(
"p_{T} [GeV]");
181 TH2F *h_pt_true =
new TH2F(
"h_pt_true",
"",pt_N,pt_range, cent_N, cent_bins);
182 h_pt_true->GetXaxis()->SetTitle(
"p_{T} [GeV]");
183 TH2F *h_pt_true_matched =
new TH2F(
"h_pt_true_matched",
"",subet_N,subet_bins, cent_N, cent_bins);
184 h_pt_true_matched->GetXaxis()->SetTitle(
"p_{T} [GeV]");
185 TH3F *h_eta_phi_reco =
new TH3F(
"h_eta_phi_reco",
"",eta_N, eta_bins, phi_N, phi_bins, cent_N, cent_bins);
186 h_eta_phi_reco->GetXaxis()->SetTitle(
"#eta");
187 h_eta_phi_reco->GetYaxis()->SetTitle(
"#phi");
188 TH3F *h_eta_phi_true =
new TH3F(
"h_eta_phi_true",
"",eta_N, eta_bins, phi_N, phi_bins, cent_N, cent_bins);
189 TH3F *h_subEt_pt =
new TH3F(
"h_subEt_pt",
"",pt_N,pt_range, subet_N, subet_bins, cent_N, cent_bins);
192 TGraphErrors *g_jes[cent_N];
193 TGraphErrors *g_jer[cent_N];
194 for(
int icent = 0; icent < cent_N; icent++){
195 g_jes[icent] =
new TGraphErrors(pt_N);
196 g_jer[icent] =
new TGraphErrors(pt_N);
200 TF1 *correction =
new TF1(
"jet energy correction",
"1",0,80);
203 corrFile =
new TFile(
"JES_IsoCorr_NumInv.root",
"READ");
205 correction = (TF1*)corrFile ->
Get(Form(
"corrFit_Iso%g",isoParam));
208 int nentries = ct->GetEntries();
209 for(
int i = 0;
i < nentries;
i++){
212 int njets = truthPt->size();
213 int nrecojets = pt->size();
216 for(
int rj = 0; rj < nrecojets; rj++)
218 pt ->
at(rj) *= correction -> Eval(pt ->
at(rj));
221 for(
int tj = 0; tj < njets; tj++){
224 h_pt_true->Fill(truthPt->at(tj), cent);
225 h_pt_true->Fill(truthPt->at(tj), -1);
226 h_eta_phi_true->Fill(truthEta->at(tj),truthPhi->at(tj), cent);
227 h_eta_phi_true->Fill(truthEta->at(tj),truthPhi->at(tj), -1);
229 float matchEta, matchPhi, matchPt, matchE, matchsubtracted_et,
dR;
231 int recoMatchJet = -9999;
233 for(
int rj = 0; rj < nrecojets; rj++){
234 float dEta = truthEta->at(tj) - eta->at(rj);
235 float dPhi = truthPhi->at(tj) - phi->at(rj);
236 while(dPhi > TMath::Pi()) dPhi -= 2*TMath::Pi();
237 while(dPhi < -TMath::Pi()) dPhi += 2*TMath::Pi();
238 dR = TMath::Sqrt(dEta*dEta + dPhi*dPhi);
241 matchEta = eta->at(rj);
242 matchPhi = phi->at(rj);
243 matchPt = pt->at(rj);
251 if(dRMax > 0.1*0.75*jetR)
continue;
252 if(minDist && !
isIso(recoMatchJet, tj, pt, truthPt, eta, truthEta, phi, truthPhi, minDist, recoDist, truthDist))
continue;
257 h_MC_Reso_pt->Fill(truthPt->at(tj),matchPt/truthPt->at(tj), cent, rWeight);
258 h_MC_Reso_pt->Fill(truthPt->at(tj),matchPt/truthPt->at(tj), -1, rWeight);
262 h_MC_Reso_pt->Fill(truthPt->at(tj),matchPt, cent, rWeight);
263 h_MC_Reso_pt->Fill(truthPt->at(tj),matchPt, -1, rWeight);
266 h_pt_true_matched->Fill(truthPt->at(tj), cent, tWeight);
267 h_eta_phi_reco->Fill(matchEta,matchPhi, cent);
268 h_pt_reco->Fill(matchPt, cent, rWeight);
270 h_pt_true_matched->Fill(truthPt->at(tj), -1, tWeight);
271 h_eta_phi_reco->Fill(matchEta,matchPhi, -1);
272 h_pt_reco->Fill(matchPt, -1, rWeight);
278 TCanvas *
c =
new TCanvas(
"c",
"c");
280 TLegend *
leg =
new TLegend(.6,.9,.9,.9);
281 leg->SetFillStyle(0);
282 gStyle->SetOptFit(0);
299 for(
int icent = 0; icent < cent_N; ++icent){
300 for (
int i = 0;
i < stop; ++
i){
301 TF1 *func =
new TF1(
"func",
"gaus",fitStart,fitEnd);
302 h_MC_Reso_pt->GetXaxis()->SetRange(
i+1,
i+1);
303 h_MC_Reso_pt->GetZaxis()->SetRange(icent+1,icent+1);
304 TH1F *h_temp = (TH1F*) h_MC_Reso_pt->Project3D(
"y");
305 if(isLin)h_temp -> Rebin(rebin[
i]);
306 func ->
SetParameter(1, h_temp -> GetBinCenter(h_temp -> GetMaximumBin()));
308 h_temp -> Fit(func,
"",
"",fitStart,fitEnd);
309 h_temp ->
Write(Form(
"hFit_cent%d_pt%d_Fit0",icent+1,i));
310 func ->
SetParameter(1, h_temp -> GetBinCenter(h_temp -> GetMaximumBin()));
312 h_temp->Fit(func,
"",
"",func->GetParameter(1)-0.75*func->GetParameter(2),func->GetParameter(1)+0.75*func->GetParameter(2));
313 if(isLin)h_temp ->
GetXaxis() -> SetRangeUser(func->GetParameter(1)-4*func->GetParameter(2),func->GetParameter(1)+4*func->GetParameter(2));
315 func ->
SetRange(func->GetParameter(1)-func->GetParameter(2),func->GetParameter(1)+func->GetParameter(2));
317 func ->
Draw(
"same");
319 func->SetLineColor(2);
322 h_temp ->
Write(Form(
"hFit_cent%d_pt%d_Fit1",icent+1,i));
324 leg->AddEntry(
"",Form(
"%g < p_T < %g GeV",h_MC_Reso_pt->GetXaxis()->GetBinLowEdge(i+1),h_MC_Reso_pt->GetXaxis()->GetBinLowEdge(i+2)),
"");
326 c->Print(Form(
"plots/hFit_cent%d_pt%d_Fit1_Corr%d_isLin%d_Param%g.pdf",icent+1,i,applyCorr,isLin,isoParam));
328 float dsigma = func->GetParError(2);
329 float denergy = func->GetParError(1);
330 float sigma = func->GetParameter(2);
331 float energy = func->GetParameter(1);
333 float djer = dsigma/energy + sigma*denergy/pow(energy,2);
336 g_jes[icent]->SetPoint(i,0.5*(pt_range_truth[i]+pt_range_truth[i+1]),func->GetParameter(1));
337 g_jes[icent]->SetPointError(i,0.5*(pt_range_truth[i+1]-pt_range_truth[i]),func->GetParError(1));
339 g_jer[icent]->SetPoint(i,0.5*(pt_range_truth[i]+pt_range_truth[i+1]),func->GetParameter(2)/func->GetParameter(1));
340 g_jer[icent]->SetPointError(i,0.5*(pt_range_truth[i+1]-pt_range_truth[i]),djer);
344 g_jes[icent]->SetPoint(i,0.5*(pt_range[i]+pt_range[i+1]),func->GetParameter(1));
345 g_jes[icent]->SetPointError(i,0.5*(pt_range[i+1]-pt_range[i]),func->GetParError(1));
347 g_jer[icent]->SetPoint(i,0.5*(pt_range[i]+pt_range[i+1]),func->GetParameter(2)/func->GetParameter(1));
348 g_jer[icent]->SetPointError(i,0.5*(pt_range[i+1]-pt_range[i]),djer);
356 for(
int icent = 0; icent < cent_N; ++icent){
357 g_jes[icent]->Write(Form(
"g_jes_cent%i",icent));
358 g_jer[icent]->Write(Form(
"g_jer_cent%i",icent));
362 truthDist ->
Write();
365 h_eta_phi_true->Write();
366 h_pt_true_matched->Write();
367 h_eta_phi_reco->Write();
374 bool isIso(
int thisRjet,
int thisTjet, vector<float> *rJetpT, vector<float> *tJetpT, vector<float> *rJetEta, vector<float> *tJetEta, vector<float> *rJetPhi, vector<float> *tJetPhi,
float minDr, TH1F *&rDist, TH1F *&
tDist)
376 if(thisRjet < 0)
return false;
377 float thisRJetEta = rJetEta->at(thisRjet);
378 float thisTJetEta = tJetEta->at(thisTjet);
379 float thisRJetPhi = rJetPhi->at(thisRjet);
380 float thisTJetPhi = tJetPhi->at(thisTjet);
386 for(
int i = 0;
i < rJetpT->size();
i++)
398 float deta = pow(thisRJetEta - rJetEta->at(
i),2);
399 float dphi = thisRJetPhi - rJetPhi->at(
i);
400 while(dphi > TMath::Pi()) dphi -= 2*TMath::Pi();
401 while(dphi < -TMath::Pi()) dphi += 2*TMath::Pi();
404 dr = sqrt(deta + dphi);
406 if(dr < minDr)
return false;
410 if(dr)rDist ->
Fill(dr);
412 for(
int i = 0;
i < tJetpT->size();
i++)
414 if(
i == thisTjet)
continue;
417 float deta = pow(thisTJetEta - tJetEta->at(
i),2);
418 float dphi = pow(thisTJetPhi - tJetPhi->at(
i),2);
419 while(dphi > TMath::Pi()) dphi -= 2*TMath::Pi();
420 while(dphi < -TMath::Pi()) dphi += 2*TMath::Pi();
423 dr = sqrt(deta + dphi);
425 if(dr < minDr)
return false;
428 if(dr)tDist ->
Fill(dr);