LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
HoughLineFinderAna_module.cc
Go to the documentation of this file.
1 //
3 // HoughLineFinder class
4 //
5 // joshua.spitz@yale.edu
6 //
7 // This algorithm is designed to find lines (Houghclusters) from clusters found by DBSCAN after deconvolution and hit finding.
8 // The algorithm is based on:
9 // Queisser, A. "Computing the Hough Transform", C/C++ Users Journal 21, 12 (Dec. 2003).
10 // Niblack, W. and Petkovic, D. On Improving the Accuracy of the Hough Transform", Machine Vision and Applications 3, 87 (1990)
12 
13 #include <cmath>
14 #include <string>
15 
16 // ROOT includes
17 #include "TTree.h"
18 
19 // Framework includes
25 #include "art_root_io/TFileService.h"
29 #include "fhiclcpp/ParameterSet.h"
31 
32 // LArSoft includes
36 
37 namespace cluster {
38 
40 
41  public:
42  explicit HoughLineFinderAna(fhicl::ParameterSet const& pset);
44 
45  private:
46  void analyze(const art::Event&);
47  void beginJob();
48 
49  std::string fHoughModuleLabel;
50  std::string fDigitModuleLabel;
51  std::string fHitsModuleLabel;
52  std::string fDBScanModuleLabel;
53  TTree* ftree;
54  int fm_run; // Run number
55  unsigned long int fm_run_timestamp; // Run number
56  int fm_event; // Event number
57  int fm_plane; // Plane number
58  int fm_dbsize;
59  int fm_clusterid; // Cluster ID
60  int fm_wirespan; // Wire spanned by track
61  int fm_sizeClusterZ; //Number of clusters
62  int fm_sizeHitZ; //Number of Hits
65  int* fm_wireZ;
66  int* fm_hitidZ;
67  float* fm_mipZ;
68  float* fm_drifttimeZ;
69  float* fm_widthZ;
70  float* fm_upadcZ;
71  };
72 
73 } // end namespace cluster
74 
75 //#endif // HoughLineFinderAna_H
76 
77 namespace cluster {
78 
80  : EDAnalyzer(pset)
81  , fHoughModuleLabel(pset.get<std::string>("HoughModuleLabel"))
82  , fDigitModuleLabel(pset.get<std::string>("DigitModuleLabel"))
83  , fHitsModuleLabel(pset.get<std::string>("HitsModuleLabel"))
84  , fDBScanModuleLabel(pset.get<std::string>("DBScanModuleLabel"))
85  , fm_run(0)
86  , fm_event(0)
87  , fm_plane(0)
88  , fm_dbsize(0)
89  , fm_clusterid(0)
90  , fm_wirespan(0)
91  , fm_sizeClusterZ(10000)
92  , fm_sizeHitZ(10000)
93  , fm_clusterslope(0)
95  {}
96 
97  //-------------------------------------------------
99  {
100  delete fm_hitidZ;
101  delete fm_mipZ;
102  delete fm_drifttimeZ;
103  delete fm_widthZ;
104  delete fm_upadcZ;
105  delete fm_wireZ;
106  }
107 
108  //-------------------------------------------------
110  {
111 
112  // get access to the TFile service
114  ftree = tfs->make<TTree>("HoughTree", "HoughTree");
115  fm_hitidZ = new int[fm_sizeHitZ];
116  fm_mipZ = new float[fm_sizeHitZ];
117  fm_drifttimeZ = new float[fm_sizeHitZ];
118  fm_widthZ = new float[fm_sizeHitZ];
119  fm_upadcZ = new float[fm_sizeHitZ];
120  fm_wireZ = new int[fm_sizeHitZ];
121  ftree->Branch("run", &fm_run, "run/I");
122  ftree->Branch("run_timestamp", &fm_run_timestamp, "run_timestamp/l"); //l is for ULong64_t
123  ftree->Branch("event", &fm_event, "event/I");
124  ftree->Branch("plane", &fm_plane, "plane/I");
125  ftree->Branch("dbsize", &fm_dbsize, "dbsize/I");
126  ftree->Branch("clusterid", &fm_clusterid, "clusterid/I");
127  ftree->Branch("clusterslope", &fm_clusterslope, "clusterslope/F");
128  ftree->Branch("clusterintercept", &fm_clusterintercept, "clusterintecept/F");
129  ftree->Branch("wirespan", &fm_wirespan, "wirespan/I");
130  ftree->Branch("numberHits", &fm_sizeHitZ, "numberHits/I");
131  ftree->Branch("numberClusters", &fm_sizeClusterZ, "numberClusters/I");
132  ftree->Branch("hitidZ", fm_hitidZ, "hitidZ[numberHits]/I");
133  ftree->Branch("wireZ", fm_wireZ, "wireZ[numberHits]/I");
134  ftree->Branch("mipZ", fm_mipZ, "mipZ[numberHits]/F");
135  ftree->Branch("drifttimeZ", fm_drifttimeZ, "drifttitmeZ[numberHits]/F");
136  ftree->Branch("widthZ", fm_widthZ, "widthZ[numberHits]/F");
137  }
138 
140  {
141 
143  evt.getByLabel(fHoughModuleLabel, hlfListHandle);
145  evt.getByLabel(fHitsModuleLabel, hitListHandle);
146  art::Handle<std::vector<recob::Cluster>> dbscanListHandle;
147  evt.getByLabel(fDBScanModuleLabel, dbscanListHandle);
148 
149  art::FindManyP<recob::Hit> fmh(dbscanListHandle, evt, fDBScanModuleLabel);
150  art::FindManyP<recob::Hit> fmhhl(hlfListHandle, evt, fHoughModuleLabel);
151 
154  // art::PtrVector<recob::Hit> hits;// unused, as yet. EC, 5-Oct-2010.
155 
156  for (size_t ii = 0; ii < hlfListHandle->size(); ++ii) {
157  art::Ptr<recob::Cluster> cluster(hlfListHandle, ii);
158  clusters.push_back(cluster);
159  }
160 
161  for (size_t ii = 0; ii < dbscanListHandle->size(); ++ii) {
162  art::Ptr<recob::Cluster> dbcluster(dbscanListHandle, ii);
163  dbclusters.push_back(dbcluster);
164  }
165 
166  MF_LOG_VERBATIM("HoughLineFinderAna") << "run : " << evt.id().run();
167  //std::cout << "subrun : " << evt.subRun() << std::endl;
168  MF_LOG_VERBATIM("HoughLineFinderAna") << "event : " << evt.id().event();
169  fm_run = evt.id().run();
170  fm_event = evt.id().event();
171  fm_run_timestamp = evt.time().value(); // won't cast, EC, 7-Oct-2010.
172  unsigned int firstwire = 0;
173  unsigned int lastwire = 0;
174  fm_sizeClusterZ = 0;
175  fm_sizeHitZ = 0;
176  fm_dbsize = 0;
178 
179  for (auto view : geo->Views()) {
180 
181  fm_dbsize = 0;
182  fm_sizeClusterZ = clusters.size();
183 
184  for (size_t j = 0; j < dbclusters.size(); ++j) {
185  if (dbclusters[j]->View() == view) {
186  std::vector<art::Ptr<recob::Hit>> _dbhits = fmh.at(j);
187  fm_dbsize += _dbhits.size();
188  if (_dbhits.size() > 0) fm_plane = _dbhits.at(0)->WireID().Plane;
189  }
190  }
191 
192  for (size_t j = 0; j < clusters.size(); ++j) {
193  if (clusters[j]->View() == view) {
194  fm_clusterid = clusters[j]->ID();
195  std::vector<art::Ptr<recob::Hit>> _hits = fmhhl.at(j);
196  fm_clusterslope = (double)std::tan(clusters[j]->StartAngle());
197  fm_clusterintercept = (double)clusters[j]->StartTick();
198  if (_hits.size() != 0) {
199  fm_plane = _hits.at(0)->WireID().Plane;
200  firstwire = _hits[0]->WireID().Wire;
201  lastwire = _hits[_hits.size() - 1]->WireID().Wire;
202  fm_wirespan = lastwire - firstwire;
203  fm_sizeHitZ = _hits.size();
204 
205  for (unsigned int i = 0; i < _hits.size(); ++i) {
206 
207  fm_hitidZ[i] = i;
208  fm_wireZ[i] = _hits[i]->WireID().Wire;
209  fm_mipZ[i] = (double)_hits[i]->Integral();
210  fm_drifttimeZ[i] = (double)_hits[i]->PeakTime();
211  fm_widthZ[i] = (double)(2. * _hits[i]->RMS());
212  fm_upadcZ[i] = (double)_hits[i]->Integral();
213  }
214 
215  ftree->Fill();
216  }
217  } //end if in the correct view
218  } // end loop over clusters
219  } // end loop over views
220  }
221 
222 } // end namespace
223 
224 namespace cluster {
225 
227 
228 } // end namespace caldata
Declaration of signal hit object.
STL namespace.
Cluster finding and building.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
constexpr TimeValue_t value() const
Definition: Timestamp.h:23
RunNumber_t run() const
Definition: EventID.h:98
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
Declaration of cluster object.
size_type size() const
Definition: PtrVector.h:302
HoughLineFinderAna(fhicl::ParameterSet const &pset)
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
#define MF_LOG_VERBATIM(category)
Timestamp time() const
Definition: Event.cc:47
std::set< View_t > const & Views() const
Returns a list of possible views in the detector.
EventNumber_t event() const
Definition: EventID.h:116
TCEvent evt
Definition: DataStructs.cxx:8
Namespace collecting geometry-related classes utilities.
EventID id() const
Definition: Event.cc:23
art framework interface to geometry description