Ntuple merging MT: issue with Filename and empty files


I have an issue a bit similar to Accumulate data from several runs in multithread mode but my case is a little bit different.

Through a .mac file I am looping over different ions and different energies and producing histograms and recently Ntuples. I am facing 2 issues for Ntuples related both to the command: analysisManager->SetNtupleMerging(true).

First, I get empty files t# remaining for the first (ion,energy) pair, while I have the actual merged file in the global root file that also contains the histograms.

Secondly for other (ion,energy) after, no t# files are present but two Ntuples are created. One empty and the second one with the column branches.
I also get this warning:
-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : Analysis_W012
issued by : G4VFileManager::SetFileName()
Cannot set File name as its value was already used.
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

I am adding a screenshot with TBrowser of this structure.

To add more details here are the codes used (non exhaustive):
auto analysisManager = G4AnalysisManager::Instance();
G4cout << "Opening output file " << fFileName << " … ";

analysisManager->CreateNtuple(“Landau”, “Edep and TrackLength”);
// If analysis is used reset the histograms
HistoManager* analysis = HistoManager::getInstance();
analysisManager->FillNtupleDColumn(0,0, run->GetRunID());
analysisManager->FillNtupleDColumn(0,1, nhist-1);
analysisManager->FillNtupleDColumn(0,2, edep);
HistoManager* analysis = HistoManager::getInstance();
void HistoManager::EndOfRun()
auto man = G4AnalysisManager::Instance();


Could you, please, post also the content of HistoManager::EndOfRun(), which is called from RunAction::EndOfRunAction.

Do you call analysis/setFileName function in your macro?

I added the HistoManager::EndOfRun() in previous post.
I use a created command:
/mycmd/analysis/setHisto Result/{particleloc}/config{ndetector}{particleloc}{eKinLoc}MeV_nucl
which uses the public function of HistoManager to set the file name:
void SetHistoName(G4String name) {fFileName=name;}

Thank you. I overlooked that you added HistoManager::EndOfRun() after the RunAction functions.

The booking of ntuple in your application is the same as what we have in the AnaEx01 example (in the extended/analysis category), but I cannot reproduce your warnings with Geant4 10.5.p01.

Could you, please, let me know which Geant4 version you use?

Thank you,

I am currently using geant4-10-05-patch-01 [MT] (17-April-2019)

Thank you.

It is still not clear from above when you set new file name. The warning which you observe tells you that you are trying to change a file name when the file with a previous name is still in use. Could you try to check this, and make sure that a new file name is set when the previous file was written and closed?

Also, could you test if you try to run just 1 run with one file name, do you see any extra *_tn.root files or empty ntuples?

Sorry for the delay. My problem is not yet solved but I tried several things and figured out that the structure I was using might not be adequate. I mixed the TestEM11 codes with the advanced gammaray telescope analysis code.
Although it worked well for the Histograms, I am facing the previous issues for ntuples when attempting to merge them. I also tested the example directly and just added the SetNtupleMerging(true); but the same issue happened of empty ntuples.

I decided to revert to TestEM11 analysis structure. However, I face a different issue where my histograms, while defined in the code, do not exist, exept histogram 0 which exists but not with the set parameters. This issue was the reason I initially tried to implement the Gammaray Telescope analysis code.
I am linking my updated HistoManager.cc (2.8 KB) . The RunAction is the same as TestEM11 with the exception of the if ( analysisManager->IsActive() ) which are now always fulfilled.

In TestEM11 histograms need to be activated and set manually but my objective is to use parameters from the geometry to fix the parameters of the histograms and their number. I would like thus to not require activation.

Thanks in advance for your help.

I found my issue was coming from the Detector parameters not yet evaluated at the Runaction initialization stage. I thus moved the creation of histogram to BeginOfRunAction.