# User routine source\_newgen.f

**URL:** <https://fluka-forum.web.cern.ch/t/user-routine-source-newgen-f/5946>\
**Category:** Advanced Features and User Routines\
**Created:** [22 April 2024 06:23 UTC](https://fluka-forum.web.cern.ch/t/user-routine-source-newgen-f/5946 "2024-04-22T06:23:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcuemo](https://fluka-forum.web.cern.ch/letter_avatar_proxy/v4/letter/a/cab0a1/32.png) [@alcuemo](https://fluka-forum.web.cern.ch/u/alcuemo)\
**Post date:** [22 April 2024 06:23 UTC](https://fluka-forum.web.cern.ch/t/user-routine-source-newgen-f/5946/1 "2024-04-22T06:23:48Z")

</div>

Dear FLUKA experts,  
How do I best implement a spectrum like this in the source user routine: (dN/dE=N/E e^(-E/10MeV)  
Thank you,  
Alejandra

---

<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:** [22 April 2024 06:47 UTC](https://fluka-forum.web.cern.ch/t/user-routine-source-newgen-f/5946/2 "2024-04-22T06:47:41Z")

</div>

Dear Alejandra,

you can find a brief summary on how to sample from an arbitrary function on slides 22-24 from here:

> **[04\_Source\_routine\_2023\_Advanced\_ANL.pdf](https://indico.cern.ch/event/1200922/contributions/5411811/attachments/2659968/4607569/04_Source_routine_2023_Advanced_ANL.pdf)**

Alternatively, you can pre-calculate the spectrum, and use the spectrum sampling function of the user routine.

Cheers.  
David

---

<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:** [6 May 2024 06:54 UTC](https://fluka-forum.web.cern.ch/t/user-routine-source-newgen-f/5946/3 "2024-05-06T06:54:37Z")

</div>

Closed on 6 May 2024 06:54 UTC


