31 HepMC::GenParticle* parent =
NULL;
32 if(!p->production_vertex())
return parent;
34 for ( HepMC::GenVertex::particle_iterator mother = p->production_vertex()-> particles_begin(HepMC::ancestors);
35 mother != p->production_vertex()-> particles_end(HepMC::ancestors);
46 if(parent !=
NULL)
break;
57 cout <<
PHWHERE <<
"Doing nothing." << endl;
61 PHHepMCGenEventMap * geneventmap = findNode::getClass<PHHepMCGenEventMap>(topNode,
"PHHepMCGenEventMap");
64 cerr <<
"ERROR: PHHepMCGenEventMap node not found!" << endl;
70 cerr <<
"PHHepMCParticleSelectorDecayProductChain::process_event - WARNING: PHHepMCGenEvent with embedding ID "<<
_embedding_id <<
" is not found! Move on." << endl;
74 HepMC::GenEvent*
event = inEvent->
getEvent();
75 int npart =
event->particles_size();
76 int nvert =
event->vertices_size();
77 if(
verbosity > 0) cout <<
"=========== Event " <<
event->event_number() <<
" contains " << npart <<
" particles and " << nvert <<
" vertices." << endl;
80 vector<HepMC::GenVertex> vkeep;
84 for ( HepMC::GenEvent::particle_const_iterator p = event->particles_begin(); p !=
event->particles_end(); ++p )
94 HepMC::GenParticle* parent =
GetParent(*p, event);
97 vkeep.push_back(*(*p)->production_vertex());
102 vkeep.push_back(*(*p)->production_vertex());
108 if ( (*p)->end_vertex() )
110 for ( HepMC::GenVertex::particle_iterator des = (*p)->end_vertex()-> particles_begin(HepMC::descendants);
111 des != (*p)->end_vertex()-> particles_end(HepMC::descendants);
118 vkeep.push_back(*(*p)->end_vertex());
131 for ( HepMC::GenEvent::particle_const_iterator p = event->particles_begin(); p !=
event->particles_end(); ++p )
137 vkeep.push_back(*(*p)->production_vertex());
144 for ( HepMC::GenEvent::vertex_const_iterator v = event->vertices_begin(); v !=
event->vertices_end(); ++v )
146 bool goodvertex =
false;
147 for(
unsigned int i = 0; i < vkeep.size(); i++)
149 HepMC::GenVertex tmp1 = (*(*v));
150 HepMC::GenVertex tmp2 = vkeep[i];
158 bool tmp =
event->remove_vertex((*v));
161 cout <<
PHWHERE <<
" Erasing empty vertex." << endl;
168 for ( HepMC::GenEvent::vertex_const_iterator v = event->vertices_begin(); v !=
event->vertices_end(); ++v )
171 std::vector<HepMC::GenParticle*> removep;
173 for ( HepMC::GenVertex::particle_iterator itpart = (*v)->particles_begin(HepMC::children);
174 itpart != (*v)->particles_end(HepMC::children);
177 bool keepparticle =
false;
184 if(abs((*itpart)->pdg_id()) ==
_theDaughters[j] && (*itpart)->status() == 1)
191 removep.push_back((*itpart));
195 for ( HepMC::GenVertex::particle_iterator itpart = (*v)->particles_begin(HepMC::parents);
196 itpart != (*v)->particles_end(HepMC::parents);
199 bool keepparticle =
false;
206 if(abs((*itpart)->pdg_id()) ==
_theDaughters[j] && (*itpart)->status() == 1)
213 removep.push_back((*itpart));
217 for(
unsigned int k = 0; k < removep.size(); k++)
219 HepMC::GenParticle *tmp = (*v)->remove_particle(removep[k]);
220 if(tmp->end_vertex())
222 delete tmp->end_vertex();
232 cout <<
"FINAL Event " <<
event->event_number() <<
" contains " <<
event->particles_size() <<
" particles and " <<
event->vertices_size() <<
" vertices." << endl;
233 cout <<
"FINAL LIST OF PARTICLES:" << endl;
235 for ( HepMC::GenEvent::particle_const_iterator p = event->particles_begin(); p !=
event->particles_end(); ++p )
237 int pid = (*p)->pdg_id();
238 int status = (*p)->status();
239 double pz = ((*p)->momentum()).pz();
240 double pt = ((*p)->momentum()).perp();
241 double eta = ((*p)->momentum()).eta();
242 double mass = ((*p)->momentum()).m();
245 cout << pid <<
" " << mass <<
" " << status <<
" " << pt <<
" " << pz <<
" " << eta <<
" " << (*p)->production_vertex() <<
" " << (*p)->end_vertex() << endl;
255 cout <<
"EVENT ABORTED: No particles to write out." << endl;
int InitRun(PHCompositeNode *topNode)
PHHepMCGenEventMap is collection of HEPMC events input into this simulation map of embedding ID -> PH...
int verbosity
The verbosity level. 0 means not verbose at all.
int _theParticle
The particle you want to have in your output.
std::vector< int > _theDaughters
virtual HepMC::GenEvent * getEvent()
const PHHepMCGenEvent * get(int idkey) const
fetch event
virtual void AddDaughter(const int pid)
Add decay products of the particle you want in your output.
HepMC::GenParticle * GetParent(HepMC::GenParticle *p, HepMC::GenEvent *event)
find out if a particle comes from one of _theAncestors
PHHepMCParticleSelectorDecayProductChain(const std::string &name="PARTICLESELECTOR")
virtual void AddAncestor(const int pid)
Add an ancestor of the particle you want in your output.
virtual void SetParticle(const int pid)
Set the ID of the particle you want in your output.
std::vector< int > _theAncestors
int process_event(PHCompositeNode *topNode)