56 std::unique_ptr< art::Assns<recob::Track, recob::PFParticle > > trackPFParticleAssns(
new art::Assns<recob::Track, recob::PFParticle>);
59 art::Handle<std::vector<recob::PFParticle> > pfParticleHandle;
64 art::Handle<std::vector<recob::Cluster> > clusterHandle;
67 if (!(pfParticleHandle.isValid() && clusterHandle.isValid()))
69 evt.put( std::move(trackPFParticleAssns) );
74 art::Handle<std::vector<recob::Track> > trackHandle;
77 if (!trackHandle.isValid())
79 evt.put( std::move(trackPFParticleAssns) );
84 using HitToTrackMap = std::map<int, std::vector<art::Ptr<recob::Track>>>;
91 HitToTrackMap hitToTrackMap;
94 for(
size_t idx = 0; idx < trackHandle->size(); idx++)
96 art::Ptr<recob::Track>
track(trackHandle, idx);
98 std::vector<art::Ptr<recob::Hit>> trackHitVec = trackHitAssns.at(
track.key());
100 for (
const auto& hitPtr : trackHitVec)
102 hitToTrackMap[hitPtr.key()].push_back(
track);
115 using TrackToPFParticleHitMap = std::map<art::Ptr<recob::Track>, std::map<art::Ptr<recob::PFParticle>,std::vector<art::Ptr<recob::Hit>>>>;
117 TrackToPFParticleHitMap trackToPFParticleHitMap;
120 for(
size_t idx = 0; idx < pfParticleHandle->size(); idx++)
122 art::Ptr<recob::PFParticle> pfParticle(pfParticleHandle, idx);
125 std::vector<art::Ptr<recob::Cluster>> clusterVec = clusterAssns.at(pfParticle.key());
128 for(
const auto&
cluster : clusterVec)
131 std::vector<art::Ptr<recob::Hit>> hitVec = clusterHitAssns.at(
cluster.key());
134 for(
const auto&
hit : hitVec)
136 HitToTrackMap::iterator hitToTrackItr = hitToTrackMap.find(
hit.key());
138 if (hitToTrackItr != hitToTrackMap.end())
140 for(
auto&
track : hitToTrackItr->second)
141 trackToPFParticleHitMap[
track][pfParticle].push_back(
hit);
148 for (
auto& trackMapItr : trackToPFParticleHitMap)
150 std::vector<art::Ptr<recob::PFParticle>> pfParticleVec;
152 for(
auto& pfParticleMapItr : trackMapItr.second)
158 int nHitsPerView[] = {0,0,0};
160 for(
const auto&
hit : pfParticleMapItr.second)
162 nHitsPerView[
hit->View()]++;
165 int nViewsWithHits(0);
167 for(
auto& nHits : nHitsPerView)
if (nHits > 0) nViewsWithHits++;
169 if (nViewsWithHits < 2)
continue;
172 std::vector<art::Ptr<recob::Hit>> trackHitVec = trackHitAssns.at(trackMapItr.first.key());
175 float sharedHitFrac = float(pfParticleMapItr.second.size()) /
float(trackHitVec.size());
177 if (sharedHitFrac < 0.3)
continue;
180 pfParticleVec.push_back(pfParticleMapItr.first);
186 evt.put( std::move(trackPFParticleAssns));
process_name use argoneut_mc_hitfinder track
std::string fTrackModuleLabel
std::string fPFParticleModuleLabel
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.