Skip to content

RepeatParametrisedVolume causes automatic deletion of ROOT output files #857

@Joshua-Dias-Barreto

Description

@Joshua-Dias-Barreto

Creating a RepeatParametrisedVolume object causes all ROOT files generated by digitizer actors to be automatically deleted after simulation completion, even when the repeater is never added to the volume manager or configured.

Minimal Script for reproduction:

import opengate as gate
from pathlib import Path
import os

def main():
    sim = gate.Simulation()
    
    # Setup output
    output_dir = Path("output")
    output_dir.mkdir(exist_ok=True)
    sim.output_dir = output_dir
    
    # Minimal world
    sim.world.size = [1 * gate.g4_units.m] * 3
    sim.world.material = "G4_AIR"
    
    # Simple detector volume
    detector = sim.add_volume("Box", "detector")
    detector.mother = "world"
    detector.material = "G4_AIR"
    detector.size = [10 * gate.g4_units.cm] * 3
    
    # THIS LINE CAUSES THE BUG - just creating the object (comment the line below to see the expected behavior)
    rpt = gate.geometry.volumes.RepeatParametrisedVolume(
         name="repeat_detector",
         repeated_volume=detector
    )
    # No need to add it or set any attributes - bug occurs anyway
    
    # Simple physics
    sim.physics_manager.physics_list_name = "G4EmStandardPhysics_option3"
    
    # Simple source
    source = sim.add_source("GenericSource", "test_source")
    source.particle = "gamma"
    source.energy.mono = 511 * gate.g4_units.keV
    source.activity = 100000 * gate.g4_units.Bq
    source.direction.type = "iso"
    
    # Statistics actor (produces stat.txt - this persists)
    stats = sim.add_actor("SimulationStatisticsActor", "Stats")
    stats.output_filename = "stat.txt"
    
    # Actor that produces ROOT file
    hits = sim.add_actor("DigitizerHitsCollectionActor", "Hits")
    hits.attached_to = ["detector"]
    hits.output_filename = "test_hits.root"
    hits.write_to_disk = True
    hits.attributes = ["TotalEnergyDeposit", "GlobalTime"]
    
    # Run
    sim.run_timing_intervals = [[0, 1 * gate.g4_units.s]]
    sim.run()
    
    # Check output
    print("Output files:", os.listdir("output"))
    # BUG: stat.txt persists but test_hits.root will be missing

if __name__ == "__main__":
    main()

Expected Behavior:

ROOT files should persist after simulation completion
stat.txt and test_hits.root should both be present in the output directory

Actual Behavior:

Simulation runs without errors
stat.txt persists
All .root files are created during simulation but automatically deleted when simulation completes
The bug occurs regardless of whether:

The repeater is added to the volume manager (sim.volume_manager.add_volume(rpt))
Any attributes are set on the repeater
The repeater is actually used

Commenting out the RepeatParametrisedVolume instantiation causes ROOT files to persist normally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions