# Plotting the Townsend Coefficient for Gas Files in Garfield++

**URL:** <https://root-forum.cern.ch/t/plotting-the-townsend-coefficient-for-gas-files-in-garfield/55520>\
**Category:** Garfield++\
**Tags:** root\
**Created:** [July 3, 2023, 10:27am UTC](https://root-forum.cern.ch/t/plotting-the-townsend-coefficient-for-gas-files-in-garfield/55520 "2023-07-03T10:27:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Khalil\_Alashy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/khalil_alashy/32/33464_2.png) [@Khalil\_Alashy](https://root-forum.cern.ch/u/Khalil_Alashy)\
**Post date:** [July 3, 2023, 10:27am UTC](https://root-forum.cern.ch/t/plotting-the-townsend-coefficient-for-gas-files-in-garfield/55520/1 "2023-07-03T10:27:24Z")

</div>

I am trying to Plot the Townsend and Attachment Coefficients for a specific Gas File I have generated. I have found success using a for loop that loops over the applied electric field and uses the MagBoltz function:

```auto
gas1->ElectronTownsend(ex, ey, ez, bx, by, bz, alpha)

```

I am now experimenting with another function I found in ViewMedium.hh: PlotElectronTownsend ().  
I am unsure how to proceed and see the plot after defining the medium and electric field range.  
This is the code:

```auto
using namespace Garfield;

int main(int argc, char * argv[]) {
    // Make a medium
    double temperature = ZeroCelsius + 20;
    double pressure = 1.1* AtmosphericPressure;
    MediumMagboltz* gas = new MediumMagboltz();
    gas->LoadGasFile("c2f4h2_85_ic4h10_5_sf6_10.gas");
    gas->Initialise(true);
    gas->SetTemperature(temperature);
    gas->SetPressure(pressure);
    TCanvas *c1 = new TCanvas("c1","Graph Draw Options", 600, 600);
    ViewMedium* viewer = new ViewMedium();
     viewer->SetMedium(gas);
     viewer->SetRangeE(100., 100000.,true);
     viewer->PlotElectronTownsend('e');
     viewer->SetCanvas(c1);
     c1->SaveAs("Townsend.png");
}

```

Of course, the proper Garfield files are included.

If anyone can help, I’d appreciate it.

Best,  
Khalil

---

<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:** [July 3, 2023, 11:43am UTC](https://root-forum.cern.ch/t/plotting-the-townsend-coefficient-for-gas-files-in-garfield/55520/2 "2023-07-03T11:43:10Z")

</div>

I guess @hschindl can help.

---

<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:** [July 3, 2023, 2:02pm UTC](https://root-forum.cern.ch/t/plotting-the-townsend-coefficient-for-gas-files-in-garfield/55520/3 "2023-07-03T14:02:56Z")

</div>

Hi,  
you can use this example as a starting point:

> **[Examples/GasFile/read.C · master · garfield / garfieldpp · GitLab](https://gitlab.cern.ch/garfield/garfieldpp/-/blob/master/Examples/GasFile/read.C)**
>
> http://garfieldpp.web.cern.ch/garfieldpp/

---

<div class="post-metadata">

**Author:** ![Khalil\_Alashy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/khalil_alashy/32/33464_2.png) [@Khalil\_Alashy](https://root-forum.cern.ch/u/Khalil_Alashy)\
**Post date:** [July 3, 2023, 2:11pm UTC](https://root-forum.cern.ch/t/plotting-the-townsend-coefficient-for-gas-files-in-garfield/55520/4 "2023-07-03T14:11:22Z")

</div>

Thank you!

---

<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:** [July 17, 2023, 2:12pm UTC](https://root-forum.cern.ch/t/plotting-the-townsend-coefficient-for-gas-files-in-garfield/55520/5 "2023-07-17T14:12:14Z")

</div>

Closed on July 17, 2023, 2:12pm UTC

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