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