SliceLIDVar.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "CAFAna/Core/Var.h"
4 #include "CAFAna/Core/MultiVar.h"
5 
7 
9 #include "TensorFlowEvaluator/SliceLID/cafana/ResultCacher.hxx"
11 
12 namespace SliceLID
13 {
14 
15 using namespace ana;
16 using CAFAnaModel = ResultCacher<Prediction>;
17 
19  const caf::SRProxy *sr,
20  const std::vector<std::pair<std::string, Var>> &sliceVarDefs,
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 : png3dVarDefs) {
31  result.vectorVarMap[namedMultiVar.first] = namedMultiVar.second(sr);
32  }
33 
34  return result;
35 }
36 
37 static std::shared_ptr<CAFAnaModel> initCAFAnaModel(
38  const std::string &modelSavedir
39 )
40 {
41  auto model = std::make_shared<Model>(modelSavedir);
42 
43  return std::make_shared<CAFAnaModel>(
44  [
45  model = std::move(model),
46  trkLenCorr = TrackLengthCorrection()
47  ] (const caf::SRProxy *sr) mutable -> Prediction
48  {
49  auto varDict = fillVarDict(
51  );
52 
53  /* TODO: remove air bubble correction once geometry is fixed */
54  bool isMC = (sr->mc.nallnus > 0) || (sr->mc.nallcosmics > 0);
55  trkLenCorr.setParams(isMC, (sr->hdr.det == caf::kFARDET));
56  trkLenCorr.shift(varDict);
57 
58  return model->predict(varDict);
59  }
60  );
61 }
62 
63 static Var numuid(const std::shared_ptr<CAFAnaModel> &model)
64 {
65  return Var(
66  [model] (const caf::SRProxy *sr) -> double
67  {
68  return (*model)(sr).numu;
69  }
70  );
71 }
72 
73 static Var ncid(const std::shared_ptr<CAFAnaModel> &model)
74 {
75  return Var(
76  [model] (const caf::SRProxy *sr) -> double
77  {
78  return (*model)(sr).nc;
79  }
80  );
81 }
82 
83 static Var nueid(const std::shared_ptr<CAFAnaModel> &model)
84 {
85  return Var(
86  [model] (const caf::SRProxy *sr) -> double
87  {
88  return (*model)(sr).nue;
89  }
90  );
91 }
92 
93 static Var nutauid(const std::shared_ptr<CAFAnaModel> &model)
94 {
95  return Var(
96  [model] (const caf::SRProxy *sr) -> double
97  {
98  return (*model)(sr).nutau;
99  }
100  );
101 }
102 
103 static Var cosmicid(const std::shared_ptr<CAFAnaModel> &model)
104 {
105  return Var(
106  [model] (const caf::SRProxy *sr) -> double
107  {
108  return (*model)(sr).cosmic;
109  }
110  );
111 }
112 
113 }
114 
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
static Var numuid(const std::shared_ptr< CAFAnaModel > &model)
Definition: SliceLIDVar.h:63
ResultCacher< Prediction > CAFAnaModel
Definition: SliceLIDVar.h:16
static Var cosmicid(const std::shared_ptr< CAFAnaModel > &model)
Definition: SliceLIDVar.h:103
short nallcosmics
Number of cosmics in allcosmics vector.
Definition: SRTruthBranch.h:40
Sum up livetimes from individual cosmic triggers.
static Var nutauid(const std::shared_ptr< CAFAnaModel > &model)
Definition: SliceLIDVar.h:93
static Var nueid(const std::shared_ptr< CAFAnaModel > &model)
Definition: SliceLIDVar.h:83
_Var< caf::SRProxy > Var
Definition: Var.h:7
static Var ncid(const std::shared_ptr< CAFAnaModel > &model)
Definition: SliceLIDVar.h:73
caf::StandardRecord * sr
const std::vector< std::pair< std::string, Var > > kSliceLIDSliceVarDefs
static VarDict fillVarDict(const caf::SRProxy *sr, const std::vector< std::pair< std::string, Var >> &sliceVarDefs, const std::vector< std::pair< std::string, MultiVar >> &png3dVarDefs)
Definition: SliceLIDVar.h:18
enum BeamMode nc
Definition: VarDict.h:7
SRTruthBranch mc
Truth branch for MC: energy, flavor, etc.
const std::vector< std::pair< std::string, MultiVar > > kSliceLIDPng3dVarDefs
short nallnus
Number of neutrinos in allnus vector.
Definition: SRTruthBranch.h:39
const XML_Char XML_Content * model
Definition: expat.h:151
static std::shared_ptr< CAFAnaModel > initCAFAnaModel(const std::string &modelSavedir)
Definition: SliceLIDVar.h:37
std::unordered_map< std::string, double > scalarVarMap
Definition: VarDict.h:10
enum BeamMode string