10 #include "art/Framework/Core/EDProducer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "art/Framework/Services/Registry/ServiceHandle.h"
15 #include "canvas/Persistency/Common/FindManyP.h"
16 #include "fhiclcpp/ParameterSet.h"
56 void produce(art::Event&
e)
override;
72 fInputProducer =
p.get<std::string>(
"InputProducer");
73 fUsePFParticle =
p.get<
bool>(
"UsePFParticle");
74 produces<std::vector<recob::Shower>>();
75 produces<art::Assns<recob::Shower, recob::Cluster>>();
76 produces<art::Assns<recob::Shower, recob::Hit>>();
77 if (fUsePFParticle) produces<art::Assns<recob::PFParticle, recob::Shower>>();
81 fShowerAlgo = new ::showerreco::ShowerRecoAlg;
82 fCPAlgoArray = new ::cmtool::CPAlgoArray;
83 fCPAlgoNHits = new ::cmtool::CPAlgoNHits;
84 fCPAlgoIgnoreTracks = new ::cmtool::CPAlgoIgnoreTracks;
85 fCFAlgoTimeOverlap = new ::cmtool::CFAlgoTimeOverlap;
88 fCPAlgoNHits->SetMinHits(
p.get<
int>(
"MinHits"));
90 fCPAlgoArray->AddAlgo(fCPAlgoNHits);
91 fCPAlgoArray->AddAlgo(fCPAlgoIgnoreTracks);
93 fManager.MatchManager().AddPriorityAlgo(fCPAlgoArray);
94 fManager.MatchManager().AddMatchAlgo(fCFAlgoTimeOverlap);
96 fShowerAlgo->Verbose(
p.get<
bool>(
"Verbosity"));
97 fShowerAlgo->SetUseArea(
p.get<
bool>(
"UseArea"));
98 fShowerAlgo->setEcorrection(
p.get<
bool>(
"ApplyMCEnergyCorrection"));
99 fShowerAlgo->CaloAlgo(fCaloAlgo);
101 fManager.Algo(fShowerAlgo);
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;
156 if (!fUsePFParticle) {
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);
176 art::FindManyP<recob::Cluster> cluster_m(pfHandle, e,
fInputProducer);
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()));
236 util::CreateAssn(*
this, e, *(out_shower_v.get()), ass_hits, *(sh_assn.get()));
238 if (fUsePFParticle) {
240 art::Handle<std::vector<recob::PFParticle>> pfHandle;
243 art::Ptr<recob::PFParticle> pf_ptr(pfHandle, shower_pfpart_index[i]);
245 util::CreateAssn(*
this, e, *(out_shower_v.get()), pf_ptr, *(sp_assn.get()));
250 e.put(std::move(out_shower_v));
251 e.put(std::move(sh_assn));
252 e.put(std::move(sc_assn));
253 if (fUsePFParticle) e.put(std::move(sp_assn));
::calo::CalorimetryAlg * fCaloAlgo
Utilities related to art service access.
::cmtool::CPAlgoArray * fCPAlgoArray
Declaration of signal hit object.
::showerreco::ShowerRecoManager fManager
::cmtool::CFAlgoTimeOverlap * fCFAlgoTimeOverlap
void produce(art::Event &e) override
std::string fInputProducer
BEGIN_PROLOG local::showertrajpointdedx icarus_pandorashower_3dTraj ShowerFinderTools[3] CalorimetryAlg
Class def header for a class CPAlgoArray.
Declaration of cluster object.
Class def header for a class CPAlgoNHits.
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.
ShowerReco3D(fhicl::ParameterSet const &p)
::cmtool::CPAlgoIgnoreTracks * fCPAlgoIgnoreTracks
::showerreco::ShowerRecoAlg * fShowerAlgo
Class def header for a class CMatchManager.
Class def header for a class CPAlgoIgnoreTracks.
ShowerReco3D & operator=(ShowerReco3D const &)=delete
Class def header for a class CFAlgoTimeOverlap.
::cmtool::CPAlgoNHits * fCPAlgoNHits
art framework interface to geometry description
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)
Class def header for a class ShowerRecoManager.