Public Member Functions | Private Member Functions | List of all members
cvn::CVNProtoDUNEUtils Class Reference

#include <CVNProtoDUNEUtils.h>

Public Member Functions

 CVNProtoDUNEUtils ()
 
 ~CVNProtoDUNEUtils ()
 
const std::vector< const recob::Hit * > GetRecoSliceHits (const recob::Slice &slice, art::Event const &evt, const std::string sliceModule) const
 
const std::vector< const recob::Hit * > GetRecoSliceHits (unsigned int sliceID, art::Event const &evt, const std::string sliceModule) const
 
const std::map< unsigned int, std::vector< const recob::Hit * > > GetRecoSliceHitMap (art::Event const &evt, const std::string sliceModule) const
 
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::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...
 
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 recob::SliceGetPFParticleSlice (const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
 Get the reconstructed slice associated with a particle. More...
 
const std::vector< const recob::SpacePoint * > GetPFParticleSpacePoints (const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
 Get the SpacePoints associated to the PFParticle. 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...
 

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...
 
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...
 

Detailed Description

Definition at line 26 of file CVNProtoDUNEUtils.h.

Constructor & Destructor Documentation

cvn::CVNProtoDUNEUtils::CVNProtoDUNEUtils ( )

Definition at line 8 of file CVNProtoDUNEUtils.cxx.

8  {
9 
10 }
cvn::CVNProtoDUNEUtils::~CVNProtoDUNEUtils ( )

Definition at line 12 of file CVNProtoDUNEUtils.cxx.

12  {
13 
14 }

Member Function Documentation

const std::map< unsigned int, std::vector< const recob::PFParticle * > > cvn::CVNProtoDUNEUtils::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 86 of file CVNProtoDUNEUtils.cxx.

86  {
87 
88  return SliceMapHelper(evt,particleLabel,false);
89 
90 }
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
unsigned short cvn::CVNProtoDUNEUtils::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 62 of file CVNProtoDUNEUtils.cxx.

62  {
63 
64  const std::map<unsigned int, std::vector<const recob::PFParticle*>> sliceMap = GetPFParticleSliceMap(evt,particleLabel);
65 
66  for(auto slice : sliceMap){
67  for(auto particle : slice.second){
68  if(IsBeamParticle(*particle,evt,particleLabel)){
69  return slice.first;
70  }
71  }
72  }
73 
74  return 9999;
75 
76 }
TCEvent evt
Definition: DataStructs.cxx:7
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.
const std::map< std::string, float > cvn::CVNProtoDUNEUtils::GetPFParticleMetaData ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel 
) const
private

Get the metadata associated to a PFParticle from pandora.

Definition at line 169 of file CVNProtoDUNEUtils.cxx.

169  {
170  // Get the particles
171  auto pfParticles = evt.getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
172  // And their meta data
173  const art::FindManyP<larpandoraobj::PFParticleMetadata> findMetaData(pfParticles,evt,particleLabel);
174 
175  const larpandoraobj::PFParticleMetadata metaData = *((findMetaData.at(particle.Self())).at(0));
176 
177  return metaData.GetPropertiesMap();
178 }
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 recob::Slice * cvn::CVNProtoDUNEUtils::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 135 of file CVNProtoDUNEUtils.cxx.

135  {
136 
137  // Perhaps we should use the associations to do this?
138  auto pfParticles = evt.getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
139  const art::FindOneP<recob::Slice> findSlice(pfParticles,evt,particleLabel);
140 
141  const recob::Slice* slice = findSlice.at(particle.Self()).get();
142 
143  return slice;
144 }
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:92
TCEvent evt
Definition: DataStructs.cxx:7
unsigned short cvn::CVNProtoDUNEUtils::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 147 of file CVNProtoDUNEUtils.cxx.

147  {
148 
149  // Try to use slices if we can
150  try{
151  const recob::Slice* slice = GetPFParticleSlice(particle,evt,particleLabel);
152  return slice->ID();
153  }
154  // Otherwise fall back on metadata
155  catch(...){
156  std::map<std::string,float> mdMap = GetPFParticleMetaData(particle,evt,particleLabel);
157  std::string search = "SliceIndex";
158  if(mdMap.find(search) != mdMap.end()){
159  return static_cast<unsigned short>(mdMap.at(search));
160  }
161  else{
162 // std::cerr << "Object has no slice index... returning 9999" << std::endl;
163  return 9999;
164  }
165  }
166 
167 }
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.
std::string string
Definition: nybbler.cc:12
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 * > > cvn::CVNProtoDUNEUtils::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 79 of file CVNProtoDUNEUtils.cxx.

79  {
80 
81  return SliceMapHelper(evt,particleLabel,true);
82 
83 }
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::SpacePoint * > cvn::CVNProtoDUNEUtils::GetPFParticleSpacePoints ( const recob::PFParticle particle,
art::Event const &  evt,
const std::string  particleLabel 
) const

Get the SpacePoints associated to the PFParticle.

Definition at line 118 of file CVNProtoDUNEUtils.cxx.

118  {
119 
120  // Get the particles and their associations
121  auto particles = evt.getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
122  const art::FindManyP<recob::SpacePoint> findSpacePoints(particles,evt,particleLabel);
123  const std::vector<art::Ptr<recob::SpacePoint>> pfpSpacePoints = findSpacePoints.at(particle.Self());
124 
125  // We don't want the art::Ptr so we need to get rid of it
126  std::vector<const recob::SpacePoint*> sp;
127  for(auto pointer : pfpSpacePoints){
128  sp.push_back(pointer.get());
129  }
130 
131  return sp;
132 }
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:92
TCEvent evt
Definition: DataStructs.cxx:7
const std::map< unsigned int, std::vector< const recob::Hit * > > cvn::CVNProtoDUNEUtils::GetRecoSliceHitMap ( art::Event const &  evt,
const std::string  sliceModule 
) const

Definition at line 43 of file CVNProtoDUNEUtils.cxx.

43  {
44 
45  auto recoSlices = evt.getValidHandle<std::vector<recob::Slice> >(sliceModule);
46  std::map<unsigned int, std::vector<const recob::Hit*>> hitMap;
47 
48  for(auto const slice : *recoSlices){
49 
50  const std::vector<const recob::Hit*> constvec = GetRecoSliceHits(slice.ID(),evt,sliceModule);
51  for(auto const h : constvec){
52  hitMap[slice.ID()].push_back(h);
53  }
54 
55  }
56 
57  return hitMap;
58 
59 }
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
const std::vector< const recob::Hit * > cvn::CVNProtoDUNEUtils::GetRecoSliceHits ( const recob::Slice slice,
art::Event const &  evt,
const std::string  sliceModule 
) const

Definition at line 17 of file CVNProtoDUNEUtils.cxx.

17  {
18 
19  return GetRecoSliceHits(slice.ID(),evt,sliceModule);
20 
21 }
const std::vector< const recob::Hit * > GetRecoSliceHits(const recob::Slice &slice, art::Event const &evt, const std::string sliceModule) const
int ID() const
Definition: Slice.h:29
TCEvent evt
Definition: DataStructs.cxx:7
const std::vector< const recob::Hit * > cvn::CVNProtoDUNEUtils::GetRecoSliceHits ( unsigned int  sliceID,
art::Event const &  evt,
const std::string  sliceModule 
) const

Definition at line 24 of file CVNProtoDUNEUtils.cxx.

24  {
25 
26  auto recoSlices = evt.getValidHandle<std::vector<recob::Slice> >(sliceModule);
27  art::FindManyP<recob::Hit> findHits(recoSlices,evt,sliceModule);
28  std::vector<art::Ptr<recob::Hit>> inputHits = findHits.at(sliceID);
29 
30  std::vector<const recob::Hit*> sliceHits;
31 
32  for(const art::Ptr<recob::Hit> hit : inputHits){
33 
34  sliceHits.push_back(hit.get());
35 
36  }
37 
38  return sliceHits;
39 
40 }
Detector simulation of raw signals on wires.
TCEvent evt
Definition: DataStructs.cxx:7
bool cvn::CVNProtoDUNEUtils::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 181 of file CVNProtoDUNEUtils.cxx.

181  {
182  std::map<std::string,float> mdMap = GetPFParticleMetaData(particle,evt,particleLabel);
183  if(mdMap.find("IsTestBeam") != mdMap.end()){
184  return true;
185  }
186  else{
187  return false;
188  }
189 }
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::map< unsigned int, std::vector< const recob::PFParticle * > > cvn::CVNProtoDUNEUtils::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 93 of file CVNProtoDUNEUtils.cxx.

93  {
94 
95  // Get the particles
96  auto pfParticles = evt.getValidHandle<std::vector<recob::PFParticle>>(particleLabel);
97 
98  std::map<unsigned int, std::vector<const recob::PFParticle*>> sliceMap;
99 
100  for(unsigned int p = 0; p < pfParticles->size(); ++p){
101  const recob::PFParticle* particle = &(pfParticles->at(p));
102 
103  // Only the primary particles have the slice association
104  if(primaryOnly && !particle->IsPrimary()) continue;
105 
106  unsigned int thisSlice = GetPFParticleSliceIndex(*particle,evt,particleLabel);
107 
108  if(thisSlice != 9999){
109  sliceMap[thisSlice].push_back(particle);
110  }
111  }
112 
113  return sliceMap;
114 
115 }
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: