muonid_optimization_plots.C
Go to the documentation of this file.
1 #pragma once
2 
6 
7 #include "TCanvas.h"
8 #include "TH1.h"
9 #include "TH1D.h"
10 #include "TArrow.h"
11 #include "TSystem.h"
12 
13 using namespace ana;
14 
15 void DrawArrow(TCanvas * c, double x, TString arrow_opt, int line_color = kBlack, int line_style = 1, int line_width = 3);
16 
17 
18 void muonid_optimization_plots(std::string input_file_name, std::string plot_dump)
19 {
20  std::cout << "Loading CutOptimization found in " << input_file_name << std::endl;
21 
22  std::string results_file_name = input_file_name;
23  results_file_name.insert(results_file_name.find(".root"), "_results");
24  std::cout << "Saving results to " << results_file_name << std::endl;
25  std::cout << "Saving plots to " << plot_dump << std::endl;
26 
27 
28  TFile * input = TFile::Open(input_file_name.c_str(), "read");
29  CutOptimization * optimize = CutOptimization::LoadFrom(input, "muonid_cut_optimize")).release(;
30  input->Close();
31 
32  TFile * results = new TFile(results_file_name.c_str(), "recreate");
33  optimize->Optimize(CutOptimization::kIntegratedDown,
36  results->mkdir("muonid_cut_optimize"),
37  plot_dump,
38  true);
39 
40  TH1D * frac_uncert_xsec = (TH1D*) results->Get("muonid_cut_optimize/frac_uncert_xsec" );
41  TH1D * frac_uncert_sel = (TH1D*) results->Get("muonid_cut_optimize/frac_uncert_sel" );
42  TH1D * frac_uncert_bkgd_stat = (TH1D*) results->Get("muonid_cut_optimize/frac_uncert_bkgd_stat");
43  TH1D * frac_uncert_bkgd_syst = (TH1D*) results->Get("muonid_cut_optimize/frac_uncert_bkgd_syst");
44  TH1D * frac_uncert_eff = (TH1D*) results->Get("muonid_cut_optimize/frac_uncert_eff" );
45 
46  double maxy = 1.2;
47 
48  TCanvas * c = new TCanvas();
49  c->SetLeftMargin(0.12);
50 
51  frac_uncert_xsec->GetXaxis()->CenterTitle();
52  frac_uncert_xsec->GetYaxis()->CenterTitle();
53  frac_uncert_xsec->GetYaxis()->SetRangeUser(0, 12);
54  frac_uncert_xsec->GetYaxis()->SetTitleOffset(0.8);
55  frac_uncert_xsec->SetLineColor(kRed);
56 
57  frac_uncert_sel->GetXaxis()->CenterTitle();
58  frac_uncert_sel->GetYaxis()->CenterTitle();
59  frac_uncert_sel->GetYaxis()->SetRangeUser(0, 1.2);
60  frac_uncert_sel->GetYaxis()->SetTitleOffset(0.8);
61  frac_uncert_sel->SetLineColor(kRed);
62 
63  frac_uncert_bkgd_stat->GetXaxis()->CenterTitle();
64  frac_uncert_bkgd_stat->GetYaxis()->CenterTitle();
65  frac_uncert_bkgd_stat->GetYaxis()->SetRangeUser(0, 1.2);
66  frac_uncert_bkgd_stat->GetYaxis()->SetTitleOffset(0.8);
67  frac_uncert_bkgd_stat->SetLineColor(kRed);
68 
69  frac_uncert_bkgd_syst->GetXaxis()->CenterTitle();
70  frac_uncert_bkgd_syst->GetYaxis()->CenterTitle();
71  frac_uncert_bkgd_syst->GetYaxis()->SetRangeUser(0, 12);
72  frac_uncert_bkgd_syst->GetYaxis()->SetTitleOffset(0.8);
73  frac_uncert_bkgd_syst->SetLineColor(kRed);
74 
75  frac_uncert_eff->GetXaxis()->CenterTitle();
76  frac_uncert_eff->GetYaxis()->CenterTitle();
77  frac_uncert_eff->GetYaxis()->SetRangeUser(0, 1.2);
78  frac_uncert_eff->GetYaxis()->SetTitleOffset(0.8);
79  frac_uncert_eff->SetLineColor(kRed);
80 
81 // frac_uncert_xsec->Draw("hist");
82 // c->Update();
83 // DrawArrow(c, ana::vtxmin.X(), ">");
84 // DrawArrow(c, ana::vtxmax.X(), "<");
85 // c->Print((plot_dump + "/fiducial_vtx_x_frac_uncert_xsec.pdf").c_str());
86 //
87 // frac_uncert_sel->Draw("hist");
88 // c->Update();
89 // DrawArrow(c, ana::vtxmin.X(), ">");
90 // DrawArrow(c, ana::vtxmax.X(), "<");
91 // c->Print((plot_dump + "/fiducial_vtx_x_frac_uncert_sel.pdf").c_str());
92 //
93 // frac_uncert_bkgd_stat->Draw("hist");
94 // c->Update();
95 // DrawArrow(c, ana::vtxmin.X(), ">");
96 // DrawArrow(c, ana::vtxmax.X(), "<");
97 // c->Print((plot_dump + "/fiducial_vtx_x_frac_uncert_bkgd_stat.pdf").c_str());
98 //
99 // frac_uncert_bkgd_syst->Draw("hist");
100 // c->Update();
101 // DrawArrow(c, ana::vtxmin.X(), ">");
102 // DrawArrow(c, ana::vtxmax.X(), "<");
103 // c->Print((plot_dump + "/fiducial_vtx_x_frac_uncert_bkgd_syst.pdf").c_str());
104 //
105 // frac_uncert_eff->Draw("hist");
106 // c->Update();
107 // DrawArrow(c, ana::vtxmin.X(), ">");
108 // DrawArrow(c, ana::vtxmax.X(), "<");
109 // c->Print((plot_dump + "/fiducial_vtx_x_frac_uncert_eff.pdf").c_str());
110 
111 }
112 
113 void DrawArrow(TCanvas * c, double x, TString arrow_opt, int line_color, int line_style, int line_width)
114 {
115 
116  bool left = arrow_opt.Contains("<");
117  double offset = 0.07 * (c->GetX2() - c->GetX1());
118  if(left) offset *= -1;
119 
120  double y = c->GetY1() + 0.7 * (c->GetY2() - c->GetY1());
121 
122  TLine * l1 = new TLine(x, 0, x, y);
123  TArrow * arrow = new TArrow(x, y, x+offset, y, 0.04, arrow_opt.Data());
124  if(left) arrow = new TArrow(x+offset, y, x, y, 0.04, arrow_opt.Data());
125 
126  arrow->SetLineColor(line_color);
127  l1 ->SetLineColor(line_color);
128 
129  arrow->SetLineStyle(line_style);
130  l1 ->SetLineStyle(line_style);
131 
132  arrow->SetLineWidth(line_width);
133  l1 ->SetLineWidth(line_width);
134 
135  arrow->Draw();
136  l1->Draw();
137  c->Update();
138 }
139 
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
double maxy
static std::unique_ptr< CutOptimization > LoadFrom(TDirectory *dir, const std::string &name)
void DrawArrow(TCanvas *c, double x, TString arrow_opt, int line_color=kBlack, int line_style=1, int line_width=3)
OStream cout
Definition: OStream.cxx:6
void muonid_optimization_plots(std::string input_file_name, std::string plot_dump)
const double kAna2019RHCPOT
Definition: Exposures.h:224
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154