How to product a SOBP

Hello Zhuhuaiyu,

The source routine I provided you manages just the particles energy spectrum.
If you want to add the beam size, you need to sample it, and add it to the particle coordinates (see also this discussion: Beam sizes when using source.f).

If you want to proceed with this source routine, my suggested approach to sample from a rectangular source would be:

  1. Sample a random variable between zero and one with FLRNDM(DUMMY)
  2. Select the limits XLOW and XHIGH of the rectangular distribution for x and y (in your case, respectively -7 and +7).
  3. Sample one random x (and then y) position from the uniform distribution:
XFLK(NPFLKA) = XBEAM + XLOW  + ( XHIGH - XLOW ) * FLRNDM(DUMMY)

Remember that this approach works only if the frame of reference of the beam is not rotated in respect of the cartesian one, otherwise you would need to add another rotation.
Cheers,
Daniele