LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 "TMath.h"
14 #include <vector>
15 #include <string>
16 
17 
18 
19 extern "C" {
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 }
23 // ROOT includes
24 #include <TH1D.h>
25 #include <TH2F.h>
26 #include <TFile.h>
27 #include <TTree.h>
28 #include <TCanvas.h>
29 #include <TTree.h>
30 #include "TDatabasePDG.h"
31 #include "TSystem.h"
32 
33 #include <sstream>
34 #include <fstream>
35 #include <math.h>
36 #include <algorithm>
37 #include <iostream>
38 
39 // Framework includes
44 #include "fhiclcpp/ParameterSet.h"
53 
54 // LArSoft includes
62 
63 
64 
65 
66 class TH1F;
67 class TTree;
68 namespace cluster {
69 
71 
72  public:
73 
74  explicit HoughLineFinderAna(fhicl::ParameterSet const& pset);
76 
77  void analyze(const art::Event&);
78  void beginJob();
79 
80  private:
81 
82  std::string fHoughModuleLabel;
83  std::string fDigitModuleLabel;
84  std::string fHitsModuleLabel;
85  std::string fDBScanModuleLabel;
86  TTree* ftree;
87  int fm_run; // Run number
88  unsigned long int fm_run_timestamp; // Run number
89  int fm_event; // Event number
90  int fm_plane; // Plane number
91  int fm_dbsize;
92  int fm_clusterid; // Cluster ID
93  int fm_wirespan; // Wire spanned by track
94  int fm_sizeClusterZ; //Number of clusters
95  int fm_sizeHitZ; //Number of Hits
98  int *fm_wireZ;
99  int *fm_hitidZ;
100  float *fm_mipZ;
102  float *fm_widthZ;
103  float *fm_upadcZ;
104 
105  };
106 
107 
108 } // end namespace cluster
109 
110 //#endif // HoughLineFinderAna_H
111 
112 
113 namespace cluster {
114 
116  : EDAnalyzer(pset)
117  , fHoughModuleLabel (pset.get< std::string >("HoughModuleLabel"))
118  , fDigitModuleLabel (pset.get< std::string >("DigitModuleLabel"))
119  , fHitsModuleLabel (pset.get< std::string >("HitsModuleLabel"))
120  , fDBScanModuleLabel(pset.get< std::string >("DBScanModuleLabel"))
121  , fm_run(0)
122  , fm_event(0)
123  , fm_plane(0)
124  , fm_dbsize(0)
125  , fm_clusterid(0)
126  , fm_wirespan(0)
127  , fm_sizeClusterZ(10000)
128  , fm_sizeHitZ(10000)
129  , fm_clusterslope(0)
131  {
132  }
133 
134  //-------------------------------------------------
136  {
137  delete fm_hitidZ;
138  delete fm_mipZ;
139  delete fm_drifttimeZ;
140  delete fm_widthZ;
141  delete fm_upadcZ;
142  delete fm_wireZ;
143  }
144 
145  //-------------------------------------------------
147  {
148 
149 
150  // get access to the TFile service
152  ftree= tfs->make<TTree>("HoughTree","HoughTree");
153  fm_hitidZ = new int[fm_sizeHitZ];
154  fm_mipZ = new float[fm_sizeHitZ];
155  fm_drifttimeZ = new float[fm_sizeHitZ];
156  fm_widthZ = new float[fm_sizeHitZ];
157  fm_upadcZ = new float[fm_sizeHitZ];
158  fm_wireZ = new int[fm_sizeHitZ];
159  ftree->Branch("run", &fm_run, "run/I");
160  ftree->Branch("run_timestamp", &fm_run_timestamp, "run_timestamp/l"); //l is for ULong64_t
161  ftree->Branch("event", &fm_event, "event/I");
162  ftree->Branch("plane",&fm_plane,"plane/I");
163  ftree->Branch("dbsize",&fm_dbsize,"dbsize/I");
164  ftree->Branch("clusterid",&fm_clusterid,"clusterid/I");
165  ftree->Branch("clusterslope",&fm_clusterslope,"clusterslope/F");
166  ftree->Branch("clusterintercept",&fm_clusterintercept,"clusterintecept/F");
167  ftree->Branch("wirespan",&fm_wirespan,"wirespan/I");
168  ftree->Branch("numberHits",&fm_sizeHitZ,"numberHits/I");
169  ftree->Branch("numberClusters",&fm_sizeClusterZ,"numberClusters/I");
170  ftree->Branch("hitidZ",fm_hitidZ,"hitidZ[numberHits]/I");
171  ftree->Branch("wireZ",fm_wireZ,"wireZ[numberHits]/I");
172  ftree->Branch("mipZ",fm_mipZ,"mipZ[numberHits]/F");
173  ftree->Branch("drifttimeZ",fm_drifttimeZ,"drifttitmeZ[numberHits]/F");
174  ftree->Branch("widthZ",fm_widthZ,"widthZ[numberHits]/F");
175  }
176 
177 
179  {
180 
182  evt.getByLabel(fHoughModuleLabel,hlfListHandle);
183  art::Handle< std::vector<recob::Hit> > hitListHandle;
184  evt.getByLabel(fHitsModuleLabel,hitListHandle);
185  art::Handle< std::vector<recob::Cluster> > dbscanListHandle;
186  evt.getByLabel(fDBScanModuleLabel,dbscanListHandle);
187 
188  art::FindManyP<recob::Hit> fmh(dbscanListHandle, evt, fDBScanModuleLabel);
189  art::FindManyP<recob::Hit> fmhhl(hlfListHandle, evt, fHoughModuleLabel);
190 
193  // art::PtrVector<recob::Hit> hits;// unused, as yet. EC, 5-Oct-2010.
194 
195  for (size_t ii = 0; ii < hlfListHandle->size(); ++ii){
196  art::Ptr<recob::Cluster> cluster(hlfListHandle,ii);
197  clusters.push_back(cluster);
198  }
199 
200  for (size_t ii = 0; ii < dbscanListHandle->size(); ++ii){
201  art::Ptr<recob::Cluster> dbcluster(dbscanListHandle,ii);
202  dbclusters.push_back(dbcluster);
203  }
204 
205  LOG_VERBATIM("HoughLineFinderAna") << "run : " << evt.id().run();
206  //std::cout << "subrun : " << evt.subRun() << std::endl;
207  LOG_VERBATIM("HoughLineFinderAna") << "event : " << evt.id().event();
208  fm_run=evt.id().run();
209  fm_event=evt.id().event();
210  fm_run_timestamp=evt.time().value(); // won't cast, EC, 7-Oct-2010.
211  unsigned int firstwire=0;
212  unsigned int lastwire=0;
213  fm_sizeClusterZ=0;
214  fm_sizeHitZ=0;
215  fm_dbsize=0;
217 
218  for(auto view : geo->Views()){
219 
220  fm_dbsize = 0;
221  fm_sizeClusterZ = clusters.size();
222 
223  for(size_t j = 0; j < dbclusters.size(); ++j) {
224  if(dbclusters[j]->View() == view){
225  std::vector< art::Ptr<recob::Hit> > _dbhits = fmh.at(j);
226  fm_dbsize += _dbhits.size();
227  if(_dbhits.size() > 0) fm_plane = _dbhits.at(0)->WireID().Plane;
228  }
229  }
230 
231  for(size_t j = 0; j < clusters.size(); ++j) {
232  if(clusters[j]->View() == view){
233  fm_clusterid=clusters[j]->ID();
234  std::vector< art::Ptr<recob::Hit> > _hits = fmhhl.at(j);
235  fm_clusterslope=(double) std::tan(clusters[j]->StartAngle());
236  fm_clusterintercept=(double)clusters[j]->StartTick();
237  if(_hits.size()!=0){
238  fm_plane = _hits.at(0)->WireID().Plane;
239  firstwire = _hits[0]->WireID().Wire;
240  lastwire = _hits[_hits.size()-1]->WireID().Wire;
241  fm_wirespan = lastwire-firstwire;
242  fm_sizeHitZ = _hits.size();
243 
244  for(unsigned int i = 0; i < _hits.size(); ++i){
245 
246  fm_hitidZ[i] = i;
247  fm_wireZ[i] = _hits[i]->WireID().Wire;
248  fm_mipZ[i] = (double)_hits[i]->Integral();
249  fm_drifttimeZ[i] = (double)_hits[i]->PeakTime();
250  fm_widthZ[i] = (double) (2. * _hits[i]->RMS());
251  fm_upadcZ[i] = (double)_hits[i]->Integral();
252  }
253 
254  ftree->Fill();
255  }
256  }//end if in the correct view
257  }// end loop over clusters
258  }// end loop over views
259 
260  }
261 
262 }// end namespace
263 
264 
265 namespace cluster{
266 
268 
269 } // end namespace caldata
270 
Encapsulate the construction of a single cyostat.
Declaration of signal hit object.
std::set< geo::View_t > const & Views() const
Returns a list of possible views in the detector.
STL namespace.
Cluster finding and building.
constexpr TimeValue_t value() const
Definition: Timestamp.h:24
RunNumber_t run() const
Definition: EventID.h:99
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
Declaration of cluster object.
size_type size() const
Definition: PtrVector.h:308
HoughLineFinderAna(fhicl::ParameterSet const &pset)
T * make(ARGS...args) const
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
Timestamp time() const
Definition: Event.h:61
EventNumber_t event() const
Definition: EventID.h:117
#define LOG_VERBATIM(category)
Namespace collecting geometry-related classes utilities.
EventID id() const
Definition: Event.h:56
art framework interface to geometry description
Encapsulate the construction of a single detector plane.