I’m using the /gps/hist/point (E_hi) (Weight) command to generate an energy distribution from SPENVIS for a space-radiation application. Since my text files from SPENVIS provide several data point pairs of incident radiation energy and particle flux (see example below), then I believe that I should use /gps/ene/type Arb (arbitrary point-wise energy spectrum) instead of /gps/ene/type User (User-defined energy histogram). However, I’m not sure what type of particle flux I should use for the “Weight” in /gps/hist/point (E_hi) (Weight).

If I’m irradiating a material using /gps/ene/type Arb, does Geant4 randomly select an energy within the energy bounds that I provide in /gps/hist/point according to the weights that I assign to it? If I use /gps/hist/inter Lin, does Geant4 linearly interpolate the energy and weight of the data points in between the ones that I specify using /gps/hist/point?

Should the “Weight” in /gps/hist/point (E_hi) (Weight) be differential particle flux (cm^-2 s^-1 MeV^-1) or integral particle flux (cm^-2 s^-1)? I think the Geant4 GPS documentation says that both the /gps/ene/type User and /gps/ene/type Arb commands require the user to list the differential energy data points via /gps/hist/point (E_hi) (Weight).

Electron Energy Spectrum from SPENVIS
/gps/ang/type planar
/gps/pos/type Plane
/gps/pos/shape Circle
/gps/pos/centre 0 0 20 cm
/gps/pos/radius 1 cm
/gps/particle e-
/gps/ene/type Arb
/gps/ene/diffspec 1
/gps/hist/type arb

Yes, and yes. If your physics behind the spectrum is some power-law-generating one, I recommend using Log interpolation to avoid funny bumps in the approximated spectrum.

You have /gps/ene/diffspec 1, and it tells Geant4 that the spectrum is differential. Points must be in differential units.

Thank you, this helps a lot! The integral and differential energy spectra that I got from SPENVIS for electrons is shown below. I think I’ll start with a linear interpolation first and I’ll see if that yields satisfactory results before moving on to one of the other interpolation options if needed.

Try plotting a linear interpolation, e.g., in Python, and see what you get in a log-log plot. I do not recommend the linear one unless for a first try.

Thank you for the suggestion! I used MatLab to plot a linear interpolation for an example of an electron and proton energy spectrum that I get from SPENVIS. In the plot below, I arbitrarily chose a 0.5 MeV step size for the interpolation of each spectrum. Of course, if I lower the step size then I get better agreement between the interpolation curves and the data points marked using asterisks (*), and worse agreement when I increase the step size.

By chance, is there some document that discusses the step size/resolution/number of points that Geant4 uses to perform its linear interpolations?

Geant4 goes from point to point. The plots you show are not linear interpolation but rather some running averaging and intelligent smoothing. Interpolation must go through all points of data.

Yes, you’re right. I plotted the previous graph using MATLAB’s linear interpolation function with a relatively coarse step size (0.5 MeV), which yielded suboptimal results. If I use a much finer step size (0.05 MeV), then MATLAB is able to generate points in between my given data points and the actual data points themselves (i.e., the interpolation goes through all points of the given data). The results are shown in the plot below. The interpolation curves are actually several closely spaced data points in the plot and are not a fitting function. Although, I have chosen to draw the interpolation points as a line instead of discrete points so that the given data points (*) are more visible.

By chance, is there some document that discusses the step size/resolution/number of points that Geant4 uses to perform its linear interpolations?

I ask this so that I can understand how Geant4 calculates its linear interpolation. Unlike other software, Geant4 does not seem to have a command for me to specify the step size/number of data points/resolution that it should use in its linear interpolation calculation. And so, I’m worried that Geant4 may use too coarse of a step size, leading to the suboptimal interpolation curves in my previous reply.

Thank you for sharing that link! I think that in order to understand how many points are being used for the linear interpolation, I would have to understand the

line in the source code. The value of imax is used by various for loops to calculate relevant quantities for the interpolation (e.g., the gradients between the data points). However, I’m not sure if Geant4 is setting imax equal to 1024 or if it’s setting imax equal to the number of points defined by the user using the /gps/hist/point command?

I haven’t been able to find what the ArbEnergy.H.GetVectorLength() does from the Geant4 source code. I’ll keep looking into it.