2 Particles in a fixed distance


I would like to shoot 2 photons in specific positions, in a fixed distance between them.
Can I do directly from the configuration file or do I have to create a geant source macro file?

Thank you a lot in advance :slight_smile:

P.S.: And if someone knows or can give me any info in how to do this in the geant macro file it would be very helpful, since I have no experience with Geant.

Hi @Peni123,

In the [DepositionGeant4] module you can include:

source_type = "macro"
file_name = "twoParticles.mac"

where twoParticles.mac is the name of the macro. A macro example that works for me with two electrons at fixed positions is:

/gps/particle e-
/gps/pos/type Point 
/gps/pos/centre 0.01 0 -10 mm 
/gps/ene/mono 5 GeV 
/gps/direction 0 0 1 
/gps/intensity 1

/gps/source/add 1
/gps/particle e-
/gps/pos/type Point 
/gps/pos/centre 0.01 0.02 -10 mm 
/gps/ene/mono 5 GeV 
/gps/direction 0 0 1 
/gps/source/multiplevertex 1

Hope that helps :slight_smile: Let me know if you have any problems adapting the code.


Dear Sara,

Thank you a lot for your response! It helped a lot.
But what happens if I want a flat beam with a specific radius for each one of them?
Does the point represent that?

Thank you again!

Hi @Peni123

have a look at the commands you can use in the Geant4 documentation here. For a flat beam at two positions, change the type for example to

/gps/pos/type beam

or to

/gps/pos/type plane
/gps/pos/shape circle


Hi Simon,

Thank you a lot for your response too. I will look through the documentation as well.


Hello again @simonspa and @ruizdaza .
Thank you a lot for your previous answers. I would like to ask you something else relevant in case you know. Because I cannot find something relevant in the gps documentation. I would like to have the two particles in a range of distance (d) between them i.e. 2 mm < d < 6 mm. Do you know if I can do that? When I add the second particle to define the range of distance relevant to the other?
Thank you very much in advance.
Kind regards

Hi @Peni123

this sounds like it could be easiest be done by defining a rectangular source (see DepositionGeant4 module documentation) with the relevant distance as size, and the to shoot two particles. They will appear at random positions within the square, so their distance is within the rectangle size. Is this roughly what you want?

Ah, the lower limit 2mm is then missing, hm…
And the position of the first particle should be fixed?

You really make me curious about what you simulate there :slightly_smiling_face: Maybe I have a chance to hear about it at our next workshop? 3rd Allpix Squared User Workshop (9-11 May 2022): Overview · Indico


Hi @simonspa ,

Thank you very much for your answer and your proposal but I what I am doing is very low level still so it is better to wait for the next year!
Basically what I want in a uniform beam with radius 55 mm these two particles to be shot in different positions with distance between them i.e. 2 mm < d < 6 mm. But if there is another option in which maybe the one will have fixed position I can have this for now.
I asked also geant people and they told em to use the G4ParticleGun, which I guess is not an option here.

Thank you a lot in advance! :slight_smile:

Hi @Peni123 ,

this sounds indeed hard to realise. I see two simple solutions (and there are probably plenty of more complex ones):

  • Define a 55 mm wide beam with two photons and then, in post-analysis, filter the events such that you only analyse the ones that match your distance requirements
  • Define a 6 mm beam that, in several runs, illuminate small sectors of your sensitive area.


Hi Paul,
I also have to implement something similar. How do you suggest that I can filter the events in the analysis? I use an output that looks like the RCEWriter and I cannot think a straightforward way to do it.


Hi @rkotitsa ,

this would depend on the processing of your simulated data. I was naively thinking of a script/programme, in which you read in the data from Allpix Squared, get the MCParticle objects and their positions and only write data, if the distance suits your case. Now, with the RCEWriter or another writer module that uses only PixelHit objects, this of course doesn’t work well.

If you did program your own module for writing, you could as well try to implement it there, as you can simply subscribe to the MCParticle message and do a filtering there.