FillTrainingTrees.C
Go to the documentation of this file.
1 #include "FillTrainingTrees.h"
2 
3 void FillTrainingTrees(TString file, TString opt){
4 
5  std::string samDefinition;
6  TString treeName;
7  bool isdata;
8  if (opt.Contains("nc", TString::kIgnoreCase)){
9  treeName = "ncTree";
10  isdata = false;
11  }
12  else if (opt.Contains("cos", TString::kIgnoreCase)){
13  treeName = "cosTree";
14  isdata = true;
15  }
16  else{
17  throw std::logic_error("opt must contain either nc or cos");
18  }
19 
20  // setup intput trees from files
21  TFile* mcFile = new TFile(file, "read");
22  TTree* recTree = (TTree*)mcFile->Get("recTree");
23 
24  SetupRecTree(recTree);
25 
26  // define signal and background trees
27  TFile* outFile = new TFile("TrainingTrees.root", "RECREATE");
28  TTree* outTree = new TTree(treeName, treeName);
29 
30  SetupOutTree(outTree);
31  FillTree(recTree, outTree, isdata);
32 
33  outFile->cd();
34  outTree->Write();
35 
36 }
37 
38 void SetupRecTree(TTree* recTree){
39 
40  recTree->SetBranchAddress("rec", &sr);
41 
42 }
43 
44 void SetupOutTree(TTree* outTree){
45 
46  outTree->Branch("run" , &run );
47  outTree->Branch("subrun" , &subrun );
48  outTree->Branch("evt" , &evt );
49  outTree->Branch("subevt" , &subevt );
50  outTree->Branch("iscc" , &iscc );
51  outTree->Branch("vtxisvalid" , &vtxisvalid );
52  outTree->Branch("nprongs" , &nprongs );
53  outTree->Branch("ncontplanes" , &ncontplanes );
54  outTree->Branch("distallpngtop" , &distallpngtop );
55  outTree->Branch("distallpngbottom" , &distallpngbottom );
56  outTree->Branch("distallpngeast" , &distallpngeast );
57  outTree->Branch("distallpngwest" , &distallpngwest );
58  outTree->Branch("distallpngfront" , &distallpngfront );
59  outTree->Branch("distallpngback" , &distallpngback );
60  outTree->Branch("vtxx" , &vtxx );
61  outTree->Branch("vtxy" , &vtxy );
62  outTree->Branch("vtxz" , &vtxz );
63  outTree->Branch("shwhitx" , &shwhitx );
64  outTree->Branch("shwhity" , &shwhity );
65  outTree->Branch("shwhittot" , &shwhittot );
66  outTree->Branch("shwhitasymm" , &shwhitasymm );
67  outTree->Branch("shwhitratio" , &shwhitratio );
68  outTree->Branch("nshowers" , &nshowers );
69  outTree->Branch("showerwidth" , &showerwidth );
70  outTree->Branch("showerlength" , &showerlength );
71  outTree->Branch("showerdirycosine" , &showerdirycosine );
72  outTree->Branch("showergap" , &showergap );
73  outTree->Branch("showercale" , &showercale );
74  outTree->Branch("nhitsperplane" , &nhitsperplane );
75  outTree->Branch("nmiphits" , &nmiphits );
76  outTree->Branch("nhitsperslice" , &nhitsperslice );
77  outTree->Branch("partptp" , &partptp );
78  outTree->Branch("closestslicetime" , &closestslicetime );
79  outTree->Branch("closestslicemindist" , &closestslicemindist );
80  outTree->Branch("CVNnc_looseptp" , &CVNnc_looseptp );
81  outTree->Branch("CVNcos_loosetptp" , &CVNcos_looseptp );
82 
83 }
84 
85 void FillTree(TTree* recTree, TTree* outTree, bool isData){
86 
87  recTree->SetBranchAddress("rec", &sr);
88  recTree->GetEntry(0);
89 
90  caf::SRProxy srProxy(0, nullptr, "", 0, 0);
91  caf::CopyRecord(*sr, srProxy);
92 
93  for (Long64_t iEnt = 0; iEnt < recTree->GetEntries(); ++iEnt){
94 
95  if (iEnt%1000 == 0) std::cout << iEnt << "/" << recTree->GetEntries() << std::endl;
96 
97  recTree->GetEntry(iEnt);
98  caf::CopyRecord(*sr, srProxy);
99 
100  // if it's mc, make sure we're only saving
101  // signal information
102  if (!isData){
103  iscc = sr->mc.nu[0].iscc;
104  if(iscc == 1) continue;
105  }
106  else iscc = -1;
107 
108  // and then apply pre-cvn cuts. that's the quality cuts
109  // and the prong distance to edge cuts
110 
111  // define cut variables
121 
122  // place selection cuts
123  if (!ana::kNus20FDCuts(&srProxy) ||
125  !ana::kInBeamSpill(&srProxy))
126  continue;
127 
128  // quality cuts
129  //if (vtxisvalid == 0 ||
130  // nprongs == 0 ||
131  // ncontplanes <= 2)
132  // continue;
133 
134  //// prong distance to edge cuts
135  //if (distallpngtop < 100 ||
136  // distallpngbottom < 100 ||
137  // distallpngwest < 100 ||
138  // distallpngeast < 100 ||
139  // distallpngfront < 160 ||
140  // distallpngback < 160)
141  // continue;
142 
143  // base variables
144  run = sr->hdr.run;
145  subrun = sr->hdr.subrun;
146  evt = sr->hdr.evt;
147  subevt = sr->hdr.subevt;
148 
149  // vetex variables
150  vtxx = sr->vtx.elastic.vtx.x;
151  vtxy = sr->vtx.elastic.vtx.y;
152  vtxz = sr->vtx.elastic.vtx.z;
153 
154  // shower hit variables
155  shwhitx = sr->vtx.elastic.fuzzyk.png[0].shwlid.nhitx;
156  shwhity = sr->vtx.elastic.fuzzyk.png[0].shwlid.nhity;
159  shwhitratio = (float)shwhitx/(float)shwhity;
160 
161  // other shower variables
163  showerwidth = sr->vtx.elastic.fuzzyk.png[0].shwlid.width;
164  showerlength = sr->vtx.elastic.fuzzyk.png[0].shwlid.len;
165  showerdirycosine = sr->vtx.elastic.fuzzyk.png[0].shwlid.dir.y;
166  showergap = sr->vtx.elastic.fuzzyk.png[0].shwlid.gap;
167  showercale = sr->vtx.elastic.fuzzyk.png[0].shwlid.calE;
168 
169  // other variables
172  nmiphits = sr->slc.nmiphit;
176 
177  // cvn variables
180 
181  outTree->Fill();
182 
183  }
184 
185 }
const SpillCut kStandardSpillCuts_FD_Prod4MotivatedDQ
Definition: SpillCuts.h:69
float ncid
Likelihood Neutral Current.
Definition: SRCVNResult.h:23
float distallpngbottom
caf::Proxy< caf::SRSpill > spill
Definition: SRProxy.h:2143
void SetupOutTree(TTree *outTree)
float closestslicemindist
minimum distance to the closest slice in time domain
Definition: SRSlice.h:56
int ncontplanes
SRHeader hdr
Header branch: run, subrun, etc.
void SetupRecTree(TTree *recTree)
unsigned int subrun
subrun number
Definition: SRHeader.h:22
float distallpngbottom
Definition: SRNueCosRej.h:95
int nprongs
void FillTrainingTrees(TString file, TString opt)
std::vector< SRFuzzyKProng > png
Vector of 3D prong objects.
Definition: SRFuzzyK.h:19
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2126
float showerwidth
float vtxx
int nmiphits
unsigned int run
run number
Definition: SRHeader.h:21
float distallpngeast
float distallpngfront
SRCVNResult cvnloosepreselptp
Output from CVN - Loose Presel plus PtP cut (many-class PID)
Definition: SRIDBranch.h:54
float distallpngtop
void FillTree(TTree *recTree, TTree *outTree, bool isData)
unsigned int evt
ART event number, indexes trigger windows.
Definition: SRHeader.h:25
float shwhitratio
float cosmicid
Likelihood Cosmic Interaction.
Definition: SRCVNResult.h:24
int shwhity
int iscc
unsigned int nshwlid
number of shwlid showers - either 0 or number of 3d prongs
Definition: SRFuzzyK.h:24
TFile * outFile
Definition: PlotXSec.C:135
float distallpngfront
Definition: SRNueCosRej.h:99
int nshowers
float partptp
unsigned int nmiphit
number of minimum ionizing hits
Definition: SRSlice.h:24
int shwhitasymm
SRNueCosRej nuecosrej
Output from NueCosRej (Nue Cosmic Rejection)
Definition: SRIDBranch.h:48
int evt
float closestslicetime
float vtxy
caf::StandardRecord * sr
float nhitsperplane
float showerdirycosine
SRVector3D vtx
Vertex position in detector coordinates. [cm].
Definition: SRElastic.h:40
float showergap
size_t npng
Definition: SRFuzzyK.h:26
int vtxisvalid
unsigned int nhit
number of hits
Definition: SRSlice.h:22
Definition: run.py:1
OStream cout
Definition: OStream.cxx:6
float CVNnc_looseptp
float vtxz
int shwhittot
int shwhitx
float CVNcos_looseptp
float distallpngback
SRIDBranch sel
Selector (PID) branch.
SRElastic elastic
Single vertex found by Elastic Arms.
float showercale
TFile * file
Definition: cellShifts.C:17
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
SRSlice slc
Slice branch: nhit, extents, time, etc.
const Cut kNus20FDCuts
Definition: NusCuts20.h:174
SRTruthBranch mc
Truth branch for MC: energy, flavor, etc.
SRFuzzyK fuzzyk
Primary 3D prong object.
Definition: SRElastic.h:44
float closestslicemindist
unsigned short subevt
slice number within spill
Definition: SRHeader.h:26
unsigned int ncontplanes
number of continuous planes
Definition: SRSlice.h:25
float closestslicetime
time difference between meantime of this slice and meantime of slice closest in time, in nanoseconds.
Definition: SRSlice.h:43
std::vector< SRNeutrino > nu
implemented as a vector to maintain mc.nu structure, i.e. not a pointer, but with 0 or 1 entries...
Definition: SRTruthBranch.h:25
float nhitsperslice
short subevt
float showerlength
float distallpngwest
SRVertexBranch vtx
Vertex branch: location, time, etc.
enum BeamMode string