Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4GeometryMessenger.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// class G4GeometryMessenger implementation
27//
28// Author: G.Cosmo, CERN
29// --------------------------------------------------------------------
30
31#include <iomanip>
32
34
36#include "G4GeometryManager.hh"
37#include "G4VPhysicalVolume.hh"
38#include "G4Navigator.hh"
40
41#include "G4UIdirectory.hh"
42#include "G4UIcommand.hh"
44#include "G4UIcmdWithABool.hh"
47
48#include "G4GeomTestVolume.hh"
49
50//
51// Constructor
52//
54 : tmanager(tman)
55{
56 geodir = new G4UIdirectory( "/geometry/" );
57 geodir->SetGuidance( "Geometry control commands." );
58
59 //
60 // Geometry navigator commands
61 //
62 navdir = new G4UIdirectory( "/geometry/navigator/" );
63 navdir->SetGuidance( "Geometry navigator control setup." );
64
65 resCmd = new G4UIcmdWithoutParameter( "/geometry/navigator/reset", this );
66 resCmd->SetGuidance( "Reset navigator and navigation history." );
67 resCmd->SetGuidance( "NOTE: must be called only after kernel has been" );
68 resCmd->SetGuidance( " initialized once through the run manager!" );
70
71 verbCmd = new G4UIcmdWithAnInteger( "/geometry/navigator/verbose", this );
72 verbCmd->SetGuidance( "Set run-time verbosity for the navigator." );
73 verbCmd->SetGuidance(" 0 : Silent (default)");
74 verbCmd->SetGuidance(" 1 : Display volume positioning and step lengths");
75 verbCmd->SetGuidance(" 2 : Display step/safety info on point location");
76 verbCmd->SetGuidance(" 3 : Display minimal state at -every- step");
77 verbCmd->SetGuidance(" 4 : Maximum verbosity (very detailed!)");
78 verbCmd->SetGuidance( "NOTE: this command has effect -only- if Geant4 has" );
79 verbCmd->SetGuidance( " been installed with the G4VERBOSE flag set!" );
80 verbCmd->SetParameterName("level",true);
81 verbCmd->SetDefaultValue(0);
82 verbCmd->SetRange("level >=0 && level <=4");
83
84 chkCmd = new G4UIcmdWithABool( "/geometry/navigator/check_mode", this );
85 chkCmd->SetGuidance( "Set navigator in -check_mode- state." );
86 chkCmd->SetGuidance( "This will cause extra checks to be applied during" );
87 chkCmd->SetGuidance( "navigation. More strict and less tolerant conditions" );
88 chkCmd->SetGuidance( "are applied. A run-time performance penalty may be" );
89 chkCmd->SetGuidance( "observed when the -check_mode- state is activated." );
90 chkCmd->SetGuidance( "NOTE: this command has effect -only- if Geant4 has" );
91 chkCmd->SetGuidance( " been installed with the G4VERBOSE flag set!" );
92 chkCmd->SetParameterName("checkFlag",true);
93 chkCmd->SetDefaultValue(false);
95
96 pchkCmd = new G4UIcmdWithABool( "/geometry/navigator/push_notify", this );
97 pchkCmd->SetGuidance( "Set navigator verbosity push notifications." );
98 pchkCmd->SetGuidance( "This allows one to disable/re-enable verbosity in" );
99 pchkCmd->SetGuidance( "navigation, when tracks may get stuck and require" );
100 pchkCmd->SetGuidance( "one artificial push along the direction by the" );
101 pchkCmd->SetGuidance( "navigator. Notification is active by default." );
102 pchkCmd->SetGuidance( "NOTE: this command has effect -only- if Geant4 has" );
103 pchkCmd->SetGuidance( " been installed with the G4VERBOSE flag set!" );
104 pchkCmd->SetParameterName("pushFlag",true);
105 pchkCmd->SetDefaultValue(true);
107
108 //
109 // Geometry verification test commands
110 //
111 testdir = new G4UIdirectory( "/geometry/test/" );
112 testdir->SetGuidance( "Geometry verification control setup." );
113 testdir->SetGuidance( "Helps in detecting possible overlapping regions." );
114
115 tolCmd = new G4UIcmdWithADoubleAndUnit( "/geometry/test/tolerance",this );
116 tolCmd->SetGuidance( "Define tolerance (in mm) by which overlaps reports" );
117 tolCmd->SetGuidance( "should be reported. By default, all overlaps are" );
118 tolCmd->SetGuidance( "reported, i.e. tolerance is set to: 0*mm." );
119 tolCmd->SetParameterName( "Tolerance", true, true );
120 tolCmd->SetDefaultValue( 0 );
121 tolCmd->SetDefaultUnit( "mm" );
122 tolCmd->SetUnitCategory( "Length" );
123
124 verCmd = new G4UIcmdWithABool( "/geometry/test/verbosity", this );
125 verCmd->SetGuidance( "Specify if running in verbosity mode or not." );
126 verCmd->SetGuidance( "By default verbosity is set to ON (TRUE)." );
127 verCmd->SetParameterName("verbosity",true);
128 verCmd->SetDefaultValue(true);
130
131 rslCmd = new G4UIcmdWithAnInteger( "/geometry/test/resolution", this );
132 rslCmd->SetGuidance( "Set the number of points on surface to be generated for" );
133 rslCmd->SetGuidance( "checking overlaps." );
134 rslCmd->SetParameterName("resolution",true);
135 rslCmd->SetDefaultValue(10000);
136
137 rcsCmd = new G4UIcmdWithAnInteger( "/geometry/test/recursion_start", this );
138 rcsCmd->SetGuidance( "Set the initial level in the geometry tree for recursion." );
139 rcsCmd->SetGuidance( "recursive_test will then start from the specified level." );
140 rcsCmd->SetParameterName("initial_level",true);
141 rcsCmd->SetDefaultValue(0);
142
143 rcdCmd = new G4UIcmdWithAnInteger( "/geometry/test/recursion_depth", this );
144 rcdCmd->SetGuidance( "Set the depth in the geometry tree for recursion." );
145 rcdCmd->SetGuidance( "recursive_test will then stop after reached the specified depth." );
146 rcdCmd->SetGuidance( "By default, recursion will proceed for the whole depth." );
147 rcdCmd->SetParameterName("recursion_depth",true);
148 rcdCmd->SetDefaultValue(-1);
149
150 errCmd = new G4UIcmdWithAnInteger( "/geometry/test/maximum_errors", this );
151 errCmd->SetGuidance( "Set the maximum number of overlap errors to report" );
152 errCmd->SetGuidance( "for each single volume being checked." );
153 errCmd->SetGuidance( "Once reached the maximum number specified, overlaps" );
154 errCmd->SetGuidance( "affecting that volume further than that are simply ignored." );
155 errCmd->SetParameterName("maximum_errors",true);
156 errCmd->SetDefaultValue(1);
157
158 parCmd = new G4UIcmdWithABool( "/geometry/test/check_parallel", this );
159 parCmd->SetGuidance( "Check for overlaps in parallel worlds." );
160 parCmd->SetGuidance( "By default, overlaps are only checked in the mass world (FALSE)." );
161 parCmd->SetParameterName("check_parallel",true);
162 parCmd->SetDefaultValue(true);
163
164 recCmd = new G4UIcmdWithoutParameter( "/geometry/test/run", this );
165 recCmd->SetGuidance( "Start running the recursive overlap check." );
166 recCmd->SetGuidance( "Volumes are recursively asked to verify for overlaps" );
167 recCmd->SetGuidance( "for points generated on the surface against their" );
168 recCmd->SetGuidance( "respective mother volume and sisters at the same" );
169 recCmd->SetGuidance( "level, performing for all daughters and daughters of" );
170 recCmd->SetGuidance( "daughters, etc." );
171 recCmd->SetGuidance( "NOTE: it may take a very long time," );
172 recCmd->SetGuidance( " depending on the geometry complexity !");
174}
175
176//
177// Destructor
178//
180{
181 delete verCmd; delete recCmd; delete rslCmd;
182 delete resCmd; delete rcsCmd; delete rcdCmd; delete errCmd;
183 delete tolCmd;
184 delete verbCmd; delete pchkCmd; delete chkCmd;
185 delete geodir; delete navdir; delete testdir;
186 for(auto* tvolume: tvolumes) {
187 delete tvolume;
188 }
189}
190
191//
192// Init
193//
194void
195G4GeometryMessenger::Init()
196{
197 // Create checker...
198 //
199 if (tvolumes.empty())
200 {
201 // Get all world volumes
202 //
203 const auto noWorlds = tmanager->GetNoWorlds();
204 const auto fWorld = tmanager->GetWorldsIterator();
205 for(size_t i=0;i<noWorlds;++i)
206 {
207 // Test the actual detector...
208 //
209 tvolumes.push_back(new G4GeomTestVolume(fWorld[i]));
210 }
211 }
212}
213
214//
215// SetNewValue
216//
217void
219{
220 if (command == resCmd) {
221 ResetNavigator();
222 }
223 else if (command == verbCmd) {
224 SetVerbosity( newValues );
225 }
226 else if (command == chkCmd) {
227 SetCheckMode( newValues );
228 }
229 else if (command == pchkCmd) {
230 SetPushFlag( newValues );
231 }
232 else if (command == tolCmd) {
233 Init();
234 tol = tolCmd->GetNewDoubleValue( newValues )
235 * tolCmd->GetNewUnitValue( newValues );
236 for(auto* tvolume: tvolumes)
237 {
238 tvolume->SetTolerance(tol);
239 }
240 }
241 else if (command == verCmd) {
242 Init();
243 for(auto* tvolume: tvolumes)
244 {
245 tvolume->SetVerbosity(verCmd->GetNewBoolValue( newValues ));
246 }
247 }
248 else if (command == rslCmd) {
249 Init();
250 for(auto* tvolume: tvolumes)
251 {
252 tvolume->SetResolution(rslCmd->GetNewIntValue( newValues ));
253 }
254 }
255 else if (command == rcsCmd) {
256 recLevel = rcsCmd->GetNewIntValue( newValues );
257 }
258 else if (command == rcdCmd) {
259 recDepth = rcdCmd->GetNewIntValue( newValues );
260 }
261 else if (command == errCmd) {
262 Init();
263 for(auto* tvolume: tvolumes)
264 {
265 tvolume->SetErrorsThreshold(errCmd->GetNewIntValue( newValues ));
266 }
267 }
268 else if (command == recCmd) {
269 Init();
270 G4cout << "Running geometry overlaps check..." << G4endl;
271 RecursiveOverlapTest();
272 G4cout << "Geometry overlaps check completed !" << G4endl;
273 }
274}
275
276//
277// GetCurrentValue
278//
281{
282 G4String cv = "";
283 if (command == tolCmd)
284 {
285 cv = tolCmd->ConvertToString( tol, "mm" );
286 }
287 return cv;
288}
289
290//
291// CheckGeometry
292//
293void
294G4GeometryMessenger::CheckGeometry()
295{
296 // Verify that the geometry is closed
297 //
299 if (!geomManager->IsGeometryClosed())
300 {
301 geomManager->OpenGeometry();
302 geomManager->CloseGeometry(true);
303 }
304}
305
306//
307// ResetNavigator
308//
309void
310G4GeometryMessenger::ResetNavigator()
311{
312 // Close geometry and reset optimisation if necessary
313 //
314 CheckGeometry();
315
316 // Reset navigator's state
317 //
318 G4ThreeVector pt(0,0,0);
319 G4Navigator* navigator = tmanager->GetNavigatorForTracking();
320 navigator->LocateGlobalPointAndSetup(pt,0,false);
321}
322
323//
324// Set navigator verbosity
325//
326void
327G4GeometryMessenger::SetVerbosity(G4String input)
328{
329 G4int level = verbCmd->GetNewIntValue(input);
330 G4Navigator* navigator = tmanager->GetNavigatorForTracking();
331 navigator->SetVerboseLevel(level);
332}
333
334//
335// Set navigator mode
336//
337void
338G4GeometryMessenger::SetCheckMode(G4String input)
339{
340 G4bool mode = chkCmd->GetNewBoolValue(input);
341 G4Navigator* navigator = tmanager->GetNavigatorForTracking();
342 navigator->CheckMode(mode);
343 G4PropagatorInField* pField = tmanager->GetPropagatorInField();
344 if (pField != nullptr) { pField->CheckMode(mode); }
345}
346
347//
348// Set navigator verbosity for push notifications
349//
350void
351G4GeometryMessenger::SetPushFlag(G4String input)
352{
353 G4bool mode = pchkCmd->GetNewBoolValue(input);
354 G4Navigator* navigator = tmanager->GetNavigatorForTracking();
355 navigator->SetPushVerbosity(mode);
356}
357
358//
359// Recursive Overlap Test
360//
361void
362G4GeometryMessenger::RecursiveOverlapTest()
363{
364 // Close geometry if necessary
365 //
366 CheckGeometry();
367
368 // Make test on single line supplied by user recursively
369 //
370 if (checkParallelWorlds)
371 {
372 for(auto* tvolume: tvolumes)
373 {
374 tvolume->TestRecursiveOverlap( recLevel, recDepth );
375 }
376 }
377 else
378 {
379 tvolumes.front()->TestRecursiveOverlap( recLevel, recDepth );
380 }
381}
@ G4State_Idle
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4bool IsGeometryClosed()
static G4GeometryManager * GetInstance()
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=nullptr)
void OpenGeometry(G4VPhysicalVolume *vol=nullptr)
void SetNewValue(G4UIcommand *command, G4String newValues)
G4String GetCurrentValue(G4UIcommand *command)
G4GeometryMessenger(G4TransportationManager *tman)
void SetVerboseLevel(G4int level)
void SetPushVerbosity(G4bool mode)
void CheckMode(G4bool mode)
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=nullptr, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
Definition: G4Navigator.cc:132
void CheckMode(G4bool mode)
G4PropagatorInField * GetPropagatorInField() const
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
G4Navigator * GetNavigatorForTracking() const
std::size_t GetNoWorlds() const
static G4bool GetNewBoolValue(const char *paramString)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(G4bool defVal)
void SetUnitCategory(const char *unitCategory)
static G4double GetNewUnitValue(const char *paramString)
void SetDefaultUnit(const char *defUnit)
static G4double GetNewDoubleValue(const char *paramString)
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 SetDefaultValue(G4int defVal)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:446
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:157
void SetRange(const char *rs)
Definition: G4UIcommand.hh:121
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:287