116 const bool doDebug =
false;
117 const bool doExtra =
false;
125 return StatusCode::FAILURE;
128 if (mcEvts->
empty()) {
130 return StatusCode::SUCCESS;
137 delete thinnedMcEvts;
138 thinnedMcEvts =
nullptr;
139 return StatusCode::FAILURE;
144 const HepMC::GenEvent* mcEvt = mcEvts->
front();
145 auto wtCont = mcEvt->weights();
146 if (!wtCont.empty()) {
150 int inEvent = mcEvt->event_number();
157 HepMC::GenEvent* thinEvt =
new HepMC::GenEvent(*mcEvt);
158 int nEvent = thinEvt->event_number();
162 std::cout <<
"========== BEGIN EVENT BEFORE THINNING ==========" << std::endl;
164 std::cout <<
"========== END EVENT BEFORE THINNING ==========" << std::endl;
184 typedef std::pair<HepMC::GenVertexPtr, HepMC::GenParticlePtr> vpPair;
185 std::vector<vpPair> removePV;
186 std::vector<vpPair> addinPV;
187 std::vector<vpPair> addoutPV;
188 std::vector<HepMC::GenVertexPtr> removeV;
191 std::list<HepMC::GenParticlePtr> deleteP;
192 std::list<HepMC::GenVertexPtr> deleteV;
204 std::vector<HepMC::GenVertexPtr> hadVertices;
207 for (
auto& hadv: thinEvt->vertices()) {
209 if (hadv->particles_in().size() < 2)
continue;
210 if (hadv->particles_out().size() < 1)
continue;
214 bool isHadVtx =
true;
215 bool isHadOut =
false;
216 for (
const auto& inp: hadv->particles_in() ) {
219 for (
const auto& vp: hadv->particles_out()) {
223 isHadVtx = isHadVtx && isHadOut;
224 if (isHadVtx) hadVertices.push_back(hadv);
225 if (doDebug && isHadVtx)
ATH_MSG_VERBOSE(
"Hadronization vertex " << hadv);
228 HepMC::GenEvent::vertex_iterator hadv = thinEvt->vertices_begin();
229 HepMC::GenEvent::vertex_iterator hadvB = thinEvt->vertices_begin();
230 HepMC::GenEvent::vertex_iterator hadvE = thinEvt->vertices_end();
232 for (; hadv != hadvE; ++hadv) {
233 if (!(*hadv))
continue;
234 if ((*hadv)->particles_in_size() < 2)
continue;
235 if ((*hadv)->particles_out_size() < 1)
continue;
240 bool isHadVtx =
true;
241 bool isHadOut =
false;
242 HepMC::GenVertex::particles_in_const_iterator inp = (*hadv)->particles_in_const_begin();
243 HepMC::GenVertex::particles_in_const_iterator inpE = (*hadv)->particles_in_const_end();
244 for (; inp != inpE; ++inp) {
247 HepMC::GenVertex::particles_out_const_iterator vp = (*hadv)->particles_out_const_begin();
248 HepMC::GenVertex::particles_out_const_iterator vpE = (*hadv)->particles_out_const_end();
249 for (; vp != vpE; ++vp) {
253 isHadVtx = isHadVtx && isHadOut;
254 if (isHadVtx) hadVertices.push_back(*hadv);
255 if (doDebug && isHadVtx)
ATH_MSG_VERBOSE(
"Hadronization vertex " << *hadv);
259 if (hadVertices.empty()) {
263 return StatusCode::SUCCESS;
272 for (
unsigned int iv = 0; iv < hadVertices.size(); ++iv) {
274 if (doDebug)
ATH_MSG_DEBUG(
"Removing partons from hadVertex " << ivtx);
275 for (
auto pin: ivtx->particles_in()) {
276 removePV.push_back(vpPair(ivtx, pin));
281 for (
unsigned int iv = 0; iv < hadVertices.size(); ++iv) {
283 auto descendants = HepMC::descendant_particles(ivtx);
284 for (
auto pout: descendants) {
286 if (vpar) removePV.push_back(vpPair(vpar,
pout));
288 if (vend) removePV.push_back(vpPair(vend,
pout));
289 deleteP.push_back(
pout);
293 for (
unsigned int iv = 0; iv < hadVertices.size(); ++iv) {
294 HepMC::GenVertex* ivtx = hadVertices[iv];
295 if (doDebug)
ATH_MSG_DEBUG(
"Removing partons from hadVertex " << ivtx);
296 HepMC::GenVertex::particles_in_const_iterator pin = ivtx->particles_in_const_begin();
297 HepMC::GenVertex::particles_in_const_iterator pinE = ivtx->particles_in_const_end();
298 for (; pin != pinE; ++pin) {
299 removePV.emplace_back(ivtx, *pin);
305 for (
unsigned int iv = 0; iv < hadVertices.size(); ++iv) {
306 HepMC::GenVertex* ivtx = hadVertices[iv];
307 HepMC::GenVertex::particle_iterator
pout = ivtx->particles_begin(HepMC::descendants);
308 HepMC::GenVertex::particle_iterator poutE = ivtx->particles_end(HepMC::descendants);
310 HepMC::GenVertex* vpar = (*pout)->production_vertex();
311 if (vpar) removePV.emplace_back(vpar, *
pout);
312 HepMC::GenVertex* vend = (*pout)->end_vertex();
313 if (vend) removePV.emplace_back(vend, *
pout);
314 deleteP.push_back(*
pout);
325 for (
auto hadv:thinEvt->vertices()) {
327 if (hadv->particles_in().size() == 0 && hadv->particles_out().size() == 0) {
328 removeV.push_back(hadv);
329 deleteV.push_back(hadv);
333 for (
auto pin: hadv->particles_in()) {
334 removePV.push_back(vpPair(hadv, pin));
337 for (
auto pout: hadv->particles_out()) {
338 removePV.push_back(vpPair(hadv,
pout));
341 removeV.push_back(hadv);
342 deleteV.push_back(std::move(hadv));
345 for (hadv = hadvB; hadv != hadvE; ++hadv) {
348 if ((*hadv)->particles_in_size() == 0 && (*hadv)->particles_out_size() == 0) {
349 removeV.push_back(*hadv);
350 deleteV.push_back(*hadv);
355 HepMC::GenVertex::particles_in_const_iterator pin = (*hadv)->particles_in_const_begin();
356 HepMC::GenVertex::particles_in_const_iterator pinE = (*hadv)->particles_in_const_end();
357 for (; pin != pinE; ++pin) {
358 removePV.emplace_back(*hadv, *pin);
361 HepMC::GenVertex::particles_out_const_iterator
pout = (*hadv)->particles_out_const_begin();
362 HepMC::GenVertex::particles_out_const_iterator poutE = (*hadv)->particles_out_const_end();
364 removePV.emplace_back(*hadv, *
pout);
367 removeV.push_back(*hadv);
368 deleteV.push_back(*hadv);
374 for (
unsigned int i = 0;
i < removePV.size(); ++
i) {
378 v->remove_particle_in(
p);
379 v->remove_particle_out(std::move(
p));
381 v->remove_particle(
p);
385 for (
unsigned int i = 0;
i < addoutPV.size(); ++
i) {
388 v->add_particle_out(std::move(
p));
391 for (
unsigned int iv = 1; iv < hadVertices.size(); ++iv) {
393 if (
v->particles_in().size() != 0 ||
v->particles_out().size() != 0) {
395 <<
" with in/out particles " <<
v->particles_in().size() <<
" " <<
v->particles_out().size());
397 thinEvt->remove_vertex(hadVertices[iv]);
402 for (
unsigned int iv = 1; iv < hadVertices.size(); ++iv) {
403 HepMC::GenVertex*
v = hadVertices[iv];
404 if (
v->particles_in_size() != 0 ||
v->particles_out_size() != 0) {
405 ATH_MSG_WARNING(
"Removing vertex " <<
HepMC::uniqueID(
v) <<
" for event " << nEvent <<
" with in/out particles " <<
v->particles_in_size() <<
" " <<
v->particles_out_size());
412 if (doDebug)
ATH_MSG_DEBUG(
"Deleting hadronization vertices " << deleteV.size());
415 for (dvItr = deleteV.begin(); dvItr != deleteV.end(); ++dvItr) {
417 if (*dvItr)
delete (*dvItr);
422 for (dpItr = deleteP.begin(); dpItr != deleteP.end(); ++dpItr) {
424 if (*dpItr)
delete (*dpItr);
432 if (doDebug && doExtra) {
433 std::cout <<
"========== BEGIN EVENT BEFORE CLUSTER ==========" << std::endl;
435 std::cout <<
"========== END EVENT BEFORE CLUSTER ==========" << std::endl;
450 using vpPair = std::pair<HepMC::GenVertexPtr, HepMC::GenParticlePtr>;
458 using pkPair = std::pair<HepMC::GenParticlePtr, HepMC::FourVector>;
459 std::vector<pkPair> changePK;
463 if (doDebug)
ATH_MSG_DEBUG(
"New parton pass " << inEvent <<
" " << thinEvt->particles_size() <<
" " << thinEvt->vertices_size());
473 for (
auto fp: thinEvt->particles() ) {
489 if (pvtx->particles_in().size() == 1 && pvtx->particles_out().size() == 1) {
492 if (!pp || pp->parent_event() ==
nullptr) {
499 if (!ppvtx || ppvtx->parent_event() ==
nullptr) {
506 removePV.push_back(vpPair(ppvtx, pp));
507 removePV.push_back(vpPair(pvtx, pp));
508 deleteP.push_back(pp);
509 removeV.push_back(pvtx);
510 deleteV.push_back(pvtx);
511 addoutPV.push_back(vpPair(ppvtx,
fp));
512 if (doDebug) {
ATH_MSG_DEBUG(
"1->1: ppvtx,pp,pvtx,fp,evtx " << ppvtx <<
" " << pp <<
" " << pvtx <<
" " <<
fp); }
521 if (pvtx->particles_in().size() == 2 && pvtx->particles_out().size() == 1) {
527 if (std::abs(pp1->momentum().perp()) < 1.e-3)
continue;
528 if (std::abs(pp2->momentum().perp()) < 1.e-3)
continue;
532 if (!ppvtx1 || ppvtx1->parent_event() ==
nullptr) {
537 if (!ppvtx2 || ppvtx2->parent_event() ==
nullptr) {
544 removePV.push_back(vpPair(pvtx,
fp));
545 removePV.push_back(vpPair(pvtx, pp1));
546 removePV.push_back(vpPair(pvtx, pp2));
547 deleteP.push_back(
fp);
548 removeV.push_back(pvtx);
549 deleteV.push_back(pvtx);
551 ATH_MSG_DEBUG(
"2->1: ppvtx1,pp1,ppvtx2,pp2,pvtx,fp " << ppvtx1 <<
" " << pp1
552 <<
" " << ppvtx2 <<
" " << pp2 <<
" " << pvtx <<
" "<<
fp);
561 if (pvtx->particles_in().size() == 1 && pvtx->particles_out().size() == 2) {
570 }
else if (
fp == pout2) {
576 ATH_MSG_WARNING(
"1->2: No match found for branching " <<
fp <<
" " << pvtx <<
" " << pout1 <<
" " << pout2);
579 if (
fp != pout1)
continue;
583 if (pout1->momentum().m() < -1.0 || pout1->momentum().perp() < 1.0)
continue;
584 if (pout2->momentum().m() < -1.0 || pout2->momentum().perp() < 1.0)
continue;
587 double m12 = p12.m();
589 if (std::abs(m12) > 10. + 1.0
e-5 * p12.e()) {
590 ATH_MSG_WARNING(
"Spacelike mass^2 for parton sum " << m12 <<
" " << pp <<
" " << pvtx <<
" " << pout1 <<
" " << pout2);
594 if (doDebug)
ATH_MSG_DEBUG(
"1->2: parton pair mass " << m12);
597 if (doDebug)
ATH_MSG_DEBUG(
"Keeping 1->2: parton mass " << m12);
602 if (!ppvtx || ppvtx->parent_event() ==
nullptr) {
610 if (doDebug)
ATH_MSG_DEBUG(
"Merging 1->2: mass " << p12.m());
611 changePK.push_back(pkPair(pp, p12));
612 removePV.push_back(vpPair(pvtx, pp));
613 removePV.push_back(vpPair(pvtx, pout1));
614 removePV.push_back(vpPair(pvtx, pout2));
615 deleteP.push_back(pout1);
616 deleteP.push_back(pout2);
617 removeV.push_back(pvtx);
618 deleteV.push_back(pvtx);
620 ATH_MSG_DEBUG(
"Merge 1->2: ppvtx,pp,pvtx,pout1,pout2,evtx " << ppvtx <<
" " << pp <<
" " << pvtx <<
" " << pout1 <<
" "
622 ATH_MSG_DEBUG(
"Merge 1->2: id " << pp->pdg_id() <<
" " << pout1->pdg_id() <<
" " << pout2->pdg_id());
629 if (pvtx->particles_in().size() == 1) {
632 if (std::abs(pp->pdg_id()) == MC::PROTON) iCase = -1;
637 if (doDebug)
ATH_MSG_DEBUG(
"Case not found " << pvtx <<
" " <<
fp <<
" " << pvtx->particles_in().size() <<
" " << pvtx->particles_out().size());
642 HepMC::GenEvent::particle_iterator finp = thinEvt->particles_begin();
643 HepMC::GenEvent::particle_iterator finpB = thinEvt->particles_begin();
644 HepMC::GenEvent::particle_iterator finpE = thinEvt->particles_end();
647 for (finp = finpB; finp != finpE; ++finp) {
655 HepMC::GenVertex* pvtx =
fp->production_vertex();
669 if (pvtx->particles_in_size() == 1 && pvtx->particles_out_size() == 1) {
671 HepMC::GenVertex::particles_in_const_iterator pitr = pvtx->particles_in_const_begin();
679 HepMC::GenVertex* ppvtx = pp->production_vertex();
688 removePV.emplace_back(ppvtx, pp);
689 removePV.emplace_back(pvtx, pp);
690 deleteP.push_back(pp);
691 removeV.push_back(pvtx);
692 deleteV.push_back(pvtx);
693 addoutPV.emplace_back(ppvtx,
fp);
706 if (pvtx->particles_in_size() == 2 && pvtx->particles_out_size() == 1) {
708 HepMC::GenVertex::particles_in_const_iterator pitr = pvtx->particles_in_const_begin();
715 if (std::abs(pp1->momentum().perp()) < 1.e-3)
continue;
716 if (std::abs(pp2->momentum().perp()) < 1.e-3)
continue;
718 HepMC::GenVertex* ppvtx1 = pp1->production_vertex();
719 HepMC::GenVertex* ppvtx2 = pp2->production_vertex();
734 removePV.emplace_back(pvtx,
fp);
735 removePV.emplace_back(pvtx, pp1);
736 removePV.emplace_back(pvtx, pp2);
737 deleteP.push_back(
fp);
738 removeV.push_back(pvtx);
739 deleteV.push_back(pvtx);
755 if (pvtx->particles_in_size() == 1 && pvtx->particles_out_size() == 2) {
756 HepMC::GenVertex::particles_out_const_iterator poutitr = pvtx->particles_out_const_begin();
767 }
else if (
fp == pout2) {
776 if (
fp != pout1)
continue;
778 HepMC::GenVertex::particles_in_const_iterator pitr = pvtx->particles_in_const_begin();
782 if (pout1->momentum().m() < -1.0 || pout1->momentum().perp() < 1.0)
continue;
783 if (pout2->momentum().m() < -1.0 || pout2->momentum().perp() < 1.0)
continue;
787 double m12 = p12.m();
789 if (fabs(m12) > 10. + 1.0
e-5 * p12.e()) {
794 if (doDebug)
ATH_MSG_DEBUG(
"1->2: parton pair mass " << m12);
797 if (doDebug)
ATH_MSG_DEBUG(
"Keeping 1->2: parton mass " << m12);
802 HepMC::GenVertex* ppvtx = pp->production_vertex();
812 if (doDebug)
ATH_MSG_DEBUG(
"Merging 1->2: mass " << p12.m());
814 changePK.emplace_back(pp, p12);
815 removePV.emplace_back(pvtx, pp);
816 removePV.emplace_back(pvtx, pout1);
817 removePV.emplace_back(pvtx, pout2);
819 deleteP.push_back(pout1);
820 deleteP.push_back(pout2);
821 removeV.push_back(pvtx);
822 deleteV.push_back(pvtx);
825 ATH_MSG_DEBUG(
"Merge 1->2: ppvtx,pp,pvtx,pout1,pout2,evtx " << ppvtx <<
" " << pp <<
" " << pvtx <<
" " << pout1 <<
" "
827 ATH_MSG_DEBUG(
"Merge 1->2: id " << pp->pdg_id() <<
" " << pout1->pdg_id() <<
" " << pout2->pdg_id());
836 if (pvtx->particles_in_size() == 1) {
838 HepMC::GenVertex::particles_in_const_iterator pitr = pvtx->particles_in_const_begin();
840 if (std::abs(pp->pdg_id()) == MC::PROTON) iCase = -1;
854 if (doDebug)
ATH_MSG_DEBUG(
"Actually removing particles " << removePV.size());
856 for (
unsigned int i = 0;
i < removePV.size(); ++
i) {
861 v->remove_particle_in(
p);
862 v->remove_particle_out(
p);
864 v->remove_particle(
p);
869 if (doDebug)
ATH_MSG_DEBUG(
"Actually add particles in/out " << addinPV.size() <<
" " << addoutPV.size());
870 for (
unsigned int i = 0;
i < addoutPV.size(); ++
i) {
874 v->add_particle_out(
p);
878 for (
unsigned int i = 0;
i < changePK.size(); ++
i) {
881 pp->set_momentum(changePK[
i].
second);
885 if (doDebug)
ATH_MSG_DEBUG(
"Actually remove vertices " << removeV.size());
886 for (
unsigned int i = 0;
i < removeV.size(); ++
i) {
888 int nv = thinEvt->vertices().size();
889 if (doDebug) {
ATH_MSG_VERBOSE(
"Removing vertex " << removeV[
i] <<
" " << nv <<
" " << thinEvt->vertices().size()); }
890 thinEvt->remove_vertex(removeV[
i]);
892 int nv = thinEvt->vertices_size();
893 if (thinEvt->remove_vertex(removeV[
i])) {
894 if (doDebug) {
ATH_MSG_VERBOSE(
"Removed vertex " << removeV[
i] <<
" " << nv <<
" " << thinEvt->vertices_size()); }
900 if (doDebug)
ATH_MSG_DEBUG(
"End while(moreP) pass " << moreP);
908 if (doDebug)
ATH_MSG_DEBUG(
"Deleting vertices " << deleteV.size());
911 for (dvItr = deleteV.begin(); dvItr != deleteV.end(); ++dvItr) {
913 if (*dvItr)
delete (*dvItr);
916 if (doDebug)
ATH_MSG_DEBUG(
"Deleting particles " << deleteP.size());
919 for (dpItr = deleteP.begin(); dpItr != deleteP.end(); ++dpItr) {
921 if (*dpItr)
delete (*dpItr);
929 if (doDebug && doExtra) {
930 std::cout <<
"========== BEGIN EVENT BEFORE SOFT ==========" << std::endl;
932 std::cout <<
"========== END EVENT BEFORE SOFT ==========" << std::endl;
937 std::list<HepMC::GenParticlePtr> pNotHad;
938 std::list<HepMC::GenParticlePtr> pHard;
940 std::vector<HepMC::GenParticlePtr> beams=thinEvt->beams();
941 for (
auto fp: thinEvt->particles()) {
945 double ep =
fp->momentum().e();
946 double pzp =
fp->momentum().pz();
947 double mtmax = (ep + pzp) * (ep - pzp);
948 auto ancestors = HepMC::ancestor_particles(
fp);
950 for (
auto gpar: ancestors) {
951 double e = gpar->momentum().e();
952 double pz = gpar->momentum().pz();
957 pNotHad.push_back(
fp);
958 int ida = std::abs(
fp->pdg_id());
959 bool keepid = (ida > 10 && ida < 20) || (ida > 1000000 && ida < 9000000);
962 pHard.insert(pHard.end(),ancestors.begin(),ancestors.end());
969 bool keepid2 = ( ida == 6) || (ida >= 11 && ida <= 16) || (ida >= 23 && ida <= 37) || (ida > 1000000 && ida < 9000000);
970 if (keepid2 &&
fp->end_vertex()) {
971 auto descendants = HepMC::descendant_particles(
fp);
972 pHard.insert(pHard.end(),descendants.begin(),descendants.end());
985 for (
auto ph: pHard) {
989 if (doDebug)
ATH_MSG_DEBUG(
"Hard GenParticles total " << nhard);
995 beams[0] = thinEvt->beam_particles().first;
996 beams[1] = thinEvt->beam_particles().second;
998 HepMC::GenEvent::particle_iterator finp = thinEvt->particles_begin();
999 HepMC::GenEvent::particle_iterator finpE = thinEvt->particles_end();
1001 for (; finp != finpE; ++finp) {
1003 HepMC::GenVertex* pvtx =
fp->production_vertex();
1004 if (!pvtx)
continue;
1006 double ep =
fp->momentum().e();
1007 double pzp =
fp->momentum().pz();
1008 double mtmax = (ep + pzp) * (ep - pzp);
1009 HepMC::GenVertex::particle_iterator gpar =
fp->production_vertex()->particles_begin(HepMC::ancestors);
1010 HepMC::GenVertex::particle_iterator gparB = gpar;
1011 HepMC::GenVertex::particle_iterator gparE =
fp->production_vertex()->particles_end(HepMC::ancestors);
1013 for (; gpar != gparE; ++gpar) {
1014 double e = (*gpar)->momentum().e();
1015 double pz = (*gpar)->momentum().pz();
1020 pNotHad.push_back(
fp);
1021 int ida = std::abs(
fp->pdg_id());
1022 bool keepid = (ida > 10 && ida < 20) || (ida > 1000000 && ida < 9000000);
1024 pHard.push_back(
fp);
1025 for (gpar = gparB; gpar != gparE; ++gpar)
1026 pHard.push_back(*gpar);
1033 bool keepid2 = ida == 6 || (ida >= 11 && ida <= 16) || (ida >= 23 && ida <= 37) || (ida > 1000000 && ida < 9000000);
1034 if (keepid2 &&
fp->end_vertex()) {
1035 HepMC::GenVertex::particle_iterator des =
fp->end_vertex()->particles_begin(HepMC::descendants);
1036 HepMC::GenVertex::particle_iterator desE =
fp->end_vertex()->particles_end(HepMC::descendants);
1037 for (; des != desE; ++des)
1038 pHard.push_back(*des);
1053 for (; hItr2 != hItr2E; ++hItr2) {
1057 if (doDebug)
ATH_MSG_DEBUG(
"Hard GenParticles total " << nhard);
1065 for (
auto p: pNotHad) {
1067 bool isHard =
false;
1068 for (
auto h: pHard) {
1074 if (doDebug)
ATH_MSG_DEBUG(
"Particle bc/isHard " <<
p <<
" " << isHard);
1075 if (isHard)
continue;
1077 if (pvtx) pvtx->remove_particle_out(
p);
1079 if (evtx) evtx->remove_particle_in(
p);
1090 for (; pItr != pItrE; ++pItr) {
1094 bool isHard =
false;
1095 for (hItr = hItrB; hItr != hItrE; ++hItr) {
1102 if (isHard)
continue;
1103 HepMC::GenVertex* pvtx =
p->production_vertex();
1104 if (pvtx) pvtx->remove_particle(
p);
1105 HepMC::GenVertex* evtx =
p->end_vertex();
1106 if (evtx) evtx->remove_particle(
p);
1119 for (
auto vtx: thinEvt->vertices()) {
1120 if (vtx->particles_in().size() != 0)
continue;
1121 if (vtx->particles_out().size() != 0)
continue;
1122 removeV.push_back(vtx);
1123 deleteV.push_back(std::move(vtx));
1125 if (doDebug)
ATH_MSG_DEBUG(
"Removing/deleting 0-particle vertices " << removeV.size() <<
" " << deleteV.size());
1126 for (
unsigned int i = 0;
i < removeV.size(); ++
i) {
1128 thinEvt->remove_vertex(removeV[
i]);
1131 HepMC::GenEvent::vertex_iterator vtx = thinEvt->vertices_begin();
1132 HepMC::GenEvent::vertex_iterator vtxE = thinEvt->vertices_end();
1133 for (; vtx != vtxE; ++vtx) {
1134 if ((*vtx)->particles_in_size() != 0)
continue;
1135 if ((*vtx)->particles_out_size() != 0)
continue;
1136 removeV.push_back(*vtx);
1137 deleteV.push_back(*vtx);
1140 if (doDebug)
ATH_MSG_DEBUG(
"Removing/deleting 0-particle vertices " << removeV.size() <<
" " << deleteV.size());
1141 for (
unsigned int i = 0;
i < removeV.size(); ++
i) {
1142 if (thinEvt->remove_vertex(removeV[
i])) {
1151 for (dvItr = deleteV.begin(); dvItr != deleteV.end(); ++dvItr) {
1153 if (*dvItr)
delete (*dvItr);
1161 if (doDebug && doExtra) {
1162 std::cout <<
"========== BEGIN EVENT BEFORE 1-BODY ==========" << std::endl;
1164 std::cout <<
"========== END EVENT BEFORE 1-BODY ==========" << std::endl;
1180 for (
auto v: thinEvt->vertices()) {
1181 if (
v->particles_in().size() != 1)
continue;
1182 if (
v->particles_out().size() != 1)
continue;
1183 pin = *(
v->particles_in().begin());
1184 pout = *(
v->particles_out().begin());
1185 if (pin->pdg_id() !=
pout->pdg_id())
continue;
1187 if (pin == beams[0] || pin == beams[1])
continue;
1189 if (!pvtx || pvtx->parent_event() ==
nullptr) {
1195 vtx11 = std::move(
v);
1201 pvtx->remove_particle_in(pin);
1202 pvtx->remove_particle_out(pin);
1203 pvtx->add_particle_out(
pout);
1204 vtx11->remove_particle_in(pin);
1205 vtx11->remove_particle_out(pin);
1206 vtx11->remove_particle_in(
pout);
1207 vtx11->remove_particle_out(
pout);
1208 thinEvt->remove_vertex(vtx11);
1209 if (doDebug)
ATH_MSG_DEBUG(
"One-body new pvtx " << pvtx <<
" " << pvtx->particles_in().size() <<
" " << pvtx->particles_out().size());
1214 HepMC::GenVertex* vtx11;
1221 HepMC::GenEvent::vertex_iterator
v = thinEvt->vertices_begin();
1222 HepMC::GenEvent::vertex_iterator vE = thinEvt->vertices_end();
1225 for (;
v != vE; ++
v) {
1226 if ((*v)->particles_in_size() != 1)
continue;
1227 if ((*v)->particles_out_size() != 1)
continue;
1228 pin = *((*v)->particles_in_const_begin());
1229 pout = *((*v)->particles_out_const_begin());
1230 if (pin->pdg_id() !=
pout->pdg_id())
continue;
1232 if (pin == beams[0] || pin == beams[1])
continue;
1233 HepMC::GenVertex* pvtx = pin->production_vertex();
1246 HepMC::GenVertex* pvtx = pin->production_vertex();
1247 pvtx->remove_particle(pin);
1248 pvtx->add_particle_out(
pout);
1249 vtx11->remove_particle(pin);
1250 vtx11->remove_particle(
pout);
1251 thinEvt->remove_vertex(vtx11);
1254 if (doDebug)
ATH_MSG_DEBUG(
"One-body new pvtx " <<
HepMC::uniqueID(pvtx) <<
" " << pvtx->particles_in_size() <<
" " << pvtx->particles_out_size());
1275 for (
auto badv: thinEvt->vertices()) {
1276 if (!badv)
continue;
1277 if (badv->particles_in().size() != 1 || badv->particles_out().size() != 0)
continue;
1278 auto pitr = badv->particles_in().begin();
1280 if (pp->production_vertex())
continue;
1281 double pt = pp->momentum().perp();
1285 if (doDebug)
ATH_MSG_DEBUG(
"1->0: removing pp,badv,pt " << pp <<
" " << badv <<
" " <<
pt);
1286 removePV.push_back(vpPair(badv, pp));
1287 deleteP.push_back(std::move(pp));
1288 removeV.push_back(badv);
1289 deleteV.push_back(std::move(badv));
1293 for (
unsigned int i = 0;
i < removePV.size(); ++
i) {
1296 v->remove_particle_in(
p);
1297 v->remove_particle_out(std::move(
p));
1300 for (
unsigned int i = 0;
i < removeV.size(); ++
i) {
1301 thinEvt->remove_vertex(removeV[
i]);
1305 HepMC::GenEvent::vertex_iterator badv = thinEvt->vertices_begin();
1306 HepMC::GenEvent::vertex_iterator badvE = thinEvt->vertices_end();
1308 for (; badv != badvE; ++badv) {
1309 if (!(*badv))
continue;
1310 if ((*badv)->particles_in_size() != 1 || (*badv)->particles_out_size() != 0)
continue;
1311 HepMC::GenVertex::particles_in_const_iterator pitr = (*badv)->particles_in_const_begin();
1313 if (pp->production_vertex())
continue;
1314 double pt = pp->momentum().perp();
1318 if (doDebug)
ATH_MSG_DEBUG(
"1->0: removing pp,badv,pt " << pp <<
" " << *badv <<
" " <<
pt);
1319 removePV.emplace_back(*badv, pp);
1320 deleteP.push_back(pp);
1321 removeV.push_back(*badv);
1322 deleteV.push_back(*badv);
1327 for (
unsigned int i = 0;
i < removePV.size(); ++
i) {
1328 HepMC::GenVertex*
v = removePV[
i].first;
1330 v->remove_particle(
p);
1334 for (
unsigned int i = 0;
i < removeV.size(); ++
i) {
1335 if (!thinEvt->remove_vertex(removeV[
i])) {
ATH_MSG_WARNING(
"1->0: Failed to remove vertex " << removeV[
i]); }
1341 for (dvItr = deleteV.begin(); dvItr != deleteV.end(); ++dvItr) {
1342 if (*dvItr)
delete (*dvItr);
1347 for (dpItr = deleteP.begin(); dpItr != deleteP.end(); ++dpItr) {
1348 if (*dpItr)
delete (*dpItr);
1358 std::cout <<
"========== BEGIN EVENT AFTER THINNING ==========" << std::endl;
1360 std::cout <<
"========== END EVENT AFTER THINNING ==========" << std::endl;
1371 return StatusCode::SUCCESS;