Ability to delete histograms after creation

Hi,

I’m writing a simulation with different geometries, using 2D and 3D histos to store the dose output. I am creating them at the time that the geometry is created. If I change the geometry using a macro, I clean the volume stores and rebuild the world with the new geometry and create new histograms. However, my old histograms persist and take up space in memory.

Is there an equivalent method or way to clear the histograms in the analysis manager?

I’ve been implementing something doing this:

G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();

G4int n_H1s = analysisManager->GetNofH1s();
G4int n_H2s = analysisManager->GetNofH2s();
G4int n_H3s = analysisManager->GetNofH3s();

if (n_H1s > 0)
{
	for (G4int i=0; i<n_H1s; i++)
	{
		auto hist = analysisManager->GetH1(i);
		delete hist;
	}	
}
if (n_H2s > 0)
{
	for (G4int i=0; i<n_H2s; i++)
	{
		auto hist = analysisManager->GetH2(i);
		delete hist;
	}	
}
if (n_H3s > 0)
{
	for (G4int i=0; i<n_H3s; i++)
	{
		auto hist = analysisManager->GetH3(i);
		delete hist;
	}	
}

but analyisManager, or G4ToolsAnalysisManager is trying to save a “deleted” histogram. This makes sense seeing as I’m simply de-allocating the memory without telling the analysisManager to forget about the histogram too.

Hello,

At present, the analysis manager does not provide functions to delete individual histograms. This is considered for the future release.
You can however change the existing histograms properties via SetHn[Pn] functions, or equivalent commands.
Or, it is also possible to delete the analysis manager instance, and then create a new one.

Best regards,