LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 // 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)
21 
22 extern "C" {
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 }
26 #include <sstream>
27 #include <fstream>
28 #include <math.h>
29 #include <algorithm>
30 #include <vector>
31 #include <vector>
32 #include <string>
33 #include <iomanip>
34 
35 // ROOT includes
36 #include <TCanvas.h>
37 #include "TDatabasePDG.h"
38 #include "TSystem.h"
39 #include "TMath.h"
40 
41 // ART includes
44 #include "fhiclcpp/ParameterSet.h"
50 #include "CLHEP/Random/JamesRandom.h"
51 
52 // art extensions
54 
55 // LArSoft includes
62 
63 //#ifndef CLUSTER_HOUGHLINEFINDER_H
64 //#define CLUSTER_HOUGHLINEFINDER_H
65 
66 
67 class TH1F;
68 class TTree;
69 
70 namespace cluster {
71 
73 
74  public:
75 
76  explicit HoughLineFinder(fhicl::ParameterSet const& pset);
77  virtual ~HoughLineFinder();
78 
79  void reconfigure(fhicl::ParameterSet const& p);
80 
81  void produce(art::Event& evt);
82 
83 
84  private:
85 
86  std::string fDBScanModuleLabel;
87  unsigned int fHoughSeed;
88 
90 
91  };
92 
93 
94 }
95 
96 //#endif // CLUSTER_HOUGHLINEFINDER_H
97 
98 
99 namespace cluster {
100 
101 
102  //------------------------------------------------------------------------------
104  : fHLAlg(pset.get< fhicl::ParameterSet >("HoughBaseAlg"))
105  {
106  this->reconfigure(pset);
107  produces< std::vector<recob::Cluster> >();
108  produces< art::Assns<recob::Cluster, recob::Hit> >();
109 
110  // Create random number engine needed for PPHT;
111  // obtain the random seed from NuRandomService,
112  // unless overridden in configuration with key "Seed"
113  // remember that HoughSeed will override this on each event if specified
115  ->createEngine(*this, pset, "Seed");
116  }
117 
118  //------------------------------------------------------------------------------
120  {
121  }
122 
123  //------------------------------------------------------------------------------
125  {
126  fDBScanModuleLabel = p.get< std::string >("DBScanModuleLabel");
127  fHoughSeed = p.get< unsigned int >("HoughSeed", 0);
128  fHLAlg.reconfigure(p.get< fhicl::ParameterSet >("HoughBaseAlg"));
129  }
130 
131  //------------------------------------------------------------------------------
133  {
134 
136  // here is how to get a collection of objects out of the file
137  // and connect it to a art::Handle
139  // Read in the clusterList object(s).
140  art::Handle< std::vector<recob::Cluster> > clusterListHandle;
141  evt.getByLabel(fDBScanModuleLabel,clusterListHandle);
142 
143  //art::PtrVector<recob::Cluster> clusIn;
144  std::vector<art::Ptr<recob::Cluster> > clusIn;
145  for(unsigned int ii = 0; ii < clusterListHandle->size(); ++ii){
146  art::Ptr<recob::Cluster> cluster(clusterListHandle, ii);
147  clusIn.push_back(cluster);
148  }
149 
150  //Point to a collection of clusters to output.
151  std::unique_ptr<std::vector<recob::Cluster> > ccol(new std::vector<recob::Cluster>);
152  std::unique_ptr< art::Assns<recob::Cluster, recob::Hit> > assn(new art::Assns<recob::Cluster, recob::Hit>);
153 
154  // make a std::vector< art::PtrVector<recob::Hit> >
155  // to hold the associated hits of the Hough Transform
156  std::vector< art::PtrVector<recob::Hit> > clusHitsOut;
157 
158  size_t numclus = 0;
159 
160 
161  // If a nonzero random number seed has been provided,
162  // overwrite the seed already initialized
163  if(fHoughSeed != 0){
165  CLHEP::HepRandomEngine &engine = rng->getEngine();
166  engine.setSeed(fHoughSeed,0);
167  }
168 
169  numclus = fHLAlg.FastTransform(clusIn, *ccol, clusHitsOut, evt, fDBScanModuleLabel);
170 
171 
172  //size_t Transform(std::vector<art::Ptr<recob::Cluster> > & clusIn,
173  //std::vector<recob::Cluster> & ccol,
174  //std::vector< art::PtrVector<recob::Hit> > & clusHitsOut,
175  //art::Event const& evt,
176  //std::string const& label);
177 
178  LOG_DEBUG("HoughLineClusters") << "found " << numclus << "clusters with HoughBaseAlg";
179 
180 
181  mf::LogVerbatim("Summary") << std::setfill('-') << std::setw(175) << "-" << std::setfill(' ');
182  mf::LogVerbatim("Summary") << "HoughLineFinder Summary:";
183  for(size_t i = 0; i < ccol->size(); ++i){
184  mf::LogVerbatim("Summary") << ccol->at(i);
185 
186  // associat the hits to this cluster
187  util::CreateAssn(*this, evt, *(ccol.get()), clusHitsOut[i], *(assn.get()), i);
188  }
189 
190  evt.put(std::move(ccol));
191  evt.put(std::move(assn));
192  return;
193  }
194 
195 
196 
197 
198 
199 
200 } // end namespace
201 
202 namespace cluster{
203 
205 
206 }
207 
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
virtual void reconfigure(fhicl::ParameterSet const &pset)
size_t FastTransform(const std::vector< art::Ptr< recob::Cluster > > &clusIn, std::vector< recob::Cluster > &ccol, std::vector< art::PtrVector< recob::Hit > > &clusHitsOut, art::Event const &evt, std::string const &label)
Declaration of signal hit object.
Definition of basic raw digits.
Cluster finding and building.
void reconfigure(fhicl::ParameterSet const &p)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
base_engine_t & getEngine() const
base_engine_t & createEngine(seed_t seed)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
parameter set interface
T get(std::string const &key) const
Definition: ParameterSet.h:231
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.
Declaration of cluster object.
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
Utility object to perform functions of association.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
HoughBaseAlg fHLAlg
object that does the Hough Transform
#define LOG_DEBUG(id)
HoughLineFinder(fhicl::ParameterSet const &pset)