VLNEnergyDataGen_module.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 
6 
12 
13 #include "utils.h"
14 
15 namespace VLN {
16 
18 {
19 public:
20  explicit VLNEnergyDataGen(const fhicl::ParameterSet &pset);
21 
22  void analyze(const art::Event &evt) override;
23  void respondToOpenInputFile(const art::FileBlock &fb) override;
24 
25 protected:
26  bool passesCut(const art::Event &evt, const VarDict &vars);
27 
28 private:
31 
33  int isCC;
34  double maxEnergy;
35  int precision;
36 
41 
43  std::unique_ptr<CSVExporter> exporter;
44 };
45 
47  : EDAnalyzer(pset),
48  applyFiducialCut(pset.get<bool>("ApplyFiducialCut")),
49  isCC(pset.get<int>("IsCC")),
50  maxEnergy(pset.get<double>("MaxEnergy")),
51  precision(pset.get<int>("OutputPrecision")),
52  inputVarExtractor("", pset.get<fhicl::ParameterSet>("ConfigInputVars")),
54  pset.get<std::string>("Flavor") + "e.",
55  pset.get<std::string>("LabelRecoE")
56  ),
57  truthVarExtractor("mc.", pset.get<std::string>("LabelGenerator")),
59  "mc.",
60  pset.get<fhicl::ParameterSet>("ConfigFiducialCut"),
61  pset.get<std::string>("LabelGenerator")
62  )
63 {
64  flavor = parseFlavor(pset.get<std::string>("Flavor"));
65  format = parseFormat(pset.get<std::string>("OutputFormat"));
66 }
67 
69 {
70  const std::string filename = convertFilename(fb.fileName(), "./", format);
71 
72  switch (format) {
73  case Format::CSV:
74  exporter = std::make_unique<CSVExporter>(filename);
75  exporter->setPrecision(precision);
76  break;
77  }
78 }
79 
81 {
82  if (
83  (flavor != Flavor::Any)
84  && (std::abs(vars.scalar.at("mc.pdg")) != static_cast<int>(flavor))
85  ) {
86  return false;
87  }
88 
89  if ((isCC >= 0) && (vars.scalar.at("mc.isCC") != isCC)) {
90  return false;
91  }
92 
93  if (applyFiducialCut && (vars.scalar.at("mc.vtxContain") != 1)) {
94  return false;
95  }
96 
97  if ((maxEnergy > 0) && (vars.scalar.at("mc.nuE") > maxEnergy)) {
98  return false;
99  }
100 
101  /* TODO: find proper way to check containment for non numu events */
102  if (
103  (flavor == Flavor::NuMu)
104  && (vars.scalar.at("numue.longestTrackContained") != 1)
105  ) {
106  return false;
107  }
108 
109  return true;
110 }
111 
113 {
117 
118  if (! passesCut(evt, vars)) {
119  return;
120  }
121 
123 
124  exporter->exportVars(vars);
125 }
126 
128 
129 }
130 
Format
Definition: utils.h:7
Format parseFormat(const std::string &formatStr)
Definition: utils.cxx:24
std::string string
Definition: nybbler.cc:12
EventRecoEVarExtractor recoEVarExtractor
void respondToOpenInputFile(const art::FileBlock &fb) override
STL namespace.
DefaultInputVarExtractor inputVarExtractor
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
string filename
Definition: train.py:213
Definition: VarDict.h:8
virtual void extract(const art::Event &evt, VarDict &vars)
VLNEnergyDataGen(const fhicl::ParameterSet &pset)
T abs(T value)
void analyze(const art::Event &evt) override
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
Flavor
Definition: utils.h:6
std::string convertFilename(const std::string &path, const std::string &root, Format format)
Definition: utils.cxx:35
T get(std::string const &key) const
Definition: ParameterSet.h:271
FiducialCutVarExtractor fiducialCutVarExtractor
std::string const & fileName() const
Definition: FileBlock.cc:29
Definition: utils.cxx:6
bool passesCut(const art::Event &evt, const VarDict &vars)
std::unique_ptr< CSVExporter > exporter
Flavor parseFlavor(const std::string &flavStr)
Definition: utils.cxx:8
EventMCVarExtractor truthVarExtractor
TCEvent evt
Definition: DataStructs.cxx:7
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
int bool
Definition: qglobal.h:345
std::unordered_map< std::string, double > scalar
Definition: VarDict.h:10