34 #include "Pythia8/Event.h" 35 #include "Pythia8/ParticleData.h" 43 EvtPythiaEngine::EvtPythiaEngine( std::string xmlDir,
bool convertPhysCodes,
44 bool useEvtGenRandom )
55 <<
"Creating generic Pythia generator" << endl;
56 _genericPythiaGen = std::make_unique<Pythia8::Pythia>( xmlDir );
59 <<
"Creating alias Pythia generator" << endl;
60 _aliasPythiaGen = std::make_unique<Pythia8::Pythia>( xmlDir,
false );
62 _thePythiaGenerator = 0;
63 _daugPDGVector.clear();
64 _daugP4Vector.clear();
66 _convertPhysCodes = convertPhysCodes;
70 _useEvtGenRandom = useEvtGenRandom;
72 _evtgenRandom = std::make_unique<EvtPythiaRandom>();
77 EvtPythiaEngine::~EvtPythiaEngine()
79 _thePythiaGenerator =
nullptr;
80 this->clearDaughterVectors();
81 this->clearPythiaModeMap();
84 void EvtPythiaEngine::clearDaughterVectors()
86 _daugPDGVector.clear();
87 _daugP4Vector.clear();
90 void EvtPythiaEngine::clearPythiaModeMap()
92 PythiaModeMap::iterator
iter;
93 for (
iter = _pythiaModeMap.begin();
iter != _pythiaModeMap.end(); ++
iter ) {
94 std::vector<int> modeVector =
iter->second;
98 _pythiaModeMap.clear();
101 void EvtPythiaEngine::initialise()
103 if ( _initialised ) {
107 this->clearPythiaModeMap();
109 this->updateParticleLists();
113 _genericPythiaGen->readString(
"ProcessLevel:all = off" );
114 _aliasPythiaGen->readString(
"ProcessLevel:all = off" );
117 _genericPythiaGen->readString(
"Print:quiet = on" );
118 _aliasPythiaGen->readString(
"Print:quiet = on" );
121 this->updatePhysicsParameters();
124 if ( _useEvtGenRandom ==
true ) {
125 _genericPythiaGen->setRndmEnginePtr( _evtgenRandom.get() );
126 _aliasPythiaGen->setRndmEnginePtr( _evtgenRandom.get() );
129 _genericPythiaGen->init();
130 _aliasPythiaGen->init();
135 bool EvtPythiaEngine::doDecay(
EvtParticle* theParticle )
152 if ( _initialised ==
false ) {
156 if ( theParticle == 0 ) {
158 <<
"Error in EvtPythiaEngine::doDecay. The mother particle is null. Not doing any Pythia decay." 164 if ( theParticle->
getNDaug() != 0 ) {
165 bool keepChannel(
false );
170 int isAlias = particleId.
isAlias();
173 _thePythiaGenerator = ( isAlias == 1 ? _aliasPythiaGen.get()
174 : _genericPythiaGen.get() );
178 Pythia8::Event& theEvent = _thePythiaGenerator->event;
185 int colour( 0 ), anticolour( 0 );
186 double px( 0.0 ), py( 0.0 ), pz( 0.0 );
187 double m0 = theParticle->
mass();
190 theEvent.append( PDGCode, status, colour, anticolour, px, py, pz, E, m0 );
194 bool generatedEvent(
false );
195 for ( iTrial = 0; iTrial < 10; iTrial++ ) {
196 generatedEvent = _thePythiaGenerator->next();
197 if ( generatedEvent ) {
202 bool success(
false );
204 if ( generatedEvent ) {
212 this->clearDaughterVectors();
217 this->storeDaughterInfo( theParticle, 1 );
222 this->createDaughterEvtParticles( theParticle );
233 void EvtPythiaEngine::storeDaughterInfo(
EvtParticle* theParticle,
int startInt )
235 Pythia8::Event& theEvent = _thePythiaGenerator->event;
237 std::vector<int> daugList = theEvent.daughterList( startInt );
239 std::vector<int>::iterator daugIter;
240 for ( daugIter = daugList.begin(); daugIter != daugList.end(); ++daugIter ) {
241 int daugInt = *daugIter;
244 Pythia8::Particle& daugParticle = theEvent[daugInt];
246 if ( daugParticle.isQuark() || daugParticle.isGluon() ) {
248 this->storeDaughterInfo( theParticle, daugInt );
258 int statusCode = daugParticle.status();
259 if ( statusCode != 1000 ) {
260 int daugPDGInt = daugParticle.id();
262 double px = daugParticle.px();
263 double py = daugParticle.py();
264 double pz = daugParticle.pz();
265 double E = daugParticle.e();
269 _daugPDGVector.push_back( daugPDGInt );
270 _daugP4Vector.push_back( daughterP4 );
274 daugParticle.status( 1000 );
281 void EvtPythiaEngine::createDaughterEvtParticles(
EvtParticle* theParent )
283 if ( theParent == 0 ) {
285 <<
"Error in EvtPythiaEngine::createDaughterEvtParticles. The parent is null" 294 int nDaughters = _daugPDGVector.size();
295 std::vector<EvtId> daugAliasIdVect( 0 );
301 int aliasInt = particleId.
getAlias();
302 int pythiaAliasInt( aliasInt );
307 pythiaAliasInt = conjPartId.
getAlias();
310 std::vector<int> pythiaModes = _pythiaModeMap[pythiaAliasInt];
316 std::vector<int>::iterator modeIter;
317 bool gotMode(
false );
319 for ( modeIter = pythiaModes.begin(); modeIter != pythiaModes.end();
326 int pythiaModeInt = *modeIter;
329 aliasInt, pythiaModeInt );
331 if ( decayModel != 0 ) {
332 int nModeDaug = decayModel->
getNDaug();
335 if ( nDaughters == nModeDaug ) {
337 for ( iModeDaug = 0; iModeDaug < nModeDaug; iModeDaug++ ) {
341 int pythiaPDGId = _daugPDGVector[iModeDaug];
343 if ( daugPDGId == pythiaPDGId ) {
344 daugAliasIdVect.push_back( daugId );
349 int daugAliasSize = daugAliasIdVect.size();
350 if ( daugAliasSize == nDaughters ) {
356 daugAliasIdVect.clear();
365 if ( gotMode ==
false ) {
369 for ( iPyDaug = 0; iPyDaug < nDaughters; iPyDaug++ ) {
370 int daugPDGCode = _daugPDGVector[iPyDaug];
372 daugAliasIdVect.push_back( daugPyId );
382 for ( iDaug = 0; iDaug < nDaughters; iDaug++ ) {
386 if ( theDaughter != 0 ) {
387 EvtId theDaugId = daugAliasIdVect[iDaug];
388 const EvtVector4R theDaugP4 = _daugP4Vector[iDaug];
389 theDaughter->
init( theDaugId, theDaugP4 );
394 void EvtPythiaEngine::updateParticleLists()
408 _addedPDGCodes.clear();
410 for ( iPDL = 0; iPDL < nPDL; iPDL++ ) {
412 int aliasInt = particleId.
getAlias();
433 Pythia8::ParticleDataEntry* entry_generic =
434 _genericPythiaGen->particleData.particleDataEntryPtr( PDGCode );
435 Pythia8::ParticleDataEntry* entry_alias =
436 _aliasPythiaGen->particleData.particleDataEntryPtr( PDGCode );
440 if ( entry_generic != 0 && this->validPDGCode( PDGCode ) ) {
441 entry_generic->setM0( mass );
442 entry_generic->setMWidth( width );
443 entry_generic->setTau0( lifetime );
445 if ( std::fabs( width ) > 0.0 ) {
446 entry_generic->setMMin( mmin );
447 entry_generic->setMMax( mmax );
453 if ( entry_alias != 0 && this->validPDGCode( PDGCode ) ) {
454 entry_alias->setM0( mass );
455 entry_alias->setMWidth( width );
456 entry_alias->setTau0( lifetime );
458 if ( std::fabs( width ) > 0.0 ) {
459 entry_alias->setMMin( mmin );
460 entry_alias->setMMax( mmax );
470 if ( hasPythiaDecays ) {
471 int isAlias = particleId.
isAlias();
475 _thePythiaGenerator = ( isAlias == 1 ? _aliasPythiaGen.get()
476 : _genericPythiaGen.get() );
479 std::string dataName = _thePythiaGenerator->particleData.name(
481 bool alreadyStored = ( _addedPDGCodes.find(
abs( PDGCode ) ) !=
482 _addedPDGCodes.end() );
484 if ( dataName ==
" " && !alreadyStored ) {
487 this->createPythiaParticle( particleId, PDGCode );
492 this->updatePythiaDecayTable( particleId, aliasInt, PDGCode );
505 bool EvtPythiaEngine::validPDGCode(
int PDGCode )
511 bool isValid(
true );
513 int absPDGCode =
abs( PDGCode );
515 if ( absPDGCode == 0 || absPDGCode == 18 ) {
518 }
else if ( absPDGCode >= 81 && absPDGCode <= 100 ) {
526 void EvtPythiaEngine::updatePythiaDecayTable(
EvtId& particleId,
int aliasInt,
539 bool firstMode(
true );
547 std::vector<int> pythiaModes( 0 );
550 for ( iMode = 0; iMode < nModes; iMode++ ) {
554 if ( decayModel != 0 ) {
565 if ( modelName ==
"PYTHIA" ) {
568 pythiaModes.push_back( iMode );
570 std::ostringstream oss;
571 oss.setf( std::ios::scientific );
578 oss <<
":oneChannel = ";
582 oss <<
":addChannel = ";
589 oss << onMode <<
" ";
596 int modeInt = this->getModeInt( decayModel );
600 for ( iDaug = 0; iDaug < nDaug; iDaug++ ) {
603 oss <<
" " << daugPDG;
607 _thePythiaGenerator->readString( oss.str() );
613 <<
"Warning in EvtPythiaEngine. Trying to redefine Pythia table for " 615 <<
" for a decay channel that has no daughters." 616 <<
" Keeping Pythia default (if available)." << endl;
621 <<
"Error in EvtPythiaEngine. decayModel is null for particle " 622 <<
EvtPDL::name( particleId ) <<
" mode number " << iMode
628 _pythiaModeMap[aliasInt] = pythiaModes;
631 std::ostringstream rescaleStr;
632 rescaleStr.setf( std::ios::scientific );
633 rescaleStr << PDGCode <<
":rescaleBR = 1.0";
635 _thePythiaGenerator->readString( rescaleStr.str() );
638 int EvtPythiaEngine::getModeInt(
EvtDecayBase* decayModel )
640 int tmpModeInt( 0 ), modeInt( 0 );
642 if ( decayModel != 0 ) {
643 int nVars = decayModel->
getNArg();
647 tmpModeInt = static_cast<int>( decayModel->
getArg( 0 ) );
651 if ( _convertPhysCodes ) {
656 if ( tmpModeInt == 0 ) {
658 }
else if ( tmpModeInt == 1 ) {
660 }
else if ( tmpModeInt == 2 ) {
662 }
else if ( tmpModeInt == 3 ) {
664 }
else if ( tmpModeInt == 4 ) {
666 }
else if ( tmpModeInt == 11 ) {
668 }
else if ( tmpModeInt == 12 ) {
670 }
else if ( tmpModeInt == 13 ) {
672 }
else if ( tmpModeInt == 14 ) {
674 }
else if ( tmpModeInt == 15 ) {
676 }
else if ( tmpModeInt >= 22 && tmpModeInt <= 30 ) {
677 modeInt = tmpModeInt +
679 }
else if ( tmpModeInt == 31 ) {
681 }
else if ( tmpModeInt == 32 ) {
683 }
else if ( tmpModeInt == 33 ) {
685 }
else if ( tmpModeInt == 41 ) {
687 }
else if ( tmpModeInt == 42 ) {
689 }
else if ( tmpModeInt == 43 ) {
691 }
else if ( tmpModeInt == 44 ) {
693 }
else if ( tmpModeInt == 48 ) {
695 }
else if ( tmpModeInt == 50 ) {
697 }
else if ( tmpModeInt == 51 ) {
699 }
else if ( tmpModeInt == 52 || tmpModeInt == 53 ) {
701 }
else if ( tmpModeInt == 84 ) {
703 }
else if ( tmpModeInt == 101 ) {
705 }
else if ( tmpModeInt == 102 ) {
709 <<
"Pythia mode integer " << tmpModeInt
710 <<
" is not recognised. Using phase-space model" << endl;
716 modeInt = tmpModeInt;
722 void EvtPythiaEngine::createPythiaParticle(
EvtId& particleId,
int PDGCode )
743 }
else if ( PDGId <= 8 && PDGId > 0 ) {
754 std::ostringstream oss;
755 oss.setf( std::ios::scientific );
756 int absPDGCode =
abs( PDGCode );
757 oss << absPDGCode <<
":new = " << aliasName <<
" " << antiName <<
" " 758 << spin <<
" " << charge <<
" " << colour <<
" " << m0 <<
" " << mWidth
759 <<
" " << mMin <<
" " << mMax <<
" " << tau0;
762 _thePythiaGenerator->readString( oss.str() );
769 _addedPDGCodes[absPDGCode] = 1;
772 void EvtPythiaEngine::updatePhysicsParameters()
782 std::string multiWeakCut(
"ParticleDecays:multIncreaseWeak = 2.0" );
783 _genericPythiaGen->readString( multiWeakCut );
784 _aliasPythiaGen->readString( multiWeakCut );
787 std::string multiCut(
"ParticleDecays:multIncrease = 4.5" );
788 _genericPythiaGen->readString( multiCut );
789 _aliasPythiaGen->readString( multiCut );
794 GeneratorCommands::iterator it = commands.begin();
796 for ( ; it != commands.end(); it++ ) {
798 std::vector<std::string> commandStrings;
800 if ( command[
"VERSION"] ==
"PYTHIA6" ) {
802 <<
"Converting Pythia 6 command: " << command[
"MODULE"] <<
"(" 803 << command[
"PARAM"] <<
")=" << command[
"VALUE"] <<
"..." << endl;
805 }
else if ( command[
"VERSION"] ==
"PYTHIA8" ) {
806 commandStrings.push_back( command[
"MODULE"] +
":" + command[
"PARAM"] +
807 " = " + command[
"VALUE"] );
810 <<
"Pythia command received by EvtPythiaEngine has bad version:" 813 <<
"Received " << command[
"VERSION"]
814 <<
" but expected PYTHIA6 or PYTHIA8." << endl;
816 <<
"The error is likely to be in EvtDecayTable.cpp" << endl;
818 <<
"EvtGen will now abort." << endl;
821 std::string generator = command[
"GENERATOR"];
822 if ( generator ==
"GENERIC" || generator ==
"Generic" ||
823 generator ==
"generic" || generator ==
"BOTH" ||
824 generator ==
"Both" || generator ==
"both" ) {
825 std::vector<std::string>::iterator it2 = commandStrings.begin();
826 for ( ; it2 != commandStrings.end(); it2++ ) {
828 <<
"Configuring generic Pythia generator: " << ( *it2 )
830 _genericPythiaGen->readString( *it2 );
833 if ( generator ==
"ALIAS" || generator ==
"Alias" ||
834 generator ==
"alias" || generator ==
"BOTH" ||
835 generator ==
"Both" || generator ==
"both" ) {
836 std::vector<std::string>::iterator it2 = commandStrings.begin();
837 for ( ; it2 != commandStrings.end(); it2++ ) {
839 <<
"Configuring alias Pythia generator: " << ( *it2 )
841 _aliasPythiaGen->readString( *it2 );
static EvtExtGeneratorCommandsTable * getInstance()
static std::string name(EvtId i)
static EvtDecayTable * getInstance()
static EvtId getEntry(int i)
double getArg(unsigned int j)
static EvtSpinType::spintype getSpinType(EvtId i)
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=0)
virtual void init(EvtId part_n, const EvtVector4R &p4)=0
const GeneratorCommands & getCommands(std::string extGenerator)
static double getctau(EvtId i)
static double getMeanMass(EvtId i)
void makeDaughters(unsigned int ndaug, EvtId *id)
std::vector< std::string > convertPythia6Command(Command command)
std::vector< Command > GeneratorCommands
double getBranchingFraction() const
int getNModes(int aliasInt)
void deleteDaughters(bool keepChannel=false)
static double getMinMass(EvtId i)
EvtDecayBase * findDecayModel(int aliasInt, int modeInt)
std::map< std::string, std::string > Command
double abs(const EvtComplex &c)
static EvtId evtIdFromStdHep(int stdhep)
static int getSpin2(spintype stype)
std::string getModelName() const
static double getWidth(EvtId i)
EvtParticle * getDaug(int i)
static EvtId chargeConj(EvtId id)
static int getStdHep(EvtId id)
bool hasPythia(int aliasInt)
static double getMaxMass(EvtId i)
EvtId getDaug(int i) const