Geant4  10.01.p03
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 // ********************************************************************
162 // GetDaughtersRegularStructureId
163 // ********************************************************************
164 //
165 inline
166 G4int G4ITNavigator2::
167 GetDaughtersRegularStructureId(const G4LogicalVolume *pLog) const
168 {
169  G4int regId = 0;
170  G4VPhysicalVolume *pVol;
171 
172  if ( pLog->GetNoDaughters()==1 )
173  {
174  pVol = pLog->GetDaughter(0);
175  regId = pVol->GetRegularStructureId();
176  }
177  return regId;
178 }
179 
180 // ********************************************************************
181 // GetGlobalToLocalTransform
182 //
183 // Returns local to global transformation.
184 // I.e. transformation that will take point or axis in world coord system
185 // and return one in the local coord system
186 // ********************************************************************
187 //
188 inline
189 const G4AffineTransform& G4ITNavigator2::GetGlobalToLocalTransform() const
190 {
191  CheckNavigatorStateIsValid();
192  return fpNavigatorState->fHistory.GetTopTransform();
193 }
194 
195 // ********************************************************************
196 // GetLocalToGlobalTransform
197 //
198 // Returns global to local transformation
199 // ********************************************************************
200 //
201 inline
202 const G4AffineTransform G4ITNavigator2::GetLocalToGlobalTransform() const
203 {
204  CheckNavigatorStateIsValid();
205  G4AffineTransform tempTransform;
206  tempTransform = fpNavigatorState->fHistory.GetTopTransform().Inverse();
207  return tempTransform;
208 }
209 
210 // ********************************************************************
211 // NetTranslation
212 //
213 // Computes+returns the local->global translation of current volume
214 // ********************************************************************
215 //
216 inline
217 G4ThreeVector G4ITNavigator2::NetTranslation() const
218 {
219  CheckNavigatorStateIsValid();
220  G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
221  return tf.NetTranslation();
222 }
223 
224 // ********************************************************************
225 // NetRotation
226 //
227 // Computes+returns the local->global rotation of current volume
228 // ********************************************************************
229 //
230 inline
231 G4RotationMatrix G4ITNavigator2::NetRotation() const
232 {
233  CheckNavigatorStateIsValid();
234  G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
235  return tf.NetRotation();
236 }
237 
238 // ********************************************************************
239 // CreateGRSVolume
240 //
241 // `Touchable' creation method: caller has deletion responsibility
242 // ********************************************************************
243 //
244 inline
245 G4GRSVolume* G4ITNavigator2::CreateGRSVolume() const
246 {
247  CheckNavigatorStateIsValid();
248  G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
249  return new G4GRSVolume(fpNavigatorState->fHistory.GetTopVolume(),
250  tf.NetRotation(),
251  tf.NetTranslation());
252 }
253 
254 // ********************************************************************
255 // CreateGRSSolid
256 //
257 // `Touchable' creation method: caller has deletion responsibility
258 // ********************************************************************
259 //
260 inline
261 G4GRSSolid* G4ITNavigator2::CreateGRSSolid() const
262 {
263  CheckNavigatorStateIsValid();
264  G4AffineTransform tf(fpNavigatorState->fHistory.GetTopTransform().Inverse());
265  return new G4GRSSolid(fpNavigatorState->fHistory.GetTopVolume()->GetLogicalVolume()->GetSolid(),
266  tf.NetRotation(),
267  tf.NetTranslation());
268 }
269 
270 // ********************************************************************
271 // CreateTouchableHistory
272 //
273 // `Touchable' creation method: caller has deletion responsibility
274 // ********************************************************************
275 //
276 inline
277 G4TouchableHistory* G4ITNavigator2::CreateTouchableHistory() const
278 {
279  CheckNavigatorStateIsValid();
280  return new G4TouchableHistory(fpNavigatorState->fHistory);
281 }
282 
283 // ********************************************************************
284 // CreateTouchableHistory(history)
285 //
286 // `Touchable' creation method: caller has deletion responsibility
287 // ********************************************************************
288 //
289 inline
290 G4TouchableHistory*
291 G4ITNavigator2::CreateTouchableHistory(const G4NavigationHistory* history) const
292 {
293  return new G4TouchableHistory(*history);
294 }
295 
296 // ********************************************************************
297 // LocateGlobalPointAndUpdateTouchableHandle
298 // ********************************************************************
299 //
300 inline
301 void G4ITNavigator2::LocateGlobalPointAndUpdateTouchableHandle(
302  const G4ThreeVector& position,
303  const G4ThreeVector& direction,
304  G4TouchableHandle& oldTouchableToUpdate,
305  const G4bool RelativeSearch )
306 {
307  G4VPhysicalVolume* pPhysVol;
308  pPhysVol = LocateGlobalPointAndSetup( position,&direction,RelativeSearch );
309  // Will check navigatorState validity
310  if( fpNavigatorState->fEnteredDaughter || fpNavigatorState->fExitedMother )
311  {
312  oldTouchableToUpdate = CreateTouchableHistory();
313  if( pPhysVol == 0 )
314  {
315  // We want to ensure that the touchable is correct in this case.
316  // The method below should do this and recalculate a lot more ....
317  //
318  oldTouchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory );
319  }
320  }
321  return;
322 }
323 
324 // ********************************************************************
325 // LocateGlobalPointAndUpdateTouchable
326 //
327 // Use direction
328 // ********************************************************************
329 //
330 inline
331 void G4ITNavigator2::LocateGlobalPointAndUpdateTouchable(
332  const G4ThreeVector& position,
333  const G4ThreeVector& direction,
334  G4VTouchable* touchableToUpdate,
335  const G4bool RelativeSearch )
336 {
337  G4VPhysicalVolume* pPhysVol;
338  pPhysVol = LocateGlobalPointAndSetup( position, &direction, RelativeSearch);
339  // Will check navigatorState validity
340  touchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory );
341 }
342 
343 // ********************************************************************
344 // LocateGlobalPointAndUpdateTouchable
345 // ********************************************************************
346 //
347 inline
348 void G4ITNavigator2::LocateGlobalPointAndUpdateTouchable(
349  const G4ThreeVector& position,
350  G4VTouchable* touchableToUpdate,
351  const G4bool RelativeSearch )
352 {
353  G4VPhysicalVolume* pPhysVol;
354  pPhysVol = LocateGlobalPointAndSetup( position, 0, RelativeSearch);
355  // Will check navigatorState validity
356  touchableToUpdate->UpdateYourself( pPhysVol, &fpNavigatorState->fHistory );
357 }
358 
359 // ********************************************************************
360 // GetVerboseLevel
361 // ********************************************************************
362 //
363 inline
364 G4int G4ITNavigator2::GetVerboseLevel() const
365 {
366  return fVerbose;
367 }
368 
369 // ********************************************************************
370 // SetVerboseLevel
371 // ********************************************************************
372 //
373 inline
374 void G4ITNavigator2::SetVerboseLevel(G4int level)
375 {
376  fVerbose = level;
377  fnormalNav.SetVerboseLevel(level);
378  fvoxelNav.SetVerboseLevel(level);
379  fparamNav.SetVerboseLevel(level);
380  freplicaNav.SetVerboseLevel(level);
381  fregularNav.SetVerboseLevel(level);
382 }
383 
384 // ********************************************************************
385 // IsActive
386 // ********************************************************************
387 //
388 inline
389 G4bool G4ITNavigator2::IsActive() const
390 {
391  return fActive;
392 }
393 
394 // ********************************************************************
395 // Activate
396 // ********************************************************************
397 //
398 inline
399 void G4ITNavigator2::Activate(G4bool flag)
400 {
401  fActive = flag;
402 }
403 
404 // ********************************************************************
405 // EnteredDaughterVolume
406 //
407 // To inform the caller if the track is entering a daughter volume
408 // ********************************************************************
409 //
410 inline
411 G4bool G4ITNavigator2::EnteredDaughterVolume() const
412 {
413  CheckNavigatorStateIsValid();
414  return fpNavigatorState->fEnteredDaughter;
415 }
416 
417 // ********************************************************************
418 // ExitedMotherVolume
419 // ********************************************************************
420 //
421 inline
422 G4bool G4ITNavigator2::ExitedMotherVolume() const
423 {
424  CheckNavigatorStateIsValid();
425  return fpNavigatorState->fExitedMother;
426 }
427 
428 // ********************************************************************
429 // CheckMode
430 // ********************************************************************
431 //
432 inline
433 void G4ITNavigator2::CheckMode(G4bool mode)
434 {
435  fCheck = mode;
436  fnormalNav.CheckMode(mode);
437  fvoxelNav.CheckMode(mode);
438  fparamNav.CheckMode(mode);
439  freplicaNav.CheckMode(mode);
440  fregularNav.CheckMode(mode);
441 }
442 
443 // ********************************************************************
444 // IsCheckModeActive
445 // ********************************************************************
446 //
447 inline
448 G4bool G4ITNavigator2::IsCheckModeActive() const
449 {
450  return fCheck;
451 }
452 
453 // ********************************************************************
454 // SetPushVerbosity
455 // ********************************************************************
456 //
457 inline
458 void G4ITNavigator2::SetPushVerbosity(G4bool mode)
459 {
460  fWarnPush = mode;
461 }
462 
463 // ********************************************************************
464 // SeverityOfZeroStepping
465 //
466 // Reports on severity of error in case Navigator is stuck
467 // and is returning zero steps
468 // ********************************************************************
469 //
470 inline
471 G4int G4ITNavigator2::SeverityOfZeroStepping( G4int* noZeroSteps ) const
472 {
473  CheckNavigatorStateIsValid();
474  G4int severity=0, noZeros= fpNavigatorState->fNumberZeroSteps;
475  if( noZeroSteps) *noZeroSteps = fpNavigatorState->fNumberZeroSteps;
476 
477  if( noZeros >= fAbandonThreshold_NoZeroSteps )
478  {
479  severity = 10;
480  }
481  if( noZeros > 0 && noZeros < fActionThreshold_NoZeroSteps )
482  {
483  severity = 5 * noZeros / fActionThreshold_NoZeroSteps;
484  }
485  else if( noZeros == fActionThreshold_NoZeroSteps )
486  {
487  severity = 5;
488  }
489  else if( noZeros >= fAbandonThreshold_NoZeroSteps - 2 )
490  {
491  severity = 9;
492  }
493  else if( noZeros < fAbandonThreshold_NoZeroSteps - 2 )
494  {
495  severity = 5 + 4 * (noZeros-fAbandonThreshold_NoZeroSteps)
496  / fActionThreshold_NoZeroSteps;
497  }
498  return severity;
499 }
500 
501 // ********************************************************************
502 // EnableBestSafety
503 // ********************************************************************
504 //
505 inline void G4ITNavigator2::EnableBestSafety( G4bool value )
506 {
507  fvoxelNav.EnableBestSafety( value );
508 }