LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
BezierTrackerModule_module.cc
Go to the documentation of this file.
2 
3 #ifndef BEZIERTRACKERMOD_H
4 #define BEZIERTRACKERMOD_H
5 
6 //
7 // Name: BezierTrackerModule.h
8 //
9 // Purpose: Header file for module BezierTrackerModule. This modules makes
10 // bezier tracks out of seed collections, or hits, or clusters
11 //
12 // Ben Jones, MIT
13 //
14 
19 
20 
21 namespace recob
22 {
23  class Seed;
24  class Trajectory;
25  class Hit;
26 }
27 
28 
29 namespace trkf {
30 
31  class BezierTrack;
32  class BezierTrackerAlgorithm;
33  class SpacePointAlg;
34 
36  {
37  public:
38 
39  // Constructors, destructor
40 
41  explicit BezierTrackerModule(fhicl::ParameterSet const& pset);
42  virtual ~BezierTrackerModule();
43 
44 
45  // Overrides.
46 
47  void reconfigure(fhicl::ParameterSet const& pset);
48  void beginJob();
49  void produce(art::Event& evt);
50  void endJob();
51 
52 
53 
54 
55  private:
56 
57  // Fcl Attributes.
58 
59  std::string fClusterModuleLabel;
60  double fTrajPtPitch;
61 
62  std::unique_ptr<trkf::BezierTrackerAlgorithm> fBTrackAlg;
63 
64 
65  void GetHitsFromClusters(std::string ClusterModuleLabel, art::Event& evt, std::vector< std::vector<art::PtrVector<recob::Hit> > >& ReturnVec, std::vector<std::map<int, int> >& ClusterMap);
66 
67  };
68 }
69 
70 #endif
71 
73 
74 
75 namespace trkf {
77 }
78 
79 //
80 // Name: BezierTrackerModule.cxx
81 //
82 // Purpose: Implementation file for module BezierTrackerModule.
83 //
84 // Ben Jones, MIT
85 //
86 
87 #include <vector>
101 #include "larcorealg/Geometry/geo_vectors_utils.h" // geo::vect namespace
102 
103 namespace trkf {
104 
105  BezierTrackerModule::BezierTrackerModule(const fhicl::ParameterSet& pset)
106  {
107  reconfigure(pset);
108  produces< std::vector<recob::Trajectory> >("bezierformat");
109  produces< std::vector<recob::Vertex> >();
110  produces< art::Assns<recob::Trajectory, recob::Hit> >("bezierformat");
111  produces< art::Assns<recob::Cluster, recob::Trajectory> >("bezierformat");
112  produces< art::Assns<recob::Trajectory, recob::Vertex> >("bezierformat");
113 
114  produces< std::vector<recob::Trajectory> >();
115  produces< art::Assns<recob::Trajectory, recob::Hit> >();
116  produces< art::Assns<recob::Cluster, recob::Trajectory> >();
117  produces< art::Assns<recob::Trajectory, recob::Vertex> >();
118 
119  }
120 
121  BezierTrackerModule::~BezierTrackerModule()
122  {
123  }
124 
125  void BezierTrackerModule::reconfigure(fhicl::ParameterSet const& pset)
126  {
127  fClusterModuleLabel = pset.get<std::string>("ClusterModuleLabel");
128  fTrajPtPitch = pset.get<double>("TrajPtPitch",0.1);
129 
130  fBTrackAlg.reset( new trkf::BezierTrackerAlgorithm(pset.get<fhicl::ParameterSet>("BezierTrackerAlgorithm")) );
131 
132 }
133 
135  {}
136 
137 
138  void BezierTrackerModule::produce(art::Event& evt)
139  {
140 
141  // Declare products to store
142 
143  std::unique_ptr< std::vector<recob::Trajectory > > btracks ( new std::vector<recob::Trajectory>);
144  std::unique_ptr< std::vector<recob::Vertex > > vertices ( new std::vector<recob::Vertex>);
145  std::unique_ptr< art::Assns<recob::Trajectory, recob::Hit > > assnhit( new art::Assns<recob::Trajectory, recob::Hit>);
146  std::unique_ptr< art::Assns<recob::Trajectory, recob::Vertex > > assnvtx( new art::Assns<recob::Trajectory, recob::Vertex>);
147  std::unique_ptr< art::Assns<recob::Cluster, recob::Trajectory> > assnclus( new art::Assns<recob::Cluster, recob::Trajectory>);
148 
149  std::unique_ptr< std::vector<recob::Trajectory > > ub_tracks ( new std::vector<recob::Trajectory>);
150  std::unique_ptr< art::Assns<recob::Trajectory, recob::Hit > > ub_assnhit( new art::Assns<recob::Trajectory, recob::Hit>);
151  std::unique_ptr< art::Assns<recob::Trajectory, recob::Vertex > > ub_assnvtx( new art::Assns<recob::Trajectory, recob::Vertex>);
152  std::unique_ptr< art::Assns<recob::Cluster, recob::Trajectory > > ub_assnclus( new art::Assns<recob::Cluster, recob::Trajectory>);
153 
154  std::vector<trkf::BezierTrack > BTracks;
155 
156  std::vector<art::PtrVector<recob::Hit> > HitsForAssns;
157 
158  std::vector<std::map<int, int> > ClusterMap;
159  std::vector< std::vector<art::PtrVector<recob::Hit> > > SortedHits;
160  // Produce appropriately organized hit object
161  GetHitsFromClusters(fClusterModuleLabel, evt, SortedHits,ClusterMap);
162 
163  // Produce bezier tracks
164  std::vector<std::vector<std::pair<int, int> > > ClustersUsed;
165  BTracks = fBTrackAlg->MakeTracks(SortedHits, HitsForAssns, ClustersUsed);
166 
167  // Attempt to mitigate clustering imperfections
168  fBTrackAlg->FilterOverlapTracks( BTracks, HitsForAssns, ClustersUsed );
169  fBTrackAlg->SortTracksByLength( BTracks, HitsForAssns, ClustersUsed );
170  fBTrackAlg->MakeOverlapJoins( BTracks, HitsForAssns, ClustersUsed );
171  fBTrackAlg->SortTracksByLength( BTracks, HitsForAssns, ClustersUsed );
172  fBTrackAlg->MakeDirectJoins( BTracks, HitsForAssns, ClustersUsed );
173  fBTrackAlg->FilterOverlapTracks( BTracks, HitsForAssns, ClustersUsed );
174 
175  // Perform bezier vertexing
176  std::vector<recob::Vertex> Vertices;
177  std::vector<std::vector<int> > VertexMapping;
178  fBTrackAlg->MakeVertexJoins(BTracks, Vertices, VertexMapping);
179 
180  for(size_t i=0; i!=BTracks.size(); ++i)
181  {
182 
183  btracks->push_back(BTracks.at(i).GetTrajectory());
184 
185  std::vector<TVector3> track_xyz,track_dir;
186  BTracks.at(i).FillTrackVectors(track_xyz,track_dir,fTrajPtPitch);
187 
188  ub_tracks->emplace_back(geo::vect::convertCollToPoint(track_xyz), geo::vect::convertCollToVector(track_dir), false);
189 
190  util::CreateAssn(*this, evt, *(btracks.get()), HitsForAssns.at(i), *(assnhit.get()));
191  util::CreateAssn(*this, evt, *(ub_tracks), HitsForAssns.at(i), *(assnhit.get()));
192  }
193 
194  // Store vertex assns
195  for(size_t v=0; v!=Vertices.size(); ++v)
196  {
197  vertices->push_back(Vertices.at(v));
198  for(size_t t=0; t!=VertexMapping.at(v).size(); ++t)
199  {
200  util::CreateAssn(*this, evt, *(btracks), *(vertices), *(assnvtx.get()), v, v, VertexMapping[v][t]);
201  util::CreateAssn(*this, evt, *(ub_tracks), *(vertices), *(assnvtx.get()), v, v, VertexMapping[v][t]);
202  }
203  }
204 
205  // Store cluster assns
206  std::vector<art::Ptr<recob::Cluster> > Clusters;
207 
209  evt.getByLabel(fClusterModuleLabel, clusterh);
210 
211  if(clusterh.isValid()) {
212  art::fill_ptr_vector(Clusters, clusterh);
213 
214 
215  for(size_t t=0; t!=btracks->size(); ++t)
216  {
217  for(size_t i=0; i!=ClustersUsed[t].size(); ++i)
218  {
219  int View = ClustersUsed[t][i].first;
220  int Index = ClustersUsed[t][i].second;
221  int ClusterID = ClusterMap[View][Index];
222  util::CreateAssn(*this, evt, *(btracks), Clusters.at(ClusterID), *(assnclus.get()), t);
223  util::CreateAssn(*this, evt, *(ub_tracks), Clusters.at(ClusterID), *(assnclus.get()), t);
224  }
225  }
226  }
227 
228  mf::LogVerbatim("BezierTrackerAlgorithm")<<"Storing in evt - check"<<std::endl;
229  evt.put(std::move(btracks),"bezierformat");
230  evt.put(std::move(vertices));
231  evt.put(std::move(assnhit),"bezierformat");
232  evt.put(std::move(assnvtx),"bezierformat");
233  evt.put(std::move(assnclus),"bezierformat");
234 
235  evt.put(std::move(ub_tracks));
236  evt.put(std::move(ub_assnhit));
237  evt.put(std::move(ub_assnvtx));
238  evt.put(std::move(ub_assnclus));
239 
240  // Now tidy up
241  trkf::SpacePointAlg *Sptalg = fBTrackAlg->GetSeedFinderAlgorithm()->GetSpacePointAlg();
242  Sptalg->clearHitMap();
243  for(size_t i=0; i!=HitsForAssns.size(); ++i)
244  HitsForAssns.at(i).clear();
245  HitsForAssns.clear();
246 
247  }
248  //-----------------------------------------
249 
250  void BezierTrackerModule::GetHitsFromClusters(std::string ClusterModuleLabel, art::Event& evt, std::vector<std::vector<art::PtrVector<recob::Hit> > > & ReturnVec, std::vector<std::map<int, int> >& ClusterMap )
251  {
252  ReturnVec.clear();
253  ReturnVec.resize(3);
254  ClusterMap.clear();
255  ClusterMap.resize(3);
256 
257  std::vector<art::Ptr<recob::Cluster> > Clusters;
258 
260  evt.getByLabel(ClusterModuleLabel, clusterh);
261 
262  if(clusterh.isValid()) {
263  art::fill_ptr_vector(Clusters, clusterh);
264  }
265 
266  art::FindManyP<recob::Hit> fm(clusterh, evt, ClusterModuleLabel);
267 
268  for(size_t iclus = 0; iclus < Clusters.size(); ++iclus) {
269  art::Ptr<recob::Cluster> ThisCluster = Clusters.at(iclus);
270 
271  std::vector< art::Ptr<recob::Hit> > ihits = fm.at(iclus);
272 
273  art::PtrVector<recob::Hit> HitsThisCluster;
274  for(std::vector< art::Ptr<recob::Hit> >::const_iterator i = ihits.begin();
275  i != ihits.end(); ++i)
276  HitsThisCluster.push_back(*i);
277 
278  int View = ThisCluster->View();
279  ClusterMap[View][ReturnVec[View].size()] = iclus;
280  ReturnVec[View].push_back(HitsThisCluster);
281  }
282  }
283 
284 
285 
286  //----------------------------------------------------------------------
287  void BezierTrackerModule::endJob()
288  {
289 
290  }
291 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
Data product for reconstructed trajectory in space.
Reconstruction base classes.
std::map< int, art::Ptr< recob::Cluster > > ClusterMap
Declaration of signal hit object.
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
bool isValid() const
Definition: Handle.h:190
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
void beginJob()
Definition: Breakpoints.cc:14
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
std::vector< geo::Point_t > convertCollToPoint(std::vector< Point > const &coll)
T get(std::string const &key) const
Definition: ParameterSet.h:231
Utilities to extend the interface of geometry vectors.
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.
geo::View_t View() const
Returns the view for this cluster.
Definition: Cluster.h:741
void clearHitMap() const
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
std::vector< geo::Vector_t > convertCollToVector(std::vector< Vector > const &coll)
std::unique_ptr< trkf::BezierTrackerAlgorithm > fBTrackAlg
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
art framework interface to geometry description