# How to avoid seg fault when using DriftLineRKF::DriftElectron()

**URL:** <https://root-forum.cern.ch/t/how-to-avoid-seg-fault-when-using-driftlinerkf-driftelectron/54263>\
**Category:** Garfield++\
**Created:** [March 28, 2023, 8:49am UTC](https://root-forum.cern.ch/t/how-to-avoid-seg-fault-when-using-driftlinerkf-driftelectron/54263 "2023-03-28T08:49:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [March 28, 2023, 8:49am UTC](https://root-forum.cern.ch/t/how-to-avoid-seg-fault-when-using-driftlinerkf-driftelectron/54263/1 "2023-03-28T08:49:01Z")

</div>

Dear Experts

I want to simulate the drift of electrons in a cell constructed by 9 wires, but I found when electron was created inside wire it will give seg fault and simulation stopped.

```auto
DriftLineRKF::DriftLine:
    Cannot retrieve drift velocity at initial position (-0.946065, 0.793843, 0.000000).

 ***Break*** segmentation violation

```

Is there any way to skip these electrons? I need to manually skip them (geometrically) for now…

---

<div class="post-metadata">

**Author:** ![mjag](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@mjag](https://root-forum.cern.ch/u/mjag)\
**Post date:** [March 30, 2023, 9:57am UTC](https://root-forum.cern.ch/t/how-to-avoid-seg-fault-when-using-driftlinerkf-driftelectron/54263/2 "2023-03-30T09:57:56Z")

</div>

You can check for status of electric field:

```auto
// Some gas
MediumMagboltz gas;
gas.LoadGasFile("ar_93_co2_7_3bar.gas");
gas.LoadIonMobility("IonMobility_Ar+_Ar.txt");

// Example component with thick wire
ComponentAnalyticField cmp;
cmp.SetMedium(&gas);
cmp.AddWire(0, 0, 2*0.1, 3000, "s"); //0.1 cm radius wire
cmp.AddTube(1, 0, 0, "t"); //1 cm radius tube
cmp.AddReadout("s");

Sensor sensor;
sensor.AddComponent(&cmp);
sensor.AddElectrode(&cmp, "s");

DriftLineRKF drift;
drift.SetSensor(&sensor);

// Make two points, one inside wire, one outside
std::vector<std::array<double,3>> points;
std::array good_point = {0.3,0.1,0.0};
std::array bad_point = {0.05,0.0,0.0};
points.push_back(good_point);
points.push_back(bad_point);

for(int i=0;i<points.size();i++){
    double ex,ey,ez,v;
    Medium* m;
    int status;
    double x=points[i][0];
    double y=points[i][1];
    double z=points[i][2];
    // Check if electric field at point is defined
    sensor.ElectricField(x,y,z,ex,ey,ez,v,m,status);
    if(!status){
        drift.DriftElectron(x,y,z,0.0);
        std::cout<<"Successfully drifted ("<<x<<","<<y<<","<<z<<")"<<std::endl;
    }else{
        std::cout<<"No field at ("<<x<<","<<y<<","<<z<<")"<<std::endl;
    }
}

```

---

<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:** [April 24, 2023, 8:00am UTC](https://root-forum.cern.ch/t/how-to-avoid-seg-fault-when-using-driftlinerkf-driftelectron/54263/4 "2023-04-24T08:00:11Z")

</div>

Closed on April 24, 2023, 8:00am UTC

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