LArSoft  v10_04_05
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 
4 // art TOOL
7 
10 #include "fhiclcpp/ParameterSet.h"
11 
12 #include <string>
13 #include <utility>
14 #include <vector>
15 
16 using std::string;
17 using std::vector;
18 
19 struct NuGraphOutput {
20  NuGraphOutput(string s, vector<float> vf) : output_name(s), output_vec(std::move(vf)) {}
21  string output_name;
22  vector<float> output_vec;
23 };
24 
26 
27 public:
31  virtual ~DecoderToolBase() noexcept = default;
32 
39  : instancename{p.get<std::string>("instanceName", "filter")}
40  , outputname{p.get<std::string>("outputName", "x_filter_")}
41  {}
42 
48  virtual void declareProducts(art::ProducesCollector&) = 0;
49 
55  virtual void writeEmptyToEvent(art::Event& e, const vector<vector<size_t>>& idsmap) = 0;
56 
64  virtual void writeToEvent(art::Event& e,
65  const vector<vector<size_t>>& idsmap,
66  const vector<NuGraphOutput>& infer_output) = 0;
67 
68  // Function to print elements of a vector<float>
69  void printVector(const std::vector<float>& vec)
70  {
71  for (size_t i = 0; i < vec.size(); ++i) {
72  std::cout << vec[i];
73  // Print space unless it's the last element
74  if (i != vec.size() - 1) { std::cout << " "; }
75  }
76  std::cout << std::endl;
77  std::cout << std::endl;
78  }
79 
80  template <typename T, size_t N>
81  void softmax(std::array<T, N>& arr)
82  {
83  T m = -std::numeric_limits<T>::max();
84  for (size_t i = 0; i < arr.size(); i++) {
85  if (arr[i] > m) { m = arr[i]; }
86  }
87  T sum = 0.0;
88  for (size_t i = 0; i < arr.size(); i++) {
89  sum += expf(arr[i] - m);
90  }
91  T offset = m + logf(sum);
92  for (size_t i = 0; i < arr.size(); i++) {
93  arr[i] = expf(arr[i] - offset);
94  }
95  return;
96  }
97 
98  void setDebugAndPlanes(bool d, vector<std::string>& p)
99  {
100  debug = d;
101  planes = p;
102  }
103 
104 protected:
105  bool debug;
106  vector<std::string> planes;
107  std::string instancename;
108  std::string outputname;
109 };
110 
111 #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