LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
HoughLineFinder_module.cc
Go to the documentation of this file.
1 //
3 // \file HoughLineFinder_module.cc
4 //
5 // \author kinga.partyka@yale.edu
6 //
9 //
10 // \file HoughLineFinder.cxx
11 //
12 // \author joshua.spitz@yale.edu
13 //
14 // This algorithm is designed to find lines (Houghclusters) from clusters found by DBSCAN
15 // after deconvolution and hit finding.
16 //
17 // The algorithm is based on:
18 // Queisser, A. "Computing the Hough Transform", C/C++ Users Journal 21, 12 (Dec. 2003).
19 // Niblack, W. and Petkovic, D. On Improving the Accuracy of the Hough Transform", Machine
20 // Vision and Applications 3, 87 (1990)
22 
23 #include <iomanip>
24 #include <string>
25 
26 // art includes
32 #include "fhiclcpp/ParameterSet.h"
34 
35 // nurandom
37 
38 // LArSoft includes
43 
44 namespace cluster {
45 
47  public:
48  explicit HoughLineFinder(fhicl::ParameterSet const& pset);
49 
50  private:
51  void produce(art::Event& evt) override;
52 
53  std::string fDBScanModuleLabel;
54  unsigned int fHoughSeed;
56  CLHEP::HepRandomEngine& fEngine;
57  };
58 
59  //------------------------------------------------------------------------------
61  : EDProducer{pset}
62  , fDBScanModuleLabel{pset.get<std::string>("DBScanModuleLabel")}
63  , fHoughSeed{pset.get<unsigned int>("HoughSeed", 0)}
64  , fHLAlg(pset.get<fhicl::ParameterSet>("HoughBaseAlg"))
65  // Create random number engine needed for PPHT; obtain the random seed from
66  // NuRandomService, unless overridden in configuration with key "Seed" remember that
67  // HoughSeed will override this on each event if specified
69  pset,
70  "Seed"))
71  {
72  produces<std::vector<recob::Cluster>>();
73  produces<art::Assns<recob::Cluster, recob::Hit>>();
74  }
75 
76  //------------------------------------------------------------------------------
78  {
80  // here is how to get a collection of objects out of the file
81  // and connect it to a art::Handle
83  auto const clusterListHandle =
84  evt.getValidHandle<std::vector<recob::Cluster>>(fDBScanModuleLabel);
85 
86  std::vector<art::Ptr<recob::Cluster>> clusIn;
87  clusIn.reserve(clusterListHandle->size());
88  for (unsigned int ii = 0; ii < clusterListHandle->size(); ++ii) {
89  clusIn.emplace_back(clusterListHandle, ii);
90  }
91 
92  //Point to a collection of clusters to output.
93  auto ccol = std::make_unique<std::vector<recob::Cluster>>();
94  auto assn = std::make_unique<art::Assns<recob::Cluster, recob::Hit>>();
95 
96  // make a std::vector< art::PtrVector<recob::Hit> >
97  // to hold the associated hits of the Hough Transform
98  std::vector<art::PtrVector<recob::Hit>> clusHitsOut;
99 
100  // If a nonzero random number seed has been provided,
101  // overwrite the seed already initialized
102  if (fHoughSeed != 0) { fEngine.setSeed(fHoughSeed, 0); }
103 
104  size_t const numclus =
105  fHLAlg.FastTransform(clusIn, *ccol, clusHitsOut, fEngine, evt, fDBScanModuleLabel);
106 
107  MF_LOG_DEBUG("HoughLineClusters") << "found " << numclus << "clusters with HoughBaseAlg";
108 
109  mf::LogVerbatim("Summary") << std::setfill('-') << std::setw(175) << "-" << std::setfill(' ');
110  mf::LogVerbatim("Summary") << "HoughLineFinder Summary:";
111  for (size_t i = 0; i < ccol->size(); ++i) {
112  mf::LogVerbatim("Summary") << ccol->at(i);
113 
114  // associate the hits to this cluster
115  util::CreateAssn(evt, *ccol, clusHitsOut[i], *assn, i);
116  }
117 
118  evt.put(move(ccol));
119  evt.put(move(assn));
120  }
121 
122 } // end namespace
123 
base_engine_t & createEngine(seed_t seed)
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
Declaration of signal hit object.
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
size_t FastTransform(const std::vector< art::Ptr< recob::Cluster >> &clusIn, std::vector< recob::Cluster > &ccol, std::vector< art::PtrVector< recob::Hit >> &clusHitsOut, CLHEP::HepRandomEngine &engine, art::Event const &evt, std::string const &label)
Cluster finding and building.
void produce(art::Event &evt) override
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
Declaration of cluster object.
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Utility object to perform functions of association.
HoughBaseAlg fHLAlg
object that does the Hough Transform
#define MF_LOG_DEBUG(id)
TCEvent evt
Definition: DataStructs.cxx:8
HoughLineFinder(fhicl::ParameterSet const &pset)
CLHEP::HepRandomEngine & fEngine