LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
LArCVNEvaluator_module.cc
Go to the documentation of this file.
1 // \file LArCVNEvaluator_module.cc
3 // \brief Producer module creating CVN neural net results
4 // \author Alexander Radovic - a.radovic@gmail.com
5 // Saul Alonso Monsalve - saul.alonso.monsalve@cern.ch
7 
8 // C/C++ includes
9 #include <iostream>
10 #include <sstream>
11 
12 // Framework includes
19 #include "art_root_io/TFileDirectory.h"
20 #include "art_root_io/TFileService.h"
22 #include "fhiclcpp/ParameterSet.h"
24 
30 
31 namespace lcvn {
32 
34  public:
35  explicit LArCVNEvaluator(fhicl::ParameterSet const& pset);
36 
37  void produce(art::Event& evt);
38 
39  private:
41  std::string fPixelMapInput;
42  std::string fResultLabel;
43 
45  std::string fCVNType;
46 
47  //lcvn::CaffeNetHandler fCaffeHandler;
48  std::unique_ptr<lcvn::ITFNetHandler> fTFHandler;
49 
51  //unsigned int fNOutput;
52 
55  };
56 
57  //.......................................................................
59  : EDProducer{pset}
60  , fPixelMapInput(pset.get<std::string>("PixelMapInput"))
61  , fResultLabel(pset.get<std::string>("ResultLabel"))
62  , fCVNType(pset.get<std::string>("CVNType"))
63  ,
64  //fCaffeHandler (pset.get<fhicl::ParameterSet> ("CaffeNetHandler")),
65  fTFHandler{art::make_tool<ITFNetHandler>(pset.get<fhicl::ParameterSet>("TFHandler"))}
66  ,
67  //fNOutput (fCaffeHandler.NOutput()),
68  fMultiplePMs(pset.get<bool>("MultiplePMs"))
69  {
70  produces<std::vector<lcvn::Result>>(fResultLabel);
71  }
72  //......................................................................
74  {
75 
77  std::unique_ptr<std::vector<Result>> resultCol(new std::vector<Result>);
78 
80  std::vector<art::Ptr<lcvn::PixelMap>> pixelmaplist;
82  auto pixelmapListHandle = evt.getHandle<std::vector<lcvn::PixelMap>>(itag1);
83  if (pixelmapListHandle) art::fill_ptr_vector(pixelmaplist, pixelmapListHandle);
84 
85  if (fCVNType == "TF" || fCVNType == "Tensorflow" || fCVNType == "TensorFlow") {
86 
87  // If we have a pixel map then use the TF interface to give us a prediction
88  if (pixelmaplist.size() > 0) {
89 
90  std::vector<std::vector<float>> networkOutput = fTFHandler->Predict(*pixelmaplist[0]);
91  // lcvn::Result can now take a vector of floats and works out the number of outputs
92  resultCol->emplace_back(networkOutput);
93 
94  // Classify other pixel maps if they exist
95  if (fMultiplePMs) {
96  for (unsigned int p = 1; p < pixelmaplist.size(); ++p) {
97  std::vector<std::vector<float>> output = fTFHandler->Predict(*pixelmaplist[p]);
98  resultCol->emplace_back(output);
99  }
100  }
101  }
102  }
103  else {
104  mf::LogError("LArCVNEvaluator::produce")
105  << "CVN Type not in the allowed list: Tensorflow" << std::endl;
106  mf::LogError("LArCVNEvaluator::produce") << "Exiting without processing events" << std::endl;
107  return;
108  }
109 
110  evt.put(std::move(resultCol), fResultLabel);
111  }
112 
114 } // end namespace cvn
void produce(art::Event &evt)
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
LArCVNEvaluator(fhicl::ParameterSet const &pset)
std::string fPixelMapInput
Module label for input pixel maps.
Utility class for truth labels.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
PixelMap for CVN.
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
Result for CVN.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
std::string fCVNType
Can use Caffe or Tensorflow.
bool fMultiplePMs
Number of outputs fron neural net.
Handle< PROD > getHandle(SelectorBase const &) const
std::unique_ptr< lcvn::ITFNetHandler > fTFHandler
TCEvent evt
Definition: DataStructs.cxx:8
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:306