ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4GeometryMessenger.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4GeometryMessenger.cc
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 
33 #include "G4GeometryMessenger.hh"
34 
36 #include "G4GeometryManager.hh"
37 #include "G4VPhysicalVolume.hh"
38 #include "G4Navigator.hh"
39 
40 #include "G4UIdirectory.hh"
41 #include "G4UIcommand.hh"
43 #include "G4UIcmdWithABool.hh"
44 #include "G4UIcmdWithAnInteger.hh"
46 
47 #include "G4GeomTestVolume.hh"
48 
49 //
50 // Constructor
51 //
53  : tmanager(tman)
54 {
55  geodir = new G4UIdirectory( "/geometry/" );
56  geodir->SetGuidance( "Geometry control commands." );
57 
58  //
59  // Geometry navigator commands
60  //
61  navdir = new G4UIdirectory( "/geometry/navigator/" );
62  navdir->SetGuidance( "Geometry navigator control setup." );
63 
64  resCmd = new G4UIcmdWithoutParameter( "/geometry/navigator/reset", this );
65  resCmd->SetGuidance( "Reset navigator and navigation history." );
66  resCmd->SetGuidance( "NOTE: must be called only after kernel has been" );
67  resCmd->SetGuidance( " initialized once through the run manager!" );
69 
70  verbCmd = new G4UIcmdWithAnInteger( "/geometry/navigator/verbose", this );
71  verbCmd->SetGuidance( "Set run-time verbosity for the navigator." );
72  verbCmd->SetGuidance(" 0 : Silent (default)");
73  verbCmd->SetGuidance(" 1 : Display volume positioning and step lengths");
74  verbCmd->SetGuidance(" 2 : Display step/safety info on point location");
75  verbCmd->SetGuidance(" 3 : Display minimal state at -every- step");
76  verbCmd->SetGuidance(" 4 : Maximum verbosity (very detailed!)");
77  verbCmd->SetGuidance( "NOTE: this command has effect -only- if Geant4 has" );
78  verbCmd->SetGuidance( " been installed with the G4VERBOSE flag set!" );
79  verbCmd->SetParameterName("level",true);
81  verbCmd->SetRange("level >=0 && level <=4");
82 
83  chkCmd = new G4UIcmdWithABool( "/geometry/navigator/check_mode", this );
84  chkCmd->SetGuidance( "Set navigator in -check_mode- state." );
85  chkCmd->SetGuidance( "This will cause extra checks to be applied during" );
86  chkCmd->SetGuidance( "navigation. More strict and less tolerant conditions" );
87  chkCmd->SetGuidance( "are applied. A run-time performance penalty may be" );
88  chkCmd->SetGuidance( "observed when the -check_mode- state is activated." );
89  chkCmd->SetGuidance( "NOTE: this command has effect -only- if Geant4 has" );
90  chkCmd->SetGuidance( " been installed with the G4VERBOSE flag set!" );
91  chkCmd->SetParameterName("checkFlag",true);
92  chkCmd->SetDefaultValue(false);
94 
95  pchkCmd = new G4UIcmdWithABool( "/geometry/navigator/push_notify", this );
96  pchkCmd->SetGuidance( "Set navigator verbosity push notifications." );
97  pchkCmd->SetGuidance( "This allows to disable/re-enable verbosity in" );
98  pchkCmd->SetGuidance( "navigation, when tracks may get stuck and require" );
99  pchkCmd->SetGuidance( "one artificial push along the direction by the" );
100  pchkCmd->SetGuidance( "navigator. Notification is active by default." );
101  pchkCmd->SetGuidance( "NOTE: this command has effect -only- if Geant4 has" );
102  pchkCmd->SetGuidance( " been installed with the G4VERBOSE flag set!" );
103  pchkCmd->SetParameterName("pushFlag",true);
104  pchkCmd->SetDefaultValue(true);
106 
107  //
108  // Geometry verification test commands
109  //
110  testdir = new G4UIdirectory( "/geometry/test/" );
111  testdir->SetGuidance( "Geometry verification control setup." );
112  testdir->SetGuidance( "Helps in detecting possible overlapping regions." );
113 
114  tolCmd = new G4UIcmdWithADoubleAndUnit( "/geometry/test/tolerance",this );
115  tolCmd->SetGuidance( "Define tolerance (in mm) by which overlaps reports" );
116  tolCmd->SetGuidance( "should be reported. By default, all overlaps are" );
117  tolCmd->SetGuidance( "reported, i.e. tolerance is set to: 0*mm." );
118  tolCmd->SetParameterName( "Tolerance", true, true );
119  tolCmd->SetDefaultValue( 0 );
120  tolCmd->SetDefaultUnit( "mm" );
121  tolCmd->SetUnitCategory( "Length" );
122 
123  verCmd = new G4UIcmdWithABool( "/geometry/test/verbosity", this );
124  verCmd->SetGuidance( "Specify if running in verbosity mode or not." );
125  verCmd->SetGuidance( "By default verbosity is set to ON (TRUE)." );
126  verCmd->SetParameterName("verbosity",true);
127  verCmd->SetDefaultValue(true);
129 
130  rslCmd = new G4UIcmdWithAnInteger( "/geometry/test/resolution", this );
131  rslCmd->SetGuidance( "Set the number of points on surface to be generated for" );
132  rslCmd->SetGuidance( "checking overlaps." );
133  rslCmd->SetParameterName("resolution",true);
134  rslCmd->SetDefaultValue(10000);
135 
136  rcsCmd = new G4UIcmdWithAnInteger( "/geometry/test/recursion_start", this );
137  rcsCmd->SetGuidance( "Set the initial level in the geometry tree for recursion." );
138  rcsCmd->SetGuidance( "recursive_test will then start from the specified level." );
139  rcsCmd->SetParameterName("initial_level",true);
141 
142  rcdCmd = new G4UIcmdWithAnInteger( "/geometry/test/recursion_depth", this );
143  rcdCmd->SetGuidance( "Set the depth in the geometry tree for recursion." );
144  rcdCmd->SetGuidance( "recursive_test will then stop after reached the specified depth." );
145  rcdCmd->SetGuidance( "By default, recursion will proceed for the whole depth." );
146  rcdCmd->SetParameterName("recursion_depth",true);
147  rcdCmd->SetDefaultValue(-1);
148 
149  errCmd = new G4UIcmdWithAnInteger( "/geometry/test/maximum_errors", this );
150  errCmd->SetGuidance( "Set the maximum number of overlap errors to report" );
151  errCmd->SetGuidance( "for each single volume being checked." );
152  errCmd->SetGuidance( "Once reached the maximum number specified, overlaps" );
153  errCmd->SetGuidance( "affecting that volume further than that are simply ignored." );
154  errCmd->SetParameterName("maximum_errors",true);
156 
157  recCmd = new G4UIcmdWithoutParameter( "/geometry/test/run", this );
158  recCmd->SetGuidance( "Start running the recursive overlap check." );
159  recCmd->SetGuidance( "Volumes are recursively asked to verify for overlaps" );
160  recCmd->SetGuidance( "for points generated on the surface against their" );
161  recCmd->SetGuidance( "respective mother volume and sisters at the same" );
162  recCmd->SetGuidance( "level, performing for all daughters and daughters of" );
163  recCmd->SetGuidance( "daughters, etc." );
164  recCmd->SetGuidance( "NOTE: it may take a very long time," );
165  recCmd->SetGuidance( " depending on the geometry complexity !");
167 }
168 
169 //
170 // Destructor
171 //
173 {
174  delete verCmd; delete recCmd; delete rslCmd;
175  delete resCmd; delete rcsCmd; delete rcdCmd; delete errCmd;
176  delete tolCmd;
177  delete verbCmd; delete pchkCmd; delete chkCmd;
178  delete geodir; delete navdir; delete testdir;
179  delete tvolume;
180 }
181 
182 //
183 // Init
184 //
185 void
187 {
188  // Create checker...
189  //
190  if (tvolume == nullptr)
191  {
192  // Get the world volume
193  //
196 
197  // Test the actual detector...
198  //
199  tvolume = new G4GeomTestVolume(world);
200  }
201 }
202 
203 //
204 // SetNewValue
205 //
206 void
208 {
209  if (command == resCmd) {
210  ResetNavigator();
211  }
212  else if (command == verbCmd) {
213  SetVerbosity( newValues );
214  }
215  else if (command == chkCmd) {
216  SetCheckMode( newValues );
217  }
218  else if (command == pchkCmd) {
219  SetPushFlag( newValues );
220  }
221  else if (command == tolCmd) {
222  Init();
223  tol = tolCmd->GetNewDoubleValue( newValues )
224  * tolCmd->GetNewUnitValue( newValues );
226  }
227  else if (command == verCmd) {
228  Init();
229  tvolume->SetVerbosity(verCmd->GetNewBoolValue( newValues ));
230  }
231  else if (command == rslCmd) {
232  Init();
233  tvolume->SetResolution(rslCmd->GetNewIntValue( newValues ));
234  }
235  else if (command == rcsCmd) {
236  recLevel = rcsCmd->GetNewIntValue( newValues );
237  }
238  else if (command == rcdCmd) {
239  recDepth = rcdCmd->GetNewIntValue( newValues );
240  }
241  else if (command == errCmd) {
242  Init();
244  }
245  else if (command == recCmd) {
246  Init();
247  G4cout << "Running geometry overlaps check..." << G4endl;
249  G4cout << "Geometry overlaps check completed !" << G4endl;
250  }
251 }
252 
253 //
254 // GetCurrentValue
255 //
256 G4String
258 {
259  G4String cv = "";
260  if (command == tolCmd)
261  {
262  cv = tolCmd->ConvertToString( tol, "mm" );
263  }
264  return cv;
265 }
266 
267 //
268 // CheckGeometry
269 //
270 void
272 {
273  // Verify that the geometry is closed
274  //
276  if (!geomManager->IsGeometryClosed())
277  {
278  geomManager->OpenGeometry();
279  geomManager->CloseGeometry(true);
280  }
281 }
282 
283 //
284 // ResetNavigator
285 //
286 void
288 {
289  // Close geometry and reset optimisation if necessary
290  //
291  CheckGeometry();
292 
293  // Reset navigator's state
294  //
295  G4ThreeVector pt(0,0,0);
297  navigator->LocateGlobalPointAndSetup(pt,0,false);
298 }
299 
300 //
301 // Set navigator verbosity
302 //
303 void
305 {
306  G4int level = verbCmd->GetNewIntValue(input);
308  navigator->SetVerboseLevel(level);
309 }
310 
311 //
312 // Set navigator mode
313 //
314 void
316 {
317  G4bool mode = chkCmd->GetNewBoolValue(input);
319  navigator->CheckMode(mode);
320 }
321 
322 //
323 // Set navigator verbosity for push notifications
324 //
325 void
327 {
328  G4bool mode = pchkCmd->GetNewBoolValue(input);
330  navigator->SetPushVerbosity(mode);
331 }
332 
333 //
334 // Recursive Overlap Test
335 //
336 void
338 {
339  // Close geometry if necessary
340  //
341  CheckGeometry();
342 
343  // Make test on single line supplied by user recursively
344  //
346 }