Master thread deletes the data in multi-thread mode

Hi all,

I am trying to store the kinetic energy of neutrons passing through a sensitive volume, by passing the data from each steppingAction to the eventAction, and from each eventAction to the runAction, and finally save the data in a .txt file, at the end of the runAction.
The code works fine in the sequential mode, but as I switch to multi-thread mode, and use: if(IsMaster()) at the end of the runAction to store the data by the master thread, the data file will be empty. However typing: if(!IsMaster()) to store the data by the worker threads the data exist in the file.
How can I fix the problem, to be able to store the data by the master thread?


In the MT mode the master thread does not perform the computaions. To transfer the data to the master thread one needs to create some state shared between the threads and make sure that no data races occur, which is not trivial. One should use G4AnalysisManager instead of reimplementing such functionality manually unless really needed.
Sometimes the command-based scoring with G4ScoringManager is sufficient. Example RE03 gives the details.