AggregateVertex_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // AggregateVertex module
4 //
5 // brebel@fnal.gov
6 //
7 ////////////////////////////////////////////////////////////////////////
8 
9 extern "C" {
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 }
13 
14 // Framework includes
17 #include "canvas/Persistency/Common/FindManyP.h"
19 #include "fhiclcpp/ParameterSet.h"
24 #include "art_root_io/TFileService.h"
25 #include "art_root_io/TFileDirectory.h"
26 #include "canvas/Persistency/Common/FindManyP.h"
28 
37 
38 #include <string>
39 
40 namespace vertex {
41 
42 
44  {
45 
46  public:
47 
48  explicit AggregateVertex(fhicl::ParameterSet const& pset);
49 
50 
51  private:
52  void produce(art::Event& evt) override;
53 
54  std::unique_ptr< std::vector<recob::Vertex> > MatchV2T(art::Event& evt,
62 
66 
67  }; // class AggregateVertex
68 
69 } // Namespace vertex
70 
71 namespace vertex {
72 
73  //-----------------------------------------------
75  : EDProducer{pset}
76  , fDBScanModuleLabel (pset.get< std::string >("DBScanModuleLabel" ))
77  , fHoughModuleLabel (pset.get< std::string >("HoughModuleLabel" ))
78  , fTrack3DModuleLabel (pset.get< std::string >("Track3DModuleLabel" ))
79  , fEndPointModuleLabel(pset.get< std::string >("EndPointModuleLabel"))
80  {
81  produces< std::vector<recob::Vertex> >();
82  produces< art::Assns<recob::Vertex, recob::Hit> >();
83  produces< art::Assns<recob::Vertex, recob::Track> >();
84  produces< art::Assns<recob::Vertex, recob::Shower> >();
85  }
86 
87  //-----------------------------------------------
89  {
90 
92  evt.getByLabel(fEndPointModuleLabel,epListHandle);
93  for(size_t ii = 0; ii < epListHandle->size(); ++ii){
94  art::Ptr<recob::EndPoint2D> ep(epListHandle, ii);
95  feplist.push_back(ep); // class member
96  }
97 
99  evt.getByLabel(fTrack3DModuleLabel,trackListHandle);
100  for(size_t ii = 0; ii < trackListHandle->size(); ++ii){
101  art::Ptr<recob::Track> track(trackListHandle, ii);
102  ftracklist.push_back(track); // class member
103  }
104 
105 
106  // Only match strong vertices to tracks.
108 
109  while (epIter != feplist.end()){
110  art::Ptr <recob::EndPoint2D> ep = (*epIter);
111  if (ep->ID() < 3) feplistStrong.push_back(ep); // -- cuz there's one less
112  epIter++;
113  }
114 
115  // We will suck up the hits out of each vertex and out of the tracks
116  // and see if there's an overlap of a sufficient (>0) number of hits. If so,
117  // call the track a match to the vtx. Then, .... stick the track pointer(s)
118  // into the AggVertex object. EC, 23-July-2010.
119  std::unique_ptr< art::Assns<recob::Vertex, recob::Track> > vtassn(new art::Assns<recob::Vertex, recob::Track>);
120  std::unique_ptr< art::Assns<recob::Vertex, recob::Shower> > vsassn(new art::Assns<recob::Vertex, recob::Shower>);
121  std::unique_ptr< art::Assns<recob::Vertex, recob::Hit> > vhassn(new art::Assns<recob::Vertex, recob::Hit>);
122 
123  std::unique_ptr< std::vector<recob::Vertex> > vcol (MatchV2T(evt, *vtassn, *vsassn, *vhassn));
124 
125  evt.put(std::move(vcol));
126  evt.put(std::move(vtassn));
127  evt.put(std::move(vsassn));
128  evt.put(std::move(vhassn));
129  }
130 
131  //-------------------------------------------------------------------------------
132  std::unique_ptr< std::vector<recob::Vertex> > AggregateVertex::MatchV2T(art::Event& evt,
136  {
137  mf::LogInfo("AggregateVertex") << "AggregateEvent::MatchV2T(): (strong) vertexlistStrong"
138  << " and tracklist lengths are "
139  << feplistStrong.size() << " and " << ftracklist.size() << ".";
140 
141  art::FindManyP<recob::Hit> fmhst(feplistStrong, evt, fEndPointModuleLabel);
142 
143  // Bail if there are no tracks or vertices.
144  // if (!((int)vertexlistStrong.size()) || !((int)tracklist.size())) return NULL;
145  if (feplistStrong.isNull() || ftracklist.isNull()) {
146  return std::unique_ptr< std::vector<recob::Vertex> > (new std::vector<recob::Vertex>);
147  }
148 
149  // Loop on the vertices, and all the hits in each
150  std::unique_ptr< std::vector<recob::Vertex> > verts(new std::vector<recob::Vertex>);
151 
152  art::FindManyP<recob::Hit> fmht(ftracklist, evt, fTrack3DModuleLabel);
153  art::FindManyP<recob::Hit> fmhs(ftracklist, evt, fTrack3DModuleLabel);
154 
155  for(size_t epctr = 0; epctr < feplistStrong.size(); ++epctr){
156  art::PtrVector<recob::Track> tlistAssoc; // Will fill with matching tracks.
157  art::PtrVector<recob::Shower> slistAssoc; // Will fill with matching showers.
158  std::vector<size_t> trkIdx;
159  std::vector<size_t> shwIdx;
160 
161  std::vector< art::Ptr<recob::Hit> > hitvertexlistStrong = fmhst.at(epctr);
162 
163  // Should be just one hit per vtx, as per Josh, but we loop anyway.
164  art::PtrVector<recob::Hit>::const_iterator hvIter = hitvertexlistStrong.begin();
165  while (hvIter != hitvertexlistStrong.end()) {
166  art::Ptr<recob::Hit> hitv = (*hvIter);
167 
168  // Now loop on the track hits
169  for(size_t t = 0; t < ftracklist.size(); ++t){
170 
171  std::vector< art::Ptr<recob::Hit> > hittlist = fmht.at(t);
172 
173  std::vector< art::Ptr<recob::Hit> >::const_iterator htIter = hittlist.begin();
174  while (htIter != hittlist.end()) {
175 
176  art::Ptr<recob::Hit> hitt = (*htIter);
177 
178  if (hitt==hitv){
179  //std::cout << "AggregateEvent::MatchV2T(): BooYiggity! Vtx/Trk hit match! hitt, hitv= "
180  //<< hitt << " " <<hitv << std::endl;
181  //std::cout << "AggregateEvent::MatchV2T(): vtx, trk " << vtx<< " " <<trk << std::endl;
182  tlistAssoc.push_back(ftracklist[t]);
183  trkIdx.push_back(t);
184  htIter = hittlist.end()-1; // jump to end of track hitlist, since we've satisfied match
185  }
186  htIter++;
187  } // end hits associated to track
188  } // end track loop
189  hvIter++;
190  }
191 
192  // Now if matching tracks were found for this vertex then create the recob::Vertex object.
193  if (tlistAssoc.size() > 0){
194  /// \todo Really need to also determine the xyz position of the found vertex
195  /// \todo Also should determine the ID for this vertex
196  double xyz[3] = {-999., -999., -999.};
197  verts->push_back(recob::Vertex(xyz, verts->size()));
198 
199  // associate the tracks to the vertex
200  util::CreateAssn(*this, evt, *verts, tlistAssoc, vtassn);
201 
202  //associate the track hits to the vertex
203  for(auto const& t : trkIdx){
204  std::vector< art::Ptr<recob::Hit> > hits = fmht.at(t);
205  util::CreateAssn(*this, evt, *verts, hits, vhassn);
206  }
207  }// end if there are tracks to be associated
208 
209  if (slistAssoc.size() > 0){
210  /// \todo Really need to also determine the xyz position of the found vertex
211  /// \todo Also should determine the ID for this vertex
212  double xyz[3] = {-999., -999., -999.};
213  verts->push_back(recob::Vertex(xyz, verts->size()));
214 
215  // associate the showers to the vertex
216  util::CreateAssn(*this, evt, *verts, slistAssoc, vsassn);
217 
218  //associate the shower hits to the vertex
219  ///\todo get a shower module label in line 169 and get a list of showers
220  ///\todo from the event
221  for(auto const& s : shwIdx){
222  std::vector< art::Ptr<recob::Hit> > hits = fmhs.at(s);
223  util::CreateAssn(*this, evt, *verts, hits, vhassn);
224  }
225  }// end if there are showers to be associated
226 
227  //HnhinVtxes->Fill(hitvertexlistStrong.size(),1);
228 
229  } // end loop over end points
230 
231  return verts;
232 
233  } // end AggregateVertex::MatchV2T
234 
235 
236 }// end namespace
237 
238 namespace vertex{
239 
241 
242 }
void produce(art::Event &evt) override
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
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
iterator begin()
Definition: PtrVector.h:217
Declaration of signal hit object.
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
AggregateVertex(fhicl::ParameterSet const &pset)
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
bool isNull() const
Definition: PtrVectorBase.h:68
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:446
typename data_t::const_iterator const_iterator
Definition: PtrVector.h:55
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:56
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
iterator end()
Definition: PtrVector.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.
reference at(size_type n)
Definition: PtrVector.h:359
Declaration of cluster object.
Provides recob::Track data product.
size_type size() const
Definition: PtrVector.h:302
Utility object to perform functions of association.
art::PtrVector< recob::EndPoint2D > feplistStrong
TCEvent evt
Definition: DataStructs.cxx:5
ProductID put(std::unique_ptr< PROD > &&edp, FullSemantic< Level::Run > const semantic)
Definition: DataViewImpl.h:730
Definition: fwd.h:29
static QCString * s
Definition: config.cpp:1042
art::PtrVector< recob::Track > ftracklist
vertex reconstruction