18 #include "art/Framework/Core/EDProducer.h"
19 #include "art/Framework/Core/ModuleMacros.h"
20 #include "art/Framework/Principal/Event.h"
21 #include "art/Framework/Services/Registry/ServiceHandle.h"
22 #include "canvas/Persistency/Common/FindManyP.h"
23 #include "messagefacility/MessageLogger/MessageLogger.h"
68 , fSptalg(pset.get<fhicl::ParameterSet>(
"SpacePointAlg"))
70 , fClusterAssns(
false)
75 fClusterModuleLabel = pset.get<std::string>(
"ClusterModuleLabel");
76 fMinHits = pset.get<
unsigned int>(
"MinHits");
77 fClusterAssns = pset.get<
bool>(
"ClusterAssns");
79 produces<std::vector<art::PtrVector<recob::SpacePoint>>>();
80 produces<std::vector<recob::SpacePoint>>();
81 produces<art::Assns<recob::SpacePoint, recob::Hit>>();
82 if (fClusterAssns) produces<art::Assns<recob::SpacePoint, recob::Cluster>>();
86 mf::LogInfo(
"SpacePointFinder")
87 <<
"SpacePointFinder configured with the following parameters:\n"
88 <<
" ClusterModuleLabel = " << fClusterModuleLabel <<
"\n"
89 <<
" Minimum Hits per Cluster = " << fMinHits <<
"\n"
90 <<
" Cluster associations = " << fClusterAssns;
106 art::ServiceHandle<geo::Geometry const> geom;
110 art::Handle<std::vector<recob::Cluster>> clusterh;
116 if (clusterh.isValid()) {
120 std::unique_ptr<std::vector<art::PtrVector<recob::SpacePoint>>> sptvecs(
121 new std::vector<art::PtrVector<recob::SpacePoint>>);
122 std::unique_ptr<std::vector<recob::SpacePoint>> spts(
new std::vector<recob::SpacePoint>);
123 std::unique_ptr<art::Assns<recob::SpacePoint, recob::Hit>> sphitassn(
124 new art::Assns<recob::SpacePoint, recob::Hit>);
125 std::unique_ptr<art::Assns<recob::SpacePoint, recob::Cluster>> spclassn(
126 new art::Assns<recob::SpacePoint, recob::Cluster>);
131 art::PtrVector<recob::Hit> hits;
134 auto const clockData =
135 art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
137 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt);
141 int nclus = clusterh->size();
142 for (
int iclus = 0; iclus < nclus; ++iclus) {
143 art::Ptr<recob::Cluster> piclus(clusterh, iclus);
146 std::vector<art::Ptr<recob::Hit>> ihits = fm.at(iclus);
150 if (ihits.size() >= fMinHits &&
156 unsigned int nihits = ihits.size();
158 hits.reserve(nihits);
159 for (
std::vector<art::Ptr<recob::Hit>>::const_iterator i = ihits.begin();
166 for (
int jclus = 0; jclus < iclus; ++jclus) {
167 art::Ptr<recob::Cluster> pjclus(clusterh, jclus);
170 std::vector<art::Ptr<recob::Hit>> jhits = fm.at(jclus);
174 if (jhits.size() >= fMinHits &&
182 unsigned int njhits = jhits.size();
183 assert(hits.size() >= nihits);
185 while (hits.size() > nihits)
187 assert(hits.size() == nihits);
188 hits.reserve(nihits + njhits);
189 for (
std::vector<art::Ptr<recob::Hit>>::const_iterator j = jhits.begin();
197 std::vector<recob::SpacePoint> new_spts;
202 if (new_spts.size() > 0) {
204 art::PtrVector<recob::Cluster> clusters;
206 clusters.push_back(piclus);
207 clusters.push_back(pjclus);
211 int nspt = spts->size();
212 spts->insert(spts->end(), new_spts.begin(), new_spts.end());
216 art::PtrVector<recob::SpacePoint> sptvec;
217 for (
unsigned int ispt = nspt; ispt < spts->size(); ++ispt) {
226 art::ProductID spid = evt.getProductID<std::vector<recob::SpacePoint>>();
227 art::Ptr<recob::SpacePoint> spptr(spid, ispt, evt.productGetter(spid));
228 sptvec.push_back(spptr);
230 sptvecs->push_back(sptvec);
236 for (
int kclus = 0; kclus < jclus; ++kclus) {
237 art::Ptr<recob::Cluster> pkclus(clusterh, kclus);
240 std::vector<art::Ptr<recob::Hit>> khits = fm.at(kclus);
244 if (khits.size() >= fMinHits &&
248 kview != iview && kview != jview) {
252 unsigned int nkhits = khits.size();
253 assert(hits.size() >= nihits + njhits);
255 while (hits.size() > nihits + njhits)
257 assert(hits.size() == nihits + njhits);
258 hits.reserve(nihits + njhits + nkhits);
259 for (
std::vector<art::Ptr<recob::Hit>>::const_iterator
k = khits.begin();
266 std::vector<recob::SpacePoint> new_spts;
271 if (new_spts.size() > 0) {
273 art::PtrVector<recob::Cluster> clusters;
275 clusters.push_back(piclus);
276 clusters.push_back(pjclus);
277 clusters.push_back(pkclus);
281 int nspt = spts->size();
282 spts->insert(spts->end(), new_spts.begin(), new_spts.end());
286 art::PtrVector<recob::SpacePoint> sptvec;
287 for (
unsigned int ispt = nspt; ispt < spts->size(); ++ispt) {
296 art::ProductID spid = evt.getProductID<std::vector<recob::SpacePoint>>();
297 art::Ptr<recob::SpacePoint> spptr(spid, ispt, evt.productGetter(spid));
298 sptvec.push_back(spptr);
300 sptvecs->push_back(sptvec);
311 evt.put(std::move(spts));
312 evt.put(std::move(sptvecs));
313 evt.put(std::move(sphitassn));
314 if (fClusterAssns) evt.put(std::move(spclassn));
325 mf::LogInfo(
"SpacePointFinder")
326 <<
"SpacePointFinder statistics:\n"
327 <<
" Number of events = " <<
fNumEvent <<
"\n"
328 <<
" Number of 2-view space points created = " <<
fNumSpt2 <<
"\n"
329 <<
" Number of 3-view space points created = " <<
fNumSpt3;
SpacePointFinder(fhicl::ParameterSet const &pset)
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Declaration of signal hit object.
Planes which measure Z direction.
bool enableV() const noexcept
const art::PtrVector< recob::Hit > & getAssociatedHits(const recob::SpacePoint &spt) const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
void makeSpacePoints(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const art::PtrVector< recob::Hit > &hits, std::vector< recob::SpacePoint > &spts) const
bool enableU() const noexcept
Declaration of cluster object.
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
bool enableW() const noexcept
Algorithm for generating space points from hits.
std::string fClusterModuleLabel
int minViews() const noexcept
art framework interface to geometry description
void produce(art::Event &evt) override