Histogram Not Resetting Between Runs

Hi!

I’m having an issue where my loop defined in macros is working fine, but the histogram is only outputted correctly on the initial run (i.e. every subsequent run outputs an empty histogram). I have tried to reset the histogram in BeginOfRunAction and EndOfRunAction, but the issue seems the same regardless. Is there a standard way of doing this to make sure histograms are correctly populated for every run?

Hello. I am beginner. What do you mean by the following warning? How to manage it.

Hi - not sure if you realise you replied on my post hahah but anyway I usually get that error if I’m missing the following lines from the end of my main.cc code:
delete visManager; delete runManager;

Try adding those in if they’re not in already and that should fix it I think

Oh, I am sorry. I simply posted without realizing it. and thanks for your comment.

this is what I learned from various sources:

void RunAction::BeginOfRunAction(const G4Run* run)
{
    G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();

    // some stuff to set file name depending on runID ...
    G4String fileName = ...

    analysisManager->SetFileName(fileName);
    analysisManager->OpenFile();
}
void RunAction::EndOfRunAction(const G4Run* run)
{
    G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
    G4int nofEvents = run->GetNumberOfEvent();
    if (nofEvents==0) {
        analysisManager->CloseFile();
        return;
    }
    analysisManager->Write();
    analysisManager->CloseFile();
}

Hello,

All histograms should be reset with the CloseFile call unless you ask explicitly not to do it via calling CloseFile(false).

Which version of Geant4 you use ?

Best regards,

Hi,

Yes, it is strange! I am running v4.11.01 if that helps.

Thank you,
Lauryn

Thank you, this version should be ok.

Can you try to run 2 runs with verbose level 4, save your output in a file. This should help you to see that your histograms are filled in the 2nd run, and if they are cleared or reset afterwards, this should also produce a message.