Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4AdjointSimMessenger.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
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 <sstream>
37
40#include "G4RunManager.hh"
42#include "G4UIcmdWithABool.hh"
43#include "G4UIcmdWithADouble.hh"
45#include "G4UIcmdWithAString.hh"
48#include "G4UIdirectory.hh"
49#include "G4UnitsTable.hh"
50
51// --------------------------------------------------------------------
52//
55 : theAdjointRunManager(pAdjointRunManager)
56{
57 AdjointSimDir = new G4UIdirectory("/adjoint/");
58 AdjointSimDir->SetGuidance(
59 "Control of the adjoint or reverse monte carlo simulation");
60
61 // Start and adjoint Run
62 //---------------------
63
64 beamOnCmd = new G4UIcommand("/adjoint/start_run", this);
65 beamOnCmd->SetGuidance("Start an adjoint Run.");
66 beamOnCmd->SetGuidance("Default number of events to be processed is 1.");
68 G4UIparameter* p1 = new G4UIparameter("numberOfEvent", 'i', true);
69 p1->SetDefaultValue(1);
70 p1->SetParameterRange("numberOfEvent >= 0");
71 beamOnCmd->SetParameter(p1);
72
73 // Commands to define parameters relative to the external source
74 //------------------------------------------------------------
75
76 G4UIparameter* pos_x_par = new G4UIparameter("X", 'd', true);
77
78 G4UIparameter* pos_y_par = new G4UIparameter("Y", 'd', true);
79
80 G4UIparameter* pos_z_par = new G4UIparameter("Z", 'd', true);
81
82 G4UIparameter* radius_par = new G4UIparameter("R", 'd', true);
83
84 radius_par->SetParameterRange("R >= 0");
85
86 G4UIparameter* unit_par = new G4UIparameter("unit", 's', true);
87
88 DefineSpherExtSourceCmd =
89 new G4UIcommand("/adjoint/DefineSphericalExtSource", this);
90 DefineSpherExtSourceCmd->SetGuidance("Define a spherical external source.");
91 DefineSpherExtSourceCmd->SetParameter(pos_x_par);
92 DefineSpherExtSourceCmd->SetParameter(pos_y_par);
93 DefineSpherExtSourceCmd->SetParameter(pos_z_par);
94 DefineSpherExtSourceCmd->SetParameter(radius_par);
95 DefineSpherExtSourceCmd->SetParameter(unit_par);
96
97 G4UIparameter* phys_vol_name_par =
98 new G4UIparameter("phys_vol_name", 's', true);
99
100 DefineSpherExtSourceCenteredOnAVolumeCmd =
101 new G4UIcommand("/adjoint/DefineSphericalExtSourceCenteredOnAVolume", this);
102 DefineSpherExtSourceCenteredOnAVolumeCmd->SetGuidance(
103 "Define a spherical external source with the center located at the center "
104 "of a "
105 "physical volume");
106 DefineSpherExtSourceCenteredOnAVolumeCmd->SetParameter(phys_vol_name_par);
107 DefineSpherExtSourceCenteredOnAVolumeCmd->SetParameter(radius_par);
108 DefineSpherExtSourceCenteredOnAVolumeCmd->SetParameter(unit_par);
109
110 DefineExtSourceOnAVolumeExtSurfaceCmd = new G4UIcmdWithAString(
111 "/adjoint/DefineExtSourceOnExtSurfaceOfAVolume", this);
112 DefineExtSourceOnAVolumeExtSurfaceCmd->SetGuidance(
113 "Set the external source on the external surface of a physical volume");
114 DefineExtSourceOnAVolumeExtSurfaceCmd->SetParameterName("phys_vol_name",
115 false);
116
117 setExtSourceEMaxCmd =
118 new G4UIcmdWithADoubleAndUnit("/adjoint/SetExtSourceEmax", this);
119 setExtSourceEMaxCmd->SetGuidance(
120 "Set the maximum energy of the external source");
121 setExtSourceEMaxCmd->SetParameterName("Emax", false);
122 setExtSourceEMaxCmd->SetUnitCategory("Energy");
123 setExtSourceEMaxCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
124
125 // Commands to define the adjoint source
126 //------------------------------------------------------------
127
128 DefineSpherAdjSourceCmd =
129 new G4UIcommand("/adjoint/DefineSphericalAdjSource", this);
130 DefineSpherAdjSourceCmd->SetGuidance("Define a spherical adjoint source.");
131 DefineSpherAdjSourceCmd->SetParameter(pos_x_par);
132 DefineSpherAdjSourceCmd->SetParameter(pos_y_par);
133 DefineSpherAdjSourceCmd->SetParameter(pos_z_par);
134 DefineSpherAdjSourceCmd->SetParameter(radius_par);
135 DefineSpherAdjSourceCmd->SetParameter(unit_par);
136
137 DefineSpherAdjSourceCenteredOnAVolumeCmd =
138 new G4UIcommand("/adjoint/DefineSphericalAdjSourceCenteredOnAVolume", this);
139 DefineSpherAdjSourceCenteredOnAVolumeCmd->SetGuidance(
140 "Define a spherical adjoint source with the center located at the center "
141 "of a "
142 "physical volume");
143 DefineSpherAdjSourceCenteredOnAVolumeCmd->SetParameter(phys_vol_name_par);
144 DefineSpherAdjSourceCenteredOnAVolumeCmd->SetParameter(radius_par);
145 DefineSpherAdjSourceCenteredOnAVolumeCmd->SetParameter(unit_par);
146
147 DefineAdjSourceOnAVolumeExtSurfaceCmd = new G4UIcmdWithAString(
148 "/adjoint/DefineAdjSourceOnExtSurfaceOfAVolume", this);
149 DefineAdjSourceOnAVolumeExtSurfaceCmd->SetGuidance(
150 "Set the adjoint source on the external surface of physical volume");
151 DefineAdjSourceOnAVolumeExtSurfaceCmd->SetParameterName("phys_vol_name",
152 false);
153
154 setAdjSourceEminCmd =
155 new G4UIcmdWithADoubleAndUnit("/adjoint/SetAdjSourceEmin", this);
156 setAdjSourceEminCmd->SetGuidance(
157 "Set the minimum energy of the adjoint source");
158 setAdjSourceEminCmd->SetParameterName("Emin", false);
159 setAdjSourceEminCmd->SetUnitCategory("Energy");
160 setAdjSourceEminCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
161
162 setAdjSourceEmaxCmd =
163 new G4UIcmdWithADoubleAndUnit("/adjoint/SetAdjSourceEmax", this);
164 setAdjSourceEmaxCmd->SetGuidance(
165 "Set the maximum energy of the adjoint source");
166 setAdjSourceEmaxCmd->SetParameterName("Emax", false);
167 setAdjSourceEmaxCmd->SetUnitCategory("Energy");
168 setAdjSourceEmaxCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
169
170 ConsiderParticleAsPrimaryCmd =
171 new G4UIcmdWithAString("/adjoint/ConsiderAsPrimary", this);
172 ConsiderParticleAsPrimaryCmd->SetGuidance(
173 "Set the selected particle as primary");
174 ConsiderParticleAsPrimaryCmd->SetParameterName("particle", false);
175 ConsiderParticleAsPrimaryCmd->SetCandidates("e- gamma proton ion");
176
177 NeglectParticleAsPrimaryCmd =
178 new G4UIcmdWithAString("/adjoint/NeglectAsPrimary", this);
179 NeglectParticleAsPrimaryCmd->SetGuidance(
180 "Remove the selected particle from the list of primaries");
181 NeglectParticleAsPrimaryCmd->SetParameterName("particle", false);
182 NeglectParticleAsPrimaryCmd->SetCandidates("e- gamma proton ion");
183
184 setNbOfPrimaryFwdGammasPerEventCmd =
185 new G4UIcmdWithAnInteger("/adjoint/SetNbOfPrimaryFwdGammasPerEvent", this);
186 setNbOfPrimaryFwdGammasPerEventCmd->SetGuidance(
187 "Set the nb of primary fwd gamm generated on the adjoint source");
188 setNbOfPrimaryFwdGammasPerEventCmd->SetParameterName("Nb_gammas", false);
189 setNbOfPrimaryFwdGammasPerEventCmd->AvailableForStates(G4State_PreInit,
191
192 setNbOfPrimaryAdjGammasPerEventCmd =
193 new G4UIcmdWithAnInteger("/adjoint/SetNbOfPrimaryAdjGammasPerEvent", this);
194 setNbOfPrimaryAdjGammasPerEventCmd->SetGuidance(
195 "Set the nb of primary fwd gamm generated on the adjoint source");
196 setNbOfPrimaryAdjGammasPerEventCmd->SetParameterName("Nb_gammas", false);
197 setNbOfPrimaryAdjGammasPerEventCmd->AvailableForStates(G4State_PreInit,
199
200 setNbOfPrimaryAdjElectronsPerEventCmd = new G4UIcmdWithAnInteger(
201 "/adjoint/SetNbOfPrimaryAdjElectronsPerEvent", this);
202 setNbOfPrimaryAdjElectronsPerEventCmd->SetGuidance(
203 "Set the nb of primary fwd gamm generated on the adjoint source");
204 setNbOfPrimaryAdjElectronsPerEventCmd->SetParameterName("Nb_gammas", false);
205 setNbOfPrimaryAdjElectronsPerEventCmd->AvailableForStates(G4State_PreInit,
207}
208
209// --------------------------------------------------------------------
210//
212{
213 delete setNbOfPrimaryAdjElectronsPerEventCmd;
214 delete setNbOfPrimaryAdjGammasPerEventCmd;
215 delete setNbOfPrimaryFwdGammasPerEventCmd;
216 delete NeglectParticleAsPrimaryCmd;
217 delete ConsiderParticleAsPrimaryCmd;
218 delete setAdjSourceEmaxCmd;
219 delete setAdjSourceEminCmd;
220 delete DefineAdjSourceOnAVolumeExtSurfaceCmd;
221 delete DefineSpherAdjSourceCenteredOnAVolumeCmd;
222 delete DefineSpherAdjSourceCmd;
223 delete setExtSourceEMaxCmd;
224 delete DefineExtSourceOnAVolumeExtSurfaceCmd;
225 delete DefineSpherExtSourceCenteredOnAVolumeCmd;
226 delete DefineSpherExtSourceCmd;
227 delete beamOnCmd;
228 delete AdjointSimDir;
229}
230
231// --------------------------------------------------------------------
232//
234{
235 if(command == nullptr)
236 return;
237 if(command == beamOnCmd)
238 {
239 G4int nev;
240 const char* nv = (const char*) newValue;
241 std::istringstream is(nv);
242 is >> nev;
243 if(G4RunManager::GetRunManager()->GetRunManagerType() ==
245 theAdjointRunManager->RunAdjointSimulation(nev);
246 }
247 else if(command == ConsiderParticleAsPrimaryCmd)
248 {
249 theAdjointRunManager->ConsiderParticleAsPrimary(newValue);
250 }
251 else if(command == NeglectParticleAsPrimaryCmd)
252 {
253 theAdjointRunManager->NeglectParticleAsPrimary(newValue);
254 }
255 if(command == DefineSpherExtSourceCmd)
256 {
257 G4double x, y, z, r;
258 G4String unit;
259 const char* nv = (const char*) newValue;
260 std::istringstream is(nv);
261 is >> x >> y >> z >> r >> unit;
262
267 theAdjointRunManager->DefineSphericalExtSource(r, G4ThreeVector(x, y, z));
268 }
269 else if(command == DefineSpherExtSourceCenteredOnAVolumeCmd)
270 {
271 G4double r;
272 G4String vol_name, unit;
273 const char* nv = (const char*) newValue;
274 std::istringstream is(nv);
275 is >> vol_name >> r >> unit;
277 theAdjointRunManager
279 }
280 else if(command == DefineExtSourceOnAVolumeExtSurfaceCmd)
281 {
282 theAdjointRunManager->DefineExtSourceOnTheExtSurfaceOfAVolume(newValue);
283 }
284 else if(command == setExtSourceEMaxCmd)
285 {
286 theAdjointRunManager->SetExtSourceEmax(
287 setExtSourceEMaxCmd->GetNewDoubleValue(newValue));
288 }
289 else if(command == DefineSpherAdjSourceCmd)
290 {
291 G4double x, y, z, r;
292 G4String unit;
293 const char* nv = (const char*) newValue;
294 std::istringstream is(nv);
295 is >> x >> y >> z >> r >> unit;
296
301 theAdjointRunManager->DefineSphericalAdjointSource(r,
302 G4ThreeVector(x, y, z));
303 }
304 else if(command == DefineSpherAdjSourceCenteredOnAVolumeCmd)
305 {
306 G4double r;
307 G4String vol_name, unit;
308 const char* nv = (const char*) newValue;
309 std::istringstream is(nv);
310 is >> vol_name >> r >> unit;
312 theAdjointRunManager
314 }
315 else if(command == DefineAdjSourceOnAVolumeExtSurfaceCmd)
316 {
317 theAdjointRunManager->DefineAdjointSourceOnTheExtSurfaceOfAVolume(newValue);
318 }
319 else if(command == setAdjSourceEminCmd)
320 {
321 theAdjointRunManager->SetAdjointSourceEmin(
322 setAdjSourceEminCmd->GetNewDoubleValue(newValue));
323 }
324 else if(command == setAdjSourceEmaxCmd)
325 {
326 theAdjointRunManager->SetAdjointSourceEmax(
327 setAdjSourceEmaxCmd->GetNewDoubleValue(newValue));
328 }
329 else if(command == setNbOfPrimaryFwdGammasPerEventCmd)
330 {
331 theAdjointRunManager->SetNbOfPrimaryFwdGammasPerEvent(
332 setNbOfPrimaryFwdGammasPerEventCmd->GetNewIntValue(newValue));
333 }
334 else if(command == setNbOfPrimaryAdjGammasPerEventCmd)
335 {
336 theAdjointRunManager->SetNbAdjointPrimaryGammasPerEvent(
337 setNbOfPrimaryAdjGammasPerEventCmd->GetNewIntValue(newValue));
338 }
339 else if(command == setNbOfPrimaryAdjElectronsPerEventCmd)
340 {
341 theAdjointRunManager->SetNbAdjointPrimaryElectronsPerEvent(
342 setNbOfPrimaryAdjElectronsPerEventCmd->GetNewIntValue(newValue));
343 }
344}
@ G4State_Idle
@ G4State_PreInit
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
G4bool DefineAdjointSourceOnTheExtSurfaceOfAVolume(const G4String &volume_name)
G4bool DefineExtSourceOnTheExtSurfaceOfAVolume(const G4String &volume_name)
void RunAdjointSimulation(G4int nb_evt)
G4bool DefineSphericalExtSourceWithCentreAtTheCentreOfAVolume(G4double radius, const G4String &volume_name)
void SetNbAdjointPrimaryGammasPerEvent(G4int)
void ConsiderParticleAsPrimary(const G4String &particle_name)
void SetExtSourceEmax(G4double Emax)
void SetAdjointSourceEmax(G4double Emax)
void SetAdjointSourceEmin(G4double Emin)
void NeglectParticleAsPrimary(const G4String &particle_name)
G4bool DefineSphericalAdjointSourceWithCentreAtTheCentreOfAVolume(G4double radius, const G4String &volume_name)
void SetNbAdjointPrimaryElectronsPerEvent(G4int)
void SetNbOfPrimaryFwdGammasPerEvent(G4int)
G4bool DefineSphericalExtSource(G4double radius, G4ThreeVector pos)
G4bool DefineSphericalAdjointSource(G4double radius, G4ThreeVector pos)
G4AdjointSimMessenger(G4AdjointSimManager *)
void SetNewValue(G4UIcommand *, G4String)
static G4RunManager * GetRunManager()
void SetUnitCategory(const char *unitCategory)
static G4double GetNewDoubleValue(const char *paramString)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetCandidates(const char *candidateList)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:147
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:157
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:287
void SetDefaultValue(const char *theDefaultValue)
void SetParameterRange(const char *theRange)
static G4double GetValueOf(const G4String &)