Functions
fiducial_optimization_plots.C File Reference
#include "CAFAna/Analysis/Exposures.h"
#include "NDAna/nuebarcc_inc/NuebarCCIncCuts.h"
#include "CAFAna/XSec/CutOptimization.h"
#include "TCanvas.h"
#include "TH1.h"
#include "TH1D.h"
#include "TArrow.h"
#include "TSystem.h"
#include "TFile.h"

Go to the source code of this file.

Functions

void DrawArrow (TCanvas *c, double x, TString arrow_opt, int line_color=kBlack, int line_style=1, int line_width=3)
 
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/")
 

Function Documentation

void DrawArrow ( TCanvas *  c,
double  x,
TString  arrow_opt,
int  line_color = kBlack,
int  line_style = 1,
int  line_width = 3 
)

Definition at line 165 of file fiducial_optimization_plots.C.

References central_limit::l1, art::left(), PandAna.reco_validation.add_data::offset, and submit_syst::y.

Referenced by fiducial_optimization_plots().

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 }
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
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/" 
)

Definition at line 17 of file fiducial_optimization_plots.C.

References plot_validation_datamc::c, om::cout, DrawArrow(), allTimeWatchdog::endl, ana::kAna2019RHCPOT, ana::CutOptimization::kBinByBin, ana::CutOptimization::kdSigmaOverSigma, kRed, ana::CutOptimization::LoadFrom(), maxy, ana::CutOptimization::PlotDebug(), makeDatasetsPage::results, string, nuebarccinc::vNueCCIncFiducialMax(), and nuebarccinc::vNueCCIncFiducialMin().

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,
58  CutOptimization::kdSigmaOverSigma,
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 }
void DrawArrow(TCanvas *c, double x, TString arrow_opt, int line_color=kBlack, int line_style=1, int line_width=3)
enum BeamMode kRed
const TVector3 vNueCCIncFiducialMin(-130,-140, 150)
double maxy
std::unique_ptr< T > LoadFrom(TDirectory *dir, const std::string &label)
Definition: LoadFromFile.h:17
void PlotDebug(std::vector< TH1 * > universes, TH1 *h_nominal, 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
enum BeamMode string