Multiple runs and storing in .root

Is there a straightforward way to either get a root file per run or combine the GEANT4 data of multiple runs into 1 root file? I have a low amount of data, even with 1e9 events; I just need more.

Getting an output for the single/first run to a root file is fine. It’s when the second run starts I get the caught signal memory error. I’ve tried to rename the root file every run in Beginning of RunAction using the run ID, but I’m having trouble doing so, and am not sure if the data of multiple runs can be combine.

BeginOfRunAction

	G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
	if ( G4Threading::IsMultithreadedApplication() ) analysisManager->SetNtupleMerging(true);
	runID = fRun->GetRunID();
	rootFileName = "output" + std::to_string(runID) + ".root";
	if(runID==0){
		analysisManager->OpenFile(rootFileName);
		analysisManager->CreateNtuple("Hits","Hits");
		analysisManager->CreateNtupleDColumn(0,"fEnergy");
		analysisManager->FinishNtuple(0);
	}

EndOfRunAction

	G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
	analysisManager->Write();
	analysisManager->CloseFile();	

	if (isMaster) {
		fRun->SetNeutronSumCount(nCount);
		fRun->EndOfRun();    
	}

Is there any obvious errors?
Is there a geant4 function such as, analysisManager->Merge()?

Thank you.

Dear m.b.james,
I am not an expert, but to my understanding there are two options.

If at the end of each run you close the file then at the beginning of the next run you should also recreate the tuples/histograms and open a new file for them. Especially the tuples are “lost” when you write and close the file. In that case probably it would be better to delete the AnalysisManager (if pre 11.0 geant4) or reset it (since 11.0)

Another possibility is not to write/close the file at the end of each run, so the results will be “appended” to the original file. In this case you have to somehow write and close the file after the last run (could be a closing command that you call by a messenger, or …).

Thank you, I’ll investigate your suggestions.

Solved the issue. I can output multiple .root files (1 for each run) using,
analysisManager->Clear();
analysisManager->Reset();
in BeginRunAction.

Edit.
When the multiple root files were generated, I used the command
hadd -f Results.root output*.root*
This command combine all the root files i generated i.e. output0.root output1.root output2.root …

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