Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // Gorad (Geant4 Open-source Radiation Analys 26 // Gorad (Geant4 Open-source Radiation Analysis and Design) 27 // 27 // 28 // Author : Makoto Asai (SLAC National Accele 28 // Author : Makoto Asai (SLAC National Accelerator Laboratory) 29 // 29 // 30 // Development of Gorad is funded by NASA Joh 30 // Development of Gorad is funded by NASA Johnson Space Center (JSC) 31 // under the contract NNJ15HK11B. 31 // under the contract NNJ15HK11B. 32 // 32 // 33 // ******************************************* 33 // ******************************************************************** 34 // 34 // 35 // GRPrimGenActionMessenger.hh 35 // GRPrimGenActionMessenger.hh 36 // Header file of a messenger that handles p 36 // Header file of a messenger that handles primary generator action. 37 // Input radiation spectrum file should be i 37 // Input radiation spectrum file should be in ASCII format and each 38 // row should have low-end kinetic energy an 38 // row should have low-end kinetic energy and differential flux 39 // separated by a space. 39 // separated by a space. 40 // 40 // 41 // History 41 // History 42 // September 8th, 2020 : first implementatio 42 // September 8th, 2020 : first implementation 43 // 43 // 44 // ******************************************* 44 // ******************************************************************** 45 45 46 #include "GRPrimGenActionMessenger.hh" 46 #include "GRPrimGenActionMessenger.hh" 47 47 48 #include "G4UIdirectory.hh" 48 #include "G4UIdirectory.hh" 49 #include "G4UIcommand.hh" 49 #include "G4UIcommand.hh" 50 #include "G4UIparameter.hh" 50 #include "G4UIparameter.hh" 51 51 52 GRPrimGenActionMessenger::GRPrimGenActionMesse 52 GRPrimGenActionMessenger::GRPrimGenActionMessenger(G4int verboseLvl) 53 : verboseLevel(verboseLvl) 53 : verboseLevel(verboseLvl) 54 { 54 { 55 G4UIparameter* param = nullptr; 55 G4UIparameter* param = nullptr; 56 56 57 srcDir = new G4UIdirectory("/gorad/source/") 57 srcDir = new G4UIdirectory("/gorad/source/"); 58 srcDir->SetGuidance("Define primary particle 58 srcDir->SetGuidance("Define primary particle spectrum."); 59 59 60 defCmd = new G4UIcommand("/gorad/source/defi 60 defCmd = new G4UIcommand("/gorad/source/define",this); 61 defCmd->SetGuidance("Define primary particle 61 defCmd->SetGuidance("Define primary particle spectrum."); 62 defCmd->SetGuidance("[usage] /gorad/source/d 62 defCmd->SetGuidance("[usage] /gorad/source/define pName fName srcType radius unit (x0 y0 z0)"); 63 defCmd->SetGuidance(" pName : Particle name 63 defCmd->SetGuidance(" pName : Particle name."); 64 defCmd->SetGuidance(" fName : File name of 64 defCmd->SetGuidance(" fName : File name of the spectrum. Directory may be preceded to the file name."); 65 defCmd->SetGuidance(" srcType : defines how 65 defCmd->SetGuidance(" srcType : defines how the primaries are generated."); 66 defCmd->SetGuidance(" Arb : Gener 66 defCmd->SetGuidance(" Arb : Generate primaries along with the defined spectrum."); 67 defCmd->SetGuidance(" LW : Gener 67 defCmd->SetGuidance(" LW : Generate primaries in flat ditribution with track weight representing the spectrum."); 68 defCmd->SetGuidance(" radius : Radius of th 68 defCmd->SetGuidance(" radius : Radius of the source sphere. If it is set to -1 (default), radius is set to 98% of the world volume."); 69 defCmd->SetGuidance(" unit : Unit of radius 69 defCmd->SetGuidance(" unit : Unit of radius value."); 70 defCmd->SetGuidance(" x0,y0,z0 : (Optional) 70 defCmd->SetGuidance(" x0,y0,z0 : (Optional) location of the center of the sphere (same unit is applied as radius)."); 71 defCmd->SetGuidance(" By default 71 defCmd->SetGuidance(" By default the sphere is located at the center of the world volume."); 72 defCmd->SetGuidance("[note] This command is 72 defCmd->SetGuidance("[note] This command is not mandatory but dwialternatively granular /gps/ commands can be used for defining primary particles."); 73 particlePara = new G4UIparameter("pName",'s' 73 particlePara = new G4UIparameter("pName",'s',false); 74 defCmd->SetParameter(particlePara); 74 defCmd->SetParameter(particlePara); 75 param = new G4UIparameter("fName",'s',false) 75 param = new G4UIparameter("fName",'s',false); 76 defCmd->SetParameter(param); 76 defCmd->SetParameter(param); 77 param = new G4UIparameter("srcType",'s',fals 77 param = new G4UIparameter("srcType",'s',false); 78 param->SetParameterCandidates("Arb LW"); 78 param->SetParameterCandidates("Arb LW"); 79 defCmd->SetParameter(param); 79 defCmd->SetParameter(param); 80 param = new G4UIparameter("radius",'d',true) 80 param = new G4UIparameter("radius",'d',true); 81 param->SetParameterRange("radius == -1. || r 81 param->SetParameterRange("radius == -1. || radius>0."); 82 param->SetDefaultValue(-1.); 82 param->SetDefaultValue(-1.); 83 defCmd->SetParameter(param); 83 defCmd->SetParameter(param); 84 param = new G4UIparameter("unit",'s',true); 84 param = new G4UIparameter("unit",'s',true); 85 param->SetDefaultUnit("m"); 85 param->SetDefaultUnit("m"); 86 defCmd->SetParameter(param); 86 defCmd->SetParameter(param); 87 param = new G4UIparameter("x0",'d',true); 87 param = new G4UIparameter("x0",'d',true); 88 param->SetDefaultValue(0.); 88 param->SetDefaultValue(0.); 89 defCmd->SetParameter(param); 89 defCmd->SetParameter(param); 90 param = new G4UIparameter("y0",'d',true); 90 param = new G4UIparameter("y0",'d',true); 91 param->SetDefaultValue(0.); 91 param->SetDefaultValue(0.); 92 defCmd->SetParameter(param); 92 defCmd->SetParameter(param); 93 param = new G4UIparameter("z0",'d',true); 93 param = new G4UIparameter("z0",'d',true); 94 param->SetDefaultValue(0.); 94 param->SetDefaultValue(0.); 95 defCmd->SetParameter(param); 95 defCmd->SetParameter(param); 96 defCmd->AvailableForStates(G4State_Idle); 96 defCmd->AvailableForStates(G4State_Idle); 97 defCmd->SetToBeBroadcasted(false); 97 defCmd->SetToBeBroadcasted(false); 98 } 98 } 99 99 100 GRPrimGenActionMessenger::~GRPrimGenActionMess 100 GRPrimGenActionMessenger::~GRPrimGenActionMessenger() 101 { 101 { 102 delete defCmd; 102 delete defCmd; 103 delete srcDir; 103 delete srcDir; 104 } 104 } 105 105 106 #include "G4UImanager.hh" 106 #include "G4UImanager.hh" 107 #include "G4Threading.hh" 107 #include "G4Threading.hh" 108 #include "G4Tokenizer.hh" 108 #include "G4Tokenizer.hh" 109 #include "G4UnitsTable.hh" 109 #include "G4UnitsTable.hh" 110 #include <fstream> 110 #include <fstream> 111 #include "GRDetectorConstruction.hh" 111 #include "GRDetectorConstruction.hh" 112 112 113 void GRPrimGenActionMessenger::SetNewValue(G4U 113 void GRPrimGenActionMessenger::SetNewValue(G4UIcommand * command,G4String newVal) 114 { 114 { 115 auto UI = G4UImanager::GetUIpointer(); 115 auto UI = G4UImanager::GetUIpointer(); 116 if(verboseLevel>0) G4cout << newVal << G4end 116 if(verboseLevel>0) G4cout << newVal << G4endl; 117 117 118 G4Tokenizer next(newVal); 118 G4Tokenizer next(newVal); 119 G4String pName = next(); 119 G4String pName = next(); 120 G4String fName = next(); 120 G4String fName = next(); 121 std::ifstream specFile; 121 std::ifstream specFile; 122 specFile.open(fName,std::ios::in); 122 specFile.open(fName,std::ios::in); 123 if(specFile.fail()) 123 if(specFile.fail()) 124 { 124 { 125 G4ExceptionDescription ed; 125 G4ExceptionDescription ed; 126 ed << "ERROR : File <" << fName << "> is n 126 ed << "ERROR : File <" << fName << "> is not found."; 127 command->CommandFailed(ed); 127 command->CommandFailed(ed); 128 return; 128 return; 129 } 129 } 130 130 131 G4String srcType = next(); 131 G4String srcType = next(); 132 G4String radius = next(); 132 G4String radius = next(); 133 G4String unit = next(); 133 G4String unit = next(); 134 G4double r = StoD(radius); 134 G4double r = StoD(radius); 135 if(r<0.) 135 if(r<0.) 136 { 136 { 137 r = GRDetectorConstruction::GetWorldSize() 137 r = GRDetectorConstruction::GetWorldSize() * 0.98; 138 radius = DtoS(r); 138 radius = DtoS(r); 139 unit = "mm"; 139 unit = "mm"; 140 G4cout<<"################ Radius of the GP 140 G4cout<<"################ Radius of the GPS sphere is set to "<<r<<" (mm)"<<G4endl; 141 } 141 } 142 G4String pos = next() + " " + next() + " " + 142 G4String pos = next() + " " + next() + " " + next(); 143 143 144 G4String cmd; 144 G4String cmd; 145 G4int ec = 0; 145 G4int ec = 0; 146 ec = std::max(UI->ApplyCommand("/gps/pos/sha 146 ec = std::max(UI->ApplyCommand("/gps/pos/shape Sphere"),ec); 147 cmd = "/gps/pos/centre " + pos + " " + unit; 147 cmd = "/gps/pos/centre " + pos + " " + unit; 148 ec = std::max(UI->ApplyCommand(cmd),ec); 148 ec = std::max(UI->ApplyCommand(cmd),ec); 149 cmd = "/gps/pos/radius " + radius + " " + un 149 cmd = "/gps/pos/radius " + radius + " " + unit; 150 ec = std::max(UI->ApplyCommand(cmd),ec); 150 ec = std::max(UI->ApplyCommand(cmd),ec); 151 ec = std::max(UI->ApplyCommand("/gps/pos/typ 151 ec = std::max(UI->ApplyCommand("/gps/pos/type Surface"),ec); 152 ec = std::max(UI->ApplyCommand("/gps/number 152 ec = std::max(UI->ApplyCommand("/gps/number 1"),ec); 153 cmd = "/gps/particle " + pName; 153 cmd = "/gps/particle " + pName; 154 ec = std::max(UI->ApplyCommand(cmd),ec); 154 ec = std::max(UI->ApplyCommand(cmd),ec); 155 ec = std::max(UI->ApplyCommand("/gps/ang/typ 155 ec = std::max(UI->ApplyCommand("/gps/ang/type cos"),ec); 156 ec = std::max(UI->ApplyCommand("/gps/ang/max 156 ec = std::max(UI->ApplyCommand("/gps/ang/maxtheta 90.0 deg"),ec); 157 ec = std::max(UI->ApplyCommand("/gps/ang/min 157 ec = std::max(UI->ApplyCommand("/gps/ang/mintheta 0.0 deg"),ec); 158 cmd = "/gps/ene/type " + srcType; 158 cmd = "/gps/ene/type " + srcType; 159 ec = std::max(UI->ApplyCommand(cmd),ec); 159 ec = std::max(UI->ApplyCommand(cmd),ec); 160 ec = std::max(UI->ApplyCommand("/gps/hist/ty 160 ec = std::max(UI->ApplyCommand("/gps/hist/type arb"),ec); 161 161 162 enum { bufsize = 128 }; 162 enum { bufsize = 128 }; 163 static char* line = new char[bufsize]; 163 static char* line = new char[bufsize]; 164 while(specFile.good()) 164 while(specFile.good()) 165 { 165 { 166 specFile.getline(line,bufsize); 166 specFile.getline(line,bufsize); 167 if(line[(size_t)0]=='#') continue; 167 if(line[(size_t)0]=='#') continue; 168 G4String valStr = line; << 168 G4String valStr(line); 169 G4StrUtil::strip(valStr); << 169 valStr = valStr.strip(G4String::both); 170 G4StrUtil::rstrip(valStr, 0x0d); << 170 valStr = valStr.strip(G4String::trailing,0x0d); 171 if(valStr.size()==0) continue; 171 if(valStr.size()==0) continue; 172 cmd = "/gps/hist/point " + valStr; 172 cmd = "/gps/hist/point " + valStr; 173 ec = std::max(UI->ApplyCommand(cmd),ec); 173 ec = std::max(UI->ApplyCommand(cmd),ec); 174 if(specFile.eof()) break; 174 if(specFile.eof()) break; 175 } 175 } 176 ec = std::max(UI->ApplyCommand("/gps/hist/in 176 ec = std::max(UI->ApplyCommand("/gps/hist/inter Lin"),ec); 177 177 178 if(ec>0) 178 if(ec>0) 179 { 179 { 180 G4ExceptionDescription ed; 180 G4ExceptionDescription ed; 181 ed << "ERROR : Internal error while proces 181 ed << "ERROR : Internal error while processing /gorad/source/define command."; 182 command->CommandFailed(ec,ed); 182 command->CommandFailed(ec,ed); 183 } 183 } 184 } 184 } 185 185 186 G4String GRPrimGenActionMessenger::GetCurrentV 186 G4String GRPrimGenActionMessenger::GetCurrentValue(G4UIcommand* /*command*/) 187 { 187 { 188 G4String val; 188 G4String val; 189 return val; 189 return val; 190 } 190 } 191 191 192 #include "G4ParticleTable.hh" 192 #include "G4ParticleTable.hh" 193 void GRPrimGenActionMessenger::UpdateParticleL 193 void GRPrimGenActionMessenger::UpdateParticleList() 194 { 194 { 195 auto particleTable = G4ParticleTable::GetPar 195 auto particleTable = G4ParticleTable::GetParticleTable(); 196 G4String candList; 196 G4String candList; 197 for(G4int i=0;i<particleTable->entries();i++ 197 for(G4int i=0;i<particleTable->entries();i++) 198 { candList += particleTable->GetParticleName 198 { candList += particleTable->GetParticleName(i) + " "; } 199 candList += "ion"; 199 candList += "ion"; 200 particlePara->SetParameterCandidates(candLis 200 particlePara->SetParameterCandidates(candList); 201 } 201 } 202 202 203 203