107 auto const& geom = *lar::providerFrom<geo::Geometry>();
108 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(
e);
110 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(
e, clockData);
114 std::unique_ptr<std::vector<recob::Shower>> out_shower_v(
new std::vector<recob::Shower>);
115 std::unique_ptr<art::Assns<recob::Shower, recob::Cluster>> sc_assn(
116 new art::Assns<recob::Shower, recob::Cluster>);
117 std::unique_ptr<art::Assns<recob::Shower, recob::Hit>> sh_assn(
118 new art::Assns<recob::Shower, recob::Hit>);
119 std::unique_ptr<art::Assns<recob::PFParticle, recob::Shower>> sp_assn(
120 new art::Assns<recob::PFParticle, recob::Shower>);
128 art::Handle<std::vector<recob::Cluster>> cHandle;
131 if (!cHandle.isValid())
132 throw cet::exception(__FUNCTION__) <<
"Invalid input cluster label!" << std::endl;
135 std::vector<std::vector<::util::PxHit>> local_clusters;
138 for (
size_t i = 0; i < cHandle->size(); ++i) {
139 local_clusters.push_back(std::vector<::util::PxHit>());
141 const std::vector<art::Ptr<recob::Hit>>& hits = hit_m.at(i);
143 conv.GeneratePxHit(hits, local_clusters.back());
150 std::vector<size_t> shower_pfpart_index;
152 std::vector<std::vector<unsigned int>> matched_pairs;
154 std::vector<recob::Shower> shower_v;
162 art::Handle<std::vector<recob::PFParticle>> pfHandle;
164 if (!pfHandle.isValid())
165 throw cet::exception(__FUNCTION__) <<
"Invalid input PFParticle label!" << std::endl;
168 std::map<art::Ptr<recob::Cluster>,
size_t> cmap;
169 for (
size_t i = 0; i < cHandle->size(); ++i) {
171 const art::Ptr<recob::Cluster> cptr(cHandle, i);
178 for (
size_t i = 0; i < pfHandle->size(); ++i) {
180 const art::Ptr<recob::PFParticle> pf(pfHandle, i);
182 if (pf->PdgCode() != 11)
continue;
184 const std::vector<art::Ptr<recob::Cluster>>& clusters = cluster_m.at(i);
186 std::vector<unsigned int> one_pair;
187 one_pair.reserve(clusters.size());
189 for (
auto const& cptr : clusters) {
191 auto iter = cmap.find(cptr);
192 if (iter == cmap.end())
193 throw cet::exception(__FUNCTION__)
194 <<
"PFParticle=>Cluster association not valid!" << std::endl;
196 one_pair.push_back((*iter).second);
198 matched_pairs.push_back(one_pair);
199 shower_pfpart_index.push_back(i);
206 if (shower_v.size() != matched_pairs.size())
207 throw cet::exception(__FUNCTION__)
208 <<
"Logic error: # of matched pairs != # of reco-ed showers!" << std::endl;
211 out_shower_v->reserve(shower_v.size());
213 for (
size_t i = 0; i < shower_v.size(); ++i) {
216 shower_v[i].set_id(i);
218 out_shower_v->push_back(shower_v[i]);
221 std::vector<art::Ptr<recob::Cluster>> ass_clusters;
223 std::vector<art::Ptr<recob::Hit>> ass_hits;
224 for (
auto const& cindex : matched_pairs[i]) {
226 ass_clusters.push_back(art::Ptr<recob::Cluster>(cHandle, cindex));
228 const std::vector<art::Ptr<recob::Hit>>& hits = hit_m.at(cindex);
230 for (
auto const& ptr : hits)
231 ass_hits.push_back(ptr);
234 util::CreateAssn(*
this,
e, *(out_shower_v.get()), ass_clusters, *(sc_assn.get()));
240 art::Handle<std::vector<recob::PFParticle>> pfHandle;
243 art::Ptr<recob::PFParticle> pf_ptr(pfHandle, shower_pfpart_index[i]);
250 e.put(std::move(out_shower_v));
251 e.put(std::move(sh_assn));
252 e.put(std::move(sc_assn));
::showerreco::ShowerRecoManager fManager
std::string fInputProducer
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.
ClusterAss_t Reconstruct(geo::GeometryCore const &geom, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const std::vector< std::vector< util::PxHit >> &clusters, std::vector<::recob::Shower > &showers)