CVNSparseMapper3D_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file CVNSparseMapper3D_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 #include "canvas/Persistency/Common/FindManyP.h"
23 
24 // LArSoft includes
26 
29 
30 namespace cvn {
31 
33  public:
34  explicit CVNSparseMapper3D(fhicl::ParameterSet const& pset);
36 
37  void produce(art::Event& evt);
38  void beginJob();
39  void endJob();
40 
41 
42 
43  private:
44  std::string fSPModuleLabel; ///< Module label for reconstructed spacepoints
45  std::string fPixelMapLabel; ///< Instance label for spacepoint pixelmaps
46  unsigned short fMinSP; ///< Minimum number of spacepoints to be converted to pixel map
47  PixelMapProducer fProducer; ///< PixelMapProducer does the heavy lifting
48 
49  };
50 
51 
52 
53  //.......................................................................
55  fSPModuleLabel(pset.get<std::string> ("SpacePointModuleLabel")),
56  fPixelMapLabel(pset.get<std::string> ("PixelMapLabel")),
57  fMinSP(pset.get<unsigned short> ("MinSP")),
58  fProducer()
59  {
60  produces< std::vector<cvn::SparsePixelMap> >(fPixelMapLabel);
61  }
62 
63  //......................................................................
65  {
66  //======================================================================
67  // Clean up any memory allocated by your module
68  //======================================================================
69  }
70 
71  //......................................................................
73  {}
74 
75  //......................................................................
77  {}
78 
79  //......................................................................
81  {
82  // Get spacepoints from art event record
83  std::vector< art::Ptr< recob::SpacePoint > > splist;
84  auto spListHandle = evt.getHandle< std::vector< recob::SpacePoint > >(fSPModuleLabel);
85  if (spListHandle)
86  art::fill_ptr_vector(splist, spListHandle);
87  unsigned short nsp = splist.size();
88 
89  // Get assocations from spacepoints to hits
90  art::FindManyP<recob::Hit> fmp(spListHandle, evt, fSPModuleLabel);
91  std::vector<std::vector<art::Ptr<recob::Hit>>> sp2Hit(nsp);
92  for (size_t spIdx = 0; spIdx < sp2Hit.size(); ++spIdx) {
93  sp2Hit[spIdx] = fmp.at(spIdx);
94  } // for spacepoint
95 
96  //Declaring containers for things to be stored in event
97  std::unique_ptr< std::vector<cvn::SparsePixelMap> >
98  pmCol(new std::vector<cvn::SparsePixelMap>);
99 
100  if (nsp > fMinSP) {
101  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
102  SparsePixelMap map = fProducer.CreateSparseMap3D(clockData, splist, sp2Hit);
103  pmCol->push_back(map);
104  mf::LogInfo("CVNSparseMapper3D") << "Created sparse pixel map from "
105  << nsp << " spacepoints and " << map.GetNPixels(0) << " hits.";
106  }
107 
108  evt.put(std::move(pmCol), fPixelMapLabel);
109  }
110 
111  //----------------------------------------------------------------------
112 
114 } // end namespace cvn
115 ////////////////////////////////////////////////////////////////////////
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
unsigned short fMinSP
Minimum number of spacepoints to be converted to pixel map.
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
Utility class for truth labels.
CVNSparseMapper3D(fhicl::ParameterSet const &pset)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
std::vector< unsigned int > GetNPixels() const
def move(depos, offset)
Definition: depos.py:107
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
PixelMapProducer for CVN.
PixelMapProducer fProducer
PixelMapProducer does the heavy lifting.
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
SparsePixelMap CreateSparseMap3D(detinfo::DetectorClocksData const &clockData, std::vector< art::Ptr< recob::SpacePoint > > &sp, std::vector< std::vector< art::Ptr< recob::Hit >>> &hit)
Producer algorithm for PixelMap, input to CVN neural net.
void produce(art::Event &evt)
std::string fPixelMapLabel
Instance label for spacepoint pixelmaps.
std::string fSPModuleLabel
Module label for reconstructed spacepoints.