# Problems about drift time in a uniform field

**URL:** <https://root-forum.cern.ch/t/problems-about-drift-time-in-a-uniform-field/54475>\
**Category:** Garfield++\
**Created:** [April 14, 2023, 7:24am UTC](https://root-forum.cern.ch/t/problems-about-drift-time-in-a-uniform-field/54475 "2023-04-14T07:24:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zql21](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/zql21/32/33487_2.png) [@zql21](https://root-forum.cern.ch/u/zql21)\
**Post date:** [April 14, 2023, 7:24am UTC](https://root-forum.cern.ch/t/problems-about-drift-time-in-a-uniform-field/54475/1 "2023-04-14T07:24:17Z")

</div>

I intend to study the motion of electrons ionized by 6MeV alpha particles in the drift electric field ( assuming a uniform electric field ). I want to obtain **the drift time** of the electron ( moving from the top of the drift electric field to the bottom ) and **the position** of the electron **reaching the bottom of the drift electric field** ( in order to evaluate the position resolution ).  
However, the 6MeV alpha particles produce a large number of electrons, so I simulate an electron ( assuming that this electron is a primary electron produced by alpha ionization ). The initial position of the electron is at the top of the drift electric field, and the direction is -z.  
I use avalMicro.DriftElectron( and avalMicro.AvalancheElectron) to simulate the drift of electron，avalMicro.GetNumberOfElectronEndpoints() to get drift time and position  
The code is as follows :

```auto
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <TCanvas.h>
#include <TROOT.h>
#include <TApplication.h>
#include "Garfield/Random.hh"
#include "Garfield/ViewCell.hh"
#include "Garfield/ViewDrift.hh"
#include "Garfield/ViewSignal.hh"
#include "Garfield/ViewField.hh"
#include "Garfield/ComponentAnalyticField.hh"
#include "Garfield/ComponentConstant.hh"
#include "Garfield/MediumMagboltz.hh"
#include "Garfield/Sensor.hh"
#include "Garfield/DriftLineRKF.hh"
#include "Garfield/AvalancheMicroscopic.hh"
#include "Garfield/AvalancheMC.hh"
#include "Garfield/TrackHeed.hh"

using namespace Garfield;
using namespace std;

int main(int argc, char *argv[])
{
    TApplication app("app", &argc, argv);
    // Set gas
    MediumMagboltz gas;
    gas.SetTemperature(293.15);
    gas.SetPressure(760.);
    gas.SetMaxElectronEnergy(200.);
    gas.SetComposition("Ar", 0.94, "CO2", 0.03, "H2O", 0.03, "O2", 20.9, "N2", 78.1);
    gas.Initialise(true); // prepares the table of microscopic scattering rates
    gas.LoadGasFile("gas_293_1atm_10-100000nE20.gas");
    const string ionpath = std::getenv("GARFIELD_INSTALL");
    gas.LoadIonMobility(ionpath + "/share/Garfield/Data/IonMobility_Ar+_Ar.txt");
    // uniform field
    ComponentConstant cmp;
    constexpr double xlength = 10.; // cm
    constexpr double ylength = 10.;
    constexpr double zlength = 10.;
    const double xmin = -0.5 * xlength;
    const double xmax = 0.5 * xlength;
    const double ymin = -0.5 * ylength;
    const double ymax = 0.5 * ylength;
    const double zmin = 0;
    const double zmax = zlength;
    cmp.SetArea(xmin, ymin, zmin, xmax, ymax, zmax);
    cmp.SetMedium(&gas);
    cmp.SetElectricField(0., 0., 800.); // V/cm

    ViewField fieldView;
    constexpr bool plotField = true;
    if (plotField)
    {
        fieldView.SetComponent(&cmp);
        fieldView.SetPlaneXZ(); // viewing plane (xz plane).
        fieldView.SetArea(xmin, zmin, xmax, zmax);
        TCanvas *cf = new TCanvas("cf", "", 600, 600);
        cf->SetLeftMargin(0.16);
        fieldView.SetCanvas(cf);
        // fieldView.PlotContour("v");
        fieldView.Plot("v", "CONT1");
        std::vector<double> xf;
        std::vector<double> yf;
        std::vector<double> zf;
        fieldView.EqualFluxIntervals(xmin, 0, 0.99 * zmax, xmax, 0, 0.99 * zmax, xf, yf, zf, 20);
        fieldView.PlotFieldLines(xf, yf, zf, true, false);
    }
    Sensor sensor;
    sensor.AddComponent(&cmp);

    DriftLineRKF drift;
    drift.SetSensor(&sensor);
    AvalancheMicroscopic avalMicro;
    avalMicro.SetSensor(&sensor);
    AvalancheMC avalMC;
    avalMC.SetSensor(&sensor);
    TrackHeed track;
    track.SetParticle("e-");
    track.SetEnergy(1e6);
    track.SetSensor(&sensor);

    TCanvas *cD = nullptr;
    ViewDrift driftView;
    constexpr bool plotDrift = true;
    if (plotDrift)
    {
        cD = new TCanvas("cD", "", 600, 600);
        driftView.SetCanvas(cD);
        avalMicro.EnablePlotting(&driftView);
        drift.EnablePlotting(&driftView);
        avalMC.EnablePlotting(&driftView);
    }
    const unsigned int nEvents = 10;
    const double x0 = 0;
    const double y0 = 0;
    const double z0 = 9;
    const double t0 = 0.;
    const double e0 = 0.1;
    const double dx0 = 0.;
    const double dy0 = 0;
    const double dz0 = -1.;
    std::ofstream datafile;
    std::string filename = "data_drift.txt";
    datafile.open(filename);

    for (unsigned int i = 0; i < nEvents; ++i)
    {
        // track.NewTrack(x0, y0, z0, t0, dx0, dy0,dz0);
        avalMicro.DriftElectron(x0, y0, z0, t0, e0, dx0, dy0, dz0);
        // avalMicro.AvalancheElectron(x0, y0, z0, t0, e0, dx0, dy0, dz0);

        const unsigned int np = avalMicro.GetNumberOfElectronEndpoints();
        // const unsigned int numdriPoint = avalMicro.GetNumberOfElectronDriftLinePoints();
        cout << "np: " << np << "\n";

        double xe1, ye1, ze1, te1, e1;
        double xe2, ye2, ze2, te2, e2;
        int status;
        std::ostringstream out;
        for (unsigned int j = 0; j < np; ++j)
        {
            avalMicro.GetElectronEndpoint(j, xe1, ye1, ze1, te1, e1,
                                          xe2, ye2, ze2, te2, e2, status);
            out << "i=" << i << " ,"
                << "j=" << j << ","
                << " ze1=" << ze1 << " ze2=" << ze2
                << " xe1=" << xe1 << " xe2=" << xe2 
                << " ye1=" << ye1 << " ye2=" << ye2 << std::endl;
        }
        std::string out_str = out.str();
        datafile << out_str;
        out.clear();
    }
    datafile.close();
    app.Run(true);
}

```

However, the result shows that the position of the electron changes little.

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

Can you help me have a look if the idea is correct?How can I get the drift time and drift line from the top of the drift electric field to the bottom, should I use TrackHeed ?  
I would appreciate it if you could provide some advice,Thanks a lot!

---

<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:** [April 14, 2023, 8:32am UTC](https://root-forum.cern.ch/t/problems-about-drift-time-in-a-uniform-field/54475/2 "2023-04-14T08:32:42Z")

</div>

@hschindl can most probably help you

---

<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:** [April 14, 2023, 9:01am UTC](https://root-forum.cern.ch/t/problems-about-drift-time-in-a-uniform-field/54475/3 "2023-04-14T09:01:13Z")

</div>

The electrons are probably stopped because of attachment. You can check using the `status` flag (attachment corresponds to a value of -7).

---

<div class="post-metadata">

**Author:** ![zql21](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/zql21/32/33487_2.png) [@zql21](https://root-forum.cern.ch/u/zql21)\
**Post date:** [April 15, 2023, 3:06am UTC](https://root-forum.cern.ch/t/problems-about-drift-time-in-a-uniform-field/54475/4 "2023-04-15T03:06:19Z")

</div>

> [@hschindl](#):
>
> The electrons are probably stopped because of attachment. You can check using the `status` flag (attachment corresponds to a value of -7).

Yes,the status is -7.  
I increase the electric field and get the drift line. As shown in the figure

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/2/c/2c8e23d1c608d18af1a1d84f7b3c319389e1d02b.png)  
I change the color value in **ViewDrift.hh** ,but the color of the drift line is still yellow and green, so I really don 't know what yellow and green mean?  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/7/b/7b055da5263e587adee729a7f646329abc56f667.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:** [April 15, 2023, 6:39am UTC](https://root-forum.cern.ch/t/problems-about-drift-time-in-a-uniform-field/54475/5 "2023-04-15T06:39:36Z")

</div>

[https://root.cern.ch/doc/master/classTColor.html](https://root.cern.ch/doc/master/classTColor.html)

---

<div class="post-metadata">

**Author:** ![zql21](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/zql21/32/33487_2.png) [@zql21](https://root-forum.cern.ch/u/zql21)\
**Post date:** [April 15, 2023, 7:13am UTC](https://root-forum.cern.ch/t/problems-about-drift-time-in-a-uniform-field/54475/6 "2023-04-15T07:13:15Z")

</div>

> [@hschindl](#):
>
> [ROOT: TColor Class Reference](https://root.cern.ch/doc/master/classTColor.html)

Thanks your reply.I’m sorry maybeI didn’t express the question clearly.my question is, I want to know what the yellow and green on the drift curve mean, is there a physical meaning?

---

<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:** [April 15, 2023, 10:02am UTC](https://root-forum.cern.ch/t/problems-about-drift-time-in-a-uniform-field/54475/7 "2023-04-15T10:02:30Z")

</div>

The green line/dots are the clusters on the charged-particle track. The yellow/orange lines are the electron drift lines.

---

<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 29, 2023, 10:02am UTC](https://root-forum.cern.ch/t/problems-about-drift-time-in-a-uniform-field/54475/8 "2023-04-29T10:02:56Z")

</div>

Closed on April 29, 2023, 10:02am UTC

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