Skip to main content

A lightweight, Python-based visualization tool for Geant4.

Project description

GeViewer

PyPI - Version GitHub Actions Workflow Status Last Commit GitHub License

A lightweight, Python-based visualization tool for Geant4. GeViewer provides a convenient way to view detector geometries and particle trajectories, with smooth rendering in an interactive window.

Features

  • 🔬 Physics visualization: See color-coded particle trajectories in a 3D rendering of the detector

  • 🕹️ Intuitive controls: Use your mouse to rotate, zoom, and pan to explore the geometry

  • 🎨 Customizable rendering: Toggle through different viewing options with simple keystroke commands

  • High-quality graphics: Produce publication-quality visuals of detectors and events

  • 🚀 Smooth & fast: Efficient handling of large and complex detector geometries

Getting started

Dependencies

The following packages are required:

  • numpy
  • tqdm
  • pyvista

Installation

GeViewer can be installed using pip as follows:

pip install geviewer

To uninstall:

pip uninstall geviewer

Usage

This package is intended to be used primarily as a command line tool. To run the program, you must have already produced one or more VRML files from Geant4 simulations. See the section below for instructions on what to put in your Geant4 macro. Following installation, the program can be run using:

geviewer /path/to/file1.wrl

This will load the meshes described in /path/to/file.wrl and display them in an interactive window. To view multiple files at once, simply provide multiple paths when launching the program. The viewing perspective can be changed by clicking, dragging, and scrolling in the window, while other functions can be activated using keystrokes. More specific instructions for use will print in the terminal window when the program is launched.

Instructions for Geant4

To produce Geant4 outputs that can be read by GeViewer, you must use /vis/open VRML2FILE to tell Geant4 to save the visualization as a VRML file. The following macro snippet shows how this could be implemented, along with some other options.

# tell Geant4 we want a VRML file rather than to use an interactive viewer
# this line should come BEFORE the /run/beamOn command
/vis/open VRML2FILE

# now ensure that the geometry is displayed
/vis/drawVolume

# add the trajectories
/vis/scene/add/trajectories

# add the step markers
/vis/modeling/trajectories/create/drawByParticleID
/vis/modeling/trajectories/drawByParticleID-0/default/setDrawStepPts true

# ensure that they are not cleared at the end of the event
/vis/scene/endOfEventAction accumulate

# you can also apply other commands here to control other
# aspects of how the geometry and events will be displayed

# the main content of your Geant4 macro goes here

# specify the number of events and start the simulation
/run/beamOn 1

# by default, the file will be saved as g4_00.wrl
# but it can easily be renamed from within the macro
/control/shell mv g4_00.wrl /new/path/to/file.wrl

# if you are running on your local computer, the
# VRML file can be piped directly to GeViewer
/control/shell geviewer /new/path/to/file.wrl

exit

For more information on how to construct a macro, refer to the Geant4 documentation. Note that if you are running Geant4 on a remote machine over ssh, you will have to download the VRML files to view on your local computer, as GeViewer does not work over X11 forwarding.

Safe mode

By default, GeViewer relies on its own VRML parser to extract the meshes to be plotted, however this has only been tested on a small sample set of Geant4 simulation results. If you encounter file parsing errors, try using the --safe-mode command line argument (and create an issue to report the problem). This will use a VRML parsing tool from vtk which should be more robust, but which does not allow the program to distinguish trajectories, step markers, and detector components. In this mode, some features will not be available.

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Clarke Hardy - cahardy@stanford.edu

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geviewer-0.0.9.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

geviewer-0.0.9-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file geviewer-0.0.9.tar.gz.

File metadata

  • Download URL: geviewer-0.0.9.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for geviewer-0.0.9.tar.gz
Algorithm Hash digest
SHA256 a9f57836eff03e9d8c5875300f22b5c73cec50e3d99e06f9265542e247d6f912
MD5 fbbfbda0fc85fc970cd70726227cf008
BLAKE2b-256 a08d212544723b019063aae38b4fbcfbf3b8895e4555b2912015374c6f810c68

See more details on using hashes here.

File details

Details for the file geviewer-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: geviewer-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for geviewer-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 69a059ab579ece52d8e6c5cf98fc7cf9096c05a20db523f5661e0226b7d7f167
MD5 854a10ec0bd9f68d4b1a044e99413a7f
BLAKE2b-256 28b2a125ec4014ac81c5f5bb762d365c485f9e85e13680767cf427f0cf79f4ca

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page