LSTMEVar.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "CAFAna/Core/Var.h"
4 #include "CAFAna/Core/MultiVar.h"
6 
9 #include "TensorFlowEvaluator/SliceLID/cafana/ResultCacher.hxx"
10 
11 namespace LSTME
12 {
13 
14 using namespace ana;
15 using CAFAnaModel = ResultCacher<LSTMEnergy>;
16 
18  const caf::SRProxy *sr,
19  const std::vector<std::pair<std::string, Var>> &sliceVarDefs,
20  const std::vector<std::pair<std::string, MultiVar>> &png2dVarDefs,
21  const std::vector<std::pair<std::string, MultiVar>> &png3dVarDefs
22 )
23 {
25 
26  for (auto &namedVar : sliceVarDefs) {
27  result.scalarVarMap[namedVar.first] = namedVar.second(sr);
28  }
29 
30  for (auto &namedMultiVar : png2dVarDefs) {
31  result.vectorVarMap[namedMultiVar.first] = namedMultiVar.second(sr);
32  }
33 
34  for (auto &namedMultiVar : png3dVarDefs) {
35  result.vectorVarMap[namedMultiVar.first] = namedMultiVar.second(sr);
36  }
37 
38  return result;
39 }
40 
41 static std::shared_ptr<CAFAnaModel> initCAFAnaModel(
42  const std::string &modelSavedir
43 )
44 {
45  auto model = std::make_shared<Model>(modelSavedir);
46 
47  return std::make_shared<CAFAnaModel>(
48  [
49  model = std::move(model),
50  trkLenCorr = TrackLengthCorrection()
51  ] (const caf::SRProxy *sr) mutable -> LSTMEnergy
52  {
53  auto varDict = fillVarDict(
55  );
56 
57  /* TODO: remove air bubble correction once geometry is fixed */
58  bool isMC = (sr->mc.nallnus > 0) || (sr->mc.nallcosmics > 0);
59  trkLenCorr.setParams(isMC, (sr->hdr.det == caf::kFARDET));
60  trkLenCorr.shift(varDict);
61 
62  return model->predict(varDict);
63  }
64  );
65 }
66 
67 static Var primaryEnergy(const std::shared_ptr<CAFAnaModel> &model)
68 {
69  return Var(
70  [model] (const caf::SRProxy *sr) -> double
71  {
72  return (*model)(sr).primaryE;
73  }
74  );
75 }
76 
77 static Var totalEnergy(const std::shared_ptr<CAFAnaModel> &model)
78 {
79  return Var(
80  [model] (const caf::SRProxy *sr) -> double
81  {
82  return (*model)(sr).totalE;
83  }
84  );
85 }
86 
87 static Var secondaryEnergy(const std::shared_ptr<CAFAnaModel> &model)
88 {
89  return Var(
90  [model] (const caf::SRProxy *sr) -> double
91  {
92  return (*model)(sr).totalE - (*model)(sr).primaryE;
93  }
94  );
95 }
96 
97 }
98 
Det_t det
Detector, ND = 1, FD = 2, NDOS = 3.
Definition: SRHeader.h:28
Far Detector at Ash River.
Definition: SREnums.h:11
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
SRHeader hdr
Header branch: run, subrun, etc.
std::unordered_map< std::string, std::vector< double > > vectorVarMap
Definition: VarDict.h:11
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2126
const std::vector< std::pair< std::string, MultiVar > > kPng2dVarDefs
static Var secondaryEnergy(const std::shared_ptr< CAFAnaModel > &model)
Definition: LSTMEVar.h:87
_Var< caf::SRProxy > Var
Representation of a variable to be retrieved from a caf::StandardRecord object.
Definition: Var.h:74
const std::vector< std::pair< std::string, Var > > kSliceVarDefs
short nallcosmics
Number of cosmics in allcosmics vector.
Definition: SRTruthBranch.h:40
static Var primaryEnergy(const std::shared_ptr< CAFAnaModel > &model)
Definition: LSTMEVar.h:67
const std::vector< std::pair< std::string, MultiVar > > kPng3dVarDefs
static std::shared_ptr< CAFAnaModel > initCAFAnaModel(const std::string &modelSavedir)
Definition: LSTMEVar.h:41
caf::StandardRecord * sr
ResultCacher< LSTMEnergy > CAFAnaModel
Definition: LSTMEVar.h:15
static VarDict fillVarDict(const caf::SRProxy *sr, const std::vector< std::pair< std::string, Var >> &sliceVarDefs, const std::vector< std::pair< std::string, MultiVar >> &png2dVarDefs, const std::vector< std::pair< std::string, MultiVar >> &png3dVarDefs)
Definition: LSTMEVar.h:17
Definition: VarDict.h:7
SRTruthBranch mc
Truth branch for MC: energy, flavor, etc.
static Var totalEnergy(const std::shared_ptr< CAFAnaModel > &model)
Definition: LSTMEVar.h:77
short nallnus
Number of neutrinos in allnus vector.
Definition: SRTruthBranch.h:39
const XML_Char XML_Content * model
Definition: expat.h:151
std::unordered_map< std::string, double > scalarVarMap
Definition: VarDict.h:10
enum BeamMode string