12 #include <HepMC/GenEvent.h>
13 #include <HepMC/GenParticle.h>
14 #include <HepMC/GenVertex.h>
15 #include <HepMC/IteratorRange.h>
16 #include <HepMC/SimpleVector.h>
40 HepMC::GenParticle*
parent =
nullptr;
41 if (!p->production_vertex())
return parent;
43 for (HepMC::GenVertex::particle_iterator mother = p->production_vertex()->particles_begin(HepMC::ancestors);
44 mother != p->production_vertex()->particles_end(HepMC::ancestors);
55 if (parent !=
nullptr)
break;
65 cout <<
PHWHERE <<
"Doing nothing." << endl;
69 PHHepMCGenEventMap* geneventmap = findNode::getClass<PHHepMCGenEventMap>(topNode,
"PHHepMCGenEventMap");
72 cerr <<
"ERROR: PHHepMCGenEventMap node not found!" << endl;
78 cerr <<
"PHHepMCParticleSelectorDecayProductChain::process_event - WARNING: PHHepMCGenEvent with embedding ID " <<
_embedding_id <<
" is not found! Move on." << endl;
82 HepMC::GenEvent*
event = inEvent->
getEvent();
83 int npart =
event->particles_size();
84 int nvert =
event->vertices_size();
85 if (
Verbosity() > 0) cout <<
"=========== Event " <<
event->event_number() <<
" contains " << npart <<
" particles and " << nvert <<
" vertices." << endl;
88 vector<HepMC::GenVertex> vkeep;
92 for (HepMC::GenEvent::particle_const_iterator
p = event->particles_begin();
p !=
event->particles_end(); ++
p)
103 vkeep.push_back(*(*p)->production_vertex());
108 vkeep.push_back(*(*p)->production_vertex());
114 if ((*p)->end_vertex())
116 for (HepMC::GenVertex::particle_iterator des = (*p)->end_vertex()->particles_begin(HepMC::descendants);
117 des != (*p)->end_vertex()->particles_end(HepMC::descendants);
124 vkeep.push_back(*(*p)->end_vertex());
137 for (HepMC::GenEvent::particle_const_iterator
p = event->particles_begin();
p !=
event->particles_end(); ++
p)
143 vkeep.push_back(*(*p)->production_vertex());
150 for (HepMC::GenEvent::vertex_const_iterator
v = event->vertices_begin();
v !=
event->vertices_end(); ++
v)
152 bool goodvertex =
false;
153 for (
unsigned int i = 0; i < vkeep.size(); i++)
155 HepMC::GenVertex
tmp1 = (*(*v));
156 HepMC::GenVertex
tmp2 = vkeep[i];
164 bool tmp =
event->remove_vertex((*
v));
167 cout <<
PHWHERE <<
" Erasing empty vertex." << endl;
173 for (HepMC::GenEvent::vertex_const_iterator
v = event->vertices_begin();
v !=
event->vertices_end(); ++
v)
175 std::vector<HepMC::GenParticle*> removep;
177 for (HepMC::GenVertex::particle_iterator itpart = (*v)->particles_begin(HepMC::children);
178 itpart != (*v)->particles_end(HepMC::children);
181 bool keepparticle =
false;
188 if (
abs((*itpart)->pdg_id()) ==
_theDaughters[j] && (*itpart)->status() == 1)
195 removep.push_back((*itpart));
199 for (HepMC::GenVertex::particle_iterator itpart = (*v)->particles_begin(HepMC::parents);
200 itpart != (*v)->particles_end(HepMC::parents);
203 bool keepparticle =
false;
210 if (
abs((*itpart)->pdg_id()) ==
_theDaughters[j] && (*itpart)->status() == 1)
217 removep.push_back((*itpart));
221 for (
unsigned int k = 0;
k < removep.size();
k++)
223 HepMC::GenParticle*
tmp = (*v)->remove_particle(removep[
k]);
224 if (tmp->end_vertex())
226 delete tmp->end_vertex();
234 cout <<
"FINAL Event " <<
event->event_number() <<
" contains " <<
event->particles_size() <<
" particles and " <<
event->vertices_size() <<
" vertices." << endl;
235 cout <<
"FINAL LIST OF PARTICLES:" << endl;
237 for (HepMC::GenEvent::particle_const_iterator
p = event->particles_begin();
p !=
event->particles_end(); ++
p)
239 int pid = (*p)->pdg_id();
240 int status = (*p)->status();
241 double pz = ((*p)->momentum()).pz();
242 double pt = ((*p)->momentum()).
perp();
243 double eta = ((*p)->momentum()).
eta();
244 double mass = ((*p)->momentum()).
m();
247 cout << pid <<
" " << mass <<
" " << status <<
" " << pt <<
" " << pz <<
" " << eta <<
" " << (*p)->production_vertex() <<
" " << (*p)->end_vertex() << endl;
257 cout <<
"EVENT ABORTED: No particles to write out." << endl;