Selection_Opt.C
Go to the documentation of this file.
1 #pragma once
2 
4 
5 // analysis cuts/vars
6 //#include "NDAna/numucc_inc/NumuCCIncCuts.h"
7 //#include "NDAna/numucc_inc/NumuCCIncVars.h"
9 
10 // for data pot
12 
13 // Multiverse includes
15 #include "CAFAna/Vars/XsecTunes.h"
19 
20 //SINCpi0 includes
24 
25 using namespace ana;
26 
27 void Selection_Optimization(){//std::string input_file_name = ""){
28  //if(input_file_name == "" ) {
29  std::map<TString, SpectrumLoader *> loaders;
30  loaders["kNominal"] = new SpectrumLoader("prod_caf_R20-11-25-prod5.1reco.a_nd_genie_N1810j0211a_nonswap_fhc_nova_v08_full_v1_batch1");
31 
32  // define a hist axis to optimize
33  const HistAxis * opti_axis = new HistAxis("CVN5LabelMuonID", Binning::Simple(100, 0.0, 1.0), CVN5LabelMuonID);
34 
35  // Define selection and signal cuts
36  const Cut *kOptSignal = new Cut(kTrueNCur && kTruePi0 && kTruePi0100MeV);
37 
38  // This demo is for fiducial cut optimization so the selection
39  // should be all preselection minus fiducial constraints
40  const Cut *kOptPreSel = new Cut(kContCut);
41 
42  // central value weight to be applied to all samples
43  const Var * kCVWeight = new Var(kXSecCVWgt2020);
44 
45  // nominal definition
46  SystematicDef * sNominal = new SystematicDef("sNominal",loaders["kNominal"], opti_axis, kCVWeight);
47 
48  // Setup the genie multiverses
49  // We take flux uncertainty to be constant, so no need for PPFX universe
50  // for the sake of example, just do 10 universes
51  GenieMultiverseParameters genie_multiverse(300, getAllXsecSysts_2020());
52  std::vector<SystShifts> genie_shifts = genie_multiverse.GetSystShifts();
53 
54  SystematicDef * sGenieMultiverse = new SystematicDef("sGenieMultiverse", loaders["kNominal"], opti_axis, kCVWeight);
55 
56  // create the optimizer.
57  CutOptimization * optimize = new CutOptimization(opti_axis,kOptSignal,kOptPreSel);
58 
59  optimize->DefineNominal(sNominal);
60 
61  optimize->DefineMultiverseSystematic(sGenieMultiverse, genie_shifts);
62 
63  // optionally set spill cuts for all loaders
64  //optimize->SetSpillCuts(kStandardSpillCuts);
65 
66  // Let the loaders go
67  optimize->Go();
68 
69  // save to file
70  TFile * output = new TFile("test_opt.root", "recreate");
71 
72  optimize->SaveTo(output, "cvn5labelmuonid_cut_optimize");
73 
74  output->Close();
75  //}
76  /* else {
77  // load input file provided in argument
78  TFile * input = TFile::Open(input_file_name.c_str(), "read");
79  CutOptimization * optimize = CutOptimization::LoadFrom(input->GetDirectory("vtx_cut_optimize"),"vtx_cut_optimize");
80  input->Close();
81 
82  // save resulting histograms back to file.
83  TFile * results = new TFile("demo_cut_optimization_results.root", "recreate");
84  results->mkdir("vtx_cut_optimize/results");
85  TDirectory * save_dir = results->GetDirectory("vtx_cut_optimize/results");
86  // directory to save plots
87  std::string plot_dump = "demo_cut_optimization_plots";
88  optimize->Optimize(CutOptimization::kBinByBin, // OptimizationMethod_t
89  CutOptimization::kdSigmaOverSigma, // FOM_t
90  kAna2018FHCPOT, // scale to data pot
91  save_dir,
92  plot_dump,
93  true);
94  delete optimize;
95  }*/
96 
97 }
ofstream output
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const Cut kTruePi0100MeV([](const caf::SRProxy *sr){if(sr->vtx.elastic.IsValid==false) return false;if(sr->mc.nnu==0) return false;if(sr->mc.nu.size()< 1) return false;assert(sr->mc.nnu==1);if(sr->mc.nu[0].prim.size()==0) return false;float Pi0Mass=0.134977;float KE=-10.0;float TE=-99.0;int nprim=sr->mc.nu[0].prim.size();int npi0=0;for(int i=0;i< nprim;i++){if(sr->mc.nu[0].prim[i].pdg==111){TE=sr->mc.nu[0].prim[i].p.E;KE=pow(pow(TE, 2.0)-pow(Pi0Mass, 2.0), 0.5);if(KE >=0.1) npi0++;}}if(npi0){return true;}return false;})
const ana::Var kCVWeight
const Cut kContCut
Definition: SINCpi0_Cuts.h:396
void DefineNominal(SystematicDef *nominal)
std::vector< const ISyst * > getAllXsecSysts_2020()
void SaveTo(TDirectory *dir, const std::string &name) const
void DefineMultiverseSystematic(SystematicDef *syst, std::vector< Var > mv_weights)
_Var< caf::SRProxy > Var
Definition: Var.h:7
const Var CVN5LabelMuonID([](const caf::SRProxy *sr){if(!(sr->vtx.elastic.IsValid)) return-999.9f;if(sr->vtx.elastic.fuzzyk.npng==0) return-999.9f;float maxscore=-999.9f;for(unsigned int i=0;i< sr->vtx.elastic.fuzzyk.npng;i++) if(maxscore< sr->vtx.elastic.fuzzyk.png[i].spprongcvnpart5label.muonid) maxscore=sr->vtx.elastic.fuzzyk.png[i].spprongcvnpart5label.muonid;return(float(maxscore));})
GenericSystematicDef< Cut, Var > SystematicDef
const Cut kTruePi0([](const caf::SRProxy *sr){if(sr->vtx.elastic.IsValid==false) return false;if(sr->mc.nnu==0) return false;if(sr->mc.nu.size()< 1) return false;assert(sr->mc.nnu==1);if(sr->mc.nu[0].prim.size()==0) return false;float Pi0Mass=0.134977;float KE=-10.0;float TE=-99.0;int nprim=sr->mc.nu[0].prim.size();int npi0=0;for(int i=0;i< nprim;i++){if(sr->mc.nu[0].prim[i].pdg==111){TE=sr->mc.nu[0].prim[i].p.E;KE=pow(pow(TE, 2.0)-pow(Pi0Mass, 2.0), 0.5);if(KE >=0.0) npi0++;}}if(npi0){return true;}return false;})
const Cut kTrueNCur([](const caf::SRProxy *sr){if(sr->vtx.elastic.IsValid==false) return false;if(sr->mc.nnu==0) return false;if(sr->mc.nu.size()< 1) return false;assert(sr->mc.nnu==1);return(sr->mc.nu[0].iscc==0);})
void Selection_Optimization()
Definition: Selection_Opt.C:27
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
_Cut< caf::SRProxy, caf::SRSpillProxy > Cut
Definition: Cut.h:9
std::vector< Loaders * > loaders
Definition: syst_header.h:386
std::vector< SystShifts > GetSystShifts()
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
_HistAxis< Var > HistAxis
Definition: HistAxis.h:10
const Var kXSecCVWgt2020
Definition: XsecTunes.h:105