File filename already exists

Hi,
When I am trying to run the geant4 simulation for 10M events, it keeps giving me this error:
Error in TFile::TFile: file /Users/brianhuang/Simulation_2/build/simulation.root already exists

can anyone help me to fix it? because I’m doing build, then run.

_Geant4 Version:_11.2.0
_Operating System:_macOS Sequoia 15.5
Compiler/Version:
CMake Version:


Can you provide more details like, is there any such file already existing?
you code snippet? does multiple runs creating multiple leaves in root file?

Dear @Brian_Huang,

Welcome to the Geant4 forum!

Since you mentioned TFile, it seems you are using ROOT to manage your output data. The error message you encountered typically means that ROOT is refusing to overwrite an existing file unless explicitly instructed to do so (default mode is read-only).

Alternatively, for a standalone Geant4 simulation, you may find it easier to use the G4Analysis tools, which provide dedicated support for file handling and data output in ROOT and other formats. You can find a good example in the extended examples [1].

Best regards,
Alvaro

[1] geant4/examples/extended/analysis/AnaEx02 at master · Geant4/geant4 · GitHub

Thanks for everyone’s reply, this error has been fixed!
Cheer!