22 #include "CLHEP/Units/SystemOfUnits.h"
42 const std::string&
name,
43 const IInterface*
parent ) :
54 "DeltaR isolation energy cut for electrons, muons, "
59 "Minimum threshold for transverse momentum of photons" );
63 "Minimum threshold for transverse momentum for all particles.\n"
64 "Warning: this cut is applied *before* Pt photon cut !" );
68 "Eta acceptance cut applied on all stable particles" );
74 "Switch to include or not particles from detector simulation "
79 "Switch to include or not parton showers" );
83 "Switch to remove particles which decay into themselves (t->tg) "
84 "*but* only for generated particles, not the ones from the "
85 "Geant4 interactions" );
104 if (
nullptr == in ||
nullptr ==
out ) {
106 <<
" in: " << in <<
endmsg
108 return StatusCode::FAILURE;
112 out->operator=( *in );
116 ATH_MSG_ERROR(
"Could not select the \"special\" barcodes !!");
117 return StatusCode::FAILURE;
122 ATH_MSG_ERROR(
"Could not remove the not \"special\" particles from the "\
123 "filtered McEventCollection !!");
124 return StatusCode::FAILURE;
129 ATH_MSG_ERROR(
"Could not reconnect the particles in the filtered "\
130 "McEventCollection !!");
131 return StatusCode::FAILURE;
134 return StatusCode::SUCCESS;
146 std::vector<HepMC::ConstGenParticlePtr>
particles;
152 if (
sc.isFailure() ) {
153 ATH_MSG_ERROR(
"Could not get Monte Carlo particles from TDS at : "
155 return StatusCode::FAILURE;
165 const int id =
part->pdg_id();
166 const int ida = std::abs(
id);
167 const HepMC::FourVector hlv =
part->momentum();
168 const double pt = hlv.perp();
169 const double eta = hlv.pseudoRapidity();
170 const double mass = hlv.m();
201 if (
nullptr ==
part->end_vertex() ) {
208 if( ida>100 && ida<1000) ifl=ida/100;
209 if( ida>1000 && ida<10000) ifl=ida/1000;
211 if( (ifl==5 && jj1<3 &&
mass<9.0*
GeV) || ( ifl==4 && jj1<3 &&
mass<2.4*
GeV) ) {
212 if (
accept) isSpcl =
true;
217 if( ida>5 && ida!=21 && ida!=9 &&
mass>9.*
GeV &&
accept ) isSpcl=
true;
220 if (ida >= 1 && ida <= 5 &&
accept ) isSpcl =
true;
223 if ( ida == 21 &&
accept ) isSpcl =
true;
226 if ( (ida == 9900041 || ida == 9900042) &&
accept ) isSpcl =
true;
229 if( ida>1000000 && ida<3000000 &&
accept ) isSpcl =
true;
236 if( ida>80 && ida<101 ) isSpcl=
false;
242 if( isSpcl && decayVtx ) {
243 auto dcyVtx =
part->end_vertex();
244 for(
const auto& child: *dcyVtx) {
245 if( child->pdg_id()==
id &&
275 if( !isSpcl )
continue;
279 if( isSpcl && decayVtx ) {
280 for(
const auto& child: *(
part->end_vertex())) {
289 <<
" and selected " <<
m_barcodes.size() <<
" particles");
291 return StatusCode::SUCCESS;
298 std::vector<HepMC::GenParticlePtr> going_out;
306 going_out.push_back(
p);
307 auto pvtx =
p->production_vertex();
308 auto evtx =
p->end_vertex();
309 if (pvtx) pvtx->remove_particle_out(
p);
312 for (
auto& pp: evtx->particles_out()) {
313 pvtx->add_particle_out(pp);
316 evtx->remove_particle_out(
p);
320 std::list<int> evtBarcodes;
321 for (
const auto&
p: **
evt ) {
324 for ( std::list<int>::const_iterator itrBc = evtBarcodes.begin();itrBc != evtBarcodes.end(); ++itrBc ) {
330 going_out.push_back(
p);
331 auto pvtx =
p->production_vertex();
332 auto evtx =
p->end_vertex();
333 if (pvtx) pvtx->remove_particle(
p);
339 while ( evtx->particles_out_const_begin() != evtx->particles_out_const_end()) {
340 HepMC::GenVertex::particles_out_const_iterator
np = evtx->particles_out_const_begin();
341 pvtx->add_particle_out(*
np);
344 evtx->remove_particle(
p);
354 std::vector<HepMC::ConstGenVertexPtr> going_out_again;
355 for (
auto&
v: (*evt)->vertices()) {
356 if (
v->particles_in().empty() &&
v->particles_out().empty() ){
357 going_out_again.push_back(
v);
364 d != going_out.end();
371 std::vector<HepMC::GenVertex*> going_out_again;
372 for ( HepMC::GenEvent::vertex_const_iterator
v = (*evt)->vertices_begin();
373 v != (*evt)->vertices_end(); ++
v ) {
374 if ( (*v)->particles_in_size() == 0 && (*v)->particles_out_size() == 0 ){
375 going_out_again.push_back(*
v);
381 d != going_out_again.end();
393 if (!sigProcVtx)
continue;
395 bool isInColl =
false;
396 for (
const auto& itrVtx: (*evt)->vertices() ) {
404 (*evt)->remove_attribute(
"signal_process_vertex");
407 const HepMC::GenVertex * sigProcVtx = (*evt)->signal_process_vertex();
408 if ( 0 != sigProcVtx ) {
409 const int sigProcBC = sigProcVtx->barcode();
410 bool isInColl =
false;
411 for ( HepMC::GenEvent::vertex_const_iterator itrVtx = (*evt)->vertices_begin();
412 itrVtx != (*evt)->vertices_end();
414 if ( sigProcBC == (*itrVtx)->barcode() ) {
420 (*evt)->set_signal_process_vertex(0);
426 return StatusCode::SUCCESS;
432 if (
nullptr == in ||
nullptr ==
out ) {
434 <<
" in: " << in <<
endmsg
436 return StatusCode::FAILURE;
439 return StatusCode::SUCCESS;
441 for (
unsigned int iEvt = 0; iEvt != in->size(); ++iEvt) {
442 const HepMC::GenEvent *
evt = (*in)[iEvt];
443 HepMC::GenEvent * outEvt = (*out)[iEvt];
447 for (
const auto& itrPart: *outEvt) {
448 if ( itrPart->end_vertex() ) {
452 ATH_MSG_WARNING(
"Could not rebuild links for this particle = "<< itrPart);
455 <<
"==========================================================="
456 <<
endmsg <<
"Production vertex for particle " << itrPart <<
" : ";
457 if ( itrPart->production_vertex() ) {
458 std::stringstream prodVtx(
"");
467 if ( itrPart->end_vertex() ) {
468 std::stringstream dcyVtx(
"");
481 return StatusCode::SUCCESS;
486 HepMC::GenEvent * outEvt,
492 return StatusCode::FAILURE;
495 if ( mcPart->end_vertex() ) {
496 ATH_MSG_VERBOSE(
"GenParticle has already a decay vertex : nothing to do");
497 return StatusCode::SUCCESS;
502 return StatusCode::FAILURE;
507 return StatusCode::FAILURE;
510 return StatusCode::SUCCESS;
513 const int pdgId = mcPart->pdg_id();
521 ATH_MSG_VERBOSE(
"No decay vertex for the particle #" << bc <<
" : " <<
"No link to rebuild...");
522 return StatusCode::SUCCESS;
525 std::list<int> bcChildPart;
526 std::list<int> bcChildVert;
532 const HepMC::GenVertex::vertex_iterator endVtx = dcyVtx->vertices_end(HepMC::descendants);
533 for ( HepMC::GenVertex::vertex_iterator itrVtx = dcyVtx->vertices_begin( HepMC::descendants );
536 bool foundPdgId =
false;
537 HepMC::GenVertex::particles_in_const_iterator endPart = (*itrVtx)->particles_in_const_end();
538 for ( HepMC::GenVertex::particles_in_const_iterator itrPart = (*itrVtx)->particles_in_const_begin();
544 bcChildPart.push_front( (*itrPart)->barcode() );
546 if ( (*itrPart)->pdg_id() ==
pdgId ) {
552 bcChildVert.push_front( (*itrVtx)->barcode() );
561 std::list<int>::const_iterator bcVtxEnd = bcChildVert.end();
562 for ( std::list<int>::const_iterator itrBcVtx = bcChildVert.begin();
563 itrBcVtx != bcVtxEnd;
565 HepMC::GenVertex * childVtx = outEvt->barcode_to_vertex(*itrBcVtx);
567 if ( childVtx->particles_in_size() > 0 ) {
568 HepMC::GenVertex::particles_in_const_iterator endPart = childVtx->particles_in_const_end();
569 for ( HepMC::GenVertex::particles_in_const_iterator itrPart = childVtx->particles_in_const_begin();
572 if ( (*itrPart)->pdg_id() ==
pdgId ) {
573 HepMC::GenVertex * prodVtx = (*itrPart)->production_vertex();
575 if ( prodVtx->particles_in_size() > 0 ) {
580 <<
"found a particle = "
581 << (*itrPart) <<
", "
582 <<
"but its production vertex has incoming particles !"
590 outEvt->add_vertex( linkVtx );
591 linkVtx->add_particle_in( mcPart );
592 linkVtx->add_particle_out( *itrPart );
595 <<
"====================================================="
597 <<
"Created a GenVertex - link !"
599 std::stringstream vtxLink(
"");
600 linkVtx->print(vtxLink);
604 <<
"====================================================="
613 childVtx->add_particle_in(mcPart);
614 msg(MSG::WARNING) <<
"Odd situation:" << std::endl;
615 std::stringstream vtxDump(
"" );
616 childVtx->print(vtxDump);
617 msg(MSG::WARNING) << vtxDump.str() <<
endmsg;
618 return StatusCode::SUCCESS;
622 return StatusCode::FAILURE;
634 return StatusCode::FAILURE;
636 return StatusCode::SUCCESS;