LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
SeedFinderModule_module.cc
Go to the documentation of this file.
1 //
2 // Name: SeedFinderModule.h
3 //
4 //
5 // Ben Jones, MIT, April 2012
6 // bjpjones@mit.edu
7 //
8 
14 
23 
24 namespace trkf {
25 
27  public:
28  explicit SeedFinderModule(fhicl::ParameterSet const& pset);
29 
30  private:
31  void produce(art::Event& evt) override;
32 
33  art::PtrVector<recob::Hit> GetHitsFromEvent(std::string HitModuleLabel, art::Event& evt);
35  std::string ClusterModuleLabel,
36  art::Event& evt,
38 
39  // Fcl Attributes.
40  SeedFinderAlgorithm fSeedAlg; // Algorithm object
41  std::string fInputModuleLabel; // Where to find hits, if we need them
42  int fInputSource; // 1: Use Clusters
43  // 2: Use Hits
44  };
45 
46 }
47 
49 
50 namespace trkf {
52 }
53 
54 namespace trkf {
55 
56  //----------------------------------------------------------------------------
58  : EDProducer{pset}, fSeedAlg(pset.get<fhicl::ParameterSet>("SeedAlg"))
59  {
60  fInputModuleLabel = pset.get<std::string>("InputModuleLabel");
61  fInputSource = pset.get<int>("InputSource");
62 
63  produces<std::vector<recob::Seed>>();
64  }
65 
66  //----------------------------------------------------------------------------
68  {
69  auto seeds = std::make_unique<std::vector<recob::Seed>>();
70 
71  std::vector<std::vector<recob::SpacePoint>> SpacePointsWithSeeds;
72  std::vector<recob::Seed> SeedVector;
73 
74  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
75  auto const detProp =
77 
78  // Make seeds from clusters
79  if (fInputSource == 1) {
80  std::vector<std::vector<art::PtrVector<recob::Hit>>> HitsPerSeed;
81 
82  std::vector<std::vector<art::PtrVector<recob::Hit>>> SortedHits;
84 
85  std::vector<std::vector<recob::Seed>> Seeds =
86  fSeedAlg.GetSeedsFromSortedHits(clockData, detProp, SortedHits, HitsPerSeed);
87 
88  for (size_t i = 0; i != Seeds.size(); ++i)
89  for (size_t j = 0; j != Seeds.at(i).size(); ++j)
90  SeedVector.push_back(Seeds.at(i).at(j));
91  }
92 
93  // Make seeds from unsorted hits
94  else if (fInputSource == 0) {
95 
97  std::vector<art::PtrVector<recob::Hit>> HitCatalogue;
98  SeedVector = fSeedAlg.GetSeedsFromUnSortedHits(clockData, detProp, Hits, HitCatalogue);
99  }
100  else {
101  throw cet::exception("SeedFinderModule") << "Unkown source mode " << fInputSource << "\n";
102  }
103 
104  if (SeedVector.size() > 0) {
105  for (size_t i = 0; i != SeedVector.size(); ++i) {
106  seeds->push_back(SeedVector.at(i));
107  }
108  }
109  else
110  mf::LogInfo("SeedFinder") << "Seed finder made no seeds : no space points in event"
111  << std::endl;
112 
113  evt.put(std::move(seeds));
114  }
115 
116  //----------------------------------------------------------------------------
117  // Get the hits associated with stored clusters
118  //
119 
121  std::string ClusterModuleLabel,
122  art::Event& evt,
124  {
125 
126  SortedHits.clear();
127  SortedHits.resize(3);
128  std::vector<art::Ptr<recob::Cluster>> Clusters;
129 
131  evt.getByLabel(ClusterModuleLabel, clusterh);
132 
133  if (clusterh.isValid()) { art::fill_ptr_vector(Clusters, clusterh); }
134 
135  art::FindManyP<recob::Hit> fm(clusterh, evt, ClusterModuleLabel);
136 
137  for (size_t iclus = 0; iclus < Clusters.size(); ++iclus) {
138  art::Ptr<recob::Cluster> ThisCluster = Clusters.at(iclus);
139 
140  std::vector<art::Ptr<recob::Hit>> ihits = fm.at(iclus);
141 
142  art::PtrVector<recob::Hit> HitsThisCluster;
143  for (std::vector<art::Ptr<recob::Hit>>::const_iterator i = ihits.begin(); i != ihits.end();
144  ++i)
145  HitsThisCluster.push_back(*i);
146 
147  SortedHits[ThisCluster->View()].push_back(HitsThisCluster);
148  }
149  }
150 
151  //----------------------------------------------------------------------------
152  // Extract vector of hits from event
153  //
155  art::Event& evt)
156  {
157 
160  evt.getByLabel(HitModuleLabel, hith);
161  for (unsigned int i = 0; i < hith->size(); ++i) {
162  art::Ptr<recob::Hit> hit(hith, i);
163  TheHits.push_back(hit);
164  }
165 
166  return TheHits;
167  }
168 }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Declaration of signal hit object.
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
bool isValid() const noexcept
Definition: Handle.h:203
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
std::vector< art::Ptr< recob::Seed > > SeedVector
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
Declaration of cluster object.
Detector simulation of raw signals on wires.
std::vector< recob::Seed > GetSeedsFromUnSortedHits(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, art::PtrVector< recob::Hit > const &, std::vector< art::PtrVector< recob::Hit >> &, unsigned int StopAfter=0) const
std::vector< TrajPoint > seeds
Definition: DataStructs.cxx:14
geo::View_t View() const
Returns the view for this cluster.
Definition: Cluster.h:714
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
void GetSortedHitsFromClusters(std::string ClusterModuleLabel, art::Event &evt, std::vector< std::vector< art::PtrVector< recob::Hit >>> &SortedHits)
SeedFinderModule(fhicl::ParameterSet const &pset)
TCEvent evt
Definition: DataStructs.cxx:8
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:306
art::PtrVector< recob::Hit > GetHitsFromEvent(std::string HitModuleLabel, art::Event &evt)
std::vector< std::vector< recob::Seed > > GetSeedsFromSortedHits(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< std::vector< art::PtrVector< recob::Hit >>> const &SortedHits, std::vector< std::vector< art::PtrVector< recob::Hit >>> &HitsPerSeed, unsigned int StopAfter=0) const
void produce(art::Event &evt) override
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33