Ana2017_sb_opening_macro.C
Go to the documentation of this file.
1 #include "CAFAna/Cuts/Cuts.h"
5 
9 #include "CAFAna/Core/Spectrum.h"
10 
11 #include "CAFAna/Vars/Vars.h"
12 #include "CAFAna/Vars/HistAxes.h"
14 
15 #include "OscLib/OscCalcDumb.h"
17 
18 #include "TH1D.h"
19 
20 using namespace ana;
21 
23 {
24  //Make time axis for 2017 analysis period
25  const Var kSliceTime = SIMPLEVAR(hdr.unixtime);
26  const Var kSliceMeanTime = SIMPLEVAR(hdr.subevtmeantime);
27  const HistAxis kTimeAxis("unix time (s)",Binning::Simple(10000, 1391000000, 1491000000), kSliceTime);
28  const HistAxis kSliceTimeAxis("slice time (ns)",Binning::Simple(600, -50000, 550000), kSliceMeanTime);
29 
30  const HistAxis kNue2017SBEnergyAxis( "Nue Energy Estimator (GeV)",
31  Binning::Simple( 20, 0, 10 ), kNueEnergy2017 );
32 
33  const std::string fnamecos =
34  //"prod_decaf_R17-03-01-prod3reco.l_fd_genie_nonswap_fhc_nova_v08_full_nue_or_numu_or_nus_contain_v1";
35  "prod_restricteddecaf_R17-03-01-prod3reco.k_fd_numi_fhc_full_v1_goodruns_nue2017";
36 
37  SpectrumLoader loadercos(fnamecos);
38 
40 
41  struct CutDef{
42  const Cut cut;
44  };
45 
46  const int kNCuts = 4;
47  const CutDef SBCuts[kNCuts] =
48  {{kNue2017FDPeripheralHELPsideband,"HELP"}, // Peripheral High Energy Low PID
49  {kNue2017FDPeripheralHEMPsideband,"HEMP"}, // Peripheral High Energy Mid PID
50  {kNue2017FDPeripheralLPsideband,"LPID"}, // Peripheral Low PID
51  {kNue2017FDPeripheralMPsideband,"MPID"} // Peripheral Mid PID
52  };
53 
54  Spectrum* spec_cvn_cvn2d_outtime[kNCuts];
55  Spectrum* spec_cvn_nueE_outtime[kNCuts];
56  Spectrum* spec_cvn_time_outtime[kNCuts];
57  Spectrum* spec_cvn_slctime_outtime[kNCuts];
58 
59  Spectrum* spec_cvn_cvn2d_intime[kNCuts];
60  Spectrum* spec_cvn_nueE_intime[kNCuts];
61  Spectrum* spec_cvn_time_intime[kNCuts];
62  Spectrum* spec_cvn_slctime_intime[kNCuts];
63 
64  for(unsigned int i = 0 ; i < kNCuts ; ++i){
65  // out of time spectra
66  spec_cvn_cvn2d_outtime[i] = new Spectrum(loadercos, kNue2017Axis,
67  SBCuts[i].cut && kInTimingSideband,
68  kNoShift);
69 
70  spec_cvn_nueE_outtime[i] = new Spectrum(loadercos, kNue2017SBEnergyAxis,
71  SBCuts[i].cut && kInTimingSideband,
72  kNoShift);
73 
74  spec_cvn_time_outtime[i] = new Spectrum(loadercos, kTimeAxis,
75  SBCuts[i].cut && kInTimingSideband,
76  kNoShift);
77 
78  spec_cvn_slctime_outtime[i] = new Spectrum(loadercos, kSliceTimeAxis,
79  SBCuts[i].cut && kInTimingSideband,
80  kNoShift);
81 
82  // in time spectra
83  spec_cvn_cvn2d_intime[i] = new Spectrum(loadercos, kNue2017Axis,
84  SBCuts[i].cut && kInBeamSpill,
85  kNoShift);
86 
87  spec_cvn_nueE_intime[i] = new Spectrum(loadercos, kNue2017SBEnergyAxis,
88  SBCuts[i].cut && kInBeamSpill,
89  kNoShift);
90 
91  spec_cvn_time_intime[i] = new Spectrum(loadercos, kTimeAxis,
92  SBCuts[i].cut && kInBeamSpill,
93  kNoShift);
94 
95  spec_cvn_slctime_intime[i] = new Spectrum(loadercos, kSliceTimeAxis,
96  SBCuts[i].cut && kInBeamSpill,
97  kNoShift);
98  }
99 
100  // let's go!
101  loadercos.Go();
102 
103  std::cout<<"Making output file ";
104  TFile fout("Ana2017_numi_sb.root","RECREATE");
105  std::cout<< fout.GetName() << std::endl;
106 
107  for(unsigned int i = 0 ; i < kNCuts ; ++i){
108  spec_cvn_cvn2d_intime[i]->SaveTo(&fout, ("spec_cvn_cvn2d_numi_"+SBCuts[i].label).c_str());
109  spec_cvn_cvn2d_outtime[i]->SaveTo(&fout, ("spec_cvn_cvn2d_cosmic_"+SBCuts[i].label).c_str());
110 
111  spec_cvn_nueE_intime[i]->SaveTo(&fout, ("spec_cvn_nueE_numi_"+SBCuts[i].label).c_str());
112  spec_cvn_nueE_outtime[i]->SaveTo(&fout, ("spec_cvn_nueE_cosmic_"+SBCuts[i].label).c_str());
113 
114  spec_cvn_time_intime[i]->SaveTo(&fout, ("spec_cvn_time_numi_"+SBCuts[i].label).c_str());
115  spec_cvn_time_outtime[i]->SaveTo(&fout, ("spec_cvn_time_cosmic_"+SBCuts[i].label).c_str());
116 
117  spec_cvn_slctime_intime[i]->SaveTo(&fout, ("spec_cvn_slctime_numi_"+SBCuts[i].label).c_str());
118  spec_cvn_slctime_outtime[i]->SaveTo(&fout, ("spec_cvn_slctime_cosmic_"+SBCuts[i].label).c_str());
119  }
120 
121  Var kRun = SIMPLEVAR(hdr.run);
122  Var kSubrun = SIMPLEVAR(hdr.subrun);
123  Var kEvt = SIMPLEVAR(hdr.evt);
124  Var kSlice = SIMPLEVAR(hdr.subevt);
125 
126  std::vector<const Var*> vars = {&kRun, &kSubrun, &kEvt, &kSlice,
127  &kSliceMeanTime,
128  &kCVNe,
130  };
131 
132  std::vector<Cut> cuts;
133  std::vector<std:: string> fnames;
134  for(unsigned int i = 0 ; i < kNCuts ; ++i){
135  cuts.push_back(SBCuts[i].cut && kInBeamSpill);
136  cuts.push_back(SBCuts[i].cut && kInTimingSideband);
137 
138  fnames.push_back(("Ana2017_selected_numi_sb_"+SBCuts[i].label+".txt").c_str());
139  fnames.push_back(("Ana2017_selected_cosmic_sb_"+SBCuts[i].label+".txt").c_str());
140  }
141 
142  MakeTextListFile(fnamecos,
143  cuts,
144  fnames,
145  vars,
147 
148 }
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const Var kCVNe
PID
Definition: Vars.cxx:35
const Cut kNue2017FDPeripheralLPsideband
Definition of the FD peripheral Low PID.
Definition: NueCuts2017.h:195
const Var kSliceTime([](const caf::SRProxy *sr){return sr->slc.meantime/1000;})
Definition: NumuVars.h:34
void SetSpillCut(const SpillCut &cut)
const Var kSubrun
Definition: Vars.cxx:21
const Cut kNue2017FDPeripheralHELPsideband
Definition of the FD peripheral High Energy Low PID.
Definition: NueCuts2017.h:183
const Cut kNue2017FDPeripheralHEMPsideband
Definition of the FD peripheral High Energy Mid PID.
Definition: NueCuts2017.h:189
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const char * label
const Cut kInTimingSideband([](const caf::SRProxy *sr){if(sr->spill.run > util::kLastBadTimingRun) return(kInTimingSideband_before(sr)|| kInTimingSideband_after(sr));else return(kInTimingSideband_before(sr)|| kInTimingSideband_afterA(sr)|| kInTimingSideband_afterB(sr));}, [](const caf::SRSpillProxy *spill){if(spill->run > util::kLastBadTimingRun) return(kInTimingSideband_before.Livetime(spill)+ kInTimingSideband_after.Livetime(spill));else return(kInTimingSideband_before.Livetime(spill)+ kInTimingSideband_afterA.Livetime(spill)+ kInTimingSideband_afterB.Livetime(spill));}, [](const caf::SRSpillProxy *spill){return 0;})
Definition: TimingCuts.h:12
void MakeTextListFile(const std::string &wildcard, const std::vector< Cut > &cut, const std::vector< std::string > &output, const std::vector< const Var * > &floatVars, const std::vector< const Var * > &intVars, const SpillCut *spillCut)
Make a file listing all the events passing the specified cut.
Definition: EventList.cxx:193
const Var kNueEnergy2017([](const caf::SRProxy *sr){if(!sr->vtx.elastic.IsValid) return-1.0;if(sr->vtx.elastic.fuzzyk.npng< 1) return-1.0;return NueRecoE_2017FDFit(kCVNemE(sr), kCVNhadE(sr));})
Definition: NueEnergy2017.h:11
const Var kEvt
Definition: Vars.cxx:23
void Ana2017_sb_opening_macro()
Struct to hold cut information.
virtual void Go() override
Load all the registered spectra.
const std::map< std::pair< std::string, std::string >, Variable > vars
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:506
std::vector< float > Spectrum
Definition: Constants.h:610
const HistAxis kNue2017Axis("NuE Energy / Analysis Bin", kNue2017Binning, kNue2017AnaBin)
Definition: NueCuts2017.h:313
const SystShifts kNoShift
Definition: SystShifts.cxx:22
OStream cout
Definition: OStream.cxx:6
const Cut kNue2017FDPeripheralMPsideband
Definition of the FD peripheral Mid PID.
Definition: NueCuts2017.h:201
const Cut cut
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
#define SIMPLEVAR(CAFNAME)
For Vars where literally all you need is a single CAF variable.
Definition: Var.h:88
const Cut kInBeamSpill([](const caf::SRProxy *sr){if(sr->spill.run > util::kLastBadTimingRun) return kInBeamSpill_main(sr);else return kInBeamSpill_main(sr)||kInBeamSpill_shifted(sr);}, [](const caf::SRSpillProxy *spill){if(spill->run > util::kLastBadTimingRun) return kInBeamSpill_main.Livetime(spill);else return kInBeamSpill_main.Livetime(spill)+kInBeamSpill_shifted.Livetime(spill);}, [](const caf::SRSpillProxy *spill) -> double{return spill->spillpot;})
Does the event fall inside the window we call the beam spill?
Definition: TimingCuts.h:8
const Var kSlice
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
const Var kRun
Definition: Vars.cxx:20
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
enum BeamMode string