Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // G4AdjointSimMessenger implementation 27 // 28 // ------------------------------------------- 29 // Class Name: G4AdjointSimMessenger 30 // Author: L. Desorgher, 2007-2009 31 // Organisation: SpaceIT GmbH 32 // Contract: ESA contract 21435/08/NL/AT 33 // Customer: ESA/ESTEC 34 // ------------------------------------------- 35 36 #include "G4AdjointSimMessenger.hh" 37 38 #include "G4AdjointSimManager.hh" 39 #include "G4RunManager.hh" 40 #include "G4UIcmdWith3VectorAndUnit.hh" 41 #include "G4UIcmdWithABool.hh" 42 #include "G4UIcmdWithADouble.hh" 43 #include "G4UIcmdWithADoubleAndUnit.hh" 44 #include "G4UIcmdWithAString.hh" 45 #include "G4UIcmdWithAnInteger.hh" 46 #include "G4UIcmdWithoutParameter.hh" 47 #include "G4UIdirectory.hh" 48 #include "G4UnitsTable.hh" 49 50 #include <sstream> 51 52 // ------------------------------------------- 53 // 54 G4AdjointSimMessenger::G4AdjointSimMessenger(G 55 : theAdjointRunManager(pAdjointRunManager) 56 { 57 AdjointSimDir = new G4UIdirectory("/adjoint/ 58 AdjointSimDir->SetGuidance("Control of the a 59 60 // Start and adjoint Run 61 //--------------------- 62 63 64 beamOnCmd = new G4UIcommand("/adjoint/start_ 65 beamOnCmd->SetGuidance("Start an adjoint Run 66 beamOnCmd->SetGuidance("Default number of ev 67 beamOnCmd->AvailableForStates(G4State_PreIni 68 auto p1 = new G4UIparameter("numberOfEvent", 69 p1->SetDefaultValue(1); 70 p1->SetParameterRange("numberOfEvent >= 0"); 71 beamOnCmd->SetParameter(p1); 72 73 // Commands to define parameters relative to 74 //------------------------------------------ 75 76 auto pos_x_par = new G4UIparameter("X", 'd', 77 78 auto pos_y_par = new G4UIparameter("Y", 'd', 79 80 auto pos_z_par = new G4UIparameter("Z", 'd', 81 82 auto radius_par = new G4UIparameter("R", 'd' 83 84 radius_par->SetParameterRange("R >= 0"); 85 86 auto unit_par = new G4UIparameter("unit", 's 87 88 DefineSpherExtSourceCmd = new G4UIcommand("/ 89 DefineSpherExtSourceCmd->SetGuidance("Define 90 DefineSpherExtSourceCmd->SetParameter(pos_x_ 91 DefineSpherExtSourceCmd->SetParameter(pos_y_ 92 DefineSpherExtSourceCmd->SetParameter(pos_z_ 93 DefineSpherExtSourceCmd->SetParameter(radius 94 DefineSpherExtSourceCmd->SetParameter(unit_p 95 96 auto phys_vol_name_par = new G4UIparameter(" 97 98 DefineSpherExtSourceCenteredOnAVolumeCmd = 99 new G4UIcommand("/adjoint/DefineSphericalE 100 DefineSpherExtSourceCenteredOnAVolumeCmd->Se 101 "Define a spherical external source with t 102 "of a " 103 "physical volume"); 104 DefineSpherExtSourceCenteredOnAVolumeCmd->Se 105 DefineSpherExtSourceCenteredOnAVolumeCmd->Se 106 DefineSpherExtSourceCenteredOnAVolumeCmd->Se 107 108 DefineExtSourceOnAVolumeExtSurfaceCmd = 109 new G4UIcmdWithAString("/adjoint/DefineExt 110 DefineExtSourceOnAVolumeExtSurfaceCmd->SetGu 111 "Set the external source on the external s 112 DefineExtSourceOnAVolumeExtSurfaceCmd->SetPa 113 114 setExtSourceEMaxCmd = new G4UIcmdWithADouble 115 setExtSourceEMaxCmd->SetGuidance("Set the ma 116 setExtSourceEMaxCmd->SetParameterName("Emax" 117 setExtSourceEMaxCmd->SetUnitCategory("Energy 118 setExtSourceEMaxCmd->AvailableForStates(G4St 119 120 // Commands to define the adjoint source 121 //------------------------------------------ 122 123 DefineSpherAdjSourceCmd = new G4UIcommand("/ 124 DefineSpherAdjSourceCmd->SetGuidance("Define 125 DefineSpherAdjSourceCmd->SetParameter(pos_x_ 126 DefineSpherAdjSourceCmd->SetParameter(pos_y_ 127 DefineSpherAdjSourceCmd->SetParameter(pos_z_ 128 DefineSpherAdjSourceCmd->SetParameter(radius 129 DefineSpherAdjSourceCmd->SetParameter(unit_p 130 131 DefineSpherAdjSourceCenteredOnAVolumeCmd = 132 new G4UIcommand("/adjoint/DefineSphericalA 133 DefineSpherAdjSourceCenteredOnAVolumeCmd->Se 134 "Define a spherical adjoint source with th 135 "of a " 136 "physical volume"); 137 DefineSpherAdjSourceCenteredOnAVolumeCmd->Se 138 DefineSpherAdjSourceCenteredOnAVolumeCmd->Se 139 DefineSpherAdjSourceCenteredOnAVolumeCmd->Se 140 141 DefineAdjSourceOnAVolumeExtSurfaceCmd = 142 new G4UIcmdWithAString("/adjoint/DefineAdj 143 DefineAdjSourceOnAVolumeExtSurfaceCmd->SetGu 144 "Set the adjoint source on the external su 145 DefineAdjSourceOnAVolumeExtSurfaceCmd->SetPa 146 147 setAdjSourceEminCmd = new G4UIcmdWithADouble 148 setAdjSourceEminCmd->SetGuidance("Set the mi 149 setAdjSourceEminCmd->SetParameterName("Emin" 150 setAdjSourceEminCmd->SetUnitCategory("Energy 151 setAdjSourceEminCmd->AvailableForStates(G4St 152 153 setAdjSourceEmaxCmd = new G4UIcmdWithADouble 154 setAdjSourceEmaxCmd->SetGuidance("Set the ma 155 setAdjSourceEmaxCmd->SetParameterName("Emax" 156 setAdjSourceEmaxCmd->SetUnitCategory("Energy 157 setAdjSourceEmaxCmd->AvailableForStates(G4St 158 159 ConsiderParticleAsPrimaryCmd = new G4UIcmdWi 160 ConsiderParticleAsPrimaryCmd->SetGuidance("S 161 ConsiderParticleAsPrimaryCmd->SetParameterNa 162 ConsiderParticleAsPrimaryCmd->SetCandidates( 163 164 NeglectParticleAsPrimaryCmd = new G4UIcmdWit 165 NeglectParticleAsPrimaryCmd->SetGuidance( 166 "Remove the selected particle from the lis 167 NeglectParticleAsPrimaryCmd->SetParameterNam 168 NeglectParticleAsPrimaryCmd->SetCandidates(" 169 170 setNbOfPrimaryFwdGammasPerEventCmd = 171 new G4UIcmdWithAnInteger("/adjoint/SetNbOf 172 setNbOfPrimaryFwdGammasPerEventCmd->SetGuida 173 "Set the nb of primary fwd gamm generated 174 setNbOfPrimaryFwdGammasPerEventCmd->SetParam 175 setNbOfPrimaryFwdGammasPerEventCmd->Availabl 176 177 setNbOfPrimaryAdjGammasPerEventCmd = 178 new G4UIcmdWithAnInteger("/adjoint/SetNbOf 179 setNbOfPrimaryAdjGammasPerEventCmd->SetGuida 180 "Set the nb of primary fwd gamm generated 181 setNbOfPrimaryAdjGammasPerEventCmd->SetParam 182 setNbOfPrimaryAdjGammasPerEventCmd->Availabl 183 184 setNbOfPrimaryAdjElectronsPerEventCmd = 185 new G4UIcmdWithAnInteger("/adjoint/SetNbOf 186 setNbOfPrimaryAdjElectronsPerEventCmd->SetGu 187 "Set the nb of primary fwd gamm generated 188 setNbOfPrimaryAdjElectronsPerEventCmd->SetPa 189 setNbOfPrimaryAdjElectronsPerEventCmd->Avail 190 } 191 192 // ------------------------------------------- 193 // 194 G4AdjointSimMessenger::~G4AdjointSimMessenger( 195 { 196 delete setNbOfPrimaryAdjElectronsPerEventCmd 197 delete setNbOfPrimaryAdjGammasPerEventCmd; 198 delete setNbOfPrimaryFwdGammasPerEventCmd; 199 delete NeglectParticleAsPrimaryCmd; 200 delete ConsiderParticleAsPrimaryCmd; 201 delete setAdjSourceEmaxCmd; 202 delete setAdjSourceEminCmd; 203 delete DefineAdjSourceOnAVolumeExtSurfaceCmd 204 delete DefineSpherAdjSourceCenteredOnAVolume 205 delete DefineSpherAdjSourceCmd; 206 delete setExtSourceEMaxCmd; 207 delete DefineExtSourceOnAVolumeExtSurfaceCmd 208 delete DefineSpherExtSourceCenteredOnAVolume 209 delete DefineSpherExtSourceCmd; 210 delete beamOnCmd; 211 delete AdjointSimDir; 212 } 213 214 // ------------------------------------------- 215 // 216 void G4AdjointSimMessenger::SetNewValue(G4UIco 217 { 218 if (command == nullptr) return; 219 if (command == beamOnCmd) { 220 G4int nev; 221 const auto nv = (const char*)newValue; 222 std::istringstream is(nv); 223 is >> nev; 224 theAdjointRunManager->RunAdjointSimulation 225 } 226 else if (command == ConsiderParticleAsPrimar 227 theAdjointRunManager->ConsiderParticleAsPr 228 } 229 else if (command == NeglectParticleAsPrimary 230 theAdjointRunManager->NeglectParticleAsPri 231 } 232 if (command == DefineSpherExtSourceCmd) { 233 G4double x, y, z, r; 234 G4String unit; 235 const auto nv = (const char*)newValue; 236 std::istringstream is(nv); 237 is >> x >> y >> z >> r >> unit; 238 239 x *= G4UnitDefinition::GetValueOf(unit); 240 y *= G4UnitDefinition::GetValueOf(unit); 241 z *= G4UnitDefinition::GetValueOf(unit); 242 r *= G4UnitDefinition::GetValueOf(unit); 243 theAdjointRunManager->DefineSphericalExtSo 244 } 245 else if (command == DefineSpherExtSourceCent 246 G4double r; 247 G4String vol_name, unit; 248 const auto nv = (const char*)newValue; 249 std::istringstream is(nv); 250 is >> vol_name >> r >> unit; 251 r *= G4UnitDefinition::GetValueOf(unit); 252 theAdjointRunManager->DefineSphericalExtSo 253 } 254 else if (command == DefineExtSourceOnAVolume 255 theAdjointRunManager->DefineExtSourceOnThe 256 } 257 else if (command == setExtSourceEMaxCmd) { 258 theAdjointRunManager->SetExtSourceEmax(set 259 } 260 else if (command == DefineSpherAdjSourceCmd) 261 G4double x, y, z, r; 262 G4String unit; 263 const auto nv = (const char*)newValue; 264 std::istringstream is(nv); 265 is >> x >> y >> z >> r >> unit; 266 267 x *= G4UnitDefinition::GetValueOf(unit); 268 y *= G4UnitDefinition::GetValueOf(unit); 269 z *= G4UnitDefinition::GetValueOf(unit); 270 r *= G4UnitDefinition::GetValueOf(unit); 271 theAdjointRunManager->DefineSphericalAdjoi 272 } 273 else if (command == DefineSpherAdjSourceCent 274 G4double r; 275 G4String vol_name, unit; 276 const auto nv = (const char*)newValue; 277 std::istringstream is(nv); 278 is >> vol_name >> r >> unit; 279 r *= G4UnitDefinition::GetValueOf(unit); 280 theAdjointRunManager->DefineSphericalAdjoi 281 } 282 else if (command == DefineAdjSourceOnAVolume 283 theAdjointRunManager->DefineAdjointSourceO 284 } 285 else if (command == setAdjSourceEminCmd) { 286 theAdjointRunManager->SetAdjointSourceEmin 287 } 288 else if (command == setAdjSourceEmaxCmd) { 289 theAdjointRunManager->SetAdjointSourceEmax 290 } 291 else if (command == setNbOfPrimaryFwdGammasP 292 theAdjointRunManager->SetNbOfPrimaryFwdGam 293 setNbOfPrimaryFwdGammasPerEventCmd->GetN 294 } 295 else if (command == setNbOfPrimaryAdjGammasP 296 theAdjointRunManager->SetNbAdjointPrimaryG 297 setNbOfPrimaryAdjGammasPerEventCmd->GetN 298 } 299 else if (command == setNbOfPrimaryAdjElectro 300 theAdjointRunManager->SetNbAdjointPrimaryE 301 setNbOfPrimaryAdjElectronsPerEventCmd->G 302 } 303 } 304