25 #include "CLHEP/Units/SystemOfUnits.h"
42 const std::string&
name,
43 const IInterface*
parent ) :
51 "DeltaR isolation energy cut for electrons, muons, "
56 "Minimum threshold for transverse momentum of photons" );
60 "Minimum threshold for transverse momentum for all particles.\n"
61 "Warning: this cut is applied *before* Pt photon cut !" );
65 "Eta acceptance cut applied on all stable particles" );
69 "radius acceptance - in milimeters - cut applied on all stable "
76 "Switch to include or not particles from detector simulation "
81 "Switch to include or not parton showers" );
85 "Switch to remove particles which decay into themselves (t->tg) "
86 "*but* only for generated particles, not the ones from the "
87 "Geant4 interactions" );
106 if (
nullptr == in ||
nullptr ==
out ) {
108 <<
" in: " << in <<
endmsg
110 return StatusCode::FAILURE;
114 out->operator=( *in );
118 ATH_MSG_ERROR(
"Could not select the \"special\" barcodes !!");
119 return StatusCode::FAILURE;
124 ATH_MSG_ERROR(
"Could not remove the not \"special\" particles from the "\
125 "filtered McEventCollection !!");
126 return StatusCode::FAILURE;
131 ATH_MSG_ERROR(
"Could not reconnect the particles in the filtered "\
132 "McEventCollection !!");
133 return StatusCode::FAILURE;
136 return StatusCode::SUCCESS;
148 std::vector<HepMC::ConstGenParticlePtr>
particles;
154 if (
sc.isFailure() ) {
156 return StatusCode::FAILURE;
164 if(
sc.isFailure() ) {
166 return StatusCode::SUCCESS;
173 for ( ; mcEventItr != mcEventItrE; ++mcEventItr ) {
175 const HepMC::GenEvent* genEvent = (*mcEventItr);
178 auto vxp = genEvent->vertices().begin();
180 HepMC::GenEvent::vertex_const_iterator vxp = genEvent->vertices_begin();
182 const float xp = (*vxp)->position().x();
183 const float yp = (*vxp)->position().y();
184 const float zp = (*vxp)->position().z();
188 for (
const auto&
part: *genEvent) {
189 const int id =
part->pdg_id();
190 const HepMC::FourVector hlv =
part->momentum();
191 const double pt = hlv.perp();
198 float xi = (prodVtx->position()).
x();
199 float yi = (prodVtx->position()).
y();
200 float zi = (prodVtx->position()).
z();
202 ATH_MSG_DEBUG(
"Primary Vertex = " << xp <<
" " << yp <<
" " << zp <<
" " <<
"Production Vertex = " << xi <<
" " << yi <<
" " << zi <<
" " <<
"Particle ID = " <<
id);
204 float deltaR = std::sqrt( (xp-xi)*(xp-xi) + (yp-yi)*(yp-yi) );
220 if( !isSpcl )
continue;
224 if( isSpcl && decayVtx ) {
225 for(
const auto& child: *(
part->end_vertex())) {
235 return StatusCode::SUCCESS;
242 std::vector<HepMC::GenParticlePtr> going_out;
243 std::list<int> evtBarcodes;
245 const auto &
barcodes = (*evt)->attribute<HepMC::GenEventBarcodes> (
"barcodes");
246 std::map<int,int> id_to_barcode_map;
248 for (
const auto& keyval: id_to_barcode_map) evtBarcodes.push_back(keyval.second);
250 for (
const auto&
p: **
evt) {
255 for ( std::list<int>::const_iterator itrBc = evtBarcodes.begin(); itrBc != evtBarcodes.end(); ++itrBc ) {
260 going_out.push_back(
p);
264 std::pair<int,int> bcNext( 0, 0 );
266 msg(
MSG::DEBUG) <<
"Removing [" <<
p <<
"]" <<
"\tprod/endVtx: " << pvtx <<
"/" << evtx <<
endmsg;
267 std::list<int>::const_iterator pNext = itrBc;
269 if ( pNext != evtBarcodes.end() ) {
274 if (pvtx) pvtx->remove_particle_out(
p);
276 if (pvtx) pvtx->remove_particle(
p);
284 while ( evtx->particles_out().begin() != evtx->particles_out().end()) {
285 pvtx->add_particle_out(evtx->particles_out().front());
288 evtx->remove_particle_out(
p);
290 while ( evtx->particles_out_const_begin() != evtx->particles_out_const_end()) {
291 HepMC::GenVertex::particles_out_const_iterator
np = evtx->particles_out_const_begin();
292 pvtx->add_particle_out(*
np);
295 evtx->remove_particle(
p);
300 std::list<int>::const_iterator pNext = itrBc;
302 if ( pNext != evtBarcodes.end() ) {
306 if ( bcNext.first != bcNext.second ) {
307 ATH_MSG_WARNING(
"\tIterator has been CORRUPTED !!" <<
endmsg <<
"\tbcNext: " << bcNext.first <<
" --> " << bcNext.second);
309 ATH_MSG_DEBUG(
"\tIterator OK:" <<
endmsg <<
"\tbcNext: " << bcNext.first <<
" --> " << bcNext.second);
320 std::vector<HepMC::ConstGenVertexPtr> going_out_again;
321 for (
auto&
v: (*evt)->vertices() ) {
322 if (
v->particles_in().empty() &&
v->particles_out().empty() ){
323 going_out_again.push_back(
v);
329 d != going_out.end();
336 std::vector<HepMC::GenVertex*> going_out_again;
337 for ( HepMC::GenEvent::vertex_const_iterator
v = (*evt)->vertices_begin();
338 v != (*evt)->vertices_end(); ++
v ) {
339 if ( (*v)->particles_in_size() == 0 && (*v)->particles_out_size() == 0 ){
340 going_out_again.push_back(*
v);
346 d != going_out_again.end();
357 if ( !sigProcVtx )
continue;
359 bool isInColl =
false;
364 (*evt)->remove_attribute(
"signal_process_vertex");
368 (*evt)->set_signal_process_vertex(0);
373 return StatusCode::SUCCESS;
378 if (
nullptr == in ||
nullptr ==
out ) {
380 return StatusCode::FAILURE;
383 for (
unsigned int iEvt = 0; iEvt != in->
size(); ++iEvt) {
384 const HepMC::GenEvent *
evt = (*in)[iEvt];
385 HepMC::GenEvent * outEvt = (*out)[iEvt];
389 for (
const auto& itrPart: *outEvt) {
390 if ( itrPart->end_vertex() ) {
394 ATH_MSG_WARNING(
"Could not rebuild links for this particle [pdgId,particle]= "<< itrPart->pdg_id() <<
", " << itrPart);
396 msg(
MSG::VERBOSE)<<
"==========================================================="<<
endmsg<<
"Production vertex for particle " << itrPart <<
" : ";
397 if ( itrPart->production_vertex() ) {
398 std::stringstream prodVtx(
"");
406 if ( itrPart->end_vertex() ) {
407 std::stringstream dcyVtx(
"");
418 return StatusCode::SUCCESS;
422 HepMC::GenEvent * outEvt,
427 return StatusCode::FAILURE;
430 if ( mcPart->end_vertex() ) {
431 ATH_MSG_VERBOSE(
"GenParticle has already a decay vertex : nothing to do");
432 return StatusCode::SUCCESS;
437 return StatusCode::FAILURE;
442 return StatusCode::FAILURE;
446 const int pdgId = mcPart->pdg_id();
458 ATH_MSG_VERBOSE(
"No decay vertex for the particle #" << bc <<
" : " <<
"No link to rebuild...");
459 return StatusCode::SUCCESS;
462 std::list<int> bcChildPart;
463 std::list<int> bcChildVert;
470 auto descendants=HepMC::descendant_vertices(dcyVtx);
471 for (
const auto& itrVtx: descendants) {
472 bool foundPdgId =
false;
473 for (
const auto& itrPart: itrVtx->particles_in()) {
476 if ( itrPart->pdg_id() ==
pdgId ) {
485 const HepMC::GenVertex::vertex_iterator endVtx = dcyVtx->vertices_end(HepMC::descendants);
486 for ( HepMC::GenVertex::vertex_iterator itrVtx = dcyVtx->vertices_begin( HepMC::descendants );
489 bool foundPdgId =
false;
490 HepMC::GenVertex::particles_in_const_iterator endPart = (*itrVtx)->particles_in_const_end();
491 for ( HepMC::GenVertex::particles_in_const_iterator itrPart = (*itrVtx)->particles_in_const_begin();
498 bcChildPart.push_front( (*itrPart)->barcode() );
500 if ( (*itrPart)->pdg_id() ==
pdgId ) {
506 bcChildVert.push_front( (*itrVtx)->barcode() );
517 std::list<int>::const_iterator bcVtxEnd = bcChildVert.end();
518 for ( std::list<int>::const_iterator itrBcVtx = bcChildVert.begin(); itrBcVtx != bcVtxEnd; ++itrBcVtx ) {
521 if ( !childVtx->particles_in().empty() ) {
522 for (
const auto& itrPart: childVtx->particles_in()) {
523 if ( itrPart->pdg_id() ==
pdgId ) {
526 if ( !prodVtx->particles_in().empty() ) {
530 msg(
MSG::VERBOSE)<<
"found a particle = "<< itrPart <<
", "<<
"but its production vertex has incoming particles !" <<
endmsg;
537 outEvt->add_vertex( linkVtx );
538 linkVtx->add_particle_in( mcPart );
539 linkVtx->add_particle_out( itrPart );
541 msg(MSG::ERROR)<<
"=====================================================" <<
endmsg <<
"Created a GenVertex - link !" << std::endl;
542 std::stringstream vtxLink(
"");
544 msg(MSG::ERROR)<< vtxLink.str()<<
endmsg<<
"====================================================="<<
endmsg;
552 childVtx->add_particle_in(mcPart);
553 msg(MSG::WARNING) <<
"Odd situation:" << std::endl;
554 std::stringstream vtxDump(
"" );
556 msg(MSG::WARNING) << vtxDump.str() <<
endmsg;
557 return StatusCode::SUCCESS;
562 std::list<int>::const_iterator bcVtxEnd = bcChildVert.end();
563 for ( std::list<int>::const_iterator itrBcVtx = bcChildVert.begin();
564 itrBcVtx != bcVtxEnd;
566 HepMC::GenVertex * childVtx = outEvt->barcode_to_vertex(*itrBcVtx);
568 if ( childVtx->particles_in_size() > 0 ) {
569 HepMC::GenVertex::particles_in_const_iterator endPart = childVtx->particles_in_const_end();
570 for ( HepMC::GenVertex::particles_in_const_iterator itrPart = childVtx->particles_in_const_begin();
573 if ( (*itrPart)->pdg_id() ==
pdgId ) {
574 HepMC::GenVertex * prodVtx = (*itrPart)->production_vertex();
576 if ( prodVtx->particles_in_size() > 0 ) {
580 msg(
MSG::VERBOSE)<<
"found a particle [bc,pdgId]= "<< (*itrPart)->barcode() <<
", "<<
"but its production vertex has incoming particles !" <<
endmsg;
587 outEvt->add_vertex( linkVtx );
588 linkVtx->add_particle_in( mcPart );
589 linkVtx->add_particle_out( *itrPart );
591 msg(MSG::ERROR)<<
"====================================================="<<
endmsg<<
"Created a GenVertex - link !"<< std::endl;
592 std::stringstream vtxLink(
"");
593 linkVtx->print(vtxLink);
594 msg(MSG::ERROR)<< vtxLink.str()<<
endmsg<<
"=====================================================" <<
endmsg;
602 childVtx->add_particle_in(mcPart);
603 msg(MSG::WARNING) <<
"Odd situation:" << std::endl;
604 std::stringstream vtxDump(
"" );
605 childVtx->print(vtxDump);
606 msg(MSG::WARNING) << vtxDump.str() <<
endmsg;
607 return StatusCode::SUCCESS;
613 return StatusCode::FAILURE;
624 return StatusCode::FAILURE;
626 return StatusCode::SUCCESS;