B1 write out from multiple events

Hello!

I am working with a simulation based off of B1 where the only thing I changed significantly was the geometry, as well as adding stuff from the G4AnalysisManager so that I get a csv file with the energy deposited written to it. I want to run a macro file with many different /BeamOn commands, each one corresponding to a different energy, so I can scan the effects of a muon hitting my object at different energies.

When I run my macro file with the 50 different /BeamOn commands, my output file only has one number. I suspect it is only saving the enrgy deposition of the last run. Is there a way to make it so it saves the energy deposition from all runs, like in a big array?

I am not an expert, but to my knowledge, you either have to write to the same file without closing it in between the different runs/BeamOn commands (especially if you are using tuples), but only once at the end of the macro file, or you have to close and open a different file for each run.

Hello,
You can change the output filename by the UI command:

/analysis/setFileName myrun1
/run/beamOn 1
/analysis/setFileName myrun2
/run/beamOn 1
...

You can see this usage in basic example B5 and run2.mac macro.

Best regards,