I’m new to Geant4 and trying to make a simple application which is supposed to be very similar to example B1. So I started with that example and tweaked it a little. My particlegun shoots neutrons on a polyethylene box and I want to know the energy spectrum of the neutrons coming out of the polyethylene. I set up a sensitive detector directly behind the polyethylene and in the ProcessHits method I get the kineticEnergy.
But I don’t know how I can get this energy to output in a csv. In general, I am quite lost in the application of Hit, Hitcollections and Analysis altogether. Could someone help me out?
Hi, I am interested to this topic, did you get a spectrum from a similar B1 example application? I would like to get the energy output spectrum for a gamma source Inside a spherical detector. What did you modify in the B1 example for get an output file?
Thanks in advance
Yeah, or with Python. What I did in the end was making my polyethyelene box a SensitiveDetector and in processHits method find the step->GetPreStepPoint->GetVolume and the step->GetPostStepPoint->GetVolume. Then if the preVolume is my sensitive detector and the postVolume is World then I get the kineticEnergy and write it to an Ntuple. Collecting the data from the Ntuple with Python or Matlab should be easy.
Thank you for your answers I got the energy output spectrum for a gamma source by writing in a csv file. Then I plotted a histogram on Matlab.
I am a new Geant4 user without a lot a c++ knowledges. Could you please help me to set my source as an isotropic source? On example B1 I would like to change parameters for seting a isotropic source. Do I have to set it on fParticleGun, if yes with which function?
I recommend the General Particle Source. Once established in your application you can control the source in many useful ways. See examples/extended//eventgenerator/exgps.