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