10#include "art/Framework/Principal/Event.h"
11#include "art/Framework/Principal/Handle.h"
12#include "art/Framework/Services/Registry/ServiceHandle.h"
13#include "canvas/Persistency/Common/FindManyP.h"
14#include "canvas/Persistency/Common/FindOneP.h"
15#include "cetlib_except/exception.h"
16#include "messagefacility/MessageLogger/MessageLogger.h"
18#include "lardataobj/AnalysisBase/BackTrackerMatchingData.h"
19#include "lardataobj/AnalysisBase/CosmicTag.h"
20#include "lardataobj/AnalysisBase/T0.h"
21#include "lardataobj/RecoBase/Cluster.h"
22#include "lardataobj/RecoBase/Hit.h"
23#include "lardataobj/RecoBase/PFParticle.h"
24#include "lardataobj/RecoBase/PFParticleMetadata.h"
25#include "lardataobj/RecoBase/Seed.h"
26#include "lardataobj/RecoBase/Shower.h"
27#include "lardataobj/RecoBase/Slice.h"
28#include "lardataobj/RecoBase/SpacePoint.h"
29#include "lardataobj/RecoBase/Track.h"
30#include "lardataobj/RecoBase/Vertex.h"
31#include "lardataobj/RecoBase/Wire.h"
32#include "nusimdata/SimulationBase/MCTruth.h"
34#include "larcore/Geometry/Geometry.h"
35#include "larcoreobj/SimpleTypesAndConstants/RawTypes.h"
36#include "lardata/DetectorInfoServices/DetectorClocksService.h"
48 const std::string& label,
51 art::Handle<std::vector<recob::Wire>> theWires;
52 evt.getByLabel(label, theWires);
54 if (!theWires.isValid()) {
55 mf::LogDebug(
"LArPandora") <<
" Failed to find wires... " << std::endl;
59 mf::LogDebug(
"LArPandora") <<
" Found: " << theWires->size() <<
" Wires " << std::endl;
62 for (
unsigned int i = 0; i < theWires->size(); ++i) {
63 const art::Ptr<recob::Wire> wire(theWires, i);
64 wireVector.push_back(wire);
71 const std::string& label,
74 art::Handle<std::vector<recob::Hit>> theHits;
75 evt.getByLabel(label, theHits);
77 if (!theHits.isValid()) {
78 mf::LogDebug(
"LArPandora") <<
" Failed to find hits... " << std::endl;
82 mf::LogDebug(
"LArPandora") <<
" Found: " << theHits->size() <<
" Hits " << std::endl;
85 for (
unsigned int i = 0; i < theHits->size(); ++i) {
86 const art::Ptr<recob::Hit> hit(theHits, i);
87 hitVector.push_back(hit);
94 const std::string& label,
97 art::Handle<std::vector<recob::PFParticle>> theParticles;
98 evt.getByLabel(label, theParticles);
100 if (!theParticles.isValid()) {
101 mf::LogDebug(
"LArPandora") <<
" Failed to find particles... " << std::endl;
105 mf::LogDebug(
"LArPandora") <<
" Found: " << theParticles->size() <<
" PFParticles "
109 for (
unsigned int i = 0; i < theParticles->size(); ++i) {
110 const art::Ptr<recob::PFParticle> particle(theParticles, i);
111 particleVector.push_back(particle);
118 const std::string& label,
124 evt, label, spacePointVector, spacePointsToHits, hitsToSpacePoints);
130 const std::string& label,
135 art::Handle<std::vector<recob::SpacePoint>> theSpacePoints;
136 evt.getByLabel(label, theSpacePoints);
138 if (!theSpacePoints.isValid()) {
139 mf::LogDebug(
"LArPandora") <<
" Failed to find spacepoints... " << std::endl;
143 mf::LogDebug(
"LArPandora") <<
" Found: " << theSpacePoints->size() <<
" SpacePoints "
147 art::FindOneP<recob::Hit> theHitAssns(theSpacePoints, evt, label);
148 for (
unsigned int i = 0; i < theSpacePoints->size(); ++i) {
149 const art::Ptr<recob::SpacePoint> spacepoint(theSpacePoints, i);
150 spacePointVector.push_back(spacepoint);
151 const art::Ptr<recob::Hit> hit = theHitAssns.at(i);
152 spacePointsToHits[spacepoint] = hit;
153 hitsToSpacePoints[hit] = spacepoint;
160 const std::string& label,
164 art::Handle<std::vector<recob::Cluster>> theClusters;
165 evt.getByLabel(label, theClusters);
167 if (!theClusters.isValid()) {
168 mf::LogDebug(
"LArPandora") <<
" Failed to find clusters... " << std::endl;
172 mf::LogDebug(
"LArPandora") <<
" Found: " << theClusters->size() <<
" Clusters " << std::endl;
175 art::FindManyP<recob::Hit> theHitAssns(theClusters, evt, label);
176 for (
unsigned int i = 0; i < theClusters->size(); ++i) {
177 const art::Ptr<recob::Cluster>
cluster(theClusters, i);
178 clusterVector.push_back(
cluster);
180 const std::vector<art::Ptr<recob::Hit>> hits = theHitAssns.at(i);
181 for (
unsigned int j = 0; j < hits.size(); ++j) {
182 const art::Ptr<recob::Hit> hit = hits.at(j);
183 clustersToHits[
cluster].push_back(hit);
191 const std::string& label,
195 art::Handle<std::vector<recob::PFParticle>> theParticles;
196 evt.getByLabel(label, theParticles);
198 if (!theParticles.isValid()) {
199 mf::LogDebug(
"LArPandora") <<
" Failed to find particles... " << std::endl;
203 mf::LogDebug(
"LArPandora") <<
" Found: " << theParticles->size() <<
" PFParticles "
207 art::FindManyP<recob::SpacePoint> theSpacePointAssns(theParticles, evt, label);
208 for (
unsigned int i = 0; i < theParticles->size(); ++i) {
209 const art::Ptr<recob::PFParticle> particle(theParticles, i);
210 particleVector.push_back(particle);
212 const std::vector<art::Ptr<recob::SpacePoint>> spacepoints = theSpacePointAssns.at(i);
213 for (
unsigned int j = 0; j < spacepoints.size(); ++j) {
214 const art::Ptr<recob::SpacePoint> spacepoint = spacepoints.at(j);
215 particlesToSpacePoints[particle].push_back(spacepoint);
223 const std::string& label,
227 art::Handle<std::vector<recob::PFParticle>> theParticles;
228 evt.getByLabel(label, theParticles);
230 if (!theParticles.isValid()) {
231 mf::LogDebug(
"LArPandora") <<
" Failed to find particles... " << std::endl;
235 mf::LogDebug(
"LArPandora") <<
" Found: " << theParticles->size() <<
" PFParticles "
239 art::FindManyP<recob::Cluster> theClusterAssns(theParticles, evt, label);
240 for (
unsigned int i = 0; i < theParticles->size(); ++i) {
241 const art::Ptr<recob::PFParticle> particle(theParticles, i);
242 particleVector.push_back(particle);
244 const std::vector<art::Ptr<recob::Cluster>> clusters = theClusterAssns.at(i);
245 for (
unsigned int j = 0; j < clusters.size(); ++j) {
246 const art::Ptr<recob::Cluster>
cluster = clusters.at(j);
247 particlesToClusters[particle].push_back(
cluster);
255 const std::string& label,
259 art::Handle<std::vector<recob::PFParticle>> theParticles;
260 evt.getByLabel(label, theParticles);
262 if (!theParticles.isValid()) {
263 mf::LogDebug(
"LArPandora") <<
" Failed to find particles... " << std::endl;
267 mf::LogDebug(
"LArPandora") <<
" Found: " << theParticles->size() <<
" PFParticles "
271 art::FindManyP<larpandoraobj::PFParticleMetadata> theMetadataAssns(theParticles, evt, label);
272 for (
unsigned int i = 0; i < theParticles->size(); ++i) {
273 const art::Ptr<recob::PFParticle> particle(theParticles, i);
274 particleVector.push_back(particle);
276 const std::vector<art::Ptr<larpandoraobj::PFParticleMetadata>> pfParticleMetadataList =
277 theMetadataAssns.at(i);
278 for (
unsigned int j = 0; j < pfParticleMetadataList.size(); ++j) {
279 const art::Ptr<larpandoraobj::PFParticleMetadata> pfParticleMetadata =
280 pfParticleMetadataList.at(j);
281 particlesToMetadata[particle].push_back(pfParticleMetadata);
289 const std::string& label,
293 art::Handle<std::vector<recob::Shower>> theShowers;
294 evt.getByLabel(label, theShowers);
296 if (!theShowers.isValid()) {
297 mf::LogDebug(
"LArPandora") <<
" Failed to find showers... " << std::endl;
301 mf::LogDebug(
"LArPandora") <<
" Found: " << theShowers->size() <<
" Showers " << std::endl;
304 art::FindManyP<recob::PFParticle> theShowerAssns(theShowers, evt, label);
305 for (
unsigned int i = 0; i < theShowers->size(); ++i) {
306 const art::Ptr<recob::Shower>
shower(theShowers, i);
307 showerVector.push_back(
shower);
309 const std::vector<art::Ptr<recob::PFParticle>> particles = theShowerAssns.at(i);
310 for (
unsigned int j = 0; j < particles.size(); ++j) {
311 const art::Ptr<recob::PFParticle> particle = particles.at(j);
312 particlesToShowers[particle].push_back(
shower);
320 const std::string& label,
324 art::Handle<std::vector<recob::Track>> theTracks;
325 evt.getByLabel(label, theTracks);
327 if (!theTracks.isValid()) {
328 mf::LogDebug(
"LArPandora") <<
" Failed to find tracks... " << std::endl;
332 mf::LogDebug(
"LArPandora") <<
" Found: " << theTracks->size() <<
" Tracks " << std::endl;
335 art::FindManyP<recob::PFParticle> theTrackAssns(theTracks, evt, label);
336 for (
unsigned int i = 0; i < theTracks->size(); ++i) {
337 const art::Ptr<recob::Track> track(theTracks, i);
338 trackVector.push_back(track);
340 const std::vector<art::Ptr<recob::PFParticle>> particles = theTrackAssns.at(i);
341 for (
unsigned int j = 0; j < particles.size(); ++j) {
342 const art::Ptr<recob::PFParticle> particle = particles.at(j);
343 particlesToTracks[particle].push_back(track);
351 const std::string& label,
355 art::Handle<std::vector<recob::Track>> theTracks;
356 evt.getByLabel(label, theTracks);
358 if (!theTracks.isValid()) {
359 mf::LogDebug(
"LArPandora") <<
" Failed to find tracks... " << std::endl;
363 mf::LogDebug(
"LArPandora") <<
" Found: " << theTracks->size() <<
" Tracks " << std::endl;
366 art::FindManyP<recob::Hit> theHitAssns(theTracks, evt, label);
367 for (
unsigned int i = 0; i < theTracks->size(); ++i) {
368 const art::Ptr<recob::Track> track(theTracks, i);
369 trackVector.push_back(track);
371 const std::vector<art::Ptr<recob::Hit>> hits = theHitAssns.at(i);
372 for (
unsigned int j = 0; j < hits.size(); ++j) {
373 const art::Ptr<recob::Hit> hit = hits.at(j);
374 tracksToHits[track].push_back(hit);
382 const std::string& label,
386 art::Handle<std::vector<recob::Shower>> theShowers;
387 evt.getByLabel(label, theShowers);
389 if (!theShowers.isValid()) {
390 mf::LogDebug(
"LArPandora") <<
" Failed to find showers... " << std::endl;
394 mf::LogDebug(
"LArPandora") <<
" Found: " << theShowers->size() <<
" Showers " << std::endl;
397 art::FindManyP<recob::Hit> theHitAssns(theShowers, evt, label);
398 for (
unsigned int i = 0; i < theShowers->size(); ++i) {
399 const art::Ptr<recob::Shower>
shower(theShowers, i);
400 showerVector.push_back(
shower);
402 const std::vector<art::Ptr<recob::Hit>> hits = theHitAssns.at(i);
403 for (
unsigned int j = 0; j < hits.size(); ++j) {
404 const art::Ptr<recob::Hit> hit = hits.at(j);
405 showersToHits[
shower].push_back(hit);
413 const std::string& label,
417 art::Handle<std::vector<recob::Seed>> theSeeds;
418 evt.getByLabel(label, theSeeds);
420 if (!theSeeds.isValid()) {
421 mf::LogDebug(
"LArPandora") <<
" Failed to find seeds... " << std::endl;
425 mf::LogDebug(
"LArPandora") <<
" Found: " << theSeeds->size() <<
" Seeds " << std::endl;
428 art::FindManyP<recob::PFParticle> theSeedAssns(theSeeds, evt, label);
429 for (
unsigned int i = 0; i < theSeeds->size(); ++i) {
430 const art::Ptr<recob::Seed> seed(theSeeds, i);
431 seedVector.push_back(seed);
433 const std::vector<art::Ptr<recob::PFParticle>> particles = theSeedAssns.at(i);
434 for (
unsigned int j = 0; j < particles.size(); ++j) {
435 const art::Ptr<recob::PFParticle> particle = particles.at(j);
436 particlesToSeeds[particle].push_back(seed);
444 const std::string& label,
448 art::Handle<std::vector<recob::Seed>> theSeeds;
449 evt.getByLabel(label, theSeeds);
451 if (!theSeeds.isValid()) {
452 mf::LogDebug(
"LArPandora") <<
" Failed to find seeds... " << std::endl;
456 mf::LogDebug(
"LArPandora") <<
" Found: " << theSeeds->size() <<
" Seeds " << std::endl;
459 art::FindOneP<recob::Hit> theHitAssns(theSeeds, evt, label);
461 if (!theHitAssns.isValid()) {
462 mf::LogDebug(
"LArPandora") <<
" Failed to find seed associations... " << std::endl;
466 for (
unsigned int i = 0; i < theSeeds->size(); ++i) {
467 const art::Ptr<recob::Seed> seed(theSeeds, i);
468 seedVector.push_back(seed);
469 const art::Ptr<recob::Hit> hit = theHitAssns.at(i);
470 seedsToHits[seed] = hit;
477 const std::string& label,
481 art::Handle<std::vector<recob::Vertex>> theVertices;
482 evt.getByLabel(label, theVertices);
484 if (!theVertices.isValid()) {
485 mf::LogDebug(
"LArPandora") <<
" Failed to find vertices... " << std::endl;
489 mf::LogDebug(
"LArPandora") <<
" Found: " << theVertices->size() <<
" Vertices " << std::endl;
492 art::FindManyP<recob::PFParticle> theVerticesAssns(theVertices, evt, label);
493 for (
unsigned int i = 0; i < theVertices->size(); ++i) {
494 const art::Ptr<recob::Vertex> vertex(theVertices, i);
495 vertexVector.push_back(vertex);
497 const std::vector<art::Ptr<recob::PFParticle>> particles = theVerticesAssns.at(i);
498 for (
unsigned int j = 0; j < particles.size(); ++j) {
499 const art::Ptr<recob::PFParticle> particle = particles.at(j);
500 particlesToVertices[particle].push_back(vertex);
518 for (PFParticleVector::const_iterator iter1 = particleVector.begin(),
519 iterEnd1 = particleVector.end();
522 const art::Ptr<recob::PFParticle> particle = *iter1;
523 particleMap[particle->Self()] = particle;
527 for (PFParticlesToSpacePoints::const_iterator iter1 = particlesToSpacePoints.begin(),
528 iterEnd1 = particlesToSpacePoints.end();
531 const art::Ptr<recob::PFParticle> thisParticle = iter1->first;
532 const art::Ptr<recob::PFParticle> particle(
543 for (SpacePointVector::const_iterator iter2 = spacePointVector.begin(),
544 iterEnd2 = spacePointVector.end();
547 const art::Ptr<recob::SpacePoint> spacepoint = *iter2;
549 SpacePointsToHits::const_iterator iter3 = spacePointsToHits.find(spacepoint);
550 if (spacePointsToHits.end() == iter3)
551 throw cet::exception(
"LArPandora") <<
" PandoraCollector::BuildPFParticleHitMaps --- "
552 "Found a space point without an associated hit ";
554 const art::Ptr<recob::Hit> hit = iter3->second;
556 particlesToHits[particle].push_back(hit);
557 hitsToParticles[hit] = particle;
574 for (PFParticleVector::const_iterator iter1 = particleVector.begin(),
575 iterEnd1 = particleVector.end();
578 const art::Ptr<recob::PFParticle> particle = *iter1;
579 particleMap[particle->Self()] = particle;
583 for (PFParticlesToClusters::const_iterator iter1 = particlesToClusters.begin(),
584 iterEnd1 = particlesToClusters.end();
587 const art::Ptr<recob::PFParticle> thisParticle = iter1->first;
588 const art::Ptr<recob::PFParticle> particle(
598 for (ClusterVector::const_iterator iter2 = clusterVector.begin(),
599 iterEnd2 = clusterVector.end();
602 const art::Ptr<recob::Cluster>
cluster = *iter2;
604 ClustersToHits::const_iterator iter3 = clustersToHits.find(
cluster);
605 if (clustersToHits.end() == iter3)
606 throw cet::exception(
"LArPandora") <<
" PandoraCollector::BuildPFParticleHitMaps --- "
607 "Found a space point without an associated hit ";
609 const HitVector& hitVector = iter3->second;
610 for (HitVector::const_iterator iter4 = hitVector.begin(), iterEnd4 = hitVector.end();
613 const art::Ptr<recob::Hit> hit = *iter4;
615 particlesToHits[particle].push_back(hit);
616 hitsToParticles[hit] = particle;
625 const std::string& label,
629 const bool useClusters)
632 evt, label, label, particlesToHits, hitsToParticles, daughterMode, useClusters);
638 const std::string& label_pfpart,
639 const std::string& label_middle,
643 const bool useClusters)
673 evt, label_pfpart, particleVector, particlesToSpacePoints);
677 particlesToSpacePoints,
690 for (PFParticleVector::const_iterator iter = inputParticles.begin(),
691 iterEnd = inputParticles.end();
694 const art::Ptr<recob::PFParticle> particle = *iter;
708 for (PFParticleVector::const_iterator iter = inputParticles.begin(),
709 iterEnd = inputParticles.end();
712 const art::Ptr<recob::PFParticle> particle = *iter;
713 particleMap[particle->Self()] = particle;
717 for (PFParticleVector::const_iterator iter = inputParticles.begin(),
718 iterEnd = inputParticles.end();
721 const art::Ptr<recob::PFParticle> particle = *iter;
724 outputParticles.push_back(particle);
731 const std::string& label,
735 art::Handle<std::vector<anab::CosmicTag>> theCosmicTags;
736 evt.getByLabel(label, theCosmicTags);
738 if (theCosmicTags.isValid()) {
739 art::FindOneP<recob::Track> theCosmicAssns(
740 theCosmicTags, evt, label);
741 for (
unsigned int i = 0; i < theCosmicTags->size(); ++i) {
742 const art::Ptr<anab::CosmicTag> cosmicTag(theCosmicTags, i);
743 const art::Ptr<recob::Track> track = theCosmicAssns.at(i);
744 tracksToCosmicTags[track].push_back(
746 cosmicTagVector.push_back(cosmicTag);
754 const std::string& label,
758 art::Handle<std::vector<anab::T0>> theT0s;
759 evt.getByLabel(label, theT0s);
761 if (theT0s.isValid()) {
762 art::FindManyP<recob::PFParticle> theAssns(theT0s, evt, label);
763 for (
unsigned int i = 0; i < theT0s->size(); ++i) {
764 const art::Ptr<anab::T0> theT0(theT0s, i);
765 t0Vector.push_back(theT0);
767 const std::vector<art::Ptr<recob::PFParticle>> particles = theAssns.at(i);
768 for (
unsigned int j = 0; j < particles.size(); ++j) {
769 const art::Ptr<recob::PFParticle> theParticle = particles.at(j);
770 particlesToT0s[theParticle].push_back(
780 const std::string& label,
782 bool& areSimChannelsValid)
784 art::Handle<std::vector<sim::SimChannel>> theSimChannels;
785 evt.getByLabel(label, theSimChannels);
787 if (!theSimChannels.isValid()) {
788 mf::LogDebug(
"LArPandora") <<
" Failed to find sim channels... " << std::endl;
789 areSimChannelsValid =
false;
793 mf::LogDebug(
"LArPandora") <<
" Found: " << theSimChannels->size() <<
" SimChannels "
795 areSimChannelsValid =
true;
798 for (
unsigned int i = 0; i < theSimChannels->size(); ++i) {
799 const art::Ptr<sim::SimChannel> channel(theSimChannels, i);
800 simChannelVector.push_back(channel);
807 const std::string& label,
810 art::Handle<RawMCParticleVector> theParticles;
811 evt.getByLabel(label, theParticles);
813 if (!theParticles.isValid()) {
814 mf::LogDebug(
"LArPandora") <<
" Failed to find MC particles... " << std::endl;
818 mf::LogDebug(
"LArPandora") <<
" Found: " << theParticles->size() <<
" MC particles "
822 for (
unsigned int i = 0; i < theParticles->size(); ++i) {
823 const art::Ptr<simb::MCParticle> particle(theParticles, i);
824 particleVector.push_back(particle);
831 const std::string& label,
834 art::Handle<std::vector<simb::MCTruth>> mcTruthBlocks;
835 evt.getByLabel(label, mcTruthBlocks);
837 if (!mcTruthBlocks.isValid()) {
838 mf::LogDebug(
"LArPandora") <<
" Failed to find MC truth blocks from generator... "
843 mf::LogDebug(
"LArPandora") <<
" Found: " << mcTruthBlocks->size() <<
" MC truth blocks "
847 if (mcTruthBlocks->size() != 1)
848 throw cet::exception(
"LArPandora") <<
" PandoraCollector::CollectGeneratorMCParticles --- "
849 "Unexpected number of MC truth blocks ";
851 const art::Ptr<simb::MCTruth> mcTruth(mcTruthBlocks, 0);
853 for (
int i = 0; i < mcTruth->NParticles(); ++i) {
854 particleVector.push_back(mcTruth->GetParticle(i));
861 const std::string& label,
865 art::Handle<RawMCParticleVector> theParticles;
866 evt.getByLabel(label, theParticles);
868 if (!theParticles.isValid()) {
869 mf::LogDebug(
"LArPandora") <<
" Failed to find MC particles... " << std::endl;
873 mf::LogDebug(
"LArPandora") <<
" Found: " << theParticles->size() <<
" MC particles "
877 art::FindOneP<simb::MCTruth> theTruthAssns(theParticles, evt, label);
879 for (
unsigned int i = 0, iEnd = theParticles->size(); i < iEnd; ++i) {
880 const art::Ptr<simb::MCParticle> particle(theParticles, i);
881 const art::Ptr<simb::MCTruth> truth(theTruthAssns.at(i));
882 truthToParticles[truth].push_back(particle);
883 particlesToTruth[particle] = truth;
894 auto const clock_data =
895 art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
899 for (SimChannelVector::const_iterator iter = simChannelVector.begin(),
900 iterEnd = simChannelVector.end();
903 const art::Ptr<sim::SimChannel> simChannel = *iter;
904 simChannelMap.insert(SimChannelMap::value_type(simChannel->Channel(), simChannel));
907 for (HitVector::const_iterator iter = hitVector.begin(), iterEnd = hitVector.end();
910 const art::Ptr<recob::Hit> hit = *iter;
912 SimChannelMap::const_iterator sIter = simChannelMap.find(hit->Channel());
913 if (simChannelMap.end() == sIter)
continue;
916 const raw::TDCtick_t start_tick(clock_data.TPCTick2TDC(hit->PeakTimeMinusRMS()));
917 const raw::TDCtick_t end_tick(clock_data.TPCTick2TDC(hit->PeakTimePlusRMS()));
918 const unsigned int start_tdc((start_tick < 0) ? 0 : start_tick);
919 const unsigned int end_tdc(end_tick);
921 if (start_tdc > end_tdc)
continue;
923 const art::Ptr<sim::SimChannel> simChannel = sIter->second;
924 const TrackIDEVector trackCollection(simChannel->TrackIDEs(start_tdc, end_tdc));
926 if (trackCollection.empty())
continue;
928 for (
unsigned int iTrack = 0, iTrackEnd = trackCollection.size(); iTrack < iTrackEnd;
930 const sim::TrackIDE trackIDE = trackCollection.at(iTrack);
931 hitsToTrackIDEs[hit].push_back(trackIDE);
947 for (MCTruthToMCParticles::const_iterator iter1 = truthToParticles.begin(),
948 iterEnd1 = truthToParticles.end();
952 for (MCParticleVector::const_iterator iter2 = particleVector.begin(),
953 iterEnd2 = particleVector.end();
956 const art::Ptr<simb::MCParticle> particle = *iter2;
957 particleMap[particle->TrackId()] = particle;
962 for (HitsToTrackIDEs::const_iterator iter1 = hitsToTrackIDEs.begin(),
963 iterEnd1 = hitsToTrackIDEs.end();
966 const art::Ptr<recob::Hit> hit = iter1->first;
970 float bestEnergyFrac(0.f);
972 for (TrackIDEVector::const_iterator iter2 = trackCollection.begin(),
973 iterEnd2 = trackCollection.end();
976 const sim::TrackIDE& trackIDE = *iter2;
977 const int trackID(std::abs(trackIDE.trackID));
978 const float energyFrac(trackIDE.energyFrac);
980 if (energyFrac > bestEnergyFrac) {
981 bestEnergyFrac = energyFrac;
982 bestTrackID = trackID;
986 if (bestTrackID >= 0) {
987 MCParticleMap::const_iterator iter3 = particleMap.find(bestTrackID);
988 if (particleMap.end() == iter3)
989 throw cet::exception(
"LArPandora") <<
" PandoraCollector::BuildMCParticleHitMaps --- "
990 "Found a track ID without an MC Particle ";
993 const art::Ptr<simb::MCParticle> thisParticle = iter3->second;
994 const art::Ptr<simb::MCParticle> primaryParticle(
996 const art::Ptr<simb::MCParticle> selectedParticle(
997 (
kAddDaughters == daughterMode) ? primaryParticle : thisParticle);
999 if ((
kIgnoreDaughters == daughterMode) && (selectedParticle != primaryParticle))
continue;
1003 particlesToHits[selectedParticle].push_back(hit);
1004 hitsToParticles[hit] = selectedParticle;
1006 catch (cet::exception& e) {
1015 const std::string& label,
1026 bool areSimChannelsValid(
false);
1032 hitsToTrackIDEs, truthToParticles, particlesToHits, hitsToParticles, daughterMode);
1038 const std::string& hitLabel,
1039 const std::string& backtrackLabel,
1043 art::Handle<std::vector<recob::Hit>> theHits;
1044 evt.getByLabel(hitLabel, theHits);
1046 if (!theHits.isValid()) {
1047 mf::LogDebug(
"LArPandora") <<
" Failed to find hits... " << std::endl;
1053 for (
unsigned int i = 0; i < theHits->size(); ++i) {
1054 const art::Ptr<recob::Hit> hit(theHits, i);
1055 hitVector.push_back(hit);
1059 std::vector<anab::BackTrackerHitMatchingData const*> backtrackerVector;
1063 art::FindManyP<simb::MCParticle, anab::BackTrackerHitMatchingData> particles_per_hit(
1064 theHits, evt, backtrackLabel);
1066 if (!particles_per_hit.isValid()) {
1067 mf::LogDebug(
"LArPandora") <<
" Failed to find reco-truth matching... " << std::endl;
1072 for (HitVector::const_iterator iter = hitVector.begin(), iterEnd = hitVector.end();
1075 const art::Ptr<recob::Hit> hit = *iter;
1077 particleVector.clear();
1078 backtrackerVector.clear();
1079 particles_per_hit.get(hit.key(), particleVector, backtrackerVector);
1081 for (
unsigned int j = 0; j < particleVector.size(); ++j) {
1082 const art::Ptr<simb::MCParticle> particle = particleVector[j];
1084 sim::TrackIDE trackIDE;
1085 trackIDE.trackID = particle->TrackId();
1086 trackIDE.energy = backtrackerVector[j]->energy;
1087 trackIDE.energyFrac = backtrackerVector[j]->ideFraction;
1089 hitsToTrackIDEs[hit].push_back(trackIDE);
1097 const std::string& truthLabel,
1098 const std::string& hitLabel,
1099 const std::string& backtrackLabel,
1111 hitsToTrackIDEs, truthToParticles, particlesToHits, hitsToParticles, daughterMode);
1116 template <
typename T>
1118 const std::string& label,
1119 const std::vector<art::Ptr<T>>& inputVector,
1124 art::Handle<std::vector<T>> handle;
1125 evt.getByLabel(label, handle);
1126 art::FindManyP<recob::Hit> hitAssoc(handle, evt, label);
1128 if (indexVector !=
nullptr) {
1129 if (inputVector.size() != indexVector->size())
1130 throw cet::exception(
"LArPandora") <<
" PandoraHelper::GetAssociatedHits --- trying to use "
1131 "an index vector not matching input vector";
1134 for (
int index : (*indexVector)) {
1135 const art::Ptr<T>& element = inputVector.at(index);
1136 const HitVector& hits = hitAssoc.at(element.key());
1137 associatedHits.insert(associatedHits.end(), hits.begin(), hits.end());
1142 for (
const art::Ptr<T>& element : inputVector) {
1143 const HitVector& hits = hitAssoc.at(element.key());
1144 associatedHits.insert(associatedHits.end(), hits.begin(), hits.end());
1154 for (MCParticleVector::const_iterator iter = particleVector.begin(),
1155 iterEnd = particleVector.end();
1158 const art::Ptr<simb::MCParticle> particle = *iter;
1159 particleMap[particle->TrackId()] = particle;
1160 particleMap[particle->TrackId()] = particle;
1169 for (PFParticleVector::const_iterator iter = particleVector.begin(),
1170 iterEnd = particleVector.end();
1173 const art::Ptr<recob::PFParticle> particle = *iter;
1174 particleMap[particle->Self()] = particle;
1182 const art::Ptr<recob::PFParticle> inputParticle)
1185 int primaryTrackID(inputParticle->Self());
1187 if (!inputParticle->IsPrimary()) {
1189 PFParticleMap::const_iterator pIter1 = particleMap.find(primaryTrackID);
1190 if (particleMap.end() == pIter1)
1191 throw cet::exception(
"LArPandora") <<
" PandoraCollector::GetParentPFParticle --- Found "
1192 "a PFParticle without a particle ID ";
1194 const art::Ptr<recob::PFParticle> primaryParticle = pIter1->second;
1195 if (primaryParticle->IsPrimary())
break;
1197 primaryTrackID = primaryParticle->Parent();
1201 PFParticleMap::const_iterator pIter2 = particleMap.find(primaryTrackID);
1202 if (particleMap.end() == pIter2)
1203 throw cet::exception(
"LArPandora")
1204 <<
" PandoraCollector::GetParentPFParticle --- Found a PFParticle without a particle ID ";
1206 const art::Ptr<recob::PFParticle> outputParticle = pIter2->second;
1207 return outputParticle;
1214 const art::Ptr<recob::PFParticle> inputParticle)
1217 int primaryTrackID(inputParticle->Self());
1219 if (!inputParticle->IsPrimary()) {
1220 int parentTrackID(inputParticle->Parent());
1223 PFParticleMap::const_iterator pIter1 = particleMap.find(parentTrackID);
1224 if (particleMap.end() == pIter1)
1225 throw cet::exception(
"LArPandora") <<
" PandoraCollector::GetFinalStatePFParticle --- "
1226 "Found a PFParticle without a particle ID ";
1228 const art::Ptr<recob::PFParticle> parentParticle = pIter1->second;
1231 primaryTrackID = parentTrackID;
1233 if (parentParticle->IsPrimary())
break;
1235 parentTrackID = parentParticle->Parent();
1239 PFParticleMap::const_iterator pIter2 = particleMap.find(primaryTrackID);
1240 if (particleMap.end() == pIter2)
1241 throw cet::exception(
"LArPandora") <<
" PandoraCollector::GetFinalStatePFParticle --- Found "
1242 "a PFParticle without a particle ID ";
1244 const art::Ptr<recob::PFParticle> outputParticle = pIter2->second;
1245 return outputParticle;
1252 const art::Ptr<simb::MCParticle> inputParticle)
1255 int primaryTrackID(inputParticle->TrackId());
1256 int parentTrackID(inputParticle->Mother());
1259 MCParticleMap::const_iterator pIter1 = particleMap.find(parentTrackID);
1260 if (particleMap.end() == pIter1)
break;
1262 const art::Ptr<simb::MCParticle> particle = pIter1->second;
1264 primaryTrackID = parentTrackID;
1265 parentTrackID = particle->Mother();
1268 MCParticleMap::const_iterator pIter2 = particleMap.find(primaryTrackID);
1269 if (particleMap.end() == pIter2)
1270 throw cet::exception(
"LArPandora")
1271 <<
" PandoraCollector::GetParentMCParticle --- Found a track ID without a MC particle ";
1273 const art::Ptr<simb::MCParticle> outputParticle = pIter2->second;
1274 return outputParticle;
1281 const art::Ptr<simb::MCParticle> inputParticle)
1286 int trackID(inputParticle->TrackId());
1289 MCParticleMap::const_iterator pIter = particleMap.find(trackID);
1290 if (particleMap.end() == pIter)
break;
1292 const art::Ptr<simb::MCParticle> particle = pIter->second;
1293 mcVector.push_back(particle);
1295 trackID = particle->Mother();
1299 for (MCParticleVector::const_reverse_iterator iter = mcVector.rbegin(),
1300 iterEnd = mcVector.rend();
1303 const art::Ptr<simb::MCParticle> nextParticle = *iter;
1308 throw cet::exception(
"LArPandora");
1315 const art::Ptr<recob::PFParticle> particle)
1317 PFParticlesToTracks::const_iterator tIter = particlesToTracks.find(particle);
1319 if (particlesToTracks.end() == tIter || tIter->second.empty())
1320 throw cet::exception(
"LArPandora")
1321 <<
" PandoraCollector::GetPrimaryTrack --- Failed to find associated track ";
1323 if (tIter->second.size() != 1)
1324 throw cet::exception(
"LArPandora")
1325 <<
" PandoraCollector::GetPrimaryTrack --- Found more than one associated track ";
1327 const art::Ptr<recob::Track> primaryTrack = *(tIter->second.begin());
1328 return primaryTrack;
1334 const art::Ptr<recob::PFParticle> inputParticle)
1337 int nGenerations(0);
1338 int primaryTrackID(inputParticle->Self());
1341 PFParticleMap::const_iterator pIter = particleMap.find(primaryTrackID);
1342 if (particleMap.end() == pIter)
1343 throw cet::exception(
"LArPandora")
1344 <<
" PandoraCollector::GetGeneration --- Found a PFParticle without a particle ID ";
1348 const art::Ptr<recob::PFParticle> primaryParticle = pIter->second;
1349 if (primaryParticle->IsPrimary())
break;
1351 primaryTrackID = primaryParticle->Parent();
1354 return nGenerations;
1360 const art::Ptr<recob::PFParticle> daughterParticle)
1362 art::Ptr<recob::PFParticle> parentParticle =
1367 if (parentParticle->IsPrimary())
return 0;
1369 const int parentID(parentParticle->Parent());
1371 PFParticleMap::const_iterator pIter = particleMap.find(parentID);
1372 if (particleMap.end() == pIter)
1373 throw cet::exception(
"LArPandora")
1374 <<
" PandoraCollector::GetParentNeutrino --- Found a PFParticle without a particle ID ";
1376 const art::Ptr<recob::PFParticle> neutrinoParticle = pIter->second;
1377 return neutrinoParticle->PdgCode();
1383 const art::Ptr<recob::PFParticle> daughterParticle)
1387 if (daughterParticle->IsPrimary())
return true;
1389 const int parentID(daughterParticle->Parent());
1391 PFParticleMap::const_iterator pIter = particleMap.find(parentID);
1392 if (particleMap.end() == pIter)
1393 throw cet::exception(
"LArPandora")
1394 <<
" PandoraCollector::IsFinalState --- Found a PFParticle without a particle ID ";
1396 const art::Ptr<recob::PFParticle> parentParticle = pIter->second;
1407 const int pdg(particle->PdgCode());
1410 return ((pandora::NU_E == std::abs(pdg)) || (pandora::NU_MU == std::abs(pdg)) ||
1411 (pandora::NU_TAU == std::abs(pdg)));
1418 const int pdg(particle->PdgCode());
1421 return ((pandora::MU_MINUS == std::abs(pdg)) || (pandora::PI_PLUS == std::abs(pdg)) ||
1422 (pandora::PROTON == std::abs(pdg)) || (pandora::K_PLUS == std::abs(pdg)));
1429 const int pdg(particle->PdgCode());
1432 return ((pandora::E_MINUS == std::abs(pdg)) || (pandora::PHOTON == std::abs(pdg)));
1440 const int pdg(particle->PdgCode());
1442 if ((pandora::E_MINUS == std::abs(pdg)) || (pandora::MU_MINUS == std::abs(pdg)) ||
1443 (pandora::PROTON == std::abs(pdg)) || (pandora::PI_PLUS == std::abs(pdg)) ||
1444 (pandora::K_PLUS == std::abs(pdg)) || (pandora::SIGMA_MINUS == std::abs(pdg)) ||
1445 (pandora::SIGMA_PLUS == std::abs(pdg)) || (pandora::HYPERON_MINUS == std::abs(pdg)) ||
1446 (pandora::PHOTON == std::abs(pdg)) || (pandora::NEUTRON == std::abs(pdg)))
1467 const std::vector<art::Ptr<recob::Cluster>>&,
1473 const std::vector<art::Ptr<recob::SpacePoint>>&,
helper function for LArPandoraInterface producer module
Header file defining relevant internal typedefs, sort and string conversion functions.
Header file for the particle flow object class.
static void CollectShowers(const art::Event &evt, const std::string &label, ShowerVector &showerVector, PFParticlesToShowers &particlesToShowers)
Collect the reconstructed PFParticles and associated Showers from the ART event record.
static void CollectClusters(const art::Event &evt, const std::string &label, ClusterVector &clusterVector, ClustersToHits &clustersToHits)
Collect the reconstructed Clusters and associated hits from the ART event record.
static void SelectNeutrinoPFParticles(const PFParticleVector &inputParticles, PFParticleVector &outputParticles)
Select reconstructed neutrino particles from a list of all reconstructed particles.
static void CollectHits(const art::Event &evt, const std::string &label, HitVector &hitVector)
Collect the reconstructed Hits from the ART event record.
DaughterMode
DaughterMode enumeration.
static void BuildMCParticleMap(const MCParticleVector &particleVector, MCParticleMap &particleMap)
Build particle maps for true particles.
static larpandoraobj::PFParticleMetadata GetPFParticleMetadata(const pandora::ParticleFlowObject *const pPfo)
Get metadata associated to a PFO.
static void CollectVertices(const art::Event &evt, const std::string &label, VertexVector &vertexVector, PFParticlesToVertices &particlesToVertices)
Collect the reconstructed PFParticles and associated Vertices from the ART event record.
static art::Ptr< simb::MCParticle > GetFinalStateMCParticle(const MCParticleMap &particleMap, const art::Ptr< simb::MCParticle > daughterParticle)
Return the final-state parent particle by navigating up the chain of parent/daughter associations.
static void BuildPFParticleMap(const PFParticleVector &particleVector, PFParticleMap &particleMap)
Build particle maps for reconstructed particles.
static void CollectSeeds(const art::Event &evt, const std::string &label, SeedVector &seedVector, PFParticlesToSeeds &particlesToSeeds)
Collect the reconstructed PFParticles and associated Seeds from the ART event record.
static void CollectPFParticleMetadata(const art::Event &evt, const std::string &label, PFParticleVector &particleVector, PFParticlesToMetadata &particlesToMetadata)
Collect the reconstructed PFParticle Metadata from the ART event record.
static art::Ptr< recob::PFParticle > GetFinalStatePFParticle(const PFParticleMap &particleMap, const art::Ptr< recob::PFParticle > daughterParticle)
Return the final-state parent particle by navigating up the chain of parent/daughter associations.
static void CollectSpacePoints(const art::Event &evt, const std::string &label, SpacePointVector &spacePointVector, SpacePointsToHits &spacePointsToHits)
Collect the reconstructed SpacePoints and associated hits from the ART event record.
static art::Ptr< simb::MCParticle > GetParentMCParticle(const MCParticleMap &particleMap, const art::Ptr< simb::MCParticle > daughterParticle)
Return the top-level parent particle by navigating up the chain of parent/daughter associations.
static void CollectT0s(const art::Event &evt, const std::string &label, T0Vector &t0Vector, PFParticlesToT0s &particlesToT0s)
Collect a vector of T0s from the ART event record.
static void SelectFinalStatePFParticles(const PFParticleVector &inputParticles, PFParticleVector &outputParticles)
Select final-state reconstructed particles from a list of all reconstructed particles.
static bool IsVisible(const art::Ptr< simb::MCParticle > particle)
Determine whether a particle is visible (i.e. long-lived charged particle)
static void GetAssociatedHits(const art::Event &evt, const std::string &label, const std::vector< art::Ptr< T > > &inputVector, HitVector &associatedHits, const pandora::IntVector *const indexVector=nullptr)
Get all hits associated with input clusters.
static void BuildMCParticleHitMaps(const art::Event &evt, const HitVector &hitVector, const SimChannelVector &simChannelVector, HitsToTrackIDEs &hitsToTrackIDEs)
Collect the links from reconstructed hits to their true energy deposits.
static art::Ptr< recob::PFParticle > GetParentPFParticle(const PFParticleMap &particleMap, const art::Ptr< recob::PFParticle > daughterParticle)
Return the top-level parent particle by navigating up the chain of parent/daughter associations.
static bool IsTrack(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as track-like.
static void CollectSimChannels(const art::Event &evt, const std::string &label, SimChannelVector &simChannelVector, bool &areSimChannelsValid)
Collect a vector of SimChannel objects from the ART event record.
static void CollectWires(const art::Event &evt, const std::string &label, WireVector &wireVector)
Collect the reconstructed wires from the ART event record.
static int GetParentNeutrino(const PFParticleMap &particleMap, const art::Ptr< recob::PFParticle > daughterParticle)
Return the parent neutrino PDG code (or zero for cosmics) for a given reconstructed particle.
static void CollectPFParticles(const art::Event &evt, const std::string &label, PFParticleVector &particleVector)
Collect the reconstructed PFParticles from the ART event record.
static void CollectCosmicTags(const art::Event &evt, const std::string &label, CosmicTagVector &cosmicTagVector, TracksToCosmicTags &tracksToCosmicTags)
Collect a vector of cosmic tags from the ART event record.
static bool IsFinalState(const PFParticleMap &particleMap, const art::Ptr< recob::PFParticle > daughterParticle)
Determine whether a particle has been reconstructed as a final-state particle.
static void CollectGeneratorMCParticles(const art::Event &evt, const std::string &label, RawMCParticleVector &particleVector)
Collect a vector of MCParticle objects from the generator in the ART event record....
static void CollectTracks(const art::Event &evt, const std::string &label, TrackVector &trackVector, PFParticlesToTracks &particlesToTracks)
Collect the reconstructed PFParticles and associated Tracks from the ART event record.
static bool IsNeutrino(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as a neutrino.
static int GetGeneration(const PFParticleMap &particleMap, const art::Ptr< recob::PFParticle > daughterParticle)
Return the generation of this particle (first generation if primary)
static art::Ptr< recob::Track > GetPrimaryTrack(const PFParticlesToTracks &particlesToTracks, const art::Ptr< recob::PFParticle > particle)
Return the primary track associated with a PFParticle.
static void BuildPFParticleHitMaps(const PFParticleVector &particleVector, const PFParticlesToSpacePoints &particlesToSpacePoints, const SpacePointsToHits &spacePointsToHits, PFParticlesToHits &particlesToHits, HitsToPFParticles &hitsToParticles, const DaughterMode daughterMode=kUseDaughters)
Build mapping between PFParticles and Hits using PFParticle/SpacePoint/Hit maps.
static void CollectMCParticles(const art::Event &evt, const std::string &label, MCParticleVector &particleVector)
Collect a vector of MCParticle objects from the ART event record.
static bool IsShower(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as shower-like.
ParticleFlowObject class.
const PropertiesMap & GetPropertiesMap() const
Get the map from registered property name to floating point property value.
std::map< art::Ptr< recob::PFParticle >, T0Vector > PFParticlesToT0s
std::vector< art::Ptr< anab::T0 > > T0Vector
std::map< int, art::Ptr< recob::PFParticle > > PFParticleMap
std::vector< art::Ptr< recob::Track > > TrackVector
std::map< int, art::Ptr< simb::MCParticle > > MCParticleMap
std::map< art::Ptr< recob::Seed >, art::Ptr< recob::Hit > > SeedsToHits
std::map< art::Ptr< simb::MCParticle >, art::Ptr< simb::MCTruth > > MCParticlesToMCTruth
std::vector< sim::TrackIDE > TrackIDEVector
std::map< art::Ptr< recob::Hit >, TrackIDEVector > HitsToTrackIDEs
std::vector< art::Ptr< recob::Shower > > ShowerVector
std::map< art::Ptr< recob::PFParticle >, ClusterVector > PFParticlesToClusters
std::vector< art::Ptr< recob::Vertex > > VertexVector
std::map< art::Ptr< recob::PFParticle >, ShowerVector > PFParticlesToShowers
std::vector< simb::MCParticle > RawMCParticleVector
std::vector< art::Ptr< sim::SimChannel > > SimChannelVector
std::map< art::Ptr< simb::MCTruth >, MCParticleVector > MCTruthToMCParticles
std::map< art::Ptr< recob::PFParticle >, SpacePointVector > PFParticlesToSpacePoints
std::vector< art::Ptr< recob::Cluster > > ClusterVector
std::map< art::Ptr< recob::PFParticle >, HitVector > PFParticlesToHits
std::vector< art::Ptr< recob::Hit > > HitVector
std::vector< art::Ptr< recob::PFParticle > > PFParticleVector
std::map< art::Ptr< recob::Shower >, HitVector > ShowersToHits
std::vector< art::Ptr< anab::CosmicTag > > CosmicTagVector
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
std::map< art::Ptr< recob::PFParticle >, TrackVector > PFParticlesToTracks
std::map< art::Ptr< recob::Track >, HitVector > TracksToHits
std::map< art::Ptr< recob::PFParticle >, MetadataVector > PFParticlesToMetadata
std::map< art::Ptr< recob::SpacePoint >, art::Ptr< recob::Hit > > SpacePointsToHits
std::map< art::Ptr< simb::MCParticle >, HitVector > MCParticlesToHits
std::vector< art::Ptr< recob::SpacePoint > > SpacePointVector
std::map< int, art::Ptr< sim::SimChannel > > SimChannelMap
std::map< art::Ptr< recob::Cluster >, HitVector > ClustersToHits
std::map< art::Ptr< recob::PFParticle >, SeedVector > PFParticlesToSeeds
std::vector< art::Ptr< recob::Seed > > SeedVector
std::map< art::Ptr< recob::Hit >, art::Ptr< recob::PFParticle > > HitsToPFParticles
std::map< art::Ptr< recob::Hit >, art::Ptr< simb::MCParticle > > HitsToMCParticles
std::vector< art::Ptr< recob::Wire > > WireVector
std::map< art::Ptr< recob::PFParticle >, VertexVector > PFParticlesToVertices
std::map< art::Ptr< recob::Hit >, art::Ptr< recob::SpacePoint > > HitsToSpacePoints
std::map< art::Ptr< recob::Track >, CosmicTagVector > TracksToCosmicTags
std::vector< int > IntVector