File indexing completed on 2025-02-25 09:22:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 #include "GRPrimGenActionMessenger.hh"
0047
0048 #include "G4UIdirectory.hh"
0049 #include "G4UIcommand.hh"
0050 #include "G4UIparameter.hh"
0051
0052 GRPrimGenActionMessenger::GRPrimGenActionMessenger(G4int verboseLvl)
0053 : verboseLevel(verboseLvl)
0054 {
0055 G4UIparameter* param = nullptr;
0056
0057 srcDir = new G4UIdirectory("/gorad/source/");
0058 srcDir->SetGuidance("Define primary particle spectrum.");
0059
0060 defCmd = new G4UIcommand("/gorad/source/define",this);
0061 defCmd->SetGuidance("Define primary particle spectrum.");
0062 defCmd->SetGuidance("[usage] /gorad/source/define pName fName srcType radius unit (x0 y0 z0)");
0063 defCmd->SetGuidance(" pName : Particle name.");
0064 defCmd->SetGuidance(" fName : File name of the spectrum. Directory may be preceded to the file name.");
0065 defCmd->SetGuidance(" srcType : defines how the primaries are generated.");
0066 defCmd->SetGuidance(" Arb : Generate primaries along with the defined spectrum.");
0067 defCmd->SetGuidance(" LW : Generate primaries in flat ditribution with track weight representing the spectrum.");
0068 defCmd->SetGuidance(" radius : Radius of the source sphere. If it is set to -1 (default), radius is set to 98% of the world volume.");
0069 defCmd->SetGuidance(" unit : Unit of radius value.");
0070 defCmd->SetGuidance(" x0,y0,z0 : (Optional) location of the center of the sphere (same unit is applied as radius).");
0071 defCmd->SetGuidance(" By default the sphere is located at the center of the world volume.");
0072 defCmd->SetGuidance("[note] This command is not mandatory but dwialternatively granular /gps/ commands can be used for defining primary particles.");
0073 particlePara = new G4UIparameter("pName",'s',false);
0074 defCmd->SetParameter(particlePara);
0075 param = new G4UIparameter("fName",'s',false);
0076 defCmd->SetParameter(param);
0077 param = new G4UIparameter("srcType",'s',false);
0078 param->SetParameterCandidates("Arb LW");
0079 defCmd->SetParameter(param);
0080 param = new G4UIparameter("radius",'d',true);
0081 param->SetParameterRange("radius == -1. || radius>0.");
0082 param->SetDefaultValue(-1.);
0083 defCmd->SetParameter(param);
0084 param = new G4UIparameter("unit",'s',true);
0085 param->SetDefaultUnit("m");
0086 defCmd->SetParameter(param);
0087 param = new G4UIparameter("x0",'d',true);
0088 param->SetDefaultValue(0.);
0089 defCmd->SetParameter(param);
0090 param = new G4UIparameter("y0",'d',true);
0091 param->SetDefaultValue(0.);
0092 defCmd->SetParameter(param);
0093 param = new G4UIparameter("z0",'d',true);
0094 param->SetDefaultValue(0.);
0095 defCmd->SetParameter(param);
0096 defCmd->AvailableForStates(G4State_Idle);
0097 defCmd->SetToBeBroadcasted(false);
0098 }
0099
0100 GRPrimGenActionMessenger::~GRPrimGenActionMessenger()
0101 {
0102 delete defCmd;
0103 delete srcDir;
0104 }
0105
0106 #include "G4UImanager.hh"
0107 #include "G4Threading.hh"
0108 #include "G4Tokenizer.hh"
0109 #include "G4UnitsTable.hh"
0110 #include <fstream>
0111 #include "GRDetectorConstruction.hh"
0112
0113 void GRPrimGenActionMessenger::SetNewValue(G4UIcommand * command,G4String newVal)
0114 {
0115 auto UI = G4UImanager::GetUIpointer();
0116 if(verboseLevel>0) G4cout << newVal << G4endl;
0117
0118 G4Tokenizer next(newVal);
0119 G4String pName = next();
0120 G4String fName = next();
0121 std::ifstream specFile;
0122 specFile.open(fName,std::ios::in);
0123 if(specFile.fail())
0124 {
0125 G4ExceptionDescription ed;
0126 ed << "ERROR : File <" << fName << "> is not found.";
0127 command->CommandFailed(ed);
0128 return;
0129 }
0130
0131 G4String srcType = next();
0132 G4String radius = next();
0133 G4String unit = next();
0134 G4double r = StoD(radius);
0135 if(r<0.)
0136 {
0137 r = GRDetectorConstruction::GetWorldSize() * 0.98;
0138 radius = DtoS(r);
0139 unit = "mm";
0140 G4cout<<"################ Radius of the GPS sphere is set to "<<r<<" (mm)"<<G4endl;
0141 }
0142 G4String pos = next() + " " + next() + " " + next();
0143
0144 G4String cmd;
0145 G4int ec = 0;
0146 ec = std::max(UI->ApplyCommand("/gps/pos/shape Sphere"),ec);
0147 cmd = "/gps/pos/centre " + pos + " " + unit;
0148 ec = std::max(UI->ApplyCommand(cmd),ec);
0149 cmd = "/gps/pos/radius " + radius + " " + unit;
0150 ec = std::max(UI->ApplyCommand(cmd),ec);
0151 ec = std::max(UI->ApplyCommand("/gps/pos/type Surface"),ec);
0152 ec = std::max(UI->ApplyCommand("/gps/number 1"),ec);
0153 cmd = "/gps/particle " + pName;
0154 ec = std::max(UI->ApplyCommand(cmd),ec);
0155 ec = std::max(UI->ApplyCommand("/gps/ang/type cos"),ec);
0156 ec = std::max(UI->ApplyCommand("/gps/ang/maxtheta 90.0 deg"),ec);
0157 ec = std::max(UI->ApplyCommand("/gps/ang/mintheta 0.0 deg"),ec);
0158 cmd = "/gps/ene/type " + srcType;
0159 ec = std::max(UI->ApplyCommand(cmd),ec);
0160 ec = std::max(UI->ApplyCommand("/gps/hist/type arb"),ec);
0161
0162 enum { bufsize = 128 };
0163 static char* line = new char[bufsize];
0164 while(specFile.good())
0165 {
0166 specFile.getline(line,bufsize);
0167 if(line[(size_t)0]=='#') continue;
0168 G4String valStr = line;
0169 G4StrUtil::strip(valStr);
0170 G4StrUtil::rstrip(valStr, 0x0d);
0171 if(valStr.size()==0) continue;
0172 cmd = "/gps/hist/point " + valStr;
0173 ec = std::max(UI->ApplyCommand(cmd),ec);
0174 if(specFile.eof()) break;
0175 }
0176 ec = std::max(UI->ApplyCommand("/gps/hist/inter Lin"),ec);
0177
0178 if(ec>0)
0179 {
0180 G4ExceptionDescription ed;
0181 ed << "ERROR : Internal error while processing /gorad/source/define command.";
0182 command->CommandFailed(ec,ed);
0183 }
0184 }
0185
0186 G4String GRPrimGenActionMessenger::GetCurrentValue(G4UIcommand* )
0187 {
0188 G4String val;
0189 return val;
0190 }
0191
0192 #include "G4ParticleTable.hh"
0193 void GRPrimGenActionMessenger::UpdateParticleList()
0194 {
0195 auto particleTable = G4ParticleTable::GetParticleTable();
0196 G4String candList;
0197 for(G4int i=0;i<particleTable->entries();i++)
0198 { candList += particleTable->GetParticleName(i) + " "; }
0199 candList += "ion";
0200 particlePara->SetParameterCandidates(candList);
0201 }
0202