Geant4 Version: 11.2.1
Operating System: Fedora 40
Compiler/Version: gcc 14.1.1
CMake Version: 3.28.2
Hello people, first post here. I’m a geant newbie.
My issue is pretty simple.
I have a simulation that has to save data to histograms. The histogram is created inside BeginOfRunAction() with the following code
auto analysisManager = G4AnalysisManager::Instance();
G4String fileName = "B4.root";
analysisManager->OpenFile(fileName);
analysisManager->CreateH1("Counts", "Revealed neutrons", 100, 1e-12*GeV, 10*GeV, "GeV", "none", "log");
The histogram is then filled in EndOfEventAction() like this
if (fEdep >= 0.01*MeV) {
analysisManager->FillH1(1, particleEnergy);
}
(the ID is indeed 1 because there is also the edep histogram)
then in EndOfRunAction() there is
auto analysisManager = G4AnalysisManager::Instance();
analysisManager->Write();
analysisManager->CloseFile();
I then have a run.mac macro. If in the macro I put exclusively
/gun/particle neutron
/gun/energy 1 MeV
/run/beamOn 10000
everything works fine for whatever energy: I get my B4.root file that has the values I want.
The problem though is that I have to run this using multiple energies, so what I would like to do is put inside my macro multiple runs like this
/gun/particle neutron
/gun/energy 1 MeV
/run/beamOn 10000
/gun/energy 10 MeV
/run/beamOn 10000
/gun/energy 100 MeV
/run/beamOn 10000
If I do this, inside B4.root multiple histograms are created (the correct number) called Counts;1 Counts;2 and Counts;3 BUT only ONE of them contains any entries (only for one energy and not even the same amount that running that energy alone gives me), the other two are empty. Mind you that running 10 MeV or 100MeV alone does instead give me entries.
The ideal thing would be having exclusively one histogram with all the entries, but as far as I can understand you create histograms at the begin of RunAction and one beamOn command constitutes a run. The middle ground of having different histograms and opening them up manually (or with a root macro) to get the data out is fine, but having every single time to change the macro > recompile everything and rerun is a bit tedious.
Do you have an idea as to why this might be? Thank you for the help.