evtgen is hosted by Hepforge, IPPP Durham
EvtGen  2.0.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
EvtPythiaEngine.cpp
Go to the documentation of this file.
1 
2 /***********************************************************************
3 * Copyright 1998-2020 CERN for the benefit of the EvtGen authors *
4 * *
5 * This file is part of EvtGen. *
6 * *
7 * EvtGen is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * EvtGen is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with EvtGen. If not, see <https://www.gnu.org/licenses/>. *
19 ***********************************************************************/
20 
21 #ifdef EVTGEN_PYTHIA
22 
24 
27 #include "EvtGenBase/EvtPDL.hh"
29 #include "EvtGenBase/EvtReport.hh"
31 
33 
34 #include "Pythia8/Event.h"
35 #include "Pythia8/ParticleData.h"
36 
37 #include <cmath>
38 #include <iostream>
39 #include <sstream>
40 
41 using std::endl;
42 
43 EvtPythiaEngine::EvtPythiaEngine( std::string xmlDir, bool convertPhysCodes,
44  bool useEvtGenRandom )
45 {
46  // Create two Pythia generators. One will be for generic
47  // Pythia decays in the decay.dec file. The other one will be to
48  // only decay aliased particles, which are in general "signal"
49  // decays different from those in the decay.dec file.
50  // Even though it is not possible to have two different particle
51  // versions in one Pythia generator, we can use two generators to
52  // get the required behaviour.
53 
54  EvtGenReport( EVTGEN_INFO, "EvtGen" )
55  << "Creating generic Pythia generator" << endl;
56  _genericPythiaGen = std::make_unique<Pythia8::Pythia>( xmlDir );
57 
58  EvtGenReport( EVTGEN_INFO, "EvtGen" )
59  << "Creating alias Pythia generator" << endl;
60  _aliasPythiaGen = std::make_unique<Pythia8::Pythia>( xmlDir, false );
61 
62  _thePythiaGenerator = 0;
63  _daugPDGVector.clear();
64  _daugP4Vector.clear();
65 
66  _convertPhysCodes = convertPhysCodes;
67 
68  // Specify if we are going to use the random number generator (engine)
69  // from EvtGen for Pythia 8.
70  _useEvtGenRandom = useEvtGenRandom;
71 
72  _evtgenRandom = std::make_unique<EvtPythiaRandom>();
73 
74  _initialised = false;
75 }
76 
77 EvtPythiaEngine::~EvtPythiaEngine()
78 {
79  _thePythiaGenerator = nullptr;
80  this->clearDaughterVectors();
81  this->clearPythiaModeMap();
82 }
83 
84 void EvtPythiaEngine::clearDaughterVectors()
85 {
86  _daugPDGVector.clear();
87  _daugP4Vector.clear();
88 }
89 
90 void EvtPythiaEngine::clearPythiaModeMap()
91 {
92  PythiaModeMap::iterator iter;
93  for ( iter = _pythiaModeMap.begin(); iter != _pythiaModeMap.end(); ++iter ) {
94  std::vector<int> modeVector = iter->second;
95  modeVector.clear();
96  }
97 
98  _pythiaModeMap.clear();
99 }
100 
101 void EvtPythiaEngine::initialise()
102 {
103  if ( _initialised ) {
104  return;
105  }
106 
107  this->clearPythiaModeMap();
108 
109  this->updateParticleLists();
110 
111  // Hadron-level processes only (hadronized, string fragmentation and secondary decays).
112  // We do not want to generate the full pp or e+e- event structure etc..
113  _genericPythiaGen->readString( "ProcessLevel:all = off" );
114  _aliasPythiaGen->readString( "ProcessLevel:all = off" );
115 
116  // Turn off Pythia warnings, e.g. changes to particle properties
117  _genericPythiaGen->readString( "Print:quiet = on" );
118  _aliasPythiaGen->readString( "Print:quiet = on" );
119 
120  // Apply any other physics (or special particle) requirements/cuts etc..
121  this->updatePhysicsParameters();
122 
123  // Set the random number generator
124  if ( _useEvtGenRandom == true ) {
125  _genericPythiaGen->setRndmEnginePtr( _evtgenRandom.get() );
126  _aliasPythiaGen->setRndmEnginePtr( _evtgenRandom.get() );
127  }
128 
129  _genericPythiaGen->init();
130  _aliasPythiaGen->init();
131 
132  _initialised = true;
133 }
134 
135 bool EvtPythiaEngine::doDecay( EvtParticle* theParticle )
136 {
137  // Store the mother particle within a Pythia8 Event object.
138  // Then do the hadron level decays.
139  // The EvtParticle must be a colour singlet (meson/baryon/lepton), i.e. not a gluon or quark
140 
141  // We delete any daughters the particle may have, since we are asking Pythia
142  // to generate the decay anew. Also note that _any_ Pythia decay allowed for the particle
143  // will be generated and not the specific Pythia decay mode that EvtGen has already
144  // specified. This is necessary since we only want to initialise the Pythia decay table
145  // once; all Pythia branching fractions for a given mother particle are renormalised to sum to 1.0.
146  // In EvtGen decay.dec files, it may be the case that Pythia decays are only used
147  // for some of the particle decays (i.e. Pythia BF sum < 1.0). As we loop over many events,
148  // the total frequency for each Pythia decay mode will normalise correctly to what
149  // we wanted via the specifications made to the decay.dec file, even though event-by-event
150  // the EvtGen decay channel and the Pythia decay channel may be different.
151 
152  if ( _initialised == false ) {
153  this->initialise();
154  }
155 
156  if ( theParticle == 0 ) {
157  EvtGenReport( EVTGEN_INFO, "EvtGen" )
158  << "Error in EvtPythiaEngine::doDecay. The mother particle is null. Not doing any Pythia decay."
159  << endl;
160  return false;
161  }
162 
163  // Delete EvtParticle daughters if they already exist
164  if ( theParticle->getNDaug() != 0 ) {
165  bool keepChannel( false );
166  theParticle->deleteDaughters( keepChannel );
167  }
168 
169  EvtId particleId = theParticle->getId();
170  int isAlias = particleId.isAlias();
171 
172  // Choose the generator depending if we have an aliased (parent) particle or not
173  _thePythiaGenerator = ( isAlias == 1 ? _aliasPythiaGen.get()
174  : _genericPythiaGen.get() );
175 
176  // Need to use the reference to the Pythia8::Event object,
177  // otherwise it will just return a new empty, default event object.
178  Pythia8::Event& theEvent = _thePythiaGenerator->event;
179  theEvent.reset();
180 
181  // Initialise the event to be the particle rest frame
182  int PDGCode = EvtPDL::getStdHep( particleId );
183 
184  int status( 1 );
185  int colour( 0 ), anticolour( 0 );
186  double px( 0.0 ), py( 0.0 ), pz( 0.0 );
187  double m0 = theParticle->mass();
188  double E = m0;
189 
190  theEvent.append( PDGCode, status, colour, anticolour, px, py, pz, E, m0 );
191 
192  // Generate the Pythia event
193  int iTrial( 0 );
194  bool generatedEvent( false );
195  for ( iTrial = 0; iTrial < 10; iTrial++ ) {
196  generatedEvent = _thePythiaGenerator->next();
197  if ( generatedEvent ) {
198  break;
199  }
200  }
201 
202  bool success( false );
203 
204  if ( generatedEvent ) {
205  // Store the daughters for this particle from the Pythia decay tree.
206  // This is a recursive function that will continue looping through
207  // all available daughters until the first set of non-quark and non-gluon
208  // particles are encountered in the Pythia Event structure.
209 
210  // First, clear up the internal vectors storing the daughter
211  // EvtId types and 4-momenta.
212  this->clearDaughterVectors();
213 
214  // Now store the daughter info. Since this is a recursive function
215  // to loop through the full Pythia decay tree, we do not want to create
216  // EvtParticles here but in the next step.
217  this->storeDaughterInfo( theParticle, 1 );
218 
219  // Now create the EvtParticle daughters of the (parent) particle.
220  // We need to use the EvtParticle::makeDaughters function
221  // owing to the way EvtParticle stores parent-daughter information.
222  this->createDaughterEvtParticles( theParticle );
223 
224  //theParticle->printTree();
225  //theEvent.list(true, true);
226 
227  success = true;
228  }
229 
230  return success;
231 }
232 
233 void EvtPythiaEngine::storeDaughterInfo( EvtParticle* theParticle, int startInt )
234 {
235  Pythia8::Event& theEvent = _thePythiaGenerator->event;
236 
237  std::vector<int> daugList = theEvent.daughterList( startInt );
238 
239  std::vector<int>::iterator daugIter;
240  for ( daugIter = daugList.begin(); daugIter != daugList.end(); ++daugIter ) {
241  int daugInt = *daugIter;
242 
243  // Ask if the daughter is a quark or gluon. If so, recursively search again.
244  Pythia8::Particle& daugParticle = theEvent[daugInt];
245 
246  if ( daugParticle.isQuark() || daugParticle.isGluon() ) {
247  // Recursively search for correct daughter type
248  this->storeDaughterInfo( theParticle, daugInt );
249 
250  } else {
251  // We have a daughter that is not a quark nor gluon particle.
252  // Make sure we are not double counting particles, since several quarks
253  // and gluons make one particle.
254  // Set the status flag for any "new" particle to say that we have stored it.
255  // Use status flag = 1000 (within the user allowed range for Pythia codes).
256 
257  // Check that the status flag for the particle is not equal to 1000
258  int statusCode = daugParticle.status();
259  if ( statusCode != 1000 ) {
260  int daugPDGInt = daugParticle.id();
261 
262  double px = daugParticle.px();
263  double py = daugParticle.py();
264  double pz = daugParticle.pz();
265  double E = daugParticle.e();
266  EvtVector4R daughterP4( E, px, py, pz );
267 
268  // Now store the EvtId and 4-momentum in the internal vectors
269  _daugPDGVector.push_back( daugPDGInt );
270  _daugP4Vector.push_back( daughterP4 );
271 
272  // Set the status flag for the Pythia particle to let us know
273  // that we have already considered it to avoid double counting.
274  daugParticle.status( 1000 );
275 
276  } // Status code != 1000
277  }
278  }
279 }
280 
281 void EvtPythiaEngine::createDaughterEvtParticles( EvtParticle* theParent )
282 {
283  if ( theParent == 0 ) {
284  EvtGenReport( EVTGEN_INFO, "EvtGen" )
285  << "Error in EvtPythiaEngine::createDaughterEvtParticles. The parent is null"
286  << endl;
287  return;
288  }
289 
290  // Get the list of Pythia decay modes defined for this particle id alias.
291  // It would be easier to just use the decay channel number that Pythia chose to use
292  // for the particle decay, but this is not accessible from the Pythia interface at present.
293 
294  int nDaughters = _daugPDGVector.size();
295  std::vector<EvtId> daugAliasIdVect( 0 );
296 
297  EvtId particleId = theParent->getId();
298  // Check to see if we have an anti-particle. If we do, charge conjugate the particle id to get the
299  // Pythia "alias" we can compare with the defined (particle) Pythia modes.
300  int PDGId = EvtPDL::getStdHep( particleId );
301  int aliasInt = particleId.getAlias();
302  int pythiaAliasInt( aliasInt );
303 
304  if ( PDGId < 0 ) {
305  // We have an anti-particle.
306  EvtId conjPartId = EvtPDL::chargeConj( particleId );
307  pythiaAliasInt = conjPartId.getAlias();
308  }
309 
310  std::vector<int> pythiaModes = _pythiaModeMap[pythiaAliasInt];
311 
312  // Loop over all available Pythia decay modes and find the channel that matches
313  // the daughter ids. Set each daughter id to also use the alias integer.
314  // This will then convert the Pythia generated channel to the EvtGen alias defined one.
315 
316  std::vector<int>::iterator modeIter;
317  bool gotMode( false );
318 
319  for ( modeIter = pythiaModes.begin(); modeIter != pythiaModes.end();
320  ++modeIter ) {
321  // Stop the loop if we have the right decay mode channel
322  if ( gotMode ) {
323  break;
324  }
325 
326  int pythiaModeInt = *modeIter;
327 
329  aliasInt, pythiaModeInt );
330 
331  if ( decayModel != 0 ) {
332  int nModeDaug = decayModel->getNDaug();
333 
334  // We need to make sure that the number of daughters match
335  if ( nDaughters == nModeDaug ) {
336  int iModeDaug( 0 );
337  for ( iModeDaug = 0; iModeDaug < nModeDaug; iModeDaug++ ) {
338  EvtId daugId = decayModel->getDaug( iModeDaug );
339  int daugPDGId = EvtPDL::getStdHep( daugId );
340  // Pythia has used the right PDG codes for this decay mode, even for conjugate modes
341  int pythiaPDGId = _daugPDGVector[iModeDaug];
342 
343  if ( daugPDGId == pythiaPDGId ) {
344  daugAliasIdVect.push_back( daugId );
345  }
346 
347  } // Loop over EvtGen mode daughters
348 
349  int daugAliasSize = daugAliasIdVect.size();
350  if ( daugAliasSize == nDaughters ) {
351  // All daughter Id codes are accounted for. Set the flag to stop the loop.
352  gotMode = true;
353  } else {
354  // We do not have the correct daughter ordering. Clear the id vector
355  // and try another mode.
356  daugAliasIdVect.clear();
357  }
358 
359  } // Same number of daughters
360 
361  } // decayModel != 0
362 
363  } // Loop over available Pythia modes
364 
365  if ( gotMode == false ) {
366  // We did not find a match for the daughter aliases. Just use the normal PDG codes
367  // from the Pythia decay result
368  int iPyDaug( 0 );
369  for ( iPyDaug = 0; iPyDaug < nDaughters; iPyDaug++ ) {
370  int daugPDGCode = _daugPDGVector[iPyDaug];
371  EvtId daugPyId = EvtPDL::evtIdFromStdHep( daugPDGCode );
372  daugAliasIdVect.push_back( daugPyId );
373  }
374  }
375 
376  // Make the EvtParticle daughters (with correct alias id's). Their 4-momenta are uninitialised.
377  theParent->makeDaughters( nDaughters, daugAliasIdVect );
378 
379  // Now set the 4-momenta of the daughters.
380  int iDaug( 0 );
381  // Can use an iterator here, but we already had to use the vector size...
382  for ( iDaug = 0; iDaug < nDaughters; iDaug++ ) {
383  EvtParticle* theDaughter = theParent->getDaug( iDaug );
384 
385  // Set the correct 4-momentum for each daughter particle.
386  if ( theDaughter != 0 ) {
387  EvtId theDaugId = daugAliasIdVect[iDaug];
388  const EvtVector4R theDaugP4 = _daugP4Vector[iDaug];
389  theDaughter->init( theDaugId, theDaugP4 );
390  }
391  }
392 }
393 
394 void EvtPythiaEngine::updateParticleLists()
395 {
396  // Use the EvtGen decay table (decay/user.dec) to update Pythia particle
397  // decay modes. Also, make sure the generic and alias Pythia generators
398  // use the same particle data entries as defined by EvtGen (evt.pdl).
399 
400  // Loop over all entries in the EvtPDL particle data table.
401  // Aliases are added at the end with id numbers equal to the
402  // original particle, but with alias integer = lastPDLEntry+1 etc..
403  int iPDL;
404  int nPDL = EvtPDL::entries();
405 
406  // Reset the _addedPDGCodes map that keeps track
407  // of any new particles added to the Pythia input data stream
408  _addedPDGCodes.clear();
409 
410  for ( iPDL = 0; iPDL < nPDL; iPDL++ ) {
411  EvtId particleId = EvtPDL::getEntry( iPDL );
412  int aliasInt = particleId.getAlias();
413 
414  // Pythia and EvtGen should use the same PDG codes for particles
415  int PDGCode = EvtPDL::getStdHep( particleId );
416 
417  // Update pole mass, width, lifetime and mass range
418  double mass = EvtPDL::getMeanMass( particleId );
419  double width = EvtPDL::getWidth( particleId );
420  double lifetime = EvtPDL::getctau( particleId );
421  double mmin = EvtPDL::getMinMass( particleId );
422  double mmax = EvtPDL::getMaxMass( particleId );
423 
424  // Particle data pointers. The generic and alias Pythia generator pointers have
425  // their own Pythia8::ParticleData particleData public data members which contain
426  // the particle properties table. We can extract and change individual particle
427  // entries using the particleDataEntryPtr() function within ParticleData.
428  // However, we must be careful when accessing the particleData table. We must do
429  // this directly, since assigning it to another Pythia8::ParticleData object via copying
430  // or assignment will give it a different memory address and it will no longer refer to
431  // the original particleData information from the generator pointer.
432 
433  Pythia8::ParticleDataEntry* entry_generic =
434  _genericPythiaGen->particleData.particleDataEntryPtr( PDGCode );
435  Pythia8::ParticleDataEntry* entry_alias =
436  _aliasPythiaGen->particleData.particleDataEntryPtr( PDGCode );
437 
438  // Check that the PDG code is not zero/null and exclude other
439  // special cases, e.g. those reserved for internal generator use
440  if ( entry_generic != 0 && this->validPDGCode( PDGCode ) ) {
441  entry_generic->setM0( mass );
442  entry_generic->setMWidth( width );
443  entry_generic->setTau0( lifetime );
444 
445  if ( std::fabs( width ) > 0.0 ) {
446  entry_generic->setMMin( mmin );
447  entry_generic->setMMax( mmax );
448  }
449  }
450 
451  // Check that the PDG code is not zero/null and exclude other
452  // special cases, e.g. those reserved for internal generator use
453  if ( entry_alias != 0 && this->validPDGCode( PDGCode ) ) {
454  entry_alias->setM0( mass );
455  entry_alias->setMWidth( width );
456  entry_alias->setTau0( lifetime );
457 
458  if ( std::fabs( width ) > 0.0 ) {
459  entry_alias->setMMin( mmin );
460  entry_alias->setMMax( mmax );
461  }
462  }
463 
464  // Check which particles have a Pythia decay defined.
465  // Get the list of all possible decays for the particle, using the alias integer.
466  // If the particle is not actually an alias, aliasInt = idInt.
467 
468  bool hasPythiaDecays = EvtDecayTable::getInstance()->hasPythia( aliasInt );
469 
470  if ( hasPythiaDecays ) {
471  int isAlias = particleId.isAlias();
472 
473  // Decide what generator to use depending on whether we have
474  // an aliased particle or not
475  _thePythiaGenerator = ( isAlias == 1 ? _aliasPythiaGen.get()
476  : _genericPythiaGen.get() );
477 
478  // Find the Pythia particle name given the standard PDG code integer
479  std::string dataName = _thePythiaGenerator->particleData.name(
480  PDGCode );
481  bool alreadyStored = ( _addedPDGCodes.find( abs( PDGCode ) ) !=
482  _addedPDGCodes.end() );
483 
484  if ( dataName == " " && !alreadyStored ) {
485  // Particle and its antiparticle do not exist in the Pythia database.
486  // Create a new particle, then create the new decay modes.
487  this->createPythiaParticle( particleId, PDGCode );
488  }
489 
490  // For the particle, create the Pythia decay modes.
491  // Update Pythia data tables.
492  this->updatePythiaDecayTable( particleId, aliasInt, PDGCode );
493 
494  } // Loop over Pythia decays
495 
496  } // Loop over EvtPDL entries
497 
498  //EvtGenReport(EVTGEN_INFO,"EvtGen")<<"Writing out changed generic Pythia decay list"<<endl;
499  //_genericPythiaGen->particleData.listChanged();
500 
501  //EvtGenReport(EVTGEN_INFO,"EvtGen")<<"Writing out changed alias Pythia decay list"<<endl;
502  //_aliasPythiaGen->particleData.listChanged();
503 }
504 
505 bool EvtPythiaEngine::validPDGCode( int PDGCode )
506 {
507  // Exclude certain PDG codes: void = 0 and special values = 81 to 100, which are reserved
508  // for internal generator use (pseudoparticles) according to PDG guidelines. Also exclude
509  // nu'_tau (nu_L) = 18, which has different masses: Pythia8 = 400 GeV, EvtGen = 0 GeV.
510 
511  bool isValid( true );
512 
513  int absPDGCode = abs( PDGCode );
514 
515  if ( absPDGCode == 0 || absPDGCode == 18 ) {
516  // Void and nu_L or nu'_tau
517  isValid = false;
518  } else if ( absPDGCode >= 81 && absPDGCode <= 100 ) {
519  // Pseudoparticles
520  isValid = false;
521  }
522 
523  return isValid;
524 }
525 
526 void EvtPythiaEngine::updatePythiaDecayTable( EvtId& particleId, int aliasInt,
527  int PDGCode )
528 {
529  // Update the particle data table in Pythia.
530  // The tables store information about the allowed decay modes
531  // where the PDGId for all particles must be positive; anti-particles are stored
532  // with the corresponding particle entry.
533  // Since we do not want to implement CP violation here, just use the same branching
534  // fractions for particle and anti-particle modes.
535 
536  int nModes = EvtDecayTable::getInstance()->getNModes( aliasInt );
537  int iMode( 0 );
538 
539  bool firstMode( true );
540 
541  // Only process positive PDG codes.
542  if ( PDGCode < 0 ) {
543  return;
544  }
545 
546  // Keep track of which decay modes are Pythia decays for each aliasInt
547  std::vector<int> pythiaModes( 0 );
548 
549  // Loop over the decay modes for this particle
550  for ( iMode = 0; iMode < nModes; iMode++ ) {
551  EvtDecayBase* decayModel =
552  EvtDecayTable::getInstance()->findDecayModel( aliasInt, iMode );
553 
554  if ( decayModel != 0 ) {
555  int nDaug = decayModel->getNDaug();
556 
557  // If the decay mode has no daughters, then that means that there will be
558  // no entries for any submode re-definitions for Pythia.
559  // This sometimes occurs for any mode using non-standard Pythia 6 codes.
560  // Do not refine the decay mode, i.e. accept the Pythia 8 default (if it exists).
561  if ( nDaug > 0 ) {
562  // Check to see if we have a Pythia decay mode
563  std::string modelName = decayModel->getModelName();
564 
565  if ( modelName == "PYTHIA" ) {
566  // Keep track which decay mode is a Pythia one. We need this in order to
567  // reassign alias Id values for particles generated in the decay.
568  pythiaModes.push_back( iMode );
569 
570  std::ostringstream oss;
571  oss.setf( std::ios::scientific );
572  // Write out the absolute value of the PDG code, since
573  // particles and anti-particles occupy the same part of the Pythia table.
574  oss << PDGCode;
575 
576  if ( firstMode ) {
577  // Create a new channel
578  oss << ":oneChannel = ";
579  firstMode = false;
580  } else {
581  // Add the channel
582  oss << ":addChannel = ";
583  }
584 
585  // Select all channels (particle and anti-particle).
586  // For CP violation, or different BFs for particle and anti-particle,
587  // use options 2 or 3 (not here).
588  int onMode( 1 );
589  oss << onMode << " ";
590 
591  double BF = decayModel->getBranchingFraction();
592  oss << BF << " ";
593 
594  // Need to convert the old Pythia physics mode integers with the new ones
595  // To do this, get the model argument and write a conversion method.
596  int modeInt = this->getModeInt( decayModel );
597  oss << modeInt;
598 
599  int iDaug( 0 );
600  for ( iDaug = 0; iDaug < nDaug; iDaug++ ) {
601  EvtId daugId = decayModel->getDaug( iDaug );
602  int daugPDG = EvtPDL::getStdHep( daugId );
603  oss << " " << daugPDG;
604 
605  } // Daughter list
606 
607  _thePythiaGenerator->readString( oss.str() );
608 
609  } // is Pythia
610 
611  } else {
612  EvtGenReport( EVTGEN_INFO, "EvtGen" )
613  << "Warning in EvtPythiaEngine. Trying to redefine Pythia table for "
614  << EvtPDL::name( particleId )
615  << " for a decay channel that has no daughters."
616  << " Keeping Pythia default (if available)." << endl;
617  }
618 
619  } else {
620  EvtGenReport( EVTGEN_INFO, "EvtGen" )
621  << "Error in EvtPythiaEngine. decayModel is null for particle "
622  << EvtPDL::name( particleId ) << " mode number " << iMode
623  << endl;
624  }
625 
626  } // Loop over modes
627 
628  _pythiaModeMap[aliasInt] = pythiaModes;
629 
630  // Now, renormalise the decay branching fractions to sum to 1.0
631  std::ostringstream rescaleStr;
632  rescaleStr.setf( std::ios::scientific );
633  rescaleStr << PDGCode << ":rescaleBR = 1.0";
634 
635  _thePythiaGenerator->readString( rescaleStr.str() );
636 }
637 
638 int EvtPythiaEngine::getModeInt( EvtDecayBase* decayModel )
639 {
640  int tmpModeInt( 0 ), modeInt( 0 );
641 
642  if ( decayModel != 0 ) {
643  int nVars = decayModel->getNArg();
644  // Just read the first integer, which specifies the Pythia decay model.
645  // Ignore any other values.
646  if ( nVars > 0 ) {
647  tmpModeInt = static_cast<int>( decayModel->getArg( 0 ) );
648  }
649  }
650 
651  if ( _convertPhysCodes ) {
652  // Extra code to convert the old Pythia decay model integer MDME(ICC,2) to the new one.
653  // This should be removed eventually after updating decay.dec files to use
654  // the new convention.
655 
656  if ( tmpModeInt == 0 ) {
657  modeInt = 0; // phase-space
658  } else if ( tmpModeInt == 1 ) {
659  modeInt = 1; // omega or phi -> 3pi
660  } else if ( tmpModeInt == 2 ) {
661  modeInt = 11; // Dalitz decay
662  } else if ( tmpModeInt == 3 ) {
663  modeInt = 2; // V -> PS PS
664  } else if ( tmpModeInt == 4 ) {
665  modeInt = 92; // onium -> ggg or gg gamma
666  } else if ( tmpModeInt == 11 ) {
667  modeInt = 42; // phase-space of hadrons from available quarks
668  } else if ( tmpModeInt == 12 ) {
669  modeInt = 42; // phase-space for onia resonances
670  } else if ( tmpModeInt == 13 ) {
671  modeInt = 43; // phase-space of at least 3 hadrons
672  } else if ( tmpModeInt == 14 ) {
673  modeInt = 44; // phase-space of at least 4 hadrons
674  } else if ( tmpModeInt == 15 ) {
675  modeInt = 45; // phase-space of at least 5 hadrons
676  } else if ( tmpModeInt >= 22 && tmpModeInt <= 30 ) {
677  modeInt = tmpModeInt +
678  40; // phase space of hadrons with fixed multiplicity (modeInt - 60)
679  } else if ( tmpModeInt == 31 ) {
680  modeInt = 42; // two or more quarks phase-space; one spectactor quark
681  } else if ( tmpModeInt == 32 ) {
682  modeInt = 91; // qqbar or gg pair
683  } else if ( tmpModeInt == 33 ) {
684  modeInt = 0; // triplet q X qbar, where X = gluon or colour singlet (superfluous, since g's are created anyway)
685  } else if ( tmpModeInt == 41 ) {
686  modeInt = 21; // weak decay phase space, weighting nu_tau spectrum
687  } else if ( tmpModeInt == 42 ) {
688  modeInt = 22; // weak decay V-A matrix element
689  } else if ( tmpModeInt == 43 ) {
690  modeInt = 22; // weak decay V-A matrix element, quarks as jets (superfluous)
691  } else if ( tmpModeInt == 44 ) {
692  modeInt = 22; // weak decay V-A matrix element, parton showers (superfluous)
693  } else if ( tmpModeInt == 48 ) {
694  modeInt = 23; // weak decay V-A matrix element, at least 3 decay products
695  } else if ( tmpModeInt == 50 ) {
696  modeInt = 0; // default behaviour
697  } else if ( tmpModeInt == 51 ) {
698  modeInt = 0; // step threshold (channel switched off when mass daughters > mother mass
699  } else if ( tmpModeInt == 52 || tmpModeInt == 53 ) {
700  modeInt = 0; // beta-factor threshold
701  } else if ( tmpModeInt == 84 ) {
702  modeInt = 42; // unknown physics process - just use phase-space
703  } else if ( tmpModeInt == 101 ) {
704  modeInt = 0; // continuation line
705  } else if ( tmpModeInt == 102 ) {
706  modeInt = 0; // off mass shell particles.
707  } else {
708  EvtGenReport( EVTGEN_INFO, "EvtGen" )
709  << "Pythia mode integer " << tmpModeInt
710  << " is not recognised. Using phase-space model" << endl;
711  modeInt = 0; // Use phase-space for anything else
712  }
713 
714  } else {
715  // No need to convert the physics mode integer code
716  modeInt = tmpModeInt;
717  }
718 
719  return modeInt;
720 }
721 
722 void EvtPythiaEngine::createPythiaParticle( EvtId& particleId, int PDGCode )
723 {
724  // Use the EvtGen name, PDGId and other variables to define the new Pythia particle.
725  EvtId antiPartId = EvtPDL::chargeConj( particleId );
726 
727  std::string aliasName = EvtPDL::name(
728  particleId ); // If not an alias, aliasName = normal name
729  std::string antiName = EvtPDL::name( antiPartId );
730 
731  EvtSpinType::spintype spinType = EvtPDL::getSpinType( particleId );
732  int spin = EvtSpinType::getSpin2( spinType );
733 
734  int charge = EvtPDL::chg3( particleId );
735 
736  // Must set the correct colour type manually here, since the evt.pdl file
737  // does not store this information. This is required for quarks otherwise
738  // Pythia cannot generate the decay properly.
739  int PDGId = EvtPDL::getStdHep( particleId );
740  int colour( 0 );
741  if ( PDGId == 21 ) {
742  colour = 2; // gluons
743  } else if ( PDGId <= 8 && PDGId > 0 ) {
744  colour = 1; // single quarks
745  }
746 
747  double m0 = EvtPDL::getMeanMass( particleId );
748  double mWidth = EvtPDL::getWidth( particleId );
749  double mMin = EvtPDL::getMinMass( particleId );
750  double mMax = EvtPDL::getMaxMass( particleId );
751 
752  double tau0 = EvtPDL::getctau( particleId );
753 
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;
760 
761  // Pass this information to Pythia
762  _thePythiaGenerator->readString( oss.str() );
763 
764  // Also store the absolute value of the PDG entry
765  // to keep track of which new particles have been added,
766  // which also automatically includes the anti-particle.
767  // We need to avoid creating new anti-particles when
768  // they already exist when the particle was added.
769  _addedPDGCodes[absPDGCode] = 1;
770 }
771 
772 void EvtPythiaEngine::updatePhysicsParameters()
773 {
774  // Update any more Pythia physics (or special particle) requirements/cuts etc..
775  // This should be used if any of the Pythia 6 parameters like JetSetPar MSTJ(i) = x
776  // are needed. Such commands will need to be implemented using the new interface
777  // pythiaGenerator->readString(cmd); Here cmd is a string telling Pythia 8
778  // what physics parameters to change. This will need to be done for the generic and
779  // alias generator pointers, as appropriate.
780 
781  // Set the multiplicity level for hadronic weak decays
782  std::string multiWeakCut( "ParticleDecays:multIncreaseWeak = 2.0" );
783  _genericPythiaGen->readString( multiWeakCut );
784  _aliasPythiaGen->readString( multiWeakCut );
785 
786  // Set the multiplicity level for all other decays
787  std::string multiCut( "ParticleDecays:multIncrease = 4.5" );
788  _genericPythiaGen->readString( multiCut );
789  _aliasPythiaGen->readString( multiCut );
790 
791  //Now read in any custom configuration entered in the XML
792  GeneratorCommands commands =
794  GeneratorCommands::iterator it = commands.begin();
795 
796  for ( ; it != commands.end(); it++ ) {
797  Command command = *it;
798  std::vector<std::string> commandStrings;
799 
800  if ( command["VERSION"] == "PYTHIA6" ) {
801  EvtGenReport( EVTGEN_INFO, "EvtGen" )
802  << "Converting Pythia 6 command: " << command["MODULE"] << "("
803  << command["PARAM"] << ")=" << command["VALUE"] << "..." << endl;
804  commandStrings = convertPythia6Command( command );
805  } else if ( command["VERSION"] == "PYTHIA8" ) {
806  commandStrings.push_back( command["MODULE"] + ":" + command["PARAM"] +
807  " = " + command["VALUE"] );
808  } else {
809  EvtGenReport( EVTGEN_ERROR, "EvtGen" )
810  << "Pythia command received by EvtPythiaEngine has bad version:"
811  << endl;
812  EvtGenReport( EVTGEN_ERROR, "EvtGen" )
813  << "Received " << command["VERSION"]
814  << " but expected PYTHIA6 or PYTHIA8." << endl;
815  EvtGenReport( EVTGEN_ERROR, "EvtGen" )
816  << "The error is likely to be in EvtDecayTable.cpp" << endl;
817  EvtGenReport( EVTGEN_ERROR, "EvtGen" )
818  << "EvtGen will now abort." << endl;
819  ::abort();
820  }
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++ ) {
827  EvtGenReport( EVTGEN_INFO, "EvtGen" )
828  << "Configuring generic Pythia generator: " << ( *it2 )
829  << endl;
830  _genericPythiaGen->readString( *it2 );
831  }
832  }
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++ ) {
838  EvtGenReport( EVTGEN_INFO, "EvtGen" )
839  << "Configuring alias Pythia generator: " << ( *it2 )
840  << endl;
841  _aliasPythiaGen->readString( *it2 );
842  }
843  }
844  }
845 }
846 
847 #endif
static EvtExtGeneratorCommandsTable * getInstance()
static std::string name(EvtId i)
Definition: EvtPDL.cpp:382
static EvtDecayTable * getInstance()
static EvtId getEntry(int i)
Definition: EvtPDL.cpp:392
double getArg(unsigned int j)
static EvtSpinType::spintype getSpinType(EvtId i)
Definition: EvtPDL.cpp:377
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=0)
Definition: EvtReport.cpp:33
virtual void init(EvtId part_n, const EvtVector4R &p4)=0
const GeneratorCommands & getCommands(std::string extGenerator)
static double getctau(EvtId i)
Definition: EvtPDL.cpp:357
static double getMeanMass(EvtId i)
Definition: EvtPDL.cpp:314
EvtId getId() const
void makeDaughters(unsigned int ndaug, EvtId *id)
std::vector< std::string > convertPythia6Command(Command command)
static int chg3(EvtId i)
Definition: EvtPDL.cpp:372
Definition: EvtId.hh:27
size_t getNDaug() const
std::vector< Command > GeneratorCommands
double getBranchingFraction() const
Definition: EvtDecayBase.hh:62
int getNModes(int aliasInt)
void deleteDaughters(bool keepChannel=false)
static double getMinMass(EvtId i)
Definition: EvtPDL.cpp:342
EvtDecayBase * findDecayModel(int aliasInt, int modeInt)
static size_t entries()
Definition: EvtPDL.cpp:387
std::map< std::string, std::string > Command
double abs(const EvtComplex &c)
Definition: EvtComplex.hh:201
static EvtId evtIdFromStdHep(int stdhep)
Definition: EvtPDL.cpp:246
static int getSpin2(spintype stype)
Definition: EvtSpinType.cpp:26
std::string getModelName() const
Definition: EvtDecayBase.hh:79
double mass() const
static double getWidth(EvtId i)
Definition: EvtPDL.cpp:352
int getNDaug() const
Definition: EvtDecayBase.hh:65
EvtParticle * getDaug(int i)
Definition: EvtParticle.cpp:91
int getAlias() const
Definition: EvtId.hh:44
int getNArg() const
Definition: EvtDecayBase.hh:68
static EvtId chargeConj(EvtId id)
Definition: EvtPDL.cpp:207
int isAlias() const
Definition: EvtId.hh:46
static int getStdHep(EvtId id)
Definition: EvtPDL.cpp:362
bool hasPythia(int aliasInt)
static double getMaxMass(EvtId i)
Definition: EvtPDL.cpp:337
EvtId getDaug(int i) const
Definition: EvtDecayBase.hh:67