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"

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

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?

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

@hschindl, thanks for your reply,

but the codes similar using AvalancheMicroscopic class can run well.

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.

@hschindl, thanks, i get it.