Package: numpythia
numpythiahas not been actively maintained for a couple of years. This is mostly due to the emergence of new alternatives which are both faster and more flexible.
For example:Theofficial Pythia 8 (SWIG) bindings available from Conda.Theimpyproject implementing a generic user interface to popular event generators
used in cosmic ray and high-energy particle physics.numpythia: The interface between PYTHIA and NumPynumpythia provides an interface betweenPYTHIAandNumPyallowing you to generate events as NumPy arrays of
particle four-momenta. By default numpythia only depends on NumPy and builds
internal copies of the PYTHIA andHepMCsource code.Standalone InstallationTo simply use the built-in PYTHIA and HepMC:pip install -v numpythiaAnd you’re good to go!Support for building against an external PYTHIA is on the wishlist.Note that if you are using a Mac OSX system, then installation may require setting an
environment variable asexplained here.Strict dependenciesPython(2.7+, 3.7+)NumpysixSource builds:Cythonand a compiler.Getting started>>>fromnumpythiaimportPythia,hepmc_write,hepmc_read>>>fromnumpythiaimportSTATUS,HAS_END_VERTEX,ABS_PDG_ID>>>fromnumpythia.testcmndimportget_cmnd>>>fromnumpy.testingimportassert_array_equal>>>pythia=Pythia(get_cmnd('w'),random_state=1)>>>selection=((STATUS==1)&~HAS_END_VERTEX&(ABS_PDG_ID!=12)&(ABS_PDG_ID!=14)&(ABS_PDG_ID!=16))>>># generate events while writing to ascii hepmc>>>foreventinhepmc_write('events.hepmc',pythia(events=1)):>>>array1=event.all(selection)>>># read the same event back from ascii hepmc>>>foreventinhepmc_read('events.hepmc'):>>>array2=event.all(selection)>>>assert_array_equal(array1,array2)TrueThe dtype of any array of particle information is:np.dtype([('E','f8'),('px','f8'),('py','f8'),('pz','f8'),('pt','f8'),('mass','f8'),('rap','f8'),('eta','f8'),('theta','f8'),('phi','f8'),('prodx','f8'),('prody','f8'),('prodz','f8'),('prodt','f8'),('pdgid','i4'),('status','i4')])Also seepyjetfor jet clustering.TutorialSetting PYTHIAPYTHIA settings can be passed in one of three ways: through the**kwargsarguments of the constructorPythia(…, **kwargs):>>>pythia=Pythia(...,Beams_eCM=13000.)Or as a dictionary:>>>pythia=Pythia(...,params={'Beams:eCM':13000.})Or via a Python command file:>>>pythia=Pythia(config='path/to/config.cmd')The full list of settings can be found on thePYTHIA homepage.Note that the “:” in settings names is replaced by a “_”  if usingkwargs.kwargstake precedence overparamsand they both take precedence overconfig.
Example config files can be found under thenumpythia.testcmnddirectory.Generate eventsTo generate events do>>>events=pythia(events=100)>>>events<generatorat0x10cf06f78>whereeventsis a generator ofGenEventcontaining all the generated particles.Generated particles can be accessed through theall,firstandlastmethods which have two optional argumentsselectionandreturn_hepmc.
Selection is a filter or a combination of filters with bitwise operations (as
shown in thegetting startedexample) applied on the particles in the event.
The available filters areSTATUS,PDG_ID,ABS_PDG_ID,HAS_END_VERTEX,HAS_PRODUCTION_VERTEX,HAS_SAME_PDG_ID_DAUGHTER,IS_STABLE,IS_BEAMreturn_hepmcis by default set toFalsewhen usingall:>>>foreinevents:>>>array=e.all(selection)returns an array of particles, with the dtype described above.return_hepmcis
by default set toTrueforfirstandlast:>>>foreinevents:>>>gen_part_f=e.first(selection)>>>gen_part_l=e.last(selection)returns aGenParticle.Generated particleGenParticleis the numpythia interface ofHepMC::GenParticle,
and has the following attributespid,status,e,px,py,pz,pt,eta,phi,mass,theta,rapGenParticlealso has the following methodsparents,children,ancestors,descendantsandsiblingsboth with the two optional argumentsselectionandreturn_hepmcdescribed before. For instance:>>>foreinevents:>>>w=e.last((ABS_PDG_ID==24)&HAS_END_VERTEX))>>>w.children()array([(240.60708981,115.76101664,126.16766767,-169.03439984,171.22760682,0.5,-0.87228439,-0.87228739,2.34974894,0.82838703,0.,0.,0.,0.,3,23),(52.59241372,9.21296404,50.77873929,-10.01763001,51.60774235,1.5,-0.19283178,-0.19291222,1.76252302,1.39131523,0.,0.,0.,0.,-4,23)],dtype=[('E','<f8'),('px','<f8'),('py','<f8'),('pz','<f8'),('pT','<f8'),('mass','<f8'),('rap','<f8'),('eta','<f8'),('theta','<f8'),('phi','<f8'),('prodx','<f8'),('prody','<f8'),('prodz','<f8'),('prodt','<f8'),('pdgid','<i4'),('status','<i4')])