fiducial_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/NuebarFiducialOptimization/fiducial_optimization_nunubar_all.root",
19  std::string plot_dump = "/nova/ana/users/ddoyle/NuebarFiducialOptimization/plots_nunubar/binbybin/")
20 {
21  std::string rootdir = "fiducial_vtx_";
22  double arrow_up = 0;
23  double arrow_down = 0;
24  switch(axis) {
25  case 0:
26  plot_dump += "x";
27  rootdir += "x";
28  arrow_down = nuebarccinc::vNueCCIncFiducialMin.X();
29  arrow_up = nuebarccinc::vNueCCIncFiducialMax.X();
30  break;
31  case 1:
32  plot_dump += "y";
33  rootdir += "y";
34  arrow_down = nuebarccinc::vNueCCIncFiducialMin.Y();
35  arrow_up = nuebarccinc::vNueCCIncFiducialMax.Y();
36  break;
37  case 2:
38  plot_dump += "z";
39  rootdir += "z";
40  arrow_down = nuebarccinc::vNueCCIncFiducialMin.Z();
41  arrow_up = nuebarccinc::vNueCCIncFiducialMax.Z();
42  break;
43  }
44 
45  std::cout << "Loading CutOptimization found in " << input_file_name << std::endl;
46 
47  std::string results_file_name = input_file_name;
48  results_file_name.insert(results_file_name.find(".root"), "_results");
49  std::cout << "Saving results to " << results_file_name << std::endl;
50  std::cout << "Saving plots to " << plot_dump << std::endl;
51 
52  TFile * input = TFile::Open(input_file_name.c_str(), "read");
53  CutOptimization * optimize = CutOptimization::LoadFrom(input, rootdir.c_str())).release(;
54  input->Close();
55 
56  TFile * results = new TFile(results_file_name.c_str(), "recreate");
57  optimize->Optimize(CutOptimization::kBinByBin,
60  results->mkdir(rootdir.c_str()),
61  plot_dump,
62  true);
63 
64  TH1D * frac_uncert_xsec = (TH1D*) results->Get((rootdir + "/frac_uncert_xsec" ).c_str());
65  TH1D * frac_uncert_sel = (TH1D*) results->Get((rootdir + "/frac_uncert_sel" ).c_str());
66  TH1D * frac_uncert_bkgd_stat = (TH1D*) results->Get((rootdir + "/frac_uncert_bkgd_stat").c_str());
67  TH1D * frac_uncert_bkgd_syst = (TH1D*) results->Get((rootdir + "/frac_uncert_bkgd_syst").c_str());
68  TH1D * frac_uncert_eff = (TH1D*) results->Get((rootdir + "/frac_uncert_eff" ).c_str());
69 
70  double maxy = 1.2;
71 
72  TCanvas * c = new TCanvas();
73  c->SetLeftMargin(0.15);
74 
75  frac_uncert_xsec->GetXaxis()->CenterTitle();
76  frac_uncert_xsec->GetYaxis()->CenterTitle();
77  frac_uncert_xsec->GetYaxis()->SetRangeUser(0, 1.2);
78  frac_uncert_xsec->GetYaxis()->SetTitleOffset(1.1);
79  frac_uncert_xsec->SetLineColor(kRed);
80 
81  frac_uncert_sel->GetXaxis()->CenterTitle();
82  frac_uncert_sel->GetYaxis()->CenterTitle();
83  frac_uncert_sel->GetYaxis()->SetRangeUser(0, 1.2);
84  frac_uncert_sel->GetYaxis()->SetTitleOffset(1.1);
85  frac_uncert_sel->SetLineColor(kRed);
86 
87  frac_uncert_bkgd_stat->GetXaxis()->CenterTitle();
88  frac_uncert_bkgd_stat->GetYaxis()->CenterTitle();
89  frac_uncert_bkgd_stat->GetYaxis()->SetRangeUser(0, 1.2);
90  frac_uncert_bkgd_stat->GetYaxis()->SetTitleOffset(1.1);
91  frac_uncert_bkgd_stat->SetLineColor(kRed);
92 
93  frac_uncert_bkgd_syst->GetXaxis()->CenterTitle();
94  frac_uncert_bkgd_syst->GetYaxis()->CenterTitle();
95  frac_uncert_bkgd_syst->GetYaxis()->SetRangeUser(0, 1.2);
96  frac_uncert_bkgd_syst->GetYaxis()->SetTitleOffset(1.1);
97  frac_uncert_bkgd_syst->SetLineColor(kRed);
98 
99  frac_uncert_eff->GetXaxis()->CenterTitle();
100  frac_uncert_eff->GetYaxis()->CenterTitle();
101  frac_uncert_eff->GetYaxis()->SetRangeUser(0, 1.2);
102  frac_uncert_eff->GetYaxis()->SetTitleOffset(1.1);
103  frac_uncert_eff->SetLineColor(kRed);
104 
105  frac_uncert_xsec->Draw("hist");
106  c->Update();
107  DrawArrow(c, arrow_down, ">");
108  DrawArrow(c, arrow_up , "<");
109  c->Print((plot_dump + "/" + rootdir + "_frac_uncert_xsec.pdf").c_str());
110 
111  frac_uncert_sel->Draw("hist");
112  c->Update();
113  DrawArrow(c, arrow_down, ">");
114  DrawArrow(c, arrow_up , "<");
115  c->Print((plot_dump + "/" + rootdir + "_frac_uncert_sel.pdf").c_str());
116 
117  frac_uncert_bkgd_stat->Draw("hist");
118  c->Update();
119  DrawArrow(c, arrow_down, ">");
120  DrawArrow(c, arrow_up , "<");
121  c->Print((plot_dump + "/" + rootdir + "_frac_uncert_bkgd_stat.pdf").c_str());
122 
123  frac_uncert_bkgd_syst->Draw("hist");
124  c->Update();
125  DrawArrow(c, arrow_down, ">");
126  DrawArrow(c, arrow_up , "<");
127  c->Print((plot_dump + "/" + rootdir + "_frac_uncert_bkgd_syst.pdf").c_str());
128 
129  frac_uncert_eff->Draw("hist");
130  c->Update();
131  DrawArrow(c, arrow_down, ">");
132  DrawArrow(c, arrow_up , "<");
133  c->Print((plot_dump + "/" + rootdir + "_frac_uncert_eff.pdf").c_str());
134 
135 
136  // debug plots
137  TFile * fdebug = TFile::Open((plot_dump + "/debug.root").c_str());
138  auto syst_defs = optimize->GetSystDefs();
139  auto mvsyst_defs = optimize->GetMVSystDefs();
140  syst_defs.insert(syst_defs.end(), mvsyst_defs.begin(), mvsyst_defs.end());
141  std::vector<TH1*> vabs_uncert_eff_syst;
142  std::vector<TH1*> vabs_uncert_bkgd_syst;
143  std::vector<TH1*> vfrac_uncert_eff_syst;
144  std::vector<TH1*> vfrac_uncert_bkgd_syst;
145  std::vector<std::string> syst_labels;
146  for(auto syst : syst_defs) {
147  syst_labels.push_back(syst->GetName());
148  vabs_uncert_eff_syst .push_back((TH1*) fdebug->Get((syst->GetName() + "_abs_uncert_eff_syst" ).c_str()));
149  vabs_uncert_bkgd_syst .push_back((TH1*) fdebug->Get((syst->GetName() + "_abs_uncert_bkgd_syst" ).c_str()));
150  vfrac_uncert_eff_syst .push_back((TH1*) fdebug->Get((syst->GetName() + "_frac_uncert_eff_syst" ).c_str()));
151  vfrac_uncert_bkgd_syst.push_back((TH1*) fdebug->Get((syst->GetName() + "_frac_uncert_bkgd_syst").c_str()));
152  vfrac_uncert_eff_syst .back()->GetYaxis()->SetRangeUser(0, 1.2);
153  vfrac_uncert_bkgd_syst.back()->GetYaxis()->SetRangeUser(0, 1.2);
154 
155  }
156 
157  CutOptimization::PlotDebug(vabs_uncert_eff_syst , syst_labels, "hist", "Abs. Syst. Uncert Efficiency", plot_dump + "/debug_syst_abs_uncert_eff.pdf");
158  CutOptimization::PlotDebug(vabs_uncert_bkgd_syst , syst_labels, "hist", "Abs. Syst. Uncert Background", plot_dump + "/debug_syst_abs_uncert_bkgd.pdf");
159  CutOptimization::PlotDebug(vfrac_uncert_eff_syst , syst_labels, "hist", "Frac. Syst. Uncert Efficiency", plot_dump + "/debug_syst_frac_uncert_eff.pdf");
160  CutOptimization::PlotDebug(vfrac_uncert_bkgd_syst, syst_labels, "hist", "Frac. Syst. Uncert Background", plot_dump + "/debug_syst_frac_uncert_bkgd.pdf");
161 
162 
163 }
164 
165 void DrawArrow(TCanvas * c, double x, TString arrow_opt, int line_color, int line_style, int line_width)
166 {
167 
168  bool left = arrow_opt.Contains("<");
169  double offset = 0.07 * (c->GetX2() - c->GetX1());
170  if(left) offset *= -1;
171 
172  double y = c->GetY1() + 0.7 * (c->GetY2() - c->GetY1());
173 
174  TLine * l1 = new TLine(x, 0, x, y);
175  TArrow * arrow = new TArrow(x, y, x+offset, y, 0.04, arrow_opt.Data());
176  if(left) arrow = new TArrow(x+offset, y, x, y, 0.04, arrow_opt.Data());
177 
178  arrow->SetLineColor(line_color);
179  l1 ->SetLineColor(line_color);
180 
181  arrow->SetLineStyle(line_style);
182  l1 ->SetLineStyle(line_style);
183 
184  arrow->SetLineWidth(line_width);
185  l1 ->SetLineWidth(line_width);
186 
187  arrow->Draw();
188  l1->Draw();
189  c->Update();
190 }
191 
void DrawArrow(TCanvas *c, double x, TString arrow_opt, int line_color=kBlack, int line_style=1, int line_width=3)
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const TVector3 vNueCCIncFiducialMin(-130,-140, 150)
double maxy
static std::unique_ptr< CutOptimization > LoadFrom(TDirectory *dir, const std::string &name)
static void PlotDebug(TH1 *hist, std::string draw_option, std::string title, std::string name)
OStream cout
Definition: OStream.cxx:6
const TVector3 vNueCCIncFiducialMax(150, 140, 800)
const double kAna2019RHCPOT
Definition: Exposures.h:224
void fiducial_optimization_plots(int axis, std::string input_file_name="/nova/ana/users/ddoyle/NuebarFiducialOptimization/fiducial_optimization_nunubar_all.root", std::string plot_dump="/nova/ana/users/ddoyle/NuebarFiducialOptimization/plots_nunubar/binbybin/")
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