134 {
135
136
137 std::vector<double> npTbinning;
138 double original_ptmin = 0, original_ptmax = 0;
139 if (pTbin){
140 original_ptmin = 40, original_ptmax = 600;
141 npTbinning =
makeLogBins(560,original_ptmin,original_ptmax);
142 }else{
143 original_ptmin = 200, original_ptmax = 3000;
144 npTbinning =
makeLogBins(2800,original_ptmin,original_ptmax);
145 }
146 int npTbins = -1+npTbinning.size();
147
148 std::unique_ptr<TFile> f_JMR_uncertainties_histograms = std::make_unique<TFile>(histofile.c_str(), "READ");
149 if (f_JMR_uncertainties_histograms == 0){
150 std::cout << "Can't find input file.\n";
151 return;
152 }
153
154 std::cout << "\n > Input root file opened \n" << std::endl;
155
156 std::vector<std::string> UFO_JMR_uncertainties_histo_names = {};
157 std::vector<std::string> uncertainty_names = {};
158 std::vector<std::string> uncertainty_treatment = {};
159
160 if (uncmodel == "SimpleJMR"){
161
162 UFO_JMR_uncertainties_histo_names = {"JMRUnc_mc20vsmc21_"+kind_of_mc+"_PreRec", "JMRUnc_mc20vsmc23_"+kind_of_mc+"_PreRec", "JMRUnc_mc20FullSimvsmc20AF3_"+kind_of_mc+"_PreRec", "JMRUnc_Noise_PreRec", "JMRUnc_mc20UFOvsmc16UFO_PreRec", "JMR_FlatSmearing20_AntiKt10UFOCSSKSoftDropBeta100Zcut10"};
163
164 uncertainty_names = {"MC20 vs MC21 ("+kind_of_mc+")", "MC20 vs MC23 ("+kind_of_mc+")", "FullSim vs AF3 ("+kind_of_mc+")", "Noise", "MC20 UFO vs MC16 UFO", "Flat smearing 20%"};
165
166 uncertainty_treatment = {"eLOGmOeAbsEta", "eLOGmOeAbsEta", "PtAbsMass", "eLOGmOeAbsEta", "eLOGmOeAbsEta", "PtAbsMass"};
167
168 }else if (uncmodel == "FullJMR"){
169
170
171
172 UFO_JMR_uncertainties_histo_names = {"JMRUnc_mc20vsmc21_"+kind_of_mc+"_PreRec", "JMRUnc_mc20vsmc23_"+kind_of_mc+"_PreRec", "JMRUnc_mc20FullSimvsmc20AF3_"+kind_of_mc+"_PreRec", "JMRUnc_Noise_PreRec", "JMRUnc_mc20UFOvsmc16UFO_PreRec", "JMR_UncertaintiesOutsideCalibratedRegion_AntiKt10UFOCSSKSoftDropBeta100Zcut10", "JMR_Smoothing_AntiKt10UFOCSSKSoftDropBeta100Zcut10", "JMR_FF_Nom_AntiKt10UFOCSSKSoftDropBeta100Zcut10", "JMR_FF_Stat_AntiKt10UFOCSSKSoftDropBeta100Zcut10", "JMR_FF_Det_AntiKt10UFOCSSKSoftDropBeta100Zcut10", "JMR_FF_MCisr_AntiKt10UFOCSSKSoftDropBeta100Zcut10", "JMR_FF_MCfsr_AntiKt10UFOCSSKSoftDropBeta100Zcut10", "JMR_FF_MCps_AntiKt10UFOCSSKSoftDropBeta100Zcut10", "JMR_FF_MCcr_AntiKt10UFOCSSKSoftDropBeta100Zcut10", "JMR_FF_MCrecoil_AntiKt10UFOCSSKSoftDropBeta100Zcut10", "JMR_FF_MCpthard_AntiKt10UFOCSSKSoftDropBeta100Zcut10"};
173
174 uncertainty_names = {"MC20 vs MC21 ("+kind_of_mc+")", "MC20 vs MC23 ("+kind_of_mc+")", "FullSim vs AF3 ("+kind_of_mc+")", "Noise", "MC20 UFO vs MC16 UFO", "Flat smearing 20% (outside)", "FF smoothing", "FF nom.", "FF stat.", "FF Detector", "FF ISR", "FF FSR", "FF PS", "FF Color recon.", "FF recoil", "FF pthard"};
175
176 uncertainty_treatment = {"eLOGmOeAbsEta", "eLOGmOeAbsEta", "PtAbsMass", "eLOGmOeAbsEta", "eLOGmOeAbsEta", "PtAbsMass", "PtAbsMass", "PtAbsMass", "PtAbsMass", "PtAbsMass", "PtAbsMass", "PtAbsMass", "PtAbsMass", "PtAbsMass", "PtAbsMass", "PtAbsMass"};
177
178 }
179
180 std::cout << " > Uncertainty model: " << uncmodel << "\n" << std::endl;
181
182 if (uncertainty_names.size() != UFO_JMR_uncertainties_histo_names.size()){
183 std::cout << "List of syst histograms and syst names of different sizes.\n";
184 return;
185 }
186
187 std::cout << " > Input uncertainty names and histograms provided \n" << std::endl;
188
189
190 std::vector<TH3F*> JMR_uncertainties_hists_3d;
191 int histocount3d = 0;
192 std::vector<TH2D*> JMR_uncertainties_hists_2d;
193 int histocount2d = 0;
194 int iprime[50] = {};
195
196 for (
int i=0;
i < std::ssize(uncertainty_names);
i++){
197
198 TString
histoname = UFO_JMR_uncertainties_histo_names[
i].c_str();
199 TString unctreatment = uncertainty_treatment[
i].c_str();
200 if (f_JMR_uncertainties_histograms->Get(histoname) != 0){
201
202 if (unctreatment == "eLOGmOeAbsEta"){
203 JMR_uncertainties_hists_3d.push_back((TH3F*)f_JMR_uncertainties_histograms->Get(histoname));
204 iprime[
i] = histocount3d;
205 histocount3d += 1;
206 }else if (unctreatment == "PtAbsMass"){
207 JMR_uncertainties_hists_2d.push_back((TH2D*)f_JMR_uncertainties_histograms->Get(histoname));
208 iprime[
i] = histocount2d;
209 histocount2d += 1;
210 }
211 std::cout <<
" >> NP read '" << UFO_JMR_uncertainties_histo_names[
i] <<
"' with iprime["<<
i<<
"] = " <<iprime[
i]<< std::endl;
212 std::cout << " >>> Uncertainty treatment = " << unctreatment << std::endl;
213
214 }else{
215 std::cout <<
"Can't read input histo." << UFO_JMR_uncertainties_histo_names[
i] <<
"\n";
216 return;
217 }
218
219 }
220
221 std::cout << "\n > Input 2D and 3D histograms are read now \n" << std::endl;
222
223
224 std::vector<std::unique_ptr<TH1D>> JMR_uncertainties_1Dhists;
225
226 for (
int i=0;
i < std::ssize(uncertainty_names);
i++){
227
228 JMR_uncertainties_1Dhists.push_back(std::make_unique<TH1D>(("UFO_"+std::to_string(i)).c_str(),("UFO_"+std::to_string(i)).c_str(), npTbins, &npTbinning[0]));
229 auto* hist0 = JMR_uncertainties_1Dhists.at(i).get();
230
231 TString unctreatment = uncertainty_treatment[
i].c_str();
232 float uncertainty_value = 0;
233
234 if (unctreatment == "eLOGmOeAbsEta"){
235
236 auto*
hist1 = JMR_uncertainties_hists_3d.at(iprime[i]);
237
239 double j = hist0->GetBinCenter(
bin);
240
241
242 double cosh_eta = std::cosh(eta_bin);
243 double energy_bin = sqrt((mass_bin*mass_bin) + (j*j)*
pow(cosh_eta,2));
244
245
246 double x = energy_bin,
y = TMath::Log(mass_bin/energy_bin),
z =
eta_bin;
247
248 Int_t bin_energy =
hist1->GetXaxis()->FindBin(
x);
249 Int_t bin_mass =
hist1->GetYaxis()->FindBin(
y);
250 Int_t bin_eta =
hist1->GetZaxis()->FindBin(
z);
251
252
253 if (pTbin){
254 energy_bin = sqrt((j*j) + (mass_bin*mass_bin)*
pow(cosh_eta,2));
255
256
257 x = energy_bin,
y = TMath::Log(j/energy_bin),
z =
eta_bin;
258
259 bin_energy =
hist1->GetXaxis()->FindBin(
x);
260 bin_mass =
hist1->GetYaxis()->FindBin(
y);
261 bin_eta =
hist1->GetZaxis()->FindBin(
z);
262 }
263
264
265 if (dointerpol){
267 }else{
268 uncertainty_value = fabs(
hist1->GetBinContent(bin_energy, bin_mass, bin_eta) );
269 }
270
271
272 hist0->SetBinContent(
bin, uncertainty_value);
273
274 }
275
276 }else if (unctreatment == "PtAbsMass"){
277
278 auto*
hist2 = JMR_uncertainties_hists_2d.at(iprime[i]);
279
281
282 double j = hist0->GetBinCenter(
bin);
283
284
285 double x =
j,
y = mass_bin;
286
287 Int_t bin_pt =
hist2->GetXaxis()->FindBin(
x);
288 Int_t bin_mass =
hist2->GetYaxis()->FindBin(
y);
289
290
291 if (pTbin){
293
294 bin_pt =
hist2->GetXaxis()->FindBin(
x);
295 bin_mass =
hist2->GetYaxis()->FindBin(
y);
296 }
297
298
299 if (dointerpol){
301 }else{
302 uncertainty_value = fabs(
hist2->GetBinContent(bin_pt, bin_mass) );
303 }
304
305
306 hist0->SetBinContent(
bin, uncertainty_value);
307
308 }
309
310 }
311
312 }
313
314 std::cout << " > Individual uncertainties evaluated \n" << std::endl;
315
317
318 std::unique_ptr<TH1D> JMR_All_uncertainties_1Dhist = std::make_unique<TH1D>("total_uncertainty", "total_uncertainty", npTbins, &npTbinning[0]);
319
320 for (
int j=1;
j<=JMR_All_uncertainties_1Dhist->GetXaxis()->GetNbins();
j++){
321
322 double total_uncertainty = 0;
323
324 for (
int i=0;
i < std::ssize(uncertainty_names);
i++){
325
326 double uncval = JMR_uncertainties_1Dhists.at(i)->GetBinContent(j);
327
328 total_uncertainty += (uncval) * (uncval);
329
330
331 }
332
333 total_uncertainty = sqrt(total_uncertainty);
334 JMR_All_uncertainties_1Dhist->SetBinContent(j, total_uncertainty);
335
336
337 }
338
339
340
341 std::unique_ptr<TH1D> JMR_old_uncertainties_1Dhist = std::make_unique<TH1D>("Old_uncertainty","Old_uncertainty", npTbins, &npTbinning[0]);
342
343 for (
int j=1;
j<=JMR_old_uncertainties_1Dhist->GetXaxis()->GetNbins();
j++){
344 JMR_old_uncertainties_1Dhist->SetBinContent(j, 0.2);
345 }
346
347 std::cout << " > Total uncertainty calculated \n" << std::endl;
348
349
350
351 gStyle->SetOptStat(0);
352 gROOT->Reset();
353 gROOT->SetStyle("ATLAS");
354 gROOT->ForceStyle();
355 gStyle->SetPadLeftMargin(0.15);
356 gStyle->SetPadRightMargin(0.08);
357 gStyle->SetEndErrorSize(4);
358 gStyle->SetPaintTextFormat("4.3f");
359 gStyle->SetPalette(8,0, 0.3);
360
361 std::unique_ptr<TCanvas>
canvas = std::make_unique<TCanvas>(
"c1",
"c1", 1200, 800);
362
363
364 int nbins = (original_ptmax - original_ptmin)/(1.);
365 std::unique_ptr<TH1D> DrawHistogram = std::make_unique<TH1D>("draw_hist","draw_hist_title",nbins, original_ptmin, original_ptmax);
366
367 DrawHistogram->SetMinimum(0);
368 DrawHistogram->SetMaximum(1.0);
369 DrawHistogram->SetLineWidth(0);
370 if (!pTbin){
372 }
373
374 DrawHistogram->GetXaxis()->SetTitle("p_{T}^{jet} [GeV]");
375 DrawHistogram->GetXaxis()->SetLabelOffset(0.0125);
376 DrawHistogram->GetXaxis()->SetNdivisions(510);
377 DrawHistogram->GetXaxis()->SetMoreLogLabels(true);
378 if (pTbin){
379 DrawHistogram->GetXaxis()->SetTitle("m^{jet} [GeV]");
380 DrawHistogram->GetXaxis()->SetNdivisions(505);
381 DrawHistogram->GetXaxis()->SetMoreLogLabels(false);
382 }
383 DrawHistogram->GetXaxis()->SetTitleOffset(1.50);
384
385 DrawHistogram->GetYaxis()->SetTitle("Fractional JMR uncertainty");
386 DrawHistogram->GetYaxis()->SetLabelOffset(0.0145);
387 DrawHistogram->GetYaxis()->SetTitleOffset(1.40);
388
389
390 DrawHistogram->Draw();
391
393
394 JMR_old_uncertainties_1Dhist->SetLineColor(kTeal+5);
395 JMR_old_uncertainties_1Dhist->SetLineStyle(1);
396 JMR_old_uncertainties_1Dhist->SetLineWidth(2);
397 JMR_old_uncertainties_1Dhist->SetFillStyle(4000);
398 JMR_old_uncertainties_1Dhist->SetFillColor(kTeal-9);
399 JMR_old_uncertainties_1Dhist->Draw("hist same");
400
401 JMR_All_uncertainties_1Dhist->SetLineColor(kBlue+2);
402 JMR_All_uncertainties_1Dhist->SetLineStyle(1);
403 JMR_All_uncertainties_1Dhist->SetLineWidth(2);
404 JMR_All_uncertainties_1Dhist->SetFillStyle(4000);
405 JMR_All_uncertainties_1Dhist->SetFillColor(590);
406 JMR_All_uncertainties_1Dhist->Draw("hist same");
407
409 int indexp =
index + 2;
410 if (
index == 8) indexp = 14;
411 if (
index == 9) indexp = 30;
412 if (
index == 10) indexp = 43;
413 if (
index == 11) indexp = 46;
414
415 auto* hist0 = JMR_uncertainties_1Dhists.at(
index).get();
416 hist0->SetLineColor(indexp);
417 hist0->SetLineStyle(
index+2);
418 hist0->SetLineWidth(2);
419 hist0->Draw("hist same");
420 }
421
423
424
425
426 TString ATLAS_LABELLING="";
427 if (atlas_approved==0){
428 ATLAS_LABELLING = "Internal";
429 }else if (atlas_approved==1)
430 ATLAS_LABELLING = "Preliminary";
431 else if (atlas_approved==2){
432 ATLAS_LABELLING = "";
433 }
434
440
444
445
446 l.DrawLatex(0.67,0.89,
"ATLAS");
447 p.DrawLatex(0.67+0.115,0.89,ATLAS_LABELLING);
448
449
450
451 TLatex data_text;
452 data_text.SetNDC();
453 data_text.SetTextFont(42);
454 data_text.SetTextSize(0.04);
455 data_text.DrawLatex(0.18,0.89,"Data 2015-2017, #sqrt{s} = 13 TeV");
456
457 TLatex jet_info_1_text;
458 jet_info_1_text.SetNDC();
459 jet_info_1_text.SetTextFont(42);
460 jet_info_1_text.SetTextSize(0.04);
461 jet_info_1_text.DrawLatex(0.18,0.89-0.06,"Phase-I unc. for UFO R = 1.0 jets");
462
463 TLatex jet_info_2_text;
464 jet_info_2_text.SetNDC();
465 jet_info_2_text.SetTextFont(42);
466 jet_info_2_text.SetTextSize(0.04);
467
468 std::string jet_info_2_string = "";
469 if (kind_of_mass == "UFO"){
470
471 jet_info_2_string = "|#eta^{jet}| = "+TString(Form("%f",eta_bin))+", m_{UFO}^{jet} = "+TString(Form("%i",mass_bin))+" GeV";
472
473 if (pTbin){
474 jet_info_2_string = "|#eta^{jet}| = "+TString(Form("%f",eta_bin))+", p_{T}^{jet} = "+TString(Form("%i",mass_bin))+" GeV";
475 }
476
477 }
478 jet_info_2_text.DrawLatex(0.18,0.89-2*0.06,jet_info_2_string.c_str());
479
481
482 std::unique_ptr<TLegend> legend0_1 = std::make_unique<TLegend>(0.17,0.89-3.33*0.06,0.45,0.89-2.33*0.06);
483 legend0_1->SetTextSize(0.035);
484 legend0_1->SetTextFont(42);
485 legend0_1->SetBorderSize(0);
486 legend0_1->SetFillStyle(0);
487 legend0_1->AddEntry(JMR_All_uncertainties_1Dhist.get(), "Tot. uncert.","f");
488 legend0_1->Draw("same");
489
490 std::unique_ptr<TLegend> legend0_2 = std::make_unique<TLegend>(0.17,0.89-4.33*0.06,0.45,0.89-3.33*0.06);
491 legend0_2->SetTextSize(0.035);
492 legend0_2->SetTextFont(42);
493 legend0_2->SetBorderSize(0);
494 legend0_2->SetFillStyle(0);
495 legend0_2->AddEntry(JMR_old_uncertainties_1Dhist.get(), "Tot. uncert. (previous)","f");
496 legend0_2->Draw("same");
497
498
499 std::unique_ptr<TLegend> legend1;
500 if (uncmodel == "SimpleJMR"){
501 legend1 = std::make_unique<TLegend>(0.55,0.70,0.85,0.88);
502 }else if (uncmodel == "FullJMR"){
503 legend1 = std::make_unique<TLegend>(0.55,0.55,0.85,0.88);
504 }
505 else {
506 std::println (std::cerr, "Unknown uncertainty model: {}", uncmodel);
507 return;
508 }
509 legend1->SetTextSize(0.035);
510 legend1->SetTextFont(42);
511 legend1->SetBorderSize(0);
512 legend1->SetFillStyle(0);
514 legend1->AddEntry(JMR_uncertainties_1Dhists.at(
index).get(), uncertainty_names[
index].c_str(),
"l");
515 }
516 legend1->Draw("same");
517
518 DrawHistogram->Draw("axis same");
519
520 std::cout << " > Plots are done now \n" << std::endl;
521
522 std::string outputdir = "./source/JetUncertainties/util/output/";
523
524 try{
525
526 if (!std::filesystem::exists(outputdir)) {
527 if (std::filesystem::create_directory(outputdir)){
528 std::cout << "Output directory created successfully: " << outputdir << std::endl;
529 }else{
530 std::cerr << "Failed to create directory: " << outputdir << std::endl;
531 return;
532 }
533 } else {
534 std::cout << "Output directory already exists: " << outputdir << std::endl;
535 }
536 }catch (const std::filesystem::filesystem_error& e){
537 std::cerr <<
"Filesystem error: " <<
e.what() << std::endl;
538 return;
539 }
540
541 std::string string_write;
542 std::string string_write_pdf;
543 std::string string_write_png;
544
545 TString mBinStr = "mass"+std::to_string(mass_bin);
546 if (pTbin){
547 mBinStr = "pT"+std::to_string(mass_bin);
548 }
549
550 TString EtaBinStr = "Eta"+std::to_string(eta_bin);
551
552 if (atlas_approved == 0){
553 string_write = outputdir+"FractionalJMRuncertainty_"+kind_of_mc+"_"+kind_of_mass+"_"+uncmodel+"_"+EtaBinStr+"_"+mBinStr+ "GeV_ATLASint";
554 string_write_pdf = string_write+".pdf";
555 string_write_png = string_write+".png";
556 }else if (atlas_approved == 1){
557 string_write = outputdir+"FractionalJMRuncertainty_"+kind_of_mc+"_"+kind_of_mass+"_"+uncmodel+"_"+EtaBinStr+"_"+mBinStr+ "GeV_ATLASprel";
558 string_write_pdf = string_write+".pdf";
559 string_write_png = string_write+".png";
560 }else if (atlas_approved == 2){
561 string_write = outputdir+"FractionalJMRuncertainty_"+kind_of_mc+"_"+kind_of_mass+"_"+uncmodel+"_"+EtaBinStr+"_"+mBinStr+ "GeV_ATLAS";
562 string_write_pdf = string_write+".pdf";
563 string_write_png = string_write+".png";
564 }
565
566 canvas->Print(string_write_pdf.c_str());
567
568
569 return;
570
571}
double Interpolate2D(const TH2 *histo, double x, double y)
double Read3DHistogram(const TH3 *histo, double x, double y, double z)
std::vector< double > makeLogBins(int nbins, double min, double max)
l
Printing final latex table to .tex output file.
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)