All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
helper_PandoraPFParticles.cxx
Go to the documentation of this file.
2 
3 namespace single_photon
4 {
6  art::Ptr<recob::PFParticle> input_PFParticle,
7  std::vector< art::Ptr< larpandoraobj::PFParticleMetadata > > input_MetaData,
8  std::vector< art::Ptr<recob::Vertex > > input_Vertex,
9  std::vector< art::Ptr<recob::Cluster> > input_Clusters,
10  std::vector< art::Ptr<recob::Shower > > input_Showers,
11  std::vector< art::Ptr<recob::Track > > input_Tracks,
12  art::FindManyP<recob::Hit> input_Hits
13  )
14  :
15  pPFParticle(input_PFParticle),
16  pMetaData(input_MetaData),
17  pVertex(input_Vertex),
18  pClusters(input_Clusters)
19  {
20  pPFParticleID = pPFParticle->Self();
21  pPdgCode = pPFParticle->PdgCode();
22 
23  //Get recob::Shower/Track
24  const unsigned int nShowers(input_Showers.size());
25  const unsigned int nTracks(input_Tracks.size());
26  if(nShowers+nTracks != 1) mf::LogDebug("SinglePhoton") << " No just one shower/track is associated to PFParticle " << pPFParticleID << "\n";
27 
28  pHasShower = nShowers;
29  pHasTrack = nTracks;
30  if(pHasShower == 1) pShower=input_Showers.front();
31  if(pHasTrack == 1) pTrack=input_Tracks.front();
32 
33 
34  //fill the vertex info.
35  if (!pVertex.empty()){
36  const art::Ptr<recob::Vertex> vertex = * (pVertex.begin());
37  vertex->XYZ(pVertex_pos);
38  }
39 
40  //fill pPFPHits from each clusters;
41  for(size_t index=0; index< pClusters.size(); ++index){
42  auto cluster = pClusters[index];
43  std::vector< art::Ptr<recob::Hit > > temp_hits = input_Hits.at(cluster.key());
44  pPFPHits.insert(pPFPHits.end(), temp_hits.begin(), temp_hits.end());
45  }
46 
47  //get ancestor for a 1st generation PFParticle
48  if(pPFParticle->IsPrimary()){
50  pAncestorID = -1;
51  }
52 
53  //fill in some booleans
54  for(auto &meta: pMetaData){
55  std::map<std::string, float> propertiesmap = meta->GetPropertiesMap();
56  if(propertiesmap.count("NuScore")==1) pNuScore = propertiesmap["NuScore"];
57  if(propertiesmap.count("TrackScore")==1) pTrackScore = propertiesmap["TrackScore"];
58  if(propertiesmap.count("IsNeutrino")==1) pIsNeutrino = true;
59  if(propertiesmap.count("IsClearCosmic")==1) pIsClearCosmic = true;
60  }
61 
62  }
63 
64  //helper functions exclusively for PandoraPFParticles
65  void PPFP_FindAncestor ( std::vector< PandoraPFParticle > & PPFPs){
66 
67  std::map< size_t, art::Ptr<recob::PFParticle>> pfParticleMap;
68  int pfp_size = PPFPs.size();
69  //build ID-PFParticle map;
70  for(int index = 0; index < pfp_size; index++){
71  PandoraPFParticle temp_pfp = PPFPs[index];
72  if (!pfParticleMap.insert(std::map< size_t, art::Ptr<recob::PFParticle>>::value_type((temp_pfp.pPFParticle)->Self(), temp_pfp.pPFParticle)).second){
73  throw cet::exception("SinglePhoton") << " Unable to get PFParticle ID map, the input PFParticle collection has repeat IDs!";
74  }
75  }
76 
77  //trace up parents
78  for(int jndex = 0; jndex < pfp_size; jndex++){
79  art::Ptr< recob::PFParticle > temp_pfp = PPFPs[jndex].pPFParticle;
80 
81  PPFPs[jndex].set_AncestorID(temp_pfp->Self() );
82  PPFPs[jndex].pAncestor = pfParticleMap[temp_pfp->Self()];
83  if(temp_pfp->IsPrimary()) continue;//skip PFP without parent is a parent of itself
84 
85  while(!(PPFPs[jndex].pAncestor)->IsPrimary()){//1+ gen. parent
86 
87  int temp_parent_id = PPFPs[jndex].pAncestor->Parent();
88  PPFPs[jndex].set_AncestorID( temp_parent_id );
89  PPFPs[jndex].pAncestor = pfParticleMap[temp_parent_id];
90  // std::cout<<PPFPs[jndex].pPFParticleID<<" Trace up a generation parent "<<temp_parent_id<<std::endl;
91 
92  }
93  }
94 
95  }
96 
97 
98  //Fill pSlice, pHits, pSliceID
99  void PPFP_FindSliceIDandHits(std::vector< PandoraPFParticle > & PPFPs, art::Ptr< recob::Slice > slice, const std::vector<art::Ptr<recob::PFParticle> > PFP_in_slice, const std::vector<art::Ptr<recob::Hit> > Hit_inslice){
100 
101  int pfp_size = PPFPs.size();
102  for( auto pfp : PFP_in_slice){
103  for(int index = 0; index < pfp_size; index++){
104  if(PPFPs[index].get_SliceID() > -1 ) continue;//slice# is found already
105  if( (PPFPs[index].pPFParticle)->Self() == pfp->Self() ){
106  PPFPs[index].pSlice = slice;
107  PPFPs[index].pSliceHits = Hit_inslice;
108  PPFPs[index].set_SliceID( slice.key() );
109  break;
110  }
111  }
112  }
113  }
114 
115 
116  //refill pNuScore and pIsNuSlice
117  int DefineNuSlice(std::vector< PandoraPFParticle > & PPFPs){
118 
119  int pfp_size = PPFPs.size();
120  double best_nuscore = 0;
121  int best_nuscore_SliceID = 0;
122  std::vector< int > IDs;
123 
124  for(int index = 0; index < pfp_size; index++){
125  PandoraPFParticle* temp_p = &PPFPs[index];
126  if(temp_p->get_IsNeutrino()){
127  int temp_sliceID = temp_p->get_SliceID();
128  //add one if not found;
129  if(!std::count(IDs.begin(), IDs.end(), temp_sliceID) ) IDs.push_back(temp_sliceID);
130  if(best_nuscore < temp_p->get_NuScore() ){
131  best_nuscore = temp_p->get_NuScore();
132 
133  best_nuscore_SliceID = temp_p->get_SliceID();
134 
135  }
136  }
137  }
138 
139  //now markdown all pfparticles in slice
140  //re-set pNuScore and pIsNuSlice
141  for(int index = 0; index < pfp_size; index++){
142  PandoraPFParticle* ppfp = &PPFPs[index];
143  if( std::count(IDs.begin(), IDs.end(), ppfp->get_SliceID()) ) ppfp->set_IsNuSlice(true);
144  }
145 
146  return best_nuscore_SliceID;
147  }
148 
149  //2. Trackers to find the correct PandoraPFParticle
150  PandoraPFParticle* PPFP_GetPPFPFromShower( std::vector< PandoraPFParticle > & PPFPs, art::Ptr<recob::Shower> pShower){
151  int pfp_size = PPFPs.size();
152  for(int index = 0; index < pfp_size; index++){
153  if(PPFPs[index].get_HasShower() != 1 ) continue;
154  // std::cout<<"CHECK Shower start "<<pShower->ShowerStart().X()<<" vs "<<PPFPs[index].pShower->ShowerStart().X()<<std::endl;
155  //CHECK, this works, but there maybe a better way;
156  if((pShower->ShowerStart() == PPFPs[index].pShower->ShowerStart())
157  && (pShower->Direction() == PPFPs[index].pShower->Direction())){
158  return &PPFPs[index];
159  }
160  }
161  std::cout<<"Error, no PFParticle matched to shower, returning the first element"<<std::endl;
162  return &PPFPs[0];
163  }
164 
165 
166  PandoraPFParticle* PPFP_GetPPFPFromTrack( std::vector< PandoraPFParticle > & PPFPs, art::Ptr<recob::Track> pTrack){
167  int pfp_size = PPFPs.size();
168  for(int index = 0; index < pfp_size; index++){
169  if(PPFPs[index].get_HasTrack() != 1 ) continue;
170  if((pTrack->StartDirection() == PPFPs[index].pTrack->StartDirection())
171  && (pTrack->EndDirection() == PPFPs[index].pTrack->EndDirection())){
172  return &PPFPs[index];
173  }
174  }
175  std::cout<<"Error, no PFParticle matched to track, returning the first element"<<std::endl;
176  return &PPFPs[0];
177  }
178 
179 
180  PandoraPFParticle* PPFP_GetPPFPFromPFID( std::vector< PandoraPFParticle > & PPFPs, int id){
181  int pfp_size = PPFPs.size();
182  for(int index = 0; index < pfp_size; index++){
183  if(PPFPs[index].get_PFParticleID() == id ){
184  return &PPFPs[index];
185  }
186  }
187  std::cout<<"Error, no PFParticle matched to track, returning the first element"<<std::endl;
188  return &PPFPs[0];
189  }
190 
191 
192 }
process_name vertex
Definition: cheaterreco.fcl:51
PandoraPFParticle * PPFP_GetPPFPFromPFID(std::vector< PandoraPFParticle > &PPFPs, int id)
std::vector< art::Ptr< recob::Cluster > > pClusters
process_name cluster
Definition: cheaterreco.fcl:51
int DefineNuSlice(std::vector< PandoraPFParticle > &PPFPs)
art::Ptr< recob::PFParticle > pPFParticle
void PPFP_FindAncestor(std::vector< PandoraPFParticle > &PPFPs)
std::vector< art::Ptr< recob::Hit > > pPFPHits
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
art::Ptr< recob::PFParticle > pAncestor
std::vector< art::Ptr< recob::Vertex > > pVertex
std::vector< art::Ptr< larpandoraobj::PFParticleMetadata > > pMetaData
PandoraPFParticle * PPFP_GetPPFPFromTrack(std::vector< PandoraPFParticle > &PPFPs, art::Ptr< recob::Track > pTrack)
void PPFP_FindSliceIDandHits(std::vector< PandoraPFParticle > &PPFPs, art::Ptr< recob::Slice > slice, const std::vector< art::Ptr< recob::PFParticle > > PFP_in_slice, const std::vector< art::Ptr< recob::Hit > > Hit_inslice)
PandoraPFParticle * PPFP_GetPPFPFromShower(std::vector< PandoraPFParticle > &PPFPs, art::Ptr< recob::Shower > pShower)
std::size_t count(Cont const &cont)
PandoraPFParticle(art::Ptr< recob::PFParticle > input_PFParticle, std::vector< art::Ptr< larpandoraobj::PFParticleMetadata > > input_MetaData, std::vector< art::Ptr< recob::Vertex > > input_Vertex, std::vector< art::Ptr< recob::Cluster > > input_Clusters, std::vector< art::Ptr< recob::Shower > > input_Showers, std::vector< art::Ptr< recob::Track > > input_Tracks, art::FindManyP< recob::Hit > input_Hits)
void set_IsNuSlice(const bool input_bool)
BEGIN_PROLOG could also be cout