9 #include "CAFAna/Cuts/NueCutsSecondAna.h" 28 std::vector <HistDef>
defs;
29 AddNueHistDefSecondAnaBasic(defs);
36 AddNueHistDefForCvn(defs);
43 const int kIdUnweight = defs.size();
54 std::vector <CutDef >
sels = {
56 {
"1_NueSecondAnaDQ",kNueSecondAnaDQ},
57 {
"2_NueNDSecondAnaDecaf",kNueNDSecondAnaDecafCut},
58 {
"3_NueNDSecondAnaPresel", kNueNDSecondAnaPresel},
60 {
"5_NueNDCVNSb",kNueNDSecondAnaPresel && kNueSecondAnaCVNSb},
65 std::vector<double> passes;
66 for (
unsigned int i=0;
i<sels.size();++
i){
67 if(sels[
i].
cut(sr)) passes.push_back(
i);
84 std::vector < std::vector<Spectrum*> > spects;
85 std::vector < std::vector<Spectrum*> > specMC;
86 std::vector < std::vector<IDecomp*> > preds;
88 for(
int selIdx = 0; selIdx<(
int)sels.size(); ++selIdx){
89 std::vector<Spectrum *> temp_spec;
90 std::vector<Spectrum *> temp_spMC;
91 std::vector<IDecomp *> temp_pred;
92 for(
int varIdx = 0; varIdx < (
int)defs.size(); ++varIdx){
97 temp_spMC.emplace_back(
new Spectrum (loaderMC, axis, sels[selIdx].cut,
kNoShift, weight));
98 temp_pred.emplace_back(
new CheatDecomp(loaderMC, axis, sels[selIdx].cut,
kNoShift, weight));
100 spects.push_back(temp_spec);
101 specMC.push_back(temp_spMC);
102 preds.push_back(temp_pred);
105 auto spfl_data =
new Spectrum (
"Cut Flow",flowBins,loaderData, kCutFlowVar,
kNoCut);
106 auto spfl_ndmc =
new Spectrum (
"Cut Flow",flowBins,loaderMC, kCutFlowVar,
kNoCut);
111 TFile*
fout =
new TFile(predFileName.c_str(),
"RECREATE");
114 for(
int selIdx = 0; selIdx < (
int)sels.size(); ++selIdx){
115 const char*
cut = sels[selIdx].name.c_str();
116 for(
int varIdx = 0; varIdx < (
int)defs.size(); ++varIdx){
117 const char*
name = defs[varIdx].name.c_str();
118 spects[selIdx][varIdx]->SaveTo(fout,
TString::Format(
"spect_%s_%s", name, cut));
119 specMC[selIdx][varIdx]->SaveTo(fout,
TString::Format(
"speMC_%s_%s", name, cut));
120 preds[selIdx][varIdx]->SaveTo(fout,
TString::Format(
"pred_%s_%s", name, cut));
122 prog.SetProgress((
double)nsteps/(sels.size()*defs.size()+1));
125 spfl_data->SaveTo(fout,
"spect_data_cutflow");
126 spfl_ndmc->SaveTo(fout,
"spect_mc_cutflow");
130 std::cout <<
"Saved prediction to " << predFileName <<
"\n";
140 TFile * predFile =
new TFile (predFileName.c_str(),
"READ");
141 TString validFileName1 (predFileName); validFileName1.ReplaceAll(
".root",
"_mc_validation.root");
142 TString validFileName2 (predFileName); validFileName2.ReplaceAll(
".root",
"_data_validation.root");
144 TFile * validFile1 =
new TFile(validFileName1,
"RECREATE");
145 TFile * validFile2 =
new TFile(validFileName2,
"RECREATE");
158 for(
int selIdx = 0; selIdx <
kNumSels; ++selIdx){
159 const char*
cut = sels[selIdx].name.c_str();
161 for(
int varIdx = 0; varIdx <
kNumVars; ++varIdx){
162 const char*
name = defs[varIdx].name.c_str();
171 spec->SaveTo(validFile2,
TString::Format(
"%s{group=Cut,cat=%s}", name,cut));
172 spMC->SaveTo(validFile1,
TString::Format(
"%s{group=Cut,cat=%s}", name,cut));
175 TDirectory* comp = validFile1->GetDirectory(
"MCComponents");
176 if(!comp) comp = validFile1->mkdir(
"MCComponents");
179 pred->AntiNueComponent().
SaveTo(comp,
TString::Format(
"%s_{group=Cut,cat=%s}{group=Component,cat=3_antinue}", name,cut));
180 pred->AntiNumuComponent().SaveTo(comp,
TString::Format(
"%s_{group=Cut,cat=%s}{group=Component,cat=4_antinumu}", name,cut));
182 (*spMC-(
pred->TotalMC())).
SaveTo(comp,
TString::Format(
"%s_{group=Cut,cat=%s}{group=Component,cat=5_other}", name,cut));
184 prog.
SetProgress((
double)nsteps/(kNumSels*kNumVars));
188 spfl->SaveTo(validFile2,
TString::Format(
"%s{group=Cut,cat=%s}",
"_cutflow",cut));
191 spfl->SaveTo(validFile1,
TString::Format(
"%s{group=Cut,cat=%s}",
"_cutflow",cut));
198 std::cout <<
"Formatted outputs saved to " << validFileName1 <<
" and " << validFileName2 <<
std::endl;
void AddNueHistDefWeight(std::vector< HistDef > &hd)
Represent the binning of a Spectrum's x-axis.
Cuts and Vars for the 2020 FD DiF Study.
void SaveTo(const osc::IOscCalc &x, TDirectory *dir, const std::string &name)
Proxy for caf::StandardRecord.
void SetSpillCut(const SpillCut &cut)
Representation of a spectrum in any variable, with associated POT.
void AddNueHistDefShowerND(std::vector< ana::HistDef > &hd)
static std::unique_ptr< CheatDecomp > LoadFrom(TDirectory *dir, const std::string &name)
void AddNueHistDefForLem(std::vector< HistDef > &)
void AddNueHistDefSelectionExtras(std::vector< HistDef > &hd)
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
const SpillCut kStandardDQCuts([](const caf::SRSpillProxy *spill){if(spill->dcmedgematchfrac==0 &&spill->fracdcm3hits==0 &&spill->nmissingdcmslg==0) return bool(spill->isgoodspill); if(spill->det==caf::kNEARDET && (spill->fracdcm3hits > 0.45|| spill->nmissingdcms > 0)) return false; if(spill->eventincomplete) return false; if(spill->det==caf::kFARDET && spill->nmissingdcmslg > 0) return false; if(spill->det==caf::kFARDET && !spill->ismc && spill->dcmedgematchfrac<=0.2) return false;return true;})
Cut out events with a noisy detector or with parts missing.
Struct to hold cut information.
const HistDef defs[kNumVars]
std::vector< float > Spectrum
const SystShifts kNoShift
void AddNueHistDefShower(std::vector< HistDef > &hd)
void AddNueHistDefTruth(std::vector< HistDef > &hd)
void SetProgress(double frac)
Update the progress fraction between zero and one.
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
A simple ascii-art progress bar.
void AddNueHistDefForLid(std::vector< HistDef > &hd)
const Var kDummy([](const caf::SRProxy *sr){return 1;})
const SpillCut kStandardSpillCuts
Apply this unless you're doing something special.
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
void AddNueHistDefVertexND(std::vector< HistDef > &hd)
void Done()
Call this when action is completed.
void AddNueHistDefConfusion(std::vector< HistDef > &hd)
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Just return the ND truth spectra as the decomposition.
const Var kUnweighted
The simplest possible Var, always 1. Used as a default weight.
void AddNueHistDefPIDs(std::vector< HistDef > &hd)
void nue_data_mc_validation(const std::string beamMode, const std::string predFileName, const bool makeFile=false)
const Cut kNoCut
The simplest possible cut: pass everything, used as a default.