# Phase-space sampling

**URL:** <https://fluka-forum.web.cern.ch/t/phase-space-sampling/6841>\
**Category:** Source Definition\
**Created:** [19 December 2024 04:56 UTC](https://fluka-forum.web.cern.ch/t/phase-space-sampling/6841 "2024-12-19T04:56:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![131415248](https://fluka-forum.web.cern.ch/letter_avatar_proxy/v4/letter/1/35a633/32.png) [@131415248](https://fluka-forum.web.cern.ch/u/131415248)\
**Post date:** [19 December 2024 04:56 UTC](https://fluka-forum.web.cern.ch/t/phase-space-sampling/6841/1 "2024-12-19T04:56:11Z")

</div>

Dear FLUKA experts,  
I have recently been researching how to use the phase-space sampling feature in source\_newgen.f. I would like to know if the phase-space file requires knowing the exact energy values for each particle, and how to use the phase-space function to set the energy spectrum for particles in each coordinate.

---

<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:** [7 January 2025 08:30 UTC](https://fluka-forum.web.cern.ch/t/phase-space-sampling/6841/2 "2025-01-07T08:30:11Z")

</div>

Dear Yingming,

the phase-space file should have a momentum/energy value for each line, but it is possible to override it in the user routine:

Instead of the line:

```
 momentum_energy = phase_space_entry%m_e

```

you can use a standard sampling function, for example:

```
momentum_energy = sample_spectrum_momentum_energy( [filename], [unit] )

```

Cheers,  
David

---

<div class="post-metadata">

**Author:** ![131415248](https://fluka-forum.web.cern.ch/letter_avatar_proxy/v4/letter/1/35a633/32.png) [@131415248](https://fluka-forum.web.cern.ch/u/131415248)\
**Post date:** [8 January 2025 05:34 UTC](https://fluka-forum.web.cern.ch/t/phase-space-sampling/6841/3 "2025-01-08T05:34:44Z")

</div>

Dear David,

Thank you for your reply, but I have another question.

If I can only determine the energy spectrum within a range and cannot obtain the exact information of individual particles required by the phase space file format, such as coordinates and cosines, what should I do?

If I directly set the coordinate range of the energy spectrum as shown in the figure, is it still necessary to include x, y, z in the phase space file?

![energy spectrum](https://fluka-forum.web.cern.ch/uploads/default/original/2X/4/4075daf666037372d4600104b619f1ddeb601829.png)

Many thanks,  
Yingming

---

<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:** [8 January 2025 09:21 UTC](https://fluka-forum.web.cern.ch/t/phase-space-sampling/6841/4 "2025-01-08T09:21:52Z")

</div>

Dear Yingming,

the phase-space sampling requires all the numbers present, but it is up to you if you put dummy values for some parameters and don’t use them in the routine.

It is perfectly fine to use standard sampling in place of phase-space sampling (if it describes your case adequately).

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:** [28 January 2025 10:29 UTC](https://fluka-forum.web.cern.ch/t/phase-space-sampling/6841/5 "2025-01-28T10:29:28Z")

</div>


