Geant4  10.02.p01
G4Navigator.icc
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: G4Navigator.icc 73164 2013-08-21 08:55:28Z gcosmo $
28 //
29 //
30 // class G4Navigator Inline implementation
31 //
32 // ********************************************************************
33 
34 // ********************************************************************
35 // GetCurrentLocalCoordinate
36 //
37 // Returns the local coordinate of the current track
38 // ********************************************************************
39 //
40 inline
41 G4ThreeVector G4Navigator::GetCurrentLocalCoordinate() const
42 {
43  return fLastLocatedPointLocal;
44 }
45 
46 // ********************************************************************
47 // ComputeLocalAxis
48 //
49 // Returns local direction of vector direction in world coord system
50 // ********************************************************************
51 //
52 inline
53 G4ThreeVector G4Navigator::ComputeLocalAxis(const G4ThreeVector& pVec) const
54 {
55  return (fHistory.GetTopTransform().IsRotated())
56  ? fHistory.GetTopTransform().TransformAxis(pVec) : pVec ;
57 }
58 
59 // ********************************************************************
60 // ComputeLocalPoint
61 //
62 // Returns local coordinates of a point in the world coord system
63 // ********************************************************************
64 //
65 inline
66 G4ThreeVector
67 G4Navigator::ComputeLocalPoint(const G4ThreeVector& pGlobalPoint) const
68 {
69  return ( fHistory.GetTopTransform().TransformPoint(pGlobalPoint) ) ;
70 }
71 
72 // ********************************************************************
73 // GetWorldVolume
74 //
75 // Returns the current world (`topmost') volume
76 // ********************************************************************
77 //
78 inline
79 G4VPhysicalVolume* G4Navigator::GetWorldVolume() const
80 {
81  return fTopPhysical;
82 }
83 
84 // ********************************************************************
85 // SetWorldVolume
86 //
87 // Sets the world (`topmost') volume
88 // ********************************************************************
89 //
90 inline
91 void G4Navigator::SetWorldVolume(G4VPhysicalVolume* pWorld)
92 {
93  if ( !(pWorld->GetTranslation()==G4ThreeVector(0,0,0)) )
94  {
95  G4Exception ("G4Navigator::SetWorldVolume()", "GeomNav0002",
96  FatalException, "Volume must be centered on the origin.");
97  }
98  const G4RotationMatrix* rm = pWorld->GetRotation();
99  if ( rm && (!rm->isIdentity()) )
100  {
101  G4Exception ("G4Navigator::SetWorldVolume()", "GeomNav0002",
102  FatalException, "Volume must not be rotated.");
103  }
104  fTopPhysical = pWorld;
105  fHistory.SetFirstEntry(pWorld);
106 }
107 
108 // ********************************************************************
109 // SetGeometrycallyLimitedStep
110 //
111 // Informs the navigator that the previous Step calculated
112 // by the geometry was taken in its entirety
113 // ********************************************************************
114 //
115 inline
116 void G4Navigator::SetGeometricallyLimitedStep()
117 {
118  fWasLimitedByGeometry=true;
119 }
120 
121 // ********************************************************************
122 // ResetStackAndState
123 //
124 // Resets stack and minimum of navigator state `machine'
125 // ********************************************************************
126 //
127 inline
128 void G4Navigator::ResetStackAndState()
129 {
130  fHistory.Reset();
131  ResetState();
132 }
133 
134 // ********************************************************************
135 // VolumeType
136 // ********************************************************************
137 //
138 inline
139 EVolume G4Navigator::VolumeType(const G4VPhysicalVolume *pVol) const
140 {
141  return pVol->VolumeType();
142 }
143 
144 // ********************************************************************
145 // CharacteriseDaughters
146 // ********************************************************************
147 //
148 inline
149 EVolume G4Navigator::CharacteriseDaughters(const G4LogicalVolume *pLog) const
150 {
151  return pLog->CharacteriseDaughters();
152 }
153 
154 // ********************************************************************
155 // GetDaughtersRegularStructureId
156 // ********************************************************************
157 //
158 inline
159 G4int G4Navigator::
160 GetDaughtersRegularStructureId(const G4LogicalVolume *pLog) const
161 {
162  G4int regId = 0;
163  G4VPhysicalVolume *pVol;
164 
165  if ( pLog->GetNoDaughters()==1 )
166  {
167  pVol = pLog->GetDaughter(0);
168  regId = pVol->GetRegularStructureId();
169  }
170  return regId;
171 }
172 
173 // ********************************************************************
174 // GetGlobalToLocalTransform
175 //
176 // Returns local to global transformation.
177 // I.e. transformation that will take point or axis in world coord system
178 // and return one in the local coord system
179 // ********************************************************************
180 //
181 inline
182 const G4AffineTransform& G4Navigator::GetGlobalToLocalTransform() const
183 {
184  return fHistory.GetTopTransform();
185 }
186 
187 // ********************************************************************
188 // GetLocalToGlobalTransform
189 //
190 // Returns global to local transformation
191 // ********************************************************************
192 //
193 inline
194 const G4AffineTransform G4Navigator::GetLocalToGlobalTransform() const
195 {
196  G4AffineTransform tempTransform;
197  tempTransform = fHistory.GetTopTransform().Inverse();
198  return tempTransform;
199 }
200 
201 // ********************************************************************
202 // NetTranslation
203 //
204 // Computes+returns the local->global translation of current volume
205 // ********************************************************************
206 //
207 inline
208 G4ThreeVector G4Navigator::NetTranslation() const
209 {
210  G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
211  return tf.NetTranslation();
212 }
213 
214 // ********************************************************************
215 // NetRotation
216 //
217 // Computes+returns the local->global rotation of current volume
218 // ********************************************************************
219 //
220 inline
221 G4RotationMatrix G4Navigator::NetRotation() const
222 {
223  G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
224  return tf.NetRotation();
225 }
226 
227 // ********************************************************************
228 // CreateGRSVolume
229 //
230 // `Touchable' creation method: caller has deletion responsibility
231 // ********************************************************************
232 //
233 inline
234 G4GRSVolume* G4Navigator::CreateGRSVolume() const
235 {
236  G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
237  return new G4GRSVolume(fHistory.GetTopVolume(),
238  tf.NetRotation(),
239  tf.NetTranslation());
240 }
241 
242 // ********************************************************************
243 // CreateGRSSolid
244 //
245 // `Touchable' creation method: caller has deletion responsibility
246 // ********************************************************************
247 //
248 inline
249 G4GRSSolid* G4Navigator::CreateGRSSolid() const
250 {
251  G4AffineTransform tf(fHistory.GetTopTransform().Inverse());
252  return new G4GRSSolid(fHistory.GetTopVolume()->GetLogicalVolume()->GetSolid(),
253  tf.NetRotation(),
254  tf.NetTranslation());
255 }
256 
257 // ********************************************************************
258 // CreateTouchableHistory
259 //
260 // `Touchable' creation method: caller has deletion responsibility
261 // ********************************************************************
262 //
263 inline
264 G4TouchableHistory* G4Navigator::CreateTouchableHistory() const
265 {
266  return new G4TouchableHistory(fHistory);
267 }
268 
269 // ********************************************************************
270 // CreateTouchableHistory(history)
271 //
272 // `Touchable' creation method: caller has deletion responsibility
273 // ********************************************************************
274 //
275 inline
276 G4TouchableHistory*
277 G4Navigator::CreateTouchableHistory(const G4NavigationHistory* history) const
278 {
279  return new G4TouchableHistory(*history);
280 }
281 
282 // ********************************************************************
283 // LocateGlobalPointAndUpdateTouchableHandle
284 // ********************************************************************
285 //
286 inline
287 void G4Navigator::LocateGlobalPointAndUpdateTouchableHandle(
288  const G4ThreeVector& position,
289  const G4ThreeVector& direction,
290  G4TouchableHandle& oldTouchableToUpdate,
291  const G4bool RelativeSearch )
292 {
293  G4VPhysicalVolume* pPhysVol;
294  pPhysVol = LocateGlobalPointAndSetup( position,&direction,RelativeSearch );
295  if( fEnteredDaughter || fExitedMother )
296  {
297  oldTouchableToUpdate = CreateTouchableHistory();
298  if( pPhysVol == 0 )
299  {
300  // We want to ensure that the touchable is correct in this case.
301  // The method below should do this and recalculate a lot more ....
302  //
303  oldTouchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
304  }
305  }
306  return;
307 }
308 
309 // ********************************************************************
310 // LocateGlobalPointAndUpdateTouchable
311 //
312 // Use direction
313 // ********************************************************************
314 //
315 inline
316 void G4Navigator::LocateGlobalPointAndUpdateTouchable(
317  const G4ThreeVector& position,
318  const G4ThreeVector& direction,
319  G4VTouchable* touchableToUpdate,
320  const G4bool RelativeSearch )
321 {
322  G4VPhysicalVolume* pPhysVol;
323  pPhysVol = LocateGlobalPointAndSetup( position, &direction, RelativeSearch);
324  touchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
325 }
326 
327 // ********************************************************************
328 // LocateGlobalPointAndUpdateTouchable
329 // ********************************************************************
330 //
331 inline
332 void G4Navigator::LocateGlobalPointAndUpdateTouchable(
333  const G4ThreeVector& position,
334  G4VTouchable* touchableToUpdate,
335  const G4bool RelativeSearch )
336 {
337  G4VPhysicalVolume* pPhysVol;
338  pPhysVol = LocateGlobalPointAndSetup( position, 0, RelativeSearch);
339  touchableToUpdate->UpdateYourself( pPhysVol, &fHistory );
340 }
341 
342 // ********************************************************************
343 // GetVerboseLevel
344 // ********************************************************************
345 //
346 inline
347 G4int G4Navigator::GetVerboseLevel() const
348 {
349  return fVerbose;
350 }
351 
352 // ********************************************************************
353 // SetVerboseLevel
354 // ********************************************************************
355 //
356 inline
357 void G4Navigator::SetVerboseLevel(G4int level)
358 {
359  fVerbose = level;
360  fnormalNav.SetVerboseLevel(level);
361  fvoxelNav.SetVerboseLevel(level);
362  fparamNav.SetVerboseLevel(level);
363  freplicaNav.SetVerboseLevel(level);
364  fregularNav.SetVerboseLevel(level);
365 }
366 
367 // ********************************************************************
368 // IsActive
369 // ********************************************************************
370 //
371 inline
372 G4bool G4Navigator::IsActive() const
373 {
374  return fActive;
375 }
376 
377 // ********************************************************************
378 // Activate
379 // ********************************************************************
380 //
381 inline
382 void G4Navigator::Activate(G4bool flag)
383 {
384  fActive = flag;
385 }
386 
387 // ********************************************************************
388 // EnteredDaughterVolume
389 //
390 // To inform the caller if the track is entering a daughter volume
391 // ********************************************************************
392 //
393 inline
394 G4bool G4Navigator::EnteredDaughterVolume() const
395 {
396  return fEnteredDaughter;
397 }
398 
399 // ********************************************************************
400 // ExitedMotherVolume
401 // ********************************************************************
402 //
403 inline
404 G4bool G4Navigator::ExitedMotherVolume() const
405 {
406  return fExitedMother;
407 }
408 
409 // ********************************************************************
410 // CheckMode
411 // ********************************************************************
412 //
413 inline
414 void G4Navigator::CheckMode(G4bool mode)
415 {
416  fCheck = mode;
417  fnormalNav.CheckMode(mode);
418  fvoxelNav.CheckMode(mode);
419  fparamNav.CheckMode(mode);
420  freplicaNav.CheckMode(mode);
421  fregularNav.CheckMode(mode);
422 }
423 
424 // ********************************************************************
425 // IsCheckModeActive
426 // ********************************************************************
427 //
428 inline
429 G4bool G4Navigator::IsCheckModeActive() const
430 {
431  return fCheck;
432 }
433 
434 // ********************************************************************
435 // SetPushVerbosity
436 // ********************************************************************
437 //
438 inline
439 void G4Navigator::SetPushVerbosity(G4bool mode)
440 {
441  fWarnPush = mode;
442 }
443 
444 // ********************************************************************
445 // SeverityOfZeroStepping
446 //
447 // Reports on severity of error in case Navigator is stuck
448 // and is returning zero steps
449 // ********************************************************************
450 //
451 inline
452 G4int G4Navigator::SeverityOfZeroStepping( G4int* noZeroSteps ) const
453 {
454  G4int severity=0, noZeros= fNumberZeroSteps;
455  if( noZeroSteps) *noZeroSteps = fNumberZeroSteps;
456 
457  if( noZeros >= fAbandonThreshold_NoZeroSteps )
458  {
459  severity = 10;
460  }
461  if( noZeros > 0 && noZeros < fActionThreshold_NoZeroSteps )
462  {
463  severity = 5 * noZeros / fActionThreshold_NoZeroSteps;
464  }
465  else if( noZeros == fActionThreshold_NoZeroSteps )
466  {
467  severity = 5;
468  }
469  else if( noZeros >= fAbandonThreshold_NoZeroSteps - 2 )
470  {
471  severity = 9;
472  }
473  else if( noZeros < fAbandonThreshold_NoZeroSteps - 2 )
474  {
475  severity = 5 + 4 * (noZeros-fAbandonThreshold_NoZeroSteps)
476  / fActionThreshold_NoZeroSteps;
477  }
478  return severity;
479 }
480 
481 // ********************************************************************
482 // EnableBestSafety
483 // ********************************************************************
484 //
485 inline void G4Navigator::EnableBestSafety( G4bool value )
486 {
487  fvoxelNav.EnableBestSafety( value );
488 }