# AvalancheMC - error with SetDistanceSteps

**URL:** <https://root-forum.cern.ch/t/avalanchemc-error-with-setdistancesteps/54579>\
**Category:** Garfield++\
**Created:** [April 21, 2023, 12:00pm UTC](https://root-forum.cern.ch/t/avalanchemc-error-with-setdistancesteps/54579 "2023-04-21T12:00:23Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![acorsi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@acorsi](https://root-forum.cern.ch/u/acorsi)\
**Post date:** [April 21, 2023, 12:00pm UTC](https://root-forum.cern.ch/t/avalanchemc-error-with-setdistancesteps/54579/1 "2023-04-21T12:00:23Z")

</div>

Hello,  
I would like to simulate an avalanche in a Ar-CO2 gas (file attached) with an electric field of 22800 V/cm and the attached arco2 file (taken rom the exemple), within garfield6. With the commands:  
AvalancheMC aval;  
aval.SetDistanceSteps(0.001);  
I obtain reasonable results, but not converged (if I increase the step, the number of electrons produced decreases). If I try to go below 1 um step, I have en error (error 9 on mac, bad alloc on a linux cluster).  
Any idea why, and how can I solve the issue?  
Anna  
[arco2.txt](https://root-forum.cern.ch/uploads/short-url/oUqdmXY7fYWJdOSEq8Y1XIhKWni.txt) (3.6 KB)  
[ar\_90\_co2\_10.txt](https://root-forum.cern.ch/uploads/short-url/4hGYmO2CjHKuG0Ev0CPL8rNb35T.txt) (56.4 KB)

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [April 21, 2023, 1:51pm UTC](https://root-forum.cern.ch/t/avalanchemc-error-with-setdistancesteps/54579/2 "2023-04-21T13:51:13Z")

</div>

Maybe @hschindl can help with that.

Cheers,  
J.

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [April 22, 2023, 6:41am UTC](https://root-forum.cern.ch/t/avalanchemc-error-with-setdistancesteps/54579/3 "2023-04-22T06:41:53Z")

</div>

Hi,  
thanks for your message! I can’t say off-hand why the error occurs, but I think there might be a mistake in your program regarding the electric field.  
The variable `field` is set to 570 × 40 = 22800 which I understand is the value in V/cm. But then when calling `SetElectricField` this value is multiplied by 1000, so what you are simulating is not 22.8 kV/cm but 22800 kV/cm which is an enormously high value.

---

<div class="post-metadata">

**Author:** ![acorsi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@acorsi](https://root-forum.cern.ch/u/acorsi)\
**Post date:** [April 23, 2023, 4:37pm UTC](https://root-forum.cern.ch/t/avalanchemc-error-with-setdistancesteps/54579/4 "2023-04-23T16:37:27Z")

</div>

Indeed, thanks ☺  
Now I manage to run the simulation for DistanceStep \< 1um, but the number of electrons produced still changes with the DistanceStep, so don’t manage to find a value for which the number of electrons is converged.  
Eventually, what I would like to do is to simulate the avalanche in a preamplification gap of ~250 um, and estimate the multiplication factor as a function of the depth in the gap. Is this way with AvalancheMC the proper way to do so?  
Best regards  
Anna

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [April 23, 2023, 5:42pm UTC](https://root-forum.cern.ch/t/avalanchemc-error-with-setdistancesteps/54579/5 "2023-04-23T17:42:36Z")

</div>

Hi,  
it’s indeed a bit of an issue with `AvalancheMC` that the results depend to some extent on the chosen step size. Just to be sure it’s really a dependence on the step size and not just statistical fluctuations: how many avalanches did you simulate to compute the mean gain?

Unless it’s computationally prohibitive, I would rather recommend `AvalancheMicroscopic` if you want an accurate simulation of electron transport (including fluctuations).  
On the other hand, if the electric field in your preamplification gap is (to good approximation) uniform, then you can just use the Townsend coefficient at this field and compute the expected average gain directly.

---

<div class="post-metadata">

**Author:** ![acorsi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@acorsi](https://root-forum.cern.ch/u/acorsi)\
**Post date:** [April 24, 2023, 9:44am UTC](https://root-forum.cern.ch/t/avalanchemc-error-with-setdistancesteps/54579/6 "2023-04-24T09:44:48Z")

</div>

Hello,  
I see. I run AvalancheMC with 1000 electrons but I see the mean number of electrons (gain) after multiplication is similar to the rms.  
I tried with AvalancheMicroscopic, but now I’m a bit perplex about the meaning of SetCollisionSteps. Its arguments should be “number of collisions to be skipped for plotting” according to the manual but actually its value affects the gain!  
I think Townsend coefficients may work for me, and I try to follow the instructions to plot them but without success (nothing happens):  
gas.LoadGasFile(“…/GasFile/ar\_90\_co2\_10.gas”);  
ViewMedium view;  
view.SetMedium(&gas);  
view.PlotElectronTownsend(‘e’,true);  
Is there an exemple I can follow?  
Thanks and cheers  
Anna

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [April 24, 2023, 1:35pm UTC](https://root-forum.cern.ch/t/avalanchemc-error-with-setdistancesteps/54579/7 "2023-04-24T13:35:12Z")

</div>

> [@acorsi](#):
>
> I run AvalancheMC with 1000 electrons but I see the mean number of electrons (gain) after multiplication is similar to the rms.

Yes, a lot to moderate field, the avalanche size follows an exponential distribution.

> [@acorsi](#):
>
> I tried with AvalancheMicroscopic, but now I’m a bit perplex about the meaning of SetCollisionSteps. Its arguments should be “number of collisions to be skipped for plotting” according to the manual but actually its value affects the gain!

Are you sure? In the HEAD version of the code, the function `SetCollisionSteps` should not affect the results at all.

> [@acorsi](#):
>
> Is there an exemple I can follow?

Yes, you can have a look at the “read” example in Examples/GasFile ([C++ version](https://gitlab.cern.ch/garfield/garfieldpp/-/blob/master/Examples/GasFile/read.C), [Python version](https://gitlab.cern.ch/garfield/garfieldpp/-/blob/master/Examples/GasFile/read.py)).

---

<div class="post-metadata">

**Author:** ![acorsi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@acorsi](https://root-forum.cern.ch/u/acorsi)\
**Post date:** [April 24, 2023, 2:16pm UTC](https://root-forum.cern.ch/t/avalanchemc-error-with-setdistancesteps/54579/8 "2023-04-24T14:16:14Z")

</div>

Hi,  
I took Garfiled from here: [garfield / garfieldpp · GitLab](https://gitlab.cern.ch/garfield/garfieldpp.git), it is labeled garfield6. The average numbers of electrons produced over a 200u gap is ~10 with CollisionStep(1), ~20 with CollisionStep(10). BTW, the first case is consistent with what I get using the Townsend coeff (thank for the macro!).  
Cheers  
Anna

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [April 25, 2023, 5:52am UTC](https://root-forum.cern.ch/t/avalanchemc-error-with-setdistancesteps/54579/9 "2023-04-25T05:52:12Z")

</div>

Hi,  
that’s indeed the correct repository (I’m not sure what you mean by “garfield6” though).

> [@acorsi](#):
>
> The average numbers of electrons produced over a 200u gap is ~10 with CollisionStep(1), ~20 with CollisionStep(10).

Thanks for reporting this, very strange, there should really be no effect of the number of “collision steps” on the avalanche size. I’ll give it a try if I can reproduce it and get back to you.

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [April 30, 2023, 6:54am UTC](https://root-forum.cern.ch/t/avalanchemc-error-with-setdistancesteps/54579/10 "2023-04-30T06:54:27Z")

</div>

Sorry for the delay in getting back to you. Unfortunately I can’t reproduce this issue; with the HEAD version of the project, I don’t see a statistically significant difference in the avalanche size distribution when I change the number of “collision steps”.

---

<div class="post-metadata">

**Author:** ![acorsi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c57346/32.png) [@acorsi](https://root-forum.cern.ch/u/acorsi)\
**Post date:** [May 1, 2023, 12:01pm UTC](https://root-forum.cern.ch/t/avalanchemc-error-with-setdistancesteps/54579/11 "2023-05-01T12:01:34Z")

</div>

Just to be sure, is your testing code is similar to the attached one, and how can I make sure I have the HEAD version of the project?  
Anna

[micro\_arco2.C](https://root-forum.cern.ch/uploads/short-url/rQU7VSZUXCZhTq5zOAnKGRgaSic.C) (3.7 KB)

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [May 2, 2023, 6:45am UTC](https://root-forum.cern.ch/t/avalanchemc-error-with-setdistancesteps/54579/12 "2023-05-02T06:45:44Z")

</div>

Hi,  
yes, it’s very similar (see the attached file).  
[test.C](https://root-forum.cern.ch/uploads/short-url/e5nZTBdva1XYyACKmQ6rOgXhf33.C) (1.8 KB)

> [@acorsi](#):
>
> How can I make sure I have the HEAD version of the project?

You need to do a `git pull` and rerun `make; make install` in the Garfield++ `build` folder.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [May 16, 2023, 6:46am UTC](https://root-forum.cern.ch/t/avalanchemc-error-with-setdistancesteps/54579/13 "2023-05-16T06:46:01Z")

</div>

Closed on May 16, 2023, 6:46am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
