Functions | Variables
plot_prediction_systs.C File Reference
#include "CAFAna/Analysis/Exposures.h"
#include "CAFAna/Core/Binning.h"
#include "CAFAna/Core/Cut.h"
#include "CAFAna/Core/HistAxis.h"
#include "CAFAna/Core/LoadFromFile.h"
#include "CAFAna/Core/Spectrum.h"
#include "3FlavorAna/Vars/NueVars.h"
#include "CAFAna/Vars/Vars.h"
#include "TFile.h"
#include "TH1.h"
#include "TCanvas.h"
#include "TGaxis.h"
#include "TLatex.h"
#include "TLegend.h"
#include "TLine.h"
#include "TSystem.h"
#include "TROOT.h"
#include "TObjectTable.h"
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstddef>
#include "CAFAna/shared/Ana2017/syst_variations.h"
#include "CAFAna/shared/Ana2017/draw_plots_util.h"

Go to the source code of this file.

Functions

ofstream mainoutput (mainfilename.Data())
 
void PrintLatexHeader ()
 
void PrintLatexComment (TString comment="")
 
void PrintLatexEnd ()
 
void LtxSection (TString sec, bool newpage=true, int sublevel=0, TString comment="")
 
void plot_prediction_systs (const std::string &filename_sh, const std::string &period="full", const std::string &filename_nom="")
 

Variables

const TString mainfilename = "PlottingSysts.tex"
 
ofstream output
 
ofstream summary
 
ofstream tables
 
bool isNumuAna =false
 

Function Documentation

void LtxSection ( TString  sec,
bool  newpage = true,
int  sublevel = 0,
TString  comment = "" 
)

Definition at line 308 of file plot_prediction_systs.C.

References allTimeWatchdog::endl, and ana::MakeLatexCommandName().

Referenced by plot_prediction_systs().

308  {
309  if(newpage) output<<" \\newpage\n"<<std::endl;
310  output<<"\n \n% ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~ ~~~ ~~~ ~~~~ \n"
311  << "% ~~~ " << comment
312  << "% ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ \n \n"<<std::endl;
313 
314  if (isNumuAna && sublevel ==1 && !sec.Contains("Q1") ) output<<" \\newpage\n"<<std::endl;
315 
316  sec.ReplaceAll("_"," ");
317  sec.ReplaceAll("\\nu {","\\nu_{");
318 
319  TString section = "section";
320  if(sublevel ==1) section = "subsection";
321  if(sublevel ==2) section = "subsubsection";
322  output << "\n \\"<<section<<"{" << sec ;
323  if(sublevel <=1) output<<"\\label{sec:" <<MakeLatexCommandName(sec) << "}";
324  output << "} \n\n";
325 
326  return;
327 }
ofstream output
bool isNumuAna
TString MakeLatexCommandName(TString mystring)
ofstream mainoutput ( mainfilename.  Data())
void plot_prediction_systs ( const std::string filename_sh,
const std::string period = "full",
const std::string filename_nom = "" 
)

Definition at line 48 of file plot_prediction_systs.C.

References om::cerr, ana::CompareNDDataMCFromVector(), ana::ComparePredictionsFromVector(), ana::ComparePredictionsPeripheralFromVector(), om::cout, d, dir, allTimeWatchdog::endl, file, ana::FixPlotName(), GetExtrapolationDefs(), GetShiftNames2017(), isNumuAna, kNue1bin, kNue3bin, kNue4bin, kNumuOpt, kNumuOther, LtxSection(), mainoutput, ana::MakeLatexCommandName(), ana::MakeSummaryV(), SliceLID::numuid(), DCS_db_parser::period, PrintLatexComment(), PrintLatexEnd(), PrintLatexHeader(), S, and PandAna.Demos.tute_pid_validation::var.

49 {
50 
51  TFile * file = new TFile(filename_sh.c_str(), "READ");
52  TFile * file_nom;
53  TObject::SetObjectStat(1);
54 
55  if(filename_nom == "") file_nom = file;
56  else file_nom = new TFile(filename_nom.c_str(), "READ");
57 
58  if(file->IsZombie() || file_nom->IsZombie()){std::cerr << "Problem with input files " << std::endl; return;}
59 
60  isNumuAna = (filename_sh.find("numu")!=std::string::npos);
61 
63 
64  TString thisoutname (filename_sh);
65  TString latexout = "latex/";
66  gSystem -> MakeDirectory( latexout );
67  thisoutname.Remove(0,thisoutname.Last('/')+1);
68  thisoutname.ReplaceAll(".root","");
69  mainoutput << "\\input{" + latexout + thisoutname + "_summary.tex}\n";
70  mainoutput << "\\input{" + latexout + thisoutname + "_tables.tex}\n";
71  mainoutput << "\\input{" + latexout + thisoutname + ".tex}\n";
72 
73  output.open((latexout+thisoutname+".tex").Data());
74  summary.open((latexout+thisoutname+"_summary.tex").Data());
75  tables.open((latexout+thisoutname+"_tables.tex").Data());
76 
77  PrintLatexComment((TString)"Comparing the shifted predictions from:"+filename_sh);
78 
79  // Get info for all systs and vars
80  std::vector<TString> xptype = {"pred_nxp"};
81  if (!isNumuAna) xptype = {"pred_nxp","pred_xp_combo", "pred_xp_prop"};
82  else xptype = {"pred_nxp","pred_xp_numu"};
83 
84  std::vector<SNameDef> systnames = GetShiftNames2017();
85  //std::vector<SNameDef> systnames = GetShiftNames2017("AllSmall");
86  //std::vector<SNameDef> systnames = GetShiftNames2017("CalibShape");
87  //std::vector<SNameDef> systnames = GetShiftNames2017("allNueReduced");
88  //std::vector<SNameDef> systnames = GetShiftNames2017("allNumuReduced");
89  //std::vector<SNameDef> systnames = GetShiftNames2017("XSecSyst_1of6");
90  //std::vector<SNameDef> systnames = GetShiftNames2017("XSecSyst_Frac");
91  std::vector<ExtrapDef> xpdefs = GetExtrapolationDefs( isNumuAna?"numu":"nue" , period.c_str() );;
92 
93  const bool printtableNumuND=true;
94  const bool printtableNueND=true;
95  const bool printtable=true;
96 
97  TString nueDecompFolder ="extrap/EEextrap/Decomp";
98  TString numuDecompFolder ="extrap/MEextrap/Decomp";
99  if(isNumuAna) numuDecompFolder = "extrap/MMextrap/Decomp";
100 
101  // Make plots and tables
102  TDirectory * nir, * dir;
103  TDirectory * dpred_no;
104  TDirectory * dnumu_no, *dnue_no ;
105  std::vector<TDirectory *> dnumu_sh;
106  std::vector<TDirectory *> dnue_sh;
107  std::vector<TDirectory *> dpred_sh;
108 
109  for ( auto const & S:systnames ){ // all systs
110  //Hack to run tests
111  //if(!isNumuAna && S.syst_name=="Cherenkov") break;
112  //if(!isNumuAna && !(S.syst_name.Contains("Ma"))) continue;
113  //if( isNumuAna && S.syst_name.Contains("RPA")) break;
114 
115  std::vector<TString> Sigmas = S.sigma_names;//shifts for this syst
116  LtxSection(S.syst_name);
117 
118  for ( auto const & var:xpdefs){ // all vars
119  TString ApName = "";
120  if ( isNumuAna) {
121  ApName = "_"+var.name(var.name.Index("_")+1,var.name.Sizeof());
122  ApName.ReplaceAll( "Quant", "Q" );
123  }
124 
125  AxisType axistype =kNue1bin;
126  if(var.name.Contains("CVN2D_3bin")) axistype = kNue3bin;
127  else if(var.name.Contains("CVN2D")) axistype = kNue4bin; //gah
128  if(isNumuAna) axistype = kNumuOther;
129  if(isNumuAna && var.name.Contains("Energy")) axistype = kNumuOpt;
130 
131  if(axistype == kNue3bin) continue;
132  if(isNumuAna && axistype != kNumuOpt) continue;
133 
134  //HACK HACK HACK
135  if(!isNumuAna && 1){
136  if(S.syst_name == "MaCCQE_reduced"){
137  std::cout << "\n\n\nswitch files \n\n\n" << std::endl;
138  file = new TFile ("/nova/ana/nu_e_ana/Ana2017/Predictions/provisional_singles/v5/pred_p_nueconcat_XSecSyst_part1_v5.root","read");
139  }
140  if(S.syst_name == "MaNCEL"){
141  std::cout << "\n\n\nswitch files \n\n\n" << std::endl;
142  file = new TFile ("/nova/ana/nu_e_ana/Ana2017/Predictions/provisional_singles/v5/pred_p_nueconcat_XSecSyst_part2_v4.root","read");
143  }
144  }
145 
146  for ( auto const & xp:xptype ){ // all pred types
147 
148  int extrapolated = ( xp == "pred_nxp" ) ? 0 : 1;
149 
150  TString dirnameNom = xp+"_Nominal";
151  // Logic to load Lightlevel nominal set.
152  if ((S.syst_name.Contains("Lightlevel") || S.syst_name.Contains("Cherenkov"))) {
153  dirnameNom = xp+"_Lightlevel";
154  std::cout << "\nSetting dirnameNom to " << dirnameNom << std::endl;
155  }
156  TString dirnameSyst = xp+"_"+S.syst_name;
157 
158  nir = file_nom->GetDirectory(dirnameNom);
159  if ( !nir ){
160  PrintLatexComment((TString) " ~~~ No Dir: " + dirnameNom );
161  continue;
162  }
163  dir = file->GetDirectory(dirnameSyst);
164  if ( !dir ){
165  PrintLatexComment((TString) " ~~~ No Dir: " + dirnameSyst );
166  continue;
167  }
168 
169  if(xp == xptype[0]) LtxSection((S.syst_name+ApName), S.syst_name != systnames[0].syst_name, 1);
170 
171  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
172  // // FD Plots
173  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
174  TString AnaType = "_";
175  if (!xp.Contains("numu") && isNumuAna) AnaType = "_numu_";
176  if (!xp.Contains("nue" ) && !isNumuAna) AnaType = "_nue_";
177 
178  TString plottitle = S.syst_name+ApName+( extrapolated >0 ? " FarDet Extrap ("+xp+")":" (FarDet MC)")+ ";"+var.name +";"+ "Events / Bin";
179  TString plotname = "compare_" + xp + AnaType + FixPlotName(S.syst_name) + "_" + var.name;
180  TString prefix = "nue_pred_";
181  if(isNumuAna) prefix = "numu_pred_";
182 
183  // Load nominal.
184  dpred_no = nir->GetDirectory("noShift/"+prefix+var.name, true);
185 
186  if(!dpred_no) continue;
187 
188  for ( uint s = 0; s<Sigmas.size(); ++s){
189  auto dirSigma = dir->GetDirectory(Sigmas[s] + "/" + prefix + var.name, true);
190  dpred_sh.push_back(dirSigma);
191  }
192  TString thissec = extrapolated >0 ? "Extrapolated prediction":"FDMC prediction (no extrap.)";
193  if(xp.Contains("prop")) thissec += " (proportional decomp.)";
194  if(xp.Contains("combo")) thissec += " (combo decomp.)";
195  LtxSection(thissec, true, 2, "Printing FD Plots " + MakeLatexCommandName(var.name));
196 
197  if( ! (axistype == kNue4bin && extrapolated) ) {
198  ComparePredictionsFromVector(dpred_no, dpred_sh, plottitle, plotname, printtable, axistype);
199  }
200  else {
201  auto dpred_no_nxp = file_nom->GetDirectory("pred_nxp_Nominal/noShift/" + prefix + var.name, true);
202  if ((S.syst_name.Contains("Lightlevel") || S.syst_name.Contains("Cherenkov"))) {
203  std::cout << "Using the LightLevelNom as nominal as looking at light level / Cherenkov.\n" << std::endl;
204  dpred_no_nxp = file_nom->GetDirectory("pred_nxp_Lightlevel/noShift/" + prefix + var.name, true);
205  }
206 
207  if(!dpred_no_nxp) std::cerr << "error nom\n";
208  std::vector<TDirectory *> dpred_sh_nxp;
209  for ( uint s = 0; s<Sigmas.size(); ++s){
210  auto dirSigma = file->GetDirectory("pred_nxp_" + S.syst_name + "/" + Sigmas[s] + "/"+prefix + var.name);
211  if(!dirSigma) std::cerr << "error sh\n";
212  dpred_sh_nxp.push_back(dirSigma);
213  }
214  ComparePredictionsPeripheralFromVector(dpred_no, dpred_no_nxp, dpred_sh, dpred_sh_nxp,
215  plottitle, plotname, printtable, axistype);
216  delete dpred_no_nxp;
217  for(auto & d:dpred_sh_nxp) delete d;
218  }
219 
220  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
221  if ( !extrapolated || ( xp == "pred_xp_combo" ) ) {
222  delete dpred_no;
223  for(auto & d:dpred_sh) delete d;
224  dpred_sh.clear();
225  delete nir, dir;
226  continue;
227  }
228  if ( !printtableNumuND ) continue; //ND Numu Plots
229  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
230  TString plottitleMu = S.syst_name+ApName+" (NearDet MC); Non-Quasielastic Energy Estimator (GeV); Events / Bin";
231  TString plotnameMu = "compare_numu_ND_"+FixPlotName(S.syst_name)+"_"+var.name;
232  TString numuid = "Numu";
233 
234  if(isNumuAna) {
235  numuid = var.name;
236  numuid= numuid.Remove(0,numuid.First("_")+1);
237  plotnameMu = "compare_numu_ND_"+var.name + "_" + MakeLatexCommandName((S.syst_name+ApName));
238  }
239 
240  dnumu_no = dpred_no->GetDirectory(numuDecompFolder);
241  for ( uint s = 0; s<Sigmas.size(); ++s)
242  dnumu_sh.push_back( dpred_sh[s]->GetDirectory(numuDecompFolder) );
243 
244  LtxSection("$\\nu_{\\mu}$ ND", true, 2, "Numu Comparisons");
245  CompareNDDataMCFromVector(dnumu_no, dnumu_sh, plottitleMu, plotnameMu, numuid, printtableNumuND, (isNumuAna ? axistype : kNumuOpt));
246 
247  delete dnumu_no;
248  for(auto & d:dnumu_sh) delete d;
249  dnumu_sh.clear();
250 
251  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
252  if ( !printtableNueND || isNumuAna ) {
253  delete dpred_no;
254  for(auto & d:dpred_sh) delete d;
255  dpred_sh.clear();
256  delete nir, dir;
257  continue;
258  }
259  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
260  TString plottitleND = S.syst_name+ApName+" (NearDet MC) "+ ";"+var.name +";"+ "Events / Bin";
261  TString plotnameND = "compare_nue_ND_"+FixPlotName(S.syst_name)+"_"+var.name;
262 
263  dnue_no = dpred_no->GetDirectory(nueDecompFolder);
264  for ( uint s = 0; s<Sigmas.size(); ++s)
265  dnue_sh.push_back( dpred_sh[s]->GetDirectory(nueDecompFolder) );
266 
267  LtxSection("$\\nu_{e}$ ND", true, 2, "Nue comparisons");
268  CompareNDDataMCFromVector(dnue_no, dnue_sh, plottitleND, plotnameND, "Nue", printtableNueND, axistype);
269 
270  delete dnue_no;
271  for(auto & d:dnue_sh) delete d;
272  delete dpred_no;
273  for(auto & d:dpred_sh) delete d;
274  dnue_sh.clear(); dpred_sh.clear();
275  delete nir, dir;
276  }// extrap, noextrap
277  } // syst names
278  }// vars
279 
280  LtxSection("Summary Tables");
281 
282  LtxSection("FDMC Prediction (no extrapolation) - Signal (Sorted by chisq)",false, 1);
283  MakeSummaryV(true , "nxp", true);
284  LtxSection("FDMC Prediction (no extrapolation) - Background (Sorted by chisq)",true, 1);
285  MakeSummaryV(false, "nxp", true);
286 
287  if(!isNumuAna) {
288  LtxSection("Extrapolated Prediction - Signal (Sorted by chisq)", true, 1);
289  MakeSummaryV(true ,"xp_combo",true);
290  LtxSection("Extrapolated Prediction - Background (Sorted by chisq)", true, 1);
291  MakeSummaryV(false,"xp_combo",true);
292  }
293 
294  LtxSection("Extrapolated Prediction - Signal PROP (Sorted by chisq)", true, 1);
295  MakeSummaryV(true ,"xp_prop",true);
296  LtxSection("Extrapolated Prediction - Background PROP (Sorted by chisq)", true, 1);
297  MakeSummaryV(false,"xp_prop",true);
298 
299  PrintLatexEnd();
300 }
ofstream output
TString FixPlotName(TString mystring)
#define S(x, n)
static Var numuid(const std::shared_ptr< CAFAnaModel > &model)
Definition: SliceLIDVar.h:63
OStream cerr
Definition: OStream.cxx:7
void PrintLatexHeader()
void ComparePredictionsPeripheralFromVector(TDirectory *dpred_no_xp, TDirectory *dpred_no_nxp, std::vector< TDirectory * > dpred_sh_xp, std::vector< TDirectory * > dpred_sh_nxp, TString plottitle, TString out_name, bool printtable=true, AxisType pidaxis=kNue4bin)
std::vector< SNameDef > GetShiftNames2017(const TString opt="all")
const XML_Char * s
Definition: expat.h:262
void CompareNDDataMCFromVector(TDirectory *d_no, std::vector< TDirectory * > d_sh, TString plottitle, TString out_name, TString tag, bool printtable=true, AxisType pidaxis=kNue1bin)
bool isNumuAna
Float_t d
Definition: plot.C:236
std::vector< ExtrapDef > GetExtrapolationDefs(const TString analysis, const TString period)
void ComparePredictionsFromVector(TDirectory *dpred_no, std::vector< TDirectory * > dpred_sh, TString plottitle, TString out_name, bool printtable=true, AxisType pidaxis=kNue1bin)
const XML_Char * prefix
Definition: expat.h:380
OStream cout
Definition: OStream.cxx:6
TString MakeLatexCommandName(TString mystring)
void MakeSummaryV(bool signal=true, TString xptype="nxp", bool sorted=false)
ofstream summary
void LtxSection(TString sec, bool newpage=true, int sublevel=0, TString comment="")
AxisType
TDirectory * dir
Definition: macro.C:5
ofstream tables
TFile * file
Definition: cellShifts.C:17
void PrintLatexComment(TString comment="")
void PrintLatexEnd()
ofstream mainoutput
unsigned int uint
void PrintLatexComment ( TString  comment = "")

Definition at line 329 of file plot_prediction_systs.C.

References allTimeWatchdog::endl.

Referenced by plot_prediction_systs().

329  {
330  output<<"% ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~\n"<<std::endl;
331  output<<"% " << comment << std::endl;
332  output<<"% ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~\n"<<std::endl;
333 }
ofstream output
void PrintLatexEnd ( )

Definition at line 335 of file plot_prediction_systs.C.

References allTimeWatchdog::endl, and mainoutput.

Referenced by plot_prediction_systs().

335  {
336  mainoutput<<" \\end{document}\n"<<std::endl;
337 }
ofstream mainoutput
void PrintLatexHeader ( )

Definition at line 302 of file plot_prediction_systs.C.

References allTimeWatchdog::endl, and mainoutput.

Referenced by plot_prediction_systs().

302  {
303  if(isNumuAna) mainoutput<<" \\input{header_numu} \n";
304  else mainoutput<<" \\input{header_nue} \n";
305  mainoutput<<" \\newpage\n"<<std::endl;
306 }
bool isNumuAna
ofstream mainoutput

Variable Documentation

bool isNumuAna =false
const TString mainfilename = "PlottingSysts.tex"

Definition at line 30 of file plot_prediction_systs.C.

Referenced by plot_prediction_systs().

ofstream output

Definition at line 32 of file plot_prediction_systs.C.

Referenced by sim::ParticleNavigator::Add(), stan::math::bernoulli_rng(), stan::math::beta_rng(), stan::math::binomial_rng(), stan::math::cauchy_rng(), caf::Proxy< caf::SRCVNResult >::CheckEquals(), caf::Proxy< caf::SRNuonEResult >::CheckEquals(), caf::Proxy< caf::SRCVNFeatures >::CheckEquals(), stan::math::chi_square_rng(), ana::ComparisonTable(), ana::ComparisonTableNbins(), ana::ComparisonTableOneNbins(), confusionMatrix(), confusionMatrixProng(), containment_optimization(), ConvertToGHad(), ConvertToGTracker(), ConvertToGXML(), rsim::PulseShaper::CreateTrace(), DataMCLoad(), demo_cut_optimization(), stan::math::double_exponential_rng(), stan::math::exp_mod_normal_rng(), stan::math::exponential_rng(), fiducial_optimization(), ana::nueccinc::NueCCIncTemplateFitter::FillCovarianceMatrix(), ana::NumuCCIncPionTemplateFitter::FillCovarianceMatrixExtra(), nueccinc_test::NueCCIncGlobalFitter::FillCovarianceMatrixFull(), nueccinc_test::NueCCIncGlobalFitter::FillCovarianceMatrixReduced(), stan::math::frechet_rng(), stan::math::gamma_rng(), stan::math::gumbel_rng(), heatMap(), stan::math::inv_chi_square_rng(), stan::math::inv_gamma_rng(), stan::math::logistic_rng(), stan::math::lognormal_rng(), LtxSection(), make_files_for_decomp_plots(), make_pair(), MakeMap(), ana::MakeSummaryV(), ana::MakeTextListFile(), model_to_cpp(), stan::math::multi_normal_cholesky_rng(), stan::math::multi_normal_rng(), stan::math::multi_student_t_rng(), muonid_optimization(), nc_bkgd_by_interaction_mode(), stan::math::neg_binomial_2_log_rng(), stan::math::neg_binomial_2_rng(), stan::math::neg_binomial_rng(), stan::math::normal_rng(), cvn::TrainingData::NSimpleOutput(), sim::operator<<(), simb::operator<<(), caf::Proxy< caf::SRCVNResult >::operator=(), caf::Proxy< caf::SRNuonEResult >::operator=(), caf::Proxy< caf::SRCVNFeatures >::operator=(), INukeNucleonCorr::OutputFiles(), stan::math::pareto_rng(), stan::math::pareto_type_2_rng(), sim::ParticleHistory::ParticleNavigator(), pidPlot(), pidPlotProng(), genie::utils::hadxs::berger::PionNucleonXSec(), plot_prediction_systs(), PlotResolution(), stan::math::poisson_log_rng(), stan::math::poisson_rng(), preselection_cutflow(), ana::CSVMaker::printHeader(), PrintLatexComment(), ana::PrintLatexFigure(), ana::PrintOscilationParameters(), ana::PrintRawEventCounts(), ana::CSVMaker::printRow(), ana::PrintTableHeader(), prod4_pid(), nuonecvntf::NuonECVNTF::produce(), cvneventtf::CVNEventTF::produce(), cvntf::CVNProngEvaluatorTF::produce(), prongcvn_optimization(), stan::math::rayleigh_rng(), SavePrediction(), stan::math::scaled_inv_chi_square_rng(), signal_count(), stan::math::skew_normal_rng(), stan::math::student_t_rng(), TEST(), stan::math::uniform_rng(), stan::math::von_mises_rng(), stan::math::weibull_rng(), and wrong_sign_uncertainty().

ofstream summary
ofstream tables