Difference of sources in Geant4 and Allpix

In my Geant 4 code my gps source is described as below:
/gps/particle neutron
/gps/direction/ 0 0 1
/gps/pos/radius 0.5 cm
/gps/pos/centre 0.70025 0.70125 4. cm
/gps/pos/type Beam
/gps/pos/shape Circle
/gps/ang/type beam2d
/gps/ene/mono 0.0253 eV

I have tried using this as a macro in AllPix but it does not accepts /gps/direction 0 0 1, and gives below error:
WARNING: Ignoring Geant4 macro command: “/gps/direction 0 0 1” - not related to particle source.

Hence I tried normal implementation in allpix input configuration file. As below:
particle_type = “neutron”
source_energy = 0.0253eV
number_of_particles = 1
source_position = 0um 0um -10mm
source_type = beam
beam_size = 0.5cm
beam_divergence = 0 0
beam_direction = 0 0 1
max_step_length = 0.25um
range_cut = 0.25um
output_plots = 1
output_plots_scale = 500ke

The problem is that now my beam is too wide as compared to my geant4 beam and is going out of sensor. In Geant 4 it stays well within the sensor location. Can you please let me know what am I doing wrong?


Hi Sanchit,

the problem with your macro is that we were very restrictive which commands could be used. I added the /gps/direction/ command to the pallette of allowed commands now (see here: https://gitlab.cern.ch/allpix-squared/allpix-squared/merge_requests/220) Once the merge request has been merged to master your macro should work just fine.

The difference between your macro and the configuration is that you simulate a circular beam with a fixed radius, while Allpix^2 generates a beam with a Gaussian profile with a sigma of size beam_size. This is why you get a larger beam in the second example.



Thanks very much for the explaination. Can you please let me know about when the merge request would be merged to master ? I just wanna know the time it takes generally.

Sanchit Sharma

Hi Sanchit,

since it’s only a small code change, probably not more than a few days. It always depends on who is around to do a code review.

Best regards,

Hi Sanchit,

MR!220 https://gitlab.cern.ch/allpix-squared/allpix-squared/merge_requests/220 has just been merged. Beware that you currently define the source position via /gps/pos/centre in your macro, which is not yet possible.

The reason is that we automatically extend the G4 world volume to always include the source, so it has to be set via the Allpix Squared parameter source_position in the same module. We might change this in the future though.


1 Like

Hi @simonspa
Just a quick question about beam direction options implemented in Allpix2, Is changing the beam direction from z-axis to x-axis direction possible?

I would like to have my beam in the x-axis direction, so I tried doing that by changing the value of the parameter “beam_direction” in the config file, by simply replacing:
beam_direction = 0 0 1 with beam_direction = 1 0 0, as it is done in GEANT4

But I don’t see any change in the beam direction when viewing the geometry in view3Dscene! It is always directed toward the z-axis!! What could be causing that?

Thanks :slight_smile:

Hi @Tasneem,

there was/is some issue in Geant4 with defining a beam shape and a direction, but this should have been taken care of in https://gitlab.cern.ch/allpix-squared/allpix-squared/merge_requests/241 - so I would expect this to work. Make sure to use the latest version, 1.4.3, just in case.

Did you check that it is an issue in the simulation and not just in the visualization? Sometimes it is hard there to see where axis are pointing to.


The issue is in the simulation, not in the visualization. But the reason I have this problem is that I have got the version 1.4-stable of the code, where the bug has not been solved yet. I should have got the latest version 1.4.3 instead.
For the moment, I implemented the needed modifications by performing a rotation of the coordinate system so that it aligns with the Z-axis, the same way it is done in GEANT4, and it is working now!

Thanks a lot for your suggestions @simonspa