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"
32 #include "nusimdata/SimulationBase/MCTruth.h"
38 #include "Objects/ParticleFlowObject.h"
39 #include "Pandora/PandoraInternal.h"
40 #include "Pandora/PdgTable.h"
45 namespace lar_pandora {
49 const std::string& label,
52 art::Handle<std::vector<recob::Wire>> theWires;
53 evt.getByLabel(label, theWires);
55 if (!theWires.isValid()) {
56 mf::LogDebug(
"LArPandora") <<
" Failed to find wires... " << std::endl;
60 mf::LogDebug(
"LArPandora") <<
" Found: " << theWires->size() <<
" Wires " << std::endl;
63 for (
unsigned int i = 0; i < theWires->size(); ++i) {
64 const art::Ptr<recob::Wire> wire(theWires, i);
65 wireVector.push_back(wire);
73 const std::string& label,
76 art::Handle<std::vector<recob::Hit>> theHits;
77 evt.getByLabel(label, theHits);
79 if (!theHits.isValid()) {
80 mf::LogDebug(
"LArPandora") <<
" Failed to find hits... " << std::endl;
84 mf::LogDebug(
"LArPandora") <<
" Found: " << theHits->size() <<
" Hits " << std::endl;
87 for (
unsigned int i = 0; i < theHits->size(); ++i) {
88 const art::Ptr<recob::Hit>
hit(theHits, i);
89 hitVector.push_back(hit);
97 const std::string& label,
100 art::Handle<std::vector<recob::PFParticle>> theParticles;
101 evt.getByLabel(label, theParticles);
103 if (!theParticles.isValid()) {
104 mf::LogDebug(
"LArPandora") <<
" Failed to find particles... " << std::endl;
108 mf::LogDebug(
"LArPandora") <<
" Found: " << theParticles->size() <<
" PFParticles "
112 for (
unsigned int i = 0; i < theParticles->size(); ++i) {
113 const art::Ptr<recob::PFParticle> particle(theParticles, i);
114 particleVector.push_back(particle);
122 const std::string& label,
128 evt, label, spacePointVector, spacePointsToHits, hitsToSpacePoints);
135 const std::string& label,
140 art::Handle<std::vector<recob::SpacePoint>> theSpacePoints;
141 evt.getByLabel(label, theSpacePoints);
143 if (!theSpacePoints.isValid()) {
144 mf::LogDebug(
"LArPandora") <<
" Failed to find spacepoints... " << std::endl;
148 mf::LogDebug(
"LArPandora") <<
" Found: " << theSpacePoints->size() <<
" SpacePoints "
152 art::FindOneP<recob::Hit> theHitAssns(theSpacePoints, evt, label);
153 for (
unsigned int i = 0; i < theSpacePoints->size(); ++i) {
154 const art::Ptr<recob::SpacePoint> spacepoint(theSpacePoints, i);
155 spacePointVector.push_back(spacepoint);
156 const art::Ptr<recob::Hit>
hit = theHitAssns.at(i);
157 spacePointsToHits[spacepoint] =
hit;
158 hitsToSpacePoints[
hit] = spacepoint;
166 const std::string& label,
170 art::Handle<std::vector<recob::Cluster>> theClusters;
171 evt.getByLabel(label, theClusters);
173 if (!theClusters.isValid()) {
174 mf::LogDebug(
"LArPandora") <<
" Failed to find clusters... " << std::endl;
178 mf::LogDebug(
"LArPandora") <<
" Found: " << theClusters->size() <<
" Clusters " << std::endl;
181 art::FindManyP<recob::Hit> theHitAssns(theClusters, evt, label);
182 for (
unsigned int i = 0; i < theClusters->size(); ++i) {
183 const art::Ptr<recob::Cluster>
cluster(theClusters, i);
184 clusterVector.push_back(cluster);
186 const std::vector<art::Ptr<recob::Hit>> hits = theHitAssns.at(i);
187 for (
unsigned int j = 0; j < hits.size(); ++j) {
188 const art::Ptr<recob::Hit>
hit = hits.at(j);
189 clustersToHits[
cluster].push_back(hit);
198 const std::string& label,
202 art::Handle<std::vector<recob::PFParticle>> theParticles;
203 evt.getByLabel(label, theParticles);
205 if (!theParticles.isValid()) {
206 mf::LogDebug(
"LArPandora") <<
" Failed to find particles... " << std::endl;
210 mf::LogDebug(
"LArPandora") <<
" Found: " << theParticles->size() <<
" PFParticles "
214 art::FindManyP<recob::SpacePoint> theSpacePointAssns(theParticles, evt, label);
215 for (
unsigned int i = 0; i < theParticles->size(); ++i) {
216 const art::Ptr<recob::PFParticle> particle(theParticles, i);
217 particleVector.push_back(particle);
219 const std::vector<art::Ptr<recob::SpacePoint>> spacepoints = theSpacePointAssns.at(i);
220 for (
unsigned int j = 0; j < spacepoints.size(); ++j) {
221 const art::Ptr<recob::SpacePoint> spacepoint = spacepoints.at(j);
222 particlesToSpacePoints[particle].push_back(spacepoint);
231 const std::string& label,
235 art::Handle<std::vector<recob::PFParticle>> theParticles;
236 evt.getByLabel(label, theParticles);
238 if (!theParticles.isValid()) {
239 mf::LogDebug(
"LArPandora") <<
" Failed to find particles... " << std::endl;
243 mf::LogDebug(
"LArPandora") <<
" Found: " << theParticles->size() <<
" PFParticles "
247 art::FindManyP<recob::Cluster> theClusterAssns(theParticles, evt, label);
248 for (
unsigned int i = 0; i < theParticles->size(); ++i) {
249 const art::Ptr<recob::PFParticle> particle(theParticles, i);
250 particleVector.push_back(particle);
252 const std::vector<art::Ptr<recob::Cluster>> clusters = theClusterAssns.at(i);
253 for (
unsigned int j = 0; j < clusters.size(); ++j) {
254 const art::Ptr<recob::Cluster>
cluster = clusters.at(j);
255 particlesToClusters[particle].push_back(cluster);
264 const std::string& label,
268 art::Handle<std::vector<recob::PFParticle>> theParticles;
269 evt.getByLabel(label, theParticles);
271 if (!theParticles.isValid()) {
272 mf::LogDebug(
"LArPandora") <<
" Failed to find particles... " << std::endl;
276 mf::LogDebug(
"LArPandora") <<
" Found: " << theParticles->size() <<
" PFParticles "
280 art::FindManyP<larpandoraobj::PFParticleMetadata> theMetadataAssns(theParticles, evt, label);
281 for (
unsigned int i = 0; i < theParticles->size(); ++i) {
282 const art::Ptr<recob::PFParticle> particle(theParticles, i);
283 particleVector.push_back(particle);
285 const std::vector<art::Ptr<larpandoraobj::PFParticleMetadata>> pfParticleMetadataList =
286 theMetadataAssns.at(i);
287 for (
unsigned int j = 0; j < pfParticleMetadataList.size(); ++j) {
288 const art::Ptr<larpandoraobj::PFParticleMetadata> pfParticleMetadata =
289 pfParticleMetadataList.at(j);
290 particlesToMetadata[particle].push_back(pfParticleMetadata);
299 const std::string& label,
303 art::Handle<std::vector<recob::Shower>> theShowers;
304 evt.getByLabel(label, theShowers);
306 if (!theShowers.isValid()) {
307 mf::LogDebug(
"LArPandora") <<
" Failed to find showers... " << std::endl;
311 mf::LogDebug(
"LArPandora") <<
" Found: " << theShowers->size() <<
" Showers " << std::endl;
314 art::FindManyP<recob::PFParticle> theShowerAssns(theShowers, evt, label);
315 for (
unsigned int i = 0; i < theShowers->size(); ++i) {
316 const art::Ptr<recob::Shower>
shower(theShowers, i);
317 showerVector.push_back(shower);
319 const std::vector<art::Ptr<recob::PFParticle>> particles = theShowerAssns.at(i);
320 for (
unsigned int j = 0; j < particles.size(); ++j) {
321 const art::Ptr<recob::PFParticle> particle = particles.at(j);
322 particlesToShowers[particle].push_back(shower);
331 const std::string& label,
335 art::Handle<std::vector<recob::Track>> theTracks;
336 evt.getByLabel(label, theTracks);
338 if (!theTracks.isValid()) {
339 mf::LogDebug(
"LArPandora") <<
" Failed to find tracks... " << std::endl;
343 mf::LogDebug(
"LArPandora") <<
" Found: " << theTracks->size() <<
" Tracks " << std::endl;
346 art::FindManyP<recob::PFParticle> theTrackAssns(theTracks, evt, label);
347 for (
unsigned int i = 0; i < theTracks->size(); ++i) {
348 const art::Ptr<recob::Track>
track(theTracks, i);
349 trackVector.push_back(track);
351 const std::vector<art::Ptr<recob::PFParticle>> particles = theTrackAssns.at(i);
352 for (
unsigned int j = 0; j < particles.size(); ++j) {
353 const art::Ptr<recob::PFParticle> particle = particles.at(j);
354 particlesToTracks[particle].push_back(track);
363 const std::string& label,
367 art::Handle<std::vector<recob::Track>> theTracks;
368 evt.getByLabel(label, theTracks);
370 if (!theTracks.isValid()) {
371 mf::LogDebug(
"LArPandora") <<
" Failed to find tracks... " << std::endl;
375 mf::LogDebug(
"LArPandora") <<
" Found: " << theTracks->size() <<
" Tracks " << std::endl;
378 art::FindManyP<recob::Hit> theHitAssns(theTracks, evt, label);
379 for (
unsigned int i = 0; i < theTracks->size(); ++i) {
380 const art::Ptr<recob::Track>
track(theTracks, i);
381 trackVector.push_back(
track);
383 const std::vector<art::Ptr<recob::Hit>> hits = theHitAssns.at(i);
384 for (
unsigned int j = 0; j < hits.size(); ++j) {
385 const art::Ptr<recob::Hit>
hit = hits.at(j);
386 tracksToHits[
track].push_back(hit);
395 const std::string& label,
399 art::Handle<std::vector<recob::Shower>> theShowers;
400 evt.getByLabel(label, theShowers);
402 if (!theShowers.isValid()) {
403 mf::LogDebug(
"LArPandora") <<
" Failed to find showers... " << std::endl;
407 mf::LogDebug(
"LArPandora") <<
" Found: " << theShowers->size() <<
" Showers " << std::endl;
410 art::FindManyP<recob::Hit> theHitAssns(theShowers, evt, label);
411 for (
unsigned int i = 0; i < theShowers->size(); ++i) {
412 const art::Ptr<recob::Shower>
shower(theShowers, i);
413 showerVector.push_back(
shower);
415 const std::vector<art::Ptr<recob::Hit>> hits = theHitAssns.at(i);
416 for (
unsigned int j = 0; j < hits.size(); ++j) {
417 const art::Ptr<recob::Hit>
hit = hits.at(j);
418 showersToHits[
shower].push_back(hit);
427 const std::string& label,
431 art::Handle<std::vector<recob::Seed>> theSeeds;
432 evt.getByLabel(label, theSeeds);
434 if (!theSeeds.isValid()) {
435 mf::LogDebug(
"LArPandora") <<
" Failed to find seeds... " << std::endl;
439 mf::LogDebug(
"LArPandora") <<
" Found: " << theSeeds->size() <<
" Seeds " << std::endl;
442 art::FindManyP<recob::PFParticle> theSeedAssns(theSeeds, evt, label);
443 for (
unsigned int i = 0; i < theSeeds->size(); ++i) {
444 const art::Ptr<recob::Seed>
seed(theSeeds, i);
445 seedVector.push_back(seed);
447 const std::vector<art::Ptr<recob::PFParticle>> particles = theSeedAssns.at(i);
448 for (
unsigned int j = 0; j < particles.size(); ++j) {
449 const art::Ptr<recob::PFParticle> particle = particles.at(j);
450 particlesToSeeds[particle].push_back(seed);
459 const std::string& label,
463 art::Handle<std::vector<recob::Seed>> theSeeds;
464 evt.getByLabel(label, theSeeds);
466 if (!theSeeds.isValid()) {
467 mf::LogDebug(
"LArPandora") <<
" Failed to find seeds... " << std::endl;
471 mf::LogDebug(
"LArPandora") <<
" Found: " << theSeeds->size() <<
" Seeds " << std::endl;
474 art::FindOneP<recob::Hit> theHitAssns(theSeeds, evt, label);
476 if (!theHitAssns.isValid()) {
477 mf::LogDebug(
"LArPandora") <<
" Failed to find seed associations... " << std::endl;
481 for (
unsigned int i = 0; i < theSeeds->size(); ++i) {
482 const art::Ptr<recob::Seed>
seed(theSeeds, i);
483 seedVector.push_back(
seed);
484 const art::Ptr<recob::Hit>
hit = theHitAssns.at(i);
493 const std::string& label,
497 art::Handle<std::vector<recob::Vertex>> theVertices;
498 evt.getByLabel(label, theVertices);
500 if (!theVertices.isValid()) {
501 mf::LogDebug(
"LArPandora") <<
" Failed to find vertices... " << std::endl;
505 mf::LogDebug(
"LArPandora") <<
" Found: " << theVertices->size() <<
" Vertices " << std::endl;
508 art::FindManyP<recob::PFParticle> theVerticesAssns(theVertices, evt, label);
509 for (
unsigned int i = 0; i < theVertices->size(); ++i) {
510 const art::Ptr<recob::Vertex>
vertex(theVertices, i);
511 vertexVector.push_back(vertex);
513 const std::vector<art::Ptr<recob::PFParticle>> particles = theVerticesAssns.at(i);
514 for (
unsigned int j = 0; j < particles.size(); ++j) {
515 const art::Ptr<recob::PFParticle> particle = particles.at(j);
516 particlesToVertices[particle].push_back(vertex);
534 for (PFParticleVector::const_iterator iter1 = particleVector.begin(),
535 iterEnd1 = particleVector.end();
538 const art::Ptr<recob::PFParticle> particle = *iter1;
539 particleMap[particle->Self()] = particle;
543 for (PFParticlesToSpacePoints::const_iterator iter1 = particlesToSpacePoints.begin(),
544 iterEnd1 = particlesToSpacePoints.end();
547 const art::Ptr<recob::PFParticle> thisParticle = iter1->first;
548 const art::Ptr<recob::PFParticle> particle(
559 for (SpacePointVector::const_iterator iter2 = spacePointVector.begin(),
560 iterEnd2 = spacePointVector.end();
563 const art::Ptr<recob::SpacePoint> spacepoint = *iter2;
565 SpacePointsToHits::const_iterator iter3 = spacePointsToHits.find(spacepoint);
566 if (spacePointsToHits.end() == iter3)
567 throw cet::exception(
"LArPandora") <<
" PandoraCollector::BuildPFParticleHitMaps --- "
568 "Found a space point without an associated hit ";
570 const art::Ptr<recob::Hit>
hit = iter3->second;
572 particlesToHits[particle].push_back(hit);
573 hitsToParticles[
hit] = particle;
591 for (PFParticleVector::const_iterator iter1 = particleVector.begin(),
592 iterEnd1 = particleVector.end();
595 const art::Ptr<recob::PFParticle> particle = *iter1;
596 particleMap[particle->Self()] = particle;
600 for (PFParticlesToClusters::const_iterator iter1 = particlesToClusters.begin(),
601 iterEnd1 = particlesToClusters.end();
604 const art::Ptr<recob::PFParticle> thisParticle = iter1->first;
605 const art::Ptr<recob::PFParticle> particle(
615 for (ClusterVector::const_iterator iter2 = clusterVector.begin(),
616 iterEnd2 = clusterVector.end();
619 const art::Ptr<recob::Cluster>
cluster = *iter2;
621 ClustersToHits::const_iterator iter3 = clustersToHits.find(cluster);
622 if (clustersToHits.end() == iter3)
623 throw cet::exception(
"LArPandora") <<
" PandoraCollector::BuildPFParticleHitMaps --- "
624 "Found a space point without an associated hit ";
626 const HitVector& hitVector = iter3->second;
627 for (HitVector::const_iterator iter4 = hitVector.begin(), iterEnd4 = hitVector.end();
630 const art::Ptr<recob::Hit>
hit = *iter4;
632 particlesToHits[particle].push_back(hit);
633 hitsToParticles[
hit] = particle;
643 const std::string& label,
647 const bool useClusters)
650 evt, label, label, particlesToHits, hitsToParticles, daughterMode, useClusters);
657 const std::string& label_pfpart,
658 const std::string& label_middle,
662 const bool useClusters)
692 evt, label_pfpart, particleVector, particlesToSpacePoints);
696 particlesToSpacePoints,
710 for (PFParticleVector::const_iterator iter = inputParticles.begin(),
711 iterEnd = inputParticles.end();
714 const art::Ptr<recob::PFParticle> particle = *iter;
729 for (PFParticleVector::const_iterator iter = inputParticles.begin(),
730 iterEnd = inputParticles.end();
733 const art::Ptr<recob::PFParticle> particle = *iter;
734 particleMap[particle->Self()] = particle;
738 for (PFParticleVector::const_iterator iter = inputParticles.begin(),
739 iterEnd = inputParticles.end();
742 const art::Ptr<recob::PFParticle> particle = *iter;
745 outputParticles.push_back(particle);
753 const std::string& label,
757 art::Handle<std::vector<anab::CosmicTag>> theCosmicTags;
758 evt.getByLabel(label, theCosmicTags);
760 if (theCosmicTags.isValid()) {
761 art::FindOneP<recob::Track> theCosmicAssns(
762 theCosmicTags, evt, label);
763 for (
unsigned int i = 0; i < theCosmicTags->size(); ++i) {
764 const art::Ptr<anab::CosmicTag> cosmicTag(theCosmicTags, i);
765 const art::Ptr<recob::Track>
track = theCosmicAssns.at(i);
766 tracksToCosmicTags[
track].push_back(
768 cosmicTagVector.push_back(cosmicTag);
777 const std::string& label,
781 art::Handle<std::vector<anab::T0>> theT0s;
782 evt.getByLabel(label, theT0s);
784 if (theT0s.isValid()) {
785 art::FindManyP<recob::PFParticle> theAssns(theT0s, evt, label);
786 for (
unsigned int i = 0; i < theT0s->size(); ++i) {
787 const art::Ptr<anab::T0> theT0(theT0s, i);
788 t0Vector.push_back(theT0);
790 const std::vector<art::Ptr<recob::PFParticle>> particles = theAssns.at(i);
791 for (
unsigned int j = 0; j < particles.size(); ++j) {
792 const art::Ptr<recob::PFParticle> theParticle = particles.at(j);
793 particlesToT0s[theParticle].push_back(
804 const std::string& label,
806 bool& areSimChannelsValid)
808 art::Handle<std::vector<sim::SimChannel>> theSimChannels;
809 evt.getByLabel(label, theSimChannels);
811 if (!theSimChannels.isValid()) {
812 mf::LogDebug(
"LArPandora") <<
" Failed to find sim channels... " << std::endl;
813 areSimChannelsValid =
false;
817 mf::LogDebug(
"LArPandora") <<
" Found: " << theSimChannels->size() <<
" SimChannels "
819 areSimChannelsValid =
true;
822 for (
unsigned int i = 0; i < theSimChannels->size(); ++i) {
823 const art::Ptr<sim::SimChannel> channel(theSimChannels, i);
824 simChannelVector.push_back(channel);
832 const std::string& label,
835 art::Handle<RawMCParticleVector> theParticles;
836 evt.getByLabel(label, theParticles);
838 if (!theParticles.isValid()) {
839 mf::LogDebug(
"LArPandora") <<
" Failed to find MC particles... " << std::endl;
843 mf::LogDebug(
"LArPandora") <<
" Found: " << theParticles->size() <<
" MC particles "
847 for (
unsigned int i = 0; i < theParticles->size(); ++i) {
848 const art::Ptr<simb::MCParticle> particle(theParticles, i);
849 particleVector.push_back(particle);
857 const std::string& label,
860 art::Handle<std::vector<simb::MCTruth>> mcTruthBlocks;
861 evt.getByLabel(label, mcTruthBlocks);
863 if (!mcTruthBlocks.isValid()) {
864 mf::LogDebug(
"LArPandora") <<
" Failed to find MC truth blocks from generator... "
869 mf::LogDebug(
"LArPandora") <<
" Found: " << mcTruthBlocks->size() <<
" MC truth blocks "
873 if (mcTruthBlocks->size() != 1)
874 throw cet::exception(
"LArPandora") <<
" PandoraCollector::CollectGeneratorMCParticles --- "
875 "Unexpected number of MC truth blocks ";
877 const art::Ptr<simb::MCTruth> mcTruth(mcTruthBlocks, 0);
879 for (
int i = 0; i < mcTruth->NParticles(); ++i) {
880 particleVector.push_back(mcTruth->GetParticle(i));
888 const std::string& label,
892 art::Handle<RawMCParticleVector> theParticles;
893 evt.getByLabel(label, theParticles);
895 if (!theParticles.isValid()) {
896 mf::LogDebug(
"LArPandora") <<
" Failed to find MC particles... " << std::endl;
900 mf::LogDebug(
"LArPandora") <<
" Found: " << theParticles->size() <<
" MC particles "
904 art::FindOneP<simb::MCTruth> theTruthAssns(theParticles, evt, label);
906 for (
unsigned int i = 0, iEnd = theParticles->size(); i < iEnd; ++i) {
907 const art::Ptr<simb::MCParticle> particle(theParticles, i);
908 const art::Ptr<simb::MCTruth> truth(theTruthAssns.at(i));
909 truthToParticles[truth].push_back(particle);
910 particlesToTruth[particle] = truth;
922 auto const clock_data =
923 art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
927 for (SimChannelVector::const_iterator iter = simChannelVector.begin(),
928 iterEnd = simChannelVector.end();
931 const art::Ptr<sim::SimChannel> simChannel = *iter;
932 simChannelMap.insert(SimChannelMap::value_type(simChannel->Channel(), simChannel));
935 for (HitVector::const_iterator iter = hitVector.begin(), iterEnd = hitVector.end();
938 const art::Ptr<recob::Hit>
hit = *iter;
940 SimChannelMap::const_iterator sIter = simChannelMap.find(hit->Channel());
941 if (simChannelMap.end() == sIter)
continue;
944 const raw::TDCtick_t start_tick(clock_data.TPCTick2TDC(hit->PeakTimeMinusRMS()));
945 const raw::TDCtick_t end_tick(clock_data.TPCTick2TDC(hit->PeakTimePlusRMS()));
946 const unsigned int start_tdc((start_tick < 0) ? 0 : start_tick);
947 const unsigned int end_tdc(end_tick);
949 if (start_tdc > end_tdc)
continue;
951 const art::Ptr<sim::SimChannel> simChannel = sIter->second;
952 const TrackIDEVector trackCollection(simChannel->TrackIDEs(start_tdc, end_tdc));
954 if (trackCollection.empty())
continue;
956 for (
unsigned int iTrack = 0, iTrackEnd = trackCollection.size(); iTrack < iTrackEnd;
959 hitsToTrackIDEs[
hit].push_back(trackIDE);
976 for (MCTruthToMCParticles::const_iterator iter1 = truthToParticles.begin(),
977 iterEnd1 = truthToParticles.end();
981 for (MCParticleVector::const_iterator iter2 = particleVector.begin(),
982 iterEnd2 = particleVector.end();
985 const art::Ptr<simb::MCParticle> particle = *iter2;
986 particleMap[particle->TrackId()] = particle;
991 for (HitsToTrackIDEs::const_iterator iter1 = hitsToTrackIDEs.begin(),
992 iterEnd1 = hitsToTrackIDEs.end();
995 const art::Ptr<recob::Hit>
hit = iter1->first;
999 float bestEnergyFrac(0.f);
1001 for (TrackIDEVector::const_iterator iter2 = trackCollection.begin(),
1002 iterEnd2 = trackCollection.end();
1009 if (energyFrac > bestEnergyFrac) {
1010 bestEnergyFrac = energyFrac;
1011 bestTrackID = trackID;
1015 if (bestTrackID >= 0) {
1016 MCParticleMap::const_iterator iter3 = particleMap.find(bestTrackID);
1017 if (particleMap.end() == iter3)
1018 throw cet::exception(
"LArPandora") <<
" PandoraCollector::BuildMCParticleHitMaps --- "
1019 "Found a track ID without an MC Particle ";
1022 const art::Ptr<simb::MCParticle> thisParticle = iter3->second;
1023 const art::Ptr<simb::MCParticle> primaryParticle(
1025 const art::Ptr<simb::MCParticle> selectedParticle(
1026 (
kAddDaughters == daughterMode) ? primaryParticle : thisParticle);
1028 if ((
kIgnoreDaughters == daughterMode) && (selectedParticle != primaryParticle))
continue;
1032 particlesToHits[selectedParticle].push_back(hit);
1033 hitsToParticles[
hit] = selectedParticle;
1035 catch (cet::exception&
e) {
1045 const std::string& label,
1056 bool areSimChannelsValid(
false);
1062 hitsToTrackIDEs, truthToParticles, particlesToHits, hitsToParticles, daughterMode);
1069 const std::string& hitLabel,
1070 const std::string& backtrackLabel,
1074 art::Handle<std::vector<recob::Hit>> theHits;
1075 evt.getByLabel(hitLabel, theHits);
1077 if (!theHits.isValid()) {
1078 mf::LogDebug(
"LArPandora") <<
" Failed to find hits... " << std::endl;
1084 for (
unsigned int i = 0; i < theHits->size(); ++i) {
1085 const art::Ptr<recob::Hit>
hit(theHits, i);
1086 hitVector.push_back(hit);
1090 std::vector<anab::BackTrackerHitMatchingData const*> backtrackerVector;
1094 art::FindManyP<simb::MCParticle, anab::BackTrackerHitMatchingData> particles_per_hit(
1095 theHits, evt, backtrackLabel);
1097 if (!particles_per_hit.isValid()) {
1098 mf::LogDebug(
"LArPandora") <<
" Failed to find reco-truth matching... " << std::endl;
1103 for (HitVector::const_iterator iter = hitVector.begin(), iterEnd = hitVector.end();
1106 const art::Ptr<recob::Hit>
hit = *iter;
1108 particleVector.clear();
1109 backtrackerVector.clear();
1110 particles_per_hit.get(hit.key(), particleVector, backtrackerVector);
1112 for (
unsigned int j = 0; j < particleVector.size(); ++j) {
1113 const art::Ptr<simb::MCParticle> particle = particleVector[j];
1116 trackIDE.
trackID = particle->TrackId();
1117 trackIDE.
energy = backtrackerVector[j]->energy;
1118 trackIDE.
energyFrac = backtrackerVector[j]->ideFraction;
1120 hitsToTrackIDEs[
hit].push_back(trackIDE);
1129 const std::string& truthLabel,
1130 const std::string& hitLabel,
1131 const std::string& backtrackLabel,
1143 hitsToTrackIDEs, truthToParticles, particlesToHits, hitsToParticles, daughterMode);
1148 template <
typename T>
1151 const std::string& label,
1157 art::Handle<std::vector<T>> handle;
1158 evt.getByLabel(label, handle);
1159 art::FindManyP<recob::Hit> hitAssoc(handle, evt, label);
1161 if (indexVector !=
nullptr) {
1162 if (inputVector.size() != indexVector->size())
1163 throw cet::exception(
"LArPandora") <<
" PandoraHelper::GetAssociatedHits --- trying to use "
1164 "an index vector not matching input vector";
1167 for (
int index : (*indexVector)) {
1168 const art::Ptr<T>&
element = inputVector.at(index);
1169 const HitVector& hits = hitAssoc.at(element.key());
1170 associatedHits.insert(associatedHits.end(), hits.begin(), hits.end());
1175 for (
const art::Ptr<T>&
element : inputVector) {
1177 associatedHits.insert(associatedHits.end(), hits.begin(), hits.end());
1188 for (MCParticleVector::const_iterator iter = particleVector.begin(),
1189 iterEnd = particleVector.end();
1192 const art::Ptr<simb::MCParticle> particle = *iter;
1193 particleMap[particle->TrackId()] = particle;
1194 particleMap[particle->TrackId()] = particle;
1204 for (PFParticleVector::const_iterator iter = particleVector.begin(),
1205 iterEnd = particleVector.end();
1208 const art::Ptr<recob::PFParticle> particle = *iter;
1209 particleMap[particle->Self()] = particle;
1215 art::Ptr<recob::PFParticle>
1217 const art::Ptr<recob::PFParticle> inputParticle)
1220 int primaryTrackID(inputParticle->Self());
1222 if (!inputParticle->IsPrimary()) {
1224 PFParticleMap::const_iterator pIter1 = particleMap.find(primaryTrackID);
1225 if (particleMap.end() == pIter1)
1226 throw cet::exception(
"LArPandora") <<
" PandoraCollector::GetParentPFParticle --- Found "
1227 "a PFParticle without a particle ID ";
1229 const art::Ptr<recob::PFParticle> primaryParticle = pIter1->second;
1230 if (primaryParticle->IsPrimary())
break;
1232 primaryTrackID = primaryParticle->Parent();
1236 PFParticleMap::const_iterator pIter2 = particleMap.find(primaryTrackID);
1237 if (particleMap.end() == pIter2)
1238 throw cet::exception(
"LArPandora")
1239 <<
" PandoraCollector::GetParentPFParticle --- Found a PFParticle without a particle ID ";
1241 const art::Ptr<recob::PFParticle> outputParticle = pIter2->second;
1242 return outputParticle;
1247 art::Ptr<recob::PFParticle>
1249 const art::Ptr<recob::PFParticle> inputParticle)
1252 int primaryTrackID(inputParticle->Self());
1254 if (!inputParticle->IsPrimary()) {
1255 int parentTrackID(inputParticle->Parent());
1258 PFParticleMap::const_iterator pIter1 = particleMap.find(parentTrackID);
1259 if (particleMap.end() == pIter1)
1260 throw cet::exception(
"LArPandora") <<
" PandoraCollector::GetFinalStatePFParticle --- "
1261 "Found a PFParticle without a particle ID ";
1263 const art::Ptr<recob::PFParticle> parentParticle = pIter1->second;
1266 primaryTrackID = parentTrackID;
1268 if (parentParticle->IsPrimary())
break;
1270 parentTrackID = parentParticle->Parent();
1274 PFParticleMap::const_iterator pIter2 = particleMap.find(primaryTrackID);
1275 if (particleMap.end() == pIter2)
1276 throw cet::exception(
"LArPandora") <<
" PandoraCollector::GetFinalStatePFParticle --- Found "
1277 "a PFParticle without a particle ID ";
1279 const art::Ptr<recob::PFParticle> outputParticle = pIter2->second;
1280 return outputParticle;
1285 art::Ptr<simb::MCParticle>
1287 const art::Ptr<simb::MCParticle> inputParticle)
1290 int primaryTrackID(inputParticle->TrackId());
1291 int parentTrackID(inputParticle->Mother());
1294 MCParticleMap::const_iterator pIter1 = particleMap.find(parentTrackID);
1295 if (particleMap.end() == pIter1)
break;
1297 const art::Ptr<simb::MCParticle> particle = pIter1->second;
1299 primaryTrackID = parentTrackID;
1300 parentTrackID = particle->Mother();
1303 MCParticleMap::const_iterator pIter2 = particleMap.find(primaryTrackID);
1304 if (particleMap.end() == pIter2)
1305 throw cet::exception(
"LArPandora")
1306 <<
" PandoraCollector::GetParentMCParticle --- Found a track ID without a MC particle ";
1308 const art::Ptr<simb::MCParticle> outputParticle = pIter2->second;
1309 return outputParticle;
1314 art::Ptr<simb::MCParticle>
1316 const art::Ptr<simb::MCParticle> inputParticle)
1321 int trackID(inputParticle->TrackId());
1324 MCParticleMap::const_iterator pIter = particleMap.find(trackID);
1325 if (particleMap.end() == pIter)
break;
1327 const art::Ptr<simb::MCParticle> particle = pIter->second;
1328 mcVector.push_back(particle);
1330 trackID = particle->Mother();
1334 for (MCParticleVector::const_reverse_iterator iter = mcVector.rbegin(),
1335 iterEnd = mcVector.rend();
1338 const art::Ptr<simb::MCParticle> nextParticle = *iter;
1343 throw cet::exception(
"LArPandora");
1348 art::Ptr<recob::Track>
1350 const art::Ptr<recob::PFParticle> particle)
1352 PFParticlesToTracks::const_iterator tIter = particlesToTracks.find(particle);
1354 if (particlesToTracks.end() == tIter || tIter->second.empty())
1355 throw cet::exception(
"LArPandora")
1356 <<
" PandoraCollector::GetPrimaryTrack --- Failed to find associated track ";
1358 if (tIter->second.size() != 1)
1359 throw cet::exception(
"LArPandora")
1360 <<
" PandoraCollector::GetPrimaryTrack --- Found more than one associated track ";
1362 const art::Ptr<recob::Track> primaryTrack = *(tIter->second.begin());
1363 return primaryTrack;
1370 const art::Ptr<recob::PFParticle> inputParticle)
1373 int nGenerations(0);
1374 int primaryTrackID(inputParticle->Self());
1377 PFParticleMap::const_iterator pIter = particleMap.find(primaryTrackID);
1378 if (particleMap.end() == pIter)
1379 throw cet::exception(
"LArPandora")
1380 <<
" PandoraCollector::GetGeneration --- Found a PFParticle without a particle ID ";
1384 const art::Ptr<recob::PFParticle> primaryParticle = pIter->second;
1385 if (primaryParticle->IsPrimary())
break;
1387 primaryTrackID = primaryParticle->Parent();
1390 return nGenerations;
1397 const art::Ptr<recob::PFParticle> daughterParticle)
1399 art::Ptr<recob::PFParticle> parentParticle =
1404 if (parentParticle->IsPrimary())
return 0;
1406 const int parentID(parentParticle->Parent());
1408 PFParticleMap::const_iterator pIter = particleMap.find(parentID);
1409 if (particleMap.end() == pIter)
1410 throw cet::exception(
"LArPandora")
1411 <<
" PandoraCollector::GetParentNeutrino --- Found a PFParticle without a particle ID ";
1413 const art::Ptr<recob::PFParticle> neutrinoParticle = pIter->second;
1414 return neutrinoParticle->PdgCode();
1421 const art::Ptr<recob::PFParticle> daughterParticle)
1425 if (daughterParticle->IsPrimary())
return true;
1427 const int parentID(daughterParticle->Parent());
1429 PFParticleMap::const_iterator pIter = particleMap.find(parentID);
1430 if (particleMap.end() == pIter)
1431 throw cet::exception(
"LArPandora")
1432 <<
" PandoraCollector::IsFinalState --- Found a PFParticle without a particle ID ";
1434 const art::Ptr<recob::PFParticle> parentParticle = pIter->second;
1446 const int pdg(particle->PdgCode());
1458 const int pdg(particle->PdgCode());
1470 const int pdg(particle->PdgCode());
1482 const int pdg(particle->PdgCode());
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 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. ...
std::map< art::Ptr< recob::Hit >, art::Ptr< simb::MCParticle > > HitsToMCParticles
static void BuildPFParticleMap(const PFParticleVector &particleVector, PFParticleMap &particleMap)
Build particle maps for reconstructed particles.
std::map< int, art::Ptr< sim::SimChannel > > SimChannelMap
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...
std::map< art::Ptr< recob::PFParticle >, ClusterVector > PFParticlesToClusters
static bool IsNeutrino(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as a neutrino.
Declaration of signal hit object.
std::map< art::Ptr< simb::MCParticle >, art::Ptr< simb::MCTruth > > MCParticlesToMCTruth
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 CollectWires(const art::Event &evt, const std::string &label, WireVector &wireVector)
Collect the reconstructed wires from the ART event record.
static bool IsShower(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as shower-like.
std::vector< art::Ptr< recob::Shower > > ShowerVector
process_name use argoneut_mc_hitfinder track
std::vector< int > IntVector
std::vector< art::Ptr< anab::CosmicTag > > CosmicTagVector
float energy
energy from the particle with this trackID [MeV]
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...
std::map< art::Ptr< recob::PFParticle >, TrackVector > PFParticlesToTracks
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. ATTN: This function is needed as accessing generator (opposed to Geant4) level MCParticles requires use of MCTruth block.
std::map< art::Ptr< recob::PFParticle >, VertexVector > PFParticlesToVertices
std::map< int, art::Ptr< recob::PFParticle > > PFParticleMap
std::map< art::Ptr< recob::Track >, CosmicTagVector > TracksToCosmicTags
int TDCtick_t
Type representing a TDC tick.
std::map< int, art::Ptr< simb::MCParticle > > MCParticleMap
std::map< art::Ptr< recob::Hit >, TrackIDEVector > HitsToTrackIDEs
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 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.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::vector< art::Ptr< recob::Seed > > SeedVector
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 bool IsVisible(const art::Ptr< simb::MCParticle > particle)
Determine whether a particle is visible (i.e. long-lived charged particle)
std::map< art::Ptr< recob::PFParticle >, MetadataVector > PFParticlesToMetadata
std::map< art::Ptr< recob::PFParticle >, T0Vector > PFParticlesToT0s
std::map< art::Ptr< recob::PFParticle >, ShowerVector > PFParticlesToShowers
std::vector< simb::MCParticle > RawMCParticleVector
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...
Metadata associated to PFParticles.
std::map< art::Ptr< simb::MCParticle >, HitVector > MCParticlesToHits
std::map< art::Ptr< recob::PFParticle >, SeedVector > PFParticlesToSeeds
std::vector< art::Ptr< recob::PFParticle > > PFParticleVector
std::map< art::Ptr< recob::Cluster >, HitVector > ClustersToHits
std::map< art::Ptr< recob::Shower >, HitVector > ShowersToHits
std::map< art::Ptr< simb::MCTruth >, MCParticleVector > MCTruthToMCParticles
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.
std::vector< art::Ptr< recob::SpacePoint > > SpacePointVector
static art::Ptr< recob::Track > GetPrimaryTrack(const PFParticlesToTracks &particlesToTracks, const art::Ptr< recob::PFParticle > particle)
Return the primary track associated with a PFParticle.
std::map< art::Ptr< recob::PFParticle >, HitVector > PFParticlesToHits
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.
float energyFrac
fraction of hit energy from the particle with this trackID
std::map< art::Ptr< recob::Hit >, art::Ptr< recob::SpacePoint > > HitsToSpacePoints
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
std::vector< sim::TrackIDE > TrackIDEVector
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 SelectFinalStatePFParticles(const PFParticleVector &inputParticles, PFParticleVector &outputParticles)
Select final-state reconstructed particles from a list of all reconstructed particles.
std::vector< art::Ptr< recob::Track > > TrackVector
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.
std::map< art::Ptr< recob::PFParticle >, SpacePointVector > PFParticlesToSpacePoints
Declaration of cluster object.
std::map< art::Ptr< recob::Track >, HitVector > TracksToHits
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 void CollectPFParticles(const art::Event &evt, const std::string &label, PFParticleVector &particleVector)
Collect the reconstructed PFParticles from the ART event record.
Provides recob::Track data product.
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 SelectNeutrinoPFParticles(const PFParticleVector &inputParticles, PFParticleVector &outputParticles)
Select reconstructed neutrino particles from a list of all reconstructed particles.
std::vector< art::Ptr< recob::Hit > > HitVector
int trackID
Geant4 supplied trackID.
std::vector< art::Ptr< sim::SimChannel > > SimChannelVector
std::vector< art::Ptr< recob::Wire > > WireVector
std::map< art::Ptr< recob::Hit >, art::Ptr< recob::PFParticle > > HitsToPFParticles
static bool IsTrack(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as track-like.
std::vector< art::Ptr< recob::Vertex > > VertexVector
Declaration of basic channel signal object.
std::vector< art::Ptr< recob::Cluster > > ClusterVector
static int GetGeneration(const PFParticleMap &particleMap, const art::Ptr< recob::PFParticle > daughterParticle)
Return the generation of this particle (first generation if primary)
std::vector< art::Ptr< anab::T0 > > T0Vector
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.
std::map< art::Ptr< recob::Seed >, art::Ptr< recob::Hit > > SeedsToHits
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 void CollectMCParticles(const art::Event &evt, const std::string &label, MCParticleVector &particleVector)
Collect a vector of MCParticle objects from the ART event record.
helper function for LArPandoraInterface producer module
Ionization energy from a Geant4 track.
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...
art framework interface to geometry description
static bool IsFinalState(const PFParticleMap &particleMap, const art::Ptr< recob::PFParticle > daughterParticle)
Determine whether a particle has been reconstructed as a final-state particle.
std::map< art::Ptr< recob::SpacePoint >, art::Ptr< recob::Hit > > SpacePointsToHits
static larpandoraobj::PFParticleMetadata GetPFParticleMetadata(const pandora::ParticleFlowObject *const pPfo)
Get metadata associated to a PFO.
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 void BuildMCParticleMap(const MCParticleVector &particleVector, MCParticleMap &particleMap)
Build particle maps for true particles.