All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HoughLineFinder_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // \file HoughLineFinder_module.cc
4 //
5 // \author kinga.partyka@yale.edu
6 //
7 ////////////////////////////////////////////////////////////////////////
8 ////////////////////////////////////////////////////////////////////////
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 // The algorithm is based on:
17 // Queisser, A. "Computing the Hough Transform", C/C++ Users Journal 21, 12 (Dec. 2003).
18 // Niblack, W. and Petkovic, D. On Improving the Accuracy of the Hough Transform", Machine
19 // Vision and Applications 3, 87 (1990)
20 ////////////////////////////////////////////////////////////////////////
21 
22 #include <iomanip>
23 #include <string>
24 
25 // art includes
26 #include "art/Framework/Core/EDProducer.h"
27 #include "art/Framework/Core/ModuleMacros.h"
28 #include "art/Framework/Principal/Event.h"
29 #include "art/Framework/Principal/Handle.h"
30 #include "art/Framework/Services/Registry/ServiceHandle.h"
31 #include "fhiclcpp/ParameterSet.h"
32 #include "messagefacility/MessageLogger/MessageLogger.h"
33 
34 // nurandom
35 #include "nurandom/RandomUtils/NuRandomService.h"
36 
37 // LArSoft includes
42 
43 namespace cluster {
44 
45  class HoughLineFinder : public art::EDProducer {
46  public:
47  explicit HoughLineFinder(fhicl::ParameterSet const& pset);
48 
49  private:
50  void produce(art::Event& evt) override;
51 
52  std::string fDBScanModuleLabel;
53  unsigned int fHoughSeed;
54  HoughBaseAlg fHLAlg; ///< object that does the Hough Transform
55  CLHEP::HepRandomEngine& fEngine;
56  };
57 
58  //------------------------------------------------------------------------------
59  HoughLineFinder::HoughLineFinder(fhicl::ParameterSet const& pset)
60  : EDProducer{pset}
61  , fDBScanModuleLabel{pset.get<std::string>("DBScanModuleLabel")}
62  , fHoughSeed{pset.get<unsigned int>("HoughSeed", 0)}
63  , fHLAlg(pset.get<fhicl::ParameterSet>("HoughBaseAlg"))
64  // Create random number engine needed for PPHT;
65  // obtain the random seed from NuRandomService,
66  // unless overridden in configuration with key "Seed"
67  // remember that HoughSeed will override this on each event if specified
68  , fEngine(art::ServiceHandle<rndm::NuRandomService> {}->createEngine(*this, pset, "Seed"))
69  {
70  produces<std::vector<recob::Cluster>>();
71  produces<art::Assns<recob::Cluster, recob::Hit>>();
72  }
73 
74  //------------------------------------------------------------------------------
75  void
77  {
78  //////////////////////////////////////////////////////
79  // here is how to get a collection of objects out of the file
80  // and connect it to a art::Handle
81  //////////////////////////////////////////////////////
82  auto const clusterListHandle =
83  evt.getValidHandle<std::vector<recob::Cluster>>(fDBScanModuleLabel);
84 
85  std::vector<art::Ptr<recob::Cluster>> clusIn;
86  clusIn.reserve(clusterListHandle->size());
87  for (unsigned int ii = 0; ii < clusterListHandle->size(); ++ii) {
88  clusIn.emplace_back(clusterListHandle, ii);
89  }
90 
91  //Point to a collection of clusters to output.
92  auto ccol = std::make_unique<std::vector<recob::Cluster>>();
93  auto assn = std::make_unique<art::Assns<recob::Cluster, recob::Hit>>();
94 
95  // make a std::vector< art::PtrVector<recob::Hit> >
96  // to hold the associated hits of the Hough Transform
97  std::vector<art::PtrVector<recob::Hit>> clusHitsOut;
98 
99  // If a nonzero random number seed has been provided,
100  // overwrite the seed already initialized
101  if (fHoughSeed != 0) { fEngine.setSeed(fHoughSeed, 0); }
102 
103  size_t const numclus =
104  fHLAlg.FastTransform(clusIn, *ccol, clusHitsOut, fEngine, evt, fDBScanModuleLabel);
105 
106  MF_LOG_DEBUG("HoughLineClusters") << "found " << numclus << "clusters with HoughBaseAlg";
107 
108  mf::LogVerbatim("Summary") << std::setfill('-') << std::setw(175) << "-" << std::setfill(' ');
109  mf::LogVerbatim("Summary") << "HoughLineFinder Summary:";
110  for (size_t i = 0; i < ccol->size(); ++i) {
111  mf::LogVerbatim("Summary") << ccol->at(i);
112 
113  // associate the hits to this cluster
114  util::CreateAssn(*this, evt, *ccol, clusHitsOut[i], *assn, i);
115  }
116 
117  evt.put(move(ccol));
118  evt.put(move(assn));
119  }
120 
121 } // end namespace
122 
123 DEFINE_ART_MODULE(cluster::HoughLineFinder)
process_name cluster
Definition: cheaterreco.fcl:51
Declaration of signal hit object.
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)
void produce(art::Event &evt) override
fEngine(art::ServiceHandle< rndm::NuRandomService >() ->createEngine(*this, pset,"Seed"))
Declaration of cluster object.
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.
HoughBaseAlg fHLAlg
object that does the Hough Transform
TCEvent evt
Definition: DataStructs.cxx:8
HoughLineFinder(fhicl::ParameterSet const &pset)
CLHEP::HepRandomEngine & fEngine