Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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);
87  verbCmd->SetDefaultValue(0);
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);
147  rcsCmd->SetDefaultValue(0);
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);
162  errCmd->SetDefaultValue(1);
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
193 G4GeometryMessenger::Init()
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 );
229  tvolume->SetTolerance(tol);
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();
247  tvolume->SetErrorsThreshold(errCmd->GetNewIntValue( newValues ));
248  }
249  else if (command == recCmd) {
250  Init();
251  G4cout << "Running geometry overlaps check..." << G4endl;
252  RecursiveOverlapTest();
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
274 G4GeometryMessenger::CheckGeometry()
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
289 G4GeometryMessenger::ResetNavigator()
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
306 G4GeometryMessenger::SetVerbosity(G4String input)
307 {
308  G4int level = verbCmd->GetNewIntValue(input);
309  G4Navigator* navigator = tmanager->GetNavigatorForTracking();
310  navigator->SetVerboseLevel(level);
311 }
312 
313 //
314 // Set navigator mode
315 //
316 void
317 G4GeometryMessenger::SetCheckMode(G4String input)
318 {
319  G4bool mode = chkCmd->GetNewBoolValue(input);
320  G4Navigator* navigator = tmanager->GetNavigatorForTracking();
321  navigator->CheckMode(mode);
322 }
323 
324 //
325 // Set navigator verbosity for push notifications
326 //
327 void
328 G4GeometryMessenger::SetPushFlag(G4String input)
329 {
330  G4bool mode = pchkCmd->GetNewBoolValue(input);
331  G4Navigator* navigator = tmanager->GetNavigatorForTracking();
332  navigator->SetPushVerbosity(mode);
333 }
334 
335 //
336 // Recursive Overlap Test
337 //
338 void
339 G4GeometryMessenger::RecursiveOverlapTest()
340 {
341  // Close geometry if necessary
342  //
343  CheckGeometry();
344 
345  // Make test on single line supplied by user recursively
346  //
347  tvolume->TestRecursiveOverlap( recLevel, recDepth );
348 }
void SetNewValue(G4UIcommand *command, G4String newValues)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void TestRecursiveOverlap(G4int sLevel=0, G4int depth=-1)
void SetResolution(G4int points)
void SetVerbosity(G4bool verbosity)
static G4int GetNewIntValue(const char *paramString)
G4Navigator * GetNavigatorForTracking() const
void SetTolerance(G4double tolerance)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:372
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)
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
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:240
tuple navigator
Definition: write_gdml.py:35
static G4GeometryManager * GetInstance()
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:125
void SetPushVerbosity(G4bool mode)
#define G4endl
Definition: G4ios.hh:61
void SetErrorsThreshold(G4int max)
void OpenGeometry(G4VPhysicalVolume *vol=0)
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)