mrbrem_get_initial_spectra.C
Go to the documentation of this file.
1 #include "CAFAna/Core/Binning.h"
2 #include "CAFAna/Core/Spectrum.h"
4 #include "CAFAna/Core/Var.h"
5 #include "CAFAna/Core/MultiVar.h"
6 
7 //#include "CAFAna/Cuts/BPFCuts.h"
8 //#include "CAFAna/Vars/BPFVars.h"
9 
10 #include "CAFAna/Cuts/Cuts.h"
12 #include "3FlavorAna/Vars/MRVars.h"
13 #include "CAFAna/Cuts/TimingCuts.h"
14 #include "CAFAna/Cuts/SpillCuts.h"
16 #include "CAFAna/Cuts/TruthCuts.h"
19 #include "CAFAna/Vars/XsecTunes.h"
20 
21 #include "CAFAna/Vars/Vars.h"
23 
25 
26 #include <cassert>
27 
28 #include "TFile.h"
29 #include "TCanvas.h"
30 #include "TH2.h"
31 #include "TH1.h"
32 #include "TStyle.h"
33 #include "TLegend.h"
34 #include "TLatex.h"
35 #include "TArrayD.h"
36 #include "TTree.h"
37 #include "TLeaf.h"
38 #include "stdio.h"
39 #include <sstream>
40 #include <string>
41 #include <iostream>
42 #include <fstream>
43 #include <string>
44 
45 
46 using namespace ana;
47 using namespace std;
48 
50 {
51 
52  std::string filenameCosmicsData = "prod_mrbremcaf_R19-11-18-prod5reco.i_fd_cosmic_fhc_full_v1_goodruns_underP9";
53  std::string filenameCRYMC = "prod_mrbremcaf_R19-11-18-prod5reco.m_fd_cry_fhc_full_v3";
54  std::string filenameGENIEFluxswap = "prod_caf_R19-11-18-prod5reco.f_fd_genie_N1810j0211a_fluxswap_fhc_nova_v08_full_v1";
55 
56  if (mode == "rhc"){
57  filenameCosmicsData = "prod_mrbremcaf_R19-11-18-prod5reco.i_fd_cosmic_rhc_full_v1_goodruns";
58  filenameCRYMC = "prod_mrbremcaf_R19-11-18-prod5reco.m_fd_cry_rhc_full_v3";
59  filenameGENIEFluxswap = "prod_caf_R19-11-18-prod5reco.f_fd_genie_N1810j0211a_fluxswap_rhc_nova_v08_full_v1";
60  }
61 
62  SpectrumLoader loaderCosmicsData(filenameCosmicsData, kCosmic);
63  SpectrumLoader loaderCRYMC(filenameCRYMC, kCosmic);
64  SpectrumLoader loaderGENIEFluxswap(filenameGENIEFluxswap);
65  loaderGENIEFluxswap.SetSpillCut(kStandardSpillCuts);
67 
68  struct HistDef
69  {
71  HistAxis axis;
72  };
73 
74  const int kNumVars = 1;
75  const int kNumSels = 9;
76 
77  const HistDef defs[kNumVars] = {
78  {"shwangle", {"Cos(#theta_{Z})", Binning::Simple(60,0,1.0), kShwAngle}},
79  };
80 
81  struct CutDef
82  {
84  Cut cut;
85  };
86 
87  const CutDef sels[kNumSels] = {
88  {"nocuts", kNoCut},
89  {"core_presel", kNue2020CorePresel_MRBrem},
90  {"periph_presel", kNue2020PeripheralPresel_MRBrem},
91  {"periph_preselbdt", kNue2020PeripheralPresel_MRBrem && kCosPIDPeriBDT > 0.57},
92  {"periph_preselcvn", kNue2020PeripheralPresel_MRBrem && kCVNe_looseptp >= 0.97},
93  {"periph_preselen", kNue2020PeripheralPresel_MRBrem && kShwE > 1},
94  {"core_full", kNue2020FD_MRBrem},
95  {"periph_full", kNue2020FDPeripheral_MRBrem},
96  {"periph_fullen", kNue2020FDPeripheral_MRBrem && kShwE > 1},
97  };
98 
99  Spectrum* spec_mrbrem_data[kNumSels][kNumVars];
100  Spectrum* spec_mrbrem_cry[kNumSels][kNumVars];
101  Spectrum* spec_genie_fd[kNumSels][kNumVars];
102 
103  for(int selIdx = 0; selIdx < kNumSels; ++selIdx){
104  for (int varIdx=0; varIdx<kNumVars;varIdx++){
105  const HistAxis& axis = defs[varIdx].axis;
106  spec_mrbrem_data[selIdx][varIdx] = new Spectrum(loaderCosmicsData, axis, sels[selIdx].cut && kInCosmicTimingWindow_FD_MR);
107  spec_mrbrem_cry[selIdx][varIdx] = new Spectrum(loaderCRYMC, axis, sels[selIdx].cut && kInCosmicTimingWindow_FD_MR);
108  spec_genie_fd[selIdx][varIdx] = new Spectrum(loaderGENIEFluxswap, axis, sels[selIdx].cut, kNoShift, kPPFXFluxCVWgt*kXSecCVWgt2020);
109  }
110  }
111 
112  loaderCosmicsData.Go();
113  loaderCRYMC.Go();
114  loaderGENIEFluxswap.Go();
115 
116  TFile *file = new TFile(("MRbrem_extract_weights_"+mode+".root").c_str(), "recreate");
117  for(int selIdx = 0; selIdx < kNumSels; ++selIdx){
118  TDirectory* d = file->mkdir(sels[selIdx].name.c_str());
119  for (int varIdx=0; varIdx<kNumVars;varIdx++){
120  const char* name = defs[varIdx].name.c_str();
121  spec_mrbrem_data[selIdx][varIdx]->SaveTo(d, TString::Format("mrbrem_data_%s", name));
122  spec_mrbrem_cry[selIdx][varIdx]->SaveTo(d, TString::Format("mrbrem_mc_%s", name));
123  spec_genie_fd[selIdx][varIdx]->SaveTo(d, TString::Format("genie_fd_%s", name));
124  }
125  }
126 
127  file->Close();
128  return;
129 
130 }
const SpillCut kStandardSpillCuts_FD_Prod4MotivatedDQ
Definition: SpillCuts.h:69
const Var kShwE([](const caf::SRProxy *sr){double maxe=-99.0;if(!sr->vtx.elastic.IsValid) return-99999.0;if(sr->vtx.elastic.fuzzyk.npng< 1) return-99999.0;for(unsigned int i=0;i< sr->vtx.elastic.fuzzyk.npng;i++){if(maxe< sr->vtx.elastic.fuzzyk.png[i].shwlid.shwE){maxe=sr->vtx.elastic.fuzzyk.png[i].shwlid.shwE;}}return maxe;})
Definition: MRVars.h:9
const XML_Char * name
Definition: expat.h:151
const int kNumVars
Definition: vars.h:14
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const Var kPPFXFluxCVWgt
Definition: PPFXWeights.h:16
const Cut kNue2020FD_MRBrem
Definition: NueCuts2020.h:144
const Cut kNue2020CorePresel_MRBrem
Definition: NueCuts2020.h:143
std::string name
Definition: NuePlotLists.h:12
void SetSpillCut(const SpillCut &cut)
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const Cut sels[kNumSels]
Definition: vars.h:44
Struct to hold cut information.
Float_t d
Definition: plot.C:236
virtual void Go() override
Load all the registered spectra.
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:517
const HistDef defs[kNumVars]
Definition: vars.h:15
const Cut kNue2020FDPeripheral_MRBrem(kNue2020FDPeripheralFunc_MRBrem)
const int kNumSels
Definition: vars.h:43
std::vector< float > Spectrum
Definition: Constants.h:570
HistAxis axis
Definition: NuePlotLists.h:13
const SystShifts kNoShift
Definition: SystShifts.cxx:21
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
const Cut cut
Definition: exporter_fd.C:30
void mrbrem_get_initial_spectra(std::string mode="fhc")
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
TFile * file
Definition: cellShifts.C:17
const Cut kInCosmicTimingWindow_FD_MR
Definition: TimingCuts.cxx:170
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
const Var kShwAngle([](const caf::SRProxy *sr){double maxe=-99.0;double cosz=-1.0;if(!sr->vtx.elastic.IsValid) return-99999.0;if(sr->vtx.elastic.fuzzyk.npng< 1) return-99999.0;for(unsigned int i=0;i< sr->vtx.elastic.fuzzyk.npng;i++){if(maxe< sr->vtx.elastic.fuzzyk.png[i].shwlid.shwE){maxe=sr->vtx.elastic.fuzzyk.png[i].shwlid.shwE;cosz=sr->vtx.elastic.fuzzyk.png[i].shwlid.dir.z;}}return cosz;})
Definition: MRVars.h:8
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:114
const Var kCVNe_looseptp
Definition: Vars.cxx:36
const Var kCosPIDPeriBDT
2020 nue cosmic rejection BDT variable - peripheral
Definition: NueVars.cxx:113
const Cut kNoCut
The simplest possible cut: pass everything, used as a default.
Definition: Cut.h:109
const Var kXSecCVWgt2020
Definition: XsecTunes.h:106