Creation of a root file and writing the event data generated in the simulation

this is the stack trace of all threads which i encountered while creating a simulation and writing the event generated data into a root file.
can you please provide some idea about how this errors need to be resolved?

There was a crash.
This is the entire stack trace of all threads:

Thread 5 (Thread 0x79325f5fc640 (LWP 12479) “GeSeV_ln_Cubic_”):
#0 0x0000793267eea42f in __GI___wait4 (pid=12501, stat_loc=stat_loc
entry=0x79325f4df198, options=options
entry=0, usage=usage
entry=0x0) at …/sysdeps/unix/sysv/linux/wait4.c:30
#1 0x0000793267eea3ab in __GI___waitpid (pid=, stat_loc=stat_loc
entry=0x79325f4df198, options=options
entry=0) at ./posix/waitpid.c:38
#2 0x0000793267e50bdb in do_system (line=) at …/sysdeps/posix/system.c:171
#3 0x0000793269714604 in TUnixSystem::StackTrace() () from /opt/root/root-6.30.02-install/lib/libCore.so
#4 0x0000793269711935 in TUnixSystem::DispatchSignals(ESignals) () from /opt/root/root-6.30.02-install/lib/libCore.so
#5
#6 0x000079326810517c in TBranch::FillImpl(ROOT::Internal::TBranchIMTHelper*) () from /opt/root/root-6.30.02-install/lib/libTree.so
#7 0x0000793268184128 in TTree::Fill() () from /opt/root/root-6.30.02-install/lib/libTree.so
#8 0x0000793267660ca9 in G4EventManager::DoProcessing(G4Event*) () from /opt/geant4/install/lib/libG4event.so
#9 0x0000793268cc0a0c in G4WorkerRunManager::DoEventLoop(int, char const*, int) () from /opt/geant4/install/lib/libG4run.so
#10 0x0000793268c70c42 in G4RunManager::BeamOn(int, char const*, int) () from /opt/geant4/install/lib/libG4run.so
#11 0x0000793268cc40c4 in G4WorkerRunManager::DoWork() () from /opt/geant4/install/lib/libG4run.so
#12 0x0000793268c674bb in G4MTRunManagerKernel::StartThread(G4WorkerThread*) () from /opt/geant4/install/lib/libG4run.so
#13 0x00007932686dc253 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#14 0x0000793267e94ac3 in start_thread (arg=) at ./nptl/pthread_create.c:442
#15 0x0000793267f26850 in clone3 () at …/sysdeps/unix/sysv/linux/x86_64/clone3.S:81

Thread 4 (Thread 0x79325fdfd640 (LWP 12478) “GeSeV_ln_Cubic_”):
#0 0x0000793267eea42f in __GI___wait4 (pid=12507, stat_loc=stat_loc
entry=0x79325fce0198, options=options
entry=0, usage=usage
entry=0x0) at …/sysdeps/unix/sysv/linux/wait4.c:30
#1 0x0000793267eea3ab in __GI___waitpid (pid=, stat_loc=stat_loc
entry=0x79325fce0198, options=options
entry=0) at ./posix/waitpid.c:38
#2 0x0000793267e50bdb in do_system (line=) at …/sysdeps/posix/system.c:171
#3 0x0000793269714604 in TUnixSystem::StackTrace() () from /opt/root/root-6.30.02-install/lib/libCore.so
#4 0x0000793269711935 in TUnixSystem::DispatchSignals(ESignals) () from /opt/root/root-6.30.02-install/lib/libCore.so
#5
#6 0x000079326810517c in TBranch::FillImpl(ROOT::Internal::TBranchIMTHelper*) () from /opt/root/root-6.30.02-install/lib/libTree.so
#7 0x0000793268184128 in TTree::Fill() () from /opt/root/root-6.30.02-install/lib/libTree.so
#8 0x0000793267660ca9 in G4EventManager::DoProcessing(G4Event*) () from /opt/geant4/install/lib/libG4event.so
#9 0x0000793268cc0a0c in G4WorkerRunManager::DoEventLoop(int, char const*, int) () from /opt/geant4/install/lib/libG4run.so
#10 0x0000793268c70c42 in G4RunManager::BeamOn(int, char const*, int) () from /opt/geant4/install/lib/libG4run.so
#11 0x0000793268cc40c4 in G4WorkerRunManager::DoWork() () from /opt/geant4/install/lib/libG4run.so
#12 0x0000793268c674bb in G4MTRunManagerKernel::StartThread(G4WorkerThread*) () from /opt/geant4/install/lib/libG4run.so
#13 0x00007932686dc253 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#14 0x0000793267e94ac3 in start_thread (arg=) at ./nptl/pthread_create.c:442
#15 0x0000793267f26850 in clone3 () at …/sysdeps/unix/sysv/linux/x86_64/clone3.S:81

Thread 3 (Thread 0x7932605fe640 (LWP 12477) “GeSeV_ln_Cubic_”):
#0 0x0000793267eea42f in __GI___wait4 (pid=12499, stat_loc=stat_loc
entry=0x7932604e1198, options=options
entry=0, usage=usage
entry=0x0) at …/sysdeps/unix/sysv/linux/wait4.c:30
#1 0x0000793267eea3ab in __GI___waitpid (pid=, stat_loc=stat_loc
entry=0x7932604e1198, options=options
entry=0) at ./posix/waitpid.c:38
#2 0x0000793267e50bdb in do_system (line=) at …/sysdeps/posix/system.c:171
#3 0x0000793269714604 in TUnixSystem::StackTrace() () from /opt/root/root-6.30.02-install/lib/libCore.so
#4 0x0000793269711935 in TUnixSystem::DispatchSignals(ESignals) () from /opt/root/root-6.30.02-install/lib/libCore.so
#5
#6 0x000079326810517c in TBranch::FillImpl(ROOT::Internal::TBranchIMTHelper*) () from /opt/root/root-6.30.02-install/lib/libTree.so
#7 0x0000793268184128 in TTree::Fill() () from /opt/root/root-6.30.02-install/lib/libTree.so
#8 0x0000793267660ca9 in G4EventManager::DoProcessing(G4Event*) () from /opt/geant4/install/lib/libG4event.so
#9 0x0000793268cc0a0c in G4WorkerRunManager::DoEventLoop(int, char const*, int) () from /opt/geant4/install/lib/libG4run.so
#10 0x0000793268c70c42 in G4RunManager::BeamOn(int, char const*, int) () from /opt/geant4/install/lib/libG4run.so
#11 0x0000793268cc40c4 in G4WorkerRunManager::DoWork() () from /opt/geant4/install/lib/libG4run.so
#12 0x0000793268c674bb in G4MTRunManagerKernel::StartThread(G4WorkerThread*) () from /opt/geant4/install/lib/libG4run.so
#13 0x00007932686dc253 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#14 0x0000793267e94ac3 in start_thread (arg=) at ./nptl/pthread_create.c:442
#15 0x0000793267f26850 in clone3 () at …/sysdeps/unix/sysv/linux/x86_64/clone3.S:81

Thread 2 (Thread 0x793260dff640 (LWP 12476) “GeSeV_ln_Cubic_”):
#0 0x0000793267eea42f in __GI___wait4 (pid=12516, stat_loc=stat_loc
entry=0x793260ce2198, options=options
entry=0, usage=usage
entry=0x0) at …/sysdeps/unix/sysv/linux/wait4.c:30
#1 0x0000793267eea3ab in __GI___waitpid (pid=, stat_loc=stat_loc
entry=0x793260ce2198, options=options
entry=0) at ./posix/waitpid.c:38
#2 0x0000793267e50bdb in do_system (line=) at …/sysdeps/posix/system.c:171
#3 0x0000793269714604 in TUnixSystem::StackTrace() () from /opt/root/root-6.30.02-install/lib/libCore.so
#4 0x0000793269711935 in TUnixSystem::DispatchSignals(ESignals) () from /opt/root/root-6.30.02-install/lib/libCore.so
#5
#6 0x000079326810517c in TBranch::FillImpl(ROOT::Internal::TBranchIMTHelper*) () from /opt/root/root-6.30.02-install/lib/libTree.so
#7 0x0000793268184128 in TTree::Fill() () from /opt/root/root-6.30.02-install/lib/libTree.so
#8 0x0000793267660ca9 in G4EventManager::DoProcessing(G4Event*) () from /opt/geant4/install/lib/libG4event.so
#9 0x0000793268cc0a0c in G4WorkerRunManager::DoEventLoop(int, char const*, int) () from /opt/geant4/install/lib/libG4run.so
#10 0x0000793268c70c42 in G4RunManager::BeamOn(int, char const*, int) () from /opt/geant4/install/lib/libG4run.so
#11 0x0000793268cc40c4 in G4WorkerRunManager::DoWork() () from /opt/geant4/install/lib/libG4run.so
#12 0x0000793268c674bb in G4MTRunManagerKernel::StartThread(G4WorkerThread*) () from /opt/geant4/install/lib/libG4run.so
#13 0x00007932686dc253 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#14 0x0000793267e94ac3 in start_thread (arg=) at ./nptl/pthread_create.c:442
#15 0x0000793267f26850 in clone3 () at …/sysdeps/unix/sysv/linux/x86_64/clone3.S:81

Thread 1 (Thread 0x793262bfe000 (LWP 12475) “GeSeV_ln_Cubic_”):
#0 __futex_abstimed_wait_common64 (private=0, cancel=true, abstime=0x0, op=393, expected=0, futex_word=0x5bc3222a63a4) at ./nptl/futex-internal.c:57
#1 __futex_abstimed_wait_common (cancel=true, private=0, abstime=0x0, clockid=0, expected=0, futex_word=0x5bc3222a63a4) at ./nptl/futex-internal.c:87
#2 __GI___futex_abstimed_wait_cancelable64 (futex_word=futex_word
entry=0x5bc3222a63a4, expected=expected
entry=0, clockid=clockid
entry=0, abstime=abstime
entry=0x0, private=private
entry=0) at ./nptl/futex-internal.c:139
#3 0x0000793267e93a41 in __pthread_cond_wait_common (abstime=0x0, clockid=0, mutex=0x5bc3222a6350, cond=0x5bc3222a6378) at ./nptl/pthread_cond_wait.c:503
#4 ___pthread_cond_wait (cond=0x5bc3222a6378, mutex=0x5bc3222a6350) at ./nptl/pthread_cond_wait.c:627
#5 0x0000793268b4dfee in G4MTBarrier::Wait() () from /opt/geant4/install/lib/libG4global.so
#6 0x0000793268c65a00 in G4MTRunManager::RunTermination() () from /opt/geant4/install/lib/libG4run.so
#7 0x0000793268c70c4b in G4RunManager::BeamOn(int, char const*, int) () from /opt/geant4/install/lib/libG4run.so
#8 0x0000793268c988e5 in G4RunMessenger::SetNewValue(G4UIcommand*, G4String) () from /opt/geant4/install/lib/libG4run.so
#9 0x0000793268bc4f8b in G4UIcommand::DoIt(G4String) () from /opt/geant4/install/lib/libG4intercoms.so
#10 0x0000793268be4611 in G4UImanager::ApplyCommand(char const*) () from /opt/geant4/install/lib/libG4intercoms.so
#11 0x0000793268bb3ce1 in G4UIbatch::ExecCommand(G4String const&) () from /opt/geant4/install/lib/libG4intercoms.so
#12 0x0000793268bb4dea in G4UIbatch::SessionStart() () from /opt/geant4/install/lib/libG4intercoms.so
#13 0x0000793268be6720 in G4UImanager::ExecuteMacroFile(char const*) () from /opt/geant4/install/lib/libG4intercoms.so
#14 0x0000793268bd2478 in G4UIcontrolMessenger::SetNewValue(G4UIcommand*, G4String) () from /opt/geant4/install/lib/libG4intercoms.so
#15 0x0000793268bc4f8b in G4UIcommand::DoIt(G4String) () from /opt/geant4/install/lib/libG4intercoms.so
#16 0x0000793268be4611 in G4UImanager::ApplyCommand(char const*) () from /opt/geant4/install/lib/libG4intercoms.so
#17 0x00005bc322044d29 in main ()

The lines below might hint at the cause of the crash. If you see question
marks as part of the stack trace, try to recompile with debugging information
enabled and export CLING_DEBUG=1 environment variable before running.
You may get help by asking at the ROOT forum ROOT Forum
preferably using the command (.forum bug) in the ROOT prompt.
Only if you are really convinced it is a bug in ROOT then please submit a
report at Sign in to GitHub · GitHub or (preferably) using the command (.gh bug) in
the ROOT prompt. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#6 0x000079326810517c in TBranch::FillImpl(ROOT::Internal::TBranchIMTHelper*) () from /opt/root/root-6.30.02-install/lib/libTree.so
#7 0x0000793268184128 in TTree::Fill() () from /opt/root/root-6.30.02-install/lib/libTree.so
#8 0x0000793267660ca9 in G4EventManager::DoProcessing(G4Event*) () from /opt/geant4/install/lib/libG4event.so
#9 0x0000793268cc0a0c in G4WorkerRunManager::DoEventLoop(int, char const*, int) () from /opt/geant4/install/lib/libG4run.so
#10 0x0000793268c70c42 in G4RunManager::BeamOn(int, char const*, int) () from /opt/geant4/install/lib/libG4run.so
#11 0x0000793268cc40c4 in G4WorkerRunManager::DoWork() () from /opt/geant4/install/lib/libG4run.so
#12 0x0000793268c674bb in G4MTRunManagerKernel::StartThread(G4WorkerThread*) () from /opt/geant4/install/lib/libG4run.so
#13 0x00007932686dc253 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#14 0x0000793267e94ac3 in start_thread (arg=) at ./nptl/pthread_create.c:442
#15 0x0000793267f26850 in clone3 () at …/sysdeps/unix/sysv/linux/x86_64/clone3.S:81

===========================================================

Segmentation fault (core dumped)

_Geant4 Version:_11.01.03
_Operating System:_Ubuntu_22.04
_Compiler/Version:_gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

_CMake Version:_3.22.1


Hello,

When using the ROOT output with a Geant4 application in MT (multi-threaded) mode, you need to lock some critical operations from simultaneous write by threads.

Or you can switch to sequential mode, see for example the main function in extended/analysis/AnaEx02 example (demonstrating the ROOT output with a Geant4 application):

  auto* runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::SerialOnly);

Geant4 provides its analysis tools that allow to output event data in the form of n-tuples into ROOT file. These tools are already “MT-aware” so you do not need to take care of thread-safety yourself. You can find examples how to use the Geant4 analysis in basic examples B4 and B5, or in extended/analysis/AnaEx01.

Best regards,

1 Like

Thank you for this quick response. The file is working now and giving me the desired output. I think this is a problem with the current 11.01.03 version as this codes runs well in the 10. versions of geant4.