I recently installed GEANT4-v11 on my MacBook, and am currently learning to use it and get familiar with it. Can anybody tell me if the simulation data and results from a GEANT4 simulation can be outputted to a data file such as a text file or a .csv file? I have visual output, and there is some output displayed in the terminal. I am interested to know if there is a way that GEANT4 can be run where an output data file is created.
The simulation output is up to you.
G4Analysis is the package you want to look into, and the documentation: Analysis — Book For Application Developers 11.0 documentation
Thanks mkelsey. I will read over this.
G4Analysis is the most general support. You can write sensitive detectors or stepping action code, and put any quantities you want from the
G4Steps into your output. This is how we have our simulation framework set up.
If there are only simple integrated quantities you care about, you may find that using “scorers” is easier. We don’t do that, because we’re interested in details like which particle deposited energy, where was the energy deposited, etc. See Command-based scoring — Book For Application Developers 11.0 documentation
I checked out the analysis section that you linked above. I found out that Basic Examples B4 and B5 have output Root histograms and ntuples, as well as a .root file. I now have a question about how these histograms are constructed and filled. In Basic Example B4, the source file RunAction.cc contains the following lines of code that create four histograms:
analysisManager->CreateH1(“Eabs”,“Edep in absorber”, 100, 0., 800MeV);
analysisManager->CreateH1(“Egap”,“Edep in gap”, 100, 0., 100MeV);
analysisManager->CreateH1(“Labs”,“trackL in absorber”, 100, 0., 1m);
analysisManager->CreateH1(“Lgap”,“trackL in gap”, 100, 0., 50cm);
and the source file EventAction.cc contains the following four lines of code that fill the histograms:
In my experience using Root, 1-D histograms are filled with one variable. These are filled with two variables, the first one being a number. What does this number mean?
And if I want to add a 2-D histogram in these files that plots fEnergyAbs against fTrackAbs, how would I do that?
the number is the index of the histogram you are filling.
2d is quite straight forward: you basically add the additional definition to the commands and replace 1 with 2. filling is then with 3 parameters: index, first value and second value.
Okay, thanks weller. I attempted the following. In RunAction.cc, I added the following line of code after those I listed above:
analysisManager->CreateH2(“Labs_vs_Eabs”,“ScatterPlot”, 100, 0., 800MeV, 100, 0., 1m);
and in EventAction.cc, I added the following line of code after those I listed above:
analysisManager->FillH2(4, fEnergyAbs, fTrackLAbs);
The the .root output file, the histogram was created, but no data was filled into it. Was there anything I missed?
When you say “no data”, do you mean no realistic values, or the histogram had identically zero entries? I presume that you have code in your EventAction to ensure that your variables of interest (fEnergyAbs, etc.) are accumulating data from the tracks in your event. This is usually done via a sensitive detector or a SteppingAction.
The histogram has zero entries. Is there anything in SteppingAction I need to do to fill the histogram? fEnergyAbs, etc. are already being filled into other histograms in the example.
I must have misunderstood. It’s only the 2D that isn’t being filled? All your other histograms and N-tuples are populated normally? That’s really weird.
One thing I can think of (but check the documentation to be sure): I have a vague memory from long ago that G4Analysis kept separate containers for each histogram type, so all the 1D plots would be indexed from 0 to N(1D)-1, the 2D plots would be indexed from 0 to N(2D)-1 and so on.
We don’t use G4Analysis in our simulation framework, so I’m not really set up to test this myself.
index starts from 0 again, as mkelsey correctly remembers, the counting is separate for each type.
fyi: using ``` for code blocks makes them look pretty
It worked! Thank you!