All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
9 #include "art/Framework/Core/EDProducer.h"
10 #include "art/Framework/Principal/Event.h"
11 #include "canvas/Persistency/Common/FindManyP.h"
12 #include "messagefacility/MessageLogger/MessageLogger.h"
13 
22 
23 namespace trkf {
24 
25  class SeedFinderModule : public art::EDProducer {
26  public:
27  explicit SeedFinderModule(fhicl::ParameterSet const& pset);
28 
29  private:
30  void produce(art::Event& evt) override;
31 
32  art::PtrVector<recob::Hit> GetHitsFromEvent(std::string HitModuleLabel, art::Event& evt);
34  std::string ClusterModuleLabel,
35  art::Event& evt,
36  std::vector<std::vector<art::PtrVector<recob::Hit>>>& SortedHits);
37 
38  // Fcl Attributes.
39  SeedFinderAlgorithm fSeedAlg; // Algorithm object
40  std::string fInputModuleLabel; // Where to find hits, if we need them
41  int fInputSource; // 1: Use Clusters
42  // 2: Use Hits
43  };
44 
45 }
46 
47 #include "art/Framework/Core/ModuleMacros.h"
48 
49 namespace trkf {
50  DEFINE_ART_MODULE(SeedFinderModule)
51 }
52 
53 namespace trkf {
54 
55  //----------------------------------------------------------------------------
56  SeedFinderModule::SeedFinderModule(const fhicl::ParameterSet& pset)
57  : EDProducer{pset}, fSeedAlg(pset.get<fhicl::ParameterSet>("SeedAlg"))
58  {
59  fInputModuleLabel = pset.get<std::string>("InputModuleLabel");
60  fInputSource = pset.get<int>("InputSource");
61 
62  produces<std::vector<recob::Seed>>();
63  }
64 
65  //----------------------------------------------------------------------------
66  void
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 =
76  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clockData);
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 
96  art::PtrVector<recob::Hit> Hits = GetHitsFromEvent(fInputModuleLabel, evt);
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 
120  void
122  std::string ClusterModuleLabel,
123  art::Event& evt,
124  std::vector<std::vector<art::PtrVector<recob::Hit>>>& SortedHits)
125  {
126 
127  SortedHits.clear();
128  SortedHits.resize(3);
129  std::vector<art::Ptr<recob::Cluster>> Clusters;
130 
131  art::Handle<std::vector<recob::Cluster>> clusterh;
132  evt.getByLabel(ClusterModuleLabel, clusterh);
133 
134  if (clusterh.isValid()) { art::fill_ptr_vector(Clusters, clusterh); }
135 
136  art::FindManyP<recob::Hit> fm(clusterh, evt, ClusterModuleLabel);
137 
138  for (size_t iclus = 0; iclus < Clusters.size(); ++iclus) {
139  art::Ptr<recob::Cluster> ThisCluster = Clusters.at(iclus);
140 
141  std::vector<art::Ptr<recob::Hit>> ihits = fm.at(iclus);
142 
143  art::PtrVector<recob::Hit> HitsThisCluster;
144  for (std::vector<art::Ptr<recob::Hit>>::const_iterator i = ihits.begin(); i != ihits.end();
145  ++i)
146  HitsThisCluster.push_back(*i);
147 
148  SortedHits[ThisCluster->View()].push_back(HitsThisCluster);
149  }
150  }
151 
152  //----------------------------------------------------------------------------
153  // Extract vector of hits from event
154  //
155  art::PtrVector<recob::Hit>
156  SeedFinderModule::GetHitsFromEvent(std::string HitModuleLabel, art::Event& evt)
157  {
158 
159  art::PtrVector<recob::Hit> TheHits;
160  art::Handle<std::vector<recob::Hit>> hith;
161  evt.getByLabel(HitModuleLabel, hith);
162  for (unsigned int i = 0; i < hith->size(); ++i) {
163  art::Ptr<recob::Hit> hit(hith, i);
164  TheHits.push_back(hit);
165  }
166 
167  return TheHits;
168  }
169 }
Declaration of signal hit object.
process_name hit
Definition: cheaterreco.fcl:51
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
std::vector< art::Ptr< recob::Seed > > SeedVector
Declaration of cluster object.
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
art::PtrVector< recob::Hit > Hits
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
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
auto const detProp