Public Member Functions | Private Member Functions | List of all members
protoana::ProtoDUNEPFParticleUtils Class Reference

#include <ProtoDUNEPFParticleUtils.h>

Public Member Functions

 ProtoDUNEPFParticleUtils ()
 
 ~ProtoDUNEPFParticleUtils ()
 
unsigned int GetNumberPrimaryPFParticle (art::Event const &evt, const std::string particleLabel) const
 Get the number of primary PFParticles. More...
 
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. More...
 
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. More...
 
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 valid. More...
 
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 valid. More...
 
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. More...
 
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 was found. More...
 
const recob::SliceGetPFParticleSlice (const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
 Get the reconstructed slice associated with a particle. More...
 
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. More...
 
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. More...
 
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. More...
 
std::vector< anab::CosmicTagGetPFParticleCosmicTag (const recob::PFParticle &particle, art::Event const &evt, std::string particleLabel) const
 Get the cosmic tag(s) from a given PFParticle. More...
 
std::vector< anab::T0GetPFParticleT0 (const recob::PFParticle &particle, art::Event const &evt, std::string particleLabel) const
 Get the T0(s) from a given PFParticle. More...
 
std::vector< anab::T0GetPFParticleT0 (const recob::PFParticle &particle, art::Event const &evt, std::string particleLabel, std::string t0Label) const
 
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. More...
 
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. More...
 
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. More...
 
const std::vector< const recob::PFParticle * > GetClearCosmicPFParticles (art::Event const &evt, const std::string particleLabel) const
 Get all of the clear cosmic ray particles. More...
 
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. More...
 
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. More...
 
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. More...
 
bool IsPFParticleTracklike (const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
 Is the particle track-like? More...
 
bool IsPFParticleTracklike (const recob::PFParticle &particle) const
 
bool IsPFParticleShowerlike (const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string showerLabel) const
 Is the particle track-like? More...
 
bool IsPFParticleShowerlike (const recob::PFParticle &particle) const
 
const recob::TrackGetPFParticleTrack (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. More...
 
const recob::ShowerGetPFParticleShower (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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
const std::vector< const recob::Hit * > GetPFParticleHitsFromPlane (const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, unsigned int planeID) const
 
const std::vector< art::Ptr< recob::Hit > > GetPFParticleHits_Ptrs (const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
 
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
 
unsigned int GetNumberPFParticleHits (const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
 Get the number of hits. More...
 
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. More...
 
const double GetPFParticleEarliestHitPeakTime (const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
 Get the earliest hit peak time. More...
 
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. More...
 
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. More...
 

Private Member Functions

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. More...
 
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. More...
 
float FindFloatInMetaData (const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string entry) const
 

Detailed Description

Definition at line 30 of file ProtoDUNEPFParticleUtils.h.

Constructor & Destructor Documentation

protoana::ProtoDUNEPFParticleUtils::ProtoDUNEPFParticleUtils ( )

Definition at line 15 of file ProtoDUNEPFParticleUtils.cxx.

15  {
16 
17 }
protoana::ProtoDUNEPFParticleUtils::~ProtoDUNEPFParticleUtils ( )

Definition at line 19 of file ProtoDUNEPFParticleUtils.cxx.

19  {
20 
21 }

Member Function Documentation

bool protoana::ProtoDUNEPFParticleUtils::FindBoolInMetaData ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel,
const std::string  entry 
) const
private

Look for entries in the meta data.

Definition at line 195 of file ProtoDUNEPFParticleUtils.cxx.

195  {
196 
197  std::map<std::string,float> mdMap = GetPFParticleMetaData(particle,evt,particleLabel);
198 
199  if(mdMap.find(entry) != mdMap.end()){
200  return true;
201  }
202  else{
203  return false;
204  }
205 
206 }
QList< Entry > entry
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.
TCEvent evt
Definition: DataStructs.cxx:7
float protoana::ProtoDUNEPFParticleUtils::FindFloatInMetaData ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel,
const std::string  entry 
) const
private

Definition at line 208 of file ProtoDUNEPFParticleUtils.cxx.

208  {
209 
210  std::map<std::string,float> mdMap = GetPFParticleMetaData(particle,evt,particleLabel);
211 
212  if(mdMap.find(entry) != mdMap.end()){
213  return mdMap.at(entry);
214  }
215  else{
216  return -999.;
217  }
218 
219 }
QList< Entry > entry
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.
TCEvent evt
Definition: DataStructs.cxx:7
const std::vector< const recob::PFParticle * > protoana::ProtoDUNEPFParticleUtils::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 valid.

Definition at line 161 of file ProtoDUNEPFParticleUtils.cxx.

161  {
162 
163  const std::map<unsigned int, std::vector<const recob::PFParticle*>> sliceMap = GetAllPFParticleSliceMap(evt,particleLabel);
164 
165  if(sliceMap.find(slice) != sliceMap.end()){
166  return sliceMap.at(slice);
167  }
168  else{
169  return std::vector<const recob::PFParticle*>();
170  }
171 
172 }
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.
TCEvent evt
Definition: DataStructs.cxx:7
const std::map< unsigned int, std::vector< const recob::PFParticle * > > protoana::ProtoDUNEPFParticleUtils::GetAllPFParticleSliceMap ( art::Event const &  evt,
const std::string  particleLabel 
) const

Get a map of slice index to all of the PFParticles within it.

Definition at line 72 of file ProtoDUNEPFParticleUtils.cxx.

72  {
73 
74  return SliceMapHelper(evt,particleLabel,false);
75 
76 }
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.
TCEvent evt
Definition: DataStructs.cxx:7
float protoana::ProtoDUNEPFParticleUtils::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.

Definition at line 182 of file ProtoDUNEPFParticleUtils.cxx.

182  {
183 
184  return FindFloatInMetaData(particle,evt,particleLabel,"TestBeamScore");
185 
186 }
float FindFloatInMetaData(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string entry) const
TCEvent evt
Definition: DataStructs.cxx:7
unsigned short protoana::ProtoDUNEPFParticleUtils::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.

Definition at line 130 of file ProtoDUNEPFParticleUtils.cxx.

130  {
131 
132  const std::map<unsigned int, std::vector<const recob::PFParticle*>> sliceMap = GetPFParticleSliceMap(evt,particleLabel);
133 
134  for(auto slice : sliceMap){
135  for(auto particle : slice.second){
136  if(IsBeamParticle(*particle,evt,particleLabel)){
137  return slice.first;
138  }
139  }
140  }
141 
142  return 9999;
143 
144 }
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::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.
TCEvent evt
Definition: DataStructs.cxx:7
const std::vector< const recob::PFParticle * > protoana::ProtoDUNEPFParticleUtils::GetClearCosmicPFParticles ( art::Event const &  evt,
const std::string  particleLabel 
) const

Get all of the clear cosmic ray particles.

Definition at line 328 of file ProtoDUNEPFParticleUtils.cxx.

328  {
329 
330  // Get the particles
331  auto pfParticles = evt.getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
332 
333  std::vector<const recob::PFParticle*> cosmicParticles;
334 
335  for(unsigned int p = 0; p < pfParticles->size(); ++p){
336  const recob::PFParticle* particle = &(pfParticles->at(p));
337 
338  // Only consider primary particles
339  if(!particle->IsPrimary()) continue;
340 
341  if(IsClearCosmic(*particle,evt,particleLabel)){
342  cosmicParticles.push_back(particle);
343  }
344 
345  }
346 
347  return cosmicParticles;
348 
349 }
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...
p
Definition: test.py:223
bool IsPrimary() const
Returns whether the particle is the root of the flow.
Definition: PFParticle.h:86
Hierarchical representation of particle flow.
Definition: PFParticle.h:44
TCEvent evt
Definition: DataStructs.cxx:7
unsigned int protoana::ProtoDUNEPFParticleUtils::GetNumberPFParticleClusters ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel 
) const

Get the number of clusters associated to the PFParticle.

Definition at line 557 of file ProtoDUNEPFParticleUtils.cxx.

557  {
558 
559  return GetPFParticleClusters(particle,evt,particleLabel).size();
560 
561 }
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.
TCEvent evt
Definition: DataStructs.cxx:7
unsigned int protoana::ProtoDUNEPFParticleUtils::GetNumberPFParticleHits ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel 
) const

Get the number of hits.

Definition at line 653 of file ProtoDUNEPFParticleUtils.cxx.

653  {
654 
655  return GetPFParticleHits(particle,evt,particleLabel).size();
656 
657 }
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.
TCEvent evt
Definition: DataStructs.cxx:7
unsigned int protoana::ProtoDUNEPFParticleUtils::GetNumberPFParticleSpacePoints ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel 
) const

Get the number of space points.

Definition at line 533 of file ProtoDUNEPFParticleUtils.cxx.

533  {
534 
535  return GetPFParticleSpacePoints(particle,evt,particleLabel).size();
536 
537 }
const std::vector< const recob::SpacePoint * > GetPFParticleSpacePoints(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
TCEvent evt
Definition: DataStructs.cxx:7
unsigned int protoana::ProtoDUNEPFParticleUtils::GetNumberPrimaryPFParticle ( art::Event const &  evt,
const std::string  particleLabel 
) const

Get the number of primary PFParticles.

Definition at line 24 of file ProtoDUNEPFParticleUtils.cxx.

24  {
25 
26  // Get the particles
27  auto pfParticles = evt.getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
28 
29  unsigned int nPrimary = 0;
30  for(unsigned int p = 0; p < pfParticles->size(); ++p){
31  if(pfParticles->at(p).IsPrimary()){
32  ++nPrimary;
33  }
34  }
35 
36  return nPrimary;
37 }
p
Definition: test.py:223
TCEvent evt
Definition: DataStructs.cxx:7
const std::vector< const recob::Cluster * > protoana::ProtoDUNEPFParticleUtils::GetPFParticleClusters ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel 
) const

Get the clusters associated to the PFParticle.

Definition at line 540 of file ProtoDUNEPFParticleUtils.cxx.

540  {
541 
542  // Get the particles and their associations
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());
546 
547  // We don't want the art::Ptr so we need to get rid of it
548  std::vector<const recob::Cluster*> clusters;
549  for(auto pointer : pfpClusters){
550  clusters.push_back(pointer.get());
551  }
552 
553  return clusters;
554 }
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:92
TCEvent evt
Definition: DataStructs.cxx:7
std::vector< anab::CosmicTag > protoana::ProtoDUNEPFParticleUtils::GetPFParticleCosmicTag ( const recob::PFParticle particle,
art::Event const &  evt,
std::string  particleLabel 
) const

Get the cosmic tag(s) from a given PFParticle.

Definition at line 79 of file ProtoDUNEPFParticleUtils.cxx.

79  {
80 
81  try{
82  auto recoParticles = evt.getValidHandle<std::vector<recob::PFParticle> >(particleLabel);
83 
84  unsigned int pIndex = particle.Self();
85 
86  std::vector<anab::CosmicTag> pTags;
87 
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])));
91  }
92 
93  return pTags;
94  }
95  catch(...){
96  return std::vector<anab::CosmicTag>();
97  }
98 }
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:92
p
Definition: test.py:223
TCEvent evt
Definition: DataStructs.cxx:7
const std::vector< const recob::Shower * > protoana::ProtoDUNEPFParticleUtils::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.

Definition at line 716 of file ProtoDUNEPFParticleUtils.cxx.

717  {
718 
719  // Get the PFParticles
720  auto particles = evt.getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
721 
722  std::vector<const recob::Shower*> daughterShowers;
723 
724  // Loop over the daughters
725  for(size_t daughterID : particle.Daughters()){
726  const recob::Shower* shower = GetPFParticleShower(particles->at(daughterID),evt,particleLabel,showerLabel);
727  if(shower != 0x0){
728  daughterShowers.push_back(shower);
729  }
730  }
731 
732  return daughterShowers;
733 
734 }
const std::vector< size_t > & Daughters() const
Returns the collection of daughter particles.
Definition: PFParticle.h:114
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.
TCEvent evt
Definition: DataStructs.cxx:7
const std::vector< const recob::Track * > protoana::ProtoDUNEPFParticleUtils::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.

Definition at line 695 of file ProtoDUNEPFParticleUtils.cxx.

696  {
697 
698  // Get the PFParticles
699  auto particles = evt.getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
700 
701  std::vector<const recob::Track*> daughterTracks;
702 
703  // Loop over the daughters
704  for(size_t daughterID : particle.Daughters()){
705  const recob::Track* track = GetPFParticleTrack(particles->at(daughterID),evt,particleLabel,trackLabel);
706  if(track != 0x0){
707  daughterTracks.push_back(track);
708  }
709  }
710 
711  return daughterTracks;
712 
713 }
const std::vector< size_t > & Daughters() const
Returns the collection of daughter particles.
Definition: PFParticle.h:114
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.
TCEvent evt
Definition: DataStructs.cxx:7
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
const double protoana::ProtoDUNEPFParticleUtils::GetPFParticleEarliestHitPeakTime ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel 
) const

Get the earliest hit peak time.

Definition at line 681 of file ProtoDUNEPFParticleUtils.cxx.

681  {
682 
683  const std::vector<const recob::Hit*> hitvector = GetPFParticleHits(particle, evt, particleLabel);
684 
685  double earliesthittime = 999999.0;
686  for(auto hit : hitvector){
687  if(hit->PeakTime() < earliesthittime)
688  earliesthittime = (double)hit->PeakTime();
689  }
690 
691  return earliesthittime;
692 }
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.
Detector simulation of raw signals on wires.
TCEvent evt
Definition: DataStructs.cxx:7
const std::vector< const recob::Hit * > protoana::ProtoDUNEPFParticleUtils::GetPFParticleHits ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel 
) const

Get the hits associated to the PFParticle.

Definition at line 564 of file ProtoDUNEPFParticleUtils.cxx.

564  {
565 
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);
569 
570  std::vector<const recob::Hit*> pfpHits;
571 
572  // Store all of the hits in a single vector
573  for(auto cluster : pfpClusters){
574  const std::vector<art::Ptr<recob::Hit>> clusterHits = findHits.at(cluster->ID());
575 // std::cout << "Cluster has " << clusterHits.size() << " hits" << std::endl;
576  for(auto hit : clusterHits){
577  pfpHits.push_back(hit.get());
578  }
579  }
580 
581  return pfpHits;
582 }
Cluster finding and building.
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.
Detector simulation of raw signals on wires.
TCEvent evt
Definition: DataStructs.cxx:7
const std::vector< art::Ptr< recob::Hit > > protoana::ProtoDUNEPFParticleUtils::GetPFParticleHits_Ptrs ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel 
) const

Definition at line 612 of file ProtoDUNEPFParticleUtils.cxx.

612  {
613 
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);
617 
618  std::vector< art::Ptr< recob::Hit > > pfpHits;
619 
620  // Store all of the hits in a single vector
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);
625  }
626  }
627 
628  return pfpHits;
629 }
Cluster finding and building.
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.
Detector simulation of raw signals on wires.
TCEvent evt
Definition: DataStructs.cxx:7
const std::vector< double > protoana::ProtoDUNEPFParticleUtils::GetPFParticleHitsCharge ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel 
) const

Get the total hit charge for each view.

Definition at line 660 of file ProtoDUNEPFParticleUtils.cxx.

660  {
661 
662  const std::vector<const recob::Hit*> hitvector = GetPFParticleHits(particle, evt, particleLabel);
663 
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;
669  //hitcharge[hit_plane] += hit->SummedADC();
670  hitcharge[hit_plane] += hit->Integral();
671  }
672 
673  std::vector<double> hitchargevec;
674  for(int i = 0; i < 3; i++)
675  hitchargevec.push_back(hitcharge[i]);
676 
677  return hitchargevec;
678 }
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.
Detector simulation of raw signals on wires.
TCEvent evt
Definition: DataStructs.cxx:7
const std::vector< const recob::Hit * > protoana::ProtoDUNEPFParticleUtils::GetPFParticleHitsFromPlane ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel,
unsigned int  planeID 
) const

Definition at line 585 of file ProtoDUNEPFParticleUtils.cxx.

585  {
586 
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);
590 
591  std::vector<const recob::Hit*> pfpHits;
592  if( planeID > 2 ){
593  std::cout << "Please input plane 0, 1, or 2" << std::endl;
594  return pfpHits;
595  }
596 
597  // Store all of the hits in a single vector
598  for(auto cluster : pfpClusters){
599  const std::vector<art::Ptr<recob::Hit>> clusterHits = findHits.at(cluster->ID());
600 // std::cout << "Cluster has " << clusterHits.size() << " hits" << std::endl;
601  for(auto hit : clusterHits){
602  unsigned int thePlane = hit.get()->WireID().asPlaneID().Plane;
603  if( thePlane != planeID ) continue;
604 
605  pfpHits.push_back(hit.get());
606  }
607  }
608 
609  return pfpHits;
610 }
Cluster finding and building.
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.
Detector simulation of raw signals on wires.
TCEvent evt
Definition: DataStructs.cxx:7
QTextStream & endl(QTextStream &s)
const std::vector< art::Ptr< recob::Hit > > protoana::ProtoDUNEPFParticleUtils::GetPFParticleHitsFromPlane_Ptrs ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel,
size_t  planeID 
) const

Definition at line 631 of file ProtoDUNEPFParticleUtils.cxx.

631  {
632 
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);
636 
637  std::vector< art::Ptr< recob::Hit > > pfpHits;
638 
639  // Store all of the hits in a single vector
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);
646  }
647  }
648 
649  return pfpHits;
650 }
Cluster finding and building.
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.
Detector simulation of raw signals on wires.
TCEvent evt
Definition: DataStructs.cxx:7
const std::map< std::string, float > protoana::ProtoDUNEPFParticleUtils::GetPFParticleMetaData ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel 
) const

Get the metadata associated to a PFParticle from pandora.

Definition at line 308 of file ProtoDUNEPFParticleUtils.cxx.

308  {
309 
310  // Get the particles
311  auto pfParticles = evt.getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
312  // And their meta data
313  const art::FindManyP<larpandoraobj::PFParticleMetadata> findMetaData(pfParticles,evt,particleLabel);
314 
315  const larpandoraobj::PFParticleMetadata metaData = *((findMetaData.at(particle.Self())).at(0));
316 
317  return metaData.GetPropertiesMap();
318 }
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:92
Metadata associated to PFParticles.
const PropertiesMap & GetPropertiesMap() const
TCEvent evt
Definition: DataStructs.cxx:7
const TVector3 protoana::ProtoDUNEPFParticleUtils::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.

Definition at line 407 of file ProtoDUNEPFParticleUtils.cxx.

407  {
408 
409  // In this case we want to find the end of the track-like PFParticle
410  // To do this, we need to access things via the track
411 
412  // Showers have no secondary vertex
413  if(!IsPFParticleTracklike(particle,evt,particleLabel,trackLabel)){
414  std::cerr << "Shower-like PFParticles have no secondary vertex. Returning default TVector3" << std::endl;
415  return TVector3();
416  }
417 
418  const recob::Track* track = GetPFParticleTrack(particle,evt,particleLabel,trackLabel);
419 
420  // Interaction vertex is the downstream end of the track, or the bottom for cosmics
421  if(track != 0x0){
422  const TVector3 start(track->Trajectory().Start().X(),track->Trajectory().Start().Y(),track->Trajectory().Start().Z());
423  const TVector3 end(track->Trajectory().End().X(),track->Trajectory().End().Y(),track->Trajectory().End().Z());
424 
425  // Return the most downstream point as some cases where the track is reversed...
426  if(IsBeamParticle(particle,evt,particleLabel)){
427  if(start.Z() > end.Z()) return start;
428  else return end;
429  }
430  // Return the lowest point for cosmics
431  else{
432  if(start.Y() < end.Y()) return start;
433  else return end;
434  }
435 
436  }
437  else{
438  std::cerr << "This track-like PFParticle has no associated track. Returning default TVector3" << std::endl;
439  return TVector3();
440  }
441 
442 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
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 recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Definition: Track.h:98
bool IsPFParticleTracklike(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
Is the particle track-like?
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.
Point_t const & End() const
Returns the position of the last valid point of the trajectory [cm].
TCEvent evt
Definition: DataStructs.cxx:7
Point_t const & Start() const
Returns the position of the first valid point of the trajectory [cm].
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
QTextStream & endl(QTextStream &s)
const std::vector< const recob::PFParticle * > protoana::ProtoDUNEPFParticleUtils::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 was found.

Definition at line 175 of file ProtoDUNEPFParticleUtils.cxx.

175  {
176 
177  unsigned short beamSlice = GetBeamSlice(evt,particleLabel);
178  return GetPFParticlesFromSlice(beamSlice,evt,particleLabel);
179 }
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::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...
TCEvent evt
Definition: DataStructs.cxx:7
const std::vector< const recob::PFParticle * > protoana::ProtoDUNEPFParticleUtils::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 valid.

Definition at line 147 of file ProtoDUNEPFParticleUtils.cxx.

147  {
148 
149  const std::map<unsigned int, std::vector<const recob::PFParticle*>> sliceMap = GetPFParticleSliceMap(evt,particleLabel);
150 
151  if(sliceMap.find(slice) != sliceMap.end()){
152  return sliceMap.at(slice);
153  }
154  else{
155  return std::vector<const recob::PFParticle*>();
156  }
157 
158 }
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.
TCEvent evt
Definition: DataStructs.cxx:7
const recob::Shower * protoana::ProtoDUNEPFParticleUtils::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.

Definition at line 496 of file ProtoDUNEPFParticleUtils.cxx.

496  {
497 
498  // Pandora produces associations between PFParticles and recob::Track objects
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());
502 
503  // Check that the shower exists
504  if(pfpShowers.size() != 0){
505  const recob::Shower* shw = (pfpShowers.at(0)).get();
506  return shw;
507  }
508  else{
509 // std::cerr << "No shower found, returning null pointer" << std::endl;
510  return nullptr;
511  }
512 
513 }
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:92
TCEvent evt
Definition: DataStructs.cxx:7
const recob::Slice * protoana::ProtoDUNEPFParticleUtils::GetPFParticleSlice ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel 
) const

Get the reconstructed slice associated with a particle.

Definition at line 223 of file ProtoDUNEPFParticleUtils.cxx.

223  {
224 
225  // Perhaps we should use the associations to do this?
226  auto pfParticles = evt.getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
227  const art::FindOneP<recob::Slice> findSlice(pfParticles,evt,particleLabel);
228 
229  const recob::Slice* slice = findSlice.at(particle.Self()).get();
230 
231  return slice;
232 }
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:92
TCEvent evt
Definition: DataStructs.cxx:7
const std::vector< const recob::Hit * > protoana::ProtoDUNEPFParticleUtils::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.

Definition at line 258 of file ProtoDUNEPFParticleUtils.cxx.

258  {
259 
260  // Use the slice utility to help us out
262 
263  unsigned short sliceIndex = GetPFParticleSliceIndex(particle,evt,particleLabel);
264  const std::vector<const recob::Hit*> hits = sliceUtil.GetRecoSliceHits(sliceIndex,evt,particleLabel);
265 
266  return hits;
267 }
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.
const std::vector< const recob::Hit * > GetRecoSliceHits(const recob::Slice &slice, art::Event const &evt, const std::string sliceModule) const
TCEvent evt
Definition: DataStructs.cxx:7
unsigned short protoana::ProtoDUNEPFParticleUtils::GetPFParticleSliceIndex ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel 
) const

Get the reconstructed slice number associated with a particle.

Definition at line 235 of file ProtoDUNEPFParticleUtils.cxx.

235  {
236 
237  // Try to use slices if we can
238  try{
239  const recob::Slice* slice = GetPFParticleSlice(particle,evt,particleLabel);
240  return slice->ID();
241  }
242  // Otherwise fall back on metadata
243  catch(...){
244  std::map<std::string,float> mdMap = GetPFParticleMetaData(particle,evt,particleLabel);
245  std::string search = "SliceIndex";
246  if(mdMap.find(search) != mdMap.end()){
247  return static_cast<unsigned short>(mdMap.at(search));
248  }
249  else{
250 // std::cerr << "Object has no slice index... returning 9999" << std::endl;
251  return 9999;
252  }
253  }
254 
255 }
std::string string
Definition: nybbler.cc:12
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 recob::Slice * GetPFParticleSlice(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Get the reconstructed slice associated with a particle.
Definition: search.py:1
int ID() const
Definition: Slice.h:29
TCEvent evt
Definition: DataStructs.cxx:7
const std::map< unsigned int, std::vector< const recob::PFParticle * > > protoana::ProtoDUNEPFParticleUtils::GetPFParticleSliceMap ( art::Event const &  evt,
const std::string  particleLabel 
) const

Get a map of slice index to the primary PFParticles within it.

Definition at line 65 of file ProtoDUNEPFParticleUtils.cxx.

65  {
66 
67  return SliceMapHelper(evt,particleLabel,true);
68 
69 }
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.
TCEvent evt
Definition: DataStructs.cxx:7
const std::vector< const recob::Hit * > protoana::ProtoDUNEPFParticleUtils::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.

Definition at line 270 of file ProtoDUNEPFParticleUtils.cxx.

270  {
271 
272  unsigned short sliceNumber = GetPFParticleSliceIndex(particle,evt,particleLabel);
273  const std::vector<const recob::Hit*> hits = GetPFParticleSliceHits(particle,evt,particleLabel);
274 
275  std::vector<bool> hitUsed(hits.size(),false);
276  std::vector<const recob::Hit*> unassocHits;
277 
278  // We need to iterate through the PFParticles in this slice and get their hits
279  const std::vector<const recob::PFParticle*> slicePFPs = GetAllPFParticlesFromSlice(sliceNumber,evt,particleLabel);
280 
281  for(auto const p : slicePFPs){
282 
283  // We are in the correct slice, so get the hits
284  const std::vector<const recob::Hit*> pfpHits = GetPFParticleHits(*p,evt,particleLabel);
285 
286  std::cout << "Hit vector sizes: " << hits.size() << ", " << pfpHits.size() << std::endl;
287 
288  for(const recob::Hit* h : pfpHits){
289  // Loop through the hit collection from the slice
290  for(unsigned int o = 0; o < hits.size(); ++o){
291  if(fabs(h->Integral() - hits[o]->Integral()) < 1e-5 && fabs(h->PeakTime() - hits[o]->PeakTime()) < 1e-5){
292  hitUsed[o] = true;
293  break;
294  }
295  }
296  }
297  }
298 
299  // Now we can fill our unassociated hits vector
300  for(unsigned int i = 0; i < hits.size(); ++i){
301  if(!hitUsed[i]) unassocHits.push_back(hits[i]);
302  }
303  std::cout << " Number of unassociated hits = " << unassocHits.size() << " of " << hits.size() << std::endl;
304 
305  return unassocHits;
306 }
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...
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.
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.
const double e
p
Definition: test.py:223
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
TCEvent evt
Definition: DataStructs.cxx:7
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.
QTextStream & endl(QTextStream &s)
const std::vector< const recob::SpacePoint * > protoana::ProtoDUNEPFParticleUtils::GetPFParticleSpacePoints ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel 
) const

Definition at line 516 of file ProtoDUNEPFParticleUtils.cxx.

516  {
517 
518  // Get the particles and their associations
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());
522 
523  // We don't want the art::Ptr so we need to get rid of it
524  std::vector<const recob::SpacePoint*> sp;
525  for(auto pointer : pfpSpacePoints){
526  sp.push_back(pointer.get());
527  }
528 
529  return sp;
530 }
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:92
TCEvent evt
Definition: DataStructs.cxx:7
std::vector< anab::T0 > protoana::ProtoDUNEPFParticleUtils::GetPFParticleT0 ( const recob::PFParticle particle,
art::Event const &  evt,
std::string  particleLabel 
) const

Get the T0(s) from a given PFParticle.

Definition at line 101 of file ProtoDUNEPFParticleUtils.cxx.

101  {
102 
103  return GetPFParticleT0(particle,evt,particleLabel,particleLabel);
104 
105 }
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.
TCEvent evt
Definition: DataStructs.cxx:7
std::vector< anab::T0 > protoana::ProtoDUNEPFParticleUtils::GetPFParticleT0 ( const recob::PFParticle particle,
art::Event const &  evt,
std::string  particleLabel,
std::string  t0Label 
) const

Definition at line 107 of file ProtoDUNEPFParticleUtils.cxx.

107  {
108 
109  try{
110  auto recoParticles = evt.getValidHandle<std::vector<recob::PFParticle> >(particleLabel);
111 
112  unsigned int pIndex = particle.Self();
113 
114  std::vector<anab::T0> pT0s;
115 
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])));
119  }
120 
121  return pT0s;
122  }
123  catch(...){
124  return std::vector<anab::T0>();
125  }
126 
127 }
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:92
p
Definition: test.py:223
TCEvent evt
Definition: DataStructs.cxx:7
const recob::Track * protoana::ProtoDUNEPFParticleUtils::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.

Definition at line 476 of file ProtoDUNEPFParticleUtils.cxx.

476  {
477 
478  // Pandora produces associations between PFParticles and recob::Track objects
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());
482 
483  // Check that the track exists
484  if(pfpTracks.size() != 0){
485  const recob::Track* track = (pfpTracks.at(0)).get();
486  return track;
487  }
488  else{
489 // std::cerr << "No track found, returning null pointer" << std::endl;
490  return nullptr;
491  }
492 
493 }
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:92
TCEvent evt
Definition: DataStructs.cxx:7
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
const TVector3 protoana::ProtoDUNEPFParticleUtils::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.

Definition at line 352 of file ProtoDUNEPFParticleUtils.cxx.

352  {
353 
354  // Pandora produces associations between PFParticles and recob::Vertex objects
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());
358 
359  // What happens next depends on the type of event.
360  // Not primary -> just use the pfparticle vertex
361  // Shower objects -> just use the pfparticle vertex
362  // Cosmics -> use track start point
363  // Beam -> use track start point
364 
365 // std::cout << "PFParticle daughters " << particle.NumDaughters() << std::endl;
366 
367  // Non-primary particle or shower-like primary particle
368  if(!particle.IsPrimary() || !IsPFParticleTracklike(particle,evt,particleLabel,trackLabel)){
369  if(vertices.size() != 0){
370  const recob::Vertex* vtx = (vertices.at(0)).get();
371  return TVector3(vtx->position().X(),vtx->position().Y(),vtx->position().Z());
372  }
373  else{
374  std::cerr << "Non track-like PFParticle has no vertex?! Return default vector" << std::endl;
375  return TVector3();
376  }
377  }
378  else{
379  // Cosmic or track-like beam primary particle
380 
381  const recob::Track* track = GetPFParticleTrack(particle,evt,particleLabel,trackLabel);
382 
383  if(track != 0x0){
384  const TVector3 start(track->Trajectory().Start().X(),track->Trajectory().Start().Y(),track->Trajectory().Start().Z());
385  const TVector3 end(track->Trajectory().End().X(),track->Trajectory().End().Y(),track->Trajectory().End().Z());
386  // Return the most upstream point as some cases where the track is reversed...
387  if(IsBeamParticle(particle,evt,particleLabel)){
388  if(start.Z() < end.Z()) return start;
389  else return end;
390  }
391  // Return the highest point for cosmics
392  else{
393  if(start.Y() > end.Y()) return start;
394  else return end;
395  }
396  }
397  else{
398  std::cerr << "No track found for track-like PFParticle?! Return default vector" << std::endl;
399  return TVector3();
400  }
401 
402  }
403 
404 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
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.
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:92
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Definition: Track.h:98
bool IsPFParticleTracklike(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
Is the particle track-like?
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
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.
bool IsPrimary() const
Returns whether the particle is the root of the flow.
Definition: PFParticle.h:86
Point_t const & End() const
Returns the position of the last valid point of the trajectory [cm].
TCEvent evt
Definition: DataStructs.cxx:7
Point_t const & Start() const
Returns the position of the first valid point of the trajectory [cm].
const Point_t & position() const
Return vertex 3D position.
Definition: Vertex.h:60
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
QTextStream & endl(QTextStream &s)
bool protoana::ProtoDUNEPFParticleUtils::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.

Definition at line 189 of file ProtoDUNEPFParticleUtils.cxx.

189  {
190 
191  return FindBoolInMetaData(particle,evt,particleLabel,"IsTestBeam");
192 
193 }
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.
TCEvent evt
Definition: DataStructs.cxx:7
bool protoana::ProtoDUNEPFParticleUtils::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.

Definition at line 321 of file ProtoDUNEPFParticleUtils.cxx.

321  {
322 
323  return FindBoolInMetaData(particle,evt,particleLabel,"IsClearCosmic");
324 
325 }
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.
TCEvent evt
Definition: DataStructs.cxx:7
bool protoana::ProtoDUNEPFParticleUtils::IsPFParticleShowerlike ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel,
const std::string  showerLabel 
) const

Is the particle track-like?

Definition at line 464 of file ProtoDUNEPFParticleUtils.cxx.

464  {
465 
466  return (GetPFParticleShower(particle,evt,particleLabel,showerLabel) != 0x0);
467 
468 }
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.
TCEvent evt
Definition: DataStructs.cxx:7
bool protoana::ProtoDUNEPFParticleUtils::IsPFParticleShowerlike ( const recob::PFParticle particle) const

Definition at line 471 of file ProtoDUNEPFParticleUtils.cxx.

471  {
472  return !IsPFParticleTracklike(particle);
473 }
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 protoana::ProtoDUNEPFParticleUtils::IsPFParticleTracklike ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel,
const std::string  trackLabel 
) const

Is the particle track-like?

Definition at line 445 of file ProtoDUNEPFParticleUtils.cxx.

445  {
446 
447  return (GetPFParticleTrack(particle,evt,particleLabel,trackLabel) != 0x0);
448 
449 }
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.
TCEvent evt
Definition: DataStructs.cxx:7
bool protoana::ProtoDUNEPFParticleUtils::IsPFParticleTracklike ( const recob::PFParticle particle) const

Definition at line 452 of file ProtoDUNEPFParticleUtils.cxx.

452  {
453  std::cerr << "This function is deprecated, please use the version with four arguments." << std::endl;
454  if(abs(particle.PdgCode()) == 11){
455  return false;
456  }
457  else{
458  return true;
459  }
460 }
int PdgCode() const
Return the type of particle as a PDG ID.
Definition: PFParticle.h:83
T abs(T value)
QTextStream & endl(QTextStream &s)
const std::map< unsigned int, std::vector< const recob::PFParticle * > > protoana::ProtoDUNEPFParticleUtils::SliceMapHelper ( art::Event const &  evt,
const std::string  particleLabel,
bool  primaryOnly 
) const
private

Helper to get the slice map and avoid code repetition.

Definition at line 40 of file ProtoDUNEPFParticleUtils.cxx.

40  {
41 
42  // Get the particles
43  auto pfParticles = evt.getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
44 
45  std::map<unsigned int, std::vector<const recob::PFParticle*>> sliceMap;
46 
47  for(unsigned int p = 0; p < pfParticles->size(); ++p){
48  const recob::PFParticle* particle = &(pfParticles->at(p));
49 
50  // Only the primary particles have the slice association
51  if(primaryOnly && !particle->IsPrimary()) continue;
52 
53  unsigned int thisSlice = GetPFParticleSliceIndex(*particle,evt,particleLabel);
54 
55  if(thisSlice != 9999){
56  sliceMap[thisSlice].push_back(particle);
57  }
58  }
59 
60  return sliceMap;
61 
62 }
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.
p
Definition: test.py:223
bool IsPrimary() const
Returns whether the particle is the root of the flow.
Definition: PFParticle.h:86
Hierarchical representation of particle flow.
Definition: PFParticle.h:44
TCEvent evt
Definition: DataStructs.cxx:7

The documentation for this class was generated from the following files: