LSTMEHelperVars.cxx
Go to the documentation of this file.
2 
4 #include "CAFAna/Vars/Vars.h"
6 
7 
8 #define SIMPLE_PNG2D_VAR(EXPR) \
9  { \
10  "png2d." #EXPR, \
11  constructPng2dVar( \
12  [](const caf::SRProngProxy *png2d) -> double \
13  { return png2d->EXPR; } \
14  ) \
15  }
16 
17 #define SIMPLE_PNG3D_VAR(EXPR) \
18  { \
19  "png." #EXPR, \
20  constructPng3dVar( \
21  [](const caf::SRFuzzyKProngProxy *png) -> double \
22  { return png->EXPR; } \
23  ) \
24  }
25 
26 #define CVN_PNG3D_VAR(EXPR,ISMUON) \
27  { \
28  "png." #EXPR, \
29  constructCVNPng3dVar( \
30  [](const caf::SRFuzzyKProngProxy *png) -> double \
31  { return png->EXPR; }, \
32  ISMUON \
33  ) \
34  }
35 
36 #define BPF_PNG3D_VAR(EXPR,IDX) \
37  { \
38  "png.bpf[" #IDX "]." #EXPR, \
39  constructBPFPng3dVar( \
40  [](const caf::SRBpfTrackProxy *bpf) -> double \
41  { return bpf->EXPR; }, \
42  IDX \
43  ) \
44  }
45 
46 namespace ana
47 {
48 
49 const Var kCoarseTiming(
50  [] (const caf::SRProxy *sr) -> double
51  {
52  const caf::Det_t det = sr->hdr.det;
53 
54  if (det != caf::kFARDET) {
55  return 0;
56  }
57 
58  return (PeriodFromRunFD(sr->hdr.run) == 1);
59  }
60 );
61 
62 const Var kLowGain(
63  [] (const caf::SRProxy *sr) -> double
64  {
65  const caf::Det_t det = sr->hdr.det;
66 
67  if (det == caf::kFARDET) {
68  return (PeriodFromRunFD(sr->hdr.run) <= 2);
69  }
70 
71  if (det == caf::kNEARDET) {
72  return (PeriodFromRunND(sr->hdr.run) <= 2);
73  }
74 
75  return 0;
76  }
77 );
78 
79 const Var kRemPngCalE(
80  [] (const caf::SRProxy *sr) -> double
81  {
82  double prongCalE = 0;
83 
84  auto &png = sr->vtx.elastic.fuzzyk.png;
85 
86  for (size_t i = 0; i < png.size(); i++) {
87  prongCalE += png[i].calE;
88  }
89 
90  return sr->slc.calE - prongCalE;
91  }
92 );
93 
95  const std::function<double (const caf::SRProngProxy *png2d)> &func
96 )
97 {
98  return MultiVar(
99  [func] (const caf::SRProxy *sr)
100  {
101  auto &png2d = sr->vtx.elastic.fuzzyk.png2d;
102 
103  std::vector<double> result;
104  result.reserve(png2d.size());
105 
106  for (size_t i = 0; i < png2d.size(); i++) {
107  result.push_back( func(& png2d[i]) );
108  }
109 
110  return result;
111  }
112  );
113 }
114 
116  const std::function<double (const caf::SRFuzzyKProngProxy *png)> &func
117 )
118 {
119  return MultiVar(
120  [func] (const caf::SRProxy *sr)
121  {
122  auto &png = sr->vtx.elastic.fuzzyk.png;
123 
124  std::vector<double> result;
125  result.reserve(png.size());
126 
127  for (size_t i = 0; i < png.size(); i++) {
128  result.push_back( func(& png[i]) );
129  }
130 
131  return result;
132  }
133  );
134 }
135 
137  const std::function<double (const caf::SRFuzzyKProngProxy *png)> &func,
138  bool isMuonID
139 )
140 {
141  return constructPng3dVar(
142  [func,isMuonID] (const caf::SRFuzzyKProngProxy *png) -> double
143  {
144  if (png->cvnpart.muonid != -5) {
145  return func(png);
146  }
147 
148  if (isMuonID && (png->len > 500)) {
149  return 1.0;
150  }
151 
152  return 0.0;
153  }
154  );
155 }
156 
158  const std::function<double (const caf::SRBpfTrackProxy *bpf)> &func,
159  size_t bpfIdx
160 )
161 {
162  return constructPng3dVar(
163  [func,bpfIdx] (const caf::SRFuzzyKProngProxy *png) -> double
164  {
165  if (!png->bpf.muon.IsValid ||
166  !png->bpf.pion.IsValid ||
167  !png->bpf.proton.IsValid) {
168  return 0;
169  }
170 
171  switch (bpfIdx) {
172  // CAUTION:
173  // These cases assume that BPF attempts to fit tracks specifically
174  // in the order: muon, pion, proton as dictated by the
175  // "FitAs*" fcl parameters in BreakPoint.fcl and the code in
176  // BreakPoint_module.cc where those fcl parameters are set (see the
177  // "reconfigure" function.)
178  case 2:
179  return func(& png->bpf.muon);
180  case 1:
181  return func(& png->bpf.pion);
182  case 0:
183  return func(& png->bpf.proton);
184  default:
185  return 0;
186  }
187  }
188  );
189 }
190 
191 const std::vector<std::pair<std::string, Var>> kSliceVarDefs({
192  { "coarseTiming", kCoarseTiming },
193  { "lowGain", kLowGain },
194  { "remPngCalE", kRemPngCalE },
195  { "nHit", kNHit },
196  { "calE", SIMPLEVAR(slc.calE) },
197  { "orphCalE", SIMPLEVAR(vtx.elastic.fuzzyk.orphCalE) }
198 });
199 
200 const std::vector<std::pair<std::string, MultiVar>> kPng2dVarDefs({
205  SIMPLE_PNG2D_VAR(nhitx),
206  SIMPLE_PNG2D_VAR(nhity),
207  SIMPLE_PNG2D_VAR(nplane),
209  SIMPLE_PNG2D_VAR(weightedCalE),
210  SIMPLE_PNG2D_VAR(calE),
214 });
215 
216 const std::vector<std::pair<std::string, MultiVar>> kPng3dVarDefs({
224  SIMPLE_PNG3D_VAR(weightedCalE),
225  SIMPLE_PNG3D_VAR(calE),
227  SIMPLE_PNG3D_VAR(nhitx),
228  SIMPLE_PNG3D_VAR(nhity),
229  SIMPLE_PNG3D_VAR(nplane),
230 
231  CVN_PNG3D_VAR(cvnpart.muonid, true ),
232  CVN_PNG3D_VAR(cvnpart.electronid, false),
233  CVN_PNG3D_VAR(cvnpart.pionid, false),
234  CVN_PNG3D_VAR(cvnpart.protonid, false),
235  CVN_PNG3D_VAR(cvnpart.photonid, false),
236 
237  BPF_PNG3D_VAR(energy, 0),
238  BPF_PNG3D_VAR(overlapE, 0),
239  BPF_PNG3D_VAR(momentum.x, 0),
240  BPF_PNG3D_VAR(momentum.y, 0),
241  BPF_PNG3D_VAR(momentum.z, 0),
242  BPF_PNG3D_VAR(nhit, 0),
243  BPF_PNG3D_VAR(nhitx, 0),
244  BPF_PNG3D_VAR(nhity, 0),
245  BPF_PNG3D_VAR(nplane, 0),
246 
247  BPF_PNG3D_VAR(energy, 1),
248  BPF_PNG3D_VAR(overlapE, 1),
249  BPF_PNG3D_VAR(momentum.x, 1),
250  BPF_PNG3D_VAR(momentum.y, 1),
251  BPF_PNG3D_VAR(momentum.z, 1),
252  BPF_PNG3D_VAR(nhit, 1),
253  BPF_PNG3D_VAR(nhitx, 1),
254  BPF_PNG3D_VAR(nhity, 1),
255  BPF_PNG3D_VAR(nplane, 1),
256 
257  BPF_PNG3D_VAR(energy, 2),
258  BPF_PNG3D_VAR(overlapE, 2),
259  BPF_PNG3D_VAR(momentum.x, 2),
260  BPF_PNG3D_VAR(momentum.y, 2),
261  BPF_PNG3D_VAR(momentum.z, 2),
262  BPF_PNG3D_VAR(nhit, 2),
263  BPF_PNG3D_VAR(nhitx, 2),
264  BPF_PNG3D_VAR(nhity, 2),
265  BPF_PNG3D_VAR(nplane, 2)
266 });
267 
268 }
const XML_Char int len
Definition: expat.h:262
Near Detector underground.
Definition: SREnums.h:10
Det_t
Which NOvA detector?
Definition: SREnums.h:7
caf::Proxy< caf::SRFuzzyK > fuzzyk
Definition: SRProxy.h:2058
Far Detector at Ash River.
Definition: SREnums.h:11
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
caf::Proxy< std::vector< caf::SRProng > > png2d
Definition: SRProxy.h:2043
MultiVar constructPng3dVar(const std::function< double(const caf::SRFuzzyKProngProxy *png)> &func)
caf::Proxy< caf::SRHeader > hdr
Definition: SRProxy.h:2136
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2125
nhit
Definition: demo1.py:25
const std::vector< std::pair< std::string, MultiVar > > kPng2dVarDefs
caf::Proxy< unsigned int > run
Definition: SRProxy.h:247
_Var< caf::SRProxy > Var
Representation of a variable to be retrieved from a caf::StandardRecord object.
Definition: Var.h:74
unsigned int PeriodFromRunFD(int run)
: Helper function to compute the period given a run number for the FD.
Definition: RunPeriods.cxx:15
caf::Proxy< caf::SRElastic > elastic
Definition: SRProxy.h:2117
const std::vector< std::pair< std::string, Var > > kSliceVarDefs
caf::Proxy< std::vector< caf::SRFuzzyKProng > > png
Definition: SRProxy.h:2042
#define SIMPLEVAR(CAFNAME)
For Vars where literally all you need is a single CAF variable.
Definition: Var.h:88
const Var kRemPngCalE([](const caf::SRProxy *sr) -> double{double prongCalE=0;auto &png=sr->vtx.elastic.fuzzyk.png;for(size_t i=0;i< png.size();i++){prongCalE+=png[i].calE;}return sr->slc.calE-prongCalE;})
if(dump)
MultiVar constructBPFPng3dVar(const std::function< double(const caf::SRBpfTrackProxy *bpf)> &func, size_t bpfIdx)
const Var kNHit
Definition: Vars.cxx:71
double energy
Definition: plottest35.C:25
const std::vector< std::pair< std::string, MultiVar > > kPng3dVarDefs
caf::StandardRecord * sr
double func(double x, double y)
#define SIMPLE_PNG3D_VAR(EXPR)
MultiVar constructPng2dVar(const std::function< double(const caf::SRProngProxy *png2d)> &func)
#define BPF_PNG3D_VAR(EXPR, IDX)
caf::Proxy< caf::SRSlice > slc
Definition: SRProxy.h:2141
TDirectory * dir
Definition: macro.C:5
caf::Proxy< float > calE
Definition: SRProxy.h:1291
MultiVar constructCVNPng3dVar(const std::function< double(const caf::SRFuzzyKProngProxy *png)> &func, bool isMuonID)
_MultiVar< caf::SRProxy > MultiVar
Definition: MultiVar.h:52
#define SIMPLE_PNG2D_VAR(EXPR)
const Var kCoarseTiming([](const caf::SRProxy *sr) -> double{const caf::Det_t det=sr->hdr.det;if(det!=caf::kFARDET){return 0;}return(PeriodFromRunFD(sr->hdr.run)==1);})
caf::Proxy< caf::SRVertexBranch > vtx
Definition: SRProxy.h:2145
#define CVN_PNG3D_VAR(EXPR, ISMUON)
unsigned int PeriodFromRunND(int run)
: Helper function to compute the period given a run number for the ND.
Definition: RunPeriods.cxx:34
const Var kLowGain([](const caf::SRProxy *sr) -> double{const caf::Det_t det=sr->hdr.det;if(det==caf::kFARDET){return(PeriodFromRunFD(sr->hdr.run)<=2);}if(det==caf::kNEARDET){return(PeriodFromRunND(sr->hdr.run)<=2);}return 0;})
caf::Proxy< caf::Det_t > det
Definition: SRProxy.h:231