Coder Social home page Coder Social logo

pyhepevt's Introduction

pyhepevt

This is a lightweight python library to facilitate conversion and manipulation of HepEvt records using python. To install ::

pip install .

usage

Conversion scripts between HepEvt formats are provided within scripts/. These can be used to convert HepEvt records of one type to another, e.g. ::

python scripts/convert_marley_to_edepsim.py <MARLEY HepEvt file> <EDepSim HepEvt file>

Within python, file parsing is broken into reading a file (HepEvtReader) and writing a file (HepEvtWriter). Sub-classes are provided for each file format that can be parsed with a naming convention of (HepEvtReader<SoftwarePackage>/HepEvtWriter<SoftwarePackage>).

To facilitate the conversion, files are read into intermediate data object(s) (HepEvtEvent/HepEvtParticle). These objects use the fields listed in the MARLEY HepEvt format to store the representation of the event and particle. A HepEvtEvent also has a particles attribute that stores all of the particles associated with that event record. Similarly, a HepEvtParticle has an event attribute that stores a reference to the parent HepEvtEvent.

Below I provide a short example of how to open a file, modify an attribute and then save the data to a new file ::

from pyhepevt import HepEvtReaderMARLEY, HepEvtWriterEDepSim
with HepEvtReaderMARLEY(<input file>) as reader:
    with HepEvtWriterEDepSim(<output file>, 'w') as writer:
        for event in reader:
            event.p = [0, 0, 0, event.m[-1]] # force the particle momentum to zero
            writer.write(event)

extending

To add read compatibility with a new HepEvt format, one needs to:

  1. implement the from_<package>(*args) method of the HepEvtEvent and HepEvtParticle

  2. create a new HepEvtReader<SoftwarePackage> class inheriting from HepEvtReader

  3. implement the _read_next(fh) method of the new reader class

To add write compatibility with a new HepEvt format, one needs to:

  1. implement the dump_<package>() method of the HepEvtEvent and HepEvtParticle

  2. create a new HepEvtWriter<SoftwarePackage> class inheriting from HepEvtWriter

  3. implement the _write_event(event) method of the new reader class

pyhepevt's People

Contributors

peter-madigan avatar

Stargazers

Masanori Ogino avatar

Watchers

James Cloos 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.