All Projects → scikit-hep → numpythia

scikit-hep / numpythia

Licence: GPL-3.0 License
The interface between PYTHIA and NumPy

Programming Languages

cython
566 projects
C++
36643 projects - #6 most used programming language
python
139335 projects - #7 most used programming language
Makefile
30231 projects
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to numpythia

pyjet
The interface between FastJet and NumPy
Stars: ✭ 31 (-6.06%)
Mutual labels:  numpy, hep, cern, scikit-hep
Uproot3
ROOT I/O in pure Python and NumPy.
Stars: ✭ 312 (+845.45%)
Mutual labels:  numpy, hep
Quantum-Computing-Collection-Of-Resources
A Well Maintained Repository On Quantum Computing Resources [Code+Theory] Updated Regularly During My Time At IBM, Qubit x Qubit And The Coding School's Introduction To Quantum Computing Course '21
Stars: ✭ 183 (+454.55%)
Mutual labels:  numpy, cern
Pyhf
pure-Python HistFactory implementation with tensors and autodiff
Stars: ✭ 171 (+418.18%)
Mutual labels:  numpy, hep
Uproot4
ROOT I/O in pure Python and NumPy.
Stars: ✭ 80 (+142.42%)
Mutual labels:  numpy, hep
particle
Package to deal with particles, the PDG particle data table, PDGIDs, etc.
Stars: ✭ 113 (+242.42%)
Mutual labels:  hep, scikit-hep
Root numpy
The interface between ROOT and NumPy
Stars: ✭ 130 (+293.94%)
Mutual labels:  numpy, hep
Rootpy
A pythonic interface for the ROOT libraries on top of the PyROOT bindings.
Stars: ✭ 186 (+463.64%)
Mutual labels:  numpy, hep
decaylanguage
Package to parse decay files, describe and convert particle decays between digital representations.
Stars: ✭ 34 (+3.03%)
Mutual labels:  hep, scikit-hep
pylhe
Lightweight Python interface to read Les Houches Event (LHE) files
Stars: ✭ 29 (-12.12%)
Mutual labels:  hep, scikit-hep
root pandas
A Python module for conveniently loading/saving ROOT files as pandas DataFrames
Stars: ✭ 108 (+227.27%)
Mutual labels:  hep, scikit-hep
alice-rs
Analyze the public data from the CERN base ALICE collaboration with Rust
Stars: ✭ 81 (+145.45%)
Mutual labels:  hep, cern
alidist
Recipes to build ALICE software
Stars: ✭ 23 (-30.3%)
Mutual labels:  hep, cern
NPY-for-Fortran
A FORTRAN module to write Numpy's *.npy and *.npz files
Stars: ✭ 30 (-9.09%)
Mutual labels:  numpy
awesome-hep
A curated list of HEP / EEP enabled projects
Stars: ✭ 22 (-33.33%)
Mutual labels:  hep
robot
Functions and classes for gradient-based robot motion planning, written in Ivy.
Stars: ✭ 29 (-12.12%)
Mutual labels:  numpy
Neo
Deep learning library in python from scratch
Stars: ✭ 36 (+9.09%)
Mutual labels:  numpy
Python-notes
Python related technologies used in work: crawler, data analysis, timing tasks, RPC, page parsing, decorator, built-in functions, Python objects, multi-threading, multi-process, asynchronous, redis, mongodb, mysql, openstack, etc.
Stars: ✭ 104 (+215.15%)
Mutual labels:  numpy
queueable
Convert streams to async ⌛ iterables ➰
Stars: ✭ 43 (+30.3%)
Mutual labels:  generators
Algorithmic-Trading
I have been deeply interested in algorithmic trading and systematic trading algorithms. This Repository contains the code of what I have learnt on the way. It starts form some basic simple statistics and will lead up to complex machine learning algorithms.
Stars: ✭ 47 (+42.42%)
Mutual labels:  numpy

numpythia: The interface between PYTHIA and NumPy

Test status Wheel builds

numpythia provides an interface between PYTHIA and NumPy allowing 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 and HepMC source code.

Standalone Installation

To simply use the built-in PYTHIA and HepMC:

pip install -v numpythia

And 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 as explained here.

Strict dependencies

Getting started

>>> from numpythia import Pythia, hepmc_write, hepmc_read
>>> from numpythia import STATUS, HAS_END_VERTEX, ABS_PDG_ID
>>> from numpythia.testcmnd import get_cmnd
>>> from numpy.testing import assert_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
>>> for event in hepmc_write('events.hepmc', pythia(events=1)):
>>>    array1 = event.all(selection)

>>> # read the same event back from ascii hepmc
>>> for event in hepmc_read('events.hepmc'):
>>>    array2 = event.all(selection)

>>> assert_array_equal(array1, array2)
True

The 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 see pyjet for jet clustering.

Tutorial

Setting PYTHIA

PYTHIA settings can be passed in one of three ways: through the **kwargs arguments of the constructor Pythia(..., **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 the PYTHIA homepage.

Note that the ":" in settings names is replaced by a "_" if using kwargs. kwargs take precedence over params and they both take precedence over config. Example config files can be found under the numpythia.testcmnd directory.

Generate events

To generate events do

>>> events = pythia(events=100)
>>> events
<generator at 0x10cf06f78>

where events is a generator of GenEvent containing all the generated particles.

Generated particles can be accessed through the all, first and last methods which have two optional arguments selection and return_hepmc. Selection is a filter or a combination of filters with bitwise operations (as shown in the getting started example) applied on the particles in the event. The available filters are

STATUS, PDG_ID, ABS_PDG_ID, HAS_END_VERTEX, HAS_PRODUCTION_VERTEX,
HAS_SAME_PDG_ID_DAUGHTER, IS_STABLE, IS_BEAM

return_hepmc is by default set to False when using all:

>>> for e in events:
>>>     array = e.all(selection)

returns an array of particles, with the dtype described above. return_hepmc is by default set to True for first and last:

>>> for e in events:
>>>     gen_part_f = e.first(selection)
>>>     gen_part_l = e.last(selection)

returns a GenParticle.

Generated particle

GenParticle is the numpythia interface of HepMC::GenParticle, and has the following attributes

pid, status, e, px, py, pz, pt, eta, phi, mass, theta, rap

GenParticle also has the following methods parents, children, ancestors, descendants and siblings both with the two optional arguments selection and return_hepmc described before. For instance:

>>> for e in events:
>>>     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')])
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].