Dear experts
I am a freshman in garfieldpp.Some questions occured when I was using DriftRKF to calculate the driftline.I searched the question in the forum,although there are some similar situations,the ways to solve this error are unsuitable for me.Pic of error and my code is presented below:

``````#include <cstdlib>
#include <iostream>
#include <TROOT.h>
#include <TApplication.h>
#include "TCanvas.h"
#include "Garfield/MediumMagboltz.hh"
#include "Garfield/ComponentAnalyticField.hh"
#include "Garfield/Sensor.hh"
#include "Garfield/TrackHeed.hh"
#include "Garfield/DriftLineRKF.hh"
#include "Garfield/ViewField.hh"
#include "Garfield/ViewCell.hh"
#include "Garfield/ViewDrift.hh"
#include "Garfield/FundamentalConstants.hh"
#include "Garfield/Random.hh"
#include "Garfield/ViewMedium.hh"
#include "Garfield/ComponentFieldMap.hh"

using namespace Garfield;

int main(int argc, char* argv[])
{
//visualization
TApplication app("app",&argc,argv);

//Switch between cathod_gap(true) or sense_gap(false)
//bool flag = true;

//set distance of cathod wires sense wires gate wires[cm]
constexpr double gap_cathod = 0.2;
constexpr double gap_sense = 0.8;

//set wire diameters[cm]
constexpr double cathod_dia = 0.01;  //cathod
constexpr double gate_dia = 0.01;   //gate
constexpr double sense_dia = 0.0025;  //sense

//Voltages Setting[V]
constexpr double vs = 1200.;   //sense
constexpr double vg = -300.;  //gate

//set gas
MediumMagboltz gas;
gas.SetComposition("ar",80,"co2",20);
gas.SetTemperature(293.15);
gas.SetPressure(637.55);
gas.WriteGasFile("ar_80_co2_20.gas");
auto installdir = std::getenv("GARFIELD_INSTALL");

//read the ion mobility table from file
if(!installdir)
{std::cerr << "GARFIELD_INSTALL variable not set.\n";
return 1;
}
const std::string path = installdir;

//set the electricfield
ComponentAnalyticField cmp;
cmp.SetMedium(&gas);

constexpr double xc = 0.;
constexpr double yc = 0.;
for(int i = 0;i <= 26;i++)
{
}

for(int j = 0;j <= 6;j++)
{

}

//plot the cell
TCanvas *c1 = new TCanvas("c1","c1",600,600);
ViewCell cellView;
cellView.SetComponent(&cmp);
cellView.SetArea(-0.5,-1.5,5.5,3.1);
cellView.SetCanvas(c1);
cellView.Plot2d();
c1 -> Update();

//make a sensor
Sensor sensor;
sensor.SetArea(0.,0.,0.,5.2,1.6,2.);

//plot iopotential contours
ViewField fieldView;
TCanvas *c2 = new TCanvas("c2","c2",600,600);
fieldView.SetComponent(&cmp);
fieldView.SetArea(0.,0.,4.,1.6);
fieldView.SetVoltageRange(-300.,1200.);
fieldView.SetCanvas(c2);
//      fieldView.PlotContour();
fieldView.Plot("e","colz");
c2 -> Update();

//set the driftline and tracks
TrackHeed track;
track.SetSensor(&sensor);
track.SetParticle("electron");
track.SetEnergy(1.e9);

DriftLineRKF drift;
drift.SetSensor(&sensor);

//plot driftline
ViewDrift driftView;
drift.EnablePlotting(&driftView);
track.EnablePlotting(&driftView);
driftView.SetCanvas(c1);

//simulate a track
//initialise of track
track.Initialise(&gas, true);
track.NewTrack(2.1,1.3,1.,0.,0,-1.,0.);
//retrieve the clusters
for(const auto& cluster : track.GetClusters())
{
for(const auto& electron : cluster.electrons)
{
drift.DriftElectron(electron.x,electron.y,electron.z,electron.t);
}
}

driftView.Plot(true,false);
c1 -> Update();

//viewmedium
TCanvas *c3 = new TCanvas("c3","c3",600,600);
ViewMedium mediumView;
mediumView.SetMedium(&gas);
mediumView.SetCanvas(c3);
mediumView.EnableAutoRangeX(false);
mediumView.SetRangeE(0.,1000.,false);
mediumView.PlotElectronVelocity('e');
c3 -> Update();

app.Run(true);
}
``````

I’m sure @hschindl can help

Hi,
can you attach the gas file you are using? And can you try to reduce your code to a minimal reproducible example?

okay，I have deleted some unneccessary codes,and it still response the errors,and my attachments of reduced codes and gas file are zipped below:

code_gasfile.zip (2.3 KB)

Thanks for the simplified code and the gas file. I’ve committed a fix that should prevent the segfault:

The reason for the error message

``````DriftLineRKF::GetVelocity:
Cannot retrieve drift velocity at ...
``````

is that your gas file does not contain any electron transport data. You need create a gas table using Magboltz and then save it to a gas file.