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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 11.0.p1)


  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 // class G4SafetyHelper Implementation             26 // class G4SafetyHelper Implementation
 27 //                                                 27 //
 28 // Original author: John Apostolakis, 2006         28 // Original author: John Apostolakis, 2006
 29 // -------------------------------------------     29 // --------------------------------------------------------------------
 30                                                    30 
 31 #include "G4SafetyHelper.hh"                       31 #include "G4SafetyHelper.hh"
 32 #include "G4PathFinder.hh"                         32 #include "G4PathFinder.hh"
 33 #include "G4TransportationManager.hh"              33 #include "G4TransportationManager.hh"
 34 #include "G4Navigator.hh"                          34 #include "G4Navigator.hh"
 35                                                    35 
 36 #include "globals.hh"                              36 #include "globals.hh"
 37                                                    37 
 38 // ------------------------------------------- << 
 39 G4SafetyHelper::G4SafetyHelper()                   38 G4SafetyHelper::G4SafetyHelper()
 40   : fLastSafetyPosition(0.0,0.0,0.0)               39   : fLastSafetyPosition(0.0,0.0,0.0)
 41 {                                                  40 {
 42 }                                                  41 }
 43                                                    42 
 44 // ------------------------------------------- << 
 45 void G4SafetyHelper::InitialiseNavigator()         43 void G4SafetyHelper::InitialiseNavigator()
 46 {                                                  44 {
 47   fpPathFinder = G4PathFinder::GetInstance();      45   fpPathFinder = G4PathFinder::GetInstance();
 48                                                    46  
 49   G4TransportationManager* pTransportMgr=          47   G4TransportationManager* pTransportMgr= 
 50     G4TransportationManager::GetTransportation     48     G4TransportationManager::GetTransportationManager();
 51                                                    49 
 52   fpMassNavigator = pTransportMgr->GetNavigato     50   fpMassNavigator = pTransportMgr->GetNavigatorForTracking(); 
 53                                                    51 
 54   // Check                                         52   // Check
 55   //                                               53   //
 56   G4VPhysicalVolume* worldPV = fpMassNavigator     54   G4VPhysicalVolume* worldPV = fpMassNavigator->GetWorldVolume(); 
 57   if( worldPV == nullptr )                         55   if( worldPV == nullptr )
 58   {                                                56   { 
 59     G4Exception("G4SafetyHelper::InitialiseNav     57     G4Exception("G4SafetyHelper::InitialiseNavigator",
 60                 "GeomNav0003", FatalException,     58                 "GeomNav0003", FatalException, 
 61                 "Found that existing tracking      59                 "Found that existing tracking Navigator has NULL world"); 
 62   }                                                60   }
                                                   >>  61 
                                                   >>  62   fMassNavigatorId = pTransportMgr->ActivateNavigator( fpMassNavigator ); 
 63 }                                                  63 }
 64                                                    64 
 65 // ------------------------------------------- << 
 66 void G4SafetyHelper::InitialiseHelper()            65 void G4SafetyHelper::InitialiseHelper()
 67 {                                                  66 {
 68   fLastSafetyPosition = G4ThreeVector(0.0,0.0,     67   fLastSafetyPosition = G4ThreeVector(0.0,0.0,0.0);
 69   fLastSafety         = 0.0;                       68   fLastSafety         = 0.0;
 70   if (fFirstCall) { InitialiseNavigator(); }       69   if (fFirstCall) { InitialiseNavigator(); }
 71   fFirstCall = false;                              70   fFirstCall = false;
 72 }                                                  71 }
 73                                                    72 
 74 G4SafetyHelper::~G4SafetyHelper() = default;   <<  73 G4SafetyHelper::~G4SafetyHelper()
                                                   >>  74 {
                                                   >>  75 }
 75                                                    76 
 76 G4double                                           77 G4double   
 77 G4SafetyHelper::CheckNextStep(const G4ThreeVec     78 G4SafetyHelper::CheckNextStep(const G4ThreeVector& position, 
 78                               const G4ThreeVec     79                               const G4ThreeVector& direction,
 79                               const G4double c     80                               const G4double currentMaxStep,
 80                                     G4double&      81                                     G4double& newSafety )
 81 {                                                  82 {  
 82   // Distance in the Mass geometry                 83   // Distance in the Mass geometry
 83   //                                               84   //
 84   G4double linstep = fpMassNavigator->CheckNex     85   G4double linstep = fpMassNavigator->CheckNextStep( position,
 85                                                    86                                                      direction,
 86                                                    87                                                      currentMaxStep,
 87                                                    88                                                      newSafety);
 88   fLastSafetyPosition = position;                  89   fLastSafetyPosition = position;
 89   fLastSafety         = newSafety;                 90   fLastSafety         = newSafety;
 90                                                    91 
 91   // TO-DO: Can replace this with a call to Pa     92   // TO-DO: Can replace this with a call to PathFinder 
 92   //        giving id of Mass Geometry --> thi     93   //        giving id of Mass Geometry --> this avoid doing the work twice
 93                                                    94 
 94   return linstep;                                  95   return linstep;
 95 }                                                  96 }
 96                                                    97 
 97 // ------------------------------------------- << 
 98 G4double G4SafetyHelper::ComputeSafety( const      98 G4double G4SafetyHelper::ComputeSafety( const G4ThreeVector& position,
 99                                                    99                                               G4double maxLength )
100 {                                                 100 {
101   G4double newSafety;                             101   G4double newSafety;
102                                                   102   
103   // Only recompute (calling Navigator/PathFin    103   // Only recompute (calling Navigator/PathFinder) if 'position'
104   // is  *not* the safety location and has mov    104   // is  *not* the safety location and has moved 'significantly'
105   //                                              105   //
106   G4double moveLengthSq = (position-fLastSafet    106   G4double moveLengthSq = (position-fLastSafetyPosition).mag2();
107   if(   (moveLengthSq > 0.0 ) )                   107   if(   (moveLengthSq > 0.0 ) )
108   {                                               108   {
109     if( !fUseParallelGeometries )                 109     if( !fUseParallelGeometries )
110     {                                             110     {
111       // Safety for mass geometry                 111       // Safety for mass geometry
112       newSafety = fpMassNavigator->ComputeSafe    112       newSafety = fpMassNavigator->ComputeSafety(position, maxLength, true);
113                                                   113 
114       // Only store a 'true' safety - one that    114       // Only store a 'true' safety - one that was not restricted by maxLength
115       if( newSafety < maxLength )                 115       if( newSafety < maxLength )
116       {                                           116       {
117          fLastSafety= newSafety;                  117          fLastSafety= newSafety;
118          fLastSafetyPosition = position;          118          fLastSafetyPosition = position;
119       }                                           119       }
120     }                                             120     }
121     else                                          121     else
122     {                                             122     {
123       // Safety for all geometries                123       // Safety for all geometries
124       newSafety = fpPathFinder->ComputeSafety(    124       newSafety = fpPathFinder->ComputeSafety(position);
125                                                   125 
126       fLastSafety= newSafety;                     126       fLastSafety= newSafety;
127       fLastSafetyPosition = position;             127       fLastSafetyPosition = position;
128     }                                             128     } 
129                                                   129  
130   }                                               130   }
131   else                                            131   else
132   {                                               132   {
133     // return last value if position is not (s    133     // return last value if position is not (significantly) changed
134     //                                            134     //
135     // G4double moveLength = 0;                   135     // G4double moveLength = 0;
136     // if( moveLengthSq > 0.0 ) { moveLength=     136     // if( moveLengthSq > 0.0 ) { moveLength= std::sqrt(moveLengthSq); }
137     newSafety = fLastSafety; // -moveLength;      137     newSafety = fLastSafety; // -moveLength;
138   }                                               138   }
139                                                   139   
140   return newSafety;                               140   return newSafety;
141 }                                                 141 }
142                                                   142 
143 // ------------------------------------------- << 
144 void G4SafetyHelper::ReLocateWithinVolume( con    143 void G4SafetyHelper::ReLocateWithinVolume( const G4ThreeVector& newPosition )
145 {                                                 144 {
146 #ifdef G4VERBOSE                                  145 #ifdef G4VERBOSE
147   if( fVerbose > 0 )                              146   if( fVerbose > 0 )
148   {                                               147   {
149     // There is an opportunity - and need - to    148     // There is an opportunity - and need - to check whether
150     // the proposed move is safe                  149     // the proposed move is safe
151     G4ThreeVector moveVec = newPosition - fLas    150     G4ThreeVector moveVec = newPosition - fLastSafetyPosition;
152     if( moveVec.mag2() > sqr(fLastSafety) )       151     if( moveVec.mag2() > sqr(fLastSafety) )
153     {                                             152     {
154       // A problem exists - we are proposing t    153       // A problem exists - we are proposing to move outside 'Safety Sphere'
155       G4ExceptionDescription ed;                  154       G4ExceptionDescription ed;
156       ed << "Unsafe Move> Asked to relocate be    155       ed << "Unsafe Move> Asked to relocate beyond 'Safety sphere'.  Details: "
157          << G4endl;                               156          << G4endl;
158       ed << " Safety Sphere:  Radius = " << fL    157       ed << " Safety Sphere:  Radius = " << fLastSafety;
159       ed << " Center   = " << fLastSafetyPosit    158       ed << " Center   = " << fLastSafetyPosition << G4endl;
160       ed << " New Location :  Move   = " << mo    159       ed << " New Location :  Move   = " << moveVec.mag();
161       ed << " Position = " << newPosition << G    160       ed << " Position = " << newPosition << G4endl;
162       G4Exception("G4SafetyHelper::ReLocateWit    161       G4Exception("G4SafetyHelper::ReLocateWithinVolume",
163                   "GeomNav1001", JustWarning,     162                   "GeomNav1001", JustWarning, ed);
164     }                                             163     }
165   }                                               164   }
166 #endif                                            165 #endif
167                                                   166    
168   if( !fUseParallelGeometries )                   167   if( !fUseParallelGeometries )
169   {                                               168   {
170     fpMassNavigator->LocateGlobalPointWithinVo    169     fpMassNavigator->LocateGlobalPointWithinVolume( newPosition ); 
171   }                                               170   }
172   else                                            171   else
173   {                                               172   {
174     fpPathFinder->ReLocate( newPosition );        173     fpPathFinder->ReLocate( newPosition ); 
175   }                                               174   }
176 }                                                 175 }
177                                                   176 
178 // ------------------------------------------- << 
179 void  G4SafetyHelper::Locate( const G4ThreeVec    177 void  G4SafetyHelper::Locate( const G4ThreeVector& newPosition, 
180                               const G4ThreeVec    178                               const G4ThreeVector& newDirection)
181 {                                                 179 {
182   if( !fUseParallelGeometries )                   180   if( !fUseParallelGeometries )
183   {                                               181   {
184     fpMassNavigator->LocateGlobalPointAndSetup    182     fpMassNavigator->LocateGlobalPointAndSetup(newPosition, &newDirection,
185                                                   183                                                true, false); 
186   }                                               184   }
187   else                                            185   else
188   {                                               186   {
189     fpPathFinder->Locate( newPosition, newDire    187     fpPathFinder->Locate( newPosition, newDirection ); 
190   }                                               188   }
191 }                                                 189 }
192                                                   190