source: trunk/source/geometry/navigation/include/G4Navigator.icc @ 1347

Last change on this file since 1347 was 1347, checked in by garnier, 13 years ago

geant4 tag 9.4

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