Merge multiple .root files when running multithreading

Hello everyone.
I noticed that I can run multithreading using code like /run/numberOfThreads 4 and merge variable data we want using accumulableManager->Merge(); in examples/basic/B1.
But I’d like to output results as root files. I wonder if there is a related example in Geant4 that I can refer to?
Thanks!

Hi,

you can have a look at, for instance, example basic/B4/B4a/
It creates a single root output file for both multi-threaded and single-threaded executions.

If you want to save root files from each thread, set
analysisManager->SetNtupleMerging(false); in RunAction.cc (line 57 with Geant4.11.0).

If you want to merge ntuples from multiple root files a posteriori
hadd -f B4.root B4_*

Cheers, Lorenzo

1 Like

Thanks for your suggestion.

I successfully merged and output .root file using multithread, but I encountered a problem related to sensitive detector.

Here is my test example: GitHub - Peterllll/MT_test: multithread_test

Once when I using SD to get deposit energy like line 57 in EventAction.cc:

ergt1+=(*SDdet1)[i1]->GetEdep()/MeV

I’ll get an error like this:

*** Break *** segmentation violation
[1]    97640 segmentation fault (core dumped)

When I comment out line 57 and line 60 in EventAction.cc, the program will run normally.
Do I need to do some special adjustments for SD when using multithread?

Thanks!

Dear @hcy,

the SD is not one of those entities that needs to be modified when running in parallel compared to sequential mode.

This might actually be a simple c++ issue. Try simple debugging like checking for the pointer actually pointing somewhere and or the size of the hitscollection.

Cheers,

/Pico

1 Like

Ok, I got it, appreciate your help. :grinning:@pico

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.