All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShowerFinder_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // ShowerFinder class
3 //
4 // \author roxanne.guenette@yale.edu
5 //
6 ////////////////////////////////////////////////////////////////////////
7 
8 #include <string>
9 
10 // Framework includes
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Core/EDProducer.h"
13 #include "canvas/Persistency/Common/FindManyP.h"
14 
15 #include <math.h>
16 
17 // Framework includes
18 #include "art/Framework/Principal/Event.h"
19 #include "fhiclcpp/ParameterSet.h"
20 #include "art/Framework/Principal/Handle.h"
21 #include "canvas/Persistency/Common/Ptr.h"
22 #include "canvas/Persistency/Common/PtrVector.h"
23 #include "art/Framework/Services/Registry/ServiceHandle.h"
24 #include "messagefacility/MessageLogger/MessageLogger.h"
25 
26 // LArSoft Includes
33 
34 
35 // ROOT
36 #include "TMath.h"
37 
38 
39 ///shower finding
40 namespace shwf {
41 
42  class ShowerFinder : public art::EDProducer {
43  public:
44  explicit ShowerFinder(fhicl::ParameterSet const&);
45 
46  private:
47  void produce(art::Event& evt);
48 
49  std::string fVertexModuleLabel; ///< label of module finding 2D endpoint
50  std::string fClusterModuleLabel; ///< label of module finding clusters
51  std::string fHoughLineModuleLabel; ///< label of module finding hough line
52  std::string fVertexStrengthModuleLabel; ///< label of module finding 2D endpoint
53  double fRcone; ///< radious of cone for method
54  double fLcone; ///< length of the cone
55  }; // class ShowerFinder
56 
57 
58 }
59 
60 namespace shwf{
61 
62  //-------------------------------------------------
63  ShowerFinder::ShowerFinder(fhicl::ParameterSet const& pset) :
64  EDProducer{pset}
65  {
66  fVertexModuleLabel = pset.get<std::string > ("VertexModuleLabel");
67  fClusterModuleLabel = pset.get<std::string > ("ClusterModuleLabel");
68  fHoughLineModuleLabel = pset.get<std::string > ("HoughLineModuleLabel");
69  fVertexStrengthModuleLabel= pset.get<std::string > ("VertexStrengthModuleLabel");
70  fRcone = pset.get<double > ("Rcone");
71  fLcone = pset.get<double > ("Lcone");
72 
73  produces< std::vector<recob::Shower> >();
74  produces< art::Assns<recob::Shower, recob::Cluster> >();
75  produces< art::Assns<recob::Shower, recob::Hit> >();
76  }
77 
78 
79  //
80  //-------------------------------------------------
81  /// \todo This method appears to produce a recob::Cluster really as it is
82  /// \todo a collection of 2D clusters from single planes
83  void ShowerFinder::produce(art::Event& evt)
84  {
85 
86  std::unique_ptr<std::vector<recob::Shower> > showercol(new std::vector<recob::Shower>);
87  std::unique_ptr< art::Assns<recob::Shower, recob::Cluster> > cassn(new art::Assns<recob::Shower, recob::Cluster>);
88  std::unique_ptr< art::Assns<recob::Shower, recob::Hit> > hassn(new art::Assns<recob::Shower, recob::Hit>);
89 
90  // Read in the vertex List object(s).
91  art::Handle< std::vector<recob::EndPoint2D> > vertexListHandle;
92  evt.getByLabel(fVertexModuleLabel,vertexListHandle);
93 
94  // Read in the hough line List object(s).
95  art::Handle< std::vector<recob::Cluster> > houghListHandle;
96  evt.getByLabel(fHoughLineModuleLabel,houghListHandle);
97 
98  // Read in the cluster List object(s).
99  art::Handle< std::vector<recob::Cluster> > clusterListHandle;
100  evt.getByLabel(fClusterModuleLabel,clusterListHandle);
101 
102  art::FindManyP<recob::Hit> fmh(clusterListHandle, evt, fClusterModuleLabel);
103 
104  // Read in the vertex Strength List object(s).
105  art::Handle< std::vector<recob::EndPoint2D> > vertexStrengthListHandle;
106  evt.getByLabel(fVertexStrengthModuleLabel,vertexStrengthListHandle);
107 
108  std::vector<size_t> protoShowers; //vector of indices of clusters associated to a cone
109 
110  std::vector< art::Ptr<recob::Hit> > clusterhits; //hits in the cluster
111 
112  art::ServiceHandle<geo::Geometry const> geom;
113 
114  //This vector will contain all strong and strongest vertices
115  art::PtrVector<recob::EndPoint2D> vertSel;
116 
117  //This loop is going over all the vertices in the event
118  //and is interested in ONLY strong and strongest vertices.
119  mf::LogInfo("ShowerFinder") << "Vertex STRENGTH list size = " << vertexStrengthListHandle->size()
120  << " AND vertices:" << vertexListHandle->size()
121  << "\nCLUSTER list size = " << clusterListHandle->size()
122  << " AND Hough: :" << houghListHandle->size();
123 
124  for(size_t iv = 0; iv < vertexListHandle->size(); ++iv){
125  art::Ptr<recob::EndPoint2D> vertex(vertexListHandle, iv);
126  //std::cout << "Vertex " << iv << " : str = " << vertex->ID() << std::endl;
127  //if(vertex->Strength() == 4 || vertex->Strength() == 3){
128  if(vertex->ID() == 1 || vertex->Strength() == 3){ //only use Strongest and strong
129  vertSel.push_back(vertex);
130  }
131  else continue;
132  }
133 
134  //Definition of the geometry of the cone (which is basically a triangle)
135  double scan_angle = 0; //angle of the scan steps
136  double xa_cone = 0; // x coordinate of the cone's apex (wire number)
137  double ya_cone = 0; // y coordinate of the cone's apex (drift time)
138  double x1_cone = 0; // x coordinate of the cone's top right point (wire number)
139  double y1_cone = 0; // y coordinate of the cone's top right point (drift time)
140  double x2_cone = 0; // x coordinate of the cone's top left point (wire number)
141  double y2_cone = 0; // y coordinate of the cone's top left point (drift time)
142 
143  //The length of the side of the cone
144  double fScone = std::sqrt( (fRcone*fRcone) + (fLcone*fLcone));
145 
146  // Opening angle of the cone (defined from input parameters)
147  double cone_angle = (TMath::ATan(fRcone / fLcone)) / 2.0;
148  mf::LogInfo("ShowerFinder") << "Cone Opening Angle: " << (180.0*cone_angle)/TMath::Pi();
149  double compl_angle = 0;
150 
151  unsigned int n_scan =1 + (int)(TMath::Pi() / (2.0*cone_angle));
152  mf::LogInfo("ShowerFinder") << "N scan: " << n_scan;
153 
154  double x_hit = 0; //x coordinate of hit
155  double y_hit = 0; //y coordinate of hit
156 
157  int hits_cluster_counter = 0; //count the number of hits in a cluster that is inside a cone
158  //int hits_cluster_Total = 0; //The total number of hits in a cluster
159 
160  // For EVERY vertex, the algorithm is going to scan the plane to find clusters
161  // contained in the scanning cones
162 
163  for(size_t ivert = 0; ivert < vertSel.size(); ++ivert){
164 
165  mf::LogInfo("ShowerFinder") << "Number of STRONG vertices = " << vertSel.size();
166 
167  //get the coordinates of the vertex for the summit of the cone
168  xa_cone = vertSel[ivert]->WireID().Wire; //for update to EndPoint2D ... WK 4/22/13
169  ya_cone = vertSel[ivert]->DriftTime();
170 
171  mf::LogInfo("ShowerFinder") << "Vertex at: (" << xa_cone << ", " << ya_cone << ")";
172 
173  //Beginning of the scan!
174  for(unsigned int iscan = 0; iscan < n_scan; ++iscan){
175 
176  mf::LogInfo("ShowerFinder") << ">>>> Start SCAN: " << iscan;
177 
178  //define the scan anlge
179  scan_angle = (TMath::Pi()/2.0) - (iscan*(2.0*cone_angle));
180 
181  mf::LogInfo("ShowerFinder") << "Scan Angle: " << (180.*scan_angle)/TMath::Pi();
182 
183  //get the complementary angle for geometry puurposes
184  compl_angle = scan_angle - cone_angle;
185 
186  //Calculate the coordinates of the top right corner of the cone
187  x1_cone = xa_cone + fScone*(std::cos(compl_angle));
188  y1_cone = ya_cone + fScone*(std::sin(compl_angle));
189 
190  //Calculate the coordinates of the top left corner of the cone
191  x2_cone = xa_cone + fScone*(std::cos(scan_angle + cone_angle));
192  y2_cone = ya_cone + fScone*(std::sin(scan_angle + cone_angle));
193 
194  //Looking if a cluster is in this cone (loop over all hits of all clusters)
195  protoShowers.clear();
196  for(size_t iclust = 0; iclust < clusterListHandle->size(); ++iclust){
197 
198  // art::Ptr<recob::Cluster> clust(clusterListHandle, iclust);
199  recob::Cluster const& clust = clusterListHandle->at(iclust);
200 
201  //Get the hits vector from the cluster
202  clusterhits = fmh.at(iclust);
203  if(clusterhits.size() == 0) continue;
204 
205  //Loop over ALL hits in the cluster. Looking if the cluster's
206  // hit is comprised in the cone
207  for(size_t ihits = 0; ihits < clusterhits.size(); ++ihits){
208 
209 
210  x_hit = clusterhits[ihits]->WireID().Wire; //for update to EndPoint2D ... WK 4/22/13
211  y_hit = clusterhits[ihits]->PeakTime();
212 
213  // Check in hits is INSIDE cone
214 
215  //define the 2 line equations:
216  if(y_hit <= ((y2_cone - ya_cone)/(x2_cone - xa_cone))*x_hit + ya_cone &&
217  y_hit >= ((y1_cone - ya_cone)/(x1_cone - xa_cone))*x_hit + ya_cone){
218  hits_cluster_counter++;
219  }
220 
221  }//end hits loop
222 
223  //If there is more than 50% if the cluster INSIDE the cone, this is a protoshower
224  if(clusterhits.size() == 0) continue;
225  if(((double)hits_cluster_counter / (double)clusterhits.size()) >= 0.5){
226  mf::LogInfo("ShowerFinder") << "GOT A SHOWER!!! in scan " << iscan
227  << " cluster: " << iclust << " : " << clust.ID();
228 
229  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
230  /// \todo NEED TO TAKE OUT THE HOUGH LINES FROM THE PROTOSHOWERS!!!!!
231  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
232 
233  protoShowers.push_back(iclust);
234  }
235  clusterhits.clear();
236  hits_cluster_counter = 0;
237 
238  } //end cluster loop
239 
240  if(protoShowers.empty()) continue;
241 
242  // loop over hits in the protoShowers to determine the total charge of the shower
243  double totalCharge = 0.;
244 
245  for(size_t p = 0; p < protoShowers.size(); ++p){
246  const size_t psIndex = protoShowers[p];
247  for (art::Ptr<recob::Hit> const& hit: fmh.at(psIndex))
248  if(hit->SignalType() == geo::kCollection) totalCharge += hit->Integral();
249  }
250 
251  /// \todo really need to determine the values of the arguments of the recob::Shower ctor
252  // fill with bogus values for now
253  //double dcosVtx[3] = { util::kBogusD };
254  //double dcosVtxErr[3] = { util::kBogusD };
255  //double maxTransWidth[2] = { util::kBogusD };
256  //double distMaxWidth = util::kBogusD;
257 
258  //showercol->push_back( recob::Shower(dcosVtx, dcosVtxErr, maxTransWidth, totalCharge, distMaxWidth) );
259  showercol->push_back(recob::Shower());
260 
261  // associate the shower with its clusters
262  util::CreateAssn(*this, evt, *cassn,
263  showercol->size() - 1, protoShowers.begin(), protoShowers.end());
264 
265  // get the hits associated with each cluster and associate those with the shower
266  for(size_t p = 0; p < protoShowers.size(); ++p){
267  const size_t psIndex = protoShowers[p];
268  std::vector< art::Ptr<recob::Hit> > hits = fmh.at(psIndex);
269  util::CreateAssn(*this, evt, *showercol, hits, *hassn);
270  }
271 
272  } //end scan loop
273  } //end vertices loop
274 
275  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
276  //NEED TO SEPARATE THE SHOWERS FROM THE DIFFERENT VERTEX!!!!
277  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
278 
279 
280  mf::LogInfo("ShowerFinder") << "---> Recorded shower = "<< showercol->size();
281  /// \todo check if protoshower from further vertex is also contained in vertex nearer...
282  //if the shower is stand alone ok, else, erase the next one
283  //shower.SetID(is);
284  //shower.SetVertexCoord(xa_cone, ya_cone);
285 
286  vertSel.clear();
287 
288  evt.put(std::move(showercol));
289  evt.put(std::move(cassn));
290  evt.put(std::move(hassn));
291 
292  return;
293  } // end of produce
294 
295 } // end of namespace
296 
297 
298 namespace shwf{
299 
300  DEFINE_ART_MODULE(ShowerFinder)
301 
302 } //end of shower namespace
process_name vertex
Definition: cheaterreco.fcl:51
std::string fHoughLineModuleLabel
label of module finding hough line
Declaration of signal hit object.
pdgs p
Definition: selectors.fcl:22
std::string fVertexModuleLabel
label of module finding 2D endpoint
Set of hits with a 2D structure.
Definition: Cluster.h:71
std::string fClusterModuleLabel
label of module finding clusters
process_name hit
Definition: cheaterreco.fcl:51
void produce(art::Event &evt)
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.
std::string fVertexStrengthModuleLabel
label of module finding 2D endpoint
double fRcone
radious of cone for method
ID_t ID() const
Identifier of this cluster.
Definition: Cluster.h:738
TCEvent evt
Definition: DataStructs.cxx:8
double fLcone
length of the cone
ShowerFinder(fhicl::ParameterSet const &)
art framework interface to geometry description
Signal from collection planes.
Definition: geo_types.h:146