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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /geometry/navigation/src/G4SafetyHelper.cc (Version 11.3.0) and /geometry/navigation/src/G4SafetyHelper.cc (Version 10.4.p3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
                                                   >>  26 // $Id$
                                                   >>  27 // GEANT4 tag $ Name:  $
                                                   >>  28 // 
 26 // class G4SafetyHelper Implementation             29 // class G4SafetyHelper Implementation
 27 //                                                 30 //
 28 // Original author: John Apostolakis, 2006         31 // Original author: John Apostolakis, 2006
                                                   >>  32 //
 29 // -------------------------------------------     33 // --------------------------------------------------------------------
 30                                                    34 
 31 #include "G4SafetyHelper.hh"                       35 #include "G4SafetyHelper.hh"
 32 #include "G4PathFinder.hh"                         36 #include "G4PathFinder.hh"
 33 #include "G4TransportationManager.hh"              37 #include "G4TransportationManager.hh"
 34 #include "G4Navigator.hh"                          38 #include "G4Navigator.hh"
 35                                                    39 
 36 #include "globals.hh"                              40 #include "globals.hh"
 37                                                    41 
 38 // ------------------------------------------- << 
 39 G4SafetyHelper::G4SafetyHelper()                   42 G4SafetyHelper::G4SafetyHelper()
 40   : fLastSafetyPosition(0.0,0.0,0.0)           <<  43  : fUseParallelGeometries(false),     // By default, one geometry only
                                                   >>  44    fFirstCall(true),
                                                   >>  45    fVerbose(0), 
                                                   >>  46    fLastSafetyPosition(0.0,0.0,0.0),
                                                   >>  47    fLastSafety(0.0)
                                                   >>  48    // fRecomputeFactor(0.0)
 41 {                                                  49 {
                                                   >>  50   fpPathFinder= 0; //  Cannot initialise this yet - a loop results
                                                   >>  51 
                                                   >>  52   // Initialization of the Navigator pointer is postponed, and must
                                                   >>  53   // be undertaken by another class calling InitialiseHelper()
                                                   >>  54   //
                                                   >>  55   fpMassNavigator= 0;  
                                                   >>  56   fMassNavigatorId= -1; 
 42 }                                                  57 }
 43                                                    58 
 44 // ------------------------------------------- << 
 45 void G4SafetyHelper::InitialiseNavigator()         59 void G4SafetyHelper::InitialiseNavigator()
 46 {                                                  60 {
 47   fpPathFinder = G4PathFinder::GetInstance();  <<  61   fpPathFinder= G4PathFinder::GetInstance();
 48                                                    62  
 49   G4TransportationManager* pTransportMgr=          63   G4TransportationManager* pTransportMgr= 
 50     G4TransportationManager::GetTransportation     64     G4TransportationManager::GetTransportationManager();
 51                                                    65 
 52   fpMassNavigator = pTransportMgr->GetNavigato     66   fpMassNavigator = pTransportMgr->GetNavigatorForTracking(); 
 53                                                    67 
 54   // Check                                         68   // Check
 55   //                                               69   //
 56   G4VPhysicalVolume* worldPV = fpMassNavigator     70   G4VPhysicalVolume* worldPV = fpMassNavigator->GetWorldVolume(); 
 57   if( worldPV == nullptr )                     <<  71   if( worldPV == 0 )
 58   {                                                72   { 
 59     G4Exception("G4SafetyHelper::InitialiseNav     73     G4Exception("G4SafetyHelper::InitialiseNavigator",
 60                 "GeomNav0003", FatalException, <<  74                 "InvalidNavigatorWorld", FatalException, 
 61                 "Found that existing tracking      75                 "Found that existing tracking Navigator has NULL world"); 
 62   }                                                76   }
                                                   >>  77 
                                                   >>  78   fMassNavigatorId = pTransportMgr->ActivateNavigator( fpMassNavigator ); 
 63 }                                                  79 }
 64                                                    80 
 65 // ------------------------------------------- << 
 66 void G4SafetyHelper::InitialiseHelper()            81 void G4SafetyHelper::InitialiseHelper()
 67 {                                                  82 {
 68   fLastSafetyPosition = G4ThreeVector(0.0,0.0,     83   fLastSafetyPosition = G4ThreeVector(0.0,0.0,0.0);
 69   fLastSafety         = 0.0;                       84   fLastSafety         = 0.0;
 70   if (fFirstCall) { InitialiseNavigator(); }       85   if (fFirstCall) { InitialiseNavigator(); }
 71   fFirstCall = false;                              86   fFirstCall = false;
 72 }                                                  87 }
 73                                                    88 
 74 G4SafetyHelper::~G4SafetyHelper() = default;   <<  89 G4SafetyHelper::~G4SafetyHelper()
                                                   >>  90 {
                                                   >>  91 }
 75                                                    92 
 76 G4double                                           93 G4double   
 77 G4SafetyHelper::CheckNextStep(const G4ThreeVec <<  94 G4SafetyHelper::CheckNextStep(const G4ThreeVector &position, 
 78                               const G4ThreeVec <<  95                               const G4ThreeVector &direction,
 79                               const G4double c     96                               const G4double currentMaxStep,
 80                                     G4double&      97                                     G4double& newSafety )
 81 {                                                  98 {  
 82   // Distance in the Mass geometry                 99   // Distance in the Mass geometry
 83   //                                              100   //
 84   G4double linstep = fpMassNavigator->CheckNex    101   G4double linstep = fpMassNavigator->CheckNextStep( position,
 85                                                   102                                                      direction,
 86                                                   103                                                      currentMaxStep,
 87                                                   104                                                      newSafety);
 88   fLastSafetyPosition = position;                 105   fLastSafetyPosition = position;
 89   fLastSafety         = newSafety;                106   fLastSafety         = newSafety;
 90                                                   107 
 91   // TO-DO: Can replace this with a call to Pa    108   // TO-DO: Can replace this with a call to PathFinder 
 92   //        giving id of Mass Geometry --> thi    109   //        giving id of Mass Geometry --> this avoid doing the work twice
 93                                                   110 
 94   return linstep;                                 111   return linstep;
 95 }                                                 112 }
 96                                                   113 
 97 // ------------------------------------------- << 114 G4double G4SafetyHelper::ComputeSafety( const G4ThreeVector& position, G4double maxLength )
 98 G4double G4SafetyHelper::ComputeSafety( const  << 
 99                                                << 
100 {                                                 115 {
101   G4double newSafety;                             116   G4double newSafety;
102                                                   117   
103   // Only recompute (calling Navigator/PathFin    118   // Only recompute (calling Navigator/PathFinder) if 'position'
104   // is  *not* the safety location and has mov    119   // is  *not* the safety location and has moved 'significantly'
105   //                                              120   //
106   G4double moveLengthSq = (position-fLastSafet    121   G4double moveLengthSq = (position-fLastSafetyPosition).mag2();
107   if(   (moveLengthSq > 0.0 ) )                   122   if(   (moveLengthSq > 0.0 ) )
108   {                                               123   {
109     if( !fUseParallelGeometries )                 124     if( !fUseParallelGeometries )
110     {                                             125     {
111       // Safety for mass geometry                 126       // Safety for mass geometry
112       newSafety = fpMassNavigator->ComputeSafe    127       newSafety = fpMassNavigator->ComputeSafety(position, maxLength, true);
113                                                   128 
114       // Only store a 'true' safety - one that    129       // Only store a 'true' safety - one that was not restricted by maxLength
115       if( newSafety < maxLength )                 130       if( newSafety < maxLength )
116       {                                           131       {
117          fLastSafety= newSafety;                  132          fLastSafety= newSafety;
118          fLastSafetyPosition = position;          133          fLastSafetyPosition = position;
119       }                                           134       }
120     }                                             135     }
121     else                                          136     else
122     {                                             137     {
123       // Safety for all geometries                138       // Safety for all geometries
124       newSafety = fpPathFinder->ComputeSafety(    139       newSafety = fpPathFinder->ComputeSafety(position);
125                                                   140 
126       fLastSafety= newSafety;                     141       fLastSafety= newSafety;
127       fLastSafetyPosition = position;             142       fLastSafetyPosition = position;
128     }                                             143     } 
129                                                   144  
130   }                                               145   }
131   else                                            146   else
132   {                                               147   {
133     // return last value if position is not (s    148     // return last value if position is not (significantly) changed
134     //                                            149     //
135     // G4double moveLength = 0;                   150     // G4double moveLength = 0;
136     // if( moveLengthSq > 0.0 ) { moveLength=     151     // if( moveLengthSq > 0.0 ) { moveLength= std::sqrt(moveLengthSq); }
137     newSafety = fLastSafety; // -moveLength;      152     newSafety = fLastSafety; // -moveLength;
138   }                                               153   }
139                                                   154   
140   return newSafety;                               155   return newSafety;
141 }                                                 156 }
142                                                   157 
143 // ------------------------------------------- << 158 void G4SafetyHelper::ReLocateWithinVolume( const G4ThreeVector &newPosition )
144 void G4SafetyHelper::ReLocateWithinVolume( con << 
145 {                                                 159 {
                                                   >> 160    // G4cout << " G4SafetyHelper::ReLocateWithinVolume called at " << newPosition << G4endl;
146 #ifdef G4VERBOSE                                  161 #ifdef G4VERBOSE
147   if( fVerbose > 0 )                           << 162   if( fVerbose > 0 ) {
148   {                                            << 163     // There is an opportunity - and need - to check whether the proposed move is safe
149     // There is an opportunity - and need - to << 164     G4ThreeVector moveVec= newPosition - fLastSafetyPosition;
150     // the proposed move is safe               << 
151     G4ThreeVector moveVec = newPosition - fLas << 
152     if( moveVec.mag2() > sqr(fLastSafety) )       165     if( moveVec.mag2() > sqr(fLastSafety) )
153     {                                             166     {
154       // A problem exists - we are proposing t    167       // A problem exists - we are proposing to move outside 'Safety Sphere'
155       G4ExceptionDescription ed;                  168       G4ExceptionDescription ed;
156       ed << "Unsafe Move> Asked to relocate be << 169       ed << "Unsafe Move> Asked to relocate beyond 'Safety sphere'.  Details: " << G4endl;
157          << G4endl;                            << 
158       ed << " Safety Sphere:  Radius = " << fL    170       ed << " Safety Sphere:  Radius = " << fLastSafety;
159       ed << " Center   = " << fLastSafetyPosit    171       ed << " Center   = " << fLastSafetyPosition << G4endl;
160       ed << " New Location :  Move   = " << mo    172       ed << " New Location :  Move   = " << moveVec.mag();
161       ed << " Position = " << newPosition << G    173       ed << " Position = " << newPosition << G4endl;
162       G4Exception("G4SafetyHelper::ReLocateWit << 174       G4Exception("G4SafetyHelper::ReLocateWithinVolume", "GeomNav999", JustWarning, ed);
163                   "GeomNav1001", JustWarning,  << 
164     }                                             175     }
165   }                                               176   }
166 #endif                                            177 #endif
167                                                   178    
168   if( !fUseParallelGeometries )                   179   if( !fUseParallelGeometries )
169   {                                               180   {
170     fpMassNavigator->LocateGlobalPointWithinVo    181     fpMassNavigator->LocateGlobalPointWithinVolume( newPosition ); 
171   }                                               182   }
172   else                                            183   else
173   {                                               184   {
174     fpPathFinder->ReLocate( newPosition );        185     fpPathFinder->ReLocate( newPosition ); 
175   }                                               186   }
176 }                                                 187 }
177                                                   188 
178 // ------------------------------------------- << 
179 void  G4SafetyHelper::Locate( const G4ThreeVec    189 void  G4SafetyHelper::Locate( const G4ThreeVector& newPosition, 
180                               const G4ThreeVec    190                               const G4ThreeVector& newDirection)
181 {                                                 191 {
182   if( !fUseParallelGeometries )                << 192   if( !fUseParallelGeometries)
183   {                                               193   {
184     fpMassNavigator->LocateGlobalPointAndSetup    194     fpMassNavigator->LocateGlobalPointAndSetup(newPosition, &newDirection,
185                                                   195                                                true, false); 
186   }                                               196   }
187   else                                            197   else
188   {                                               198   {
189     fpPathFinder->Locate( newPosition, newDire    199     fpPathFinder->Locate( newPosition, newDirection ); 
190   }                                               200   }
191 }                                                 201 }
                                                   >> 202 
                                                   >> 203 G4bool G4SafetyHelper::RecheckDistanceToCurrentBoundary(
                                                   >> 204                                         const G4ThreeVector &pGlobalPoint,
                                                   >> 205                                         const G4ThreeVector &pDirection,
                                                   >> 206                                         const G4double aProposedMove,
                                                   >> 207                                         G4double  *prDistance,
                                                   >> 208                                         G4double  *prNewSafety) const
                                                   >> 209 {
                                                   >> 210   G4bool retval;
                                                   >> 211   if( !fUseParallelGeometries)
                                                   >> 212   {
                                                   >> 213     retval= fpMassNavigator->RecheckDistanceToCurrentBoundary(
                                                   >> 214                                                               pGlobalPoint,
                                                   >> 215                                                               pDirection,
                                                   >> 216                                                               aProposedMove,
                                                   >> 217                                                               prDistance,
                                                   >> 218                                                               prNewSafety);
                                                   >> 219   }
                                                   >> 220   else
                                                   >> 221   {
                                                   >> 222     //G4Exception("G4Navigator::RecheckDistanceToCurrentBoundary()", "GeomNav0001",
                                                   >> 223     //  JustWarning, "Method NOT Available (yet) in case of Multiple Geometries (where PathFinder is involved.).");
                                                   >> 224     retval= fpPathFinder->RecheckDistanceToCurrentBoundary(
                                                   >> 225                                                               pGlobalPoint,
                                                   >> 226                                                                pDirection,
                                                   >> 227                                                               aProposedMove,
                                                   >> 228                                                               prDistance,
                                                   >> 229                                                               prNewSafety);
                                                   >> 230   }
                                                   >> 231   return retval;
                                                   >> 232 }
                                                   >> 233 
192                                                   234