# What is the difference between 2 methods to add medium gas

**URL:** <https://root-forum.cern.ch/t/what-is-the-difference-between-2-methods-to-add-medium-gas/50246>\
**Category:** Garfield++\
**Created:** [June 2, 2022, 4:56pm UTC](https://root-forum.cern.ch/t/what-is-the-difference-between-2-methods-to-add-medium-gas/50246 "2022-06-02T16:56:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [June 2, 2022, 4:56pm UTC](https://root-forum.cern.ch/t/what-is-the-difference-between-2-methods-to-add-medium-gas/50246/1 "2022-06-02T16:56:56Z")

</div>

Dear experts, I used **GeometrySimple::Addsolid(box, gas)** to add the medium gas but I got complain from **TrackHeed::NewTrack**  
Here are part of my codes:

```auto

void simXT::SetupGeo(std::string geoFile){
        fGeo= new GeometrySimple();

        TFile* f_geo = new TFile(geoFile.c_str(), "read");
        if(!f_geo) std::cerr<<"Can not find Geo file!"<<std::endl;
        TTree* t_geo = (TTree*)f_geo->Get("t");

        t_geo->SetBranchAddress("x", &wire_x);
        t_geo->SetBranchAddress("y", &wire_y);
        t_geo->SetBranchAddress("type", &wire_type);

        SolidBox* box = new SolidBox(-5, -5, -fSize_box/2, 5, 5, fSize_box/2);
        fGeo->AddSolid(box,fGas);
        fGeo->PrintSolids();
        fGeo->SetMedium(fGas);

        std::cout<<"\033[32m";
        std::cout<<fGeo->IsInside(0, 0, -73)<<std::endl;
        std::cout<<"\033[0m";

        fCompE_field = new ComponentAnalyticField();
        fCompE_field->SetGeometry(fGeo);

        for(int i=0; i<t_geo->GetEntries(); i++){
                t_geo->GetEntry(i);
                if(wire_type == 0) fCompE_field->AddWire(wire_x, wire_y, r_field, fHV*wire_type, "field");
                if(wire_type == 1) fCompE_field->AddWire(wire_x, wire_y, r_sense, fHV*wire_type, "sense");
                std::cout<<"added wire at "<<wire_x<<" "<<wire_y<<std::endl;
        }

        fCompE_field->AddReadout("sense");
        fCompE_field->SetMagneticField(0, 0, 0);

        std::cout<<"Set geometry for EM field"<<std::endl;
        //view geometry
        ViewCell* cellView = new ViewCell();
        cellView->SetCanvas(fMyCanvas);
        cellView->EnableWireMarkers();
        cellView->SetComponent(fCompE_field);
        cellView->SetArea(-5, -5, -fSize_box/2, 5, 5, fSize_box/2);
        cellView->Plot2d();

        fFile_out->cd();
        fMyCanvas->Write();
        fFile_out->Close();
}

void simXT::SetupSensor(){
        const double tMin = 0.;
        const double tMax = 2.;
        const double tStep = 0.01;
        const int nSteps = (int)(tMax-tMin)/tStep;
        fSensor_e = new Sensor();
        fSensor_e->AddComponent(fCompE_field);
        fSensor_e->SetArea(-5., -5., -fSize_box/2, 5., 5., fSize_box/2);
        fSensor_e->AddElectrode(fCompE_field, "sense");
        fSensor_e->SetTimeWindow(0., tStep, nSteps);
}

void simXT::MakeTrack(){
        TrackHeed* track = new TrackHeed();
        track->SetSensor(fSensor_e);
        track->SetParticle(fPrimaryParticle);
        track->SetMomentum(fPrimaryMomentum);
        track->EnableDebugging();

        DriftLineRKF* drift = new DriftLineRKF();
        drift->SetSensor(fSensor_e);

        track->NewTrack(0.5, 0.5, 0., 0., -1., -1., 0.);
        //cluster coordinates
        double xc = 0., yc = 0., zc = 0., tc = 0.;
        //number of electrons produced in a collision
        int nc = 0;
        //energy loss in a collision
        double ec = 0.;
        //dummy variable
        double extra = 0.;
        while(track->GetCluster(xc, yc, zc, tc, nc, ec, extra)){ // Why not use references but normal variables?
                std::cout<<nc<<" of electrons generated"<<std::endl;
                double del_x, del_y, del_z, del_t;
                double ke;
                double dummy;
                track->GetElectron(0, del_x, del_y, del_z, del_t, ke, dummy, dummy, dummy);
                drift->DriftElectron(del_x, del_y, del_z, del_t);
                std::cout<<"electron at "<<del_x<<" "<<del_y<<" "<<del_z<<std::endl;
        }
        ViewDrift* draw_drift = new ViewDrift();
        track->EnablePlotting(draw_drift);
        drift->EnablePlotting(draw_drift);
        draw_drift->Plot();

}

```

Error message:

```auto
TrackHeed::NewTrack:
    No medium at initial position.

```

When I added another function **GeometrySimple::SetMedium(gas)** it didn’t complain. I wonder why I need to set gas twice and what is the difference?

---

<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 2, 2022, 8:00pm UTC](https://root-forum.cern.ch/t/what-is-the-difference-between-2-methods-to-add-medium-gas/50246/2 "2022-06-02T20:00:52Z")

</div>

> [@Crisps](#):
>
> I wonder why I need to set gas twice

You don’t need to. `fGeo->AddSolid(box,fGas);` sets the medium (`fGas`) to be associated with the `SolidBox` object. `fGeo->SetMedium(fGas);` sets the “background medium”, i. e. the medium everywhere else other than inside the box.

The reason for the error message is that the starting point of the track (0.5, 0.5, 0) is outside the `SolidBox` object which is centred at (-5, -5, -fSize\_box/2) and has half widths of 5 cm in x and y and fSize\_box/2 along z.

---

<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, 2022, 8:01pm UTC](https://root-forum.cern.ch/t/what-is-the-difference-between-2-methods-to-add-medium-gas/50246/3 "2022-06-16T20:01:11Z")

</div>

Closed on June 16, 2022, 8:01pm UTC

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