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
31 #include "fhiclcpp/ParameterSet.h"
33 
34 // nurandom
35 #include "nurandom/RandomUtils/NuRandomService.h"
36 
37 // LArSoft includes
42 
43 namespace cluster {
44 
46  public:
47  explicit HoughLineFinder(fhicl::ParameterSet const& pset);
48 
49  private:
50  void produce(art::Event& evt) override;
51 
53  unsigned int fHoughSeed;
54  HoughBaseAlg fHLAlg; ///< object that does the Hough Transform
55  CLHEP::HepRandomEngine& fEngine;
56  };
57 
58  //------------------------------------------------------------------------------
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 
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
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
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
def move(depos, offset)
Definition: depos.py:107
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
Declaration of signal hit object.
HoughBaseAlg fHLAlg
object that does the Hough Transform
#define MF_LOG_DEBUG(id)
TCEvent evt
Definition: DataStructs.cxx:7
HoughLineFinder(fhicl::ParameterSet const &pset)
Q_EXPORT QTSManip setfill(int f)
Definition: qtextstream.h:337
CLHEP::HepRandomEngine & fEngine