// RAT::Gen_FluxMessenger // Provide user commands to allow the user to change // the parameters of the Gen_Flux generator via the command line. #include #include #include #include #include #include #include #include #include #define G4std std namespace RAT { Gen_FluxMessenger::Gen_FluxMessenger(Gen_Flux* lg):fGenFlux(lg){ // Commands will in a /generator/flux/ directory G4UIdirectory* dir = new G4UIdirectory("/generator/flux/"); dir->SetGuidance("Control the parameters of the Flux generator"); fTimeSetCmd= new G4UIcmdWithAString("/generator/flux/settimegen",this); fTimeSetCmd->SetGuidance("Set time generator for the used flux spectrum"); fTimeSetCmd->SetParameter(new G4UIparameter("setting", 's', true)); fSpectrumCmd = new G4UIcmdWithAString("/generator/flux/setspectrum",this); fSpectrumCmd->SetGuidance("Set flux spectrum"); fSpectrumCmd->SetParameter(new G4UIparameter("setting", 's', true)); fRadiusCmd = new G4UIcmdWithADouble("/generator/flux/setradius",this); fRadiusCmd->SetGuidance("Set radius of sphere"); fRadiusCmd->SetParameter(new G4UIparameter("setting", 'd', true)); fPositionCmd = new G4UIcmdWithAString("/generator/flux/setposition",this); fPositionCmd->SetGuidance("Set generation position"); fPositionCmd->SetParameter(new G4UIparameter("setting", 's', true)); fDirectionCmd = new G4UIcmdWithAString("/generator/flux/setdirection",this); fDirectionCmd->SetGuidance("Set generation direction"); fDirectionCmd->SetParameter(new G4UIparameter("setting", 's', true)); } Gen_FluxMessenger::~Gen_FluxMessenger(){ delete fTimeSetCmd; delete fSpectrumCmd; delete fRadiusCmd; } double stringToDouble(const std::string& str_){ G4std::istringstream is(str_.c_str()); double rtnDouble; is >> rtnDouble; return rtnDouble; } void Gen_FluxMessenger::SetNewValue(G4UIcommand* command, G4String newValues) { if ( command == fTimeSetCmd ){ G4String state = util_strip_default(newValues); fGenFlux->SetTimeGen(state); } else if( command == fSpectrumCmd ){ G4String state = util_strip_default(newValues); fGenFlux->SetSpectrum(state); } else if( command == fRadiusCmd ){ G4String state = util_strip_default(newValues); G4std::istringstream is(state.c_str()); double radius; is >> radius; fGenFlux->SetRadius(radius); } else if( command == fDirectionCmd ){ G4String state = util_strip_default(newValues); std::vector coordinates = util_split(state," "); if (coordinates.size() != 2) throw Gen_Flux::FluxException("FLUX Generator : Direction arguments must specify THETA and PHI with respect to the centre of the PSUP i.e. two arguments. See user manual. "); double theta = stringToDouble(coordinates.at(0)); if(theta< 0.0 || cos(theta) < 0.2 ) throw Gen_Flux::FluxException("FLUX Generator : Direction coordinate THETA is out of the interval [0.0, 1.36] ( range specified by input cosmic distribution "); double phi = stringToDouble(coordinates.at(1)); if(phi< 0.0 || phi > CLHEP::twopi) throw Gen_Flux::FluxException("FLUX Generator : Direction coordinate PHI is out of the interval [0.0,2pi]"); fGenFlux->SetGeneratorDirection(theta,phi); } else if( command == fPositionCmd ){ // When parsing the position cmd, expect both Cartesian and // spherical coordinates. G4String state = util_strip_default(newValues); std::vector coordinates = util_split(state," "); switch(coordinates.size()){ case 3:{ double x0 = stringToDouble(coordinates.at(0)); if(x0< 0.0 || x0>20000.0) throw Gen_Flux::FluxException("FLUX Generator : Coordinate X is out of the interval [0.0,20000.0]"); double y0 = stringToDouble(coordinates.at(1)); if(y0< 0.0 || y0>20000.0) throw Gen_Flux::FluxException("FLUX Generator : Coordinate Y is out of the interval [0.0,20000.0]"); double z0 = stringToDouble(coordinates.at(2)); if(z0< 0.0 || z0>20000.0) throw Gen_Flux::FluxException("FLUX Generator : Coordinate Z is out of the interval [0.0,20000.0]"); fGenFlux->SetGeneratorPosition(x0,y0,z0); break; } case 2:{ double theta = stringToDouble(coordinates.at(0)); if(theta< 0.0 || theta > CLHEP::pi) throw Gen_Flux::FluxException("FLUX Generator : Coordinate THETA is out of the interval [0.0,pi]"); double phi = stringToDouble(coordinates.at(1)); if(phi< 0.0 || phi > CLHEP::twopi) throw Gen_Flux::FluxException("FLUX Generator : Coordinate PHI is out of the interval [0.0,2pi]"); fGenFlux->SetGeneratorPosition(theta,phi); break; } default:{ throw Gen_Flux::FluxException("FLUX Generator : Position arguments supplied are not expected. See user manual."); } } }else{ // Error if we reach here. warn << "Gen_FluxMessenger::SetNewValue: Error: Gen_FluxMessenger invalid command" << newline; } } G4String Gen_FluxMessenger::GetCurrentValue(G4UIcommand * command) { // The command parameter is totally unused. Mark it as such. __unused_parameter(command); return G4String("invalid Gen_Flux Messenger \"get\" command"); } }