MakeUnoscPlots.C
Go to the documentation of this file.
1 // script to plot the variables for the NuS20 preselection,
2 // along with the correlation between each variable and
3 // each other variable.
4 //
5 // author: Adam Lister
6 // date : 2020-02-19
7 // email : adam.lister@wisc.edu
8 
9 #pragma once
10 
11 // framework includes
13 #include "CAFAna/Core/Loaders.h"
14 #include "CAFAna/Core/Binning.h"
15 #include "CAFAna/Core/Spectrum.h"
17 #include "CAFAna/Core/EventList.h"
18 #include "CAFAna/Core/Utilities.h"
20 #include "CAFAna/Cuts/Cuts.h"
21 #include "CAFAna/Cuts/SpillCuts.h"
22 #include "CAFAna/Vars/Vars.h"
25 
30 
31 #include "NuXAna/Vars/NusVars.h"
33 #include "NuXAna/Cuts/NusCuts20.h"
34 #include "NuXAna/Cuts/NusCuts.h"
35 
36 #include "TMVA/Reader.h"
37 #include "TMVA/IMethod.h"
38 #include "TString.h"
39 
40 // selection includes
44 
45 // root includes
46 #include "TFile.h"
47 #include "TCanvas.h"
48 #include "TH1.h"
49 #include "TH2.h"
50 
51 #include <cassert>
52 
53 using namespace ana;
54 
56 
57 void MakeUnoscPlots(TString opt){
58 
59  bool isCaf = opt.Contains("caf" , TString::kIgnoreCase);
60  bool isConcat = opt.Contains("concat", TString::kIgnoreCase);
61  assert(isCaf or isConcat);
62 
63  bool isND = opt.Contains("nd" , TString::kIgnoreCase);
64  bool isFD = opt.Contains("fd" , TString::kIgnoreCase);
65  bool isFDData = opt.Contains("fddata" , TString::kIgnoreCase);
66  bool isNDData = opt.Contains("nddata" , TString::kIgnoreCase);
67 
68  bool isCosmic = opt.Contains("cos" , TString::kIgnoreCase);
69  bool isSysts = opt.Contains("syst" , TString::kIgnoreCase);
70 
71  // ----------------------
72  // set up loaders
73  // ----------------------
74 
75  // placeholders...
76  std::string kFDDataFHCNus20Concat = "";
77  std::string kFDDataFHCNus20CAF = "";
78  std::string kFDCosmicFHCProd5 = "prod_sumdecaf_R19-11-18-prod5reco.i_fd_cosmic_fhc_full_v1_goodruns_nus2020";
79  std::string kFDCosmicFHCProd5CAF = "prod_caf_R19-11-18-prod5reco.i_fd_cosmic_fhc_full_v1_goodruns";
80  std::string kNDBurnerData = "nux_burner_prod_caf_R19-11-18-prod5reco.d.f.h_nd_numi_fhc_period235910_v1_goodruns";
81 
82  Loaders* loadersMC = new Prod5NomLoaders(
85  loadersMC->SetSpillCut(kStandardSpillCuts);
86 
87  SpectrumLoader* loadersFDData = nullptr;
88  if (isFDData) {
89  const std::string dataDef =
90  isConcat? kFDDataFHCNus20Concat : kFDDataFHCNus20CAF;
91  loadersFDData = new SpectrumLoader(dataDef);
92  loadersFDData->SetSpillCut(kStandardSpillCuts);
93  }
94 
95  SpectrumLoader* loadersNDData = nullptr;
96  if (isNDData) {
97  loadersNDData = new SpectrumLoader(kNDBurnerData);
98  loadersNDData->SetSpillCut(kStandardSpillCuts);
99  }
100 
101  SpectrumLoader* loadersCosmic = nullptr;
102  if (isCosmic){
103  loadersCosmic = new SpectrumLoader(kFDCosmicFHCProd5CAF, kCosmic);
104  //loadersCosmic->SetSpillCut(kStandardSpillCuts);
105  loadersCosmic->SetSpillCut(kStandardSpillCuts_FD_Prod4MotivatedDQ); // uses good runs list from prod4
106  }
107 
108  // --------------------------
109  // setup prediction handler
110  // --------------------------
111 
112  FDPredictionHandler fdPredH("NoExtrap");
113  fdPredH.AddLoaders(loadersMC);
114  if (isFDData)
115  fdPredH.AddData(loadersFDData);
116  if (isCosmic)
117  fdPredH.AddCosmics(loadersCosmic);
118 
119  NDPredictionHandler ndPredH("Decomp");
120  ndPredH.AddLoaders(loadersMC);
121  if (isNDData)
122  ndPredH.AddData(loadersNDData);
123 
124  if (isFD)
125  addVars(&fdPredH, "fd");
126 
127  if (isND)
128  addVars(&ndPredH, "nd");
129 
130  loadersMC->Go();
131  if (isFDData)
132  loadersFDData->Go();
133  if (isNDData)
134  loadersNDData->Go();
135  if (isCosmic)
136  loadersCosmic->Go();
137 
138  std::cout << "got all spectra" << std::endl;
139 
140  // setup output file
141  std::string fileOutName = "SelectionSpectr_Unosc.root";
142  TFile* fileOut = new TFile(fileOutName.c_str(), "RECREATE");
143 
144  if (isFD)
145  fdPredH.Save(fileOut);
146  if (isND)
147  ndPredH.Save(fileOut);
148 
149  fileOut->Close();
150 
151 }
152 
154 
155  std::vector<VarContainer> vars;
156  std::vector<VarContainer2D> vars2D;
157  std::vector<VarContainer3D> vars3D;
158  std::vector<CutContainer> cuts;
159  std::vector<CutContainer> subcuts;
160 
161  if (det == "nd"){
162  vars = varsND;
163  vars2D = vars2DND;
164  vars3D = vars3DND;
165  cuts = cutsND;
166  subcuts = subCutsND;
167  }
168  else if (det == "fd"){
169  vars = varsFD;
170  vars2D = vars2DFD;
171  vars3D = vars3DFD;
172  cuts = cutsFD;
173  subcuts = subCutsFD;
174  }
175  else {
176  throw std::logic_error("options for detector are nd or fd");
177  }
178 
179  for (size_t iCut = 0; iCut < cuts.size(); ++iCut){
180 
181  ana::Cut thisCut = cuts.at(iCut).cut;
182  std::string thisName = cuts.at(iCut).name;
183 
184  for (size_t iSub = 0; iSub < subcuts.size(); ++iSub){
185 
186  ana::Cut fullCut = thisCut && subcuts.at(iSub).cut;
187  std::string fullName = thisName + subcuts.at(iSub).name;
188 
189  for (size_t iVar = 0; iVar < vars.size(); ++iVar){
190 
191  std::cout << vars.at(iVar).name+fullName << std::endl;
192 
193  // one dimensional
194  predH->AddVar((vars.at(iVar).name+fullName).c_str(),
195  vars.at(iVar).label.c_str(),
196  vars.at(iVar).var,
197  vars.at(iVar).bins,
198  fullCut,
199  kNoShift,
200  kUnweighted,
201  cuts.at(iCut).cutdata && subcuts.at(iSub).cutdata);
202  }
203 
204  // two dimensional
205  for (size_t iVar = 0; iVar < vars2D.size(); ++iVar){
206 
207  predH->AddVar((vars2D.at(iVar).name+fullName).c_str(),
208  vars2D.at(iVar).labelx.c_str(),
209  vars2D.at(iVar).labely.c_str(),
210  vars2D.at(iVar).varx,
211  vars2D.at(iVar).vary,
212  vars2D.at(iVar).binsx,
213  vars2D.at(iVar).binsy,
214  fullCut,
215  kNoShift,
216  kUnweighted,
217  cuts.at(iCut).cutdata && subcuts.at(iSub).cutdata);
218  }
219 
220  // three dimensional
221  for (size_t iVar = 0; iVar < vars3D.size(); ++iVar){
222 
223  predH->AddVar((vars3D.at(iVar).name+fullName).c_str(),
224  vars3D.at(iVar).labelx.c_str(),
225  vars3D.at(iVar).labely.c_str(),
226  vars3D.at(iVar).labelz.c_str(),
227  vars3D.at(iVar).varx,
228  vars3D.at(iVar).vary,
229  vars3D.at(iVar).varz,
230  vars3D.at(iVar).binsx,
231  vars3D.at(iVar).binsy,
232  vars3D.at(iVar).binsz,
233  fullCut,
234  kNoShift,
235  kUnweighted,
236  cuts.at(iCut).cutdata && subcuts.at(iSub).cutdata);
237  }
238  }
239  }
240 }
const SpillCut kStandardSpillCuts_FD_Prod4MotivatedDQ
Definition: SpillCuts.h:69
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
std::vector< CutContainer > cutsFD
Definition: CutFlow.h:23
std::vector< CutContainer > subCutsND
Definition: CutFlow.h:46
Collection of SpectrumLoaders for many configurations.
Definition: Loaders.h:23
void Save(TFile *outFile)
map< string, vector< ana::Binning > > vars3D
Logic to go from unfolded data (in histogram form) to a cross-section.
Definition: CalculateXSec.C:31
void AddData(SpectrumLoader *loadersData)
void SetSpillCut(const SpillCut &cut)
std::vector< CutContainer > subCutsFD
Definition: CutFlow.h:40
void MakeUnoscPlots(TString opt)
std::vector< CutContainer > cutsND
Definition: CutFlow.h:32
void Go()
Call Go() on all the loaders.
Definition: Loaders.cxx:162
void SetSpillCut(const SpillCut &cut)
Definition: Loaders.cxx:121
std::vector< VarContainer3D > vars3DFD
Definition: CutVariables.h:74
For nominal spectra and reweighting systs (xsec/flux)
Definition: Prod5Loaders.h:101
void AddLoaders(Loaders *loaders)
virtual void AddVar(std::string name, HistAxis axis, Cut cuts, SystShifts shift, Var weight, bool cutdata=true)=0
Class to handle ND predictions.
std::vector< VarContainer2D > vars2DFD
Definition: CutVariables.h:63
virtual void Go() override
Load all the registered spectra.
const std::map< std::pair< std::string, std::string >, Variable > vars
void AddCosmics(SpectrumLoader *loaders_cosmics)
std::vector< VarContainer > varsND
Definition: CutVariables.h:82
const SystShifts kNoShift
Definition: SystShifts.cxx:21
OStream cout
Definition: OStream.cxx:6
void Save(TFile *outFile)
std::vector< CutContainer > subcuts
Definition: PlotSpectra.h:50
void AddLoaders(Loaders *loaders)
std::vector< VarContainer3D > vars3DND
Definition: CutVariables.h:109
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
std::vector< VarContainer2D > vars2DND
Definition: CutVariables.h:103
assert(nhit_max >=nhit_nbins)
std::vector< VarContainer > varsFD
Definition: CutVariables.h:28
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
Class to handle FD predictions.
void addVars(PredictionHandler *predH, std::string det)
const Var kUnweighted
The simplest possible Var, always 1. Used as a default weight.
Definition: Var.h:96
void AddData(SpectrumLoader *loaders_data)
enum BeamMode string