Geant4  10.00.p01
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 //
27 // $Id: G4GeometryMessenger.cc 73253 2013-08-22 13:24:02Z gcosmo $
28 //
29 // --------------------------------------------------------------------
30 // GEANT 4 class source file
31 //
32 // G4GeometryMessenger
33 //
34 // Author: G.Cosmo, CERN.
35 //
36 // --------------------------------------------------------------------
37 
38 #include <iomanip>
39 
40 #include "G4GeometryMessenger.hh"
41 
43 #include "G4GeometryManager.hh"
44 #include "G4VPhysicalVolume.hh"
45 #include "G4Navigator.hh"
46 
47 #include "G4UIdirectory.hh"
48 #include "G4UIcommand.hh"
50 #include "G4UIcmdWithABool.hh"
51 #include "G4UIcmdWithAnInteger.hh"
53 
54 #include "G4GeomTestVolume.hh"
55 
56 //
57 // Constructor
58 //
60  : tol(0.0), recLevel(0), recDepth(-1), tmanager(tman), tvolume(0)
61 {
62  geodir = new G4UIdirectory( "/geometry/" );
63  geodir->SetGuidance( "Geometry control commands." );
64 
65  //
66  // Geometry navigator commands
67  //
68  navdir = new G4UIdirectory( "/geometry/navigator/" );
69  navdir->SetGuidance( "Geometry navigator control setup." );
70 
71  resCmd = new G4UIcmdWithoutParameter( "/geometry/navigator/reset", this );
72  resCmd->SetGuidance( "Reset navigator and navigation history." );
73  resCmd->SetGuidance( "NOTE: must be called only after kernel has been" );
74  resCmd->SetGuidance( " initialized once through the run manager!" );
76 
77  verbCmd = new G4UIcmdWithAnInteger( "/geometry/navigator/verbose", this );
78  verbCmd->SetGuidance( "Set run-time verbosity for the navigator." );
79  verbCmd->SetGuidance(" 0 : Silent (default)");
80  verbCmd->SetGuidance(" 1 : Display volume positioning and step lengths");
81  verbCmd->SetGuidance(" 2 : Display step/safety info on point location");
82  verbCmd->SetGuidance(" 3 : Display minimal state at -every- step");
83  verbCmd->SetGuidance(" 4 : Maximum verbosity (very detailed!)");
84  verbCmd->SetGuidance( "NOTE: this command has effect -only- if Geant4 has" );
85  verbCmd->SetGuidance( " been installed with the G4VERBOSE flag set!" );
86  verbCmd->SetParameterName("level",true);
88  verbCmd->SetRange("level >=0 && level <=4");
89 
90  chkCmd = new G4UIcmdWithABool( "/geometry/navigator/check_mode", this );
91  chkCmd->SetGuidance( "Set navigator in -check_mode- state." );
92  chkCmd->SetGuidance( "This will cause extra checks to be applied during" );
93  chkCmd->SetGuidance( "navigation. More strict and less tolerant conditions" );
94  chkCmd->SetGuidance( "are applied. A run-time performance penalty may be" );
95  chkCmd->SetGuidance( "observed when the -check_mode- state is activated." );
96  chkCmd->SetGuidance( "NOTE: this command has effect -only- if Geant4 has" );
97  chkCmd->SetGuidance( " been installed with the G4VERBOSE flag set!" );
98  chkCmd->SetParameterName("checkFlag",true);
99  chkCmd->SetDefaultValue(false);
101 
102  pchkCmd = new G4UIcmdWithABool( "/geometry/navigator/push_notify", this );
103  pchkCmd->SetGuidance( "Set navigator verbosity push notifications." );
104  pchkCmd->SetGuidance( "This allows to disable/re-enable verbosity in" );
105  pchkCmd->SetGuidance( "navigation, when tracks may get stuck and require" );
106  pchkCmd->SetGuidance( "one artificial push along the direction by the" );
107  pchkCmd->SetGuidance( "navigator. Notification is active by default." );
108  pchkCmd->SetGuidance( "NOTE: this command has effect -only- if Geant4 has" );
109  pchkCmd->SetGuidance( " been installed with the G4VERBOSE flag set!" );
110  pchkCmd->SetParameterName("pushFlag",true);
111  pchkCmd->SetDefaultValue(true);
113 
114  //
115  // Geometry verification test commands
116  //
117  testdir = new G4UIdirectory( "/geometry/test/" );
118  testdir->SetGuidance( "Geometry verification control setup." );
119  testdir->SetGuidance( "Helps in detecting possible overlapping regions." );
120 
121  tolCmd = new G4UIcmdWithADoubleAndUnit( "/geometry/test/tolerance",this );
122  tolCmd->SetGuidance( "Define tolerance (in mm) by which overlaps reports" );
123  tolCmd->SetGuidance( "should be reported. By default, all overlaps are" );
124  tolCmd->SetGuidance( "reported, i.e. tolerance is set to: 0*mm." );
125  tolCmd->SetParameterName( "Tolerance", true, true );
126  tolCmd->SetDefaultValue( 0 );
127  tolCmd->SetDefaultUnit( "mm" );
128  tolCmd->SetUnitCategory( "Length" );
129 
130  verCmd = new G4UIcmdWithABool( "/geometry/test/verbosity", this );
131  verCmd->SetGuidance( "Specify if running in verbosity mode or not." );
132  verCmd->SetGuidance( "By default verbosity is set to ON (TRUE)." );
133  verCmd->SetParameterName("verbosity",true);
134  verCmd->SetDefaultValue(true);
136 
137  rslCmd = new G4UIcmdWithAnInteger( "/geometry/test/resolution", this );
138  rslCmd->SetGuidance( "Set the number of points on surface to be generated for" );
139  rslCmd->SetGuidance( "checking overlaps." );
140  rslCmd->SetParameterName("resolution",true);
141  rslCmd->SetDefaultValue(10000);
142 
143  rcsCmd = new G4UIcmdWithAnInteger( "/geometry/test/recursion_start", this );
144  rcsCmd->SetGuidance( "Set the initial level in the geometry tree for recursion." );
145  rcsCmd->SetGuidance( "recursive_test will then start from the specified level." );
146  rcsCmd->SetParameterName("initial_level",true);
148 
149  rcdCmd = new G4UIcmdWithAnInteger( "/geometry/test/recursion_depth", this );
150  rcdCmd->SetGuidance( "Set the depth in the geometry tree for recursion." );
151  rcdCmd->SetGuidance( "recursive_test will then stop after reached the specified depth." );
152  rcdCmd->SetGuidance( "By default, recursion will proceed for the whole depth." );
153  rcdCmd->SetParameterName("recursion_depth",true);
154  rcdCmd->SetDefaultValue(-1);
155 
156  errCmd = new G4UIcmdWithAnInteger( "/geometry/test/maximum_errors", this );
157  errCmd->SetGuidance( "Set the maximum number of overlap errors to report" );
158  errCmd->SetGuidance( "for each single volume being checked." );
159  errCmd->SetGuidance( "Once reached the maximum number specified, overlaps" );
160  errCmd->SetGuidance( "affecting that volume further than that are simply ignored." );
161  errCmd->SetParameterName("maximum_errors",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  delete tvolume;
187 }
188 
189 //
190 // Init
191 //
192 void
194 {
195  // Create checker...
196  //
197  if (!tvolume)
198  {
199  // Get the world volume
200  //
201  G4VPhysicalVolume* world =
203 
204  // Test the actual detector...
205  //
206  tvolume = new G4GeomTestVolume(world);
207  }
208 }
209 
210 //
211 // SetNewValue
212 //
213 void
215 {
216  if (command == resCmd) {
217  ResetNavigator();
218  }
219  else if (command == verbCmd) {
220  SetVerbosity( newValues );
221  }
222  else if (command == chkCmd) {
223  SetCheckMode( newValues );
224  }
225  else if (command == tolCmd) {
226  Init();
227  tol = tolCmd->GetNewDoubleValue( newValues )
228  * tolCmd->GetNewUnitValue( newValues );
230  }
231  else if (command == verCmd) {
232  Init();
233  tvolume->SetVerbosity(verCmd->GetNewBoolValue( newValues ));
234  }
235  else if (command == rslCmd) {
236  Init();
237  tvolume->SetResolution(rslCmd->GetNewIntValue( newValues ));
238  }
239  else if (command == rcsCmd) {
240  recLevel = rcsCmd->GetNewIntValue( newValues );
241  }
242  else if (command == rcdCmd) {
243  recDepth = rcdCmd->GetNewIntValue( newValues );
244  }
245  else if (command == errCmd) {
246  Init();
248  }
249  else if (command == recCmd) {
250  Init();
251  G4cout << "Running geometry overlaps check..." << G4endl;
253  G4cout << "Geometry overlaps check completed !" << G4endl;
254  }
255 }
256 
257 //
258 // GetCurrentValue
259 //
260 G4String
262 {
263  G4String cv = "";
264  if (command == tolCmd) {
265  cv = tolCmd->ConvertToString( tol, "mm" );
266  }
267  return cv;
268 }
269 
270 //
271 // CheckGeometry
272 //
273 void
275 {
276  // Verify that the geometry is closed
277  //
279  if (!geomManager->IsGeometryClosed()) {
280  geomManager->OpenGeometry();
281  geomManager->CloseGeometry(true);
282  }
283 }
284 
285 //
286 // ResetNavigator
287 //
288 void
290 {
291  // Close geometry and reset optimisation if necessary
292  //
293  CheckGeometry();
294 
295  // Reset navigator's state
296  //
297  G4ThreeVector pt(0,0,0);
299  navigator->LocateGlobalPointAndSetup(pt,0,false);
300 }
301 
302 //
303 // Set navigator verbosity
304 //
305 void
307 {
308  G4int level = verbCmd->GetNewIntValue(input);
310  navigator->SetVerboseLevel(level);
311 }
312 
313 //
314 // Set navigator mode
315 //
316 void
318 {
319  G4bool mode = chkCmd->GetNewBoolValue(input);
321  navigator->CheckMode(mode);
322 }
323 
324 //
325 // Set navigator verbosity for push notifications
326 //
327 void
329 {
330  G4bool mode = pchkCmd->GetNewBoolValue(input);
332  navigator->SetPushVerbosity(mode);
333 }
334 
335 //
336 // Recursive Overlap Test
337 //
338 void
340 {
341  // Close geometry if necessary
342  //
343  CheckGeometry();
344 
345  // Make test on single line supplied by user recursively
346  //
348 }
void SetNewValue(G4UIcommand *command, G4String newValues)
void SetCheckMode(G4String newValue)
void SetVerbosity(G4String newValue)
G4UIcmdWithAnInteger * errCmd
void SetPushFlag(G4String newValue)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
CLHEP::Hep3Vector G4ThreeVector
void TestRecursiveOverlap(G4int sLevel=0, G4int depth=-1)
G4UIcmdWithADoubleAndUnit * tolCmd
void SetResolution(G4int points)
void SetVerbosity(G4bool verbosity)
static G4int GetNewIntValue(const char *paramString)
G4UIcmdWithAnInteger * verbCmd
G4Navigator * GetNavigatorForTracking() const
void SetTolerance(G4double tolerance)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:357
void SetUnitCategory(const char *unitCategory)
static G4double GetNewDoubleValue(const char *paramString)
int G4int
Definition: G4Types.hh:78
static G4bool GetNewBoolValue(const char *paramString)
void SetVerboseLevel(G4int level)
void SetDefaultValue(G4bool defVal)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4UIcmdWithAnInteger * rcsCmd
G4GLOB_DLL std::ostream G4cout
G4UIcmdWithoutParameter * resCmd
G4UIcmdWithABool * verCmd
bool G4bool
Definition: G4Types.hh:79
G4TransportationManager * tmanager
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:225
static G4GeometryManager * GetInstance()
G4UIcmdWithABool * pchkCmd
G4UIcmdWithAnInteger * rcdCmd
G4UIcmdWithoutParameter * recCmd
void SetDefaultUnit(const char *defUnit)
G4String GetCurrentValue(G4UIcommand *command)
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=0, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
Definition: G4Navigator.cc:118
void SetPushVerbosity(G4bool mode)
#define G4endl
Definition: G4ios.hh:61
void SetErrorsThreshold(G4int max)
void OpenGeometry(G4VPhysicalVolume *vol=0)
G4UIcmdWithAnInteger * rslCmd
void SetDefaultValue(G4int defVal)
void CheckMode(G4bool mode)
G4GeometryMessenger(G4TransportationManager *tman)
G4VPhysicalVolume * GetWorldVolume() const
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=0)
static G4double GetNewUnitValue(const char *paramString)
G4GeomTestVolume * tvolume
G4UIcmdWithABool * chkCmd