CVNSparseMapper_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file CVNSparseMapper_module.cc
3 // \brief Producer module for creating CVN SparsePixelMap objects
4 // \author Jeremy Hewes - jhewes15@fnal.gov
5 ////////////////////////////////////////////////////////////////////////
6 
7 // C/C++ includes
8 #include <iostream>
9 #include <sstream>
10 
11 // Framework includes
15 #include "art_root_io/TFileDirectory.h"
16 #include "art_root_io/TFileService.h"
18 #include "fhiclcpp/ParameterSet.h"
22 
23 // LArSoft includes
25 
28 
29 namespace cvn {
30 
32  public:
33  explicit CVNSparseMapper(fhicl::ParameterSet const& pset);
35 
36  void produce(art::Event& evt);
37  void beginJob();
38  void endJob();
39 
40 
41 
42  private:
43  std::string fHitsModuleLabel; ///< Module label for input clusters
44  std::string fClusterPMLabel; ///< Instance label for cluster pixelmaps
45  unsigned short fMinClusterHits; ///< Minimum number of hits for cluster to be converted to pixel map
46  bool fIncludePixelTruth; ///< Whether to include per-pixel ground truth for segmentation
47  PixelMapProducer fProducer; ///< PixelMapProducer does the heavy lifting
48 
49  };
50 
51 
52 
53  //.......................................................................
55  fHitsModuleLabel(pset.get<std::string> ("HitsModuleLabel")),
56  fClusterPMLabel(pset.get<std::string> ("ClusterPMLabel")),
57  fMinClusterHits(pset.get<unsigned short> ("MinClusterHits")),
58  fIncludePixelTruth(pset.get<bool> ("IncludePixelTruth")),
59  fProducer()
60  {
61 
62  produces< std::vector<cvn::SparsePixelMap> >(fClusterPMLabel);
63 
64  }
65 
66  //......................................................................
68  {
69  //======================================================================
70  // Clean up any memory allocated by your module
71  //======================================================================
72  }
73 
74  //......................................................................
76  {}
77 
78  //......................................................................
80  {}
81 
82  //......................................................................
84  {
85  std::vector< art::Ptr< recob::Hit > > hitlist;
86  auto hitListHandle = evt.getHandle< std::vector< recob::Hit > >(fHitsModuleLabel);
87  if (hitListHandle)
88  art::fill_ptr_vector(hitlist, hitListHandle);
89  unsigned short nhits = hitlist.size();
90 
91  //Declaring containers for things to be stored in event
92  std::unique_ptr< std::vector<cvn::SparsePixelMap> >
93  pmCol(new std::vector<cvn::SparsePixelMap>);
94 
95  if (nhits > fMinClusterHits) {
96  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
97  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clockData);
98  SparsePixelMap map = fProducer.CreateSparseMap2D(clockData, detProp, hitlist, fIncludePixelTruth);
99  mf::LogInfo("CVNSparseMapper") << "Created sparse pixel map with "
100  << map.GetNPixels(0) << ", " << map.GetNPixels(1) << ", "
101  << map.GetNPixels(2) << " pixels.";
102  pmCol->push_back(map);
103  }
104 
105  evt.put(std::move(pmCol), fClusterPMLabel);
106  }
107 
108  //----------------------------------------------------------------------
109 
111 } // end namespace cvn
112 ////////////////////////////////////////////////////////////////////////
unsigned short fMinClusterHits
Minimum number of hits for cluster to be converted to pixel map.
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
Utility class for truth labels.
void produce(art::Event &evt)
CVNSparseMapper(fhicl::ParameterSet const &pset)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
std::vector< unsigned int > GetNPixels() const
std::string fClusterPMLabel
Instance label for cluster pixelmaps.
def move(depos, offset)
Definition: depos.py:107
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
PixelMapProducer fProducer
PixelMapProducer does the heavy lifting.
Declaration of signal hit object.
SparsePixelMap CreateSparseMap2D(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit > > &cluster, bool usePixelTruth=false)
std::string fHitsModuleLabel
Module label for input clusters.
PixelMapProducer for CVN.
Sparse pixel map for CVN.
TCEvent evt
Definition: DataStructs.cxx:7
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
Producer algorithm for PixelMap, input to CVN neural net.
bool fIncludePixelTruth
Whether to include per-pixel ground truth for segmentation.