34#include "Pythia8/Event.h"
35#include "Pythia8/ParticleData.h"
41#if PYTHIA_VERSION_INTEGER < 8304
50 bool useEvtGenRandom ) :
62 <<
"Creating generic Pythia generator" << endl;
66 <<
"Creating alias Pythia generator" << endl;
109#if PYTHIA_VERSION_INTEGER < 8310
145 if ( theParticle ==
nullptr ) {
147 <<
"Error in EvtPythiaEngine::doDecay. The mother particle is null. Not doing any Pythia decay."
153 if ( theParticle->
getNDaug() != 0 ) {
154 bool keepChannel(
false );
159 const bool isAlias = particleId.
isAlias();
167 Pythia8::Event& theEvent = thePythiaGenerator.event;
174 int colour( 0 ), anticolour( 0 );
175 double px( 0.0 ), py( 0.0 ), pz( 0.0 );
176 double m0 = theParticle->
mass();
179 theEvent.append( PDGCode, status, colour, anticolour, px, py, pz, E, m0 );
183 bool generatedEvent(
false );
184 for ( iTrial = 0; iTrial < 10; iTrial++ ) {
185 generatedEvent = thePythiaGenerator.next();
186 if ( generatedEvent ) {
191 bool success(
false );
193 if ( generatedEvent ) {
225 std::vector<int> daugList = theEvent.daughterList( startInt );
227 std::vector<int>::iterator daugIter;
228 for ( daugIter = daugList.begin(); daugIter != daugList.end(); ++daugIter ) {
229 int daugInt = *daugIter;
232 Pythia8::Particle& daugParticle = theEvent[daugInt];
234 if ( daugParticle.isQuark() || daugParticle.isGluon() ) {
246 int statusCode = daugParticle.status();
247 if ( statusCode != 1000 ) {
248 int daugPDGInt = daugParticle.id();
250 double px = daugParticle.px();
251 double py = daugParticle.py();
252 double pz = daugParticle.pz();
253 double E = daugParticle.e();
262 daugParticle.status( 1000 );
271 if ( theParent ==
nullptr ) {
273 <<
"Error in EvtPythiaEngine::createDaughterEvtParticles. The parent is null"
283 std::vector<EvtId> daugAliasIdVect( 0 );
289 int aliasInt = particleId.
getAlias();
290 int pythiaAliasInt( aliasInt );
295 pythiaAliasInt = conjPartId.
getAlias();
304 std::vector<int>::iterator modeIter;
305 bool gotMode(
false );
307 for ( modeIter = pythiaModes.begin(); modeIter != pythiaModes.end();
314 int pythiaModeInt = *modeIter;
317 aliasInt, pythiaModeInt );
319 if ( decayModel !=
nullptr ) {
320 int nModeDaug = decayModel->
getNDaug();
323 if ( nDaughters == nModeDaug ) {
325 for ( iModeDaug = 0; iModeDaug < nModeDaug; iModeDaug++ ) {
331 if ( daugPDGId == pythiaPDGId ) {
332 daugAliasIdVect.push_back( daugId );
337 int daugAliasSize = daugAliasIdVect.size();
338 if ( daugAliasSize == nDaughters ) {
344 daugAliasIdVect.clear();
353 if ( gotMode ==
false ) {
357 for ( iPyDaug = 0; iPyDaug < nDaughters; iPyDaug++ ) {
360 daugAliasIdVect.push_back( daugPyId );
370 for ( iDaug = 0; iDaug < nDaughters; iDaug++ ) {
374 if ( theDaughter !=
nullptr ) {
375 EvtId theDaugId = daugAliasIdVect[iDaug];
377 theDaughter->
init( theDaugId, theDaugP4 );
398 for ( iPDL = 0; iPDL < nPDL; iPDL++ ) {
400 int aliasInt = particleId.
getAlias();
428 if ( entry_generic !=
nullptr && this->
validPDGCode( PDGCode ) ) {
429 entry_generic->setM0( mass );
430 entry_generic->setMWidth( width );
431 entry_generic->setTau0( lifetime );
433 if ( std::fabs( width ) > 0.0 ) {
434 entry_generic->setMMin( mmin );
435 entry_generic->setMMax( mmax );
441 if ( entry_alias !=
nullptr && this->
validPDGCode( PDGCode ) ) {
442 entry_alias->setM0( mass );
443 entry_alias->setMWidth( width );
444 entry_alias->setTau0( lifetime );
446 if ( std::fabs( width ) > 0.0 ) {
447 entry_alias->setMMin( mmin );
448 entry_alias->setMMax( mmax );
459 if ( hasPythiaDecays ) {
460 const bool isAlias = particleId.
isAlias();
464 Pythia8::Pythia& thePythiaGenerator =
468 const std::string dataName = thePythiaGenerator.particleData.name(
473 if ( dataName ==
" " && !alreadyStored ) {
502 bool isValid(
true );
504 int absPDGCode =
abs( PDGCode );
506 if ( absPDGCode == 0 || absPDGCode == 18 ) {
509 }
else if ( absPDGCode >= 81 && absPDGCode <= 100 ) {
518 EvtId& particleId,
int aliasInt,
531 bool firstMode(
true );
539 std::vector<int> pythiaModes( 0 );
542 for ( iMode = 0; iMode < nModes; iMode++ ) {
546 if ( decayModel !=
nullptr ) {
557 if ( modelName ==
"PYTHIA" ) {
560 pythiaModes.push_back( iMode );
562 std::ostringstream oss;
563 oss.setf( std::ios::scientific );
570 oss <<
":oneChannel = ";
574 oss <<
":addChannel = ";
581 oss << onMode <<
" ";
592 for ( iDaug = 0; iDaug < nDaug; iDaug++ ) {
595 oss <<
" " << daugPDG;
599 thePythiaGenerator.readString( oss.str() );
605 <<
"Warning in EvtPythiaEngine. Trying to redefine Pythia table for "
607 <<
" for a decay channel that has no daughters."
608 <<
" Keeping Pythia default (if available)." << endl;
613 <<
"Error in EvtPythiaEngine. decayModel is null for particle "
614 <<
EvtPDL::name( particleId ) <<
" mode number " << iMode
623 std::ostringstream rescaleStr;
624 rescaleStr.setf( std::ios::scientific );
625 rescaleStr << PDGCode <<
":rescaleBR = 1.0";
627 thePythiaGenerator.readString( rescaleStr.str() );
632 int tmpModeInt( 0 ), modeInt( 0 );
634 if ( decayModel !=
nullptr ) {
635 int nVars = decayModel->
getNArg();
639 tmpModeInt =
static_cast<int>( decayModel->
getArg( 0 ) );
648 if ( tmpModeInt == 0 ) {
650 }
else if ( tmpModeInt == 1 ) {
652 }
else if ( tmpModeInt == 2 ) {
654 }
else if ( tmpModeInt == 3 ) {
656 }
else if ( tmpModeInt == 4 ) {
658 }
else if ( tmpModeInt == 11 ) {
660 }
else if ( tmpModeInt == 12 ) {
662 }
else if ( tmpModeInt == 13 ) {
664 }
else if ( tmpModeInt == 14 ) {
666 }
else if ( tmpModeInt == 15 ) {
668 }
else if ( tmpModeInt >= 22 && tmpModeInt <= 30 ) {
669 modeInt = tmpModeInt +
671 }
else if ( tmpModeInt == 31 ) {
673 }
else if ( tmpModeInt == 32 ) {
675 }
else if ( tmpModeInt == 33 ) {
677 }
else if ( tmpModeInt == 41 ) {
679 }
else if ( tmpModeInt == 42 ) {
681 }
else if ( tmpModeInt == 43 ) {
683 }
else if ( tmpModeInt == 44 ) {
685 }
else if ( tmpModeInt == 48 ) {
687 }
else if ( tmpModeInt == 50 ) {
689 }
else if ( tmpModeInt == 51 ) {
691 }
else if ( tmpModeInt == 52 || tmpModeInt == 53 ) {
693 }
else if ( tmpModeInt == 84 ) {
695 }
else if ( tmpModeInt == 101 ) {
697 }
else if ( tmpModeInt == 102 ) {
701 <<
"Pythia mode integer " << tmpModeInt
702 <<
" is not recognised. Using phase-space model" << endl;
708 modeInt = tmpModeInt;
715 EvtId& particleId,
int PDGCode )
736 }
else if ( PDGId <= 8 && PDGId > 0 ) {
747 std::ostringstream oss;
748 oss.setf( std::ios::scientific );
749 int absPDGCode =
abs( PDGCode );
750 oss << absPDGCode <<
":new = " << aliasName <<
" " << antiName <<
" "
751 << spin <<
" " << charge <<
" " << colour <<
" " << m0 <<
" " << mWidth
752 <<
" " << mMin <<
" " << mMax <<
" " << tau0;
755 thePythiaGenerator.readString( oss.str() );
775 std::string multiWeakCut(
"ParticleDecays:multIncreaseWeak = 2.0" );
780 std::string multiCut(
"ParticleDecays:multIncrease = 4.5" );
787 GeneratorCommands::iterator it = commands.begin();
789 for ( ; it != commands.end(); it++ ) {
791 std::vector<std::string> commandStrings;
793 if ( command[
"VERSION"] ==
"PYTHIA6" ) {
795 <<
"Converting Pythia 6 command: " << command[
"MODULE"] <<
"("
796 << command[
"PARAM"] <<
")=" << command[
"VALUE"] <<
"..." << endl;
798 }
else if ( command[
"VERSION"] ==
"PYTHIA8" ) {
799 commandStrings.push_back( command[
"MODULE"] +
":" + command[
"PARAM"] +
800 " = " + command[
"VALUE"] );
803 <<
"Pythia command received by EvtPythiaEngine has bad version:"
806 <<
"Received " << command[
"VERSION"]
807 <<
" but expected PYTHIA6 or PYTHIA8." << endl;
809 <<
"The error is likely to be in EvtDecayTable.cpp" << endl;
811 <<
"EvtGen will now abort." << endl;
814 std::string generator = command[
"GENERATOR"];
815 if ( generator ==
"GENERIC" || generator ==
"Generic" ||
816 generator ==
"generic" || generator ==
"BOTH" ||
817 generator ==
"Both" || generator ==
"both" ) {
818 std::vector<std::string>::iterator it2 = commandStrings.begin();
819 for ( ; it2 != commandStrings.end(); it2++ ) {
821 <<
"Configuring generic Pythia generator: " << ( *it2 )
826 if ( generator ==
"ALIAS" || generator ==
"Alias" ||
827 generator ==
"alias" || generator ==
"BOTH" ||
828 generator ==
"Both" || generator ==
"both" ) {
829 std::vector<std::string>::iterator it2 = commandStrings.begin();
830 for ( ; it2 != commandStrings.end(); it2++ ) {
832 <<
"Configuring alias Pythia generator: " << ( *it2 )
double abs(const EvtComplex &c)
std::vector< Command > GeneratorCommands
std::map< std::string, std::string > Command
std::vector< std::string > convertPythia6Command(Command command)
Pythia8::ParticleDataEntry * ParticleDataEntryPtr
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=nullptr)
double getArg(unsigned int j)
std::string getModelName() const
EvtId getDaug(int i) const
double getBranchingFraction() const
static EvtDecayTable & getInstance()
EvtDecayBase * findDecayModel(int aliasInt, int modeInt)
bool hasPythia(int aliasInt) const
int getNModes(int aliasInt) const
const GeneratorCommands & getCommands(std::string extGenerator)
static EvtExtGeneratorCommandsTable * getInstance()
static double getWidth(EvtId i)
static EvtSpinType::spintype getSpinType(EvtId i)
static int getStdHep(EvtId id)
static EvtId getEntry(int i)
static double getMaxMass(EvtId i)
static EvtId evtIdFromStdHep(int stdhep)
static std::string name(EvtId i)
static double getMeanMass(EvtId i)
static EvtId chargeConj(EvtId id)
static double getctau(EvtId i)
static double getMinMass(EvtId i)
virtual void init(EvtId part_n, const EvtVector4R &p4)=0
EvtParticle * getDaug(const int i)
void deleteDaughters(bool keepChannel=false)
void makeDaughters(size_t ndaug, const EvtId *id)
void updatePythiaDecayTable(Pythia8::Pythia &thePythiaGenerator, EvtId &particleId, int aliasInt, int PDGCode)
std::shared_ptr< EvtPythiaRandom > m_evtgenRandom
int getModeInt(EvtDecayBase *decayModel)
EvtPythiaEngine(std::string xmlDir="./xmldoc", bool convertPhysCodes=false, bool useEvtGenRandom=true)
void initialise() override
std::map< int, int > m_addedPDGCodes
std::map< int, std::vector< int > > m_pythiaModeMap
bool validPDGCode(int PDGCode)
void clearPythiaModeMap()
std::unique_ptr< Pythia8::Pythia > m_aliasPythiaGen
void createPythiaParticle(Pythia8::Pythia &thePythiaGenerator, EvtId &particleId, int PDGCode)
void updatePhysicsParameters()
void createDaughterEvtParticles(EvtParticle *theParent)
std::unique_ptr< Pythia8::Pythia > m_genericPythiaGen
bool doDecay(EvtParticle *theMother) override
void clearDaughterVectors()
std::vector< int > m_daugPDGVector
void updateParticleLists()
std::vector< EvtVector4R > m_daugP4Vector
void storeDaughterInfo(Pythia8::Event &theEvent, EvtParticle *theParticle, int startInt)
static int getSpin2(spintype stype)