LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
SeedFinderModule_module.cc
Go to the documentation of this file.
1 #ifndef SEEDFINDER_H
2 #define SEEDFINDER_H
3 
4 //
5 // Name: SeedFinderModule.h
6 //
7 //
8 // Ben Jones, MIT, April 2012
9 // bjpjones@mit.edu
10 //
11 
16 
17 
18 namespace recob
19 {
20  class SpacePoint;
21  class Cluster;
22  class Seed;
23  class Hit;
24 }
25 
26 namespace trkf {
27 
29  {
30  public:
31 
32  // Constructors, destructor
33 
34  explicit SeedFinderModule(fhicl::ParameterSet const& pset);
35  virtual ~SeedFinderModule();
36 
37  // Overrides.
38 
39  void reconfigure(fhicl::ParameterSet const& pset);
40  void beginJob();
41  void produce(art::Event& evt);
42 
43  void endJob();
44 
45 
46  art::PtrVector<recob::Hit> GetHitsFromEvent(std::string HitModuleLabel, art::Event & evt);
47  void GetSortedHitsFromClusters(std::string ClusterModuleLabel, art::Event& evt,std::vector< std::vector< art::PtrVector<recob::Hit> > > & SortedHits );
48 
49 
50 
51  private:
52 
53 
54  // Fcl Attributes.
55 
56  SeedFinderAlgorithm fSeedAlg; // Algorithm object
57  std::string fInputModuleLabel; // Where to find hits, if we need them
58  int fInputSource; // 1: Use Clusters
59  // 2: Use Hits
60 
61  };
62 
63 }
64 
65 #endif // SEEDFINDER_H
66 
67 
68 
70 
71 
72 namespace trkf {
74 }
75 
76 //
77 // Name: SeedFinderModule.cxx
78 //
79 // Purpose: Implementation file for module SeedFinderModule.
80 //
81 // Ben Jones, MIT
82 //
83 
84 #include <vector>
95 #include "TMatrixD.h"
96 #include "TVectorD.h"
97 
98 namespace trkf {
99 
100  //----------------------------------------------------------------------------
101  SeedFinderModule::SeedFinderModule(const fhicl::ParameterSet& pset) :
102  fSeedAlg(pset.get<fhicl::ParameterSet>("SeedAlg"))
103  {
104  reconfigure(pset);
105  produces<std::vector<recob::Seed> >();
106 
107 
108  }
109 
110  //----------------------------------------------------------------------------
112  {
113  }
114 
115  //----------------------------------------------------------------------------
117  {
118  fSeedAlg.reconfigure ( pset.get<fhicl::ParameterSet>("SeedAlg") );
119  fInputModuleLabel = pset.get<std::string>("InputModuleLabel");
120  fInputSource = pset.get<int>("InputSource");
121 
122  }
123 
124  //----------------------------------------------------------------------------
126  {}
127 
128 
129 
130 
131  //----------------------------------------------------------------------------
133  {
134 
135  std::unique_ptr<std::vector<recob::Seed> > seeds(new std::vector<recob::Seed>);
136 
137  std::vector<std::vector<recob::SpacePoint> > SpacePointsWithSeeds;
138  std::vector<recob::Seed> SeedVector;
139 
140  // Make seeds from clusters
141  if(fInputSource==1)
142  {
143  std::vector<std::vector<art::PtrVector<recob::Hit> > > HitsPerSeed;
144 
145  std::vector< std::vector< art::PtrVector<recob::Hit> > > SortedHits;
147 
148  std::vector<std::vector<recob::Seed> > Seeds = fSeedAlg.GetSeedsFromSortedHits(SortedHits, HitsPerSeed);
149 
150  for(size_t i=0; i!=Seeds.size(); ++i)
151  for(size_t j=0; j!=Seeds.at(i).size(); ++j)
152  SeedVector.push_back(Seeds.at(i).at(j));
153  }
154 
155  // Make seeds from unsorted hits
156  else if(fInputSource==0)
157  {
158 
160  std::vector<art::PtrVector<recob::Hit> > HitCatalogue;
161  SeedVector = fSeedAlg.GetSeedsFromUnSortedHits(Hits, HitCatalogue);
162  }
163  else
164  {
165  throw cet::exception("SeedFinderModule") <<
166  "Unkown source mode " << fInputSource<<"\n";
167  }
168 
169  if(SeedVector.size()>0)
170  {
171  for(size_t i=0; i!=SeedVector.size(); ++i)
172  {
173  seeds->push_back(SeedVector.at(i));
174  }
175 
176  }
177  else
178  mf::LogInfo("SeedFinder")<<"Seed finder made no seeds : no space points in event"<<std::endl;
179 
180  evt.put(std::move(seeds));
181 
182 
183 
184  }
185 
186 
187 
188 
189  //----------------------------------------------------------------------------
190  // Get the hits associated with stored clusters
191  //
192 
193  void SeedFinderModule::GetSortedHitsFromClusters(std::string ClusterModuleLabel, art::Event& evt,std::vector< std::vector< art::PtrVector<recob::Hit> > > & SortedHits )
194  {
195 
196  SortedHits.clear();
197  SortedHits.resize(3);
198  std::vector<art::Ptr<recob::Cluster> > Clusters;
199 
201  evt.getByLabel(ClusterModuleLabel, clusterh);
202 
203  if(clusterh.isValid()) {
204  art::fill_ptr_vector(Clusters, clusterh);
205  }
206 
207  art::FindManyP<recob::Hit> fm(clusterh, evt, ClusterModuleLabel);
208 
209  for(size_t iclus = 0; iclus < Clusters.size(); ++iclus) {
210  art::Ptr<recob::Cluster> ThisCluster = Clusters.at(iclus);
211 
212  std::vector< art::Ptr<recob::Hit> > ihits = fm.at(iclus);
213 
214  art::PtrVector<recob::Hit> HitsThisCluster;
215  for(std::vector< art::Ptr<recob::Hit> >::const_iterator i = ihits.begin();
216  i != ihits.end(); ++i)
217  HitsThisCluster.push_back(*i);
218 
219  SortedHits[ThisCluster->View()].push_back(HitsThisCluster);
220 
221  }
222  }
223 
224 
225 
226 
227 
228 
229 
230  //----------------------------------------------------------------------------
231  // Extract vector of hits from event
232  //
233 
235  {
236 
239  evt.getByLabel(HitModuleLabel, hith);
240  for(unsigned int i=0; i<hith->size(); ++i)
241  {
242  art::Ptr<recob::Hit> hit(hith, i);
243  TheHits.push_back(hit);
244  }
245 
246  return TheHits;
247  }
248 
249 
250 
251 
252 
253 
254  //----------------------------------------------------------------------------
256  {
257 
258  }
259 }
std::vector< art::Ptr< recob::Seed > > SeedVector
Reconstruction base classes.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Declaration of signal hit object.
void reconfigure(fhicl::ParameterSet const &pset)
void GetSortedHitsFromClusters(std::string ClusterModuleLabel, art::Event &evt, std::vector< std::vector< art::PtrVector< recob::Hit > > > &SortedHits)
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
std::vector< std::vector< recob::Seed > > GetSeedsFromSortedHits(std::vector< std::vector< art::PtrVector< recob::Hit > > > const &SortedHits, std::vector< std::vector< art::PtrVector< recob::Hit > > > &HitsPerSeed, unsigned int StopAfter=0)
#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
parameter set interface
T get(std::string const &key) const
Definition: ParameterSet.h:231
Declaration of cluster object.
Provides recob::Track data product.
Detector simulation of raw signals on wires.
geo::View_t View() const
Returns the view for this cluster.
Definition: Cluster.h:741
void reconfigure(fhicl::ParameterSet const &pset)
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< recob::Seed > GetSeedsFromUnSortedHits(art::PtrVector< recob::Hit > const &, std::vector< art::PtrVector< recob::Hit > > &, unsigned int StopAfter=0)
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
void produce(art::Event &evt)
art::PtrVector< recob::Hit > GetHitsFromEvent(std::string HitModuleLabel, art::Event &evt)
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33