LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
AggregateVertex_module.cc
Go to the documentation of this file.
1 //
3 // AggregateVertex module
4 //
5 // brebel@fnal.gov
6 //
8 #ifndef AGGREGATEVERTEX_H
9 #define AGGREGATEVERTEX_H
10 
11 extern "C" {
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 }
15 
16 // Framework includes
21 #include "fhiclcpp/ParameterSet.h"
30 
39 
40 #include <vector>
41 #include <string>
42 
43 namespace vertex {
44 
45 
47  {
48 
49  public:
50 
51  explicit AggregateVertex(fhicl::ParameterSet const& pset);
52  virtual ~AggregateVertex();
53 
54  void produce(art::Event& evt);
55  void beginJob();
56 
57  std::unique_ptr< std::vector<recob::Vertex> > MatchV2T(art::Event& evt,
61 
62  private:
63 
64  std::string fDBScanModuleLabel;
65  std::string fHoughModuleLabel;
66  std::string fTrack3DModuleLabel;
67  std::string fEndPointModuleLabel;
68 
72 
73  }; // class AggregateVertex
74 
75 } // Namespace vertex
76 
77 namespace vertex {
78 
79  //-----------------------------------------------
81  : fDBScanModuleLabel (pset.get< std::string >("DBScanModuleLabel" ))
82  , fHoughModuleLabel (pset.get< std::string >("HoughModuleLabel" ))
83  , fTrack3DModuleLabel (pset.get< std::string >("Track3DModuleLabel" ))
84  , fEndPointModuleLabel(pset.get< std::string >("EndPointModuleLabel"))
85  {
86  produces< std::vector<recob::Vertex> >();
87  produces< art::Assns<recob::Vertex, recob::Hit> >();
88  produces< art::Assns<recob::Vertex, recob::Track> >();
89  produces< art::Assns<recob::Vertex, recob::Shower> >();
90  }
91 
92  //-----------------------------------------------
94  {
95  }
96 
97  //-----------------------------------------------
99  {
100  }
101 
102  //-----------------------------------------------
104  {
105 
107  evt.getByLabel(fEndPointModuleLabel,epListHandle);
108  for(size_t ii = 0; ii < epListHandle->size(); ++ii){
109  art::Ptr<recob::EndPoint2D> ep(epListHandle, ii);
110  feplist.push_back(ep); // class member
111  }
112 
113  art::Handle< std::vector<recob::Track> > trackListHandle;
114  evt.getByLabel(fTrack3DModuleLabel,trackListHandle);
115  for(size_t ii = 0; ii < trackListHandle->size(); ++ii){
116  art::Ptr<recob::Track> track(trackListHandle, ii);
117  ftracklist.push_back(track); // class member
118  }
119 
120 
121  // Only match strong vertices to tracks.
123 
124  while (epIter != feplist.end()){
125  art::Ptr <recob::EndPoint2D> ep = (*epIter);
126  if (ep->ID() < 3) feplistStrong.push_back(ep); // -- cuz there's one less
127  epIter++;
128  }
129 
130  // We will suck up the hits out of each vertex and out of the tracks
131  // and see if there's an overlap of a sufficient (>0) number of hits. If so,
132  // call the track a match to the vtx. Then, .... stick the track pointer(s)
133  // into the AggVertex object. EC, 23-July-2010.
134  std::unique_ptr< art::Assns<recob::Vertex, recob::Track> > vtassn(new art::Assns<recob::Vertex, recob::Track>);
135  std::unique_ptr< art::Assns<recob::Vertex, recob::Shower> > vsassn(new art::Assns<recob::Vertex, recob::Shower>);
136  std::unique_ptr< art::Assns<recob::Vertex, recob::Hit> > vhassn(new art::Assns<recob::Vertex, recob::Hit>);
137 
138  std::unique_ptr< std::vector<recob::Vertex> > vcol (MatchV2T(evt, *vtassn, *vsassn, *vhassn));
139 
140  evt.put(std::move(vcol));
141  evt.put(std::move(vtassn));
142  evt.put(std::move(vsassn));
143  evt.put(std::move(vhassn));
144  }
145 
146  //-------------------------------------------------------------------------------
147  std::unique_ptr< std::vector<recob::Vertex> > AggregateVertex::MatchV2T(art::Event& evt,
151  {
152  mf::LogInfo("AggregateVertex") << "AggregateEvent::MatchV2T(): (strong) vertexlistStrong"
153  << " and tracklist lengths are "
154  << feplistStrong.size() << " and " << ftracklist.size() << ".";
155 
157 
158  // Bail if there are no tracks or vertices.
159  // if (!((int)vertexlistStrong.size()) || !((int)tracklist.size())) return NULL;
160  if (feplistStrong.isNull() || ftracklist.isNull()) {
161  return std::unique_ptr< std::vector<recob::Vertex> > (new std::vector<recob::Vertex>);
162  }
163 
164  // Loop on the vertices, and all the hits in each
165  std::unique_ptr< std::vector<recob::Vertex> > verts(new std::vector<recob::Vertex>);
166 
169 
170  for(size_t epctr = 0; epctr < feplistStrong.size(); ++epctr){
171  art::PtrVector<recob::Track> tlistAssoc; // Will fill with matching tracks.
172  art::PtrVector<recob::Shower> slistAssoc; // Will fill with matching showers.
173  std::vector<size_t> trkIdx;
174  std::vector<size_t> shwIdx;
175 
176  std::vector< art::Ptr<recob::Hit> > hitvertexlistStrong = fmhst.at(epctr);
177 
178  // Should be just one hit per vtx, as per Josh, but we loop anyway.
179  art::PtrVector<recob::Hit>::const_iterator hvIter = hitvertexlistStrong.begin();
180  while (hvIter != hitvertexlistStrong.end()) {
181  art::Ptr<recob::Hit> hitv = (*hvIter);
182 
183  // Now loop on the track hits
184  for(size_t t = 0; t < ftracklist.size(); ++t){
185 
186  std::vector< art::Ptr<recob::Hit> > hittlist = fmht.at(t);
187 
188  std::vector< art::Ptr<recob::Hit> >::const_iterator htIter = hittlist.begin();
189  while (htIter != hittlist.end()) {
190 
191  art::Ptr<recob::Hit> hitt = (*htIter);
192 
193  if (hitt==hitv){
194  //std::cout << "AggregateEvent::MatchV2T(): BooYiggity! Vtx/Trk hit match! hitt, hitv= "
195  //<< hitt << " " <<hitv << std::endl;
196  //std::cout << "AggregateEvent::MatchV2T(): vtx, trk " << vtx<< " " <<trk << std::endl;
197  tlistAssoc.push_back(ftracklist[t]);
198  trkIdx.push_back(t);
199  htIter = hittlist.end()-1; // jump to end of track hitlist, since we've satisfied match
200  }
201  htIter++;
202  } // end hits associated to track
203  } // end track loop
204  hvIter++;
205  }
206 
207  // Now if matching tracks were found for this vertex then create the recob::Vertex object.
208  if (tlistAssoc.size() > 0){
211  double xyz[3] = {-999., -999., -999.};
212  verts->push_back(recob::Vertex(xyz, verts->size()));
213 
214  // associate the tracks to the vertex
215  util::CreateAssn(*this, evt, *verts, tlistAssoc, vtassn);
216 
217  //associate the track hits to the vertex
218  for(auto const& t : trkIdx){
219  std::vector< art::Ptr<recob::Hit> > hits = fmht.at(t);
220  util::CreateAssn(*this, evt, *verts, hits, vhassn);
221  }
222  }// end if there are tracks to be associated
223 
224  if (slistAssoc.size() > 0){
227  double xyz[3] = {-999., -999., -999.};
228  verts->push_back(recob::Vertex(xyz, verts->size()));
229 
230  // associate the showers to the vertex
231  util::CreateAssn(*this, evt, *verts, slistAssoc, vsassn);
232 
233  //associate the shower hits to the vertex
236  for(auto const& s : shwIdx){
237  std::vector< art::Ptr<recob::Hit> > hits = fmhs.at(s);
238  util::CreateAssn(*this, evt, *verts, hits, vhassn);
239  }
240  }// end if there are showers to be associated
241 
242  //HnhinVtxes->Fill(hitvertexlistStrong.size(),1);
243 
244  } // end loop over end points
245 
246  return verts;
247 
248  } // end AggregateVertex::MatchV2T
249 
250 
251 }// end namespace
252 
253 namespace vertex{
254 
256 
257 }
258 #endif // AGGREGATEVERTEX_H
259 
Float_t s
Definition: plot.C:23
std::unique_ptr< std::vector< recob::Vertex > > MatchV2T(art::Event &evt, art::Assns< recob::Vertex, recob::Track > &vtassn, art::Assns< recob::Vertex, recob::Shower > &vsassn, art::Assns< recob::Vertex, recob::Hit > &vhassn)
art::PtrVector< recob::EndPoint2D > feplist
int ID() const
Definition: EndPoint2D.h:58
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
iterator begin()
Definition: PtrVector.h:223
Declaration of signal hit object.
AggregateVertex(fhicl::ParameterSet const &pset)
STL namespace.
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
bool isNull() const
Definition: PtrVectorBase.h:72
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
void hits()
Definition: readHits.C:15
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
Provides recob::Track data product.
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
iterator end()
Definition: PtrVector.h:237
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.
size_type size() const
Definition: PtrVector.h:308
data_t::const_iterator const_iterator
Definition: PtrVector.h:61
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
void produce(art::Event &evt)
art::PtrVector< recob::EndPoint2D > feplistStrong
TCEvent evt
Definition: DataStructs.cxx:5
Float_t track
Definition: plot.C:34
Definition: fwd.h:25
art::PtrVector< recob::Track > ftracklist
vertex reconstruction