# Multiple beams using source routine

**URL:** <https://fluka-forum.web.cern.ch/t/multiple-beams-using-source-routine/2575>\
**Category:** Advanced Features and User Routines\
**Created:** [22 December 2021 17:25 UTC](https://fluka-forum.web.cern.ch/t/multiple-beams-using-source-routine/2575 "2021-12-22T17:25:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cspalacios](https://fluka-forum.web.cern.ch/letter_avatar_proxy/v4/letter/c/50afbb/32.png) [@cspalacios](https://fluka-forum.web.cern.ch/u/cspalacios)\
**Post date:** [22 December 2021 17:25 UTC](https://fluka-forum.web.cern.ch/t/multiple-beams-using-source-routine/2575/1 "2021-12-22T17:25:30Z")

</div>

Dear FLUKA and FLAIR experts,

I need some clarification.

Let’s say I have 3 different particles in a beam.

Using my source routine I would have something like this

> [@Multiple complex source in Fluka](https://fluka-forum.web.cern.ch/t/multiple-complex-source-in-fluka/1241/2):
>
> Dear ArghyaC, unfortunately, the SPECSOUR card is ignored if a source routine is linked. So you need to specify each beam parameter in the routine. You can select a beam like: random = FLRNDM(XDUMMY) if (random .lt. beam1\_probablility) then beam\_1\_parameters ... else if (random .lt. beam1\_probability + beam2\_probability) then beam\_2\_parameters ... else if (random .lt. beam1\_probability + beam2\_probability + beam3\_probability) then beam\_3\_parameters ... else beam\_4\_parameters ... …

My questions are:

1.- For every primary, I would have only one particle at random taking into account its probability. This process would be similar to what SPOTBEAM card does using spot weights. Is this correct?

2.- Is there a way to have multiple particles at the same time instead of one per primary in my simulation? Each kind of particle having a different distribution defined by source.f

Thank you in advance.

Best Regards,  
Carlos

---

<div class="post-metadata">

**Author:** ![horvathd](https://fluka-forum.web.cern.ch/user_avatar/fluka-forum.web.cern.ch/horvathd/32/10584_2.png) [@horvathd](https://fluka-forum.web.cern.ch/u/horvathd)\
**Post date:** [5 January 2022 15:20 UTC](https://fluka-forum.web.cern.ch/t/multiple-beams-using-source-routine/2575/2 "2022-01-05T15:20:58Z")

</div>

Dear Carlos,

1. Yes, this it the same idea as the spot weights.

2. It is possible to have multiple primaries in a single event in FLUKA. However, if you are not utilizing event-by-event scorings ( **EVENTBIN** , **DETECT** , etc.), the results will be the same as having only one primary particle in an event.

Cheers,  
David

---

<div class="post-metadata">

**Author:** ![cspalacios](https://fluka-forum.web.cern.ch/letter_avatar_proxy/v4/letter/c/50afbb/32.png) [@cspalacios](https://fluka-forum.web.cern.ch/u/cspalacios)\
**Post date:** [10 January 2022 11:14 UTC](https://fluka-forum.web.cern.ch/t/multiple-beams-using-source-routine/2575/3 "2022-01-10T11:14:42Z")

</div>

Dear David,

Thank you for your reply.

To your second point. I am using EVENTBIN for scoring, so I want to be able to have multiple primaries per event, but I am unable to do so.

Could you point me on how to do it?

Best Regards,  
Carlos

---

<div class="post-metadata">

**Author:** ![horvathd](https://fluka-forum.web.cern.ch/user_avatar/fluka-forum.web.cern.ch/horvathd/32/10584_2.png) [@horvathd](https://fluka-forum.web.cern.ch/u/horvathd)\
**Post date:** [11 January 2022 10:10 UTC](https://fluka-forum.web.cern.ch/t/multiple-beams-using-source-routine/2575/4 "2022-01-11T10:10:10Z")

</div>

Dear Carlos,

you need to duplicate the main part of the source routine to put another particle into the stack.

For example see: [source.f](https://fluka-forum.web.cern.ch/uploads/short-url/1hiR8c3Fdt0g32LZJsNp9XLRVSL.f) (15.0 KB)  
This user routine will add a proton and an electron to the stack with different energies and starting points.

Cheers,  
David

---

<div class="post-metadata">

**Author:** ![cspalacios](https://fluka-forum.web.cern.ch/letter_avatar_proxy/v4/letter/c/50afbb/32.png) [@cspalacios](https://fluka-forum.web.cern.ch/u/cspalacios)\
**Post date:** [11 January 2022 14:04 UTC](https://fluka-forum.web.cern.ch/t/multiple-beams-using-source-routine/2575/5 "2022-01-11T14:04:52Z")

</div>

Dear David,

I am bit unfamiliar with source.f syntaxis. Is there a way to add to the stack using source\_newgen.f syntaxis?

Best Regards,  
Carlos

---

<div class="post-metadata">

**Author:** ![horvathd](https://fluka-forum.web.cern.ch/user_avatar/fluka-forum.web.cern.ch/horvathd/32/10584_2.png) [@horvathd](https://fluka-forum.web.cern.ch/u/horvathd)\
**Post date:** [11 January 2022 14:16 UTC](https://fluka-forum.web.cern.ch/t/multiple-beams-using-source-routine/2575/6 "2022-01-11T14:16:47Z")

</div>

Dear Carlos,

technically it is possible to use the _source\_newgen.f_ user routine. However with _source\_newgen.f_ you can sample only from one histogram, without significant changes.

You can find the description of the _source.f_ user routine here: [13.2.20} source.f: user-written source | FLUKA](https://flukafiles.web.cern.ch/manual/13.2.20.html)

Cheers,  
David

---

<div class="post-metadata">

**Author:** ![rversaci](https://fluka-forum.web.cern.ch/letter_avatar_proxy/v4/letter/r/cc9497/32.png) [@rversaci](https://fluka-forum.web.cern.ch/u/rversaci)\
**Post date:** [11 February 2022 07:46 UTC](https://fluka-forum.web.cern.ch/t/multiple-beams-using-source-routine/2575/7 "2022-02-11T07:46:41Z")

</div>


