# Questions about DriftNegativeIon

**URL:** <https://root-forum.cern.ch/t/questions-about-driftnegativeion/55113>\
**Category:** Garfield++\
**Created:** [May 31, 2023, 2:02pm UTC](https://root-forum.cern.ch/t/questions-about-driftnegativeion/55113 "2023-05-31T14:02:21Z")\
**Posts on this page:** 11\
**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:** [May 31, 2023, 2:02pm UTC](https://root-forum.cern.ch/t/questions-about-driftnegativeion/55113/1 "2023-05-31T14:02:21Z")

</div>

Hello  
I would like to confirm whether DriftLineRKF and AvalancheMC consider diffusion when simulating negative ion drift.

---

<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:** [May 31, 2023, 2:17pm UTC](https://root-forum.cern.ch/t/questions-about-driftnegativeion/55113/2 "2023-05-31T14:17:00Z")

</div>

AvalancheMC does, DriftLineRKF does not.

---

<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:** [May 31, 2023, 2:48pm UTC](https://root-forum.cern.ch/t/questions-about-driftnegativeion/55113/3 "2023-05-31T14:48:30Z")

</div>

> [@hschindl](#):
>
> AvalancheMC does, DriftLineRKF does not.

When I use AvalancheMC DriftNegativeIon ( xe1, ye1, ze1, te1); the program will report **an error " AvalancheMC: :Avalanche:Neither electron nor hole/ion component requested."** However, when DriftLineRKF DriftNegativeIon ( xe1, ye1, ze1, te1 ) is used, the program can run.  
Here are the key code.

```auto
   AvalancheMC *avalMC = new AvalancheMC();
    avalMC->SetSensor(&sensor);
    avalMC->EnableSignalCalculation(true);
    avalMC->UseWeightingPotential(true);
    avalMC->DisableAvalancheSizeLimit();

    DriftLineRKF *drift = new DriftLineRKF();
    drift->SetSensor(&sensor);
    drift->EnableNegativeIonTail(true);
    drift->EnableSignalCalculation(true);
    drift->SetMaximumStepSize(10e-4);

   for (unsigned int i = 0; i < nTracks; i++)
    {
        unsigned int netot = 0;
        tr->NewTrack(0, 0.8 * Ymax, 0, 0., 0., -1., 0.);
        for (const auto &cluster : tr->GetClusters())
        {
            netot += cluster.n;
            avalMC->SetElectronSignalScalingFactor(cluster.n);
            avalMC->DriftElectron(cluster.x, cluster.y, cluster.z, cluster.t);
            avalMC->GetElectronEndpoint(0, xe0, ye0, ze0, te0, xe1, ye1, ze1, te1, status);
            avalMC->SetIonSignalScalingFactor(cluster.n);
            avalMC->DriftNegativeIon(xe1, ye1, ze1, te1);

            // if (status == -7)
            // {
            // drift->SetIonSignalScalingFactor(cluster.n);
            // drift->DriftNegativeIon(xe1, ye1, ze1, te1);
            // drift->GetEndPoint(xi1, yi1, zi1, ti1, statusi);
            // // cout << "ion position: " << xi1 << "," << yi1 << "," << zi1 << endl;
            // // cout << "=======statusi======" << statusi << endl;
            // }
            
        }
    }

```

Is it because AvalancheMC does not have the **EnableNegativeIonTail (true)** function in DriftLineRKF ? This is just my guess, look forward to your explanation of this error.Thanks!

---

<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:** [May 31, 2023, 3:11pm UTC](https://root-forum.cern.ch/t/questions-about-driftnegativeion/55113/4 "2023-05-31T15:11:43Z")

</div>

That may be a bug. Will take a look…

---

<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:** [June 1, 2023, 5:52am UTC](https://root-forum.cern.ch/t/questions-about-driftnegativeion/55113/6 "2023-06-01T05:52:58Z")

</div>

Should be fixed now:

> **[Bug fix for negative ion drift in AvalancheMC (!358) · Merge requests ·...](https://gitlab.cern.ch/garfield/garfieldpp/-/merge_requests/358)**
>
> http://garfieldpp.web.cern.ch/garfieldpp/

---

<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:** [June 1, 2023, 7:00am UTC](https://root-forum.cern.ch/t/questions-about-driftnegativeion/55113/7 "2023-06-01T07:00:20Z")

</div>

> [@hschindl](#):
>
> Should be fixed now:  
> [Bug fix for negative ion drift in AvalancheMC (!358) · Merge requests · garfield / garfieldpp · GitLab](https://gitlab.cern.ch/garfield/garfieldpp/-/merge_requests/358)

Thanks a lot, the error **‘AvalancheMC: :Avalanche : Nether electron nor hole/ion component requested.’**  **disappeared**.But there was **a new error** , use AvalancheMC to simulate the drift of negative ions was very slow, **and the computer memory overflowed** , and the **program was killed**. But I would like to **use AvalancheMC because it takes into account the diffusion** of ions.  
So if I want to consider diffusion and will not make computer memory overflow, do you have any suggestions?

Here are the key code

```auto
 for (unsigned int i = 0; i < nTracks; i++)
    {
        unsigned int netot = 0;
        tr->NewTrack(5, 0.8 * Ymax, 5, 0., 0., -1., 0.);
        for (const auto &cluster : tr->GetClusters())
        {
            netot += cluster.n;
            avalMC->SetElectronSignalScalingFactor(cluster.n);
            avalMC->DriftElectron(cluster.x, cluster.y, cluster.z, cluster.t);
            avalMC->GetElectronEndpoint(0, xe0, ye0, ze0, te0, xe1, ye1, ze1, te1, statuse);
            cout << "=======statuse======" << statuse << endl;
            avalMC->SetIonSignalScalingFactor(cluster.n);
            avalMC->DriftNegativeIon(xe1, ye1, ze1, te1);
        }
    }

```

---

<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:** [June 1, 2023, 7:12am UTC](https://root-forum.cern.ch/t/questions-about-driftnegativeion/55113/8 "2023-06-01T07:12:31Z")

</div>

Try to set the step size explicitly. For instance, to set 100 um steps:

```auto
avalMC->SetDistanceSteps(0.01);

```

---

<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:** [June 1, 2023, 7:34am UTC](https://root-forum.cern.ch/t/questions-about-driftnegativeion/55113/9 "2023-06-01T07:34:32Z")

</div>

> [@hschindl](#):
>
> Try to set the step size explicitly. For instance, to set 100 um steps:
> 
> ```auto
> avalMC->SetDistanceSteps(0.01);
> 
> ```

Thank you very much! avalMC-\>SetDistanceSteps(0.01); make sense

I still have two small questions：

1. Is **avalMC-\>SetIonSignalScalingFactor(cluster.n)** applicable to both negative ions and positive ions?"

2.The **status obtained using drift-\>DriftElectron() is -1**. **( Notice: I did not open drift-\>EnableNegativeIonTail(true);**. However, when using **avalMC-\>DriftElectron(), the obtained status is -7**. Could you explain it briefly？

Therefore, if using DriftLineRKF, **I get a driftline without using drift-\>DriftNegativeIon(xe1, ye1, ze1, te1);**

```auto
drift->SetElectronSignalScalingFactor(cluster.n);
drift->DriftElectron(cluster.x, cluster.y, cluster.z, cluster.t);
drift->GetEndPoint(xe1, ye1, ze1, te1, statuse);
cout << "eletron position: " << xe1 << "," << ye1 << "," << ze1 << endl;
cout << "=======status======" << statuse << endl;

```

---

<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:** [June 1, 2023, 3:53pm UTC](https://root-forum.cern.ch/t/questions-about-driftnegativeion/55113/10 "2023-06-01T15:53:17Z")

</div>

1. Yes, it’s applied to both. But if needed, we could add a separate scaling factor for negative ions.

2. DriftLineRKF first calculates the average drift path of an electron (or ion), essentially following the electric field lines until the particle leaves the active region, without any random element, and subsequently calculates the multiplication and attachment along this average drift path. If enabled, it then simulates (positive and negative) ion drift lines with starting points according to the multiplication and attachment profile along the drift line.  
AvalancheMC simulates _individual_ electrons (or ions). It does include a random component, if you call AvalancheMC::DriftElectron multiple times, you will get (slightly) different results, some might be lost due to attachment, some might make it to the electrode, etc.

---

<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:** [June 2, 2023, 12:53am UTC](https://root-forum.cern.ch/t/questions-about-driftnegativeion/55113/11 "2023-06-02T00:53:40Z")

</div>

I understand，thanks a lot!

---

<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:** [June 16, 2023, 12:53am UTC](https://root-forum.cern.ch/t/questions-about-driftnegativeion/55113/12 "2023-06-16T00:53:48Z")

</div>

Closed on June 16, 2023, 12:53am UTC

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