# How do I make the correct non-uniform sampling along the depth direction?

**URL:** <https://fluka-forum.web.cern.ch/t/how-do-i-make-the-correct-non-uniform-sampling-along-the-depth-direction/3338>\
**Category:** Source Definition\
**Created:** [29 June 2022 22:23 UTC](https://fluka-forum.web.cern.ch/t/how-do-i-make-the-correct-non-uniform-sampling-along-the-depth-direction/3338 "2022-06-29T22:23:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fengfengxu](https://fluka-forum.web.cern.ch/user_avatar/fluka-forum.web.cern.ch/fengfengxu/32/3529_2.png) [@fengfengxu](https://fluka-forum.web.cern.ch/u/fengfengxu)\
**Post date:** [29 June 2022 22:23 UTC](https://fluka-forum.web.cern.ch/t/how-do-i-make-the-correct-non-uniform-sampling-along-the-depth-direction/3338/1 "2022-06-29T22:23:47Z")

</div>

Dear Experts,

After a period of study, I still haven’t solved the previous problem,I continue with the previous topic.

[[Nonuniformly distributed volume source construction](https://fluka-forum.web.cern.ch/t/nonuniformly-distributed-volume-source-construction/2929)]

I looked for the old official tutorial,Despite the details, my programming ability cannot turn it into an executable program,this question bothers me.

 ![屏幕截图 2022-06-30 060119](https://fluka-forum.web.cern.ch/uploads/default/original/2X/d/d2ae61e947b22011c12d4a142e69e855fc851716.png)

According to my idea, this should be modified on the basis of the program defined by the regional source, but it seemed as if my idea was very immature.  
[disk.flair](https://fluka-forum.web.cern.ch/uploads/short-url/vqzDJyG4ucpcwc1PECGb2SlMZQM.flair) (3.0 KB)  
[disk.inp](https://fluka-forum.web.cern.ch/uploads/short-url/7Xu9sxeb9bg8MO3wI4cJ5QOEiQq.inp) (2.3 KB)  
[source.f](https://fluka-forum.web.cern.ch/uploads/short-url/b84ZLnk1Mn9HQF8yS8H34STQOBd.f) (9.8 KB)

I would like to ask the expert how I can get a distribution similar to the official tutorial:  
y=exp( -A \* x)

Maybe the problem is simple, but it’s really troubling!  
Thanks in advance！  
fengfeng

---

<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:** [30 June 2022 06:11 UTC](https://fluka-forum.web.cern.ch/t/how-do-i-make-the-correct-non-uniform-sampling-along-the-depth-direction/3338/2 "2022-06-30T06:11:42Z")

</div>

Dear Fengfeng,

as this is not a FLUKA, but a mathematical question, you can find many places, where sampling from probability distributions is explained, like [this one](https://web.mit.edu/urban_or_book/www/book/chapter7/7.1.3.html).

Cheers,  
David

---

<div class="post-metadata">

**Author:** ![fengfengxu](https://fluka-forum.web.cern.ch/user_avatar/fluka-forum.web.cern.ch/fengfengxu/32/3529_2.png) [@fengfengxu](https://fluka-forum.web.cern.ch/u/fengfengxu)\
**Post date:** [30 June 2022 08:53 UTC](https://fluka-forum.web.cern.ch/t/how-do-i-make-the-correct-non-uniform-sampling-along-the-depth-direction/3338/4 "2022-06-30T08:53:06Z")

</div>

Dear Professor David，

```
    I set the increment to ：

```

t=-(1/A)log(1-FLRNDM( z ))

I got the following results, I think it is in line with expectations, what do you think?  
 ![屏幕截图 2022-06-30 164917](https://fluka-forum.web.cern.ch/uploads/default/original/2X/7/7c37d89d95dd414869c30a6ed77689ed4b8e5202.png)

Thanks in advance！  
fengfeng

---

<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:** [30 June 2022 13:06 UTC](https://fluka-forum.web.cern.ch/t/how-do-i-make-the-correct-non-uniform-sampling-along-the-depth-direction/3338/5 "2022-06-30T13:06:05Z")

</div>

Dear Fengfeng,

Unfortunately I can’t verify if your implementation is correct or not based on a picture. Furthermore, you need to be careful, how the shift from z = 0 to z = zmin is implemented as it can influence what section of the exponential you are sampling from.

Cheers,  
David

---

<div class="post-metadata">

**Author:** ![fengfengxu](https://fluka-forum.web.cern.ch/user_avatar/fluka-forum.web.cern.ch/fengfengxu/32/3529_2.png) [@fengfengxu](https://fluka-forum.web.cern.ch/u/fengfengxu)\
**Post date:** [30 June 2022 14:04 UTC](https://fluka-forum.web.cern.ch/t/how-do-i-make-the-correct-non-uniform-sampling-along-the-depth-direction/3338/6 "2022-06-30T14:04:26Z")

</div>

Dear Professor David，

I forgot to upload my source file,It seems to be working well for now. You check it out. I found that with the decrease of the coefficient A, the result of the calculation seemed to differ more from the numerical integral.This is a very strange result for me.  
[source.f](https://fluka-forum.web.cern.ch/uploads/short-url/oVzMmYhROC0WUAMIXISUMNdHfTd.f) (9.8 KB)

I hope that the teacher will analyze why the difference between the counting result and the numerical integral will become larger and larger as the coefficient A decreases.At the same time, first make sure that it does achieve exponential distribution sampling.

Thanks in advance！  
fengfeng

---

<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:** [1 July 2022 06:37 UTC](https://fluka-forum.web.cern.ch/t/how-do-i-make-the-correct-non-uniform-sampling-along-the-depth-direction/3338/7 "2022-07-01T06:37:39Z")

</div>

Dear Fengfeng,

1. I did not specify which results are you comparing to what numerical integral, so I can’t comment on their differences.

2. The formula

Cheers,  
David

---

<div class="post-metadata">

**Author:** ![fengfengxu](https://fluka-forum.web.cern.ch/user_avatar/fluka-forum.web.cern.ch/fengfengxu/32/3529_2.png) [@fengfengxu](https://fluka-forum.web.cern.ch/u/fengfengxu)\
**Post date:** [1 July 2022 06:59 UTC](https://fluka-forum.web.cern.ch/t/how-do-i-make-the-correct-non-uniform-sampling-along-the-depth-direction/3338/8 "2022-07-01T06:59:41Z")

</div>

Dear Professor David，

It is a pleasure to have implemented the program with the help of my teachers.I think I got the best affirmation.The first one is not a fluka problem, I will solve it myself, delaying your time.This post can be closed.

Thanks to Mr. David, I can learn something new!  
Fengfeng

---

<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:** [1 July 2022 07:01 UTC](https://fluka-forum.web.cern.ch/t/how-do-i-make-the-correct-non-uniform-sampling-along-the-depth-direction/3338/9 "2022-07-01T07:01:39Z")

</div>

Closed on 1 July 2022 07:01 UTC


