DUNEAnaPFParticleUtils.cxx
Go to the documentation of this file.
1 /**
2 *
3 * @file dunereco/AnaUtils/DUNEAnaPFParticleUtils.cxx
4 *
5 * @brief Utility containing helpful functions for end users to access information about PFParticles
6 */
7 
9 
10 #include "cetlib_except/exception.h"
12 #include "canvas/Persistency/Common/FindManyP.h"
14 
25 
26 namespace dune_ana
27 {
28 
29 std::vector<art::Ptr<anab::T0>> DUNEAnaPFParticleUtils::GetT0(const art::Ptr<recob::PFParticle> &pParticle, const art::Event &evt, const std::string &label)
30 {
31  return DUNEAnaPFParticleUtils::GetAssocProductVector<anab::T0>(pParticle,evt,label,label);
32 }
33 
34 //-----------------------------------------------------------------------------------------------------------------------------------------
35 
36 std::vector<art::Ptr<anab::CosmicTag>> DUNEAnaPFParticleUtils::GetCosmicTag(const art::Ptr<recob::PFParticle> &pParticle, const art::Event &evt, const std::string &label)
37 {
38  return DUNEAnaPFParticleUtils::GetAssocProductVector<anab::CosmicTag>(pParticle,evt,label,label);
39 }
40 
41 //-----------------------------------------------------------------------------------------------------------------------------------------
42 
43 std::vector<art::Ptr<recob::PFParticle>> DUNEAnaPFParticleUtils::GetChildParticles(const art::Ptr<recob::PFParticle> &pParticle, const art::Event &evt, const std::string &label)
44 {
45  auto theseParticles = evt.getHandle<std::vector<recob::PFParticle>>(label);
46  bool success = theseParticles.isValid();
47 
48  if (!success)
49  {
50  mf::LogError("LArPandora") << " Failed to find product with label " << label << " ... returning empty vector" << std::endl;
51  return std::vector<art::Ptr<recob::PFParticle>>();
52  }
53 
54  std::vector<art::Ptr<recob::PFParticle>> children;
55 
56  for (unsigned int iPart = 0; iPart < theseParticles->size(); ++iPart)
57  {
58  if (theseParticles->at(iPart).Parent() == pParticle.key())
59  {
60  art::Ptr<recob::PFParticle> pChild(theseParticles,iPart);
61  children.push_back(pChild);
62  }
63  }
64 
65  return children;
66 }
67 
68 //-----------------------------------------------------------------------------------------------------------------------------------------
69 
70 std::vector<art::Ptr<recob::Hit>> DUNEAnaPFParticleUtils::GetHits(const art::Ptr<recob::PFParticle> &pParticle, const art::Event &evt, const std::string &label)
71 {
72  // There isn't a direct association between PFParticles and hits, so we go via clusters
73  const std::vector<art::Ptr<recob::Cluster>> theseClusters = DUNEAnaPFParticleUtils::GetAssocProductVector<recob::Cluster>(pParticle,evt,label,label);
74 
75  std::vector<art::Ptr<recob::Hit>> theseHits;
76  for (const art::Ptr<recob::Cluster> pCluster : theseClusters)
77  {
78  const std::vector<art::Ptr<recob::Hit>> tempHits = DUNEAnaPFParticleUtils::GetAssocProductVector<recob::Hit>(pCluster,evt,label,label);
79  theseHits.insert(theseHits.end(),tempHits.begin(),tempHits.end());
80  }
81  return theseHits;
82 }
83 
84 //-----------------------------------------------------------------------------------------------------------------------------------------
85 
86 std::vector<art::Ptr<recob::Hit>> DUNEAnaPFParticleUtils::GetViewHits(const art::Ptr<recob::PFParticle> &pParticle, const art::Event &evt, const std::string &label, const unsigned short &view)
87 {
88  // There isn't a direct association between PFParticles and hits, so we go via clusters
89  const std::vector<art::Ptr<recob::Cluster>> theseClusters = DUNEAnaPFParticleUtils::GetAssocProductVector<recob::Cluster>(pParticle,evt,label,label);
90 
91  std::vector<art::Ptr<recob::Hit>> theseHits;
92  for (const art::Ptr<recob::Cluster> pCluster : theseClusters)
93  {
94  const std::vector<art::Ptr<recob::Hit>> tempHits = DUNEAnaPFParticleUtils::GetAssocProductVector<recob::Hit>(pCluster,evt,label,label);
95  for(const art::Ptr<recob::Hit> pHit : tempHits)
96  {
97  if (pHit->View() == view)
98  {
99  theseHits.push_back(pHit);
100  }
101  }
102  }
103  return theseHits;
104 }
105 
106 //-----------------------------------------------------------------------------------------------------------------------------------------
107 
108 std::vector<art::Ptr<recob::SpacePoint>> DUNEAnaPFParticleUtils::GetSpacePoints(const art::Ptr<recob::PFParticle> &pParticle, const art::Event &evt, const std::string &label)
109 {
110  return DUNEAnaPFParticleUtils::GetAssocProductVector<recob::SpacePoint>(pParticle,evt,label,label);
111 }
112 
113 //-----------------------------------------------------------------------------------------------------------------------------------------
114 
116 {
117  return DUNEAnaPFParticleUtils::GetAssocProduct<recob::Track>(pParticle,evt,particleLabel,trackLabel);
118 }
119 
120 //-----------------------------------------------------------------------------------------------------------------------------------------
121 
123 {
124  return DUNEAnaPFParticleUtils::GetAssocProduct<recob::Shower>(pParticle,evt,particleLabel,showerLabel);
125 }
126 
127 //-----------------------------------------------------------------------------------------------------------------------------------------
128 
130 {
131  return DUNEAnaPFParticleUtils::GetAssocProduct<recob::Vertex>(pParticle,evt,particleLabel,particleLabel);
132 }
133 
134 //-----------------------------------------------------------------------------------------------------------------------------------------
135 
137 {
139  std::map<std::string,float> metaMap = pMetadata->GetPropertiesMap();
140 
141  unsigned int sliceIndex;
142  std::map<std::string,float>::iterator mapItr = metaMap.find("SliceIndex");
143 
144  if (mapItr == metaMap.end())
145  {
146  throw cet::exception("DUNEAna") << " DUNEAnaPFParticleUtils::GetSlice --- No associated slice found";
147  }
148  else
149  {
150  sliceIndex = mapItr->second;
151  }
152 
153  return DUNEAnaPFParticleUtils::GetProductVector<recob::Slice>(evt,label).at(sliceIndex);
154 }
155 
156 //-----------------------------------------------------------------------------------------------------------------------------------------
157 
159 {
160  return DUNEAnaPFParticleUtils::GetAssocProduct<larpandoraobj::PFParticleMetadata>(pParticle,evt,label,label);
161 }
162 
163 //-----------------------------------------------------------------------------------------------------------------------------------------
164 
165 bool DUNEAnaPFParticleUtils::IsTrack(const art::Ptr<recob::PFParticle> &pParticle, const art::Event &evt, const std::string &particleLabel, const std::string &trackLabel)
166 {
167  // This function needs to fail if GetTrack would fail
168  const std::vector<art::Ptr<recob::Track>> theseTracks = DUNEAnaPFParticleUtils::GetAssocProductVector<recob::Track>(pParticle,evt,particleLabel,trackLabel);
169 
170  return !theseTracks.empty();
171 }
172 
173 //-----------------------------------------------------------------------------------------------------------------------------------------
174 
175 bool DUNEAnaPFParticleUtils::IsShower(const art::Ptr<recob::PFParticle> &pParticle, const art::Event &evt, const std::string &particleLabel, const std::string &showerLabel)
176 {
177  const std::vector<art::Ptr<recob::Shower>> theseShowers = DUNEAnaPFParticleUtils::GetAssocProductVector<recob::Shower>(pParticle,evt,particleLabel,showerLabel);
178 
179  return !theseShowers.empty();
180 }
181 
182 //-----------------------------------------------------------------------------------------------------------------------------------------
183 
185 {
186  const art::Ptr<larpandoraobj::PFParticleMetadata> pMetadata = DUNEAnaPFParticleUtils::GetMetadata(pParticle,evt,particleLabel);
187 
188  std::map<std::string,float> metaMap = pMetadata->GetPropertiesMap();
189 
190  return metaMap.find("IsClearCosmic") != metaMap.end();
191 }
192 
193 //-----------------------------------------------------------------------------------------------------------------------------------------
194 
196 {
197  const int pdg = pParticle->PdgCode();
198  return ((std::abs(pdg) == 12) || (std::abs(pdg) == 14) || (std::abs(pdg) ==16));
199 }
200 
201 } // namespace dune_ana
202 
203 
intermediate_table::iterator iterator
static std::vector< art::Ptr< anab::T0 > > GetT0(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &label)
Get the T0(s) associated with the particle.
static art::Ptr< recob::Track > GetTrack(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &pParticleLabel, const std::string &trackLabel)
Get the track associated to this particle. Should only be called if IsTrack method succeeds...
static art::Ptr< recob::Slice > GetSlice(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &pParticleLabel)
Get the slice associated to this particle.
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
static bool IsClearCosmic(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &pParticleLabel)
Check if this particle is a clear cosmic ray.
static bool IsShower(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &pParticleLabel, const std::string &showerLabel)
Check if this particle has an associated shower.
int PdgCode() const
Return the type of particle as a PDG ID.
Definition: PFParticle.h:83
static std::vector< art::Ptr< recob::Hit > > GetViewHits(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &label, const unsigned short &view)
Get the hits associated to this particle in a given view.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
static art::Ptr< recob::Shower > GetShower(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &pParticleLabel, const std::string &showerLabel)
Get the shower associated to this particle. Should only be called if IsShower method succeeds...
static std::vector< art::Ptr< recob::PFParticle > > GetChildParticles(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &label)
Get the child particles (one step down in the hierarchy) of this particle.
T abs(T value)
static std::vector< art::Ptr< recob::SpacePoint > > GetSpacePoints(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &label)
Get the spacepoints associated to this particle.
static bool IsNeutrino(const art::Ptr< recob::PFParticle > &pParticle)
Check if this particle is a neutrino.
key_type key() const noexcept
Definition: Ptr.h:216
const PropertiesMap & GetPropertiesMap() const
Utility containing helpful functions for end users to access information about PFParticles.
static art::Ptr< larpandoraobj::PFParticleMetadata > GetMetadata(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &label)
Get the metadata associated to this particle.
Declaration of signal hit object.
static std::vector< art::Ptr< recob::Hit > > GetHits(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &label)
Get the hits associated to this particle.
Provides recob::Track data product.
static art::Ptr< recob::Vertex > GetVertex(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &pParticleLabel)
Get the vertex associated to this particle.
static bool IsTrack(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &pParticleLabel, const std::string &trackLabel)
Check if this particle has an associated track.
static std::vector< art::Ptr< anab::CosmicTag > > GetCosmicTag(const art::Ptr< recob::PFParticle > &pParticle, const art::Event &evt, const std::string &label)
Get the Cosmic Tag(s) associated with the particle.
TCEvent evt
Definition: DataStructs.cxx:7
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)