19#include "EvtGenBase/EvtAbsRadCorr.hh"
20#include "EvtGenBase/EvtDecayBase.hh"
21#include "EvtGen_i/EvtGenExternal/EvtExternalGenList.hh"
23#include "EvtGenBase/EvtVector4R.hh"
24#include "EvtGenBase/EvtParticle.hh"
25#include "EvtGenBase/EvtParticleFactory.hh"
26#include "EvtGen/EvtGen.hh"
27#include "EvtGenBase/EvtRandomEngine.hh"
28#include "EvtGenBase/EvtDecayTable.hh"
38#include "GaudiKernel/MsgStream.h"
39#include "GaudiKernel/ISvcLocator.h"
40#include "GaudiKernel/DataSvc.h"
45#include "CLHEP/Random/RandFlat.h"
46#include "CLHEP/Vector/LorentzVector.h"
122 msg(MSG::INFO) <<
"EvtInclusiveDecay initialize" <<
endmsg;
127 msg(MSG::INFO) <<
"EvtInclusiveDecay selection parameters:" <<
endmsg;
134 msg(MSG::INFO) <<
"User selection parameters:" <<
endmsg;
146 msg(MSG::INFO) <<
"* blackList; = ";
148 msg(MSG::INFO) << (*i) <<
" ";
153 msg(MSG::INFO) <<
"* whiteList = ";
155 msg(MSG::INFO) << (*i) <<
" ";
163 EvtExternalGenList genList(
true,
xmlpath(),
"gamma");
164 EvtAbsRadCorr* radCorrEngine = genList.getPhotosModel();
165 std::list<EvtDecayBase*> extraModels = genList.getListOfModels();
176 return StatusCode::SUCCESS;
181 const EventContext& ctx)
190 const EventContext& ctx)
const
193 rngWrapper->
setSeed( streamName, ctx.slot(), randomSeedOffset, ctx.eventID().run_number() );
203 ctx.setEventID (EventIDBase (conditionsRun,
204 EventIDBase::UNDEFEVT,
205 EventIDBase::UNDEFNUM,
206 EventIDBase::UNDEFNUM,
246 std::set<HepMC::GenVertexPtr> visited;
247 std::set<HepMC::GenParticlePtr,ParticleIdCompare> toBeDecayed;
248 for (
auto p: *hepMC) {
249 if ( (!p->production_vertex()) ||
250 (p->production_vertex()->particles_in_size() == 0) ) {
253 return StatusCode::FAILURE;
258 msg(MSG::INFO) <<
"Printing HepMC record at " << hepMC <<
" BEFORE running EvtGen:" <<
endmsg;
267 bool eventPassesCuts(
false);
271 for (
auto p: toBeDecayed) {
273 msg(MSG::ERROR ) <<
"Overlapping decay tree for particle" << p <<
endmsg;
274 return StatusCode::FAILURE;
283 eventPassesCuts =
true;
292 hepMC->weight(
"nEvtGenDecayAttempts") = loopCounter;
296 msg(MSG::INFO) <<
"Printing HepMC record at " << hepMC <<
" AFTER running EvtGen:" <<
endmsg;
308 return StatusCode::SUCCESS;
315 ATH_MSG_INFO(
"The following particles were checked and didn't have any decay channels:");
317 std::cout << std::endl;
318 std::cout <<
" Particle code # Occurences" << std::endl;
319 std::cout <<
"----------------------------------" << std::endl;
322 int count = p->second;
323 std::cout << std::setw(14) <<
id
324 << std::setw(20) <<
count
327 std::cout << std::endl;
332 return StatusCode::SUCCESS;
346 std::set<HepMC::GenVertexPtr>& visited,
347 std::set<HepMC::GenParticlePtr,ParticleIdCompare>& toBeDecayed) {
349 if (!isToBeRemoved) {
351 toBeDecayed.insert(p);
352 isToBeRemoved =
true;
362 auto v = p->end_vertex();
364 if (visited.insert(v).second) {
366 ATH_MSG_WARNING(
"Found particle to be decayed with vertex with >1 incoming mother particles in decay tree");
367 ATH_MSG_WARNING( ([&p, &v](){ std::stringstream
ss; HepMC::Print::line(
ss,p); HepMC::Print::line(
ss,v);
return ss.str();})());
375 return StatusCode::SUCCESS;
384 auto v = p->end_vertex();
387 hepMC->remove_vertex(std::move(v));
412 if (
msgLvl(MSG::VERBOSE)) HepMC::Print::line(std::cout,part);
420 int id = part->pdg_id();
421 EvtId evtId=EvtPDL::evtIdFromStdHep(
id);
422 double en =(part->momentum()).e()/1000.;
423 double px=(part->momentum()).px()/1000.;
424 double py=(part->momentum()).py()/1000.;
425 double pz=(part->momentum()).pz()/1000.;
426 EvtVector4R evtP(en,px,py,pz);
427 EvtParticle* evtPart = EvtParticleFactory::particleFactory(evtId,evtP);
430 if(
m_setVMtransversePol && (
id==113 ||
id== 443 ||
id==100443 ||
id==553 ||
id==100553 ||
id==200553) )evtPart->setVectorSpinDensity();
433 if (
msgLvl(MSG::VERBOSE)) evtPart->printTree();
434 double ct_s = part->production_vertex()->position().t();
435 double x_s = part->production_vertex()->position().x();
436 double y_s = part->production_vertex()->position().y();
437 double z_s = part->production_vertex()->position().z();
439 EvtVector4R treeStart(ct_s,x_s,y_s,z_s);
442 if(evtPart->getNDaug() !=0) part->set_status(2);
443 evtPart->deleteTree();
449 EvtParticle* evtPart, EvtVector4R treeStart,
double momentumScaleFactor) {
450 if(evtPart->getNDaug()!=0) {
452 double ct=(evtPart->getDaug(0)->get4Pos()).get(0)+treeStart.get(0);
453 double x=(evtPart->getDaug(0)->get4Pos()).get(1)+treeStart.get(1);
454 double y=(evtPart->getDaug(0)->get4Pos()).get(2)+treeStart.get(2);
455 double z=(evtPart->getDaug(0)->get4Pos()).get(3)+treeStart.get(3);
459 hepMC->add_vertex(end_vtx);
460 end_vtx->add_particle_in(std::move(part));
463 for(
uint it=0; it<evtPart->getNDaug(); it++) {
464 double e=(evtPart->getDaug(it)->getP4Lab()).get(0) * momentumScaleFactor;
465 double px=(evtPart->getDaug(it)->getP4Lab()).get(1) * momentumScaleFactor;
466 double py=(evtPart->getDaug(it)->getP4Lab()).get(2) * momentumScaleFactor;
467 double pz=(evtPart->getDaug(it)->getP4Lab()).get(3) * momentumScaleFactor;
468 int id=EvtPDL::getStdHep(evtPart->getDaug(it)->getId());
470 if(evtPart->getDaug(it)->getNDaug() != 0) status=2;
472 end_vtx->add_particle_out(daughter);
473 addEvtGenDecayTree(hepMC, std::move(daughter), evtPart->getDaug(it), treeStart, momentumScaleFactor);
487 int id = p->pdg_id();
489 auto v = p->end_vertex();
490 if (v) nDaughters = v->particles_out_size();
493 if (p->status() == 3)
return false;
499 double m2 = p->momentum().m2();
506 EvtId evtId = EvtPDL::evtIdFromStdHep(
id);
509 if (evtId.getId()>=0)
511 nModes = EvtDecayTable::getInstance()->getNMode(evtId.getAlias());
514 <<
" (status = " << p->status()
515 <<
") -- " << nModes <<
" decay modes found");
533 if (std::abs(itd->pdg_id()) == std::abs(
id))
return false;
556 int id = std::abs(pId);
579 std::vector<HepMC::GenParticlePtr> *muons =
new std::vector<HepMC::GenParticlePtr>;
581 for (
const auto& p: *hepMC) {
582 if( std::abs(p->pdg_id()) == 13 )
586 for (
auto muItr1 = muons->begin(); muItr1 != muons->end(); ++muItr1) {
587 for (
auto muItr2 = muItr1+1; muItr2 != muons->end(); ++muItr2) {
595 double dimuMass =
invMass((*muItr1),(*muItr2));
608 double p1Px = p1->momentum().px();
609 double p1Py = p1->momentum().py();
610 double p1Pz = p1->momentum().pz();
611 double p1E = p1->momentum().e();
612 double p2Px = p2->momentum().px();
613 double p2Py = p2->momentum().py();
614 double p2Pz = p2->momentum().pz();
615 double p2E = p2->momentum().e();
616 double dimuE = p2E + p1E;
617 double dimuPx = p2Px + p1Px;
618 double dimuPy = p2Py + p1Py;
619 double dimuPz = p2Pz + p1Pz;
620 double invMass = std::sqrt(dimuE*dimuE - dimuPx*dimuPx - dimuPy*dimuPy - dimuPz*dimuPz);
632 std::set<HepMC::GenVertexPtr> visited;
633 unsigned int nParticlesFound = 0;
634 unsigned int nTreesFound = 0;
635 for (
auto p: *hepMC) {
636 if ( (!p->production_vertex()) ||
637 (p->production_vertex()->particles_in_size() == 0) ) {
639 std::cout <<
"\n Found new partial decay tree:\n" << std::endl;
640 unsigned int nParticlesVisited =
printTree(std::move(p),visited,1,particleSet);
641 std::cout <<
"\n " << nParticlesVisited <<
" particles in this subtree" << std::endl;
642 nParticlesFound += nParticlesVisited;
645 std::cout <<
"\n Total of " << nParticlesFound <<
" particles found in "
646 << nTreesFound <<
" decay subtrees in HepMC event record\n" << std::endl;
651 unsigned int nParticlesVisited = 1;
652 for (
int i=0; i<level; i++) std::cout <<
" ";
654 auto v = p->end_vertex();
656 if (v->particles_in_size() > 1)
657 std::cout <<
" [interaction: " << v->particles_in_size() <<
" particles, vertex " << v <<
"] --> ";
659 std::cout <<
" --> ";
660 if (visited.insert(v).second) {
664 std::cout << std::endl;
666 if (itp->end_vertex())
667 nParticlesVisited +=
printTree(std::move(itp), visited, level+1, particleSet);
672 std::cout <<
"see above" << std::endl;
674 std::cout <<
" no decay vertex\n" << std::endl;
675 return nParticlesVisited;
679 std::ostringstream buf;
681 if (particleSet)
for (
const auto& pinl: *particleSet)
if (pinl&&p)
if (pinl.get() == p.get()) inlist=
true;
682 if (statusHighlighting) {
683 if ( ((particleSet!=0) && (inlist)) ||
695 if (statusHighlighting) {
711 return CLHEP::RandFlat::shoot(
m_engine);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define CHECK(...)
Evaluate an expression and check for errors.
ATLAS-specific HepMC functions.
std::string PathResolverFindCalibDirectory(const std::string &logical_file_name)
Define macros for attributes used to control the static checker.
A wrapper class for event-slot-local random engines.
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
bool msgLvl(const MSG::Level lvl) const
DataModel_detail::iterator< DataVector > iterator
EvtInclusiveAtRndmGen(CLHEP::HepRandomEngine *engine)
CLHEP::HepRandomEngine * m_engine
bool m_applyUserSelection
void printHepMC(HepMC::GenEvent *hepMC, std::set< HepMC::GenParticlePtr, ParticleIdCompare > *particleSet=nullptr)
CLHEP::HepRandomEngine * getRandomEngine(const std::string &streamName, unsigned long int randomSeedOffset, const EventContext &ctx) const
bool m_setVMtransversePol
ServiceHandle< IAthRNGSvc > m_rndmSvc
double m_userSelMu1MaxEta
void removeDecayTree(HepMC::GenEvent *hepMC, HepMC::GenParticlePtr p)
bool m_userSelRequireOppositeSignedMu
void reseedRandomEngine(const std::string &streamName, const EventContext &ctx)
virtual ~EvtInclusiveDecay()
bool isDefaultB(const int pId) const
std::set< int > m_blackListSet
CLHEP::HepRandomEngine * getRandomEngineDuringInitialize(const std::string &streamName, unsigned long int randomSeedOffset, unsigned int conditionsRun=1, unsigned int lbn=1) const
bool m_printHepMCAfterEvtGen
bool m_checkDecayChannels
void addEvtGenDecayTree(HepMC::GenEvent *hepMC, HepMC::GenParticlePtr part, EvtParticle *evtPart, EvtVector4R treeStart, double momentumScaleFactor=1.0)
std::string m_randomStreamName
double m_userSelMaxDimuMass
StatusCode traverseDecayTree(HepMC::GenParticlePtr p, bool isToBeRemoved, std::set< HepMC::GenVertexPtr > &visited, std::set< HepMC::GenParticlePtr, ParticleIdCompare > &toBeDecayed)
bool passesUserSelection(HepMC::GenEvent *hepMC)
double m_userSelMinDimuMass
bool m_printHepMCBeforeEvtGen
double invMass(HepMC::ConstGenParticlePtr p1, HepMC::ConstGenParticlePtr p2)
McEventCollection * m_mcEvtColl
bool m_allowDefaultBDecays
std::string m_userDecayFile
std::string xmlpath(void)
std::set< int > m_whiteListSet
double m_userSelMu2MaxEta
IntegerProperty m_randomSeed
Seed for random number engine.
std::vector< int > m_blackList
bool m_prohibitRemoveSelfDecay
unsigned int printTree(HepMC::GenParticlePtr p, std::set< HepMC::GenVertexPtr > &visited, int level, std::set< HepMC::GenParticlePtr, ParticleIdCompare > *particleSet=nullptr)
std::string m_outputKeyName
bool isToBeDecayed(HepMC::ConstGenParticlePtr p, bool doCrossChecks)
bool m_printHepMCHighLightTopLevelDecays
std::string m_inputKeyName
bool m_allowAllKnownDecays
std::string pdgName(HepMC::ConstGenParticlePtr p, bool statusHighlighting=false, std::set< HepMC::GenParticlePtr, ParticleIdCompare > *particleSet=nullptr)
std::map< int, long > m_noDecayChannels
bool m_prohibitFinalStateDecay
bool m_printHepMCHighlighted
void decayParticle(HepMC::GenEvent *hepMC, HepMC::GenParticlePtr p)
StatusCode execute(const EventContext &ctx)
Execute method.
EvtInclusiveAtRndmGen * m_evtAtRndmGen
EvtInclusiveDecay(const std::string &name, ISvcLocator *pSvcLocator)
std::vector< int > m_whiteList
virtual StatusCode initialize() override
GenBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
void calculateSeedsMC21(long *seeds, const std::string &algName, uint64_t ev, uint64_t run, uint64_t offset=0)
Set the random seed using a string (e.g.
void setExtendedEventContext(EventContext &ctx, ExtendedEventContext &&ectx)
Move an extended context into a context object.
HepMC3::FourVector FourVector
GenParticlePtr newGenParticlePtr(const HepMC3::FourVector &mom=HepMC3::FourVector::ZERO_VECTOR(), int pid=0, int status=0)
void fillBarcodesAttribute(GenEvent *e)
HepMC3::GenParticlePtr GenParticlePtr
GenVertexPtr newGenVertexPtr(const HepMC3::FourVector &pos=HepMC3::FourVector::ZERO_VECTOR(), const int i=0)
HepMC3::GenVertexPtr GenVertexPtr
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
HepMC3::GenEvent GenEvent
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
bool isDecayed(const T &p)
Identify if the particle decayed.
bool isPhysical(const T &p)
Identify if the particle is physical, i.e. is stable or decayed.