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


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:

#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.);

  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;

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

GeometrySimple* GeometryConstructor()
    GeometrySimple* geo = new GeometrySimple();
    // Make a medium
    MediumMagboltz* gas = new MediumMagboltz();
    gas->SetComposition("Ar", 90., "CO2", 10.); 
    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,

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.

1 Like

Thank you!

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