Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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//
27/////////////////////////////////////////////////////////////////////////////
28// Class Name: G4AdjointCrossSurfChecker
29// Author: L. Desorgher
30// Organisation: SpaceIT GmbH
31// Contract: ESA contract 21435/08/NL/AT
32// Customer: ESA/ESTEC
33/////////////////////////////////////////////////////////////////////////////
34
35#include <sstream>
36
39#include "G4RunManager.hh"
41#include "G4UIcmdWithABool.hh"
42#include "G4UIcmdWithADouble.hh"
44#include "G4UIcmdWithAString.hh"
47#include "G4UIdirectory.hh"
48#include "G4UnitsTable.hh"
49/*
50#ifdef G4MULTITHREADED
51#include "G4MTAdjointSimManager.hh"
52#endif
53*/
54///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
55//
57 G4AdjointSimManager* pAdjointRunManager)
58 : theAdjointRunManager(pAdjointRunManager)
59/*
60#ifdef G4MULTITHREADED
61 ,theMTAdjointRunManager(0),beamOnCmd(0)
62#endif
63*/
64
65{
66 AdjointSimDir = new G4UIdirectory("/adjoint/");
67 AdjointSimDir->SetGuidance(
68 "Control of the adjoint or reverse monte carlo simulation");
69
70 // Start and adjoint Run
71 //---------------------
72 // if (G4RunManager::GetRunManager()->GetRunManagerType() ==
73 // G4RunManager::sequentialRM){
74 beamOnCmd = new G4UIcommand("/adjoint/start_run", this);
75 beamOnCmd->SetGuidance("Start an adjoint Run.");
76 beamOnCmd->SetGuidance("Default number of events to be processed is 1.");
78 G4UIparameter* p1 = new G4UIparameter("numberOfEvent", 'i', true);
79 p1->SetDefaultValue(1);
80 p1->SetParameterRange("numberOfEvent >= 0");
81 beamOnCmd->SetParameter(p1);
82 //}
83
84 // Commands to define parameters relative to the external source
85 //------------------------------------------------------------
86
87 G4UIparameter* pos_x_par = new G4UIparameter("X", 'd', true);
88
89 G4UIparameter* pos_y_par = new G4UIparameter("Y", 'd', true);
90
91 G4UIparameter* pos_z_par = new G4UIparameter("Z", 'd', true);
92
93 G4UIparameter* radius_par = new G4UIparameter("R", 'd', true);
94
95 radius_par->SetParameterRange("R >= 0");
96
97 G4UIparameter* unit_par = new G4UIparameter("unit", 's', true);
98
99 DefineSpherExtSourceCmd =
100 new G4UIcommand("/adjoint/DefineSphericalExtSource", this);
101 DefineSpherExtSourceCmd->SetGuidance("Define a spherical external source.");
102 DefineSpherExtSourceCmd->SetParameter(pos_x_par);
103 DefineSpherExtSourceCmd->SetParameter(pos_y_par);
104 DefineSpherExtSourceCmd->SetParameter(pos_z_par);
105 DefineSpherExtSourceCmd->SetParameter(radius_par);
106 DefineSpherExtSourceCmd->SetParameter(unit_par);
107
108 G4UIparameter* phys_vol_name_par =
109 new G4UIparameter("phys_vol_name", 's', true);
110
111 DefineSpherExtSourceCenteredOnAVolumeCmd =
112 new G4UIcommand("/adjoint/DefineSphericalExtSourceCenteredOnAVolume", this);
113 DefineSpherExtSourceCenteredOnAVolumeCmd->SetGuidance(
114 "Define a spherical external source with the center located at the center "
115 "of a "
116 "physical volume");
117 DefineSpherExtSourceCenteredOnAVolumeCmd->SetParameter(phys_vol_name_par);
118 DefineSpherExtSourceCenteredOnAVolumeCmd->SetParameter(radius_par);
119 DefineSpherExtSourceCenteredOnAVolumeCmd->SetParameter(unit_par);
120
121 DefineExtSourceOnAVolumeExtSurfaceCmd = new G4UIcmdWithAString(
122 "/adjoint/DefineExtSourceOnExtSurfaceOfAVolume", this);
123 DefineExtSourceOnAVolumeExtSurfaceCmd->SetGuidance(
124 "Set the external source on the external surface of a physical volume");
125 DefineExtSourceOnAVolumeExtSurfaceCmd->SetParameterName("phys_vol_name",
126 false);
127
128 setExtSourceEMaxCmd =
129 new G4UIcmdWithADoubleAndUnit("/adjoint/SetExtSourceEmax", this);
130 setExtSourceEMaxCmd->SetGuidance(
131 "Set the maximum energy of the external source");
132 setExtSourceEMaxCmd->SetParameterName("Emax", false);
133 setExtSourceEMaxCmd->SetUnitCategory("Energy");
134 setExtSourceEMaxCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
135
136 // Commands to define the adjoint source
137 //------------------------------------------------------------
138
139 DefineSpherAdjSourceCmd =
140 new G4UIcommand("/adjoint/DefineSphericalAdjSource", this);
141 DefineSpherAdjSourceCmd->SetGuidance("Define a spherical adjoint source.");
142 DefineSpherAdjSourceCmd->SetParameter(pos_x_par);
143 DefineSpherAdjSourceCmd->SetParameter(pos_y_par);
144 DefineSpherAdjSourceCmd->SetParameter(pos_z_par);
145 DefineSpherAdjSourceCmd->SetParameter(radius_par);
146 DefineSpherAdjSourceCmd->SetParameter(unit_par);
147
148 DefineSpherAdjSourceCenteredOnAVolumeCmd =
149 new G4UIcommand("/adjoint/DefineSphericalAdjSourceCenteredOnAVolume", this);
150 DefineSpherAdjSourceCenteredOnAVolumeCmd->SetGuidance(
151 "Define a spherical adjoint source with the center located at the center "
152 "of a "
153 "physical volume");
154 DefineSpherAdjSourceCenteredOnAVolumeCmd->SetParameter(phys_vol_name_par);
155 DefineSpherAdjSourceCenteredOnAVolumeCmd->SetParameter(radius_par);
156 DefineSpherAdjSourceCenteredOnAVolumeCmd->SetParameter(unit_par);
157
158 DefineAdjSourceOnAVolumeExtSurfaceCmd = new G4UIcmdWithAString(
159 "/adjoint/DefineAdjSourceOnExtSurfaceOfAVolume", this);
160 DefineAdjSourceOnAVolumeExtSurfaceCmd->SetGuidance(
161 "Set the adjoint source on the external surface of physical volume");
162 DefineAdjSourceOnAVolumeExtSurfaceCmd->SetParameterName("phys_vol_name",
163 false);
164
165 setAdjSourceEminCmd =
166 new G4UIcmdWithADoubleAndUnit("/adjoint/SetAdjSourceEmin", this);
167 setAdjSourceEminCmd->SetGuidance(
168 "Set the minimum energy of the adjoint source");
169 setAdjSourceEminCmd->SetParameterName("Emin", false);
170 setAdjSourceEminCmd->SetUnitCategory("Energy");
171 setAdjSourceEminCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
172
173 setAdjSourceEmaxCmd =
174 new G4UIcmdWithADoubleAndUnit("/adjoint/SetAdjSourceEmax", this);
175 setAdjSourceEmaxCmd->SetGuidance(
176 "Set the maximum energy of the adjoint source");
177 setAdjSourceEmaxCmd->SetParameterName("Emax", false);
178 setAdjSourceEmaxCmd->SetUnitCategory("Energy");
179 setAdjSourceEmaxCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
180
181 ConsiderParticleAsPrimaryCmd =
182 new G4UIcmdWithAString("/adjoint/ConsiderAsPrimary", this);
183 ConsiderParticleAsPrimaryCmd->SetGuidance(
184 "Set the selected particle as primary");
185 ConsiderParticleAsPrimaryCmd->SetParameterName("particle", false);
186 ConsiderParticleAsPrimaryCmd->SetCandidates("e- gamma proton ion");
187
188 NeglectParticleAsPrimaryCmd =
189 new G4UIcmdWithAString("/adjoint/NeglectAsPrimary", this);
190 NeglectParticleAsPrimaryCmd->SetGuidance(
191 "Remove the selected particle from the list of primaries");
192 NeglectParticleAsPrimaryCmd->SetParameterName("particle", false);
193 NeglectParticleAsPrimaryCmd->SetCandidates("e- gamma proton ion");
194
195 setNbOfPrimaryFwdGammasPerEventCmd =
196 new G4UIcmdWithAnInteger("/adjoint/SetNbOfPrimaryFwdGammasPerEvent", this);
197 setNbOfPrimaryFwdGammasPerEventCmd->SetGuidance(
198 "Set the nb of primary fwd gamm generated on the adjoint source");
199 setNbOfPrimaryFwdGammasPerEventCmd->SetParameterName("Nb_gammas", false);
200 setNbOfPrimaryFwdGammasPerEventCmd->AvailableForStates(G4State_PreInit,
202
203 setNbOfPrimaryAdjGammasPerEventCmd =
204 new G4UIcmdWithAnInteger("/adjoint/SetNbOfPrimaryAdjGammasPerEvent", this);
205 setNbOfPrimaryAdjGammasPerEventCmd->SetGuidance(
206 "Set the nb of primary fwd gamm generated on the adjoint source");
207 setNbOfPrimaryAdjGammasPerEventCmd->SetParameterName("Nb_gammas", false);
208 setNbOfPrimaryAdjGammasPerEventCmd->AvailableForStates(G4State_PreInit,
210
211 setNbOfPrimaryAdjElectronsPerEventCmd = new G4UIcmdWithAnInteger(
212 "/adjoint/SetNbOfPrimaryAdjElectronsPerEvent", this);
213 setNbOfPrimaryAdjElectronsPerEventCmd->SetGuidance(
214 "Set the nb of primary fwd gamm generated on the adjoint source");
215 setNbOfPrimaryAdjElectronsPerEventCmd->SetParameterName("Nb_gammas", false);
216 setNbOfPrimaryAdjElectronsPerEventCmd->AvailableForStates(G4State_PreInit,
218}
219///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
220//
221/*
222#ifdef G4MULTITHREADED
223G4AdjointSimMessenger::G4AdjointSimMessenger(G4MTAdjointSimManager*
224pAdjointRunManager)
225 :
226theAdjointRunManager(0),theMTAdjointRunManager(pAdjointRunManager),DefineSpherExtSourceCmd(0),
227 DefineSpherExtSourceCenteredOnAVolumeCmd(0),
228DefineExtSourceOnAVolumeExtSurfaceCmd(0),
229 setExtSourceEMaxCmd(0),DefineSpherAdjSourceCmd(0),DefineSpherAdjSourceCenteredOnAVolumeCmd(0),
230 DefineAdjSourceOnAVolumeExtSurfaceCmd(0),setAdjSourceEminCmd(0),setAdjSourceEmaxCmd(0),
231 ConsiderParticleAsPrimaryCmd(0),NeglectParticleAsPrimaryCmd(0)
232{
233 AdjointSimDir = new G4UIdirectory("/adjoint/");
234 AdjointSimDir->SetGuidance("Control of the adjoint or reverse monte carlo
235simulation");
236
237
238 //Start and adjoint Run
239 //---------------------
240 beamOnCmd = new G4UIcommand("/adjoint/start_run",this);
241 beamOnCmd->SetGuidance("Start an adjoint Run.");
242 beamOnCmd->SetGuidance("Default number of events to be processed is 1.");
243 beamOnCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
244 G4UIparameter* p1 = new G4UIparameter("numberOfEvent",'i',true);
245 p1->SetDefaultValue(1);
246 p1->SetParameterRange("numberOfEvent >= 0");
247 beamOnCmd->SetParameter(p1);
248
249
250 ConsiderParticleAsPrimaryCmd = new
251G4UIcmdWithAString("/adjoint/ConsiderAsPrimary",this);
252 ConsiderParticleAsPrimaryCmd->SetGuidance("Set the selected particle as
253primary"); ConsiderParticleAsPrimaryCmd->SetParameterName("particle",false);
254 ConsiderParticleAsPrimaryCmd->SetCandidates("e- gamma proton ion");
255
256 NeglectParticleAsPrimaryCmd= new
257G4UIcmdWithAString("/adjoint/NeglectAsPrimary",this);
258 NeglectParticleAsPrimaryCmd->SetGuidance("Remove the selected particle from
259the lits of primaries");
260NeglectParticleAsPrimaryCmd->SetParameterName("particle",false);
261 NeglectParticleAsPrimaryCmd->SetCandidates("e- gamma proton ion");
262
263
264}
265#endif
266*/
267
268///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
269//
270
272{
273 if(beamOnCmd)
274 delete beamOnCmd;
275}
276
277///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
278//
279
281{
282 if(!command)
283 return;
284 if(command == beamOnCmd)
285 {
286 G4int nev;
287 const char* nv = (const char*) newValue;
288 std::istringstream is(nv);
289 is >> nev;
290 if(G4RunManager::GetRunManager()->GetRunManagerType() ==
292 theAdjointRunManager->RunAdjointSimulation(nev);
293 /*
294 #ifdef G4MULTITHREADED
295 else if (theMTAdjointRunManager)
296 theMTAdjointRunManager->RunAdjointSimulation(nev); else if
297 (theAdjointRunManager)
298 theAdjointRunManager->SwitchToAdjointSimulationMode(); #endif
299 */
300 // G4cout<<"G4AdjointSimMessenger::SetNewValue BeamOnCmd out"<<std::endl;
301 }
302 else if(command == ConsiderParticleAsPrimaryCmd)
303 {
304 theAdjointRunManager->ConsiderParticleAsPrimary(newValue);
305 }
306 else if(command == NeglectParticleAsPrimaryCmd)
307 {
308 theAdjointRunManager->NeglectParticleAsPrimary(newValue);
309 }
310 /*
311 #ifdef G4MULTITHREADED
312 if (G4RunManager::GetRunManager()->GetRunManagerType() ==
313 G4RunManager::masterRM) return; #endif
314 */
315 if(command == DefineSpherExtSourceCmd)
316 {
317 G4double x, y, z, r;
318 G4String unit;
319 const char* nv = (const char*) newValue;
320 std::istringstream is(nv);
321 is >> x >> y >> z >> r >> unit;
322
327 theAdjointRunManager->DefineSphericalExtSource(r, G4ThreeVector(x, y, z));
328 }
329 else if(command == DefineSpherExtSourceCenteredOnAVolumeCmd)
330 {
331 G4double r;
332 G4String vol_name, unit;
333 const char* nv = (const char*) newValue;
334 std::istringstream is(nv);
335 is >> vol_name >> r >> unit;
337 theAdjointRunManager
339 }
340 else if(command == DefineExtSourceOnAVolumeExtSurfaceCmd)
341 {
342 theAdjointRunManager->DefineExtSourceOnTheExtSurfaceOfAVolume(newValue);
343 }
344 else if(command == setExtSourceEMaxCmd)
345 {
346 theAdjointRunManager->SetExtSourceEmax(
347 setExtSourceEMaxCmd->GetNewDoubleValue(newValue));
348 }
349 else if(command == DefineSpherAdjSourceCmd)
350 {
351 G4double x, y, z, r;
352 G4String unit;
353 const char* nv = (const char*) newValue;
354 std::istringstream is(nv);
355 is >> x >> y >> z >> r >> unit;
356
361 theAdjointRunManager->DefineSphericalAdjointSource(r,
362 G4ThreeVector(x, y, z));
363 }
364 else if(command == DefineSpherAdjSourceCenteredOnAVolumeCmd)
365 {
366 G4double r;
367 G4String vol_name, unit;
368 const char* nv = (const char*) newValue;
369 std::istringstream is(nv);
370 is >> vol_name >> r >> unit;
372 theAdjointRunManager
374 }
375 else if(command == DefineAdjSourceOnAVolumeExtSurfaceCmd)
376 {
377 theAdjointRunManager->DefineAdjointSourceOnTheExtSurfaceOfAVolume(newValue);
378 }
379 else if(command == setAdjSourceEminCmd)
380 {
381 theAdjointRunManager->SetAdjointSourceEmin(
382 setAdjSourceEminCmd->GetNewDoubleValue(newValue));
383 }
384 else if(command == setAdjSourceEmaxCmd)
385 {
386 theAdjointRunManager->SetAdjointSourceEmax(
387 setAdjSourceEmaxCmd->GetNewDoubleValue(newValue));
388 }
389 else if(command == setNbOfPrimaryFwdGammasPerEventCmd)
390 {
391 theAdjointRunManager->SetNbOfPrimaryFwdGammasPerEvent(
392 setNbOfPrimaryFwdGammasPerEventCmd->GetNewIntValue(newValue));
393 }
394 else if(command == setNbOfPrimaryAdjGammasPerEventCmd)
395 {
396 theAdjointRunManager->SetNbAdjointPrimaryGammasPerEvent(
397 setNbOfPrimaryAdjGammasPerEventCmd->GetNewIntValue(newValue));
398 }
399 else if(command == setNbOfPrimaryAdjElectronsPerEventCmd)
400 {
401 theAdjointRunManager->SetNbAdjointPrimaryElectronsPerEvent(
402 setNbOfPrimaryAdjElectronsPerEventCmd->GetNewIntValue(newValue));
403 }
404}
@ 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()
Definition: G4RunManager.cc:84
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:146
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:273
void SetDefaultValue(const char *theDefaultValue)
void SetParameterRange(const char *theRange)
static G4double GetValueOf(const G4String &)