containment_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 #include "TFile.h"
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 
18  std::string input_file_name = "/nova/ana/users/ddoyle/NuebarContainmentOptimization/containment_optimization_nunubar_all.root",
19  std::string plot_dump = "/nova/ana/users/ddoyle/NuebarContainmentOptimization/plots_nunubar/integrated/")
20 {
21  std::vector<std::string> opti_labels = {"contain_top", "contain_bottom", "contain_east",
22  "contain_west", "contain_front"};
23  double arrow = 0;
24  switch(axis) {
25  case 0:
26  plot_dump += "top/";
27  arrow = 50;
28  break;
29  case 1:
30  plot_dump += "bottom/";
31  arrow = 30;
32  break;
33  case 2:
34  plot_dump += "east/";
35  arrow = 50;
36  break;
37  case 3:
38  plot_dump += "west/";
39  arrow = 30;
40  break;
41  case 4:
42  plot_dump += "front/";
43  arrow = 150;
44  break;
45  }
46 
47 
48 
49  std::cout << "Loading CutOptimization found in " << input_file_name << std::endl;
50 
51  std::string results_file_name = input_file_name;
52  results_file_name.insert(results_file_name.find(".root"), "_results");
53  std::cout << "Saving results to " << results_file_name << std::endl;
54  std::cout << "Saving plots to " << plot_dump << std::endl;
55 
56 
57  TFile * input = TFile::Open(input_file_name.c_str(), "read");
58  CutOptimization * optimize = CutOptimization::LoadFrom(input, opti_labels[axis].c_str())).release(;
59  input->Close();
60 
61  TFile * results = new TFile(results_file_name.c_str(), "update");
62  optimize->Optimize(CutOptimization::kIntegratedUp,
65  results->mkdir(opti_labels[axis].c_str()),
66  plot_dump,
67  true);
68 
69  TH1D * frac_uncert_xsec = (TH1D*) results->Get((opti_labels[axis] + "/frac_uncert_xsec" ).c_str());
70  TH1D * frac_uncert_sel = (TH1D*) results->Get((opti_labels[axis] + "/frac_uncert_sel" ).c_str());
71  TH1D * frac_uncert_bkgd_stat = (TH1D*) results->Get((opti_labels[axis] + "/frac_uncert_bkgd_stat").c_str());
72  TH1D * frac_uncert_bkgd_syst = (TH1D*) results->Get((opti_labels[axis] + "/frac_uncert_bkgd_syst").c_str());
73  TH1D * frac_uncert_eff = (TH1D*) results->Get((opti_labels[axis] + "/frac_uncert_eff" ).c_str());
74 
75  double maxy = 1.2;
76 
77  TCanvas * c = new TCanvas();
78  c->SetLeftMargin(0.17);
79 
80  frac_uncert_xsec->GetXaxis()->CenterTitle();
81  frac_uncert_xsec->GetYaxis()->CenterTitle();
82  frac_uncert_xsec->GetYaxis()->SetRangeUser(0, 1.2);
83  frac_uncert_xsec->GetYaxis()->SetTitleOffset(1.1);
84  frac_uncert_xsec->SetLineColor(kRed);
85  // frac_uncert_xsec->Rebin(2);
86 
87  frac_uncert_sel->GetXaxis()->CenterTitle();
88  frac_uncert_sel->GetYaxis()->CenterTitle();
89  frac_uncert_sel->GetYaxis()->SetRangeUser(0, 1.2);
90  frac_uncert_sel->GetYaxis()->SetTitleOffset(1.1);
91  frac_uncert_sel->SetLineColor(kRed);
92  // frac_uncert_sel->Rebin(2);
93 
94  frac_uncert_bkgd_stat->GetXaxis()->CenterTitle();
95  frac_uncert_bkgd_stat->GetYaxis()->CenterTitle();
96  frac_uncert_bkgd_stat->GetYaxis()->SetRangeUser(0, 1.2);
97  frac_uncert_bkgd_stat->GetYaxis()->SetTitleOffset(1.1);
98  frac_uncert_bkgd_stat->SetLineColor(kRed);
99  // frac_uncert_bkgd_stat->Rebin(2);
100 
101  frac_uncert_bkgd_syst->GetXaxis()->CenterTitle();
102  frac_uncert_bkgd_syst->GetYaxis()->CenterTitle();
103  frac_uncert_bkgd_syst->GetYaxis()->SetRangeUser(0, 1.2);
104  frac_uncert_bkgd_syst->GetYaxis()->SetTitleOffset(1.1);
105  frac_uncert_bkgd_syst->SetLineColor(kRed);
106  // frac_uncert_bkgd_syst->Rebin(2);
107 
108  frac_uncert_eff->GetXaxis()->CenterTitle();
109  frac_uncert_eff->GetYaxis()->CenterTitle();
110  frac_uncert_eff->GetYaxis()->SetRangeUser(0, 1.2);
111  frac_uncert_eff->GetYaxis()->SetTitleOffset(0.8);
112  frac_uncert_eff->SetLineColor(kRed);
113  // frac_uncert_eff->Rebin(2);
114 
115  frac_uncert_xsec->Draw("hist");
116  c->Update();
117  DrawArrow(c, arrow , ">");
118  c->Print((plot_dump + "/" + opti_labels[axis] + "_frac_uncert_xsec.pdf").c_str());
119 
120  frac_uncert_sel->Draw("hist");
121  c->Update();
122  DrawArrow(c, arrow , ">");
123  c->Print((plot_dump + "/" + opti_labels[axis] + "_frac_uncert_sel.pdf").c_str());
124 
125  frac_uncert_bkgd_stat->Draw("hist");
126  c->Update();
127  DrawArrow(c, arrow , ">");
128  c->Print((plot_dump + "/" + opti_labels[axis] + "_frac_uncert_bkgd_stat.pdf").c_str());
129 
130  frac_uncert_bkgd_syst->Draw("hist");
131  c->Update();
132  DrawArrow(c, arrow , ">");
133  c->Print((plot_dump + "/" + opti_labels[axis] + "_frac_uncert_bkgd_syst.pdf").c_str());
134 
135  frac_uncert_eff->Draw("hist");
136  c->Update();
137  DrawArrow(c, arrow , ">");
138  c->Print((plot_dump + "/" + opti_labels[axis] + "_frac_uncert_eff.pdf").c_str());
139 
140 
141 
142 
143 }
144 
145 void DrawArrow(TCanvas * c, double x, TString arrow_opt, int line_color, int line_style, int line_width)
146 {
147 
148  bool left = arrow_opt.Contains("<");
149  double offset = 0.07 * (c->GetX2() - c->GetX1());
150  if(left) offset *= -1;
151 
152  double y = c->GetY1() + 0.7 * (c->GetY2() - c->GetY1());
153 
154  TLine * l1 = new TLine(x, 0, x, y);
155  TArrow * arrow = new TArrow(x, y, x+offset, y, 0.04, arrow_opt.Data());
156  if(left) arrow = new TArrow(x+offset, y, x, y, 0.04, arrow_opt.Data());
157 
158  arrow->SetLineColor(line_color);
159  l1 ->SetLineColor(line_color);
160 
161  arrow->SetLineStyle(line_style);
162  l1 ->SetLineStyle(line_style);
163 
164  arrow->SetLineWidth(line_width);
165  l1 ->SetLineWidth(line_width);
166 
167  arrow->Draw();
168  l1->Draw();
169  c->Update();
170 }
171 
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
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
void containment_optimization_plots(int axis, std::string input_file_name="/nova/ana/users/ddoyle/NuebarContainmentOptimization/containment_optimization_nunubar_all.root", std::string plot_dump="/nova/ana/users/ddoyle/NuebarContainmentOptimization/plots_nunubar/integrated/")