134void MakeJMRPlot(
int atlas_approved,
const std::string & histofile,
const std::string & uncmodel,
const std::string & kind_of_mass,
const std::string & kind_of_mc,
bool dointerpol,
int mass_bin,
double eta_bin,
bool pTbin=
false){
137 std::vector<double> npTbinning;
138 double original_ptmin = 0, original_ptmax = 0;
140 original_ptmin = 40, original_ptmax = 600;
141 npTbinning =
makeLogBins(560,original_ptmin,original_ptmax);
143 original_ptmin = 200, original_ptmax = 3000;
144 npTbinning =
makeLogBins(2800,original_ptmin,original_ptmax);
146 int npTbins = -1+npTbinning.size();
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";
154 std::cout <<
"\n > Input root file opened \n" << std::endl;
156 std::vector<std::string> UFO_JMR_uncertainties_histo_names = {};
157 std::vector<std::string> uncertainty_names = {};
158 std::vector<std::string> uncertainty_treatment = {};
160 if (uncmodel ==
"SimpleJMR"){
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"};
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%"};
166 uncertainty_treatment = {
"eLOGmOeAbsEta",
"eLOGmOeAbsEta",
"PtAbsMass",
"eLOGmOeAbsEta",
"eLOGmOeAbsEta",
"PtAbsMass"};
168 }
else if (uncmodel ==
"FullJMR"){
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"};
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"};
176 uncertainty_treatment = {
"eLOGmOeAbsEta",
"eLOGmOeAbsEta",
"PtAbsMass",
"eLOGmOeAbsEta",
"eLOGmOeAbsEta",
"PtAbsMass",
"PtAbsMass",
"PtAbsMass",
"PtAbsMass",
"PtAbsMass",
"PtAbsMass",
"PtAbsMass",
"PtAbsMass",
"PtAbsMass",
"PtAbsMass",
"PtAbsMass"};
180 std::cout <<
" > Uncertainty model: " << uncmodel <<
"\n" << std::endl;
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";
187 std::cout <<
" > Input uncertainty names and histograms provided \n" << std::endl;
190 std::vector<TH3F*> JMR_uncertainties_hists_3d;
191 int histocount3d = 0;
192 std::vector<TH2D*> JMR_uncertainties_hists_2d;
193 int histocount2d = 0;
196 for (
int i=0; i < std::ssize(uncertainty_names); i++){
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){
202 if (unctreatment ==
"eLOGmOeAbsEta"){
203 JMR_uncertainties_hists_3d.push_back((TH3F*)f_JMR_uncertainties_histograms->Get(histoname));
204 iprime[i] = histocount3d;
206 }
else if (unctreatment ==
"PtAbsMass"){
207 JMR_uncertainties_hists_2d.push_back((TH2D*)f_JMR_uncertainties_histograms->Get(histoname));
208 iprime[i] = histocount2d;
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;
215 std::cout <<
"Can't read input histo." << UFO_JMR_uncertainties_histo_names[i] <<
"\n";
221 std::cout <<
"\n > Input 2D and 3D histograms are read now \n" << std::endl;
224 std::vector<std::unique_ptr<TH1D>> JMR_uncertainties_1Dhists;
226 for (
int i=0; i < std::ssize(uncertainty_names); i++){
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();
231 TString unctreatment = uncertainty_treatment[i].c_str();
232 float uncertainty_value = 0;
234 if (unctreatment ==
"eLOGmOeAbsEta"){
236 auto* hist1 = JMR_uncertainties_hists_3d.at(iprime[i]);
239 double j = hist0->GetBinCenter(
bin);
242 double cosh_eta = std::cosh(eta_bin);
243 double energy_bin = sqrt((mass_bin*mass_bin) + (j*j)*pow(cosh_eta,2));
246 double x = energy_bin,
y = TMath::Log(mass_bin/energy_bin),
z = eta_bin;
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);
254 energy_bin = sqrt((j*j) + (mass_bin*mass_bin)*pow(cosh_eta,2));
257 x = energy_bin,
y = TMath::Log(j/energy_bin),
z = eta_bin;
259 bin_energy = hist1->GetXaxis()->FindBin(
x);
260 bin_mass = hist1->GetYaxis()->FindBin(
y);
261 bin_eta = hist1->GetZaxis()->FindBin(
z);
268 uncertainty_value = fabs( hist1->GetBinContent(bin_energy, bin_mass, bin_eta) );
272 hist0->SetBinContent(
bin, uncertainty_value);
276 }
else if (unctreatment ==
"PtAbsMass"){
278 auto* hist2 = JMR_uncertainties_hists_2d.at(iprime[i]);
282 double j = hist0->GetBinCenter(
bin);
285 double x = j,
y = mass_bin;
287 Int_t bin_pt = hist2->GetXaxis()->FindBin(
x);
288 Int_t bin_mass = hist2->GetYaxis()->FindBin(
y);
294 bin_pt = hist2->GetXaxis()->FindBin(
x);
295 bin_mass = hist2->GetYaxis()->FindBin(
y);
302 uncertainty_value = fabs( hist2->GetBinContent(bin_pt, bin_mass) );
306 hist0->SetBinContent(
bin, uncertainty_value);
314 std::cout <<
" > Individual uncertainties evaluated \n" << std::endl;
318 std::unique_ptr<TH1D> JMR_All_uncertainties_1Dhist = std::make_unique<TH1D>(
"total_uncertainty",
"total_uncertainty", npTbins, &npTbinning[0]);
320 for (
int j=1; j<=JMR_All_uncertainties_1Dhist->GetXaxis()->GetNbins(); j++){
322 double total_uncertainty = 0;
324 for (
int i=0; i < std::ssize(uncertainty_names); i++){
326 double uncval = JMR_uncertainties_1Dhists.at(i)->GetBinContent(j);
328 total_uncertainty += (uncval) * (uncval);
333 total_uncertainty = sqrt(total_uncertainty);
334 JMR_All_uncertainties_1Dhist->SetBinContent(j, total_uncertainty);
341 std::unique_ptr<TH1D> JMR_old_uncertainties_1Dhist = std::make_unique<TH1D>(
"Old_uncertainty",
"Old_uncertainty", npTbins, &npTbinning[0]);
343 for (
int j=1; j<=JMR_old_uncertainties_1Dhist->GetXaxis()->GetNbins(); j++){
344 JMR_old_uncertainties_1Dhist->SetBinContent(j, 0.2);
347 std::cout <<
" > Total uncertainty calculated \n" << std::endl;
351 gStyle->SetOptStat(0);
353 gROOT->SetStyle(
"ATLAS");
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);
361 std::unique_ptr<TCanvas> canvas = std::make_unique<TCanvas>(
"c1",
"c1", 1200, 800);
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);
367 DrawHistogram->SetMinimum(0);
368 DrawHistogram->SetMaximum(1.0);
369 DrawHistogram->SetLineWidth(0);
374 DrawHistogram->GetXaxis()->SetTitle(
"p_{T}^{jet} [GeV]");
375 DrawHistogram->GetXaxis()->SetLabelOffset(0.0125);
376 DrawHistogram->GetXaxis()->SetNdivisions(510);
377 DrawHistogram->GetXaxis()->SetMoreLogLabels(
true);
379 DrawHistogram->GetXaxis()->SetTitle(
"m^{jet} [GeV]");
380 DrawHistogram->GetXaxis()->SetNdivisions(505);
381 DrawHistogram->GetXaxis()->SetMoreLogLabels(
false);
383 DrawHistogram->GetXaxis()->SetTitleOffset(1.50);
385 DrawHistogram->GetYaxis()->SetTitle(
"Fractional JMR uncertainty");
386 DrawHistogram->GetYaxis()->SetLabelOffset(0.0145);
387 DrawHistogram->GetYaxis()->SetTitleOffset(1.40);
390 DrawHistogram->Draw();
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");
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");
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;
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");
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 =
"";
446 l.DrawLatex(0.67,0.89,
"ATLAS");
447 p.DrawLatex(0.67+0.115,0.89,ATLAS_LABELLING);
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");
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");
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);
468 std::string jet_info_2_string =
"";
469 if (kind_of_mass ==
"UFO"){
471 jet_info_2_string =
"|#eta^{jet}| = "+TString(Form(
"%f",eta_bin))+
", m_{UFO}^{jet} = "+TString(Form(
"%i",mass_bin))+
" GeV";
474 jet_info_2_string =
"|#eta^{jet}| = "+TString(Form(
"%f",eta_bin))+
", p_{T}^{jet} = "+TString(Form(
"%i",mass_bin))+
" GeV";
478 jet_info_2_text.DrawLatex(0.18,0.89-2*0.06,jet_info_2_string.c_str());
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");
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");
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);
506 std::println (std::cerr,
"Unknown uncertainty model: {}", uncmodel);
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");
516 legend1->Draw(
"same");
518 DrawHistogram->Draw(
"axis same");
520 std::cout <<
" > Plots are done now \n" << std::endl;
522 std::string outputdir =
"./source/JetUncertainties/util/output/";
526 if (!std::filesystem::exists(outputdir)) {
527 if (std::filesystem::create_directory(outputdir)){
528 std::cout <<
"Output directory created successfully: " << outputdir << std::endl;
530 std::cerr <<
"Failed to create directory: " << outputdir << std::endl;
534 std::cout <<
"Output directory already exists: " << outputdir << std::endl;
536 }
catch (
const std::filesystem::filesystem_error& e){
537 std::cerr <<
"Filesystem error: " << e.what() << std::endl;
541 std::string string_write;
542 std::string string_write_pdf;
543 std::string string_write_png;
545 TString mBinStr =
"mass"+std::to_string(mass_bin);
547 mBinStr =
"pT"+std::to_string(mass_bin);
550 TString EtaBinStr =
"Eta"+std::to_string(eta_bin);
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";
566 canvas->Print(string_write_pdf.c_str());