# DriftLineRKF looping indefinitely in MPGD implementation

**URL:** <https://root-forum.cern.ch/t/driftlinerkf-looping-indefinitely-in-mpgd-implementation/64313>\
**Category:** Garfield++\
**Created:** [October 14, 2025, 8:42am UTC](https://root-forum.cern.ch/t/driftlinerkf-looping-indefinitely-in-mpgd-implementation/64313 "2025-10-14T08:42:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gzunica](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/3e96dc/32.png) [@gzunica](https://root-forum.cern.ch/u/gzunica)\
**Post date:** [October 14, 2025, 8:42am UTC](https://root-forum.cern.ch/t/driftlinerkf-looping-indefinitely-in-mpgd-implementation/64313/1 "2025-10-14T08:42:38Z")

</div>

Dear Experts,

I am trying to simulate drift lines with DriftLineRKF in a proof of concept MPGD-like implementation.

The geometry consists of two plates (cathode on top, anode on bottom) with a thin dielectric medium on top of the bottom plate. One readout wire and two “field” anodic wires are resting on top of the glass. The overall gap thickness is 5mm.

I have tested multiple combinations of “SetMaximumStepSize” and "SetIntegrationAccuracy” to no avail. More specifically, with some voltage combinations the computation converges, with some others it gets stuck an a loop trying to optimise the step size.

I attach a minimal example.

Is there something that i am missing?

Thank you in advance!

```cpp

using namespace Garfield;

int main(int argc, char* argv[]) {

  MediumMagboltz gas;//("Ar", 87.5, "CO2", 12.5);
  gas.LoadGasFile("/afs/cern.ch/work/g/gzunica/garfield/Examples/GasFile/ar_93_co2_7.gas");
  gas.LoadIonMobility("/afs/cern.ch/work/g/gzunica/garfield/Data/IonMobility_Ar+_Ar.txt");
  gas.SetPressure(760.);
  gas.SetTemperature(293.15);

  MediumConductor Cu;
  MediumPlastic glass;
  glass.SetDielectricConstant(10.0);
  MediumPlastic kapton;
  kapton.SetDielectricConstant(3.0);

  // Geometry.
  GeometrySimple geo;

  const double cat_v=-2000.;
  const double sense_v=+10.;
  const double field_v=-1700.;
  const double backplane_v=-1500.;
  

  SolidBox box1(0, 0, 0.5, 3.2,2.5, 0.0);
  box1.SetBoundaryPotential(cat_v);
  SolidBox box2(0, 0, -0.105, 3.2,2.5, 0.1);
  box2.SetBoundaryDielectric();
  SolidBox box3(0, 0, -0.205, 3.2,2.5, 0.0);
  box3.SetBoundaryPotential(backplane_v);
 
   geo.AddSolid(&box1, &Cu);
   geo.AddSolid(&box2, &glass);
   geo.AddSolid(&box3, &Cu);
   

  const double radiusS = 0.0015; //0.0015
  const double radiusF = 0.005;
  const double halflength = 2.5;
  double passo = 0.4;

  SolidWire wireS(xposS, 0.0, -0.0035, radiusS, halflength, 0, 1, 0); 
  wireS.SetBoundaryPotential(sense_v);
  wireS.SetLabel("readout");
  geo.AddSolid(&wireS, &Cu);

  SolidWire wireF1(xposF, 0.0, 0.0, radiusF, halflength, 0, 1, 0);
  wireF1.SetBoundaryPotential(field_v);
  SolidWire wireF2(xposF+passo, 0.0, 0.0, radiusF, halflength, 0, 1, 0); 
  wireF2.SetBoundaryPotential(field_v);
  geo.AddSolid(&wireF1, &Cu);
  geo.AddSolid(&wireF2, &Cu);

  geo.PrintSolids();
  geo.SetMedium(&gas);

  ComponentNeBem3d nebem;
  nebem.SetGeometry(&geo);
  nebem.SetTargetElementSize(0.2);
  nebem.SetMinMaxNumberOfElements(1, 100); 

  nebem.Initialise();

  Medium* medium = nullptr;
  double ex = 0., ey = 0., ez = 0., v = 0.;
  int status = 0;
  nebem.ElectricField(0, 0, 0, ex, ey, ez, v, medium, status);
  std::printf("E = (%15.8f, %15.8f %15.8f), V = %15.8f, status = %d\n", ex, ey,
              ez, v, status);

 Sensor sensor(&nebem);
 sensor.AddElectrode(&nebem, "readout");

 Shaper shaper(3,0.5,1,"unipolar");
 sensor.SetTransferFunction(shaper);

 sensor.SetTimeWindow(0., 0.5, 200);

  DriftLineRKF driftRKF(&sensor);
  driftRKF.SetIntegrationAccuracy(1e-6);
  driftRKF.SetMaximumStepSize(0.0005);
  driftRKF.EnableIonTail();
  driftRKF.EnableAvalanche();
  //driftRKF.EnableDebugging();

  ViewDrift driftView;
  driftView.SetPlaneXZ();
  driftView.SetArea(-5.,-5.,-0.5,5.,5.,0.6);
  heed.EnablePlotting(&driftView);
  driftRKF.EnablePlotting(&driftView);

  ViewSignal signalView(&sensor);

   std::vector<double> xe;
   std::vector<double> ye;
   std::vector<double> ze;
   xe.push_back(0.);

   ye.push_back(0.);

   ze.push_back(0.1);

   for(int i=0; i<xe.size();i++){

       driftRKF.DriftElectron(xe.at(i), ye.at(i), ze.at(i), 0);
       double ne=0;
       double ni=0;

         driftRKF.GetAvalancheSize(ne,ni);
         std::cout<< "ne " << ne << ", ni "<< ni <<"\n";
     }
}

```

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [October 14, 2025, 9:30am UTC](https://root-forum.cern.ch/t/driftlinerkf-looping-indefinitely-in-mpgd-implementation/64313/2 "2025-10-14T09:30:03Z")

</div>

Welcome to the ROOT Forum!  
I’m sure @hschindl can help

---

<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:** [October 15, 2025, 7:34am UTC](https://root-forum.cern.ch/t/driftlinerkf-looping-indefinitely-in-mpgd-implementation/64313/3 "2025-10-15T07:34:47Z")

</div>

Hi,  
what are the values of `xposS` and `xposF`?

---

<div class="post-metadata">

**Author:** ![gzunica](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/3e96dc/32.png) [@gzunica](https://root-forum.cern.ch/u/gzunica)\
**Post date:** [October 16, 2025, 6:27am UTC](https://root-forum.cern.ch/t/driftlinerkf-looping-indefinitely-in-mpgd-implementation/64313/4 "2025-10-16T06:27:50Z")

</div>

Hello,

those are the positions on the X axis of the wires. The “readout” wire should be at x=0 while the field wires should be at x=±0.2 cm.  
I just realised i have deleted their definition while posting the script, apologies!

---

<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:** [October 25, 2025, 11:34am UTC](https://root-forum.cern.ch/t/driftlinerkf-looping-indefinitely-in-mpgd-implementation/64313/5 "2025-10-25T11:34:54Z")

</div>

Hi,  
sorry for the delay! The issue is that the ion drift lines jump across the box electrodes. I should think of a better way to prevent/fix this, but as a work-around, you can/should set explicitly the active region of the sensor, something like this:

```cpp
sensor.SetArea(-3., -3., -0.205, 3., 3., 0.5);

```

Alternatively, you could also add a `SolidBox` for the gas volume and remove the line `geo.SetMedium(&gas);`.

Not directly related to your question, but:

- I assume the glass layer in your detector is weakly conductive? If it is, that means for the purposes of calculating the electrostatic field in your detector, it is a conductor, while for the purposes of calculating the prompt component of the weighting potential, it is an insulator.
- The value of the max. step size limit (5 μm) seems a bit small, I would try increasing it a bit to speed up the calculation.

---

<div class="post-metadata">

**Author:** ![gzunica](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/3e96dc/32.png) [@gzunica](https://root-forum.cern.ch/u/gzunica)\
**Post date:** [October 28, 2025, 8:55am UTC](https://root-forum.cern.ch/t/driftlinerkf-looping-indefinitely-in-mpgd-implementation/64313/6 "2025-10-28T08:55:09Z")

</div>

Indeed using sensor.SetArea() did the solve the issue!

As for the glass layer, i’m not sure i understand.  
I’m using the standard “MediumPlastic” definition, explicitly setting the dielectric constant.  
I had assumed it’s non driftable and non ionisable (as for the MediumPlastic.h), although it would be useful if this “glass” could be tweaked to have some weak conductivity (for ions at least). Or better still if it could mimick more of a “resistive” medium.

---

<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:** [October 29, 2025, 1:29pm UTC](https://root-forum.cern.ch/t/driftlinerkf-looping-indefinitely-in-mpgd-implementation/64313/7 "2025-10-29T13:29:40Z")

</div>

Hi,  
regarding the glass layer, what I meant is that in neBEM a solid can only be either a conductor (at fixed potential) or a dielectric. If you describe the glass layer as a dielectric (i. e. an insulator), the electric field will be “wrong” because even though the resistivity is high, from an electrostatic point of view it is nevertheless a conductor. For calculating the prompt weighting field, treating the glass layer as a dielectric is correct (and the time constant is typically so high that you can neglect the contribution from the delayed weighting field).

---

<div class="post-metadata">

**Author:** ![gzunica](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/3e96dc/32.png) [@gzunica](https://root-forum.cern.ch/u/gzunica)\
**Post date:** [October 30, 2025, 9:25am UTC](https://root-forum.cern.ch/t/driftlinerkf-looping-indefinitely-in-mpgd-implementation/64313/8 "2025-10-30T09:25:23Z")

</div>

Hello,

indeed my aim is to have a feeling of how the electric field behaves when “crossing” the glass. From what i understood neBEM should be handling the effect of different mediums on the electric field, is this correct?

Just to be clear, the glass was not intended to “block” the electric field, but rather to stop particles drifting to the backplane electrode.

---

<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 13, 2025, 9:25am UTC](https://root-forum.cern.ch/t/driftlinerkf-looping-indefinitely-in-mpgd-implementation/64313/9 "2025-11-13T09:25:58Z")

</div>

Closed on November 13, 2025, 9:25am UTC

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