What is the difference between 2 methods to add medium gas

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:


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:

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?

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.

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