# ComponentAnalyticField and ComponentElmer2d give different results

**URL:** <https://root-forum.cern.ch/t/componentanalyticfield-and-componentelmer2d-give-different-results/49547>\
**Category:** Garfield++\
**Created:** [April 11, 2022, 5:56pm UTC](https://root-forum.cern.ch/t/componentanalyticfield-and-componentelmer2d-give-different-results/49547 "2022-04-11T17:56:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ming](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ming/32/29383_2.png) [@ming](https://root-forum.cern.ch/u/ming)\
**Post date:** [April 11, 2022, 5:56pm UTC](https://root-forum.cern.ch/t/componentanalyticfield-and-componentelmer2d-give-different-results/49547/1 "2022-04-11T17:56:57Z")

</div>

Hi,

I am trying to calculate the signals and charges created by alpha particles in a gas tube, but I got different results when I replaced `ComponentAnalyticField` with `ComponentElmer2d`.

The tube radius is 0.2 cm and the wire radius is 0.01 cm. The ion tracks were calculated by TRIM and imported into Garfield++ using `TrackTrim`. The wire voltage is 700V and the tube wall is grounded. I set up the electric field map using two different methods: in the first method I used `ComponentAnalyticField`, and in the second method I used `ComponentElmer2d` to import the field calculated by Elmer.

However, the current signals and integrated charges calculated by these two methods were very different. Below are plots of track/drift lines and current signal from the same alpha. The first one was calculated using `ComponentAnalyticField`, and the second one using `ComponentElmer2d`. The last figure is the histogram of the integrated charge for a number of alphas, which shows clearly using `ComponentElmer2d` resulted in much smaller charges.

 ![single-alpha-ComponentAnalyticField](https://root-forum.cern.ch/uploads/default/original/3X/b/2/b23f0b77842b6bdb68ba23f61d8b11578f8e6948.png)

 ![single-alpha-ComponentElmer2d](https://root-forum.cern.ch/uploads/default/original/3X/6/5/650afac3709ac3e818d73c781b876e28fe8c6215.png)

 ![Compare-histogram-of-charges](https://root-forum.cern.ch/uploads/default/original/3X/4/b/4b1a9ae90221a64f272ec7bd9cea071a26426df1.png)

I am not sure why I got inconsistent results. The ion track file and gas file are the same, and the electric field calculated by Elmer agrees well with the analytic one. The code and input files can be downloaded from [here](https://uofi.box.com/s/2vnelvxbdwwimrtwp086cdfno620kccc). I am inclined to think something went wrong when I imported the field using `ComponentElmer2d`. Could you please help me fix this?

Thank you,

Ming

---

<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 12, 2022, 6:59am UTC](https://root-forum.cern.ch/t/componentanalyticfield-and-componentelmer2d-give-different-results/49547/2 "2022-04-12T06:59:56Z")

</div>

Many thanks for your message. I’ll try to take a look in the coming days…

---

<div class="post-metadata">

**Author:** ![ming](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ming/32/29383_2.png) [@ming](https://root-forum.cern.ch/u/ming)\
**Post date:** [April 22, 2022, 9:59pm UTC](https://root-forum.cern.ch/t/componentanalyticfield-and-componentelmer2d-give-different-results/49547/3 "2022-04-22T21:59:23Z")

</div>

Hi, thanks for your reply. I wanted to share an update on this issue. So I tried to replace `ComponentElmer2D` with `ComponentAnsys121`, and the result is close to `ComponentElmer2D`. I then looked into the drift of a single electron and compared the signals I got with `ComponentAnalyticField` and `ComponentAnsys121`. And finally, I found the problem was that the time step was too coarse in the analytic case. Below are the current signals passed into `Sensor::FillSignal` function, where the discretized signal is first linearly interpolated and integrated using Simpson integration to get the charge in a time bin. And you can see that in the last time bin (light blue region), there are only two samples in the `Analytic` signal, and this procedure led to overestimated integral. It’s not clear to me how this step can be controlled, but the ANSYS one looks okay so I will probably just use that.

 ![signal_comparison](https://root-forum.cern.ch/uploads/default/original/3X/2/6/26115fc2d96fc16471ce7f2ddbde300a34fe4c46.jpeg)

---

<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, 2022, 1:00pm UTC](https://root-forum.cern.ch/t/componentanalyticfield-and-componentelmer2d-give-different-results/49547/4 "2022-04-24T13:00:08Z")

</div>

Hi  
apologies for my late reply and thanks a lot for your thorough investigation/debugging!

`DriftLineRKF` checks at every step whether the electron is in the vicinity (i. e. within a distance _R_) of a wire (this check is implemented only for `ComponentAnalyticField` but not for field maps). If it is then it is considered “trapped” by the wire and a dedicated algorithm takes over for the last steps towards the wire. This algorithm ignores the max. step size set by the user (this is something I need to fix).

By default, the distance _R_ is set to five times the physical wire radius. If you set it to be identical to the physical wire radius, that is if you replace the line

```auto
cmp.AddWire(0, 0, 2 * rWire, vWire, "s");

```

by

```auto
cmp.AddWire(0, 0, 2 * rWire, vWire, "s", 100., 50., 19.3, 1);

```

(the “trap radius” is the last argument of the function `AddWire`) then the electron trajectory obtained using `ComponentAnalyticField` should be very close to the one obtained using `ComponentElmer2d` or `ComponentAnsys121`.

There is another thing though that I noticed running the example. There seems to be a significant difference in the signal depending on whether the weighting field or the weighting potential are used for calculating the induced current. Will look more closely into that…

---

<div class="post-metadata">

**Author:** ![ming](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ming/32/29383_2.png) [@ming](https://root-forum.cern.ch/u/ming)\
**Post date:** [April 25, 2022, 7:40pm UTC](https://root-forum.cern.ch/t/componentanalyticfield-and-componentelmer2d-give-different-results/49547/5 "2022-04-25T19:40:26Z")

</div>

Hi many thanks for your reply. Setting `R` to the physical wire radius solved the issue. The two distributions are now in better agreement.

 ![ANSYS-analytic](https://root-forum.cern.ch/uploads/default/original/3X/0/7/075917da808c8e2c290f995e647e115d328d504b.png)

I also noticed the difference between using weighting potential and weighting field. Below are the charge distributions calculated using weighting potential. Also not sure what’s causing the difference, but according to the manual, I will use weighting potential to make sure the charge is correct.

 ![ANSYS-analytic-weighting-potential](https://root-forum.cern.ch/uploads/default/original/3X/e/a/ea12740d4b63f2d64a46048418c0df43a303cb28.png)

---

<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 9, 2022, 7:41pm UTC](https://root-forum.cern.ch/t/componentanalyticfield-and-componentelmer2d-give-different-results/49547/6 "2022-05-09T19:41:00Z")

</div>

Closed on May 9, 2022, 7:41pm UTC

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