reduce_the_predfile_nue_numu.C
Go to the documentation of this file.
2 #include "CAFAna/Core/Binning.h"
3 #include "CAFAna/Core/Cut.h"
4 #include "CAFAna/Core/HistAxis.h"
6 #include "CAFAna/Core/Spectrum.h"
9 #include "CAFAna/Vars/Vars.h"
10 
11 #include "TFile.h"
12 #include "TH1.h"
13 #include "TCanvas.h"
14 #include "TGaxis.h"
15 #include "TLatex.h"
16 #include "TLegend.h"
17 #include "TLine.h"
18 #include "TSystem.h"
19 #include "TROOT.h"
20 #include "TObjectTable.h"
21 #include <fstream>
22 #include <iostream>
23 #include <iomanip>
24 #include <string>
25 #include <cstddef>
26 
27 #include "syst_variations.h"
28 
29 using namespace ana;
30 
31 void reduce_the_predfile_nue_numu(const bool ReduceNue = false, const TString suffix = "v2", const int thisquantile=-1)
32 {
33  TString outfilename;
34  std::vector<TString> filenames;
35  std::vector<TString> xptype;
36  std::vector<SNameDef> systnames;
37  if (ReduceNue) {
38  // --- If reducing for nue
39  outfilename = "pred_nue_reduced_" + suffix + ".root";
40  TString folder = "/nova/ana/nu_e_ana/Ana2017/Predictions/provisional_singles/latest/";
41  filenames = {
42  folder+"pred_nxp_EnergyCVN2D_full_nueconcat_other.root",
43  folder+"pred_nxp_EnergyCVN2D_full_nueconcat_XSecSyst_part1.root",
44  folder+"pred_nxp_EnergyCVN2D_full_nueconcat_XSecSyst_part2.root",
45  folder+"pred_xp_prop_EnergyCVN2D_full_nueconcat_other.root",
46  folder+"pred_xp_prop_EnergyCVN2D_full_nueconcat_XSecSyst_part1.root",
47  folder+"pred_xp_prop_EnergyCVN2D_full_nueconcat_XSecSyst_part2.root",
48  folder+"pred_xp_combo_EnergyCVN2D_full_nueconcat_other.root",
49  folder+"pred_xp_combo_EnergyCVN2D_full_nueconcat_XSecSyst_part1.root",
50  folder+"pred_xp_combo_EnergyCVN2D_full_nueconcat_XSecSyst_part2.root"
51  };
52  xptype = {"pred_nxp"/*, "pred_xp_prop"*/, "pred_xp_combo"};
53  systnames = GetShiftNames2017("allNueReduced");
54  } else {
55  // --- If reducing for numu.
56  outfilename = "pred_numu_reduced_" + suffix + ".root";
57  filenames = {
58  "/nova/ana/nu_mu_ana/Ana2017/Predictions/provisional/singles/fromShiqi/TO_NUMU_XP.root",
59  "/nova/ana/nu_mu_ana/Ana2017/Predictions/provisional/pred_nxp_Energy_AllQuantiles_full_numuconcat_numuconcat_Everything_v2.root"
60  };
61  //filenames = { "/nova/ana/users/karlwarb/Systematic_Studies/pred_nxp_xp_numu_Energy_AllQuants_full_numudecaf_CalShifts_2sigmaNoTau.root" };
62  xptype = {"pred_nxp","pred_xp_numu"};
63  systnames = GetShiftNames2017("allNumuReduced");
64  }
65 
66  std::cout << "\n\t ReduceNue is " << ReduceNue << " ==> outfilename is " << outfilename << "\n" << std::endl;
67 
68  // --- Now open the output file.
69  auto outfile = new TFile(outfilename,"recreate");
70  // --- Push back the nominal sets to this vector.
71  systnames.push_back({"Nominal" ,{"noShift"}}); // Real nominal
72 
73  for(auto const & filename:filenames){
74  std::cout << "\n Open file " << filename << std::endl;
75  auto infile = new TFile (filename,"read");
76  for ( auto const & S:systnames ){
77 
78  std::vector<TString> Sigmas = S.sigma_names;
79 
80  //HACK HACK
81  //if(!ReduceNue && ! S.syst_name.Contains("SumSmallXSecJoint2017")) continue;
82  // --- Make sure that Lightlevel has the noshift sample!!
83  if (S.syst_name == "Lightlevel") Sigmas = {"plusOne","noShift","minusOne"};
84 
85  for ( auto const & xp:xptype ){
86  auto dir = infile->GetDirectory(xp + "_" + S.syst_name);
87  if(!dir) continue;
88  if(!ReduceNue && S.syst_name.Contains("SumSmallXSecJoint2017") && xp == "pred_xp_numu" && !filename.Contains("Shiqi")) {
89  std::cerr << "\nSkipping " << S.syst_name << " from " << filename << std::endl;
90  continue;
91  }
92 
93  auto outdir = outfile->mkdir(xp + "_" + S.syst_name);
94  std::cout << "\nCreate " << xp + "_" + S.syst_name << std::endl;
95 
96  for ( uint s = 0; s<Sigmas.size(); ++s){
97  // === This section is a direct + lazy copy for ReduceNue and ReduceNumu. If you change something in the schema of
98  // === Nue/Numu please change the same thing in the other one.
99  // --- If Reduce Nue
100  if (ReduceNue) {
101  TString VarNa = "nue_pred_EnergyCVN2D";
102  auto dirSigma = dir->GetDirectory(Sigmas[s] + "/" + VarNa );
103  if(!dirSigma) {
104  std::cerr << "\n\nI can't find " << Sigmas[s] + "/" + VarNa << ". Check the name" << std::endl;
105  continue;
106  //std::cerr << "Problem " << dirSigma->GetPath() << std::endl;
107  //abort();
108  }
109  auto temp = outdir->mkdir(Sigmas[s]);
110  auto pred = ana::LoadFrom<IPrediction> (dirSigma);
111  pred->SaveTo( temp, VarNa ) ;
112  std::cout << "wrote " << temp->GetPath() << std::endl;
113  } else {
114  // --- If Reduce Numu
115  std::cerr << "ReduceNue is false so doing NuMu path..." << std::endl;
116  // Now loop through quantiles.
117  for (uint qu=1; qu<5; ++qu) {
118 
119  if(thisquantile > 0 && qu !=thisquantile) continue;
120 
121  TString QuantNa = "numu_pred_Energy_Quant" + std::to_string(qu);
122  TString DirNa = Sigmas[s] + "_Quant" + std::to_string(qu);
123 
124  auto dirSigma = dir->GetDirectory( Sigmas[s] + "/" + QuantNa );
125  //HACK HACK
126  if(filename.Contains("Shiqi")) dirSigma = dir->GetDirectory( Sigmas[s] + "_Quant" + std::to_string(qu) + "/" + QuantNa );
127 
128  if(!dirSigma) {
129  std::cerr << "\n\nI can't find " << Sigmas[s] + "/" + QuantNa << ". Check the name" << std::endl;
130  continue;
131  //abort();
132  }
133 
134  auto temp = outdir->mkdir( DirNa );
135  auto pred = ana::LoadFrom<IPrediction> (dirSigma);
136  pred->SaveTo( temp, QuantNa ) ;
137 
138  std::cout << "wrote " << temp->GetPath() << std::endl;
139  delete dirSigma;
140  }
141  }
142  }
143  }//end xp
144  }//end systs;
145  std::cout << "Done with " << filename << std::endl;
146  delete infile;
147  }
148  std::cout << "Done. Now closing file " << outfilename << std::endl;
149  delete outfile;
150 
151  std::cout << "Saved to " << outfilename << std::endl;
152 }
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
#define S(x, n)
OStream cerr
Definition: OStream.cxx:7
string filename
Definition: shutoffs.py:106
std::vector< SNameDef > GetShiftNames2017(const TString opt="all")
const XML_Char * s
Definition: expat.h:262
string outfilename
knobs that need extra care
string infile
std::unique_ptr< IPrediction > LoadFrom< IPrediction >(TDirectory *dir, const std::string &label)
Definition: IPrediction.cxx:18
OStream cout
Definition: OStream.cxx:6
TDirectory * dir
Definition: macro.C:5
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
void reduce_the_predfile_nue_numu(const bool ReduceNue=false, const TString suffix="v2", const int thisquantile=-1)
const std::string outdir
FILE * outfile
Definition: dump_event.C:13
unsigned int uint