All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PandoraNuScoreCosmicIdAlg.cc
Go to the documentation of this file.
2 
3 namespace sbnd{
4 
6 
7  this->reconfigure(config);
8 
9  }
10 
11 
13 
14  }
15 
16 
18 
19  }
20 
21 
23 
24  fPandoraLabel = config.PandoraLabel();
26  fNuScoreCut = config.NuScoreCut();
27 
28  return;
29  }
30 
31  // Finds any t0s associated with track by pandora, tags if outside beam
33 
34  // Get the pfps and associations
35  art::Handle< std::vector<recob::PFParticle> > pfParticleHandle;
36  event.getByLabel(fPandoraLabel, pfParticleHandle);
37  art::FindManyP<recob::Track> pfPartToTrackAssoc(pfParticleHandle, event, fTpcTrackModuleLabel);
38  art::FindManyP<larpandoraobj::PFParticleMetadata> PFPMetaDataAssoc(pfParticleHandle, event, fPandoraLabel);
39 
40  // Loop over all the pfps
41  for(auto const pfp : (*pfParticleHandle)){
42  // Get the associated track if there is one
43  const std::vector< art::Ptr<recob::Track> > associatedTracks(pfPartToTrackAssoc.at(pfp.Self()));
44  if(associatedTracks.size() != 1) continue;
45  recob::Track trk = *associatedTracks.front();
46  if(trk.ID() != track.ID()) continue;
47 
48  recob::PFParticle PFPNeutrino = GetPFPNeutrino(pfp, (*pfParticleHandle));
49 
50  float pfpNuScore = GetPandoraNuScore(PFPNeutrino, PFPMetaDataAssoc);
51  if (pfpNuScore < fNuScoreCut){
52  return true;
53  } else {
54  return false;
55  }
56  }
57  return false;
58 
59  }
60 
61  // Finds any t0s associated with pfparticle by pandora, tags if outside beam
63  std::map< size_t, art::Ptr<recob::PFParticle> > pfParticleMap, const art::Event& event){
64 
65  // Get pfp associations to t0s
66  art::Handle< std::vector<recob::PFParticle> > pfParticleHandle;
67  event.getByLabel(fPandoraLabel, pfParticleHandle);
68 
69  art::FindManyP<larpandoraobj::PFParticleMetadata> PFPMetaDataAssoc(pfParticleHandle, event, fPandoraLabel);
70 
71  recob::PFParticle PFPNeutrino = GetPFPNeutrino(pfparticle, pfParticleMap);
72 
73  float pfpNuScore = GetPandoraNuScore(PFPNeutrino, PFPMetaDataAssoc);
74 
75  if (pfpNuScore < fNuScoreCut){
76  return true;
77  }
78  return false;
79  }
80 
81 
82  recob::PFParticle PandoraNuScoreCosmicIdAlg::GetPFPNeutrino(recob::PFParticle pfparticle, std::map< size_t, art::Ptr<recob::PFParticle> >& pfParticleMap){
83 
84  if ((pfparticle.PdgCode()==12) ||(pfparticle.PdgCode()==14)){
85  return pfparticle;
86  } else {
87  art::Ptr<recob::PFParticle> parentPFP= pfParticleMap.at(pfparticle.Parent());
88  return GetPFPNeutrino(*parentPFP, pfParticleMap);
89  }
90  }
91 
93  const std::vector<recob::PFParticle>& pfpVec){
94 
95  if ((pfparticle.PdgCode()==12) ||(pfparticle.PdgCode()==14)){
96  return pfparticle;
97  } else {
98  size_t parentID = pfparticle.Parent();
99  auto parentPFPIter = std::find_if(pfpVec.begin(), pfpVec.end(),
100  [&](const auto& pfp){return pfp.Self()==parentID;});
101 
102  if (parentPFPIter==pfpVec.end()){
103  return pfparticle;
104  } else {
105  return GetPFPNeutrino(*parentPFPIter, pfpVec);
106  }
107  }
108  }
109 
111  art::FindManyP<larpandoraobj::PFParticleMetadata> PFPMetaDataAssoc){
112 
113  const std::vector<art::Ptr<larpandoraobj::PFParticleMetadata> > pfpMetaVec =
114  PFPMetaDataAssoc.at(pfparticle.Self());
115 
116  if (pfpMetaVec.size() !=1){
117  std::cout<<"Cannot get PFPMetadata"<<std::endl;
118  return 99999;
119  }
120 
121  art::Ptr<larpandoraobj::PFParticleMetadata> pfpMeta = pfpMetaVec.front();
122 
123  larpandoraobj::PFParticleMetadata::PropertiesMap propertiesMap = pfpMeta->GetPropertiesMap();
124  auto propertiesMapIter = propertiesMap.find("NuScore");
125  if (propertiesMapIter == propertiesMap.end()){
126  std::cout<<"Cannot get PFP Nu Score in Metadata"<<std::endl;
127  std::cout<<"PFP pdg: "<<pfparticle.PdgCode()<<std::endl;
128  return 99999;
129  }
130 
131  return propertiesMapIter->second;
132  }
133 
134 }
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:92
void reconfigure(const Config &config)
int PdgCode() const
Return the type of particle as a PDG ID.
Definition: PFParticle.h:83
std::map< std::string, float > PropertiesMap
process_name use argoneut_mc_hitfinder track
recob::PFParticle GetPFPNeutrino(recob::PFParticle pfparticle, std::map< size_t, art::Ptr< recob::PFParticle > > &pfParticleMap)
float GetPandoraNuScore(recob::PFParticle pfparticle, art::FindManyP< larpandoraobj::PFParticleMetadata > PFPMetaDataAssoc)
size_t Parent() const
Definition: PFParticle.h:96
Hierarchical representation of particle flow.
Definition: PFParticle.h:44
bool PandoraNuScoreCosmicId(recob::Track track, const art::Event &event)
stream1 can override from command line with o or output services user sbnd
fhicl::Atom< art::InputTag > TpcTrackModuleLabel
PandoraNuScoreCosmicIdAlg(const Config &config)
BEGIN_PROLOG could also be cout
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a &quot;fitted&quot; track: