# Deference between using a ".gas" file and setting gas parameters in code

**URL:** <https://root-forum.cern.ch/t/deference-between-using-a-gas-file-and-setting-gas-parameters-in-code/54224>\
**Category:** Garfield++\
**Created:** [March 26, 2023, 8:05am UTC](https://root-forum.cern.ch/t/deference-between-using-a-gas-file-and-setting-gas-parameters-in-code/54224 "2023-03-26T08:05:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DvirAY](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/8e7dd6/32.png) [@DvirAY](https://root-forum.cern.ch/u/DvirAY)\
**Post date:** [March 26, 2023, 8:05am UTC](https://root-forum.cern.ch/t/deference-between-using-a-gas-file-and-setting-gas-parameters-in-code/54224/1 "2023-03-26T08:05:34Z")

</div>

Hello,

I am simulating a drift tube detector and I came across something I can’t explain.  
In short, If I am using “GasFile” example to generate gas file with specific parameters, and then load said file in my simulation I get different results then setting the same parameters for the gas is the simulation file. (Random seed exists in code and working).

The modified GasFile example:

```auto
#include <iostream>
#include "Garfield/MediumMagboltz.hh"
#include "Garfield/FundamentalConstants.hh"
using namespace Garfield;

int main(int argc, char * argv[]) {
  const double pressure = 2 * AtmosphericPressure;
  const double temperature = 293.15 + 20 ; 

  MediumMagboltz gas("Ar", 90., "CO2", 10.);
  gas.SetTemperature(temperature);
  gas.SetPressure(pressure);

  const size_t nE = 200;
  const double emin = 100.;
  const double emax = 1000 ;
  constexpr bool useLog = true;
  gas.SetFieldGrid(emin, emax, nE, useLog);

  const int ncoll = 10;
  gas.GenerateGasTable(ncoll);
  gas.WriteGasFile("ar_90_co2_10_atm2.gas");
}

```

In the simulation code, when I don’t load that gas file I use:

```auto
GeometrySimple* GeometryConstructor()
{
    GeometrySimple* geo = new GeometrySimple();
    // Make a medium
    MediumMagboltz* gas = new MediumMagboltz();
    gas->SetComposition("Ar", 90., "CO2", 10.); 
    gas->SetTemperature(273.15+25); 
    const double now_pressure = 2 * AtmosphericPressure ;
    gas->SetPressure(now_pressure) ;
    // gas->LoadGasFile("ar_90_co2_10_atm2.gas") ;
    auto installdir = std::getenv("GARFIELD_INSTALL");
    if (!installdir) {
      std::cerr << "GARFIELD_INSTALL variable not set.\n" ;
    }
    const std::string path = installdir;
    gas->LoadIonMobility(path + "/share/Garfield/Data/IonMobility_Ar+_Ar.txt");
    // gas->Initialise(0); 
    SolidTube* tube = new SolidTube(0., 0., 0., rTube, lTube) ;
    geo->AddSolid(tube, gas) ; 

    return geo;
}

```

Right below the gas parameters there is a commented line that load the gas file if I want. I comment out the four lines above it if I load a gas file.

What is the source of the different results I get for allegedly the same parameters?  
In general, is it better to load a gas file to a simulation or to generate gas parameters in it?

Have a good day,  
Dvir

---

<div class="post-metadata">

**Author:** ![mjag](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/ce7236/32.png) [@mjag](https://root-forum.cern.ch/u/mjag)\
**Post date:** [March 27, 2023, 11:04am UTC](https://root-forum.cern.ch/t/deference-between-using-a-gas-file-and-setting-gas-parameters-in-code/54224/2 "2023-03-27T11:04:48Z")

</div>

Hello,  
at first glance it looks like your saved gas has temperature of 293.15 + 20 = 313.15 kelvin while ad hoc generated gas is at 273.15 + 25 = 298.15 kelvin. Additionally, in second part you don’t SetFieldGrid.

---

<div class="post-metadata">

**Author:** ![DvirAY](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/8e7dd6/32.png) [@DvirAY](https://root-forum.cern.ch/u/DvirAY)\
**Post date:** [March 28, 2023, 8:17am UTC](https://root-forum.cern.ch/t/deference-between-using-a-gas-file-and-setting-gas-parameters-in-code/54224/3 "2023-03-28T08:17:46Z")

</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:** [April 11, 2023, 8:18am UTC](https://root-forum.cern.ch/t/deference-between-using-a-gas-file-and-setting-gas-parameters-in-code/54224/4 "2023-04-11T08:18:27Z")

</div>

Closed on April 11, 2023, 8:18am UTC

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