# The error "terminate called after throwing an instance of 'Garfield::Exception' what(): Index out of range in GetElectronEndpoint at /usr/local/garfieldpp-master/Source/AvalancheMC.cc:196:0"

**URL:** <https://root-forum.cern.ch/t/the-error-terminate-called-after-throwing-an-instance-of-garfield-exception-what-index-out-of-range-in-getelectronendpoint-at-usr-local-garfieldpp-master-source-avalanchemc-cc0/64374>\
**Category:** Garfield++\
**Created:** [November 3, 2025, 2:44am UTC](https://root-forum.cern.ch/t/the-error-terminate-called-after-throwing-an-instance-of-garfield-exception-what-index-out-of-range-in-getelectronendpoint-at-usr-local-garfieldpp-master-source-avalanchemc-cc0/64374 "2025-11-03T02:44:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![newconcept1979](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/newconcept1979/32/26349_2.png) [@newconcept1979](https://root-forum.cern.ch/u/newconcept1979)\
**Post date:** [November 3, 2025, 2:44am UTC](https://root-forum.cern.ch/t/the-error-terminate-called-after-throwing-an-instance-of-garfield-exception-what-index-out-of-range-in-getelectronendpoint-at-usr-local-garfieldpp-master-source-avalanchemc-cc0/64374/1 "2025-11-03T02:44:15Z")

</div>

After a electron avalanche, the ions drift is expected, the code is:

```auto
mc.AvalancheElectron(xx, yy, zz, tt);

double x1,y1,z1,t1,x2,y2,z2,t2;
std::size_t num_tracks;
num_tracks=mc.GetNumberOfElectronEndpoints();
          
 for (std::size_t i = 0; i < num_tracks; i++)
 {
      mc.GetElectronEndpoint(i, x1, y1, z1, t1, x2, y2, z2, t2, status);
      mc.DriftIon(x1, y1, z1, t1);
 }

```

but the error occured:

“erminate called after throwing an instance of ‘Garfield::Exception’  
what(): Index out of range in GetElectronEndpoint at /usr/local/garfieldpp-master/Source/AvalancheMC.cc:196:0”

what is the reason that cause this error?

---

<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:** [November 3, 2025, 6:10am UTC](https://root-forum.cern.ch/t/the-error-terminate-called-after-throwing-an-instance-of-garfield-exception-what-index-out-of-range-in-getelectronendpoint-at-usr-local-garfieldpp-master-source-avalanchemc-cc0/64374/2 "2025-11-03T06:10:42Z")

</div>

Hi,  
calling `DriftIon` resets all electron and ion “end points” stored within `mc`.

---

<div class="post-metadata">

**Author:** ![newconcept1979](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/newconcept1979/32/26349_2.png) [@newconcept1979](https://root-forum.cern.ch/u/newconcept1979)\
**Post date:** [November 3, 2025, 6:32am UTC](https://root-forum.cern.ch/t/the-error-terminate-called-after-throwing-an-instance-of-garfield-exception-what-index-out-of-range-in-getelectronendpoint-at-usr-local-garfieldpp-master-source-avalanchemc-cc0/64374/3 "2025-11-03T06:32:17Z")

</div>

@hschindl, thanks for your reply,

but the codes similar using AvalancheMicroscopic class can run well.

---

<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:** [November 3, 2025, 9:07am UTC](https://root-forum.cern.ch/t/the-error-terminate-called-after-throwing-an-instance-of-garfield-exception-what-index-out-of-range-in-getelectronendpoint-at-usr-local-garfieldpp-master-source-avalanchemc-cc0/64374/4 "2025-11-03T09:07:21Z")

</div>

It’s a bit different because in that case you’re using an `AvalancheMicroscopic` object to simulate the electron avalanche and an `AvalancheMC` object to drift the ions. One solution/workaround would be to use two separate `AvalancheMC` objects, one for electrons and one for ions.

---

<div class="post-metadata">

**Author:** ![newconcept1979](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/newconcept1979/32/26349_2.png) [@newconcept1979](https://root-forum.cern.ch/u/newconcept1979)\
**Post date:** [November 3, 2025, 11:37am UTC](https://root-forum.cern.ch/t/the-error-terminate-called-after-throwing-an-instance-of-garfield-exception-what-index-out-of-range-in-getelectronendpoint-at-usr-local-garfieldpp-master-source-avalanchemc-cc0/64374/5 "2025-11-03T11:37:18Z")

</div>

@hschindl, thanks, i get it.

---

<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:** [November 17, 2025, 11:37am UTC](https://root-forum.cern.ch/t/the-error-terminate-called-after-throwing-an-instance-of-garfield-exception-what-index-out-of-range-in-getelectronendpoint-at-usr-local-garfieldpp-master-source-avalanchemc-cc0/64374/6 "2025-11-17T11:37:50Z")

</div>

Closed on November 17, 2025, 11:37am UTC

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