# How to plot the drift line

**URL:** <https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120>\
**Category:** Garfield++\
**Created:** [December 20, 2021, 1:58am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120 "2021-12-20T01:58:38Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![XiCheng](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/x/aca169/32.png) [@XiCheng](https://root-forum.cern.ch/u/XiCheng)\
**Post date:** [December 20, 2021, 1:58am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/1 "2021-12-20T01:58:38Z")

</div>

I want to get the drift line of the electron and proton, but the result shows that " Could not determine the plot limits." should I set the range of the particle trace in the beginning ? I just want the proton can pass through the whole gas area. I find a example in the drift tube, it define the particle passes at a distance of 3 mm from the wire centre. Dose that mean I should set the range of the trace?

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/1/6/16bc44221130efc1bc250b7d005457af9b72e9ba.png)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [December 20, 2021, 7:37am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/2 "2021-12-20T07:37:16Z")

</div>

Instead of a screen (very difficult to read) can you post a small macro reproducing your problem ? We can then execute it locally and fix it to make it work.

---

<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:** [December 20, 2021, 8:05am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/3 "2021-12-20T08:05:30Z")

</div>

Indeed, a minimal working example would be very helpful.

You do not need to set the range of the particle track, only its starting point, time, and direction.  
You have to make sure though that the initial position is in an active medium (i. e. in the gas in your case).

The message “Could not determine the plot limits.” comes from the class `ViewDrift`. If the plot limits are not set explicitly by the user (`SetArea`), `ViewDrift` will try to determine the plot range based on the extent of the drift lines to be plotted. I suspect that the reason you see this message is that there are no drift lines present.

---

<div class="post-metadata">

**Author:** ![XiCheng](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/x/aca169/32.png) [@XiCheng](https://root-forum.cern.ch/u/XiCheng)\
**Post date:** [December 20, 2021, 8:29am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/4 "2021-12-20T08:29:27Z")

</div>

Hi,  
Thanks a lot for your reply  
So would you please tell me what’s the reason for no drift lines, does that means something wrong with the model? I have set six gas air area,each of them has a slice gap, is the gap be the reason for the particle killed?  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/1/1/11c2b53a6f5dda2ed44777496e5832c085ae6c6f.png)

---

<div class="post-metadata">

**Author:** ![XiCheng](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/x/aca169/32.png) [@XiCheng](https://root-forum.cern.ch/u/XiCheng)\
**Post date:** [December 20, 2021, 8:31am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/5 "2021-12-20T08:31:19Z")

</div>

Hi,Thanks a lot for your reply  
Sorry , I don’t know how to post a small macro reproducing my problem, my model is imported from the ansys, and I am the novice of Garfield++, So I don’t know how to show the problem.

---

<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:** [December 20, 2021, 8:58am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/6 "2021-12-20T08:58:11Z")

</div>

> [@XiCheng](#):
>
> So I don’t know how to show the problem.

Just post (a minimal version of the) source code of the macro/program you are running.

---

<div class="post-metadata">

**Author:** ![XiCheng](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/x/aca169/32.png) [@XiCheng](https://root-forum.cern.ch/u/XiCheng)\
**Post date:** [December 20, 2021, 9:29am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/7 "2021-12-20T09:29:09Z")

</div>

```auto
#include <iostream>
#include "Garfield/MediumMagboltz.hh"
#include "Garfield/FundamentalConstants.hh"
#include <cstdlib>
#include <fstream>
#include <TROOT.h>
#include <TApplication.h>
#include <TCanvas.h>
#include <TH1F.h>
#include <TTree.h>
#include <TFile.h>
#include "Garfield/ViewDrift.hh"
#include "Garfield/ComponentAnsys123.hh"
#include "Garfield/ViewField.hh"
#include "Garfield/ViewFEMesh.hh"
#include "Garfield/Sensor.hh"
#include "Garfield/AvalancheMicroscopic.hh"
#include "Garfield/AvalancheMC.hh"
#include "Garfield/Random.hh"
#include "Garfield/TrackHeed.hh"
#include "Garfield/DriftLineRKF.hh"
#include "Garfield/ViewMedium.hh"

using namespace Garfield;

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

  TApplication app("app", &argc, argv);
  //SetDefaultStyle();
// Load the field map.
  ComponentAnsys123 fm;
  fm.Initialise("ELIST.lis", "NLIST.lis", "MPLIST.lis", "PRNSOL.lis", "cm");
  fm.PrintRange();
  fm.PrintMaterials();
// Get the extent of the field map.
  double x0, y0, z0, x1, y1, z1;
  fm.GetBoundingBox(x0, y0, z0, x1, y1, z1);

  ViewField fieldView;
  constexpr bool plotField = true;
  if (plotField) {
    fieldView.SetComponent(&fm);
    // Set the normal vector of the viewing plane (xz plane).
    fieldView.SetPlane(0, 0, -1, 0, 0, 0.5 * (z0 + z1));
    fieldView.PlotContour();
    std::vector<double> xf;
    std::vector<double> yf;
    std::vector<double> zf;
    fieldView.PlotFieldLines(xf, yf, zf, true, true, kOrange-3); 
  }

  Sensor sensor;
  sensor.AddComponent(&fm);//calculate the field

  // Setup the gas.
  MediumMagboltz gas;
  gas.LoadGasFile("4He.gas");
  gas.PrintGas();
  fm.SetMedium(0, &gas);
  fm.PrintMaterials();

  ViewMedium view;
  view.SetMedium(&gas);
  view.PlotElectronVelocity('e');
  
  // Track class
  TrackHeed track;
  track.SetParticle("proton");
  track.SetEnergy(100.e9);
  track.SetSensor(&sensor);

   //RKF integration
  DriftLineRKF drift;
  drift.SetSensor(&sensor); //chuanganqidaoru
  drift.EnableSignalCalculation();
  
  ViewDrift driftview;
  //the visualize of the electron drift
  TCanvas* CD= nullptr;
  constexpr bool plotDrift = true;
  if (plotDrift)
  {
    CD = new TCanvas("CD", "", 600, 600);
    const bool twod = false;
  	const bool axis = true;
    driftview.SetCanvas(CD);
    driftview.Plot(twod,axis);
    drift.EnablePlotting(&driftview);//plot the track of electron
    track.EnablePlotting(&driftview);//plot the track of proton
  }

  //the calculation of the transportation
  const unsigned int nTracks = 1;//one proton
  double counts,counts_e=0;
  for (unsigned int j=0; j < nTracks; ++j)
  {
    sensor.ClearSignal();
    double x0 = -0.1, y0 = 0.204, z0 = -0.07, t0 = 0.; //make sure the start point of the proton and the direction
    double dx0 = 0., dy0 = 1., dz0 = 0.; 
    track.NewTrack(x0, y0, z0, t0, dx0, dy0, dz0);
    double xc = 0., yc = 0., zc = 0., tc = 0., ec = 0., extra = 0.;
    int nc=0;

    //loop clusters
    while (track.GetCluster(xc, yc, zc, tc, nc, ec, extra))//loop clusters,gain the information of each cluster
    {
      counts++;
      cout<<"cluster position: "<< xc <<"\t"<< yc <<"\t"<< zc<<endl;

      //loop electrons in a cluster
      for (int k = 0; k < nc; k++)//loop electrons in a cluster,one cluster has nc number of electrons
      {
        double xe = 0., ye = 0., ze = 0., te = 0., ee = 0.;
        double dx = 0., dy = 0., dz = 0.;
        track.GetElectron(k, xe, ye, ze, te, ee, dx, dy, dz);//gain the electron information in one cluster
        drift.DriftElectron(xe, ye, ze, te);//calculate the drift of the electron
        
      }
    }

  }
  app.Run(true);
}

```

---

<div class="post-metadata">

**Author:** ![XiCheng](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/x/aca169/32.png) [@XiCheng](https://root-forum.cern.ch/u/XiCheng)\
**Post date:** [December 20, 2021, 9:32am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/8 "2021-12-20T09:32:22Z")

</div>

Hi,  
Thanks a lot for helping me . I have post the source code of the program I am running

---

<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:** [December 20, 2021, 9:42am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/9 "2021-12-20T09:42:08Z")

</div>

Thanks. You need to call `driftview.Plot(twod,axis);` **after** simulating the charged particle track and electron drift lines. If you call it before there are not drift lines present to be plotted.

---

<div class="post-metadata">

**Author:** ![XiCheng](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/x/aca169/32.png) [@XiCheng](https://root-forum.cern.ch/u/XiCheng)\
**Post date:** [December 20, 2021, 10:34am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/10 "2021-12-20T10:34:24Z")

</div>

Hi,  
Thanks a lot for telling me the reason of the problem. I put the driftview after simulating the charged particle track and electron drift lines. the results show in the below. It seems the particles are all killed.

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/2/0/206b8b144d32e968227a6b8042ee916d067b08b0.png)

---

<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:** [December 20, 2021, 2:01pm UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/11 "2021-12-20T14:01:21Z")

</div>

Looks like the process was killed by the kernel (maybe because it ran out of memory).  
I can’t say offhand what’s the reason for that, but I noticed something else when reading your code. The starting point is at the “top edge” of the geometry and the direction vector is (0, 1, 0). I guess you meant to use (0, -1, 0) instead, otherwise the proton has a high chance of escaping from the detector before it ionises.

 ![fieldmap](https://root-forum.cern.ch/uploads/default/original/3X/2/b/2b3393a3c5459243b91e9660b181b1a29b40a92b.png)

---

<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:** [December 20, 2021, 2:06pm UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/12 "2021-12-20T14:06:29Z")

</div>

I would also start with simulating and visualising a single electron drift line, and once you have checked that this works fine move on to simulating a charged particle track.

---

<div class="post-metadata">

**Author:** ![XiCheng](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/x/aca169/32.png) [@XiCheng](https://root-forum.cern.ch/u/XiCheng)\
**Post date:** [December 21, 2021, 2:13am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/13 "2021-12-21T02:13:25Z")

</div>

Hi,  
Thanks a lot for your reply.  
you are so meticulous,yes the direction vector actually should be -1. I have modified it ,and start with simulating and visualising a single electron drift line by setting the K value from K\<nc to K\<1. But the result seems the same, after get the bounding box, then killed.

```auto
 //loop electrons in a cluster
      for (int k = 0; **k < 1** ; k++)//loop electrons in a cluster,one cluster has nc number of electrons
      {
        double xe = 0., ye = 0., ze = 0., te = 0., ee = 0.;
        double dx = 0., dy = 0., dz = 0.;
        track.GetElectron(k, xe, ye, ze, te, ee, dx, dy, dz);//gain the electron information in one cluster
        drift.DriftElectron(xe, ye, ze, te);//calculate the drift of the electron
      }

```

---

<div class="post-metadata">

**Author:** ![XiCheng](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/x/aca169/32.png) [@XiCheng](https://root-forum.cern.ch/u/XiCheng)\
**Post date:** [December 21, 2021, 2:16am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/14 "2021-12-21T02:16:06Z")

</div>

Hi,  
There is indeed kernel problem, sometimes there maybe plot a curve and then disappeared. I don’t know how to enlarge the home directory. there are a lot of methods on line ,but they seem not fit for my ubuntu system.

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/1/0/104c77d7d9bc56d57e1e825a420ad7541e9fe326.png)

---

<div class="post-metadata">

**Author:** ![XiCheng](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/x/aca169/32.png) [@XiCheng](https://root-forum.cern.ch/u/XiCheng)\
**Post date:** [December 21, 2021, 2:25am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/15 "2021-12-21T02:25:21Z")

</div>

Hi,  
That’s the running results in the below

```auto
xxc@xxc-linux:~/garfieldpp/Gem/build$ ./gem
ComponentAnsys123::Initialise:
    Read properties of 2 materials from file MPLIST.lis.
ComponentAnsys123::Initialise:
    Read 2159067 elements from file ELIST.lis,
    highest node number: 3124105,
    background elements skipped: 0
ComponentAnsys123::Initialise:
    Read 3124105 nodes from file NLIST.lis.
ComponentAnsys123::Initialise:
    Read 3124105 potentials from file PRNSOL.lis.
ComponentAnsys123::Prepare:
    Caching the bounding boxes of all elements... done.
ComponentAnsys123::InitializeTetrahedralTree: Success.
ComponentAnsys123::PrintRange:
        Dimensions of the elementary block
                  -0.167044 < x < -0.0670436 cm,
                   0.172927 < y < 0.205927 cm,
                  -0.115321 < z < -0.0353211 cm,
                          0 < V < 1500 V.
        Periodicities
            x: none
            y: none
            z: none
ComponentAnsys123::PrintMaterials:
    Currently 2 materials are defined.
      Index Permittivity Resistivity Notes
          0 1 -1 (drift medium)
          1 4.25 1e+10
MediumMagboltz::LoadGasFile:
    Reading file N2.gas.
    Version 12.
    Gas composition set to N2.
MediumMagboltz::PrintGas:
    Gas composition: N2
    Pressure: 10 Torr
    Temperature: 293.15 K
    Gas file:
      Pressure: 10 Torr
      Temperature: 293.15 K
    Electric field range: 0.5 - 3 V/cm in 19 steps.
    Magnetic field: 0 T
    Angle between E and B: 1.5708 rad
    Available electron transport data:
      Velocity along E
      Velocity along Bt
      Velocity along ExB
        Low field extrapolation: constant
        High field extrapolation: linear
        Interpolation order: 2
      Longitudinal diffusion coefficient
      Transverse diffusion coefficient
      Diffusion tensor
        Low field extrapolation: constant
        High field extrapolation: linear
        Interpolation order: 2
      Townsend coefficient
        Low field extrapolation: constant
        High field extrapolation: linear
        Interpolation order: 2
      Attachment coefficient
        Low field extrapolation: constant
        High field extrapolation: linear
        Interpolation order: 2
      Lorentz Angle
        Low field extrapolation: constant
        High field extrapolation: linear
        Interpolation order: 2
      Ionisation rates
        N2 IONISATION N2+ X2SIGMA VIB=0 ELOSS= 15.581  
          Threshold = 15.5807 eV
        N2 IONISATION N2+ X2SIGMA VIB>0 ELOSS= 15.855  
          Threshold = 15.8547 eV
        N2 IONISATION N2+ A2PI VIB=0 ELOSS= 16.699  
          Threshold = 16.6987 eV
        N2 IONISATION N2+ A2PI VIB=1 ELOSS= 16.935  
          Threshold = 16.9347 eV
        N2 IONISATION N2+ A2PI VIB>1 ELOSS= 17.171  
          Threshold = 17.1707 eV
        N2 IONISATION N2+ B2SIGMA ELOSS= 18.751  
          Threshold = 18.7506 eV
        N2 IONISATION N2+ C2SIGMA ELOSS= 23.591  
          Threshold = 23.5905 eV
        N2 DISSOC ION (N+,N) ELOSS= 24.294  
          Threshold = 24.2935 eV
        N2 DISSOC ION (N+,N*) ELOSS= 24.4    
          Threshold = 24.3995 eV
        N2 DISSOC ION (N+*,N) ELOSS= 35.7    
          Threshold = 35.6993 eV
        N2 DISSOC ION (N++,N) AND (N+,N+) ELOSS= 38.8    
          Threshold = 38.7992 eV
        N2 IONISATION K-SHELL ELOSS= 401.6    
          Threshold = 401.592 eV
        Low field extrapolation: constant
        High field extrapolation: linear
        Interpolation order: 2
    Available ion transport data:
      none
Killed

```

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [December 21, 2021, 7:58am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/16 "2021-12-21T07:58:37Z")

</div>

> [@Cannot open file He.gas](https://root-forum.cern.ch/t/cannot-open-file-he-gas/48061/5):
>
> You need to execute [“ulimit -s unlimited”](https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#index-ulimit) BEFORE you start your executable.

---

<div class="post-metadata">

**Author:** ![XiCheng](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/x/aca169/32.png) [@XiCheng](https://root-forum.cern.ch/u/XiCheng)\
**Post date:** [December 21, 2021, 8:19am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/17 "2021-12-21T08:19:35Z")

</div>

Hi,  
Thanks for your advice, I will try to execute “ulimit -s unlimited” BEFORE I start my executable to see whether it can fix.

---

<div class="post-metadata">

**Author:** ![XiCheng](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/x/aca169/32.png) [@XiCheng](https://root-forum.cern.ch/u/XiCheng)\
**Post date:** [December 21, 2021, 9:32am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/18 "2021-12-21T09:32:25Z")

</div>

Hi,  
I have tried the ulimit -s unlimited, it can work. However the drift lines are empty and notice "could not determine the plot limits.

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/6/9/69fd7f83417a2848577cf5f97ca8275682b53bba.png)

---

<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:** [December 21, 2021, 11:22am UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/19 "2021-12-21T11:22:22Z")

</div>

Hi,

the reason you don’t see any drift lines is that the proton has very little chance to ionize the gas before it leaves the detector.  
I don’t have your gas file, so I used another one (the one from the drift tube example) to run (a slightly modified version of) your program. In my version of the program (which you’l find attached) I added a line `track.Initialise(&gas, true);` to print out some information about the ionisation cross-section of the charged particle. For the gas file I’m using, which is at a pressure of 3 atmospheres, the cluster density (average number of ionising collisions per track length) is about 100 / cm.

Your field map has a length of 300 um along y. So, with the gas file I’m using, the charged particle should on average have about 3 ionising collisions (=clusters) inside the detector. I’ve run the program a few times and this seems about right, that is I did get a couple of clusters and electron drift lines.

The gas file you are using is for a pressure of 10 Torr though, so the cluster density is very low and that’s why in most cases there will be no clusters, and thus no drift lines in your plot.

[test.C](https://root-forum.cern.ch/uploads/short-url/usFXohPvBBymCOTWV9L0V9y2SfU.C) (2.7 KB)

---

<div class="post-metadata">

**Author:** ![XiCheng](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/x/aca169/32.png) [@XiCheng](https://root-forum.cern.ch/u/XiCheng)\
**Post date:** [December 21, 2021, 1:02pm UTC](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120/20 "2021-12-21T13:02:44Z")

</div>

Hi,  
Thanks for your help.  
I don’t know how to say, you are indeed a Garfield++ master, what you say is clear and intelligible.  
I have modified the pressure to 750 Torr which is the biggest pressure of the detector, maybe the detector’s design approaches to the vacuum condition.  
Thanks again!

[Next page](https://root-forum.cern.ch/t/how-to-plot-the-drift-line/48120.md?page=2)
