MakeSystsPDF.C
Go to the documentation of this file.
1 
2 #include <fstream>
3 
4 #include "TSystem.h"
5 #include "TFile.h"
6 #include "TCanvas.h"
7 #include "TKey.h"
8 #include "TLegend.h"
9 #include "TLegendEntry.h"
10 #include "TPaletteAxis.h"
11 
13 #include "CAFAna/Core/Progress.h"
14 #include "CAFAna/Core/ISyst.h"
18 
21 
22 using namespace ana;
23 
24 using std::cout;
25 using std::endl;
26 using std::ofstream;
27 using std::ostringstream;
28 using std::string;
29 
30 using covmx::Sample;
31 
32 void MakeSystsPDF(string systFileName, string sampleName) {
33 
34  DontAddDirectory guard;
35  gErrorIgnoreLevel = kWarning;
36 
37  Sample sample = GetSampleFromOptString(sampleName);
38  SetInfo(sample);
39 
40  auto calc = DefaultSterileCalc(4);
42  calc->SetDm(4, 10);
43  calc->SetAngle(2, 4, M_PI/4);
44  calc->SetAngle(3, 4, M_PI/2);
45 
46  SystematicsMaker* systs = LoadFromFile<SystematicsMaker>(systFileName, sample.GetTag()).release();
47  systs->Go(sample, calc);
48 
49  string buildDir = "systs_pdf/build/"+sample.GetTag();
50 
51  // Create latex file to write to
52  gSystem->MakeDirectory("systs_pdf");
53  gSystem->MakeDirectory("systs_pdf/pdf");
54  gSystem->MakeDirectory("systs_pdf/build");
55  gSystem->MakeDirectory(buildDir.c_str());
56  gSystem->MakeDirectory(Form("%s/plots", buildDir.c_str()));
57  gSystem->CopyFile(Form("%s/nus/Nus20/Plots/header.tex",
58  FindCAFAnaDir().c_str()), Form("%s/header.tex", buildDir.c_str()));
59 
60  // Write header
61  ofstream maintex;
62  maintex.open(Form("%s/main.tex", buildDir.c_str()));
63  maintex << "\n\\input{header.tex}\n\n"
64  << "\\begin{document}\n\n"
65  << "\\title{\\textcolor{\\mycolor}{\\bf "
66  << sample.GetLatexName()
67  << " Systematics 2020}}\n"
68  << "\\author{J. Hewes}\n"
69  << "\\date{\\today}\n\n"
70  << "\\maketitle\n\n"
71  << "\\begin{abstract}\n"
72  << "This document is an extensive collection of plots and tables for all the systematics considered for the CAFAna covariance framework.\n"
73  << "\\end{abstract}\n\n"
74  << "\\tableofcontents\n\n"
75  << "\\newpage\n\n"
76  << "\\input{tables.tex}\n\n";
77 
78  // Open table file
79  ofstream tabletex;
80  tabletex.open(Form("%s/tables.tex", buildDir.c_str()));
81 
82  // Loop over each systmaker
83  Progress* p = new Progress("Writing file systs");
84  size_t counter = 0;
85  for (auto it : systs->GetSystMakers()) {
86  p->SetProgress(double(counter)/double(systs->GetSystMakers().size()));
87  string systname = it.first;
88  auto syst = it.second;
89 
90  maintex << "\\section{" << systname << "}\n\n";
91 
92  // Make and save the plots
93  TCanvas* c = syst->DrawSig();
94  TString plotname = Form("%s/plots/%s_sig_all.pdf",
95  buildDir.c_str(), systname.c_str());
96  c->SaveAs(plotname.Data());
97  delete c;
98 
99  c = syst->DrawBkg();
100  plotname = Form("%s/plots/%s_bkg_all.pdf",
101  buildDir.c_str(), systname.c_str());
102  c->SaveAs(plotname.Data());
103  delete c;
104 
105  maintex << "\\begin{figure}[h!]\n"
106  << " \\includegraphics[width=0.49\\textwidth]{plots/"
107  << systname << "_sig_all.pdf}\n"
108  << " \\includegraphics[width=0.49\\textwidth]{plots/"
109  << systname << "_bkg_all.pdf}\n"
110  << " \\caption{Systematic shifts in the near detector for signal (left) and background (right).}\n"
111  << "\\end{figure}\n\n";
112 
113  // Now write the shift table
114  ostringstream ssTable;
115  ssTable << "ratiotable" << systname << "all";
116  string tablename = MakeLatexCommandName(ssTable.str());
117 
118  tabletex << syst->WriteTable(tablename);
119 
120  maintex << "\\begin{table}[h!]\n"
121  << " \\caption{Systematic shift table.}\n"
122  << " \\" << tablename << "\n"
123  << "\\end{table}\n\n"
124  << "\\clearpage\n\n";
125 
126  if (syst->GetShifts().size() > 1) {
127 
128  for (auto it : syst->GetShifts()) {
129 
130  string shiftname = it.first;
131  auto shift = it.second;
132 
133  maintex << "\\subsection{" << shiftname << "}\n\n";
134 
135  c = shift->DrawSig(syst->GetSpectra()[0].first);
136  plotname = Form("%s/plots/%s_sig_%s.pdf",
137  buildDir.c_str(), systname.c_str(), shiftname.c_str());
138  c->SaveAs(plotname.Data());
139  delete c;
140 
141  c = shift->DrawBkg(syst->GetSpectra()[0].second);
142  plotname = Form("%s/plots/%s_bkg_%s.pdf",
143  buildDir.c_str(), systname.c_str(), shiftname.c_str());
144  c->SaveAs(plotname.Data());
145  delete c;
146 
147  maintex << "\\begin{figure}[h!]\n"
148  << " \\includegraphics[width=0.49\\textwidth]{plots/"
149  << systname << "_sig_" << shiftname << ".pdf}\n"
150  << " \\includegraphics[width=0.49\\textwidth]{plots/"
151  << systname << "_bkg_" << shiftname << ".pdf}\n"
152  << " \\caption{Systematic shifts in the near detector for signal (left) and background (right).}\n"
153  << "\\end{figure}\n\n";
154 
155  ssTable.str("");
156  ssTable << "ratiotable" << systname << shiftname;
157  tablename = MakeLatexCommandName(ssTable.str());
158 
159  tabletex << shift->WriteTable(syst->GetSpectra()[0], tablename);
160 
161  maintex << "\\begin{table}[h!]\n"
162  << " \\caption{Systematic shift table for near detector.}\n"
163  << " \\" << tablename << "\n"
164  << "\\end{table}\n\n"
165  << "\\clearpage\n\n";
166 
167  }
168  }
169  ++counter;
170  }
171 
172  p->Done();
173  delete p;
174 
175  maintex << "\\end{document}\n";
176  maintex.close();
177 
178 }
179 
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
set< int >::iterator it
std::vector< SystGroupDef > systs
Definition: syst_header.h:385
const char * p
Definition: xmltok.h:285
void SetNus20Params(osc::IOscCalcSterile *calc, std::string type)
Definition: Calcs.cxx:29
void SetInfo(covmx::Sample &sample, double res=0)
Definition: Utilities.h:403
osc::OscCalcDumb calc
covmx::Sample GetSampleFromOptString(TString optString)
Function to take an option TString and return a single associated covmx::Sample.
Definition: Utilities.h:250
std::string FindCAFAnaDir()
Definition: Utilities.cxx:203
#define M_PI
Definition: SbMath.h:34
osc::OscCalcSterile * DefaultSterileCalc(int nflavors)
Create a sterile calculator with default assumptions for all parameters.
Definition: Calcs.cxx:97
OStream cout
Definition: OStream.cxx:6
TString MakeLatexCommandName(TString mystring)
void SetProgress(double frac)
Update the progress fraction between zero and one.
Definition: Progress.cxx:41
std::map< std::string, SystMaker * > GetSystMakers()
Definition: SystMaker.h:264
void Go(const covmx::Sample sample, osc::IOscCalc *calc)
Definition: SystMaker.cxx:1601
A simple ascii-art progress bar.
Definition: Progress.h:9
Prevent histograms being added to the current directory.
Definition: UtilsExt.h:46
void Done()
Call this when action is completed.
Definition: Progress.cxx:90
void MakeSystsPDF(string systFileName, string sampleName)
Definition: MakeSystsPDF.C:32
enum BeamMode string