resolution_event_tree.C
Go to the documentation of this file.
1 #pragma once
2 
4 #include "CAFAna/Core/Spectrum.h"
5 
7 
11 
12 #include "CAFAna/Core/EventList.h"
13 
14 #include "TSystem.h"
15 
16 #include "CAFAna/Core/Var.h"
17 #include <fstream>
18 // temporary measure to use prod4 trained muonid
19 #include "NDAna/muonid/NDXSecMuonPID.h"
20 namespace nuebarccinc {
21  const ana::Cut kMuonIDProd4Cut = ana::kMuonIDProd4 < -0.2;
22 }
23 
25 {
26  const int ret = gSystem->Load("libNDAnamuonid");
27  if(ret != 0) exit(1);
28 }
29 
30 using namespace ana;
31 
32 std::vector<std::string> get_files(std::string file_list)
33 {
34  std::vector<std::string> files;
35  std::ifstream in(file_list);
36 
38  while(std::getline(in, file)) {
39  if(file.size() > 0) files.push_back(file);
40  }
41  return files;
42 }
43 
44 void resolution_event_tree(std::string file_list = "", std::string eventlist = "resolution_event_tree")
45 {
46 
47  std::vector<std::string> files;
48  if(file_list != "") files= get_files(file_list);
49 
50  const Var kNuPDG = VarFromNuTruthVar(SIMPLENUTRUTHVAR(pdg));
51  const Var kElectronPDG([](const caf::SRProxy * sr)->int
52  {
53  if ( !sr->vtx.elastic.IsValid ) return -1;
54  if (sr->vtx.elastic.fuzzyk.npng < 1) return -1;
55  return sr->vtx.elastic.fuzzyk.png[nuebarccinc::true_electron_png(sr)].truth.pdg;
56  });
57  const Var kElectronProngIdx([](const caf::SRProxy * sr)->int
58  {
60  });
61 
63  const Var kHasElectronFuzzyK([](const caf::SRProxy * sr)->int
64  {
65  if ( !sr->vtx.elastic.IsValid ) return -1;
66  if (sr->vtx.elastic.fuzzyk.npng < 1) return -1;
67  int npngs = sr->vtx.elastic.fuzzyk.npng;
68  bool haselectron = false;
69  for(auto ipng = 0; ipng < npngs; ipng++) {
70  if(abs(sr->vtx.elastic.fuzzyk.png[ipng].truth.pdg) == 11) {
71  haselectron = true;
72  break;
73  }
74  }
75  return haselectron;
76  });
77 
78  const Var kHasElectronPrim([](const caf::SRProxy * sr)->int
79  {
80  if ( !sr->vtx.elastic.IsValid ) return -1;
81  if (sr->vtx.elastic.fuzzyk.npng < 1) return -1;
82  int npngs = sr->mc.nu[0].prim.size();
83  bool haselectron = false;
84  for(auto ipng = 0; ipng < npngs; ipng++) {
85  if(abs(sr->mc.nu[0].prim[ipng].pdg) == 11) {
86  haselectron = true;
87  break;
88  }
89  }
90  return haselectron;
91  });
92 
93 
94  const Var kRun = SIMPLEVAR(hdr.run);
95  const Var kSubrun = SIMPLEVAR(hdr.subrun);
96  const Var kCycle = SIMPLEVAR(hdr.cycle);
97  const Var kBatch = SIMPLEVAR(hdr.batch);
98  const Var kEvent = SIMPLEVAR(hdr.evt);
99  const Var kSlice = SIMPLEVAR(hdr.subevt);
100 
101 
103  const Cut kSelectedNueNuebarCC =
107 
108  std::vector<std::pair<std::string, Var> > floatvars
109  = { {"reco_cos_theta", nuebarccinc::kTrueElectronRecoCosTheta},
110  {"true_cos_theta", nuebarccinc::kTrueElectronCosTheta},
111  {"reco_e_untuned", nuebarccinc::kTrueElectronRecoEUntuned},
112  {"reco_e_fhctuned", nuebarccinc::kTrueElectronRecoEFHCTuned},
113  {"true_e", nuebarccinc::kTrueElectronE} };
114 
115  std::vector<std::pair<std::string, Var> > intvars
116  = { {"nupdg", kNuPDG},
117  {"electron_pdg", kElectronPDG},
118  {"iscc", kIsCC},
119  {"has_electron_fuzzyk", kHasElectronFuzzyK},
120  {"has_electron_prim", kHasElectronPrim},
121  {"electron_png_idx", kElectronProngIdx},
122  {"run", kRun},
123  {"subrun", kSubrun},
124  {"cycle", kCycle},
125  {"batch", kBatch},
126  {"event", kEvent},
127  {"slice", kSlice} };
128 
129 
130  if(file_list != "")
132  eventlist + ".root",
133  {{"selected", nuebarccinc::kHasReconstructedElectronProng && kSelectedNueNuebarCC}},
134  floatvars,
135  intvars);
136  else
138  eventlist + ".root",
139  //{{"selected", nuebarccinc::kHasReconstructedElectronProng && kSelectedNueNuebarCC && kBackwardsElectrons}},
140  {{"selected", nuebarccinc::kHasReconstructedElectronProng && kSelectedNueNuebarCC}},
141  floatvars,
142  intvars);
143 
144 }
std::vector< std::string > get_files(std::string file_list)
caf::Proxy< size_t > npng
Definition: SRProxy.h:2038
caf::Proxy< caf::SRFuzzyK > fuzzyk
Definition: SRProxy.h:2059
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const ana::Cut kNuebarCC
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2126
caf::Proxy< std::vector< caf::SRNeutrino > > nu
Definition: SRProxy.h:618
void abs(TH1 *hist)
const ana::Var kTrueElectronRecoCosTheta([](const caf::SRProxy *sr) ->float{if(!sr->vtx.elastic.IsValid) return-1000.f;if(sr->vtx.elastic.fuzzyk.npng< 1) return-1000.f;int true_electron_idx=true_electron_png(sr);if(true_electron_idx< 0) return-5.f;TVector3 elecdir=(TVector3) sr->vtx.elastic.fuzzyk.png[true_electron_idx].dir;TVector3 beamdir=ana::NuMIBeamDirection(caf::kNEARDET);return elecdir.Dot(beamdir);})
const Var kSubrun
Definition: Vars.cxx:21
caf::Proxy< caf::SRElastic > elastic
Definition: SRProxy.h:2118
caf::Proxy< std::vector< caf::SRFuzzyKProng > > png
Definition: SRProxy.h:2043
void load_libs_muonid()
int iscc
if(dump)
const ana::Var kTrueElectronCosTheta
const std::string PROD5_MC_RHC_NOMINAL
caf::StandardRecord * sr
const Var kCycle
Definition: Vars.cxx:22
#define SIMPLENUTRUTHVAR(CAFNAME)
Definition: Var.h:89
const int kElectronPDG
Definition: PngCVNVars.h:28
const ana::Cut kPreselectionLoose
const ana::Cut kHasReconstructedElectronProng([](const caf::SRProxy *sr){return true_electron_png(sr) >=0;})
caf::Proxy< caf::SRTruthBranch > mc
Definition: SRProxy.h:2138
const ana::Var kTrueElectronRecoEFHCTuned([](const caf::SRProxy *sr) ->float{double p0=-0.10588;double p1=0.57885;double p2=-0.408767;double p3=0.153795;double p4=-0.0270565;double p5=0.00171687;float energy=-1000.f;if(!sr->vtx.elastic.IsValid) return-1000.f;if(sr->vtx.elastic.fuzzyk.npng< 1) return-1000.f;int true_electron_idx=true_electron_png(sr);if(true_electron_idx< 0) return-5.f;float x=(sr->vtx.elastic.fuzzyk.png[true_electron_idx].shwlid.shwE);if(x< 0) return 0.0f;if(x<=6) energy=x-(p0+x *p1+p2 *pow(x, 2)+p3 *pow(x, 3)+p4 *pow(x, 4)+p5 *pow(x, 5));else energy=x;if(energy< 0) energy=x;return energy;})
Var VarFromNuTruthVar(const NuTruthVar &stv, double _default)
Definition: Var.cxx:7
ifstream in
Definition: comparison.C:7
caf::Proxy< bool > IsValid
Definition: SRProxy.h:2058
void MakeEventTTreeFile(const std::string &wildcard, const std::string &output, const std::vector< std::pair< std::string, Cut >> &cuts, const std::vector< std::pair< std::string, Var >> &floatVars, const std::vector< std::pair< std::string, Var >> &intVars, const SpillCut *spillCut)
Make a ROOT file listing all the events passing the specified cut.
Definition: EventList.cxx:324
#define SIMPLEVAR(CAFNAME)
For Vars where literally all you need is a single CAF variable.
Definition: Var.h:88
exit(0)
const ana::Var kTrueElectronE
TFile * file
Definition: cellShifts.C:17
const SpillVar kRun([](const caf::SRSpillProxy *spill){return spill->run;})
const Var kSlice
const ana::Var kTrueElectronRecoEUntuned([](const caf::SRProxy *sr) ->float{if(!sr->vtx.elastic.IsValid) return-1000.f;if(sr->vtx.elastic.fuzzyk.npng< 1) return-1000.f;int true_electron_idx=true_electron_png(sr);if(true_electron_idx< 0) return-5.f;float x=(sr->vtx.elastic.fuzzyk.png[true_electron_idx].shwlid.shwE);return x;})
const ana::Cut kMuonIDProd4Cut
Definition: datamc.C:28
void resolution_event_tree(std::string file_list="", std::string eventlist="resolution_event_tree")
int true_electron_png(const caf::SRProxy *sr)
const ana::Cut kNueCC
caf::Proxy< caf::SRVertexBranch > vtx
Definition: SRProxy.h:2146
enum BeamMode string