LArSoft  v10_06_00
Liquid Argon Software toolkit - https://larsoft.org/
DecoderToolBase.h
Go to the documentation of this file.
1 #ifndef DECODERTOOLBASE_H
2 #define DECODERTOOLBASE_H
3 
7 
8 #include <string>
9 #include <utility>
10 #include <vector>
11 
12 using std::string;
13 using std::vector;
14 
15 struct NuGraphOutput {
16  NuGraphOutput(string s, vector<float> vf) : output_name(s), output_vec(std::move(vf)) {}
17  string output_name;
18  vector<float> output_vec;
19 };
20 
22 
23 public:
27  virtual ~DecoderToolBase() noexcept = default;
28 
35  : instancename{p.get<std::string>("instanceName", "filter")}
36  , outputname{p.get<std::string>("outputName", "x_filter_")}
37  {}
38 
44  virtual void declareProducts(art::ProducesCollector&) = 0;
45 
51  virtual void writeEmptyToEvent(art::Event& e, const vector<vector<size_t>>& idsmap) = 0;
52 
60  virtual void writeToEvent(art::Event& e,
61  const vector<vector<size_t>>& idsmap,
62  const vector<NuGraphOutput>& infer_output) = 0;
63 
64  // Function to print elements of a vector<float>
65  void printVector(const std::vector<float>& vec)
66  {
67  for (size_t i = 0; i < vec.size(); ++i) {
68  std::cout << vec[i];
69  // Print space unless it's the last element
70  if (i != vec.size() - 1) { std::cout << " "; }
71  }
72  std::cout << std::endl;
73  std::cout << std::endl;
74  }
75 
76  template <typename T, size_t N>
77  void softmax(std::array<T, N>& arr)
78  {
79  T m = -std::numeric_limits<T>::max();
80  for (size_t i = 0; i < arr.size(); i++) {
81  if (arr[i] > m) { m = arr[i]; }
82  }
83  T sum = 0.0;
84  for (size_t i = 0; i < arr.size(); i++) {
85  sum += expf(arr[i] - m);
86  }
87  T offset = m + logf(sum);
88  for (size_t i = 0; i < arr.size(); i++) {
89  arr[i] = expf(arr[i] - offset);
90  }
91  return;
92  }
93 
94  void setDebugAndPlanes(bool d, vector<std::string>& p)
95  {
96  debug = d;
97  planes = p;
98  }
99 
100 protected:
101  bool debug;
102  vector<std::string> planes;
103  std::string instancename;
104  std::string outputname;
105 };
106 
107 #endif
vector< std::string > planes
DecoderToolBase(fhicl::ParameterSet const &p)
Construcutor.
vector< float > output_vec
std::string outputname
STL namespace.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
DebugStuff debug
Definition: DebugStruct.cxx:4
T get(std::string const &key) const
Definition: ParameterSet.h:314
void setDebugAndPlanes(bool d, vector< std::string > &p)
Float_t d
Definition: plot.C:235
void printVector(const std::vector< float > &vec)
NuGraphOutput(string s, vector< float > vf)
std::string instancename
void softmax(std::array< T, N > &arr)
Double_t sum
Definition: plot.C:31
Float_t e
Definition: plot.C:35