Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4ITMultiNavigator.cc
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 // $Id: G4ITMultiNavigator.cc 70934 2013-06-07 13:29:05Z gcosmo $
28 // GEANT4 tag $ Name: $
29 //
30 // class G4PathFinder Implementation
31 //
32 // Author: John Apostolakis, November 2006
33 // --------------------------------------------------------------------
34 
35 #include <iomanip>
36 
37 #include "G4ITMultiNavigator.hh"
38 
39 class G4FieldManager;
40 
41 #include "G4SystemOfUnits.hh"
42 #include "G4ITNavigator.hh"
43 #include "G4PropagatorInField.hh"
45 
46 #define State(X) fpTrackState->X
47 #define fLimitedStep State(fLimitedStep)
48 #define fLimitTruth State(fLimitTruth)
49 #define fCurrentStepSize State(fCurrentStepSize)
50 #define fNewSafety State(fNewSafety)
51 #define fNoLimitingStep State(fNoLimitingStep)
52 #define fIdNavLimiting State(fIdNavLimiting)
53 #define fMinStep State(fMinStep)
54 #define fMinSafety State(fMinSafety)
55 #define fTrueMinStep State(fTrueMinStep)
56 #define fLocatedVolume State(fLocatedVolume)
57 #define fLastLocatedPosition State(fLastLocatedPosition)
58 #define fSafetyLocation State(fSafetyLocation)
59 #define fMinSafety_atSafLocation State(fMinSafety_atSafLocation)
60 #define fPreStepLocation State(fPreStepLocation)
61 #define fMinSafety_PreStepPt State(fMinSafety_PreStepPt)
62 #define fWasLimitedByGeometry State(fWasLimitedByGeometry)
63 
64 // ********************************************************************
65 // Constructor
66 // ********************************************************************
67 //
69  : G4ITNavigator(), fLastMassWorld(0)
70 {
71  fNoActiveNavigators= 0;
72 
73  for(G4int num=0; num< fMaxNav; ++num )
74  {
75  fpNavigator[num] = 0;
76  }
77 
79 
80  G4ITNavigator* massNav= pTransportManager->GetNavigatorForTracking();
81  if( massNav )
82  {
83  G4VPhysicalVolume* pWorld= massNav->GetWorldVolume();
84  if( pWorld )
85  {
86  SetWorldVolume( pWorld );
87  fLastMassWorld = pWorld;
88  }
89  }
90 }
91 
93 {
94 }
95 
97  const G4ThreeVector &pDirection,
98  const G4double proposedStepLength,
99  G4double &pNewSafety)
100 {
101  G4double safety= 0.0, step=0.0;
102  G4double minSafety= kInfinity, minStep= kInfinity;
103 
104  fNoLimitingStep= -1;
105  fIdNavLimiting= -1; // Reset for new step
106 
107 #ifdef G4DEBUG_NAVIGATION
108  if( fVerbose > 2 )
109  {
110  G4cout << " G4ITMultiNavigator::ComputeStep : entered " << G4endl;
111  G4cout << " Input position= " << pGlobalPoint
112  << " direction= " << pDirection << G4endl;
113  G4cout << " Requested step= " << proposedStepLength << G4endl;
114  }
115 #endif
116 
117  std::vector<G4ITNavigator*>::iterator pNavigatorIter;
118 
119  pNavigatorIter= pTransportManager-> GetActiveNavigatorsIterator();
120 
121  G4ThreeVector initialPosition = pGlobalPoint;
122  G4ThreeVector initialDirection= pDirection;
123 
124  for( G4int num=0; num< fNoActiveNavigators; ++pNavigatorIter,++num )
125  {
126  safety= kInfinity;
127 
128  step= (*pNavigatorIter)->ComputeStep( initialPosition,
129  initialDirection,
130  proposedStepLength,
131  safety );
132  if( safety < minSafety ){ minSafety = safety; }
133  if( step < minStep ) { minStep= step; }
134 
135  fCurrentStepSize[num] = step;
136  fNewSafety[num]= safety;
137  // This is currently the safety from the last sub-step
138 
139 #ifdef G4DEBUG_NAVIGATION
140  if( fVerbose > 2 )
141  {
142  G4cout << "G4ITMultiNavigator::ComputeStep : Navigator ["
143  << num << "] -- step size " << step
144  << " safety= " << safety << G4endl;
145  }
146 #endif
147  }
148 
149  // Save safety value, related position
150  //
151  fPreStepLocation = initialPosition;
152  fMinSafety_PreStepPt = minSafety;
153  fMinStep = minStep;
154 
155  if( fMinStep == kInfinity )
156  {
157  fTrueMinStep = proposedStepLength; // Use this below for endpoint !!
158  }
159  else
160  {
161  fTrueMinStep = minStep;
162  }
163 
164 #ifdef G4DEBUG_NAVIGATION
165  if( fVerbose > 1 )
166  {
167  G4ThreeVector endPosition = initialPosition+fTrueMinStep*initialDirection;
168 
169  G4int oldPrec = G4cout.precision(8);
170  G4cout << "G4ITMultiNavigator::ComputeStep : "
171  << " initialPosition = " << initialPosition
172  << " and endPosition = " << endPosition << G4endl;
173  G4cout.precision( oldPrec );
174  }
175 #endif
176 
177  pNewSafety = minSafety;
178 
179  this->WhichLimited();
180 
181 #ifdef G4DEBUG_NAVIGATION
182  if( fVerbose > 2 )
183  {
184  G4cout << " G4ITMultiNavigator::ComputeStep : exits returning "
185  << minStep << G4endl;
186  }
187 #endif
188 
189  return minStep; // must return kInfinity if do not limit step
190 }
191 
192 // ----------------------------------------------------------------------
193 
194 G4double
196  G4double &pNewSafety, // for this geometry
197  G4double &minStep,
198  ELimited &limitedStep)
199 {
200  if( navigatorId > fNoActiveNavigators )
201  {
202  std::ostringstream message;
203  message << "Bad Navigator Id!" << G4endl
204  << " Navigator Id = " << navigatorId
205  << " No Active = " << fNoActiveNavigators << ".";
206  G4Exception("G4ITMultiNavigator::ObtainFinalStep()", "GeomNav0002",
207  FatalException, message);
208  }
209 
210  // Prepare the information to return
211  //
212  pNewSafety = fNewSafety[ navigatorId ];
213  limitedStep = fLimitedStep[ navigatorId ];
214  minStep= fMinStep;
215 
216 #ifdef G4DEBUG_NAVIGATION
217  if( fVerbose > 1 )
218  {
219  G4cout << " G4ITMultiNavigator::ComputeStep returns "
220  << fCurrentStepSize[ navigatorId ]
221  << " for Navigator " << navigatorId
222  << " Limited step = " << limitedStep
223  << " Safety(mm) = " << pNewSafety / mm << G4endl;
224  }
225 #endif
226 
227  return fCurrentStepSize[ navigatorId ];
228 }
229 
230 // ----------------------------------------------------------------------
231 
233  const G4ThreeVector direction )
234 {
235 #ifdef G4DEBUG_NAVIGATION
236  if( fVerbose > 1 )
237  {
238  G4cout << " Entered G4ITMultiNavigator::PrepareNewTrack() " << G4endl;
239  }
240 #endif
241 
243 
244  LocateGlobalPointAndSetup( position, &direction, false, false );
245  //
246  // The first location for each Navigator must be non-relative
247  // or else call ResetStackAndState() for each Navigator
248  // Use direction to get correct side of boundary (ignore dir= false)
249 }
250 
251 // ----------------------------------------------------------------------
252 
254 {
255  // Key purposes:
256  // - Check and cache set of active navigators
257  // - Reset state for new track
258 
259 #ifdef G4DEBUG_NAVIGATION
260  if( fVerbose > 1 )
261  {
262  G4cout << " Entered G4ITMultiNavigator::PrepareNavigators() " << G4endl;
263  }
264 #endif
265 
266  // Message the transportation-manager to find active navigators
267 
268  std::vector<G4ITNavigator*>::iterator pNavigatorIter;
269  fNoActiveNavigators= pTransportManager-> GetNoActiveNavigators();
270 
271  if( fNoActiveNavigators > fMaxNav )
272  {
273  std::ostringstream message;
274  message << "Too many active Navigators / worlds !" << G4endl
275  << " Active Navigators (worlds): "
276  << fNoActiveNavigators << G4endl
277  << " which is more than the number allowed: "
278  << fMaxNav << " !";
279  G4Exception("G4ITMultiNavigator::PrepareNavigators()", "GeomNav0002",
280  FatalException, message);
281  }
282 
283  pNavigatorIter= pTransportManager-> GetActiveNavigatorsIterator();
284  for( G4int num=0; num< fNoActiveNavigators; ++pNavigatorIter,++num )
285  {
286  fpNavigator[num] = *pNavigatorIter;
287  fLimitTruth[num] = false;
288  fLimitedStep[num] = kDoNot;
289  fCurrentStepSize[num] = 0.0;
290  fLocatedVolume[num] = 0;
291  }
292  fWasLimitedByGeometry = false;
293 
294  // Check the world volume of the mass navigator
295  // in case a call to SetWorldVolume() changed it
296 
297  G4VPhysicalVolume* massWorld = GetWorldVolume();
298 
299  if( (massWorld != fLastMassWorld) && (massWorld!=0) )
300  {
301  // Pass along change to Mass Navigator
302  fpNavigator[0] -> SetWorldVolume( massWorld );
303 
304 #ifdef G4DEBUG_NAVIGATION
305  if( fVerbose > 0 )
306  {
307  G4cout << " G4ITMultiNavigator::PrepareNavigators() changed world volume "
308  << " for mass geometry to " << massWorld->GetName() << G4endl;
309  }
310 #endif
311 
312  fLastMassWorld = massWorld;
313  }
314 }
315 
316 // ----------------------------------------------------------------------
317 
320  const G4ThreeVector* pDirection,
321  const G4bool pRelativeSearch,
322  const G4bool ignoreDirection )
323 {
324  // Locate the point in each geometry
325 
326  G4ThreeVector direction(0.0, 0.0, 0.0);
327  G4bool relative = pRelativeSearch;
328  std::vector<G4ITNavigator*>::iterator pNavIter
329  = pTransportManager->GetActiveNavigatorsIterator();
330 
331  if( pDirection ) { direction = *pDirection; }
332 
333 #ifdef G4DEBUG_NAVIGATION
334  if( fVerbose > 2 )
335  {
336  G4cout << " Entered G4ITMultiNavigator::LocateGlobalPointAndSetup() "
337  << G4endl;
338  G4cout << " Locating at position: " << position
339  << ", with direction: " << direction << G4endl
340  << " Relative: " << relative
341  << ", ignore direction: " << ignoreDirection << G4endl;
342  G4cout << " Number of active navigators: " << fNoActiveNavigators
343  << G4endl;
344  }
345 #endif
346 
347  for ( G4int num=0; num< fNoActiveNavigators ; ++pNavIter,++num )
348  {
349  if( fWasLimitedByGeometry && fLimitTruth[num] )
350  {
351  (*pNavIter)->SetGeometricallyLimitedStep();
352  }
353 
354  G4VPhysicalVolume *pLocated
355  = (*pNavIter)->LocateGlobalPointAndSetup( position, &direction,
356  relative, ignoreDirection );
357  // Set the state related to the location
358  //
359  fLocatedVolume[num] = pLocated;
360 
361  // Clear state related to the step
362  //
363  fLimitedStep[num] = kDoNot;
364  fCurrentStepSize[num] = 0.0;
365  fLimitTruth[ num ] = false; // Always clear on locating (see Navigator)
366 
367 #ifdef G4DEBUG_NAVIGATION
368  if( fVerbose > 2 )
369  {
370  G4cout << " Located in world: " << num << ", at: " << position << G4endl
371  << " Used geomLimStp: " << fLimitTruth[num]
372  << ", found in volume: " << pLocated << G4endl;
373  G4cout << " Name = '" ;
374  if( pLocated )
375  {
376  G4cout << pLocated->GetName() << "'";
377  G4cout << " - CopyNo= " << pLocated->GetCopyNo();
378  }
379  else
380  {
381  G4cout << "Null' Id: Not-Set ";
382  }
383  G4cout << G4endl;
384  }
385 #endif
386  }
387 
388  fWasLimitedByGeometry = false; // Clear on locating
389  G4VPhysicalVolume* volMassLocated= fLocatedVolume[0];
390 
391  return volMassLocated;
392 }
393 
394 // ----------------------------------------------------------------------
395 
396 void
398 {
399  // Relocate the point in each geometry
400 
401  std::vector<G4ITNavigator*>::iterator pNavIter
402  = pTransportManager->GetActiveNavigatorsIterator();
403 
404 #ifdef G4DEBUG_NAVIGATION
405  if( fVerbose > 2 )
406  {
407  G4cout << " Entered G4ITMultiNavigator::ReLocate() " << G4endl
408  << " Re-locating at position: " << position << G4endl;
409  }
410 #endif
411 
412  for ( G4int num=0; num< fNoActiveNavigators ; ++pNavIter,++num )
413  {
414  // ... none limited the step
415 
416  (*pNavIter)->LocateGlobalPointWithinVolume( position );
417 
418  // Clear state related to the step
419  //
420  fLimitedStep[num] = kDoNot;
421  fCurrentStepSize[num] = 0.0;
422 
423  fLimitTruth[ num ] = false; // Always clear on locating (see Navigator)
424  }
425  fWasLimitedByGeometry = false; // Clear on locating
427 }
428 
429 // ----------------------------------------------------------------------
430 
432  const G4double maxDistance,
433  const G4bool state)
434 {
435  // Recompute safety for the relevant point
436 
437  G4double minSafety = kInfinity, safety = kInfinity;
438 
439  std::vector<G4ITNavigator*>::iterator pNavigatorIter;
440  pNavigatorIter= pTransportManager-> GetActiveNavigatorsIterator();
441 
442  for( G4int num=0; num< fNoActiveNavigators; ++pNavigatorIter,++num )
443  {
444  safety = (*pNavigatorIter)->ComputeSafety( position, maxDistance, state);
445  if( safety < minSafety ) { minSafety = safety; }
446  }
447 
449  fMinSafety_atSafLocation = minSafety;
450 
451 #ifdef G4DEBUG_NAVIGATION
452  if( fVerbose > 1 )
453  {
454  G4cout << " G4ITMultiNavigator::ComputeSafety - returns: "
455  << minSafety << ", at location: " << position << G4endl;
456  }
457 #endif
458  return minSafety;
459 }
460 
461 // -----------------------------------------------------------------------
462 
465 {
466  G4Exception( "G4ITMultiNavigator::CreateTouchableHistoryHandle()",
467  "GeomNav0001", FatalException,
468  "Getting a touchable from G4ITMultiNavigator is not defined.");
469 
470  G4TouchableHistory* touchHist;
471  touchHist= fpNavigator[0] -> CreateTouchableHistory();
472 
473  G4VPhysicalVolume* locatedVolume= fLocatedVolume[0];
474  if( locatedVolume == 0 )
475  {
476  // Workaround to ensure that the touchable is fixed !! // TODO: fix
477  //
478  touchHist->UpdateYourself( locatedVolume, touchHist->GetHistory() );
479  }
480 
481  return G4TouchableHistoryHandle(touchHist);
482 }
483 
484 // -----------------------------------------------------------------------
485 
487 {
488  // Flag which processes limited the step
489 
490  G4int last=-1;
491  const G4int IdTransport= 0; // Id of Mass Navigator !!
492  G4int noLimited=0;
493  ELimited shared= kSharedOther;
494 
495 #ifdef G4DEBUG_NAVIGATION
496  if( fVerbose > 2 )
497  {
498  G4cout << " Entered G4ITMultiNavigator::WhichLimited() " << G4endl;
499  }
500 #endif
501 
502  // Assume that [IdTransport] is Mass / Transport
503  //
504  G4bool transportLimited = (fCurrentStepSize[IdTransport] == fMinStep)
505  && ( fMinStep!= kInfinity);
506  if( transportLimited )
507  {
508  shared= kSharedTransport;
509  }
510 
511  for ( G4int num= 0; num < fNoActiveNavigators; num++ )
512  {
513  G4bool limitedStep;
514 
515  G4double step= fCurrentStepSize[num];
516 
517  limitedStep = ( step == fMinStep ) && ( step != kInfinity);
518 
519  fLimitTruth[ num ] = limitedStep;
520  if( limitedStep )
521  {
522  noLimited++;
523  fLimitedStep[num] = shared;
524  last= num;
525  }
526  else
527  {
528  fLimitedStep[num] = kDoNot;
529  }
530  }
531  if( (last > -1) && (noLimited == 1 ) )
532  {
533  fLimitedStep[ last ] = kUnique;
534  }
535 
536  fNoLimitingStep= noLimited;
537 
538  return;
539 }
540 
541 // -----------------------------------------------------------------------
542 
543 void
545 {
546  // Report results -- for checking
547 
548  static const G4String StrDoNot("DoNot"), StrUnique("Unique"),
549  StrUndefined("Undefined"),
550  StrSharedTransport("SharedTransport"),
551  StrSharedOther("SharedOther");
552  G4cout << "### G4ITMultiNavigator::PrintLimited() reports: " << G4endl;
553  G4cout << " Minimum step (true): " << fTrueMinStep
554  << ", reported min: " << fMinStep << G4endl;
555 
556 #ifdef G4DEBUG_NAVIGATION
557  if(fVerbose>=2)
558  {
559  G4cout << std::setw(5) << " NavId" << " "
560  << std::setw(12) << " step-size " << " "
561  << std::setw(12) << " raw-size " << " "
562  << std::setw(12) << " pre-safety " << " "
563  << std::setw(15) << " Limited / flag" << " "
564  << std::setw(15) << " World " << " "
565  << G4endl;
566  }
567 #endif
568 
569  for ( G4int num= 0; num < fNoActiveNavigators; num++ )
570  {
571  G4double rawStep = fCurrentStepSize[num];
572  G4double stepLen = fCurrentStepSize[num];
573  if( stepLen > fTrueMinStep )
574  {
575  stepLen = fTrueMinStep; // did not limit (went as far as asked)
576  }
577  G4int oldPrec= G4cout.precision(9);
578 
579  G4cout << std::setw(5) << num << " "
580  << std::setw(12) << stepLen << " "
581  << std::setw(12) << rawStep << " "
582  << std::setw(12) << fNewSafety[num] << " "
583  << std::setw(5) << (fLimitTruth[num] ? "YES" : " NO") << " ";
584  G4String limitedStr;
585  switch ( fLimitedStep[num] )
586  {
587  case kDoNot : limitedStr= StrDoNot; break;
588  case kUnique : limitedStr = StrUnique; break;
589  case kSharedTransport: limitedStr= StrSharedTransport; break;
590  case kSharedOther : limitedStr = StrSharedOther; break;
591  default : limitedStr = StrUndefined; break;
592  }
593  G4cout << " " << std::setw(15) << limitedStr << " ";
594  G4cout.precision(oldPrec);
595 
596  G4ITNavigator *pNav= fpNavigator[ num ];
597  G4String WorldName( "Not-Set" );
598  if (pNav)
599  {
600  G4VPhysicalVolume *pWorld= pNav->GetWorldVolume();
601  if( pWorld )
602  {
603  WorldName = pWorld->GetName();
604  }
605  }
606  G4cout << " " << WorldName ;
607  G4cout << G4endl;
608  }
609 }
610 
611 
612 // -----------------------------------------------------------------------
613 
615 {
616  fWasLimitedByGeometry= false;
617 
618  G4Exception("G4ITMultiNavigator::ResetState()", "GeomNav0001",
620  "Cannot reset state for navigators of G4ITMultiNavigator.");
621 
622  std::vector<G4ITNavigator*>::iterator pNavigatorIter;
623  pNavigatorIter= pTransportManager-> GetActiveNavigatorsIterator();
624  for( G4int num=0; num< fNoActiveNavigators; ++pNavigatorIter,++num )
625  {
626  // (*pNavigatorIter)->ResetState(); // KEEP THIS comment !!!
627  }
628 }
629 
630 // -----------------------------------------------------------------------
631 
633 {
634  G4Exception( "G4ITMultiNavigator::SetupHierarchy()",
635  "GeomNav0001", FatalException,
636  "Cannot setup hierarchy for navigators of G4ITMultiNavigator.");
637 }
638 
639 // -----------------------------------------------------------------------
640 
642 {
643  G4VPhysicalVolume* navTrackWorld=
644  pTransportManager->GetNavigatorForTracking()->GetWorldVolume();
645 
646  if( navTrackWorld != fLastMassWorld )
647  {
648  G4Exception( "G4ITMultiNavigator::CheckMassWorld()",
649  "GeomNav0003", FatalException,
650  "Mass world pointer has been changed." );
651  }
652 }
653 
654 // -----------------------------------------------------------------------
655 
658  const G4ThreeVector &direction,
659  const G4TouchableHistory &MassHistory)
660 {
661  // Reset geometry for all -- and use the touchable for the mass history
662 
663  G4VPhysicalVolume* massVolume=0;
664  G4ITNavigator* pMassNavigator= fpNavigator[0];
665 
666  if( pMassNavigator )
667  {
668  massVolume= pMassNavigator->ResetHierarchyAndLocate( point, direction,
669  MassHistory);
670  }
671  else
672  {
673  G4Exception("G4ITMultiNavigator::ResetHierarchyAndLocate()",
674  "GeomNav0002", FatalException,
675  "Cannot reset hierarchy before navigators are initialised.");
676  }
677 
678  std::vector<G4ITNavigator*>::iterator pNavIter=
679  pTransportManager->GetActiveNavigatorsIterator();
680 
681  for ( G4int num=0; num< fNoActiveNavigators ; ++pNavIter,++num )
682  {
683  G4bool relativeSearch, ignoreDirection;
684 
685  (*pNavIter)-> LocateGlobalPointAndSetup( point,
686  &direction,
687  relativeSearch=false,
688  ignoreDirection=false);
689  }
690  return massVolume;
691 }
692 
693 // ----------------- ooooooOOOOOOOOOOOOOOOoooooo -------------------------------------
694 
697  G4bool* argpObtained) // obtained valid
698 {
699  G4ThreeVector normalGlobalCrd(0.0, 0.0, 0.0);
700  G4bool isObtained= false;
701  // These default values will be used if fNoLimitingStep== 0
702  G4int firstNavigatorId= -1;
703  G4bool oneObtained= false;
704 
705  if( fNoLimitingStep==1 )
706  {
707  // Only message the Navigator which limited the step!
708  normalGlobalCrd= fpNavigator[ fIdNavLimiting ]->GetGlobalExitNormal( argPoint, &isObtained);
709  *argpObtained= isObtained;
710  }
711  else
712  {
713  if( fNoLimitingStep > 1 )
714  {
715  std::vector<G4ITNavigator*>::iterator pNavIter=
716  pTransportManager->GetActiveNavigatorsIterator();
717 
718  for ( G4int num=0; num< fNoActiveNavigators ; ++pNavIter,++num )
719  {
720  G4ThreeVector oneNormal;
721  if( fLimitTruth[ num ] ) // Did this geometry limit the step ?
722  {
723  G4ThreeVector newNormal= (*pNavIter)-> GetGlobalExitNormal( argPoint, &oneObtained );
724  if( oneObtained )
725  {
726  // Keep first one - only if it is valid (ie not null)
727  if( !isObtained && (newNormal.mag2() != 0.0) )
728  {
729  normalGlobalCrd= newNormal;
730  isObtained = oneObtained;
731  firstNavigatorId= num;
732  }else{
733  // Check for clash
734  G4double dotNewPrevious= newNormal.dot( normalGlobalCrd );
735  G4double productMagSq= normalGlobalCrd.mag2() * newNormal.mag2();
736  if( productMagSq > 0.0 )
737  {
738  G4double productMag= std::sqrt( productMagSq );
739  dotNewPrevious /= productMag; // Normalise
740  if( dotNewPrevious < (1 - perThousand) )
741  {
742  *argpObtained= false;
743 
744  if( fVerbose > 2 ) // dotNewPrevious <= 0.0 )
745  {
746  std::ostringstream message;
747  message << "Clash of Normal from different Navigators!" << G4endl
748  << " Previous Navigator Id = " << firstNavigatorId << G4endl
749  << " Current Navigator Id = " << num << G4endl;
750  message << " Dot product of 2 normals = " << dotNewPrevious << G4endl;
751  message << " Normal (previous) = " << normalGlobalCrd << G4endl;
752  message << " Normal (current) = " << newNormal << G4endl;
753  G4Exception("G4ITMultiNavigator::GetGlobalExitNormal()", "GeomNav0002",
754  JustWarning, message);
755  }
756  }
757  else
758  {
759  // Close agreement - Do not change
760  }
761  }
762  }
763  }
764  }
765  } // end for over the Navigators
766 
767  // Report if no Normal was obtained
768  if( !oneObtained )
769  {
770  std::ostringstream message;
771  message << "No Normal obtained despite having " << fNoLimitingStep
772  << " candidate Navigators limiting the step!" << G4endl;
773  G4Exception("G4ITMultiNavigator::GetGlobalExitNormal()", "GeomNav0002",
774  JustWarning, message);
775  }
776 
777  } // end if ( fNoLimiting > 1 )
778  } // end else
779 
780  *argpObtained= isObtained;
781  return normalGlobalCrd;
782 }
783 
784 // ----------------- ooooooOOOOOOOOOOOOOOOoooooo -------------------------------------
785 
788 {
789  // If it is the mass navigator, then expect
790  G4ThreeVector normalGlobalCrd(0.0, 0.0, 0.0);
791  G4bool isObtained= false;
792  // These default values will be used if fNoLimitingStep== 0
793 
794  if( fNoLimitingStep==1 )
795  {
796  // Only message the Navigator which limited the step!
797  normalGlobalCrd= fpNavigator[ fIdNavLimiting ]->GetLocalExitNormal( &isObtained);
798  *argpObtained= isObtained;
799 
800  static G4ThreadLocal G4int numberWarnings= 0;
801  G4int noWarningsStart= 10, noModuloWarnings=100;
802  numberWarnings++;
803  if( (numberWarnings < noWarningsStart ) || (numberWarnings%noModuloWarnings==0) )
804  {
805  std::ostringstream message;
806  message << "Cannot obtain normal in local coordinates of two or more coordinate systems." << G4endl;
807  G4Exception("G4ITMultiNavigator::GetGlobalExitNormal()", "GeomNav0002",
808  JustWarning, message);
809  }
810  }
811  else
812  {
813  if( fNoLimitingStep > 1 )
814  {
815  // Does not make sense - cannot obtain *local* normal in several coordinate systems
816  std::ostringstream message;
817  message << "Cannot obtain normal in local coordinates of two or more coordinate systems." << G4endl;
818  G4Exception("G4ITMultiNavigator::GetGlobalExitNormal()", "GeomNav0002",
819  FatalException, message);
820  }
821  }
822 
823  *argpObtained= isObtained;
824  return normalGlobalCrd;
825 }
826 
827 
828 // ----------------- ooooooOOOOOOOOOOOOOOOoooooo -------------------------------------
829 
832  G4bool* obtained)
833 {
834  return G4ITMultiNavigator::GetLocalExitNormal( obtained);
835 }
virtual G4ThreeVector GetLocalExitNormalAndCheck(const G4ThreeVector &CurrentE_Point, G4bool *obtained)
static constexpr double mm
Definition: G4SIunits.hh:115
#define fSafetyLocation
static const G4double kInfinity
Definition: geomdefs.hh:42
#define fWasLimitedByGeometry
double dot(const Hep3Vector &) const
void LocateGlobalPointWithinVolume(const G4ThreeVector &position)
ELimited
#define fLocatedVolume
#define fIdNavLimiting
G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=0, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
#define fMinSafety_atSafLocation
#define G4ThreadLocal
Definition: tls.hh:89
G4ReferenceCountedHandle< G4TouchableHistory > G4TouchableHistoryHandle
int G4int
Definition: G4Types.hh:78
#define fLastLocatedPosition
void PrepareNewTrack(const G4ThreeVector position, const G4ThreeVector direction)
static G4ITTransportationManager * GetTransportationManager()
#define position
Definition: xmlparse.cc:622
G4GLOB_DLL std::ostream G4cout
#define fLimitTruth
const G4String & GetName() const
#define fTrueMinStep
bool G4bool
Definition: G4Types.hh:79
G4double ComputeSafety(const G4ThreeVector &globalpoint, const G4double pProposedMaxLength=DBL_MAX, const G4bool keepState=false)
#define fPreStepLocation
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4double ObtainFinalStep(G4int navigatorId, G4double &pNewSafety, G4double &minStepLast, ELimited &limitedStep)
virtual G4ThreeVector GetGlobalExitNormal(const G4ThreeVector &CurrentE_Point, G4bool *obtained)
#define fMinStep
#define fLimitedStep
std::vector< G4ITNavigator * >::iterator GetActiveNavigatorsIterator()
G4ITNavigator * GetNavigatorForTracking() const
virtual G4int GetCopyNo() const =0
#define fCurrentStepSize
#define fMinSafety_PreStepPt
double mag2() const
#define G4endl
Definition: G4ios.hh:61
void UpdateYourself(G4VPhysicalVolume *pPhysVol, const G4NavigationHistory *history=0)
static constexpr double perThousand
Definition: G4SIunits.hh:333
const G4NavigationHistory * GetHistory() const
G4VPhysicalVolume * ResetHierarchyAndLocate(const G4ThreeVector &point, const G4ThreeVector &direction, const G4TouchableHistory &h)
#define fNewSafety
double G4double
Definition: G4Types.hh:76
G4double ComputeStep(const G4ThreeVector &pGlobalPoint, const G4ThreeVector &pDirection, const G4double pCurrentProposedStepLength, G4double &pNewSafety)
virtual G4ThreeVector GetLocalExitNormal(G4bool *obtained)
#define fNoLimitingStep
G4TouchableHistoryHandle CreateTouchableHistoryHandle() const