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