Functions | Variables
plot_prediction_systs.C File Reference
#include "CAFAna/Core/Loaders.h"
#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 "3FlavorAna/Prediction/PredictionSyst3Flavor2020.h"
#include "3FlavorAna/Systs/3FlavorSystHelper.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 "TError.h"
#include "3FlavorAna/Ana2020/Systs/syst/syst_variations.h"
#include "3FlavorAna/Ana2020/Systs/syst/draw_plots_util.h"

Go to the source code of this file.

Functions

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 bool isNumu=false, const TString &option="FHC_All_nue", const TString &analysis="allxp_nue", const std::string &period="full", const std::string &filename_sh="")
 

Variables

TString mainfilename = "PlottingSysts.tex"
 
ofstream mainoutput
 
ofstream output
 
ofstream summary
 
ofstream tables
 
bool isNumuAna =false
 
Loaders::FluxType flux = Loaders::kFHC
 

Function Documentation

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

Definition at line 447 of file plot_prediction_systs.C.

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

448 {
449  if(newpage) output<<" \\newpage\n"<<std::endl;
450  output<<"\n \n% ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~ ~~~ ~~~ ~~~~ \n"
451  << "% ~~~ " << comment
452  << "% ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ \n \n"<<std::endl;
453 
454  if (isNumuAna && sublevel == 1 && !sec.Contains("Q1") )
455  output<<" \\newpage\n"<<std::endl;
456 
457  sec.ReplaceAll("_"," ");
458  sec.ReplaceAll("\\nu {","\\nu_{");
459 
460  TString section = "section";
461  if(sublevel ==1) section = "subsection";
462  if(sublevel ==2) section = "subsubsection";
463  output << "\n \\"<<section<<"{" << sec ;
464  if(sublevel <=1)
465  output<<"\\label{sec:" <<MakeLatexCommandName(sec) << "}";
466  output << "} \n\n";
467 
468  return;
469 }
ofstream output
bool isNumuAna
TString MakeLatexCommandName(TString mystring)
void plot_prediction_systs ( const bool  isNumu = false,
const TString &  option = "FHC_All_nue",
const TString &  analysis = "allxp_nue",
const std::string period = "full",
const std::string filename_sh = "" 
)

Definition at line 59 of file plot_prediction_systs.C.

References calc, ana::CompareNDDataMCFromVector(), ana::ComparePredictionsFromVector(), om::cout, allTimeWatchdog::endl, ana::FixPlotName(), GetCalculator(), ana::GetSystematics2020(), plot_timing_data::horn, isFHC, isNumuAna, ana::kCombo, ana::kComboPtExtrap, ana::kEEAntiextrap, ana::kEEextrap, ana::kMEAntiextrap, ana::kMEextrap, ana::kMMAntiextrap, ana::kMMextrap, kNue1bin, kNue3bin, ana::kNuMu, ana::kNuMuNoExtrap, kNumuOpt, kNumuOther, ana::kNuMuPtExtrap, ana::kProportional, ana::kPropPtExtrap, LtxSection(), mainfilename, mainoutput, ana::MakeLatexCommandName(), ana::MakeSummaryV(), mergePeripheral, SliceLID::numuid(), output, DCS_db_parser::period, plot_validation_datamc::pred, PrintLatexComment(), PrintLatexEnd(), PrintLatexHeader(), string, summary, systs, tables, and usedumb.

65 {
66 
68  std::cout << "******************************************" << std::endl;
69  std::cout << "isNumu: " << isNumu << std::endl;
70  std::cout << "option: " << option << std::endl;
71  std::cout << "analysis: " << analysis << std::endl;
72  std::cout << "period: " << period << std::endl;
73  std::cout << "filename_sh: " << filename_sh << std::endl;
74  std::cout << "******************************************" << std::endl;
76 
77  // Messy but we need to keep isNumuAna global for now
78  // TODO: make isNumuAna less global
79  if (isNumu)
80  isNumuAna = true;
81 
82  // Extract FHC/RHC from option
83  TString HCString;
84  if (option.Contains("FHC"))
85  {
86  isFHC = true;
87  HCString = "fhc";
88  }
89  else
90  {
91  isFHC = false;
92  HCString = "rhc";
93  }
94 
95  const bool printtableNumuND=true;
96  const bool printtableNueND=true;
97  const bool printtable=true;
98 
99  // Define output name
100  // Default is to use prediction file name, but may want to look at subset
101  TString thisoutname (filename_sh);
102  thisoutname.Remove(0,thisoutname.Last('/')+1);
103  thisoutname.ReplaceAll(".root","");
104  // If both option and analysis are specified construct a better name
105  if (!(option == "" || analysis == ""))
106  {
107  thisoutname = TString(option.Data());
108  thisoutname += "_" + analysis + "_" + TString(period.c_str());
109  }
110 
111  // Update main filename and open file
112  mainfilename = TString(thisoutname.Data());
113  mainfilename += ".tex";
114  mainoutput.open(mainfilename.Data());
115 
117 
118  // Make sub-directory and files for summary and tables
119  TString latexout = "latex/";
120  gSystem -> MakeDirectory(latexout);
121  mainoutput << "\\input{" + latexout + thisoutname + "_summary.tex}\n";
122  mainoutput << "\\input{" + latexout + thisoutname + "_tables.tex}\n";
123  mainoutput << "\\input{" + latexout + thisoutname + ".tex}\n";
124 
125  output.open((latexout+thisoutname+".tex").Data());
126  summary.open((latexout+thisoutname+"_summary.tex").Data());
127  tables.open((latexout+thisoutname+"_tables.tex").Data());
128 
130  (TString)"Comparing the shifted predictions from:"+filename_sh);
131 
132  struct PredDef
133  {
135  TString axisName;
136  };
137 
138  // Get info for all systs
139  // Define extrap type
140  // Vector of extrap types to loop over
141  struct xpDef
142  {
144  TString xpName;
145  bool isExtrap;
146  std::vector<PredDef> predDefs;
147  };
148  std::vector<xpDef> xps;
149 
150  const bool isPtExtrap = option.Contains( "PtExtrap" );
151 
152  // If not doing NuMu, then fill xps_nue.
153  if (!isNumuAna)
154  {
155  // No extrap
156  if (analysis.Contains("nxp") || analysis.Contains("allxp"))
157  xps.push_back( xpDef{ ENu2020ExtrapType::kNoExtrap, "pred_nxp", false, {} } );
158  // Proportional decomposition
159  if (analysis.Contains("xp_prop") || analysis.Contains("allxp_nue"))
160  {
161  if ( isPtExtrap ) xps.push_back( xpDef{ ENu2020ExtrapType::kPropPtExtrap, "pred_xp_prop_pt", true, {} } );
162  else xps.push_back( xpDef{ ENu2020ExtrapType::kProportional, "pred_xp_prop" , true, {} } );
163  }
164  // Combo --> FHC only
165  if (analysis.Contains("xp_combo") || (analysis.Contains("allxp_nue") && isFHC))
166  {
167  if ( isPtExtrap ) xps.push_back( xpDef{ ENu2020ExtrapType::kComboPtExtrap, "pred_xp_combo_pt", true, {} } );
168  else xps.push_back( xpDef{ ENu2020ExtrapType::kCombo , "pred_xp_combo" , true, {} } );
169  }
170  }
171  // If doing NuMu, then fill xps_numu.
172  else
173  {
174  if ( isPtExtrap )
175  {
176  // The Numu Pt extrap prediction files only contain extrapolated predictions
177  if ( analysis.Contains( "extrap" ) ) xps.push_back( xpDef{ ENu2020ExtrapType::kNuMuPtExtrap, "pred_xp_numu_pt", true, {} } );
178  }
179  else
180  {
181  // No Extrapolation
182  if (analysis.Contains("nxp") || analysis.Contains("allxp")) { xps.push_back( xpDef{ ENu2020ExtrapType::kNuMuNoExtrap, "pred_nxp" , false, {} } ); }
183  // Extrapolation
184  if (analysis.Contains("extrap") || analysis.Contains("allxp")) { xps.push_back( xpDef{ ENu2020ExtrapType::kNuMu , "pred_xp_numu", true , {} } ); }
185  }
186  }
187 
188  std::cout << "Making plots for the following extrapolations: " << std::endl;
189  for (const auto xp:xps)
190  std::cout << "\t- " << xp.xpName << std::endl;
191 
192  // Get list of systematics
193  // Pass option to determine group(s) of systematics to include in the document
194  auto systs = GetSystematics2020(option);
195  std::cout << "systs has size " << systs.size() << std::endl;
196 
197  // Define ocillation calculator
198  auto calc = GetCalculator(usedumb); // dumOsc? Default false --> global
199  // varaible defined in
200  // draw_plots_util
201 
202  //-----------------------------------------------------------------------------------------------------
203  // Get Predictions
204 
205  TString horn = isFHC ? "FHC" : "RHC";
206  bool isFakeData = option.Contains("fakeNDData");
207  bool minimizeMemory = false;
208  bool mergePeripheral = false;
209 
210  for ( auto & xp : xps )
211  {
212  if ( isNumuAna )
213  {
214  std::cout << "\nLoading Numu predictions..." << std::endl;
215 
216  std::string numuAxisName = "NumuEnergy";
217 
218  // There is no All EhadFrac Quantiles prediction for Pt extrap
219  if ( xp.xp != ENu2020ExtrapType::kNuMuPtExtrap )
220  {
221  int EhadFracQuant = -1; // All quants
222  PredictionSyst3Flavor2020* pred = new PredictionSyst3Flavor2020( xp.xp, calc, HCString.Data(), EhadFracQuant, systs, isFakeData, filename_sh, minimizeMemory );
223  xp.predDefs.push_back( PredDef{ pred, numuAxisName } );
224  }
225  for ( int EhadFracQuant = 1; EhadFracQuant <= 4; EhadFracQuant++ )
226  {
227  PredictionSyst3Flavor2020* pred = new PredictionSyst3Flavor2020( xp.xp, calc, HCString.Data(), EhadFracQuant, systs, isFakeData, filename_sh, minimizeMemory );
228  std::string numuAxisNameQuant = numuAxisName + Form( "_EhadFracQ%d", EhadFracQuant );
229  xp.predDefs.push_back( PredDef{ pred, numuAxisNameQuant } );
230  }
231  }
232  else
233  {
234  std::cout << "\nLoading Nue predictions..." << std::endl;
235  PredictionSyst3Flavor2020* pred = new PredictionSyst3Flavor2020( xp.xp, calc, systs, HCString.Data(), isFakeData, mergePeripheral, filename_sh, minimizeMemory );
236  std::string nueAxisName = "Nue2020Axis";
237  xp.predDefs.push_back( PredDef{ pred, nueAxisName } );
238  }
239  }
240  //-----------------------------------------------------------------------------------------------------
241 
242  // Make plots and tables
243  for ( auto & xp : xps )
244  { // all pred types
245  TString thissec = xp.isExtrap ?
246  "Extrapolated prediction ":"FDMC prediction (no extrap.) ";
247  thissec += horn;
248  if(xp.xpName.Contains("prop")) thissec += ": (proportional decomp.) ";
249  if(xp.xpName.Contains("combo")) thissec += ": (combo decomp.) ";
250  LtxSection(thissec);
251 
252  //auto S = systnames.begin();
253  //auto shift = shifts.begin();
254  //for ( ; S!=systnames.end() && shift!=shifts.end(); ++S, ++shift)
255  for (const auto syst:systs)
256  { // all systs
257 
258  std::cout << "Processing systematic: " << syst->ShortName() << std::endl;
259  LtxSection(syst->ShortName(), true, 1,
260  "Processing systematic: " + syst->ShortName());
261 
262  for ( auto const & pd : xp.predDefs )
263  {
264  // ApName - Want to add "_QX" to the file names so that they are
265  // unique.
266  TString ApName = "";
267  if (isNumuAna) ApName = "_"+pd.axisName(pd.axisName.Index("_")+1,pd.axisName.Sizeof());
268 
269  LtxSection((syst->ShortName() + ApName), false, 2,
270  "Printing FD Plots " + MakeLatexCommandName(pd.axisName));
271 
272  AxisType axistype = kNue1bin;
273  if(pd.axisName.Contains("Nue2020Axis")) axistype = kNue3bin;
274  if(isNumuAna) axistype = kNumuOther;
275  if(isNumuAna && pd.axisName.Contains("Energy")) axistype = kNumuOpt;
276  if(isNumuAna && axistype != kNumuOpt) continue;
277 
278  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
279  // // FD Plots
280  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
281  TString AnaType = "_";
282  if (!analysis.Contains("numu") && isNumuAna) AnaType = "_numu_";
283  if (!analysis.Contains("nue" ) && !isNumuAna) AnaType = "_nue_";
284  TString plottitle = (
285  syst->ShortName() + ApName + " " + horn +
286  (xp.isExtrap ? " FarDet Extrap (" + xp.xpName + ")":" (FarDet MC)")+
287  ";" + pd.axisName + ";" + "Events / Bin");
288  TString plotname = "compare_" + xp.xpName + AnaType + horn + "_" +
289  FixPlotName(syst->ShortName()) + "_" + pd.axisName;
290  TString prefix = "nue_pred_";
291  if(isNumuAna) prefix = "numu_pred_";
292 
293  bool printtable = true;
294 
295  ComparePredictionsFromVector(pd.pred, syst, plottitle,
296  plotname, printtable, axistype);
297 
298  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
299  // // ND Plots
300  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
301  /* How do we include the ND plots using the new loading using
302  PredictionSystJoint2018 concept?
303 
304  Decided with Alex that the best solution is to move the code that produces the ND plots to PredictionSystJoint2018.
305 
306  Moving towards a scenario where we have PredictionSystJoint2018 handle all the loading from file and extracting spectra.
307 
308  */
309  if (!xp.isExtrap || (isPtExtrap))// && !isNumuAna))
310  continue; // only make ND plots for extrapolated predictions
311 
312  // Define ModularExtrapComponent
313  EModExtrapComps modExtrapComp;
314 
315  if (isNumuAna)
316  {
317  if (isFHC)
318  modExtrapComp = kMMextrap;
319  else
320  modExtrapComp = kMMAntiextrap;
321  }
322  else // Nue
323  {
324  if (isFHC)
325  modExtrapComp = kMEextrap;
326  else
327  modExtrapComp = kMEAntiextrap;
328  }
329 
330  TString plottitleMu = syst->ShortName() + ApName + " " + horn +
331  " (NearDet MC); Non-Quasielastic Energy Estimator (GeV); Events / Bin";
332  TString plotnameMu = "compare_numu_ND_" + horn + "_" +
333  FixPlotName(syst->ShortName()) + "_" + pd.axisName;
334  TString numuid = "Numu";
335  if(isNumuAna)
336  {
337  numuid = pd.axisName;
338  numuid = numuid.Remove(0, numuid.First("_")+1);
339  plotnameMu = "compare_numu_ND_" + pd.axisName + "_" + horn + "_" +
340  MakeLatexCommandName((syst->ShortName() + ApName));
341  }
342  LtxSection("$\\nu_{\\mu}$ ND", true, 2, "Numu Comparisons");
343 
345  pd.pred, syst, modExtrapComp, plottitleMu, plotnameMu,
346  numuid, kNumuOpt, printtableNumuND);
347  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
348  if ( !printtableNueND || isNumuAna ) // continue
349  continue;
350  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
351  // Redefine ModularExtrapComponent for beam Nue background
352  if (isFHC)
353  modExtrapComp = kEEextrap;
354  else
355  modExtrapComp = kEEAntiextrap;
356  TString plottitleND = syst->ShortName() + ApName + " " + horn +
357  " (NearDet MC) "+ ";" + pd.axisName + ";" + "Events / Bin";
358  TString plotnameND = "compare_nue_ND_" + horn + "_" +
359  FixPlotName(syst->ShortName()) + "_" + pd.axisName;
360  numuid = "Nue";
361  LtxSection("$\\nu_{e}$ ND", true, 2, "Nue comparisons");
363  pd.pred, syst, modExtrapComp, plottitleND,
364  plotnameND, numuid, kNue3bin, printtableNueND);
365 
366  } // for pd in xp.predDefs
367  }// for S in systnames
368  // Clean up PredictionSystJoint2018 objects
369 
370  /*
371  for (auto predictionSyst:PredictionSysts)
372  {
373  delete predictionSyst;
374  predictionSyst = NULL;
375  }
376  */
377  }// for xp in xptypes
378 
379  for (auto xp:xps)
380  {
381  LtxSection("Summary Tables");
382 
383  if (xp.xpName.Contains("nxp"))
384  {
385  LtxSection(
386  "FDMC Prediction " + horn + " (no extrapolation) - Signal (Sorted by chisq)",
387  false, 1);
388  MakeSummaryV("sig" , "nxp", true);
389  LtxSection(
390  "FDMC Prediction " + horn + " (no extrapolation) - Background (Sorted by chisq)",
391  true, 1);
392  MakeSummaryV("bkg", "nxp", true);
393  LtxSection(
394  "FDMC Prediction " + horn + " (no extrapolation) - Signal+Background (Sorted by chisq)",
395  true, 1);
396  MakeSummaryV("tot", "nxp", true);
397  }
398 
399  if (xp.xpName.Contains("combo"))
400  {
401  LtxSection("Extrapolated Prediction " + horn + " (combo decomp.) - Signal (Sorted by chisq)", true, 1);
402  MakeSummaryV("sig" ,"xp_combo",true);
403  LtxSection("Extrapolated Prediction " + horn + " (combo decomp.) - Background (Sorted by chisq)",
404  true, 1);
405  MakeSummaryV("bkg","xp_combo",true);
406  LtxSection("Extrapolated Prediction " + horn + " (combo decomp.) - Signal+Background (Sorted by chisq)",
407  true, 1);
408  MakeSummaryV("tot","xp_combo",true);
409  }
410 
411  if (xp.xpName.Contains("prop"))
412  {
413  LtxSection(
414  "Extrapolated Prediction " + horn + " (prop decomp.) - Signal PROP (Sorted by chisq)", true, 1);
415  MakeSummaryV("sig" ,"xp_prop",true);
416  LtxSection(
417  "Extrapolated Prediction " + horn + " (prop decomp.) - Background PROP (Sorted by chisq)", true, 1);
418  MakeSummaryV("bkg","xp_prop",true);
419  LtxSection(
420  "Extrapolated Prediction " + horn + " (prop decomp.) - Signal+Background PROP (Sorted by chisq)", true, 1);
421  MakeSummaryV("tot","xp_prop",true);
422  }
423  if (xp.xpName.Contains("pred_xp_numu")) {
424  LtxSection ( "Extrapolated Prediction " + horn + " - Signal PROP (Sorted by chisq)" , true, 1);
425  MakeSummaryV( "sig" ,"pred_xp_numu",true);
426  LtxSection ( "Extrapolated Prediction " + horn + " - Background PROP (Sorted by chisq)", true, 1);
427  MakeSummaryV( "bkg","pred_xp_numu",true);
428  LtxSection ( "Extrapolated Prediction " + horn + " - Signal+Background PROP (Sorted by chisq)", true, 1);
429  MakeSummaryV( "tot","pred_xp_numu",true);
430  }
431  }
432 
433  PrintLatexEnd();
434 
435  std::cout << "Tested to HERE!" << std::endl;
436  std::cout << "Finished!" << std::endl;
437  return;
438 }
ofstream output
TString FixPlotName(TString mystring)
osc::IOscCalc * GetCalculator(bool usingdumb)
std::vector< SystGroupDef > systs
Definition: syst_header.h:385
Loads shifted spectra from files.
bool mergePeripheral
Struct to hold prediction information.
static Var numuid(const std::shared_ptr< CAFAnaModel > &model)
Definition: SliceLIDVar.h:63
void PrintLatexHeader()
const IPrediction * pred
osc::OscCalcDumb calc
const TString mainfilename
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
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
static bool isFHC
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
std::vector< const ISyst * > GetSystematics2020(const TString option)
ofstream tables
void PrintLatexComment(TString comment="")
bool usedumb
void PrintLatexEnd()
ofstream mainoutput
enum BeamMode string
void PrintLatexComment ( TString  comment = "")

Definition at line 471 of file plot_prediction_systs.C.

References allTimeWatchdog::endl, and output.

472 {
473  output<<"% ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~\n"<<std::endl;
474  output<<"% " << comment << std::endl;
475  output<<"% ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~\n"<<std::endl;
476 }
ofstream output
void PrintLatexEnd ( )

Definition at line 478 of file plot_prediction_systs.C.

References allTimeWatchdog::endl, and mainoutput.

479 {
480  mainoutput<<" \\end{document}\n"<<std::endl;
481 }
ofstream mainoutput
void PrintLatexHeader ( )

Definition at line 440 of file plot_prediction_systs.C.

References allTimeWatchdog::endl, isNumuAna, and mainoutput.

441 {
442  if(isNumuAna) mainoutput<<" \\input{header_numu} \n";
443  else mainoutput<<" \\input{header_nue} \n";
444  mainoutput<<" \\newpage\n"<<std::endl;
445 }
bool isNumuAna
ofstream mainoutput

Variable Documentation

Definition at line 48 of file plot_prediction_systs.C.

bool isNumuAna =false

Definition at line 41 of file plot_prediction_systs.C.

TString mainfilename = "PlottingSysts.tex"

Definition at line 35 of file plot_prediction_systs.C.

ofstream mainoutput

Definition at line 36 of file plot_prediction_systs.C.

ofstream output

Definition at line 37 of file plot_prediction_systs.C.

ofstream summary

Definition at line 38 of file plot_prediction_systs.C.

ofstream tables

Definition at line 39 of file plot_prediction_systs.C.