Skip to content

Export Geant4 Simulation Events to JSON for 3D Web Visualization - OpenGL #10

Description

@jhajduga

✨ Issue: Export Geant4 Simulation Events to JSON for 3D Web Visualization

🎯 Goal

Enable the visualization of selected Geant4 simulation events (including full secondary particle showers) in a modern 3D web environment (e.g., using three.js).
This requires exporting complete event-level tracking data (trajectory points per particle) from ROOT trees into a single structured JSON file.


📋 Current State

  • Event data is stored in TTree structures, using G4AnalysisManager.

  • Per-step data (position, energy, time, track info) is already collected in vectors:

    • e.g., m_VoxelHitsTrkId, m_VoxelHitsTrkEnergy, m_VoxelHitsTrkPosX/Y/Z, etc.
  • However, ParentID information is missing, which is needed to reconstruct particle shower trees (γ → e⁻/e⁺ → ...).


📦 Task Overview

🔧 [C++] Extend Tracking and NTuple Output

  • In SteppingAction or hit creation logic, capture G4Track::GetParentID() for each step.
  • Add a new vector (e.g., m_VoxelHitsParentTrkId) and include it in the NTuple output.
  • Optionally, capture G4Track::GetDefinition()->GetPDGEncoding() and/or name for particle typing.

🧪 [Python] Write PyROOT-based Export Script

  • Use PyROOT to load the .root file and access TTrees.

  • Group all hits/steps by (G4EvtId, TrackId) to form trajectories.

  • For each trajectory:

    • Store ordered 3D positions and times.
    • Include TrackId, ParentId, ParticleType.
  • Dump all selected events into a single events.json file with a structure like:

    {
      "event_id": 42,
      "particles": [
        {
          "track_id": 1,
          "parent_id": 0,
          "pdg": 22,
          "name": "gamma",
          "trajectory": [
            { "x": ..., "y": ..., "z": ..., "t": ... },
            ...
          ]
        },
        ...
      ]
    }

🌐 [Frontend] Basic three.js Renderer (later step)

  • Load events.json and render each particle as a colored trajectory line.
  • Add basic interactivity (event selection, toggling particle types, play/pause time).
  • Optional: visualize parent_id relations as shower trees or via color-coding.
  • Optional: visualize process_type_id and 'electron_origin_type_id'/'particle_origin_type_id' in shower trees or via color-coding. (

📁 Output Format (Single File)

Output will be a JSON file:

  • all_events.json (list of events with particle trajectories)

🧠 Notes / Considerations

  • The filtering (e.g. “only events with primary γ > 5 MeV”) will be handled in Python, prior to JSON export.
  • Parent tracking must be consistent: if TrackId == 1 has ParentId == 0, we assume it's a primary.
  • No need to visualize voxels or energy deposition – focus is on geometry + causality of particle motion.
  • Firstly - pull changes from dose3d/g4rt:51-the-process-of-recording-the-type-of-physical-event-in-g4 to obtain all required info about particles.

🛠 Tools

  • Simulation: Geant4, ROOT TTree (G4AnalysisManager)
  • Export: PyROOT
  • Frontend: JavaScript + three.js
  • (optional) ROOT.js considered, but not selected for now

Metadata

Metadata

Assignees

No one assigned

    Labels

    designUI/UX or visual improvements. / Zmiany wizualne, UX/UI.featureNew major functionality. / Nowa funkcjonalność.frontendUI or web-related work. / Interfejs użytkownika, front-end.priority: lowCan be addressed later. / Niski priorytet.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions