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"
41#include "GaudiKernel/IPartPropSvc.h"
46#include "CLHEP/Random/RandFlat.h"
47#include "CLHEP/Vector/LorentzVector.h"
123 msg(MSG::INFO) <<
"EvtInclusiveDecay initialize" <<
endmsg;
128 msg(MSG::INFO) <<
"EvtInclusiveDecay selection parameters:" <<
endmsg;
135 msg(MSG::INFO) <<
"User selection parameters:" <<
endmsg;
147 msg(MSG::INFO) <<
"* blackList; = ";
149 msg(MSG::INFO) << (*i) <<
" ";
154 msg(MSG::INFO) <<
"* whiteList = ";
156 msg(MSG::INFO) << (*i) <<
" ";
164 EvtExternalGenList genList(
true,
xmlpath(),
"gamma");
165 EvtAbsRadCorr* radCorrEngine = genList.getPhotosModel();
166 std::list<EvtDecayBase*> extraModels = genList.getListOfModels();
177 return StatusCode::SUCCESS;
182 const EventContext& ctx)
191 const EventContext& ctx)
const
194 rngWrapper->
setSeed( streamName, ctx.slot(), randomSeedOffset, ctx.eventID().run_number() );
204 ctx.setEventID (EventIDBase (conditionsRun,
205 EventIDBase::UNDEFEVT,
206 EventIDBase::UNDEFNUM,
207 EventIDBase::UNDEFNUM,
247 std::set<HepMC::GenVertexPtr> visited;
248 std::set<HepMC::GenParticlePtr,ParticleIdCompare> toBeDecayed;
249 for (
auto p: *hepMC) {
250 if ( (!p->production_vertex()) ||
251 (p->production_vertex()->particles_in_size() == 0) ) {
254 return StatusCode::FAILURE;
259 msg(MSG::INFO) <<
"Printing HepMC record at " << hepMC <<
" BEFORE running EvtGen:" <<
endmsg;
268 bool eventPassesCuts(
false);
272 for (
auto p: toBeDecayed) {
274 msg(MSG::ERROR ) <<
"Overlapping decay tree for particle" << p <<
endmsg;
275 return StatusCode::FAILURE;
284 eventPassesCuts =
true;
293 hepMC->weight(
"nEvtGenDecayAttempts") = loopCounter;
297 msg(MSG::INFO) <<
"Printing HepMC record at " << hepMC <<
" AFTER running EvtGen:" <<
endmsg;
309 return StatusCode::SUCCESS;
316 ATH_MSG_INFO(
"The following particles were checked and didn't have any decay channels:");
318 std::cout << std::endl;
319 std::cout <<
" Particle code # Occurences" << std::endl;
320 std::cout <<
"----------------------------------" << std::endl;
323 int count = p->second;
324 std::cout << std::setw(14) <<
id
325 << std::setw(20) <<
count
328 std::cout << std::endl;
333 return StatusCode::SUCCESS;
347 std::set<HepMC::GenVertexPtr>& visited,
348 std::set<HepMC::GenParticlePtr,ParticleIdCompare>& toBeDecayed) {
350 if (!isToBeRemoved) {
352 toBeDecayed.insert(p);
353 isToBeRemoved =
true;
363 auto v = p->end_vertex();
365 if (visited.insert(v).second) {
367 ATH_MSG_WARNING(
"Found particle to be decayed with vertex with >1 incoming mother particles in decay tree");
368 ATH_MSG_WARNING( ([&p, &v](){ std::stringstream
ss; HepMC::Print::line(
ss,p); HepMC::Print::line(
ss,v);
return ss.str();})());
376 return StatusCode::SUCCESS;
385 auto v = p->end_vertex();
388 hepMC->remove_vertex(std::move(v));
413 if (
msgLvl(MSG::VERBOSE)) HepMC::Print::line(std::cout,part);
421 int id = part->pdg_id();
422 EvtId evtId=EvtPDL::evtIdFromStdHep(
id);
423 double en =(part->momentum()).e()/1000.;
424 double px=(part->momentum()).px()/1000.;
425 double py=(part->momentum()).py()/1000.;
426 double pz=(part->momentum()).pz()/1000.;
427 EvtVector4R evtP(en,px,py,pz);
428 EvtParticle* evtPart = EvtParticleFactory::particleFactory(evtId,evtP);
431 if(
m_setVMtransversePol && (
id==113 ||
id== 443 ||
id==100443 ||
id==553 ||
id==100553 ||
id==200553) )evtPart->setVectorSpinDensity();
434 if (
msgLvl(MSG::VERBOSE)) evtPart->printTree();
435 double ct_s = part->production_vertex()->position().t();
436 double x_s = part->production_vertex()->position().x();
437 double y_s = part->production_vertex()->position().y();
438 double z_s = part->production_vertex()->position().z();
440 EvtVector4R treeStart(ct_s,x_s,y_s,z_s);
443 if(evtPart->getNDaug() !=0) part->set_status(2);
444 evtPart->deleteTree();
450 EvtParticle* evtPart, EvtVector4R treeStart,
double momentumScaleFactor) {
451 if(evtPart->getNDaug()!=0) {
453 double ct=(evtPart->getDaug(0)->get4Pos()).get(0)+treeStart.get(0);
454 double x=(evtPart->getDaug(0)->get4Pos()).get(1)+treeStart.get(1);
455 double y=(evtPart->getDaug(0)->get4Pos()).get(2)+treeStart.get(2);
456 double z=(evtPart->getDaug(0)->get4Pos()).get(3)+treeStart.get(3);
460 hepMC->add_vertex(end_vtx);
461 end_vtx->add_particle_in(std::move(part));
464 for(
uint it=0; it<evtPart->getNDaug(); it++) {
465 double e=(evtPart->getDaug(it)->getP4Lab()).get(0) * momentumScaleFactor;
466 double px=(evtPart->getDaug(it)->getP4Lab()).get(1) * momentumScaleFactor;
467 double py=(evtPart->getDaug(it)->getP4Lab()).get(2) * momentumScaleFactor;
468 double pz=(evtPart->getDaug(it)->getP4Lab()).get(3) * momentumScaleFactor;
469 int id=EvtPDL::getStdHep(evtPart->getDaug(it)->getId());
471 if(evtPart->getDaug(it)->getNDaug() != 0) status=2;
473 end_vtx->add_particle_out(daughter);
474 addEvtGenDecayTree(hepMC, std::move(daughter), evtPart->getDaug(it), treeStart, momentumScaleFactor);
488 int id = p->pdg_id();
490 auto v = p->end_vertex();
491 if (v) nDaughters = v->particles_out_size();
494 if (p->status() == 3)
return false;
500 double m2 = p->momentum().m2();
507 EvtId evtId = EvtPDL::evtIdFromStdHep(
id);
510 if (evtId.getId()>=0)
512 nModes = EvtDecayTable::getInstance()->getNMode(evtId.getAlias());
515 <<
" (status = " << p->status()
516 <<
") -- " << nModes <<
" decay modes found");
534 if (std::abs(itd->pdg_id()) == std::abs(
id))
return false;
557 int id = std::abs(pId);
580 std::vector<HepMC::GenParticlePtr> *muons =
new std::vector<HepMC::GenParticlePtr>;
582 for (
const auto& p: *hepMC) {
583 if( std::abs(p->pdg_id()) == 13 )
587 for (
auto muItr1 = muons->begin(); muItr1 != muons->end(); ++muItr1) {
588 for (
auto muItr2 = muItr1+1; muItr2 != muons->end(); ++muItr2) {
596 double dimuMass =
invMass((*muItr1),(*muItr2));
609 double p1Px = p1->momentum().px();
610 double p1Py = p1->momentum().py();
611 double p1Pz = p1->momentum().pz();
612 double p1E = p1->momentum().e();
613 double p2Px = p2->momentum().px();
614 double p2Py = p2->momentum().py();
615 double p2Pz = p2->momentum().pz();
616 double p2E = p2->momentum().e();
617 double dimuE = p2E + p1E;
618 double dimuPx = p2Px + p1Px;
619 double dimuPy = p2Py + p1Py;
620 double dimuPz = p2Pz + p1Pz;
621 double invMass = std::sqrt(dimuE*dimuE - dimuPx*dimuPx - dimuPy*dimuPy - dimuPz*dimuPz);
633 std::set<HepMC::GenVertexPtr> visited;
634 unsigned int nParticlesFound = 0;
635 unsigned int nTreesFound = 0;
636 for (
auto p: *hepMC) {
637 if ( (!p->production_vertex()) ||
638 (p->production_vertex()->particles_in_size() == 0) ) {
640 std::cout <<
"\n Found new partial decay tree:\n" << std::endl;
641 unsigned int nParticlesVisited =
printTree(std::move(p),visited,1,particleSet);
642 std::cout <<
"\n " << nParticlesVisited <<
" particles in this subtree" << std::endl;
643 nParticlesFound += nParticlesVisited;
646 std::cout <<
"\n Total of " << nParticlesFound <<
" particles found in "
647 << nTreesFound <<
" decay subtrees in HepMC event record\n" << std::endl;
652 unsigned int nParticlesVisited = 1;
653 for (
int i=0; i<level; i++) std::cout <<
" ";
655 auto v = p->end_vertex();
657 if (v->particles_in_size() > 1)
658 std::cout <<
" [interaction: " << v->particles_in_size() <<
" particles, vertex " << v <<
"] --> ";
660 std::cout <<
" --> ";
661 if (visited.insert(v).second) {
665 std::cout << std::endl;
667 if (itp->end_vertex())
668 nParticlesVisited +=
printTree(std::move(itp), visited, level+1, particleSet);
673 std::cout <<
"see above" << std::endl;
675 std::cout <<
" no decay vertex\n" << std::endl;
676 return nParticlesVisited;
680 std::ostringstream buf;
682 if (particleSet)
for (
const auto& pinl: *particleSet)
if (pinl&&p)
if (pinl.get() == p.get()) inlist=
true;
683 if (statusHighlighting) {
684 if ( ((particleSet!=0) && (inlist)) ||
696 if (statusHighlighting) {
712 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.