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,
227 std::unique_ptr<McEventCollection> mcEvtCollPtr;
236 mcEvtCollPtr = std::make_unique<McEventCollection>(*oldmcEvtColl);
237 mcEvtColl = mcEvtCollPtr.get();
242 for( mcItr = mcEvtColl->
begin(); mcItr != mcEvtColl->
end(); ++mcItr ) {
248 std::set<HepMC::GenVertexPtr> visited;
249 std::set<HepMC::GenParticlePtr,ParticleIdCompare> toBeDecayed;
250 for (
auto p: *hepMC) {
251 if ( (!p->production_vertex()) ||
252 (p->production_vertex()->particles_in_size() == 0) ) {
255 return StatusCode::FAILURE;
260 msg(MSG::INFO) <<
"Printing HepMC record at " << hepMC <<
" BEFORE running EvtGen:" <<
endmsg;
269 bool eventPassesCuts(
false);
273 for (
auto p: toBeDecayed) {
275 msg(MSG::ERROR ) <<
"Overlapping decay tree for particle" << p <<
endmsg;
276 return StatusCode::FAILURE;
285 eventPassesCuts =
true;
294 hepMC->weight(
"nEvtGenDecayAttempts") = loopCounter;
298 msg(MSG::INFO) <<
"Printing HepMC record at " << hepMC <<
" AFTER running EvtGen:" <<
endmsg;
315 return StatusCode::SUCCESS;
322 ATH_MSG_INFO(
"The following particles were checked and didn't have any decay channels:");
324 std::cout << std::endl;
325 std::cout <<
" Particle code # Occurences" << std::endl;
326 std::cout <<
"----------------------------------" << std::endl;
329 int count = p->second;
330 std::cout << std::setw(14) <<
id
331 << std::setw(20) <<
count
334 std::cout << std::endl;
339 return StatusCode::SUCCESS;
353 std::set<HepMC::GenVertexPtr>& visited,
354 std::set<HepMC::GenParticlePtr,ParticleIdCompare>& toBeDecayed) {
356 if (!isToBeRemoved) {
358 toBeDecayed.insert(p);
359 isToBeRemoved =
true;
369 auto v = p->end_vertex();
371 if (visited.insert(v).second) {
373 ATH_MSG_WARNING(
"Found particle to be decayed with vertex with >1 incoming mother particles in decay tree");
374 ATH_MSG_WARNING( ([&p, &v](){ std::stringstream
ss; HepMC::Print::line(
ss,p); HepMC::Print::line(
ss,v);
return ss.str();})());
382 return StatusCode::SUCCESS;
391 auto v = p->end_vertex();
394 hepMC->remove_vertex(std::move(v));
419 if (
msgLvl(MSG::VERBOSE)) HepMC::Print::line(std::cout,part);
427 int id = part->pdg_id();
428 EvtId evtId=EvtPDL::evtIdFromStdHep(
id);
429 double en =(part->momentum()).e()/1000.;
430 double px=(part->momentum()).px()/1000.;
431 double py=(part->momentum()).py()/1000.;
432 double pz=(part->momentum()).pz()/1000.;
433 EvtVector4R evtP(en,px,py,pz);
434 EvtParticle* evtPart = EvtParticleFactory::particleFactory(evtId,evtP);
437 if(
m_setVMtransversePol && (
id==113 ||
id== 443 ||
id==100443 ||
id==553 ||
id==100553 ||
id==200553) )evtPart->setVectorSpinDensity();
440 if (
msgLvl(MSG::VERBOSE)) evtPart->printTree();
441 double ct_s = part->production_vertex()->position().t();
442 double x_s = part->production_vertex()->position().x();
443 double y_s = part->production_vertex()->position().y();
444 double z_s = part->production_vertex()->position().z();
446 EvtVector4R treeStart(ct_s,x_s,y_s,z_s);
449 if(evtPart->getNDaug() !=0) part->set_status(2);
450 evtPart->deleteTree();
456 EvtParticle* evtPart, EvtVector4R treeStart,
double momentumScaleFactor) {
457 if(evtPart->getNDaug()!=0) {
459 double ct=(evtPart->getDaug(0)->get4Pos()).get(0)+treeStart.get(0);
460 double x=(evtPart->getDaug(0)->get4Pos()).get(1)+treeStart.get(1);
461 double y=(evtPart->getDaug(0)->get4Pos()).get(2)+treeStart.get(2);
462 double z=(evtPart->getDaug(0)->get4Pos()).get(3)+treeStart.get(3);
466 hepMC->add_vertex(end_vtx);
467 end_vtx->add_particle_in(std::move(part));
470 for(
uint it=0; it<evtPart->getNDaug(); it++) {
471 double e=(evtPart->getDaug(it)->getP4Lab()).get(0) * momentumScaleFactor;
472 double px=(evtPart->getDaug(it)->getP4Lab()).get(1) * momentumScaleFactor;
473 double py=(evtPart->getDaug(it)->getP4Lab()).get(2) * momentumScaleFactor;
474 double pz=(evtPart->getDaug(it)->getP4Lab()).get(3) * momentumScaleFactor;
475 int id=EvtPDL::getStdHep(evtPart->getDaug(it)->getId());
477 if(evtPart->getDaug(it)->getNDaug() != 0) status=2;
479 end_vtx->add_particle_out(daughter);
480 addEvtGenDecayTree(hepMC, std::move(daughter), evtPart->getDaug(it), treeStart, momentumScaleFactor);
494 int id = p->pdg_id();
496 auto v = p->end_vertex();
497 if (v) nDaughters = v->particles_out_size();
500 if (p->status() == 3)
return false;
506 double m2 = p->momentum().m2();
513 EvtId evtId = EvtPDL::evtIdFromStdHep(
id);
516 if (evtId.getId()>=0)
518 nModes = EvtDecayTable::getInstance()->getNMode(evtId.getAlias());
521 <<
" (status = " << p->status()
522 <<
") -- " << nModes <<
" decay modes found");
540 if (std::abs(itd->pdg_id()) == std::abs(
id))
return false;
563 int id = std::abs(pId);
586 std::vector<HepMC::GenParticlePtr> *muons =
new std::vector<HepMC::GenParticlePtr>;
588 for (
const auto& p: *hepMC) {
589 if( std::abs(p->pdg_id()) == 13 )
593 for (
auto muItr1 = muons->begin(); muItr1 != muons->end(); ++muItr1) {
594 for (
auto muItr2 = muItr1+1; muItr2 != muons->end(); ++muItr2) {
602 double dimuMass =
invMass((*muItr1),(*muItr2));
615 double p1Px = p1->momentum().px();
616 double p1Py = p1->momentum().py();
617 double p1Pz = p1->momentum().pz();
618 double p1E = p1->momentum().e();
619 double p2Px = p2->momentum().px();
620 double p2Py = p2->momentum().py();
621 double p2Pz = p2->momentum().pz();
622 double p2E = p2->momentum().e();
623 double dimuE = p2E + p1E;
624 double dimuPx = p2Px + p1Px;
625 double dimuPy = p2Py + p1Py;
626 double dimuPz = p2Pz + p1Pz;
627 double invMass = std::sqrt(dimuE*dimuE - dimuPx*dimuPx - dimuPy*dimuPy - dimuPz*dimuPz);
639 std::set<HepMC::GenVertexPtr> visited;
640 unsigned int nParticlesFound = 0;
641 unsigned int nTreesFound = 0;
642 for (
auto p: *hepMC) {
643 if ( (!p->production_vertex()) ||
644 (p->production_vertex()->particles_in_size() == 0) ) {
646 std::cout <<
"\n Found new partial decay tree:\n" << std::endl;
647 unsigned int nParticlesVisited =
printTree(std::move(p),visited,1,particleSet);
648 std::cout <<
"\n " << nParticlesVisited <<
" particles in this subtree" << std::endl;
649 nParticlesFound += nParticlesVisited;
652 std::cout <<
"\n Total of " << nParticlesFound <<
" particles found in "
653 << nTreesFound <<
" decay subtrees in HepMC event record\n" << std::endl;
658 unsigned int nParticlesVisited = 1;
659 for (
int i=0; i<level; i++) std::cout <<
" ";
661 auto v = p->end_vertex();
663 if (v->particles_in_size() > 1)
664 std::cout <<
" [interaction: " << v->particles_in_size() <<
" particles, vertex " << v <<
"] --> ";
666 std::cout <<
" --> ";
667 if (visited.insert(v).second) {
671 std::cout << std::endl;
673 if (itp->end_vertex())
674 nParticlesVisited +=
printTree(std::move(itp), visited, level+1, particleSet);
679 std::cout <<
"see above" << std::endl;
681 std::cout <<
" no decay vertex\n" << std::endl;
682 return nParticlesVisited;
686 std::ostringstream buf;
688 if (particleSet)
for (
const auto& pinl: *particleSet)
if (pinl&&p)
if (pinl.get() == p.get()) inlist=
true;
689 if (statusHighlighting) {
690 if ( ((particleSet!=0) && (inlist)) ||
702 if (statusHighlighting) {
718 return CLHEP::RandFlat::shoot(
m_engine);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(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
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
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)
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.