trim_caf.C
Go to the documentation of this file.
1 #ifdef __CINT__
2 void trim_caf(std::string inputFilename)
3 {
4  std::cout << "Sorry, you must run in compiled mode" << std::endl;
5 }
6 #else
7 
8 #include "CAFAna/Cuts/Cuts.h"
9 #include "CAFAna/Cuts/NumuCuts.h"
10 #include "CAFAna/Cuts/SpillCuts.h"
11 #include "CAFAna/Core/Loaders.h"
12 #include "CAFAna/Core/Binning.h"
15 #include "CAFAna/Prediction/PredictionInterp2.h"
16 #include "CAFAna/Prediction/PredictionNumuFAHadE.h"
19 #include "CAFAna/Systs/Systs.h"
20 #include "CAFAna/Systs/NumuSysts.h"
22 #include "CAFAna/Analysis/Calcs.h"
23 #include "CAFAna/Analysis/Fit.h"
24 #include "CAFAna/Analysis/Surface.h"
25 #include "CAFAna/Analysis/Plots.h"
30 #include "CAFAna/Vars/FitVars.h"
31 #include "CAFAna/FC/FCCollection.h"
32 #include "CAFAna/FC/FCPoint.h"
33 #include "CAFAna/FC/FCSurface.h"
34 
35 #include "TCanvas.h"
36 #include "TFile.h"
37 #include "TGraph.h"
38 #include "TH1.h"
39 #include "TH2.h"
40 #include "TMath.h"
41 #include "TGaxis.h"
42 #include "TMultiGraph.h"
43 #include "TLegend.h"
44 #include "TLatex.h"
45 #include "TStyle.h"
46 #include "THStack.h"
47 #include "TPaveText.h"
48 #include "TGraphAsymmErrors.h"
49 #include "TLegendEntry.h"
50 #include "TMarker.h"
51 #include "TFeldmanCousins.h"
52 #include "TRandom3.h"
53 #include "TChain.h"
54 #include "TTree.h"
55 #include "TString.h"
56 #include "TObjString.h"
57 #include "TSystem.h"
58 #include "TROOT.h"
59 
60 #include <cmath>
61 #include <iostream>
62 #include <vector>
63 #include <sstream>
64 #include <string>
65 #include <fstream>
66 #include <iomanip>
67 #include <cstdlib>
68 #include <map>
69 
71 
72 //#include "TMVARegGui.C"
73 
74 #if not defined(__CINT__) || defined(__MAKECINT__)
75 #include "TMVA/Tools.h"
76 #include "TMVA/Factory.h"
77 #endif
78 
79 using namespace TMVA;
80 
81 void trim_caf(std::string inputFilename)
82 {
83  int fntracks3d, fcosfwdcell, fcosbakcell, fkalfwdcell, fkalbakcell, fnhit, fnhitkal, fnhitcos, ftype, frun, fncontplanes, fev;
84  float fmaxy, fminy, fanglekal, fanglecos, fkaldiry, fcosdiry, fscatt, fvisE, fremid, fvtxX, fvtxY, fvtxZ;
85  float fHadE,fmisse,ftrueE,fosc,ftracklen,foldbdt,fcvnnumu,fcvncosmic,fpngptp,fcdirscore;
86 
87  TFile* outputFile = TFile::Open( "bdt_trimmed.root", "RECREATE" );
88 
89  TTree *trim = new TTree("trimmed", "trimmed tree");
90  trim->SetDirectory(0);
91 
92  trim->Branch("ntracks3d", &fntracks3d, "ntracks3d/I");
93  trim->Branch("cosfwdcell", &fcosfwdcell, "cosfwdcell/I");
94  trim->Branch("cosbakcell", &fcosbakcell, "cosbakcell/I");
95  trim->Branch("kalfwdcell", &fkalfwdcell, "kalfwdcell/I");
96  trim->Branch("kalbakcell", &fkalbakcell, "kalbakcell/I");
97  trim->Branch("type", &ftype, "type/I"); // 0 for data, 1 for CC MC, 2 for NC MC
98  trim->Branch("maxy", &fmaxy, "maxy/F");
99  trim->Branch("miny", &fminy, "miny/F");
100  trim->Branch("tracklen", &ftracklen, "tracklen/F");
101  trim->Branch("run", &frun, "run/I");
102  trim->Branch("ev", &fev, "ev/I");
103  trim->Branch("ncontplanes", &fncontplanes, "ncontplanes/I");
104  trim->Branch("anglekal", &fanglekal, "anglekal/F");
105  trim->Branch("anglecos", &fanglecos, "anglecos/F");
106  trim->Branch("kaldiry", &fkaldiry, "kaldiry/F");
107  trim->Branch("cosdiry", &fcosdiry, "cosdiry/F");
108  trim->Branch("scatt", &fscatt, "scatt/F");
109  trim->Branch("nhit", &fnhit, "nhit/I");
110  trim->Branch("nhitkal", &fnhitkal, "nhitkal/I");
111  trim->Branch("nhitcos", &fnhitcos, "nhitcos/I");
112  trim->Branch("remid", &fremid, "remid/F");
113  trim->Branch("vtx", &fvtxX, "vtx/F");
114  trim->Branch("vty", &fvtxY, "vty/F");
115  trim->Branch("vtz", &fvtxZ, "vtz/F");
116  trim->Branch("visE", &fvisE, "visE/F");
117  trim->Branch("hade", &fHadE, "hade/F");
118  trim->Branch("misse", &fmisse, "misse/F");
119  trim->Branch("trueE", &ftrueE, "trueE/F");
120  trim->Branch("osc", &fosc, "osc/F");
121  trim->Branch("cvnnumu", &fcvnnumu, "cvnnumu/F");
122  trim->Branch("cvncosmic", &fcvncosmic, "cvncosmic/F");
123  trim->Branch("cdirscore", &fcdirscore, "cdirscore/F");
124  trim->Branch("pngptp", &fpngptp, "pngptp/F");
125  trim->Branch("oldbdt", &foldbdt, "oldbdt/F");
126 
127  //note would be useful to add: proper numu energy estimator, ppfx and x-section weights for MC
128 
129  caf::StandardRecord* sr = 0;
130 
131  // data
132 
133  TFile *file = new TFile(inputFilename.c_str());
134  TTree *tree = (TTree*)file->Get("recTree");
135  tree->SetBranchAddress("rec", &sr);
136 
137  for(int i = 0; i<tree->GetEntries(); i++) {
138  tree->GetEntry(i);
139  if(i%10000==0) std::cout << "processing " << i << " of " << tree->GetEntries() << " is " << 100.0*float(i)/float(tree->GetEntries()) << "% done" << std::endl;
140 
141  if(sr->trk.cosmic.ntracks==0) continue; // needs to be a cosmic track
142  if(sr->trk.kalman.ntracks==0) continue; // needs to be a kalman track
143  if(sr->sel.veto.keep==0) continue; // needs to pass cosveto
144  if(sr->sel.contain.numucontain==0) continue; // numu containment; this is SA containment cut, needs to be updated by writing out explicitly
145 
146  if(sr->hdr.ismc) { // for GENIE
147  fosc = sr->mc.nu[0].woscdumb; // want to use oscillated FD; this is simplest approximation; could replace with latest best fits
148  if(sr->mc.nu[0].iscc) ftype = 1; // TYPE = 1 for CC MC
149  else ftype = 2; // TYPE = 2 for NC MC
150  fmisse = sr->sel.contain.missE; // spectrator variable, could replace with newer better missing E handles
151  ftrueE = sr->mc.nu[0].E;
152  }
153 
154  else {
155  fosc = 1; // don't oscillate data
156  ftype = 0; // TYPE = 0 for data
157  fmisse = 0; // true vars don't exist for data
158  ftrueE = 0;
159  }
160 
161  frun = sr->hdr.run;
162  fev = sr->hdr.evt;
163  ftracklen = sr->trk.kalman.tracks[0].len;
164  fncontplanes = sr->slc.ncontplanes;
165  fntracks3d = sr->trk.kalman.ntracks;
166  fcosfwdcell = sr->sel.contain.cosfwdcell;
167  fcosbakcell = sr->sel.contain.cosbakcell;
168  fkalfwdcell = sr->sel.contain.kalfwdcell;
169  fkalbakcell = sr->sel.contain.kalbakcell;
170  fmaxy = sr->slc.boxmax.y;
171  fminy = sr->slc.boxmin.y;
172  fanglekal = sr->sel.cosrej.anglekal;
173  fanglecos = sr->sel.cosrej.anglecos;
174  fnhitkal = sr->trk.kalman.tracks[0].nhit;
175  fnhitcos = sr->trk.cosmic.tracks[0].nhit;
176  fremid = sr->sel.remid.pid;
177  fkaldiry = sr->trk.kalman.tracks[0].dir.y;
178  fcosdiry = sr->trk.cosmic.tracks[0].dir.y;
179  fnhit = sr->slc.nhit;
180  fvtxX = sr->trk.kalman.tracks[0].start.x;
181  fvtxY = sr->trk.kalman.tracks[0].start.y;
182  fvtxZ = sr->trk.kalman.tracks[0].start.z;
183  fscatt = sr->sel.cosrej.scatt;
184  fvisE = sr->slc.calE;
185  foldbdt = sr->sel.cosrej.numucontpid;
186  fHadE = sr->energy.numu.hadcalE;
187  fcvnnumu = sr->sel.cvn.numuid;
188  fcvncosmic = sr->sel.cvn.output[14];
189  fpngptp = sr->sel.nuecosrej.pngptp;
190  fcdirscore = sr->sel.cosrej.cdirscore;
191 
192  trim->Fill();
193  }
194 
195  outputFile->cd();
196 
197  trim->Write();
198 
199  outputFile->Close();
200 }
201 
202 #endif
int cosfwdcell
cosmictrack projected # cells from end point forwards to det edge
Definition: SRContain.h:30
float missE
sum of energy of particles that leave detector. example cut: missE/trueE > 0.01 is truly uncontained ...
Definition: SRContain.h:21
SRHeader hdr
Header branch: run, subrun, etc.
SRCosRej cosrej
Output from CosRej (Cosmic Rejection)
Definition: SRIDBranch.h:47
size_t ntracks
Definition: SRKalman.h:23
SRVector3D boxmax
Maximum coordinates box containing all the hits [cm].
Definition: SRSlice.h:47
void trim_caf(std::string inputFilename)
Definition: trim_caf.C:81
string trim(string in)
Definition: rootgINukeVal.C:65
unsigned int run
run number
Definition: SRHeader.h:21
bool ismc
data or MC? True if MC
Definition: SRHeader.h:27
int cosbakcell
cosmictrack projected # cells from start point backwards to det edge
Definition: SRContain.h:35
float scatt
sum of all all angular deviation (looping over kaltrk traj pts) / trk len
Definition: SRCosRej.h:41
unsigned int evt
ART event number, indexes trigger windows.
Definition: SRHeader.h:25
SRKalman kalman
Tracks produced by KalmanTrack.
Definition: SRTrackBranch.h:24
float pid
PID value output by kNN.
Definition: SRRemid.h:25
bool keep
Definition: SRVeto.h:34
SRVector3D boxmin
Minimum coordinates box containing all the hits [cm].
Definition: SRSlice.h:46
float anglekal
cos of angle of best ReMId Kalman track
Definition: SRCosRej.h:23
SRCVNResult cvn
Horrible hack to appease CAFAna.
Definition: SRIDBranch.h:53
bool numucontain
is this contained by Numu Standards? (can use as general containment)
Definition: SRContain.h:18
SRNueCosRej nuecosrej
Output from NueCosRej (Nue Cosmic Rejection)
Definition: SRIDBranch.h:48
SRRemid remid
Output from RecoMuonID (ReMId) package.
Definition: SRIDBranch.h:39
float calE
Calorimetric energy of the cluster [GeV].
Definition: SRSlice.h:38
std::vector< float > output
List of net output nodes.
Definition: SRCVNResult.h:19
caf::StandardRecord * sr
unsigned int nhit
number of hits
Definition: SRSlice.h:22
OStream cout
Definition: OStream.cxx:6
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
The StandardRecord is the primary top-level object in the Common Analysis File trees.
int kalfwdcell
Kalmantrack projected # cells from end point forwards to det edge.
Definition: SRContain.h:40
SRNumuEnergy numu
Numu energy estimator.
SRIDBranch sel
Selector (PID) branch.
float numuid
Likelihood Charge Current NuMu.
Definition: SRCVNResult.h:20
int kalbakcell
Kalmantrack projected # cells from start point backwards to det edge.
Definition: SRContain.h:45
TFile * file
Definition: cellShifts.C:17
Definition: tmvaglob.h:28
SRSlice slc
Slice branch: nhit, extents, time, etc.
SRTruthBranch mc
Truth branch for MC: energy, flavor, etc.
SRVeto veto
Output from CosmicVeto (Preliminary preselection)
Definition: SRIDBranch.h:52
unsigned int ncontplanes
number of continuous planes
Definition: SRSlice.h:25
SRTrackBranch trk
Track branch: nhit, len, etc.
SREnergyBranch energy
Energy estimator branch.
SRTrackBase cosmic
Tracks produced by CosmicTrack.
Definition: SRTrackBranch.h:26
float anglecos
cos of angle of Cosmic Track
Definition: SRCosRej.h:24
SRContain contain
Output from SRContain (containment related variables)
Definition: SRIDBranch.h:51
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
std::vector< SRTrack > tracks
Definition: SRTrackBase.h:15
float cdirscore
chisq score difference between +c and -c assumptions in Hough timing fit (TimingFit module) for cosmi...
Definition: SRCosRej.h:58
float hadcalE
Hadronic calorimetric energy NOT on the muon track[GeV].
Definition: SRNumuEnergy.h:35
std::vector< SRKalmanTrack > tracks
3D Tracks produced by KalmanTrack
Definition: SRKalman.h:16