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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 9.0.p2)


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