Hi Geant4 Experts:
I am simulating a gamma source with user defined energy histogram in /gps commands. The gpsSrc.mac command is:
# Energy and Spectrum
# beam position define
/gps/pos/centre 0 0 0 cm
/gps/pos/radius 10 cm
/gps/pos/halfz 5 cm
I define my energy spectrum with the /gps/hist/file command, the content of gammaHist.txt is:
There are 301 lines in the gammaHist.txt file in total. When I run my code, the program can be compiled and initialized with no error, however, when I try to /run/beamOn some primary, then program crashed with “Segmentation fault (Address not mapped to object [(nil)])”.
I use gdb to track the error and it returns:
Thread 11 "BNCTrun" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffcf7fe640 (LWP 452)]
0x00007ffff78a2d76 in G4SPSEneDistribution::GenUserHistEnergies() () from /intall_path/geant4-v11.0.1-install/lib/libG4event.so
Looks like that the histogram related commands have error in executing, if I use /gps/ene/mono instead of the histogram, everything goes OK.
Are there any examples on how to construct a gamma source with energy spectrum defined by /gps/hist/file command? I can hardly fine an example about this, I have seen other threads in this forum which describe the spectrum with /gps/hist/point, but that is not what I want.
Thanks in advance.
_Operating System:_windows subsystem for linux (WSL2), ubuntu 22.04 LTS
_Compiler/Version:_gcc version 11.4.0
Can you try with the absolute path of gammaHist.txt defined in your gpsSrc.mac?
Example: /gps/hist/file /home/path/to/spectrum/gammaHist.txt
Thank you James. I try to use the full path of the histogram file, but the program broke again.
It seems that if you want to use /gps/hist/file, it will only work with an Arb energy distribution. That is:
You would need to change the data in the input txt file to be normalised correctly for an arb distribution in that case, so you get the correct equivalent histogram being used by PrimaryGeneratorAction.
Otherwise you could use the User defined histogram as before, but change your input data to be in the /gps/hist/point form:
with gammaHist.mac defined as:
/gps/hist/point 0 0
/gps/hist/point 0.01 4.1965e-06
/gps/hist/point 0.02 0.000197235
/gps/hist/point 0.03 0.000684029
/gps/hist/point 0.04 0.00118761
/gps/hist/point 0.05 0.00154431
/gps/hist/point 2.91 0
/gps/hist/point 2.92 0
/gps/hist/point 2.93 0
/gps/hist/point 2.94 0
/gps/hist/point 2.95 0
/gps/hist/point 2.96 0
/gps/hist/point 2.97 0
/gps/hist/point 2.98 0
/gps/hist/point 2.99 0
/gps/hist/point 3 0
Hopefully this gives you something to work from.
Possibly another user can confirm or provide suggestion to get “/gps/hist/type energy” to work with “/gps/hist/file”.
Thank you very much James, I try the Arb type and there is no error reported, the program works correctly.
By the way, what is the difference between Arb spectrum and User-histogram spectrum? Looks in the Arb spectrum there is an additional /gps/hist/inter command to do the interpolation work while in the User-histogram there is no interpolation.