Coder Social home page Coder Social logo

raymondehlers / pyfastjet Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 161 KB

Fastjet bindings based on pybind11

License: BSD 3-Clause "New" or "Revised" License

CMake 21.91% Python 20.34% C++ 57.75%
alice-experiment heavy-ion-collisions lhc physics

pyfastjet's Introduction

Python Fastjet Bindings

Python bindings for fastjet. fastjet-contrib is not yet supported, but could be added depending on demand.

NOTE: These are still in development / are experimental!

Installation

Prerequisites:

  1. Clone the repository, and initialize the submodule with git submodule init.

  2. You need to set the environment variables:

    • FASTJET
    • CGAL_ROOT
    • GMP_ROOT

    They need to be set to the install locations of the three packages. alibuild will set the first two. (Note that alibuild used to call it $FASTJET_ROOT, but now it's known as just $FASTJET). However, GMP_ROOT unfortunately isn't seen as a fastjet dependency, so we have to load it explicitly. For convenience with AliBuild, you can use (assuming zsh):

    $ alienv modulecmd zsh load fastjet/latest GMP/latest
  3. Install poetry, and install the package via poetry install in the repository root directory.

  4. The tests can be via poetry run pytest -l -vv tests/.

Done. If you need a virtualenv with the package, this can be useful:

alias poetryShell='source "$(dirname $(poetry run which python))/activate"'

Usage

By way of an example from the fastjet quick start:

import pyfastjet as fj

# Create the PseudoJets
# an event with three particles:   px    py  pz      E
particles = []
particles.append(PseudoJet( 99.0,  0.1,  0, 100.0))
particles.append(PseudoJet(  4.0, -0.1,  0,   5.0))
particles.append(PseudoJet(-99.0,    0,  0,  99.0))

# choose a jet definition
R = 0.7
jet_def = fj.JetDefinition(fj.JetAlgorithm.antikt_algorithm, R)

# run the clustering, extract the jets
cs = fj.ClusterSequence(particles, jet_def)
jets = fj.sorted_by_pt(cs.inclusive_jets())

for jet in cs:
    print(f"jet: {jet}")
    for j, constituent in enumerate(jet.constituents):
        print(f"    constituent {j}: {constituent}")

See the tests for more functionality.

Alternatives

I was looking for very simple bindings, and control of the API was helpful, so I decided to write my own. But there are many other excellent binding options:

  • Official bindings: Fastjet recently pushed SWIG based python bindings. You need a fairly recent version of fastjet, which isn't yet deployed for ALICE.
  • pyjet: It currently (Nov 2019) doesn't have fastjet-contrib bindings. They possible could have been added, but it didn't appear as straightforward as I would have liked.
  • heppy: I was unable to get this setup :-(

pyfastjet's People

Contributors

raymondehlers avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.