All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
vertex::VertexCheater Class Reference
Inheritance diagram for vertex::VertexCheater:

Public Member Functions

 VertexCheater (fhicl::ParameterSet const &pset)
 
void produce (art::Event &evt)
 

Private Attributes

std::string fCheatedTrackLabel
 label for module creating recob::Track objects More...
 
std::string fCheatedShowerLabel
 label for module creating recob::Shower objects More...
 
std::string fG4ModuleLabel
 label for module running G4 and making particles, etc More...
 

Detailed Description

Definition at line 32 of file VertexCheater_module.cc.

Constructor & Destructor Documentation

vertex::VertexCheater::VertexCheater ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 50 of file VertexCheater_module.cc.

51  : EDProducer{pset}
52  {
53  fCheatedTrackLabel = pset.get< std::string >("CheatedTrackLabel", "track" );
54  fCheatedShowerLabel = pset.get< std::string >("CheatedShowerLabel", "shower" );
55  fG4ModuleLabel = pset.get< std::string >("G4ModuleLabel", "largeant");
56 
57  produces< std::vector<recob::Vertex> >();
58  produces< art::Assns<recob::Vertex, recob::Shower> >();
59  produces< art::Assns<recob::Vertex, recob::Track> >();
60  produces< art::Assns<recob::Vertex, recob::Hit> >();
61 
62  }
std::string fCheatedTrackLabel
label for module creating recob::Track objects
std::string fG4ModuleLabel
label for module running G4 and making particles, etc
std::string fCheatedShowerLabel
label for module creating recob::Shower objects

Member Function Documentation

void vertex::VertexCheater::produce ( art::Event &  evt)

Definition at line 65 of file VertexCheater_module.cc.

66  {
67  art::ServiceHandle<cheat::ParticleInventoryService const> pi_serv;
68 
69  // grab the sim::ParticleList
70  const sim::ParticleList& plist = pi_serv->ParticleList();
71 
72  // grab the showers that have been reconstructed
73  art::Handle< std::vector<recob::Shower> > showercol;
74  evt.getByLabel(fCheatedShowerLabel, showercol);
75 
76  // make a vector of them - we aren't writing anything out to a file
77  // so no need for a art::PtrVector here
78  std::vector< art::Ptr<recob::Shower> > showers;
79  try{
80  art::fill_ptr_vector(showers, showercol);
81  }
82  catch(cet::exception &e){
83  mf::LogWarning("VertexCheater") << "showers: " << e;
84  }
85 
86  // grab the tracks that have been reconstructed
87  art::Handle< std::vector<recob::Track> > trackcol;
88  evt.getByLabel(fCheatedTrackLabel, trackcol);
89 
90  // make a vector of them - we aren't writing anything out to a file
91  // so no need for a art::PtrVector here
92  std::vector< art::Ptr<recob::Track> > tracks;
93  try{
94  art::fill_ptr_vector(tracks, trackcol);
95  }
96  catch(cet::exception &e){
97  mf::LogWarning("VertexCheater") << "tracks: " << e;
98  }
99 
100  art::FindManyP<recob::Hit> fmhs(showers, evt, fCheatedShowerLabel);
101  art::FindManyP<recob::Hit> fmht(tracks, evt, fCheatedTrackLabel);
102 
103  // loop over the prongs and figure out which primaries they are associated with
104  std::vector< art::Ptr<recob::Shower> >::iterator shwitr = showers.begin();
105  std::vector< art::Ptr<recob::Track> >::iterator trkitr = tracks.begin();
106 
107  // protect against events where there are either no tracks or no showers
108  if(tracks.size() < 1) trkitr = tracks.end();
109  if(showers.size() < 1) shwitr = showers.end();
110 
111  // make a map of eve id's to collections of prongs
112  std::map<int, std::vector< std::pair<size_t, art::Ptr<recob::Shower> > > > eveShowerMap;
113  std::map<int, std::vector< std::pair<size_t, art::Ptr<recob::Track> > > > eveTrackMap;
114 
115  // make a map of eve id's to the number of prongs corresponding to that id
116  std::vector<int> eveIDs;
117 
118  // loop over all showers
119  for(size_t s = 0; s < showers.size(); ++s){
120 
121  std::pair<size_t, art::Ptr<recob::Shower> > idxShw(s, showers[s]);
122 
123  // in the ProngCheater module we set the prong ID to be
124  // the particle track ID creating the energy depositions
125  // of the prong
126  int prongID = showers[s]->ID();
127 
128  // now get the mother particle of this prong if it exists
129  // set the eveID to the mother particle track ID, or to the
130  // ID of this prong if it is primary and mother ID = 0
131  int eveID = plist[prongID]->Mother();
132  if( eveID < 1 ) eveID = prongID;
133 
134  if(std::find(eveIDs.begin(), eveIDs.end(), eveID) == eveIDs.end())
135  eveIDs.push_back(eveID);
136 
137  // now we want to associate all prongs having the same
138  // eve ID, so look to see if there are other prongs with that
139  // ID
140  eveShowerMap[eveID].push_back(idxShw);
141 
142  mf::LogInfo("VertexCheater") << "shower: " << prongID << " has mother " << eveID;
143 
144  }// end loop over showers
145 
146  // loop over all tracks
147  for(size_t t = 0; t < tracks.size(); ++t){
148 
149  std::pair<size_t, art::Ptr<recob::Track> > idxTrk(t, tracks[t]);
150 
151  // in the ProngCheater module we set the prong ID to be
152  // the particle track ID creating the energy depositions
153  // of the prong
154  int prongID = tracks[t]->ID();
155 
156  // now get the mother particle of this prong if it exists
157  // set the eveID to the mother particle track ID, or to the
158  // ID of this prong if it is primary and mother ID = 0
159  int eveID = plist[prongID]->Mother();
160  if( eveID < 1 ) eveID = prongID;
161 
162  if(std::find(eveIDs.begin(), eveIDs.end(), eveID) == eveIDs.end())
163  eveIDs.push_back(eveID);
164 
165  // now we want to associate all prongs having the same
166  // eve ID, so look to see if there are other prongs with that
167  // ID
168  eveTrackMap[eveID].push_back(idxTrk);
169 
170  mf::LogInfo("VertexCheater") << "track: " << prongID << " has mother " << eveID;
171 
172  }// end loop over tracks
173 
174  std::unique_ptr< std::vector<recob::Vertex> > vertexcol(new std::vector<recob::Vertex>);
175  std::unique_ptr< art::Assns<recob::Vertex, recob::Shower> > vsassn(new art::Assns<recob::Vertex, recob::Shower>);
176  std::unique_ptr< art::Assns<recob::Vertex, recob::Track> > vtassn(new art::Assns<recob::Vertex, recob::Track>);
177  std::unique_ptr< art::Assns<recob::Vertex, recob::Hit> > vhassn(new art::Assns<recob::Vertex, recob::Hit>);
178 
179  // loop over the eve ID values and make Vertexs
180  for(auto const& eveID : eveIDs){
181 
182  // Vertex objects require PtrVectors of showers and tracks as well
183  // as a vertex position for their constructor
184  art::PtrVector<recob::Shower> ptrvshw;
185  art::PtrVector<recob::Track> ptrvtrk;
186  std::vector<size_t> idxShw;
187  std::vector<size_t> idxTrk;
188 
189  // first get the showers
190  if(eveShowerMap.find(eveID) != eveShowerMap.end()){
191  auto const& eveShowers = eveShowerMap[eveID];
192  for(auto const& is : eveShowers){
193  ptrvshw.push_back(is.second);
194  idxShw.push_back(is.first);
195  } // end loop over showers for this particle
196  } // end find showers for this particle
197 
198  // now the tracks
199  if(eveTrackMap.find(eveID) != eveTrackMap.end()){
200  auto const& eveTracks = eveTrackMap[eveID];
201  for(auto const& it : eveTracks){
202  ptrvtrk.push_back(it.second);
203  idxTrk.push_back(it.first);
204  } // end loop over tracks for this particle
205  } // end find tracks for this particle
206 
207  double xyz[3] = { plist[eveID]->Vx(),
208  plist[eveID]->Vy(),
209  plist[eveID]->Vz() };
210 
211  // add a vector to the collection.
212  vertexcol->push_back(recob::Vertex(xyz, eveID));
213 
214  // associate the vertex with its showers and tracks
215 
216  if( ptrvtrk.size() > 0 ){
217  util::CreateAssn(*this, evt, *vertexcol, ptrvtrk, *vtassn);
218 
219  // get the hits associated with each track and associate those with the vertex
220  for(auto const& i : idxTrk){
221  std::vector< art::Ptr<recob::Hit> > hits = fmht.at(i);
222  util::CreateAssn(*this, evt, *vertexcol, hits, *vhassn);
223  }
224  }
225 
226  if( ptrvshw.size() > 0 ){
227  util::CreateAssn(*this, evt, *vertexcol, ptrvshw, *vsassn);
228  // get the hits associated with each shower and associate those with the vertex
229  for(auto const& i : idxShw){
230  std::vector< art::Ptr<recob::Hit> > hits = fmhs.at(i);
231  util::CreateAssn(*this, evt, *vertexcol, hits, *vhassn);
232  }
233  }
234 
235  mf::LogInfo("VertexCheater") << "adding vertex: \n"
236  << vertexcol->back()
237  << "\nto collection.";
238 
239  } // end loop over the eve ID values
240 
241  evt.put(std::move(vertexcol));
242  evt.put(std::move(vsassn));
243  evt.put(std::move(vtassn));
244  evt.put(std::move(vhassn));
245 
246  return;
247 
248  } // end produce
ClusterModuleLabel join with tracks
std::string fCheatedTrackLabel
label for module creating recob::Track objects
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
std::string fCheatedShowerLabel
label for module creating recob::Shower objects
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
do i e
TCEvent evt
Definition: DataStructs.cxx:8

Member Data Documentation

std::string vertex::VertexCheater::fCheatedShowerLabel
private

label for module creating recob::Shower objects

Definition at line 41 of file VertexCheater_module.cc.

std::string vertex::VertexCheater::fCheatedTrackLabel
private

label for module creating recob::Track objects

Definition at line 40 of file VertexCheater_module.cc.

std::string vertex::VertexCheater::fG4ModuleLabel
private

label for module running G4 and making particles, etc

Definition at line 42 of file VertexCheater_module.cc.


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