Exemplo n.º 1
0
 void start() {
     if (times(&tstart) < 0) {
         egsWarning(" times returned < 0???\n");
     }
 };
Exemplo n.º 2
0
EGS_Object *EGS_ObjectFactory::createSingleObject(EGS_Input *i,
        const char *funcname, bool unique) {
    if (!i) {
        egsWarning("EGS_ObjectFactory::createSingleObject(): null input?\n");
        return 0;
    }
    string type;
    int err = i->getInput("type",type);
    if (!err) {
        for (unsigned int j=0; j<known_objects.size(); j++) {
            if (i->compare(type,known_objects[j]->getObjectType())) {
                EGS_Object *o = known_objects[j]->createObject(i);
                if (addObject(o,unique)) {
                    return o;
                }
                EGS_Object::deleteObject(o);
                return 0;
            }
        }
    }
    string libname;
    int error = i->getInput("library",libname);
    if (error) {
        if (err) egsWarning("EGS_ObjectFactory::createObject(): \n"
                                "  input item %s does not define an object type or an object "
                                "library\n",i->name());
        else egsWarning("EGS_ObjectFactory::createObject(): input item %s\n"
                            "  don't know anything about object type %s and no object"
                            "library defined\n",i->name(),type.c_str());
        return 0;
    }
    EGS_Library *lib = 0;
    for (unsigned int j=0; j<libs.size(); j++) {
        if (libname == libs[j]->libraryName()) {
            lib = libs[j];
            break;
        }
    }
    if (!lib) {
        lib = new EGS_Library(libname.c_str(),dso_path.c_str());
        lib->load();
        if (!lib->isLoaded()) {
            egsWarning("EGS_ObjectFactory::createObject(): "
                       "failed to load the library %s from %s\n",
                       libname.c_str(),dso_path.c_str());
            return 0;
        }
        libs.push_back(lib);
    }
    EGS_ObjectCreationFunction create;
    const char *fname = funcname ? funcname : "createObject";
    create = (EGS_ObjectCreationFunction) lib->resolve(fname);
    if (!create) {
        egsWarning("EGS_ObjectFactory::createObject():\n"
                   "  failed to resolve the '%s' function in the library %s\n",
                   fname,lib->libraryName());
        return 0;
    }
    EGS_Object *o = create(i,this);
    if (addObject(o,unique)) {
        return o;
    }
    EGS_Object::deleteObject(o);
    return 0;
}
Exemplo n.º 3
0
EGS_RangeRejection* EGS_RangeRejection::getRangeRejection(EGS_Input *input,
        EGS_Interpolator *i_ededx, EGS_Interpolator *i_pdedx) {
    EGS_Input *rr; bool delete_it;
    if( input->isA("range rejection") ) {
        rr = input; delete_it = false;
    }
    else {
        rr = input->takeInputItem("range rejection");
        if( !rr ) return 0;
        delete_it = true;
    }
    int iaux; int err = rr->getInput("rejection",iaux);
    EGS_RangeRejection *result = 0;
    if( !err && iaux > 0 ) {
        result = new EGS_RangeRejection;
        if( iaux == 1 )
            result->type = RangeDiscard;
        else {
            result->type = RussianRoulette;
            result->probi = iaux;
        }
        EGS_Float aux; err = rr->getInput("Esave",aux);
        if( !err && aux >= 0 ) result->Esave = aux;
        string cavity_geometry;
        err = rr->getInput("cavity geometry",cavity_geometry);
        if( !err ) {
            result->cgeom = EGS_BaseGeometry::getGeometry(cavity_geometry);
            if( !result->cgeom ) egsWarning("\n\n********** no geometry named"
                       " %s exists => using region-by-region rejection only\n");
        }
        if( result->Esave <= the_useful->prm && result->type == RangeDiscard ) {
            egsWarning("\n\n********* rr_flag = 1 but Esave = 0 =>"
                         " not using range rejection\n\n");
            delete result; result = 0;
        }
        if( result && result->type != None && result->cgeom ) {
            string rej_medium; int irej_medium = -1;
            err = rr->getInput("rejection range medium",rej_medium);
            if( !err ) {
                int imed = EGS_BaseGeometry::getMediumIndex(rej_medium);
                if( imed < 0 ) egsWarning("\n\n*********** no medium"
                    " with name %s initialized => using region-by-region rejection only\n",
                    rej_medium.c_str());
                else irej_medium = imed;
            }
            if( irej_medium < 0 ) { result->cgeom = 0; result->type = RangeDiscard; }
            else {
                //
                // *** prepare an interpolator for the electron range
                //     in the range rejection medium
                //
                int i = irej_medium; // save some typing
                EGS_Float log_emin = i_ededx[i].getXmin();
                EGS_Float log_emax = i_ededx[i].getXmax();
                int nbin = 512;
                EGS_Float dloge = (log_emax - log_emin)/nbin;
                EGS_Float *erange = new EGS_Float [nbin];
                EGS_Float *prange = new EGS_Float [nbin];
                erange[0] = 0; prange[0] = 0;
                EGS_Float ededx_old = i_ededx[i].interpolate(log_emin);
                EGS_Float pdedx_old = i_pdedx[i].interpolate(log_emin);
                EGS_Float Eold = exp(log_emin);
                EGS_Float efak = exp(dloge);
                for(int j=1; j<nbin; j++) {
                    EGS_Float elke = log_emin + dloge*j;
                    EGS_Float E = Eold*efak;
                    EGS_Float ededx = i_ededx[i].interpolate(elke);
                    EGS_Float pdedx = i_pdedx[i].interpolate(elke);
                    if( ededx < ededx_old )
                    erange[j] = erange[j-1]+1.02*(E-Eold)/ededx;
                    else
                    erange[j] = erange[j-1]+1.02*(E-Eold)/ededx_old;
                    if( pdedx < pdedx_old )
                    prange[j] = prange[j-1]+1.02*(E-Eold)/pdedx;
                    else
                    prange[j] = prange[j-1]+1.02*(E-Eold)/pdedx_old;
                    Eold = E; ededx_old = ededx; pdedx_old = pdedx;
                }
                result->erange.initialize(nbin,log_emin,log_emax,erange);
                result->prange.initialize(nbin,log_emin,log_emax,prange);
            }
        }
    }
    if( delete_it ) delete rr;
    return result;
}
Exemplo n.º 4
0
EGS_BeamSource::EGS_BeamSource(EGS_Input *input, EGS_ObjectFactory *f) :
    EGS_BaseSource(input,f) {
    n_reuse_photon = 0; n_reuse_electron = 0;
    i_reuse_photon = 0; i_reuse_electron = 0;
    is_valid = false; lib = 0;
    Xmin = -1e30; Xmax = 1e30; Ymin = -1e30; Ymax = 1e30;
    wmin = -1e30; wmax = 1e30;
    string beam_code; int err1 = input->getInput("beam code",beam_code);
    string pegs_file; int err2 = input->getInput("pegs file",pegs_file);
    string input_file; int err3 = input->getInput("input file",input_file);
    if( err1 ) egsWarning("EGS_BeamSource: no 'beam code' input\n");
    if( err2 ) egsWarning("EGS_BeamSource: no 'pegs file' input\n");
    if( err3 ) egsWarning("EGS_BeamSource: no 'input file' input\n");
    if( err1 || err2 || err3 ) return;
    char *egs_home = getenv("EGS_HOME");
    if( !egs_home ) {
        egsWarning("EGS_BeamSource: EGS_HOME is not defined\n"); return;
    }
    char *hen_house = getenv("HEN_HOUSE");
    if( !hen_house ) {
        egsWarning("EGS_BeamSource: HEN_HOUSE is not defined\n"); return;
    }
    string path = egs_home; path += "bin/"; path += CONFIG_NAME;
    lib = new EGS_Library(beam_code.c_str(),path.c_str());

    InitFunction init = (InitFunction)
        lib->resolve(F77_NAME_(beamlib_init,BEAMLIB_INIT));
    finish = (FinishFunction)
        lib->resolve(F77_NAME_(beamlib_finish,BEAMLIB_FINISH));
    sample = (SampleFunction)
        lib->resolve(F77_NAME_(beamlib_sample,BEAMLIB_SAMPLE));
    MaxEnergyFunction maxenergy = (MaxEnergyFunction)
        lib->resolve(F77_NAME_(beamlib_max_energy,BEAMLIB_MAX_ENERGY));
    if( !init )
        egsWarning("EGS_BeamSource: failed to resolve the init function\n");
    if( !sample )
        egsWarning("EGS_BeamSource: failed to resolve the sample function\n");
    if( !finish )
        egsWarning("EGS_BeamSource: failed to resolve the finish function\n");
    if( !maxenergy )
    egsWarning("EGS_BeamSource: failed to resolve the max. energy function\n");
    if( !init || !sample || !finish || !maxenergy ) return;

    int ipar=0, ilog=6;
    EGS_Application *app = EGS_Application::activeApplication();
    if( app ) ipar = app->getIparallel();

    init(&ipar,&ilog,hen_house,egs_home,beam_code.c_str(),
            pegs_file.c_str(),input_file.c_str(),
            strlen(hen_house), strlen(egs_home),
            beam_code.size(),pegs_file.size(),input_file.size());
    maxenergy(&Emax);

    is_valid = true;

    vector<EGS_Float> cutout;
    int err = input->getInput("cutout",cutout);
    if( !err && cutout.size() == 4 )
        setCutout(cutout[0],cutout[1],cutout[2],cutout[3]);
    vector<string> ptype;
    ptype.push_back("electrons"); ptype.push_back("photons");
    ptype.push_back("positrons"); ptype.push_back("all");
    ptype.push_back("charged");
    particle_type = input->getInput("particle type",ptype,3)-1;

    vector<EGS_Float> wwindow;
    err = input->getInput("weight window",wwindow);
    if( !err && wwindow.size() == 2 ) {
        wmin = wwindow[0]; wmax = wwindow[1];
    }

    int ntmp;
    err = input->getInput("reuse photons",ntmp);
    if( !err && ntmp > 1 ) n_reuse_photon = ntmp;
    err = input->getInput("reuse electrons",ntmp);
    if( !err && ntmp > 1 ) n_reuse_electron = ntmp;

    description = beam_code; description += "(";
    description += input_file; description += ") simulation source";
}