caf_numu_nd_cutflow.C
Go to the documentation of this file.
1 // numu selection n-1 plots. Only currently for the ND
2 
3 /*
4 */
5 #ifdef __CINT__
6 void caf_numu_nd_cutflow(std::string kInputFileName, std::string kOutputFileName)
7 {
8  std::cout << "Sorry, you must run in compiled mode" << std::endl;
9 }
10 #else
11 
12 #include "CAFAna/Core/Binning.h"
13 #include "CAFAna/Cuts/Cuts.h"
14 #include "CAFAna/Core/Spectrum.h"
17 #include "CAFAna/Vars/NumuVars.h"
18 #include "CAFAna/Cuts/SpillCuts.h"
19 //#include "CAFAna/Cuts/NumuCuts.h"
20 #include "CAFAna/Vars/Vars.h"
21 #include "CAFAna/Analysis/Plots.h"
22 #include "CAFAna/Analysis/Style.h"
23 
24 //#include "NumuEnergy/NumuEAlg.h"
25 
26 #include "TCanvas.h"
27 #include "TH1.h"
28 #include "TH2.h"
29 #include "TLine.h"
30 #include "TFile.h"
31 #include "TStyle.h"
32 #include "TLegend.h"
33 #include "TLine.h"
34 #include "TLatex.h"
35 #include "THStack.h"
36 
37 using namespace ana;
38 
39 // Put a "NOvA Preliminary" tag in the corner
40 void Preliminary(){
41  TLatex* prelim = new TLatex(.9, .95, "NO#nuA Preliminary");
42  prelim->SetTextColor(kBlue);
43  prelim->SetNDC();
44  prelim->SetTextSize(2/30.);
45  prelim->SetTextAlign(32);
46  prelim->Draw();
47 }
48 
49 template<class T> class Tangible{
50 
51 public:
52  Tangible(const T& obj, const std::string& shortName,
53  const std::string& blurb ):
54  fObj(obj),
55  fShortName(shortName),
56  fBlurb(blurb)
57  {};
58 
59  T fObj;
62 
63 };
64 
65 const Cut kIsDytmanMEC({"mc.nnu", "mc.nu.mode"},
66  [](const caf::StandardRecord* sr)
67  {
68  if(sr->mc.nnu == 0) return false;
69  assert(sr->mc.nnu == 1);
70  return (sr->mc.nu[0].mode == caf::kMEC);
71  });
72 
75 
76 
77 class UsefulHist{
78 
79 public:
80 
82  fSel(sel),
83  fAxis(tanAxis),
84  fHist(loader, fAxis.fObj, fSel.fObj),
85  fName(tanAxis.fShortName + "-" + sel.fShortName){};
86 
87  Selection fSel;
88  TangibleAxis fAxis;
89  Spectrum fHist;
90  std::string fName;
91 
92 };
93 
94 void caf_numu_nd_cutflow(std::string kInputFileName, std::string kOutputFileName){
95 
96  std::cout << "\nrun : ---- Running CAF NuMU ND Validation.\n";
97  std::cout << "run : input file name: " << kInputFileName << std::endl;
98  std::cout << "run : output file name: " << kOutputFileName << std::endl;
99 
100  // make loader with user input dataset
101  SpectrumLoader loader(kInputFileName);
102 
103  // make spill histogram tokeep record of spills. Going to use to count total number of events
104  TH1D* spillHist = new TH1D("reco-spills", ";Detector;Spills", 3, 0, 3);
105  SpillVar spillRun({"det"}, [](const caf::SRSpill* spill) {return spill->det;});
106 
107  // set spill cuts
109  loader.AddSpillHistogram(spillHist, spillRun, kStandardSpillCuts);
110 
111  //////////////////// Cuts ////////////////////////
112  // cuts located in /CAFAna/Cuts/NumuCuts_breakdown.h
113  // included here for quick turnaround testing
114 
115  // kNumuQuality cuts
116  const Cut kNumuQuality_trkCCE({"energy.numusimp.trkccE"},
117  [](const caf::StandardRecord* sr)
118  {
119  return(sr->energy.numusimp.trkccE > 0);
120  }
121  );
122  const Cut kNumuQuality_pid({"sel.remid.pid"},
123  [](const caf::StandardRecord* sr)
124  {
125  return(sr->sel.remid.pid > 0);
126  }
127  );
128  const Cut kNumuQuality_nhit({"slc.nhit"},
129  [](const caf::StandardRecord* sr)
130  {
131  return(sr->slc.nhit > 20);
132  }
133  );
134  const Cut kNumuQuality_ncontplanes({"slc.ncontplanes"},
135  [](const caf::StandardRecord* sr)
136  {
137  return(sr->slc.ncontplanes > 4);
138  }
139  );
140  const Cut kNumuQuality_ncosmic({"trk.ncosmic"},
141  [](const caf::StandardRecord* sr)
142  {
143  return(sr->trk.ncosmic > 0);
144  }
145  );
146  // kNumuNCRej cuts:
147  const Cut kNumuNCRej_pid({"sel.remid.pid"},
148  [](const caf::StandardRecord* sr)
149  {
150  return(sr->sel.remid.pid > 0.75);
151  }
152  );
153  // kNumuContainND cuts
154 
155  const Cut kNumuContainND_nkalman({"trk.nkalman","sel.remid.bestidx"},
156  [](const caf::StandardRecord* sr)
157  {
158  return(sr->trk.nkalman > sr->sel.remid.bestidx);
159  }
160  );
161  const Cut kNumuContainND_ncellsfromedge({"slc.ncellsfromedge"},
162  [](const caf::StandardRecord* sr)
163  {
164  return(sr->slc.ncellsfromedge > 1);
165  }
166  );
167  const Cut kNumuContainND_firstplane({"slc.firstplane"},
168  [](const caf::StandardRecord* sr)
169  {
170  return(sr->slc.firstplane > 1);
171  }
172  );
173  const Cut kNumuContainND_lastplane({"slc.lastplane"},
174  [](const caf::StandardRecord* sr)
175  {
176  return(sr->slc.lastplane < 212);
177  }
178  );
179  const Cut kNumuContainND_stopZ({"trk.kalman.stop.fZ","sel.remid.bestidx","sel.contain.kalyposattrans"},
180  [](const caf::StandardRecord* sr)
181  {
182  //return(sr->trk.kalman[sr->sel.remid.bestidx].stop.Z() < 1275);
183 
184  return((sr->trk.kalman[sr->sel.remid.bestidx].stop.Z() < 1275) ||
185  sr->sel.contain.kalyposattrans < 55);
186  }
187  );
188  const Cut kNumuContainND_startZ({"trk.kalman.start.fZ","sel.remid.bestidx"},
189  [](const caf::StandardRecord* sr)
190  {
191  return(sr->trk.kalman[sr->sel.remid.bestidx].start.Z() < 1150);
192  }
193  );
194  const Cut kNumuContainND_hadcalE({"energy.numusimp.ndhadcalcatE","energy.numusimp.ndhadcaltranE"},
195  [](const caf::StandardRecord* sr)
196  {
197  return((sr->energy.numusimp.ndhadcalcatE + sr->energy.numusimp.ndhadcaltranE ) < 0.03);
198  }
199  );
200  const Cut kNumuContainND_kalfwdcell({"sel.contain.kalfwdcellnd"},
201  [](const caf::StandardRecord* sr)
202  {
203  return(sr->sel.contain.kalfwdcellnd > 4);
204  /* return(sr->sel.contain.kalfwdcellnd > 100); */
205  }
206  );
207  const Cut kNumuContainND_kalbakcell({"sel.contain.kalbakcellnd"},
208  [](const caf::StandardRecord* sr)
209  {
210  return(sr->sel.contain.kalbakcellnd > 8);
211  }
212  );
213  ////////////////////////////////////////////////////////////////////////////////
214 
215  //////////////////// Vars ////////////////////////
216  // Vars located in /CAFAna/Vars/NumuVars_sel.h
217  // included here for quick turnaround testing
218 
219  //kNumuQuality vars
220  const Var varNumuQuality_trkccE = SIMPLEVAR(energy.numusimp.trkccE);
221  const Var varNumuQuality_pid = SIMPLEVAR(sel.remid.pid);
222  const Var varNumuQuality_nhit = SIMPLEVAR(slc.nhit);
223  const Var varNumuQuality_ncontplanes = SIMPLEVAR(slc.ncontplanes);
224  const Var varNumuQuality_ncosmic = SIMPLEVAR(trk.ncosmic);
225  //kNumuContainND vars
226  const Var varNumuContainND_nkalman = SIMPLEVAR(trk.nkalman);
227  const Var varNumuContainND_ncellsfromedge = SIMPLEVAR(slc.ncellsfromedge);
228  const Var varNumuContainND_firstplane = SIMPLEVAR(slc.firstplane);
229  const Var varNumuContainND_lastplane = SIMPLEVAR(slc.lastplane);
230  const Var varNumuContainND_startZ({"trk.kalman.start.fZ","sel.remid.bestidx","trk.nkalman"},
231  [](const caf::StandardRecord* sr)
232  {
233  if(sr->trk.nkalman == 0) return 0.;
234  return sr->trk.kalman[sr->sel.remid.bestidx].start.Z(); // vertex in mC &&
235  }
236  );
237  const Var varNumuContainND_stopZ({"trk.kalman.stop.fZ","sel.remid.bestidx","trk.nkalman"},
238  [](const caf::StandardRecord* sr)
239  {
240  if(sr->trk.nkalman == 0) return 0.;
241  return sr->trk.kalman[sr->sel.remid.bestidx].stop.Z(); // vertex in mC &&
242  }
243  );
244  const Var varNumuContainND_kalyposattrans = SIMPLEVAR(sel.contain.kalyposattrans);
245  const Var varNumuContainND_hadcalE({"energy.numusimp.ndhadcalcatE","energy.numusimp.ndhadcaltranE"},
246  [](const caf::StandardRecord* sr)
247  {
248  return (sr->energy.numusimp.ndhadcalcatE + sr->energy.numusimp.ndhadcaltranE);
249  }
250  );
251  const Var varNumuContainND_kalfwdcell = SIMPLEVAR(sel.contain.kalfwdcellnd);
252  const Var varNumuContainND_kalbakcell = SIMPLEVAR(sel.contain.kalbakcellnd);
253  //kNumuNCRej var
254  const Var varNumuNCRej_pid = SIMPLEVAR(sel.remid.pid);
255  ////////////////////////////////////////////////////////////////////////////////
256 
257  //HistAxis
258  const HistAxis axNumuQuality_trkccE("NumuQuality, trkccE (GeV)", Binning::Simple(80,0,20), varNumuQuality_trkccE);
259  const HistAxis axNumuQuality_pid("NumuQuality, muon pid", Binning::Simple(40,0,1), varNumuQuality_pid);
260  const HistAxis axNumuQuality_nhit("NumuQuality, nhit", Binning::Simple(600,0,600), varNumuQuality_nhit);
261  const HistAxis axNumuQuality_ncontplanes("NumuQuality, ncontplanes", Binning::Simple(200,0,200), varNumuQuality_ncontplanes);
262  const HistAxis axNumuQuality_ncosmic("NumuQuality, ncosmic", Binning::Simple(10,0,10), varNumuQuality_ncosmic);
263  const HistAxis axNumuContainND_nkalman("NumuContainND, nkalman", Binning::Simple(40,0,40), varNumuContainND_nkalman);
264  const HistAxis axNumuContainND_ncellsfromedge("NumuContainND, ncellsfromedge", Binning::Simple(50,0,50), varNumuContainND_ncellsfromedge);
265  const HistAxis axNumuContainND_firstplane("NumuContainND, firstplane", Binning::Simple(200,0,200), varNumuContainND_firstplane);
266  const HistAxis axNumuContainND_lastplane("NumuContainND, lastplane", Binning::Simple(300,0,300), varNumuContainND_lastplane);
267  const HistAxis axNumuContainND_startZ("NumuContainND, startZ", Binning::Simple(160,0,1600), varNumuContainND_startZ);
268  const HistAxis axNumuContainND_stopZ("NumuContainND, stopZ", Binning::Simple(160,0,1600), varNumuContainND_stopZ);
269  const HistAxis axNumuContainND_kalyposattrans("NumuContainND, kalyposattrans", Binning::Simple(200,-2000,2000), varNumuContainND_kalyposattrans);
270  const HistAxis axNumuContainND_hadcalE("NumuContainND, hadcalcatE + hadcaltranE", Binning::Simple(100,0,0.2), varNumuContainND_hadcalE);
271  const HistAxis axNumuContainND_kalfwdcell("NumuContainND, kalfwdcell", Binning::Simple(320,-20,300), varNumuContainND_kalfwdcell);
272  const HistAxis axNumuContainND_kalbakcell("NumuContainND, kalbakcell", Binning::Simple(320,-20,300), varNumuContainND_kalbakcell);
273  const HistAxis axNumuNCRej_pid("NumuNCRej, pid", Binning::Simple(40,0,1), varNumuNCRej_pid);
274  ////////////////////////////////////////////////////////////////////////////////
275 
276  // do no cuts first
277  // do all cuts
278  const Cut kNumuQuality =
279  (!kIsDytmanMEC) && kNumuQuality_trkCCE && kNumuQuality_pid && kNumuQuality_nhit
280  && kNumuQuality_ncontplanes && kNumuQuality_ncosmic;
281  const Cut kNumuNCRej =
282  (!kIsDytmanMEC) && kNumuNCRej_pid;
283  const Cut kNumuContainND =
284  (!kIsDytmanMEC) && kNumuContainND_nkalman && kNumuContainND_ncellsfromedge && kNumuContainND_firstplane
285  && kNumuContainND_lastplane && kNumuContainND_stopZ && kNumuContainND_startZ
286  && kNumuContainND_hadcalE && kNumuContainND_kalfwdcell && kNumuContainND_kalbakcell;
287  const Cut kNumuND =
288  (!kIsDytmanMEC) && kNumuQuality && kNumuContainND && kNumuNCRej;
289 
290  // do all cuts but the plotted variable
291  const Cut kNMinus1_trkccE = (!kIsDytmanMEC) && kNumuContainND && kNumuNCRej &&
292  kNumuQuality_pid && kNumuQuality_nhit && kNumuQuality_ncontplanes && kNumuQuality_ncosmic;
293  const Cut kNMinus1_pid = (!kIsDytmanMEC) && kNumuContainND && kNumuNCRej &&
294  kNumuQuality_trkCCE && kNumuQuality_nhit && kNumuQuality_ncontplanes && kNumuQuality_ncosmic;
295  const Cut kNMinus1_nhit = (!kIsDytmanMEC) && kNumuContainND && kNumuNCRej &&
296  kNumuQuality_trkCCE && kNumuQuality_pid && kNumuQuality_ncontplanes && kNumuQuality_ncosmic;
297  const Cut kNMinus1_ncontplanes = (!kIsDytmanMEC) && kNumuContainND && kNumuNCRej &&
298  kNumuQuality_trkCCE && kNumuQuality_pid && kNumuQuality_nhit && kNumuQuality_ncosmic;
299  const Cut kNMinus1_ncosmic = (!kIsDytmanMEC) && kNumuContainND && kNumuNCRej &&
300  kNumuQuality_trkCCE && kNumuQuality_pid && kNumuQuality_nhit && kNumuQuality_ncontplanes;
301  const Cut kNMinus1_nkalman = (!kIsDytmanMEC) && kNumuQuality && kNumuNCRej &&
302  kNumuContainND_ncellsfromedge && kNumuContainND_firstplane && kNumuContainND_lastplane && kNumuContainND_startZ &&
303  kNumuContainND_stopZ && kNumuContainND_hadcalE && kNumuContainND_kalfwdcell &&
304  kNumuContainND_kalbakcell;
305  const Cut kNMinus1_ncellsfromedge = (!kIsDytmanMEC) && kNumuQuality && kNumuNCRej &&
306  kNumuContainND_nkalman && kNumuContainND_firstplane && kNumuContainND_lastplane && kNumuContainND_startZ &&
307  kNumuContainND_stopZ && kNumuContainND_hadcalE && kNumuContainND_kalfwdcell &&
308  kNumuContainND_kalbakcell;
309  const Cut kNMinus1_firstplane = (!kIsDytmanMEC) && kNumuQuality && kNumuNCRej &&
310  kNumuContainND_nkalman && kNumuContainND_ncellsfromedge && kNumuContainND_lastplane && kNumuContainND_startZ &&
311  kNumuContainND_stopZ && kNumuContainND_hadcalE && kNumuContainND_kalfwdcell &&
312  kNumuContainND_kalbakcell;
313  const Cut kNMinus1_lastplane = (!kIsDytmanMEC) && kNumuQuality && kNumuNCRej &&
314  kNumuContainND_nkalman && kNumuContainND_ncellsfromedge && kNumuContainND_firstplane && kNumuContainND_startZ &&
315  kNumuContainND_stopZ && kNumuContainND_hadcalE && kNumuContainND_kalfwdcell &&
316  kNumuContainND_kalbakcell;
317  const Cut kNMinus1_startZ = (!kIsDytmanMEC) && kNumuQuality && kNumuNCRej &&
318  kNumuContainND_nkalman && kNumuContainND_ncellsfromedge && kNumuContainND_firstplane && kNumuContainND_lastplane &&
319  kNumuContainND_stopZ && kNumuContainND_hadcalE && kNumuContainND_kalfwdcell &&
320  kNumuContainND_kalbakcell;
321  const Cut kNMinus1_stopZ = (!kIsDytmanMEC) && kNumuQuality && kNumuNCRej &&
322  kNumuContainND_nkalman && kNumuContainND_ncellsfromedge && kNumuContainND_firstplane && kNumuContainND_lastplane &&
323  kNumuContainND_startZ && kNumuContainND_hadcalE && kNumuContainND_kalfwdcell &&
324  kNumuContainND_kalbakcell;
325  const Cut kNMinus1_kalyposattrans = (!kIsDytmanMEC) && kNumuQuality && kNumuNCRej &&
326  kNumuContainND_nkalman && kNumuContainND_ncellsfromedge && kNumuContainND_firstplane && kNumuContainND_lastplane &&
327  kNumuContainND_startZ && kNumuContainND_stopZ && kNumuContainND_hadcalE && kNumuContainND_kalfwdcell &&
328  kNumuContainND_kalbakcell;
329  const Cut kNMinus1_hadcalE = (!kIsDytmanMEC) && kNumuQuality && kNumuNCRej &&
330  kNumuContainND_nkalman && kNumuContainND_ncellsfromedge && kNumuContainND_firstplane && kNumuContainND_lastplane &&
331  kNumuContainND_startZ && kNumuContainND_stopZ && kNumuContainND_kalfwdcell &&
332  kNumuContainND_kalbakcell;
333  const Cut kNMinus1_kalfwdcell = (!kIsDytmanMEC) && kNumuQuality && kNumuNCRej &&
334  kNumuContainND_nkalman && kNumuContainND_ncellsfromedge && kNumuContainND_firstplane && kNumuContainND_lastplane &&
335  kNumuContainND_startZ && kNumuContainND_stopZ && kNumuContainND_hadcalE &&
336  kNumuContainND_kalbakcell;
337  const Cut kNMinus1_kalbakcell = (!kIsDytmanMEC) && kNumuQuality && kNumuNCRej &&
338  kNumuContainND_nkalman && kNumuContainND_ncellsfromedge && kNumuContainND_firstplane && kNumuContainND_lastplane &&
339  kNumuContainND_startZ && kNumuContainND_stopZ && kNumuContainND_hadcalE &&
340  kNumuContainND_kalfwdcell;
341  const Cut kNMinus1_NCRej =
342  (!kIsDytmanMEC) && kNumuQuality && kNumuContainND;
343  ////////////////////////////////////////////////////////////////////////////////
344 
345  std::vector<Selection> selections;
346  selections.emplace_back(kNoCut, "NoCuts",
347  "Selected events have no selection applied. ");
348  selections.emplace_back((!kIsDytmanMEC), "NoMEC",
349  "Selected events have only MEC rejection. ");
350  selections.emplace_back((!kIsDytmanMEC) && kNumuND, "NumuND",
351  "Selected events pass numu containment, slice quality, and ReMId cuts. ");
352  ////////////////////////////////////////////////////////////////////////////////
353 
354  std::vector<Selection> nMinusOneSelections;
355  std::vector<TangibleAxis> variables;
356  variables.emplace_back(axNumuQuality_trkccE,
357  "reco-trkccE", "numu CC track energy estimator. ");
358  nMinusOneSelections.emplace_back(kNMinus1_trkccE, "NMinus1_trkccE",
359  "Selected events have all ND numu selection except for trkccE");
360  variables.emplace_back(axNumuQuality_pid,
361  "reco-pid", "Reconstructed muon identification. ");
362  nMinusOneSelections.emplace_back(kNMinus1_pid, "NMinus1_pid",
363  "Selected events have all ND numu selection except for pid");
364  variables.emplace_back(axNumuQuality_nhit,
365  "reco-nhit", "Number of hits in the slice. ");
366  nMinusOneSelections.emplace_back(kNMinus1_nhit, "NMinus1_nhit",
367  "Selected events have all ND numu selection except for nhit");
368  variables.emplace_back(axNumuQuality_ncontplanes,
369  "reco-ncontplanes", "Number of continuous planes in the slice. ");
370  nMinusOneSelections.emplace_back(kNMinus1_ncontplanes, "NMinus1_ncontplanes",
371  "Selected events have all ND numu selection except for ncontplanes");
372  variables.emplace_back(axNumuQuality_ncosmic,
373  "reco-ncosmic", "Number of cosmic tracks in the slice. ");
374  nMinusOneSelections.emplace_back(kNMinus1_ncosmic, "NMinus1_ncosmic",
375  "Selected events have all ND numu selection except for ncosmic");
376  variables.emplace_back(axNumuContainND_nkalman,
377  "reco-nkalman", "Number of kalman tracks in the slice. ");
378  nMinusOneSelections.emplace_back(kNMinus1_nkalman, "NMinus1_nkalman",
379  "Selected events have all ND numu selection except for nkalman");
380  variables.emplace_back(axNumuContainND_ncellsfromedge,
381  "reco-ncellsfromedge", "Minimum number of cells to edge of detector. ");
382  nMinusOneSelections.emplace_back(kNMinus1_ncellsfromedge, "NMinus1_ncellsfromedge",
383  "Selected events have all ND numu selection except for ncellsfromedge");
384  variables.emplace_back(axNumuContainND_firstplane,
385  "reco-firstplane", "First plane in the slice. ");
386  nMinusOneSelections.emplace_back(kNMinus1_firstplane, "NMinus1_firstplane",
387  "Selected events have all ND numu selection except for firstplane");
388  variables.emplace_back(axNumuContainND_lastplane,
389  "reco-lastplane", "Last plane in the slice. ");
390  nMinusOneSelections.emplace_back(kNMinus1_lastplane, "NMinus1_lastplane",
391  "Selected events have all ND numu selection except for lastplane");
392  variables.emplace_back(axNumuContainND_startZ,
393  "reco-startZ", "Z-pos of track start. ");
394  nMinusOneSelections.emplace_back(kNMinus1_startZ, "NMinus1_startZ",
395  "Selected events have all ND numu selection except for startZ");
396  variables.emplace_back(axNumuContainND_stopZ,
397  "reco-stopZ", "Z-pos of track stop. ");
398  nMinusOneSelections.emplace_back(kNMinus1_stopZ, "NMinus1_stopZ",
399  "Selected events have all ND numu selection except for stopZ");
400  variables.emplace_back(axNumuContainND_kalyposattrans,
401  "reco-kalyposattrans", "Y position of kalman track at transition. ");
402  nMinusOneSelections.emplace_back(kNMinus1_kalyposattrans, "NMinus1_kalyposattrans",
403  "Selected events have all ND numu selection except for kalyposattrans");
404  variables.emplace_back(axNumuContainND_hadcalE,
405  "reco-hadcalcatE_plus_hadcaltranE", "Had. calE not on muon track in (muon catcher + transition plane) [GeV]. ");
406  nMinusOneSelections.emplace_back(kNMinus1_hadcalE, "NMinus1_hadcalE",
407  "Selected events have all ND numu selection except for hadcalE");
408  variables.emplace_back(axNumuContainND_kalfwdcell,
409  "reco-kalfwdcell", "Kalmantrack projected # cells from end point forwards to det edge, including muon catcher. ");
410  nMinusOneSelections.emplace_back(kNMinus1_kalfwdcell, "NMinus1_kalfwdcell",
411  "Selected events have all ND numu selection except for kalfwdcell");
412  variables.emplace_back(axNumuContainND_kalbakcell,
413  "reco-kalbakcell", "Kalmantrack projected # cells from start point backwards to det edge, including muon catcher. ");
414  nMinusOneSelections.emplace_back(kNMinus1_kalbakcell, "NMinus1_kalbakcell",
415  "Selected events have all ND numu selection except for kalbakcell");
416  variables.emplace_back(axNumuNCRej_pid,
417  "reco-pid_nc_rej", "Reconstructed muon identification. ");
418  nMinusOneSelections.emplace_back(kNMinus1_NCRej, "NMinus1_NCRej",
419  "Selected events have all ND numu selection except for NCRej");
420  ////////////////////////////////////////////////////////////////////////////////
421 
422 
423  // do two loops to fill vector of spectra.
424  // first through all variables and two selections (no cuts and all cuts)
425  // second through each variable and corresponding n-1 selection. Use same element of variable and selection vectors to ensure matching cuts
426  std::vector<UsefulHist> hists;
427  hists.reserve(selections.size() * variables.size() + variables.size());
428 
429  for(const auto& sel:selections){
430  for(const auto& variable:variables){
431  hists.emplace_back(sel, variable, loader);
432  }
433  }
434  for(std::vector<int>::size_type i = 0; i != variables.size(); i++) {
435  hists.emplace_back(nMinusOneSelections[i], variables[i], loader);
436  }
437 
438  std::cout << "\nrun : --- run loader.\n";
439  loader.Go();
440  std::cout << "\nrun : --- done.\n";
441  double pot = hists[0].fHist.POT();
442 
443  std::cout << "\nrun : --- save output.\n";
444  // TFile inputfile(kInputFileName.c_str(), "READ");
445  TFile outputfile(kOutputFileName.c_str(), "RECREATE");
446 
447  for(const auto& hist:hists){
448  TH1 *temp = hist.fHist.ToTH1(pot);
449  std::string tempName = hist.fName;
450  temp->Write(tempName.c_str());
451  }
452 
453  std::cout << "\nrun : --- save PoT.\n";
454 
455  TH1F *pothist = new TH1F("meta-TotalPOT", "TotalPOT", 1, 0, 1);
456  TH1F *evthist = new TH1F("meta-TotalEvents", "TotalEvents", 1, 0, 1);
457  pothist->SetBinContent(1, pot);
458  evthist->SetBinContent(1, spillHist->GetEntries());
459  pothist->Write("meta-TotalPOT");
460  evthist->Write("meta-TotalEvents");
461 
462  std::cout << "\nrun : --- close output files.\n";
463  outputfile.Close();
464  // inputfile.Close(); // will produce error if running over SAM dataset
465 
466 
467  std::cout << "\nrun : --- done.\n";
468 
469 
470  // dictionary to translate histogram names
471  /*
472  trkccE: numu energy (GeV)
473  pid: Reconstructed muon identification
474  nhit: Number of hits in the slice
475  ncontplanes: Number of continuous planes in the slice
476  ncosmic: Number of cosmic tracks in the slice
477  nkalman: Number of Kalman tracks in the slice
478  ncellsfromedge: Minimum number of cells to edge of detector
479  firstplane: First plane in the slice
480  lastplane: Last plane in the slice
481  startZ: Z-pos of track start
482  stopZ: Z-pos of track stop
483  kalyposattrans: Y position of Kalman track at transition
484  hadcalcatE_plus_hadcaltranE: hadronic calorometric energy NOT on muon track in (muon catcher + transition plane) [GeV]
485  kalfwdcell: Kalmantrack projected # cells from end point forwards to det edge, including muon catcher
486  kalbakcell: Kalmantrack projected # cells from start point backwards to det edge, including muon catcher
487  */
488 
489 
490  return;
491 }
492 
493 #endif
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
unsigned int lastplane
last plane
Definition: SRSlice.h:27
unsigned int firstplane
first plane
Definition: SRSlice.h:26
float kalyposattrans
Y position of Kalman track and transition (ND only, use to check if went through air gap) ...
Definition: SRContain.h:50
std::string fShortName
Definition: DataMCPair.h:47
Tangible< Cut > Selection
Definition: DataMCPair.h:52
void SetSpillCut(const SpillCut &cut)
TString hists[nhists]
Definition: bdt_com.C:3
void caf_numu_nd_cutflow(std::string kInputFileName, std::string kOutputFileName)
int kalbakcellnd
Kalmantrack projected # cells from start point backwards to det edge, including muon catcher...
Definition: SRContain.h:46
const Cut kNumuContainND([](const caf::SRProxy *sr){return( sr->trk.kalman.ntracks > sr->trk.kalman.idxremid &&sr->slc.ncellsfromedge > 1 &&sr->slc.firstplane > 1 &&sr->slc.lastplane< 212 &&sr->trk.kalman.tracks[0].start.Z()< 1150 &&( sr->trk.kalman.tracks[0].stop.Z()< 1275 ||sr->sel.contain.kalyposattrans< 55) &&( sr->energy.numu.ndhadcalcatE +sr->energy.numu.ndhadcaltranE)< 0.03 &&sr->sel.contain.kalfwdcellnd > 4 &&sr->sel.contain.kalbakcellnd > 8);})
Definition: NumuCuts.h:22
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const Cut kIsDytmanMEC
Definition: TruthCuts.cxx:187
Track finder for cosmic rays.
SRKalman kalman
Tracks produced by KalmanTrack.
Definition: SRTrackBranch.h:24
float pid
PID value output by kNN.
Definition: SRRemid.h:25
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Definition: typedefs.hpp:11
int kalfwdcellnd
Kalmantrack projected # cells from end point forwards to det edge, including muon catcher...
Definition: SRContain.h:41
virtual void AddSpillHistogram(TH1 *h, const SpillVar &var, const SpillCut &cut, const SpillVar &wei=kSpillUnweighted)
Uses include counting the total POT or spills in a run.
Tangible(const T &obj, const std::string &shortName, const std::string &blurb)
UsefulHist(Selection sel, TangibleAxis tanAxis, SpectrumLoader &loader, const Cut &bkg=kNoCut)
SRRemid remid
Output from RecoMuonID (ReMId) package.
Definition: SRIDBranch.h:39
Tangible< HistAxis > TangibleAxis
Definition: DataMCPair.h:53
const Cut kNumuND
Definition: NumuCuts.h:55
double energy
Definition: plottest35.C:25
#define pot
caf::StandardRecord * sr
virtual void Go() override
Load all the registered spectra.
const Cut kNumuNCRej([](const caf::SRProxy *sr){return(sr->sel.remid.pid >0.75);})
Definition: NumuCuts.h:24
loader
Definition: demo0.py:10
short nnu
Number of neutrinos in nu vector (0 or 1)
Definition: SRTruthBranch.h:37
unsigned int nhit
number of hits
Definition: SRSlice.h:22
TLatex * prelim
Definition: Xsec_final.C:133
void Preliminary()
Put NOvA Preliminary on plots.
OStream cout
Definition: OStream.cxx:6
std::string fBlurb
Definition: DataMCPair.h:46
unsigned int ncellsfromedge
minimum number of cells to edge of detector
Definition: SRSlice.h:30
The StandardRecord is the primary top-level object in the Common Analysis File trees.
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
SRIDBranch sel
Selector (PID) branch.
assert(nhit_max >=nhit_nbins)
string shortName
THUMBNAIL BLOCK: We need to make a thumbnail for each.
SRSlice slc
Slice branch: nhit, extents, time, etc.
SRTruthBranch mc
Truth branch for MC: energy, flavor, etc.
string tempName
const SpillCut kStandardSpillCuts
Apply this unless you&#39;re doing something special.
Definition: SpillCuts.h:49
double T
Definition: Xdiff_gwt.C:5
const Cut kNumuQuality
Definition: NumuCuts.h:18
Template for Var and SpillVar.
unsigned int ncontplanes
number of continuous planes
Definition: SRSlice.h:25
SRTrackBranch trk
Track branch: nhit, len, etc.
SREnergyBranch energy
Energy estimator branch.
enum BeamMode kBlue
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:107
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
const Cut kNoCut
The simplest possible cut: pass everything, used as a default.
Definition: Cut.h:109
enum BeamMode string