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>>();
84 mf::LogInfo(
"SpacePointCheater")
85 <<
"SpacePointCheater configured with the following parameters:\n"
86 <<
" ClusterModuleLabel = " << fClusterModuleLabel <<
"\n"
87 <<
" Minimum Hits per Cluster = " << fMinHits <<
"\n"
88 <<
" Cluster associations = " << fClusterAssns;
104 art::ServiceHandle<geo::Geometry const> geom;
108 art::Handle<std::vector<recob::Cluster>> clusterh;
114 if (clusterh.isValid()) {
118 auto sptvecs = std::make_unique<std::vector<art::PtrVector<recob::SpacePoint>>>();
119 auto spts = std::make_unique<std::vector<recob::SpacePoint>>();
120 auto sphitassn = std::make_unique<art::Assns<recob::SpacePoint, recob::Hit>>();
121 auto spclassn = std::make_unique<art::Assns<recob::SpacePoint, recob::Cluster>>();
126 art::PtrVector<recob::Hit> hits;
131 auto const clockData =
132 art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
134 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clockData);
136 int nclus = clusterh->size();
137 for (
int iclus = 0; iclus < nclus; ++iclus) {
138 art::Ptr<recob::Cluster> piclus(clusterh, iclus);
141 std::vector<art::Ptr<recob::Hit>> ihits = fm.at(iclus);
145 if (ihits.size() >= fMinHits &&
151 unsigned int nihits = ihits.size();
153 hits.reserve(nihits);
154 for (
std::vector<art::Ptr<recob::Hit>>::const_iterator i = ihits.begin();
161 for (
int jclus = 0; jclus < iclus; ++jclus) {
162 art::Ptr<recob::Cluster> pjclus(clusterh, jclus);
165 std::vector<art::Ptr<recob::Hit>> jhits = fm.at(jclus);
169 if (jhits.size() >= fMinHits &&
177 unsigned int njhits = jhits.size();
178 assert(hits.size() >= nihits);
180 while (hits.size() > nihits)
182 assert(hits.size() == nihits);
183 hits.reserve(nihits + njhits);
184 for (
std::vector<art::Ptr<recob::Hit>>::const_iterator j = jhits.begin();
192 std::vector<recob::SpacePoint> new_spts;
197 if (new_spts.size() > 0) {
199 art::PtrVector<recob::Cluster> clusters;
201 clusters.push_back(piclus);
202 clusters.push_back(pjclus);
206 int nspt = spts->size();
207 spts->insert(spts->end(), new_spts.begin(), new_spts.end());
211 art::PtrVector<recob::SpacePoint> sptvec;
212 for (
unsigned int ispt = nspt; ispt < spts->size(); ++ispt) {
221 art::ProductID spid = evt.getProductID<std::vector<recob::SpacePoint>>();
222 art::Ptr<recob::SpacePoint> spptr(spid, ispt, evt.productGetter(spid));
223 sptvec.push_back(spptr);
225 sptvecs->push_back(sptvec);
231 for (
int kclus = 0; kclus < jclus; ++kclus) {
232 art::Ptr<recob::Cluster> pkclus(clusterh, kclus);
235 std::vector<art::Ptr<recob::Hit>> khits = fm.at(kclus);
239 if (khits.size() >= fMinHits &&
243 kview != iview && kview != jview) {
247 unsigned int nkhits = khits.size();
248 assert(hits.size() >= nihits + njhits);
250 while (hits.size() > nihits + njhits)
252 assert(hits.size() == nihits + njhits);
253 hits.reserve(nihits + njhits + nkhits);
254 for (
std::vector<art::Ptr<recob::Hit>>::const_iterator
k = khits.begin();
261 std::vector<recob::SpacePoint> new_spts;
266 if (new_spts.size() > 0) {
268 art::PtrVector<recob::Cluster> clusters;
270 clusters.push_back(piclus);
271 clusters.push_back(pjclus);
272 clusters.push_back(pkclus);
276 int nspt = spts->size();
277 spts->insert(spts->end(), new_spts.begin(), new_spts.end());
281 art::PtrVector<recob::SpacePoint> sptvec;
282 for (
unsigned int ispt = nspt; ispt < spts->size(); ++ispt) {
291 art::ProductID spid = evt.getProductID<std::vector<recob::SpacePoint>>();
292 art::Ptr<recob::SpacePoint> spptr(spid, ispt, evt.productGetter(spid));
293 sptvec.push_back(spptr);
295 sptvecs->push_back(sptvec);
306 evt.put(std::move(spts));
307 evt.put(std::move(sptvecs));
308 evt.put(std::move(sphitassn));
309 if (fClusterAssns) evt.put(std::move(spclassn));
320 mf::LogInfo(
"SpacePointCheater")
321 <<
"SpacePointCheater statistics:\n"
322 <<
" Number of events = " <<
fNumEvent <<
"\n"
323 <<
" Number of 2-view space points created = " <<
fNumSpt2 <<
"\n"
324 <<
" Number of 3-view space points created = " <<
fNumSpt3;
std::string fClusterModuleLabel
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
void makeMCTruthSpacePoints(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const art::PtrVector< recob::Hit > &hits, std::vector< recob::SpacePoint > &spts) const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
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
SpacePointCheater(fhicl::ParameterSet const &pset)
Algorithm for generating space points from hits.
int minViews() const noexcept
art framework interface to geometry description
void produce(art::Event &evt) override