source: trunk/source/geometry/navigation/src/G4GeometryMessenger.cc@ 1349

Last change on this file since 1349 was 1347, checked in by garnier, 15 years ago

geant4 tag 9.4

File size: 20.1 KB
RevLine 
[831]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//
[1347]27// $Id: G4GeometryMessenger.cc,v 1.6 2010/11/10 14:06:40 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-04-ref-00 $
[831]29//
30// --------------------------------------------------------------------
31// GEANT 4 class source file
32//
33// G4GeometryMessenger
34//
35// Author: G.Cosmo, CERN.
36//
37// --------------------------------------------------------------------
38
39#include <iomanip>
40#include "G4GeometryMessenger.hh"
41
42#include "G4TransportationManager.hh"
43#include "G4GeometryManager.hh"
44#include "G4VPhysicalVolume.hh"
45#include "G4Navigator.hh"
46
47#include "G4UIdirectory.hh"
48#include "G4UIcommand.hh"
49#include "G4UIcmdWith3VectorAndUnit.hh"
50#include "G4UIcmdWith3Vector.hh"
51#include "G4UIcmdWithoutParameter.hh"
52#include "G4UIcmdWithABool.hh"
53#include "G4UIcmdWithAnInteger.hh"
54#include "G4UIcmdWithADouble.hh"
55#include "G4UIcmdWithADoubleAndUnit.hh"
56
57#include "G4GeomTestStreamLogger.hh"
58#include "G4GeomTestVolume.hh"
59
60//
61// Constructor
62//
63G4GeometryMessenger::G4GeometryMessenger(G4TransportationManager* tman)
64 : x(0,0,0), p(0,0,1), grdRes(100,100,100), cylRes(90,50,50),
65 cylfZ(0.8), cylfR(0.8), newtol(false), tol(1E-4*mm),
66 recLevel(0), recDepth(-1), tmanager(tman), tlogger(0), tvolume(0)
67{
68 geodir = new G4UIdirectory( "/geometry/" );
69 geodir->SetGuidance( "Geometry control commands." );
70
71 //
72 // Geometry navigator commands
73 //
74 navdir = new G4UIdirectory( "/geometry/navigator/" );
75 navdir->SetGuidance( "Geometry navigator control setup." );
76
77 resCmd = new G4UIcmdWithoutParameter( "/geometry/navigator/reset", this );
78 resCmd->SetGuidance( "Reset navigator and navigation history." );
79 resCmd->SetGuidance( "NOTE: must be called only after kernel has been" );
80 resCmd->SetGuidance( " initialized once through the run manager!" );
81 resCmd->AvailableForStates(G4State_Idle);
82
83 verbCmd = new G4UIcmdWithAnInteger( "/geometry/navigator/verbose", this );
84 verbCmd->SetGuidance( "Set run-time verbosity for the navigator." );
85 verbCmd->SetGuidance(" 0 : Silent (default)");
86 verbCmd->SetGuidance(" 1 : Display volume positioning and step lengths");
87 verbCmd->SetGuidance(" 2 : Display step/safety info on point location");
88 verbCmd->SetGuidance(" 3 : Display minimal state at -every- step");
89 verbCmd->SetGuidance(" 4 : Maximum verbosity (very detailed!)");
90 verbCmd->SetGuidance( "NOTE: this command has effect -only- if Geant4 has" );
91 verbCmd->SetGuidance( " been installed with the G4VERBOSE flag set!" );
92 verbCmd->SetParameterName("level",true);
93 verbCmd->SetDefaultValue(0);
94 verbCmd->SetRange("level >=0 && level <=4");
95
96 chkCmd = new G4UIcmdWithABool( "/geometry/navigator/check_mode", this );
97 chkCmd->SetGuidance( "Set navigator in -check_mode- state." );
98 chkCmd->SetGuidance( "This will cause extra checks to be applied during" );
99 chkCmd->SetGuidance( "navigation. More strict and less tolerant conditions" );
100 chkCmd->SetGuidance( "are applied. A run-time performance penalty may be" );
101 chkCmd->SetGuidance( "observed when the -check_mode- state is activated." );
102 chkCmd->SetGuidance( "NOTE: this command has effect -only- if Geant4 has" );
103 chkCmd->SetGuidance( " been installed with the G4VERBOSE flag set!" );
104 chkCmd->SetParameterName("checkFlag",true);
105 chkCmd->SetDefaultValue(false);
106 chkCmd->AvailableForStates(G4State_Idle);
107
[1347]108 pchkCmd = new G4UIcmdWithABool( "/geometry/navigator/push_notify", this );
109 pchkCmd->SetGuidance( "Set navigator verbosity push notifications." );
110 pchkCmd->SetGuidance( "This allows to disable/re-enable verbosity in" );
111 pchkCmd->SetGuidance( "navigation, when tracks may get stuck and require" );
112 pchkCmd->SetGuidance( "one artificial push along the direction by the" );
113 pchkCmd->SetGuidance( "navigator. Notification is active by default." );
114 pchkCmd->SetGuidance( "NOTE: this command has effect -only- if Geant4 has" );
115 pchkCmd->SetGuidance( " been installed with the G4VERBOSE flag set!" );
116 pchkCmd->SetParameterName("pushFlag",true);
117 pchkCmd->SetDefaultValue(true);
118 pchkCmd->AvailableForStates(G4State_Idle);
119
[831]120 //
121 // Geometry verification test commands
122 //
123 testdir = new G4UIdirectory( "/geometry/test/" );
124 testdir->SetGuidance( "Geometry verification control setup." );
125 testdir->SetGuidance( "Helps in detecting possible overlapping regions." );
126
127 tolCmd = new G4UIcmdWithADoubleAndUnit( "/geometry/test/tolerance",this );
128 tolCmd->SetGuidance( "Set error tolerance value." );
129 tolCmd->SetGuidance( "Initial default value: 1E-4*mm." );
130 tolCmd->SetParameterName( "Tolerance", true, true );
131 tolCmd->SetDefaultValue( 1E-4 );
132 tolCmd->SetDefaultUnit( "mm" );
133 tolCmd->SetUnitCategory( "Length" );
134
135 posCmd = new G4UIcmdWith3VectorAndUnit( "/geometry/test/position", this );
136 posCmd->SetGuidance( "Set starting position for the line_test." );
137 posCmd->SetParameterName( "X", "Y", "Z", true, true );
138 posCmd->SetDefaultUnit( "cm" );
139
140 dirCmd = new G4UIcmdWith3VectorAndUnit( "/geometry/test/direction", this );
141 dirCmd->SetGuidance( "Set momentum direction for the line_test." );
142 dirCmd->SetGuidance( "Direction needs not to be a unit vector." );
143 dirCmd->SetParameterName( "Px", "Py", "Pz", true, true );
144 dirCmd->SetRange( "Px != 0 || Py != 0 || Pz != 0" );
145
146 linCmd = new G4UIcmdWithABool( "/geometry/test/line_test", this );
147 linCmd->SetGuidance( "Performs test along a single specified direction/position." );
148 linCmd->SetGuidance( "Use position and direction commands to change default." );
149 linCmd->SetGuidance( "Initial default: position(0,0,0), direction(0,0,1)." );
150 linCmd->SetGuidance( "If recursion flag is set to TRUE, the intersection checks" );
151 linCmd->SetGuidance( "will be performed recursively in the geometry tree." );
152 linCmd->SetParameterName("recursionFlag",true);
153 linCmd->SetDefaultValue(false);
154 linCmd->AvailableForStates(G4State_Idle);
155
156 grzCmd = new G4UIcmdWith3Vector( "/geometry/test/grid_cells", this );
157 grzCmd->SetGuidance( "Define resolution of grid geometry as number of cells," );
158 grzCmd->SetGuidance( "specifying them for each dimension, X, Y and Z." );
159 grzCmd->SetGuidance( "Will be applied to grid_test and recursive_test commands." );
160 grzCmd->SetGuidance( "Initial default values: X=100, Y=100, Z=100." );
161 grzCmd->SetParameterName( "X", "Y", "Z", true, true );
162 grzCmd->SetDefaultValue( G4ThreeVector(100, 100, 100) );
163
164 grdCmd = new G4UIcmdWithABool( "/geometry/test/grid_test", this );
165 grdCmd->SetGuidance( "Start running the default grid test." );
166 grdCmd->SetGuidance( "A grid of lines parallel to a cartesian axis is used;" );
167 grdCmd->SetGuidance( "By default, only direct daughters of the mother volumes are checked." );
168 grdCmd->SetGuidance( "If recursion flag is set to TRUE, the intersection checks" );
169 grdCmd->SetGuidance( "will be performed recursively in the geometry tree." );
170 grdCmd->SetGuidance( "NOTE: the recursion may take a very long time," );
171 grdCmd->SetGuidance( " depending on the geometry complexity !");
172 grdCmd->SetParameterName("recursionFlag",true);
173 grdCmd->SetDefaultValue(false);
174 grdCmd->AvailableForStates(G4State_Idle);
175
176 cyzCmd = new G4UIcmdWith3Vector( "/geometry/test/cylinder_geometry", this );
177 cyzCmd->SetGuidance( "Define details of the cylinder geometry, specifying:" );
178 cyzCmd->SetGuidance( " nPhi - number of lines per Phi" );
179 cyzCmd->SetGuidance( " nZ - number of Z points" );
180 cyzCmd->SetGuidance( " nRho - number of Rho points" );
181 cyzCmd->SetGuidance( "Will be applied to the cylinder_test command." );
182 cyzCmd->SetGuidance( "Initial default values: nPhi=90, nZ=50, nRho=50." );
183 cyzCmd->SetParameterName( "nPhi", "nZ", "nRho", true, true );
184 cyzCmd->SetDefaultValue( G4ThreeVector(90, 50, 50) );
185
186 cfzCmd = new G4UIcmdWithADouble( "/geometry/test/cylinder_scaleZ", this );
187 cfzCmd->SetGuidance( "Define the resolution of the cylinder geometry, specifying" );
188 cfzCmd->SetGuidance( "the fraction scale for points along Z." );
189 cfzCmd->SetGuidance( "Initial default values: fracZ=0.8" );
190 cfzCmd->SetParameterName("fracZ",true);
191 cfzCmd->SetDefaultValue(0.8);
192
193 cfrCmd = new G4UIcmdWithADouble( "/geometry/test/cylinder_scaleRho", this );
194 cfrCmd->SetGuidance( "Define the resolution of the cylinder geometry, specifying" );
195 cfrCmd->SetGuidance( "the fraction scale for points along Rho." );
196 cfrCmd->SetGuidance( "Initial default values: fracRho=0.8" );
197 cfrCmd->SetParameterName("fracRho",true);
198 cfrCmd->SetDefaultValue(0.8);
199
200 cylCmd = new G4UIcmdWithABool( "/geometry/test/cylinder_test", this );
201 cylCmd->SetGuidance( "Start running the cylinder test." );
202 cylCmd->SetGuidance( "A set of lines in a cylindrical pattern of gradually" );
203 cylCmd->SetGuidance( "increasing mesh size." );
204 cylCmd->SetGuidance( "By default, only direct daughters of the mother volumes are checked." );
205 cylCmd->SetGuidance( "If recursion flag is set to TRUE, the intersection checks" );
206 cylCmd->SetGuidance( "will be performed recursively in the geometry tree." );
207 cylCmd->SetGuidance( "NOTE: the recursion may take a very long time," );
208 cylCmd->SetGuidance( " depending on the geometry complexity !");
209 cylCmd->SetParameterName("recursionFlag",true);
210 cylCmd->SetDefaultValue(false);
211 cylCmd->AvailableForStates(G4State_Idle);
212
213 rcsCmd = new G4UIcmdWithAnInteger( "/geometry/test/recursion_start", this );
214 rcsCmd->SetGuidance( "Set the initial level in the geometry tree for recursion." );
215 rcsCmd->SetGuidance( "recursive_test will then start from the specified level." );
216 rcsCmd->SetParameterName("initial_level",true);
217 rcsCmd->SetDefaultValue(0);
218
219 rcdCmd = new G4UIcmdWithAnInteger( "/geometry/test/recursion_depth", this );
220 rcdCmd->SetGuidance( "Set the depth in the geometry tree for recursion." );
221 rcdCmd->SetGuidance( "recursive_test will then stop after reached the specified depth." );
222 rcdCmd->SetGuidance( "By default, recursion will proceed for the whole depth." );
223 rcdCmd->SetParameterName("recursion_depth",true);
224 rcdCmd->SetDefaultValue(-1);
225
226 // Obsolete verification commands ...
227
228 runCmd = new G4UIcmdWithABool( "/geometry/test/run", this );
229 runCmd->SetGuidance( "Start running the default grid test." );
230 runCmd->SetGuidance( "Same as the grid_test command." );
231 runCmd->SetGuidance( "If recursion flag is set to TRUE, the intersection checks" );
232 runCmd->SetGuidance( "will be performed recursively in the geometry tree." );
233 runCmd->SetGuidance( "NOTE: the recursion may take a very long time," );
234 runCmd->SetGuidance( " depending on the geometry complexity !");
235 runCmd->SetParameterName("recursionFlag",true);
236 runCmd->SetDefaultValue(false);
237 runCmd->AvailableForStates(G4State_Idle);
238
239 recCmd = new G4UIcmdWithoutParameter( "/geometry/test/recursive_test", this );
240 recCmd->SetGuidance( "Start running the recursive grid test." );
241 recCmd->SetGuidance( "A grid of lines along a cartesian axis is recursively" );
242 recCmd->SetGuidance( "to all daughters and daughters of daughters, etc." );
243 recCmd->SetGuidance( "NOTE: it may take a very long time," );
244 recCmd->SetGuidance( " depending on the geometry complexity !");
245 recCmd->AvailableForStates(G4State_Idle);
246}
247
248//
249// Destructor
250//
251G4GeometryMessenger::~G4GeometryMessenger()
252{
253 delete linCmd; delete posCmd; delete dirCmd;
254 delete grzCmd; delete grdCmd; delete recCmd; delete runCmd;
255 delete rcsCmd; delete rcdCmd;
256 delete cyzCmd; delete cfzCmd; delete cfrCmd; delete cylCmd;
257 delete tolCmd;
[1347]258 delete resCmd; delete verbCmd; delete pchkCmd; delete chkCmd;
[831]259 delete geodir; delete navdir; delete testdir;
260 delete tvolume; delete tlogger;
261}
262
263//
264// Init
265//
266void
267G4GeometryMessenger::Init()
268{
269 // Clean old allocated loggers...
270 //
271 if (tlogger) delete tlogger;
272 if (tvolume) delete tvolume;
273
274 // Create a logger to send errors/output to cout
275 //
276 tlogger = new G4GeomTestStreamLogger(std::cout);
277
278 // Get the world volume
279 //
280 G4VPhysicalVolume* world =
281 tmanager->GetNavigatorForTracking()->GetWorldVolume();
282
283 // Test the actual detector...
284 //
285 tvolume = new G4GeomTestVolume(world, tlogger);
286}
287
288//
289// SetNewValue
290//
291void
292G4GeometryMessenger::SetNewValue( G4UIcommand* command, G4String newValues )
293{
294 if (command == resCmd) {
295 ResetNavigator();
296 }
297 else if (command == verbCmd) {
298 SetVerbosity( newValues );
299 }
300 else if (command == chkCmd) {
301 SetCheckMode( newValues );
302 }
303 else if (command == posCmd) {
304 x = posCmd->GetNew3VectorValue( newValues );
305 }
306 else if (command == dirCmd) {
307 p = dirCmd->GetNew3VectorValue( newValues );
308 if (p.mag() < DBL_MIN) {
309 G4cerr << "Please specify non-zero momentum!" << G4endl;
310 p = G4ThreeVector(0,0,1);
311 }
312 }
313 else if (command == tolCmd) {
314 tol = tolCmd->GetNewDoubleValue( newValues );
315 newtol = true;
316 }
317 else if (command == linCmd) {
318 Init();
319 if (linCmd->GetNewBoolValue( newValues ))
320 RecursiveLineTest();
321 else
322 LineTest();
323 }
324 else if ((command == grdCmd) || (command == runCmd)){
325 Init();
326 if (grdCmd->GetNewBoolValue( newValues ) || runCmd->GetNewBoolValue( newValues ))
327 RecursiveGridTest();
328 else
329 GridTest();
330 }
331 else if (command == grzCmd) {
332 grdRes = grzCmd->GetNew3VectorValue( newValues );
333 if (grdRes.mag() < DBL_MIN) {
334 G4cerr << "Please specify non-zero resolution!" << G4endl;
335 grdRes = G4ThreeVector(100,100,100);
336 }
337 }
338 else if (command == cyzCmd) {
339 cylRes = cyzCmd->GetNew3VectorValue( newValues );
340 }
341 else if (command == cfzCmd) {
342 cylfZ = cfzCmd->GetNewDoubleValue( newValues );
343 }
344 else if (command == cfrCmd) {
345 cylfR = cfrCmd->GetNewDoubleValue( newValues );
346 }
347 else if (command == rcsCmd) {
348 recLevel = rcsCmd->GetNewIntValue( newValues );
349 }
350 else if (command == rcdCmd) {
351 recDepth = rcdCmd->GetNewIntValue( newValues );
352 }
353 else if (command == recCmd) {
354 Init();
355 RecursiveGridTest();
356 }
357 else if (command == cylCmd) {
358 Init();
359 if (cylCmd->GetNewBoolValue( newValues ))
360 RecursiveCylinderTest();
361 else
362 CylinderTest();
363 }
364}
365
366//
367// GetCurrentValue
368//
369G4String
370G4GeometryMessenger::GetCurrentValue(G4UIcommand* command )
371{
372 G4String cv = "";
373 if (command == posCmd) {
374 cv = posCmd->ConvertToString( x, "cm" );
375 }
376 else if (command == tolCmd) {
377 cv = tolCmd->ConvertToString( tol, "mm" );
378 }
379 else if (command == dirCmd) {
380 cv = dirCmd->ConvertToString( p, "GeV" );
381 }
382 return cv;
383}
384
385//
386// CheckGeometry
387//
388void
389G4GeometryMessenger::CheckGeometry()
390{
391 // Verify that the geometry is closed
392 //
393 G4GeometryManager* geomManager = G4GeometryManager::GetInstance();
394 if (!geomManager->IsGeometryClosed()) {
395 geomManager->OpenGeometry();
396 geomManager->CloseGeometry(true);
397 }
398}
399
400//
401// ResetNavigator
402//
403void
404G4GeometryMessenger::ResetNavigator()
405{
406 // Close geometry and reset optimisation if necessary
407 //
408 CheckGeometry();
409
410 // Reset navigator's state
411 //
412 G4ThreeVector pt(0,0,0);
413 G4Navigator* navigator = tmanager->GetNavigatorForTracking();
414 navigator->LocateGlobalPointAndSetup(pt,0,false);
415}
416
417//
418// Set navigator verbosity
419//
420void
421G4GeometryMessenger::SetVerbosity(G4String input)
422{
423 G4int level = verbCmd->GetNewIntValue(input);
424 G4Navigator* navigator = tmanager->GetNavigatorForTracking();
425 navigator->SetVerboseLevel(level);
426}
427
428//
429// Set navigator mode
430//
431void
432G4GeometryMessenger::SetCheckMode(G4String input)
433{
434 G4bool mode = chkCmd->GetNewBoolValue(input);
435 G4Navigator* navigator = tmanager->GetNavigatorForTracking();
436 navigator->CheckMode(mode);
437}
438
439//
[1347]440// Set navigator verbosity for push notifications
441//
442void
443G4GeometryMessenger::SetPushFlag(G4String input)
444{
445 G4bool mode = pchkCmd->GetNewBoolValue(input);
446 G4Navigator* navigator = tmanager->GetNavigatorForTracking();
447 navigator->SetPushVerbosity(mode);
448}
449
450//
[831]451// LineTest
452//
453void
454G4GeometryMessenger::LineTest()
455{
456 // Close geometry if necessary
457 //
458 CheckGeometry();
459
460 // Verify if error tolerance has changed
461 //
462 if (newtol) tvolume->SetTolerance(tol);
463
464 // Make test on single line supplied by user
465 //
466 tvolume->TestOneLine( x, p );
467
468 // Print out any errors, if found
469 //
470 tvolume->ReportErrors();
471}
472
473//
474// RecursiveLineTest
475//
476void
477G4GeometryMessenger::RecursiveLineTest()
478{
479 // Close geometry if necessary
480 //
481 CheckGeometry();
482
483 // Verify if error tolerance has changed
484 //
485 if (newtol) tvolume->SetTolerance(tol);
486
487 // Make test on single line supplied by user recursively
488 //
489 tvolume->TestRecursiveLine( x, p, recLevel, recDepth );
490
491 // Print out any errors, if found
492 //
493 tvolume->ReportErrors();
494}
495
496//
497// GridTest
498//
499void
500G4GeometryMessenger::GridTest()
501{
502 // Close geometry if necessary
503 //
504 CheckGeometry();
505
506 // Verify if error tolerance has changed
507 //
508 if (newtol) tvolume->SetTolerance(tol);
509
510 // Apply set of trajectories in a 3D grid pattern
511 //
512 tvolume->TestCartGridXYZ( G4int(grdRes.x()),
513 G4int(grdRes.y()),
514 G4int(grdRes.z()) );
515
516 // Print out any errors, if found
517 //
518 tvolume->ReportErrors();
519}
520
521//
522// RecursiveGridTest
523//
524void
525G4GeometryMessenger::RecursiveGridTest()
526{
527 // Close geometry if necessary
528 //
529 CheckGeometry();
530
531 // Verify if error tolerance has changed
532 //
533 if (newtol) tvolume->SetTolerance(tol);
534
535 // Apply set of trajectories in a 3D grid pattern recursively
536 //
537 tvolume->TestRecursiveCartGrid( G4int(grdRes.x()),
538 G4int(grdRes.y()),
539 G4int(grdRes.z()),
540 recLevel, recDepth );
541
542 // Print out any errors, if found
543 //
544 tvolume->ReportErrors();
545}
546
547//
548// CylinderTest
549//
550void
551G4GeometryMessenger::CylinderTest()
552{
553 // Close geometry if necessary
554 //
555 CheckGeometry();
556
557 // Verify if error tolerance has changed
558 //
559 if (newtol) tvolume->SetTolerance(tol);
560
561 // Apply default set of lines in a cylindrical pattern of gradually
562 // increasing mesh size of trajectories in a 3D grid pattern
563 //
564 tvolume->TestCylinder(G4int(cylRes.x()),
565 G4int(cylRes.y()),
566 G4int(cylRes.z()),
567 cylfZ, cylfR, true);
568
569 // Print out any errors, if found
570 //
571 tvolume->ReportErrors();
572}
573
574//
575// RecursiveCylinderTest
576//
577void
578G4GeometryMessenger::RecursiveCylinderTest()
579{
580 // Close geometry if necessary
581 //
582 CheckGeometry();
583
584 // Verify if error tolerance has changed
585 //
586 if (newtol) tvolume->SetTolerance(tol);
587
588 // Apply default set of lines in a cylindrical pattern of gradually
589 // increasing mesh size of trajectories in a 3D grid pattern recursively
590 //
591 tvolume->TestRecursiveCylinder(G4int(cylRes.x()),
592 G4int(cylRes.y()),
593 G4int(cylRes.z()),
594 cylfZ, cylfR, true,
595 recLevel, recDepth );
596
597 // Print out any errors, if found
598 //
599 tvolume->ReportErrors();
600}
Note: See TracBrowser for help on using the repository browser.