LArSoft  v10_06_00
Liquid Argon Software toolkit - https://larsoft.org/
FilterDecoder Class Reference
Inheritance diagram for FilterDecoder:
DecoderToolBase

Public Member Functions

 FilterDecoder (const fhicl::ParameterSet &pset)
 Constructor. More...
 
virtual ~FilterDecoder () noexcept=default
 Virtual Destructor. More...
 
void declareProducts (art::ProducesCollector &collector) override
 declareProducts function More...
 
void writeEmptyToEvent (art::Event &e, const vector< vector< size_t >> &idsmap) override
 writeEmptyToEvent function More...
 
void writeToEvent (art::Event &e, const vector< vector< size_t >> &idsmap, const vector< NuGraphOutput > &infer_output) override
 Decoder function. More...
 
void printVector (const std::vector< float > &vec)
 
template<typename T , size_t N>
void softmax (std::array< T, N > &arr)
 
void setDebugAndPlanes (bool d, vector< std::string > &p)
 

Protected Attributes

bool debug
 
vector< std::string > planes
 
std::string instancename
 
std::string outputname
 

Detailed Description

Definition at line 11 of file FilterDecoder_tool.cc.

Constructor & Destructor Documentation

FilterDecoder::FilterDecoder ( const fhicl::ParameterSet pset)

Constructor.

Parameters
pset

Definition at line 53 of file FilterDecoder_tool.cc.

virtual FilterDecoder::~FilterDecoder ( )
virtualdefaultnoexcept

Virtual Destructor.

Member Function Documentation

void FilterDecoder::declareProducts ( art::ProducesCollector collector)
inlineoverridevirtual

declareProducts function

Parameters
art::ProducesCollector

Implements DecoderToolBase.

Definition at line 31 of file FilterDecoder_tool.cc.

References e, DecoderToolBase::instancename, art::ProducesCollector::produces(), lar::dump::vector(), writeEmptyToEvent(), and writeToEvent().

32  {
33  collector.produces<vector<FeatureVector<1>>>(instancename);
34  }
void produces(std::string const &instanceName={}, Persistable const persistable=Persistable::Yes)
std::string instancename
void DecoderToolBase::printVector ( const std::vector< float > &  vec)
inlineinherited

Definition at line 65 of file DecoderToolBase.h.

Referenced by writeToEvent(), and SemanticDecoder::writeToEvent().

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  }
void DecoderToolBase::setDebugAndPlanes ( bool  d,
vector< std::string > &  p 
)
inlineinherited

Definition at line 94 of file DecoderToolBase.h.

References d, and tca::debug.

95  {
96  debug = d;
97  planes = p;
98  }
vector< std::string > planes
Float_t d
Definition: plot.C:235
template<typename T , size_t N>
void DecoderToolBase::softmax ( std::array< T, N > &  arr)
inlineinherited

Definition at line 77 of file DecoderToolBase.h.

References sum.

Referenced by SemanticDecoder::writeToEvent().

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  }
Double_t sum
Definition: plot.C:31
void FilterDecoder::writeEmptyToEvent ( art::Event e,
const vector< vector< size_t >> &  idsmap 
)
overridevirtual

writeEmptyToEvent function

Parameters
art::Eventevent record

Implements DecoderToolBase.

Definition at line 55 of file FilterDecoder_tool.cc.

References DecoderToolBase::instancename, art::Event::put(), and util::size().

Referenced by declareProducts().

56 {
57  //
58  size_t size = 0;
59  for (auto& v : idsmap)
60  size += v.size();
61  auto filtcol =
62  std::make_unique<vector<FeatureVector<1>>>(size, FeatureVector<1>(std::array<float, 1>({-1.})));
63  e.put(std::move(filtcol), instancename);
64  //
65 }
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
std::string instancename
void FilterDecoder::writeToEvent ( art::Event e,
const vector< vector< size_t >> &  idsmap,
const vector< NuGraphOutput > &  infer_output 
)
overridevirtual

Decoder function.

Parameters
art::Eventevent record for decoder

Implements DecoderToolBase.

Definition at line 67 of file FilterDecoder_tool.cc.

References DecoderToolBase::debug, DEFINE_ART_CLASS_TOOL, f, DecoderToolBase::instancename, DecoderToolBase::outputname, DecoderToolBase::planes, DecoderToolBase::printVector(), art::Event::put(), and util::size().

Referenced by declareProducts().

70 {
71  //
72  size_t size = 0;
73  for (auto& v : idsmap)
74  size += v.size();
75  auto filtcol =
76  std::make_unique<vector<FeatureVector<1>>>(size, FeatureVector<1>(std::array<float, 1>({-1.})));
77  //
78  for (size_t p = 0; p < planes.size(); p++) {
79  //
80  const std::vector<float>* x_filter_data = 0;
81  for (auto& io : infer_output) {
82  if (io.output_name == outputname + planes[p]) x_filter_data = &io.output_vec;
83  }
84  if (debug) {
85  std::cout << outputname + planes[p] << std::endl;
86  printVector(*x_filter_data);
87  }
88  //
89  torch::TensorOptions options = torch::TensorOptions().dtype(torch::kFloat32);
90  int64_t num_elements = x_filter_data->size();
91  const torch::Tensor f =
92  torch::from_blob(const_cast<float*>(x_filter_data->data()), {num_elements}, options);
93  //
94  for (int i = 0; i < f.numel(); ++i) {
95  size_t idx = idsmap[p][i];
96  std::array<float, 1> input({f[i].item<float>()});
97  (*filtcol)[idx] = FeatureVector<1>(input);
98  }
99  }
100  e.put(std::move(filtcol), instancename);
101 }
vector< std::string > planes
std::string outputname
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
TFile f
Definition: plotHisto.C:6
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
void printVector(const std::vector< float > &vec)
std::string instancename

Member Data Documentation

bool DecoderToolBase::debug
protectedinherited
std::string DecoderToolBase::outputname
protectedinherited

Definition at line 104 of file DecoderToolBase.h.

Referenced by writeToEvent(), and SemanticDecoder::writeToEvent().

vector<std::string> DecoderToolBase::planes
protectedinherited

Definition at line 102 of file DecoderToolBase.h.

Referenced by writeToEvent(), and SemanticDecoder::writeToEvent().


The documentation for this class was generated from the following file: