All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
helper.h
Go to the documentation of this file.
1 #pragma once
2 
5 #include "sbnanaobj/StandardRecord/Proxy/SRProxy.h"
6 
7 #include "SBNAna/Vars/Binnings.h"
8 #include "SBNAna/Vars/NueVars.h"
9 #include "SBNAna/Vars/Vars.h"
10 #include "SBNAna/Cuts/Cuts.h"
11 #include "SBNAna/Cuts/NueCuts.h"
12 #include "SBNAna/Cuts/TruthCuts.h"
13 
14 using namespace ana;
15 
16 // These are examples of useful structs to
17 // use when making a bunch of Spectra
18 struct PlotDef
19 {
20  std::string suffix = "";
21  std::string label = "";
22  Binning bins = Binning::Simple(3,0,3);
23  Var var = kCounting;
24 };
25 
26 struct PlotDefSpill
27 {
28  std::string suffix = "";
29  std::string label = "";
30  Binning bins = Binning::Simple(3,0,3);
32 };
33 
38 const Binning kPEBinning = Binning::Simple(70,0.,1400);
39 const Binning kTimeBinning = Binning::Simple(70,0.,3500);
40 
41 
42 // // In this example, we are making the following Spectra
43 std::vector<PlotDef> plots =
44  {{"count", "", Binning::Simple(3,0,3), kCounting},
45  {"bestenergy", "Best plane energy (GeV)", kLowEnergyBinningGeV, kRecoShower_BestEnergy},
46  {"conversion", "Conversion gap (cm)", kGapBinning, kRecoShower_ConversionGap},
47  {"density", "Shower density (MeV/cm)", kDensityBinning, kRecoShower_Density},
48  {"energy", "Energy (MeV)", kNueEnergyBinning, kRecoShower_Energy},
49  {"length", "Length (cm)", kLengthBinning, kRecoShower_Length},
50  {"openangle", "Opening angle", kOpenAngleBinning, kRecoShower_OpenAngle},
51  {"startx", "Shower start position X (cm)", kPositionXFDBinning, kRecoShower_StartX},
52  {"starty", "Shower start position Y (cm)", kPositionYFDBinning, kRecoShower_StartY},
53  {"startz", "Shower start position Z (cm)", kPositionZFDBinning, kRecoShower_StartZ},
54  {"endx", "Shower end position X (cm)", kPositionXFDBinning, kRecoShower_EndX},
55  {"endy", "Shower end position Y (cm)", kPositionYFDBinning, kRecoShower_EndY},
56  {"endz", "Shower end position Z (cm)", kPositionZFDBinning, kRecoShower_EndZ},
57  {"vtxx", "Slice vertex X (cm)", kPositionXFDBinning, kSlcVtxX},
58  {"vtxy", "Slice vertes Y (cm)", kPositionYFDBinning, kSlcVtxY},
59  {"vtxz", "Slice vertex Z (cm)", kPositionZFDBinning, kSlcVtxZ}
60  };
61 
62 std::vector<PlotDefSpill> plots_spill =
63  {{"crtx", "CRT Hit Position X (cm)", kPositionXFDBinning, kCRTHitX},
64  {"crty", "CRT Hit Position Y (cm)", kPositionYFDBinning, kCRTHitY},
65  {"crtz", "CRT Hit Position Z (cm)", kPositionZFDBinning, kCRTHitZ},
66  {"crttime", "CRT Hit Time (xs)", kTimeBinning, kCRTHitTime},
67  {"crtpe", "CRT PE", kPEBinning, kCRTHitPE}
68 };
69 
70 // Selection Struc
71 struct SelDef
72 {
73  std::string suffix = "";
74  std::string label = "";
75  Cut cut = kNoCut;
76  int color = kBlack;
77 };
78 
79 struct SelDefSpill
80 {
81  std::string suffix = "";
82  std::string label = "";
83  SpillCut cut = kNoSpillCut;
84  int color = kBlack;
85 };
86 
87 // In this example, our signal is Nue cc
88 const Cut kSig = kIsNue && !kIsNC;
90 
91 // Define a basic cut for testing
92 const Cut kShortShower(
93  [](const caf::SRSliceProxy* slc){
94  if(slc->reco.nshw>0){ // check if there is actually a shower
95  return ( slc->reco.shw[0].len < 30.);
96  }
97  return false;
98  }
99  );
100 
101 
102 std::vector<SelDef> sels =
103  {{"nocut", "All Slices", kNoCut, kBlack},
104  {"sig", "True NumuCC", kSig, kRed+1},
105  {"bkg", "Not NumuCC", !kSig, kAzure+2},
106  {"cont", "Contained", kContained, kBlack},
107  {"sig_cont", "Contained Signal", kContained && kSig, kRed+1},
108  {"bkg_cont", "Contained Bkg", kContained && !kSig, kAzure+2},
109  {"uncont", "Uncontained", !kContained, kBlack},
110  {"sig_uncont", "Uncontained Signal", !kContained && kSig, kRed+1},
111  {"bkg_uncont", "Uncontained Bkg", !kContained && !kSig, kAzure+2}
112  };
113 
114 std::vector<SelDefSpill> sels_spill =
115  {{"nocut_spill", "All Slices", kNoSpillCut, kBlack},
116  {"event_spill", "First Events", kFirstEvents, kRed+1},
117  {"flash_spill", "Pass flash Trigger", kFlashTrigger, kAzure+2}
118  };
const Binning kLengthBinning
const Cut kNoCut([](const caf::SRSliceProxy *){return true;})
The simplest possible cut: pass everything, used as a default.
const Var kRecoShower_EndX([](const caf::SRSliceProxy *slc) -> double{const caf::SRShowerProxy *shw=LargestRecoShower(slc);return shw?double(shw->start.x+shw->dir.x *shw->len):-9999.;})
Definition: NueVars.h:20
const Var kRecoShower_OpenAngle([](const caf::SRSliceProxy *slc) -> double{const caf::SRShowerProxy *shw=LargestRecoShower(slc);return shw?180.*shw->open_angle/M_PI:-5.;})
Definition: NueVars.h:16
const SpillCut kFirstEvents
Definition: Cuts.cxx:14
const SpillMultiVar kCRTHitTime([](const caf::SRSpillProxy *sr){std::vector< double > times;for(const auto &hit:sr->crt_hits){times.push_back(hit.time);}return times;})
Definition: Vars.h:19
const Cut kIsNC([](const caf::SRSliceProxy *slc){return kHasMatchedNu(slc)&&slc->truth.isnc;})
Is this a Neutral Current event?
Represent the binning of a Spectrum&#39;s x-axis.
Definition: Binning.h:18
const SpillMultiVar kCRTHitX([](const caf::SRSpillProxy *sr){std::vector< double > positions;for(const auto &hit:sr->crt_hits){positions.push_back(hit.position.x);}return positions;})
Definition: Vars.h:15
const Binning kTimeBinning
const Cut kNueContainedFD([](const caf::SRSliceProxy *slc){const int largestShwIdx(kLargestRecoShowerIdx(slc));return false;double this_endx=slc->reco.shw[largestShwIdx].start.x+(slc->reco.shw[largestShwIdx].dir.x *slc->reco.shw[largestShwIdx].len);double this_endy=slc->reco.shw[largestShwIdx].start.y+(slc->reco.shw[largestShwIdx].dir.y *slc->reco.shw[largestShwIdx].len);double this_endz=slc->reco.shw[largestShwIdx].start.z+(slc->reco.shw[largestShwIdx].dir.z *slc->reco.shw[largestShwIdx].len);bool startx=(fvfd_cryo1.xmin< slc->reco.shw[largestShwIdx].start.x)&&(slc->reco.shw[largestShwIdx].start.x< fvfd_cryo1.xmax);bool endx=(fvfd_cryo1.xmin< this_endx)&&(this_endx< fvfd_cryo1.xmax);bool starty=(fvfd_cryo1.ymin< slc->reco.shw[largestShwIdx].start.y)&&(slc->reco.shw[largestShwIdx].start.y< fvfd_cryo1.ymax);bool endy=(fvfd_cryo1.ymin< this_endy)&&(this_endy< fvfd_cryo1.ymax);bool startz=(fvfd_cryo1.zmin< slc->reco.shw[largestShwIdx].start.z)&&(slc->reco.shw[largestShwIdx].start.z< fvfd_cryo1.zmax);bool endz=(fvfd_cryo1.zmin< this_endz)&&(this_endz< fvfd_cryo1.zmax);return(startx &&endx &&starty &&endy &&startz &&endz);})
Definition: NueCuts.h:34
std::vector< SelDefSpill > sels_spill
const Binning kDensityBinning
const Var kRecoShower_StartX([](const caf::SRSliceProxy *slc) -> double{const caf::SRShowerProxy *shw=LargestRecoShower(slc);return shw?double(shw->start.x):-9999.;})
Definition: NueVars.h:17
const Var kRecoShower_StartY([](const caf::SRSliceProxy *slc) -> double{const caf::SRShowerProxy *shw=LargestRecoShower(slc);return shw?double(shw->start.y):-9999.;})
Definition: NueVars.h:18
const Binning kOpenAngleBinning
process_name opflashCryoW ana
caf::Proxy< caf::SRSlice > SRSliceProxy
Definition: EpilogFwd.h:2
const Cut kIsNue([](const caf::SRSliceProxy *slc){return slc->truth.index >=0 &&abs(slc->truth.pdg)==12;})
const Var kSlcVtxX([](const caf::SRSliceProxy *slc) -> double{return slc->vertex.x;})
Definition: Vars.h:30
const Var kSlcVtxY([](const caf::SRSliceProxy *slc) -> double{return slc->vertex.y;})
Definition: Vars.h:31
Definition: demo.h:63
const Var kRecoShower_BestEnergy([](const caf::SRSliceProxy *slc) -> double{const caf::SRShowerProxy *shw=LargestRecoShower(slc);return shw?double(shw->bestplane_energy):-5;})
Definition: NueVars.h:10
const SpillMultiVar kCRTHitPE([](const caf::SRSpillProxy *sr){std::vector< double > pes;for(const auto &hit:sr->crt_hits){pes.push_back(hit.pe);}return pes;})
Definition: Vars.h:18
const Cut kSig
Definition: demo.h:73
const Binning kPositionXFDBinning
Definition: Binnings.cxx:32
const Var kSlcVtxZ([](const caf::SRSliceProxy *slc) -> double{return slc->vertex.z;})
Definition: Vars.h:32
const Var kRecoShower_EndY([](const caf::SRSliceProxy *slc) -> double{const caf::SRShowerProxy *shw=LargestRecoShower(slc);return shw?double(shw->start.y+shw->dir.y *shw->len):-9999.;})
Definition: NueVars.h:21
const SpillMultiVar kCRTHitY([](const caf::SRSpillProxy *sr){std::vector< double > positions;for(const auto &hit:sr->crt_hits){positions.push_back(hit.position.y);}return positions;})
Definition: Vars.h:16
const Binning kPEBinning
const Var kRecoShower_Length([](const caf::SRSliceProxy *slc) -> double{const caf::SRShowerProxy *shw=LargestRecoShower(slc);return shw?double(shw->len):-5.;})
Definition: NueVars.h:15
const Var kRecoShower_Energy([](const caf::SRSliceProxy *slc) -> double{const caf::SRShowerProxy *shw=LargestRecoShower(slc);return shw?double(shw->plane[1].energy):-5.;})
Definition: NueVars.h:14
const SpillMultiVar kCRTHitZ([](const caf::SRSpillProxy *sr){std::vector< double > positions;for(const auto &hit:sr->crt_hits){positions.push_back(hit.position.z);}return positions;})
Definition: Vars.h:17
std::vector< PlotDef > plots
Definition: demo.h:54
const SpillCut kNoSpillCut([](const caf::SRSpillProxy *){return true;})
The simplest possible cut: pass everything, used as a default.
const SpillCut kFlashTrigger([](const caf::SRSpillProxy *sr){return(sr->pass_flashtrig);})
const Var kRecoShower_StartZ([](const caf::SRSliceProxy *slc) -> double{const caf::SRShowerProxy *shw=LargestRecoShower(slc);return shw?double(shw->start.z):-9999.;})
Definition: NueVars.h:19
const Binning kPositionYFDBinning
Definition: Binnings.cxx:33
const Binning kNueEnergyBinning
Definition: Binnings.cxx:22
std::vector< SelDef > sels
Definition: demo.h:77
const Cut kContained
const Binning kPositionZFDBinning
Definition: Binnings.cxx:34
std::vector< PlotDefSpill > plots_spill
Definition: demo.h:45
const Var kRecoShower_Density([](const caf::SRSliceProxy *slc) -> double{const caf::SRShowerProxy *shw=LargestRecoShower(slc);return shw?double(shw->density):-5.;})
Definition: NueVars.h:13
const Binning kGapBinning
const Var kCounting
Definition: Vars.cxx:19
const Var kRecoShower_EndZ([](const caf::SRSliceProxy *slc) -> double{const caf::SRShowerProxy *shw=LargestRecoShower(slc);return shw?double(shw->start.z+shw->dir.z *shw->len):-9999.;})
Definition: NueVars.h:22
const Var kRecoShower_ConversionGap([](const caf::SRSliceProxy *slc) -> double{const caf::SRShowerProxy *shw=LargestRecoShower(slc);return shw?double(shw->conversion_gap):-5.;})
Definition: NueVars.h:12
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:38
const Cut kShortShower([](const caf::SRSliceProxy *slc){if(slc->reco.nshw >0){return(slc->reco.shw[0].len< 30.);}return false;})