LArSoft  v10_04_05
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 9 of file FilterDecoder_tool.cc.

Constructor & Destructor Documentation

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

Constructor.

Parameters
pset

Definition at line 51 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 29 of file FilterDecoder_tool.cc.

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

30  {
31  collector.produces<vector<FeatureVector<1>>>(instancename);
32  }
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 69 of file DecoderToolBase.h.

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

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

Definition at line 98 of file DecoderToolBase.h.

References d, and tca::debug.

99  {
100  debug = d;
101  planes = p;
102  }
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 81 of file DecoderToolBase.h.

References sum.

Referenced by SemanticDecoder::writeToEvent().

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  }
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 53 of file FilterDecoder_tool.cc.

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

Referenced by declareProducts().

54 {
55  //
56  size_t size = 0;
57  for (auto& v : idsmap)
58  size += v.size();
59  auto filtcol =
60  std::make_unique<vector<FeatureVector<1>>>(size, FeatureVector<1>(std::array<float, 1>({-1.})));
61  e.put(std::move(filtcol), instancename);
62  //
63 }
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 65 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().

68 {
69  //
70  size_t size = 0;
71  for (auto& v : idsmap)
72  size += v.size();
73  auto filtcol =
74  std::make_unique<vector<FeatureVector<1>>>(size, FeatureVector<1>(std::array<float, 1>({-1.})));
75  //
76  for (size_t p = 0; p < planes.size(); p++) {
77  //
78  const std::vector<float>* x_filter_data = 0;
79  for (auto& io : infer_output) {
80  if (io.output_name == outputname + planes[p]) x_filter_data = &io.output_vec;
81  }
82  if (debug) {
83  std::cout << outputname + planes[p] << std::endl;
84  printVector(*x_filter_data);
85  }
86  //
87  torch::TensorOptions options = torch::TensorOptions().dtype(torch::kFloat32);
88  int64_t num_elements = x_filter_data->size();
89  const torch::Tensor f =
90  torch::from_blob(const_cast<float*>(x_filter_data->data()), {num_elements}, options);
91  //
92  for (int i = 0; i < f.numel(); ++i) {
93  size_t idx = idsmap[p][i];
94  std::array<float, 1> input({f[i].item<float>()});
95  (*filtcol)[idx] = FeatureVector<1>(input);
96  }
97  }
98  e.put(std::move(filtcol), instancename);
99 }
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 108 of file DecoderToolBase.h.

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

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

Definition at line 106 of file DecoderToolBase.h.

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


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