7 #include "canvas/Persistency/Common/FindManyP.h" 8 #include "canvas/Persistency/Common/FindOneP.h" 27 auto pfParticles = evt.
getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
29 unsigned int nPrimary = 0;
30 for(
unsigned int p = 0;
p < pfParticles->size(); ++
p){
31 if(pfParticles->at(
p).IsPrimary()){
43 auto pfParticles = evt.
getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
45 std::map<unsigned int, std::vector<const recob::PFParticle*>> sliceMap;
47 for(
unsigned int p = 0;
p < pfParticles->size(); ++
p){
51 if(primaryOnly && !particle->
IsPrimary())
continue;
55 if(thisSlice != 9999){
56 sliceMap[thisSlice].push_back(particle);
82 auto recoParticles = evt.
getValidHandle<std::vector<recob::PFParticle> >(particleLabel);
84 unsigned int pIndex = particle.
Self();
86 std::vector<anab::CosmicTag> pTags;
88 const art::FindManyP<anab::CosmicTag> findCosmicTags(recoParticles,evt,particleLabel);
89 for(
unsigned int p = 0;
p < findCosmicTags.at(pIndex).size(); ++
p){
90 pTags.push_back((*(findCosmicTags.at(pIndex)[
p])));
96 return std::vector<anab::CosmicTag>();
110 auto recoParticles = evt.
getValidHandle<std::vector<recob::PFParticle> >(particleLabel);
112 unsigned int pIndex = particle.
Self();
114 std::vector<anab::T0> pT0s;
116 const art::FindManyP<anab::T0> findParticleT0s(recoParticles,evt,t0Label);
117 for(
unsigned int p = 0;
p < findParticleT0s.at(pIndex).size(); ++
p){
118 pT0s.push_back((*(findParticleT0s.at(pIndex)[
p])));
124 return std::vector<anab::T0>();
132 const std::map<unsigned int, std::vector<const recob::PFParticle*>> sliceMap =
GetPFParticleSliceMap(evt,particleLabel);
134 for(
auto slice : sliceMap){
135 for(
auto particle : slice.second){
149 const std::map<unsigned int, std::vector<const recob::PFParticle*>> sliceMap =
GetPFParticleSliceMap(evt,particleLabel);
151 if(sliceMap.find(slice) != sliceMap.end()){
152 return sliceMap.at(slice);
155 return std::vector<const recob::PFParticle*>();
163 const std::map<unsigned int, std::vector<const recob::PFParticle*>> sliceMap =
GetAllPFParticleSliceMap(evt,particleLabel);
165 if(sliceMap.find(slice) != sliceMap.end()){
166 return sliceMap.at(slice);
169 return std::vector<const recob::PFParticle*>();
177 unsigned short beamSlice =
GetBeamSlice(evt,particleLabel);
199 if(mdMap.find(entry) != mdMap.end()){
212 if(mdMap.find(entry) != mdMap.end()){
213 return mdMap.at(entry);
226 auto pfParticles = evt.
getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
227 const art::FindOneP<recob::Slice> findSlice(pfParticles,evt,particleLabel);
246 if(mdMap.find(search) != mdMap.end()){
247 return static_cast<unsigned short>(mdMap.at(search));
264 const std::vector<const recob::Hit*> hits = sliceUtil.
GetRecoSliceHits(sliceIndex,evt,particleLabel);
275 std::vector<bool> hitUsed(hits.size(),
false);
276 std::vector<const recob::Hit*> unassocHits;
281 for(
auto const p : slicePFPs){
284 const std::vector<const recob::Hit*> pfpHits =
GetPFParticleHits(*
p,evt,particleLabel);
286 std::cout <<
"Hit vector sizes: " << hits.size() <<
", " << pfpHits.size() <<
std::endl;
290 for(
unsigned int o = 0; o < hits.size(); ++o){
291 if(fabs(
h->Integral() - hits[o]->Integral()) < 1
e-5 && fabs(
h->PeakTime() - hits[o]->PeakTime()) < 1
e-5){
300 for(
unsigned int i = 0; i < hits.size(); ++i){
301 if(!hitUsed[i]) unassocHits.push_back(hits[i]);
303 std::cout <<
" Number of unassociated hits = " << unassocHits.size() <<
" of " << hits.size() <<
std::endl;
311 auto pfParticles = evt.
getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
313 const art::FindManyP<larpandoraobj::PFParticleMetadata> findMetaData(pfParticles,evt,particleLabel);
331 auto pfParticles = evt.
getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
333 std::vector<const recob::PFParticle*> cosmicParticles;
335 for(
unsigned int p = 0;
p < pfParticles->size(); ++
p){
342 cosmicParticles.push_back(particle);
347 return cosmicParticles;
355 auto pfParticles = evt.
getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
356 const art::FindManyP<recob::Vertex> findVertices(pfParticles,evt,particleLabel);
357 const std::vector<art::Ptr<recob::Vertex>> vertices = findVertices.at(particle.
Self());
369 if(vertices.size() != 0){
374 std::cerr <<
"Non track-like PFParticle has no vertex?! Return default vector" <<
std::endl;
388 if(start.Z() <
end.Z())
return start;
393 if(start.Y() >
end.Y())
return start;
398 std::cerr <<
"No track found for track-like PFParticle?! Return default vector" <<
std::endl;
414 std::cerr <<
"Shower-like PFParticles have no secondary vertex. Returning default TVector3" <<
std::endl;
427 if(start.Z() >
end.Z())
return start;
432 if(start.Y() <
end.Y())
return start;
438 std::cerr <<
"This track-like PFParticle has no associated track. Returning default TVector3" <<
std::endl;
453 std::cerr <<
"This function is deprecated, please use the version with four arguments." <<
std::endl;
479 auto particles = evt.
getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
480 const art::FindManyP<recob::Track> findTracks(particles,evt,trackLabel);
481 const std::vector<art::Ptr<recob::Track>> pfpTracks = findTracks.at(particle.
Self());
484 if(pfpTracks.size() != 0){
499 auto particles = evt.
getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
500 const art::FindManyP<recob::Shower> findShowers(particles,evt,showerLabel);
501 const std::vector<art::Ptr<recob::Shower>> pfpShowers = findShowers.at(particle.
Self());
504 if(pfpShowers.size() != 0){
519 auto particles = evt.
getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
520 const art::FindManyP<recob::SpacePoint> findSpacePoints(particles,evt,particleLabel);
521 const std::vector<art::Ptr<recob::SpacePoint>> pfpSpacePoints = findSpacePoints.at(particle.
Self());
524 std::vector<const recob::SpacePoint*> sp;
525 for(
auto pointer : pfpSpacePoints){
526 sp.push_back(pointer.get());
543 auto particles = evt.
getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
544 const art::FindManyP<recob::Cluster> findClusters(particles,evt,particleLabel);
545 const std::vector<art::Ptr<recob::Cluster>> pfpClusters = findClusters.at(particle.
Self());
548 std::vector<const recob::Cluster*> clusters;
549 for(
auto pointer : pfpClusters){
550 clusters.push_back(pointer.get());
566 const std::vector<const recob::Cluster*> pfpClusters =
GetPFParticleClusters(particle,evt,particleLabel);
567 auto allClusters = evt.
getValidHandle<std::vector<recob::Cluster>>(particleLabel);
568 const art::FindManyP<recob::Hit> findHits(allClusters,evt,particleLabel);
570 std::vector<const recob::Hit*> pfpHits;
573 for(
auto cluster : pfpClusters){
574 const std::vector<art::Ptr<recob::Hit>> clusterHits = findHits.at(
cluster->ID());
576 for(
auto hit : clusterHits){
577 pfpHits.push_back(
hit.get());
587 const std::vector<const recob::Cluster*> pfpClusters =
GetPFParticleClusters(particle,evt,particleLabel);
588 auto allClusters = evt.
getValidHandle<std::vector<recob::Cluster>>(particleLabel);
589 const art::FindManyP<recob::Hit> findHits(allClusters,evt,particleLabel);
591 std::vector<const recob::Hit*> pfpHits;
593 std::cout <<
"Please input plane 0, 1, or 2" <<
std::endl;
598 for(
auto cluster : pfpClusters){
599 const std::vector<art::Ptr<recob::Hit>> clusterHits = findHits.at(
cluster->ID());
601 for(
auto hit : clusterHits){
602 unsigned int thePlane =
hit.get()->WireID().asPlaneID().Plane;
603 if( thePlane != planeID )
continue;
605 pfpHits.push_back(
hit.get());
614 const std::vector<const recob::Cluster*> pfpClusters =
GetPFParticleClusters(particle,evt,particleLabel);
615 auto allClusters = evt.
getValidHandle<std::vector<recob::Cluster>>(particleLabel);
616 const art::FindManyP<recob::Hit> findHits(allClusters,evt,particleLabel);
618 std::vector< art::Ptr< recob::Hit > > pfpHits;
621 for(
auto cluster : pfpClusters){
622 const std::vector<art::Ptr<recob::Hit>> clusterHits = findHits.at(
cluster->ID());
623 for(
auto hit : clusterHits){
624 pfpHits.push_back(
hit);
633 const std::vector<const recob::Cluster*> pfpClusters =
GetPFParticleClusters(particle,evt,particleLabel);
634 auto allClusters = evt.
getValidHandle<std::vector<recob::Cluster>>(particleLabel);
635 const art::FindManyP<recob::Hit> findHits(allClusters,evt,particleLabel);
637 std::vector< art::Ptr< recob::Hit > > pfpHits;
640 for(
auto cluster : pfpClusters){
641 const std::vector<art::Ptr<recob::Hit>> clusterHits = findHits.at(
cluster->ID());
642 for(
auto hit : clusterHits){
643 size_t thePlane =
hit.get()->WireID().asPlaneID().Plane;
644 if( thePlane != planeID )
continue;
645 pfpHits.push_back(
hit);
662 const std::vector<const recob::Hit*> hitvector =
GetPFParticleHits(particle, evt, particleLabel);
664 double hitcharge[3] = {0.0, 0.0, 0.0};
665 for(
auto hit : hitvector){
666 int hit_plane = (
int)
hit->WireID().Plane;
667 if(hit_plane < 0)
continue;
668 if(hit_plane > 2)
continue;
670 hitcharge[hit_plane] +=
hit->Integral();
673 std::vector<double> hitchargevec;
674 for(
int i = 0; i < 3; i++)
675 hitchargevec.push_back(hitcharge[i]);
683 const std::vector<const recob::Hit*> hitvector =
GetPFParticleHits(particle, evt, particleLabel);
685 double earliesthittime = 999999.0;
686 for(
auto hit : hitvector){
687 if(
hit->PeakTime() < earliesthittime)
688 earliesthittime = (
double)
hit->PeakTime();
691 return earliesthittime;
699 auto particles = evt.
getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
701 std::vector<const recob::Track*> daughterTracks;
704 for(
size_t daughterID : particle.
Daughters()){
707 daughterTracks.push_back(track);
711 return daughterTracks;
720 auto particles = evt.
getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
722 std::vector<const recob::Shower*> daughterShowers;
725 for(
size_t daughterID : particle.
Daughters()){
728 daughterShowers.push_back(shower);
732 return daughterShowers;
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
const std::vector< size_t > & Daughters() const
Returns the collection of daughter particles.
bool IsBeamParticle(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Use the pandora metadata to tell us if this is a beam particle or not.
const std::vector< const recob::PFParticle * > GetAllPFParticlesFromSlice(const unsigned short slice, art::Event const &evt, const std::string particleLabel) const
Get all of the PFParticles from a given slice. Returns an empty vector if the slice number is not val...
std::vector< anab::T0 > GetPFParticleT0(const recob::PFParticle &particle, art::Event const &evt, std::string particleLabel) const
Get the T0(s) from a given PFParticle.
size_t Self() const
Returns the index of this particle.
const recob::Shower * GetPFParticleShower(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string showerLabel) const
Get the shower associated to this particle. Returns a null pointer if not found.
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
const std::vector< const recob::Hit * > GetPFParticleSliceUnassociatedHits(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
For a given PFParticle find its slice and return all those hits not associated to any PFParticle...
bool FindBoolInMetaData(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string entry) const
Look for entries in the meta data.
const std::vector< const recob::Hit * > GetPFParticleHits(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Get the hits associated to the PFParticle.
const TVector3 GetPFParticleVertex(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
Function to find the interaction vertex of a primary PFParticle.
bool IsClearCosmic(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Pandora tags and removes clear cosmics before slicing, so check if this particle is a clear cosmic...
~ProtoDUNEPFParticleUtils()
unsigned short GetPFParticleSliceIndex(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Get the reconstructed slice number associated with a particle.
int PdgCode() const
Return the type of particle as a PDG ID.
Cluster finding and building.
const double GetPFParticleEarliestHitPeakTime(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Get the earliest hit peak time.
bool IsPFParticleTracklike(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
Is the particle track-like?
bool IsPFParticleShowerlike(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string showerLabel) const
Is the particle track-like?
Definition of vertex object for LArSoft.
const std::vector< const recob::Hit * > GetRecoSliceHits(const recob::Slice &slice, art::Event const &evt, const std::string sliceModule) const
ProtoDUNEPFParticleUtils()
const std::vector< art::Ptr< recob::Hit > > GetPFParticleHitsFromPlane_Ptrs(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, size_t planeID) const
float FindFloatInMetaData(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string entry) const
const std::map< std::string, float > GetPFParticleMetaData(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Get the metadata associated to a PFParticle from pandora.
const std::vector< const recob::Cluster * > GetPFParticleClusters(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Get the clusters associated to the PFParticle.
Metadata associated to PFParticles.
unsigned short GetBeamSlice(art::Event const &evt, const std::string particleLabel) const
Try to get the slice tagged as beam. Returns 9999 if no beam slice was found.
const std::map< unsigned int, std::vector< const recob::PFParticle * > > GetAllPFParticleSliceMap(art::Event const &evt, const std::string particleLabel) const
Get a map of slice index to all of the PFParticles within it.
const recob::Track * GetPFParticleTrack(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
Get the track associated to this particle. Returns a null pointer if not found.
const PropertiesMap & GetPropertiesMap() const
const recob::Slice * GetPFParticleSlice(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Get the reconstructed slice associated with a particle.
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
const std::map< unsigned int, std::vector< const recob::PFParticle * > > GetPFParticleSliceMap(art::Event const &evt, const std::string particleLabel) const
Get a map of slice index to the primary PFParticles within it.
bool IsPrimary() const
Returns whether the particle is the root of the flow.
const std::vector< const recob::PFParticle * > GetPFParticlesFromBeamSlice(art::Event const &evt, const std::string particleLabel) const
Return the pointers for the PFParticles in the beam slice. Returns an empty vector is no beam slice w...
const std::vector< const recob::SpacePoint * > GetPFParticleSpacePoints(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
unsigned int GetNumberPFParticleSpacePoints(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Get the number of space points.
Detector simulation of raw signals on wires.
const std::vector< double > GetPFParticleHitsCharge(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Get the total hit charge for each view.
Hierarchical representation of particle flow.
unsigned int GetNumberPFParticleClusters(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Get the number of clusters associated to the PFParticle.
const std::vector< const recob::PFParticle * > GetClearCosmicPFParticles(art::Event const &evt, const std::string particleLabel) const
Get all of the clear cosmic ray particles.
std::vector< anab::CosmicTag > GetPFParticleCosmicTag(const recob::PFParticle &particle, art::Event const &evt, std::string particleLabel) const
Get the cosmic tag(s) from a given PFParticle.
const std::vector< const recob::Shower * > GetPFParticleDaughterShowers(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string showerLabel) const
Get the daughter showers from the PFParticle.
const std::vector< const recob::PFParticle * > GetPFParticlesFromSlice(const unsigned short slice, art::Event const &evt, const std::string particleLabel) const
Get the Primary PFParticles from a given slice. Returns an empty vector if the slice number is not va...
Point_t const & End() const
Returns the position of the last valid point of the trajectory [cm].
Provides recob::Track data product.
const std::vector< art::Ptr< recob::Hit > > GetPFParticleHits_Ptrs(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
const TVector3 GetPFParticleSecondaryVertex(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
Function to find the secondary interaction vertex of a primary PFParticle.
const std::vector< const recob::Hit * > GetPFParticleHitsFromPlane(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, unsigned int planeID) const
2D representation of charge deposited in the TDC/wire plane
const std::map< unsigned int, std::vector< const recob::PFParticle * > > SliceMapHelper(art::Event const &evt, const std::string particleLabel, bool primaryOnly) const
Helper to get the slice map and avoid code repetition.
unsigned int GetNumberPrimaryPFParticle(art::Event const &evt, const std::string particleLabel) const
Get the number of primary PFParticles.
Point_t const & Start() const
Returns the position of the first valid point of the trajectory [cm].
const std::vector< const recob::Hit * > GetPFParticleSliceHits(const recob::PFParticle &particlei, art::Event const &evt, const std::string particleLabel) const
For a given PFParticle, return all hits from the slice it comes from.
const std::vector< const recob::Track * > GetPFParticleDaughterTracks(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
Get the daughter tracks from the PFParticle.
float GetBeamCosmicScore(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Access the BDT output used to decide if a slice is beam-like or cosmic-like.
unsigned int GetNumberPFParticleHits(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Get the number of hits.
const Point_t & position() const
Return vertex 3D position.
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
QTextStream & endl(QTextStream &s)