G4PathFinder.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 // 
00028 // class G4PathFinder 
00029 //
00030 // Class description:
00031 // 
00032 // This class directs the lock-stepped propagation of a track in the 
00033 // 'mass' and other parallel geometries.  It ensures that tracking 
00034 // in a magnetic field sees these parallel geometries at each trial step, 
00035 // and that the earliest boundary limits the step.
00036 // 
00037 // For the movement in field, it relies on the class G4PropagatorInField
00038 //
00039 // History:
00040 // -------
00041 //  7.10.05 John Apostolakis,  Draft design 
00042 // 26.04.06 John Apostolakis,  Revised design and first implementation 
00043 // ---------------------------------------------------------------------------
00044 #ifndef G4PATHFINDER_HH 
00045 #define G4PATHFINDER_HH  1
00046 
00047 #include <vector>
00048 #include "G4Types.hh"
00049 
00050 #include "G4FieldTrack.hh"
00051 
00052 class G4TransportationManager; 
00053 class G4Navigator;
00054 
00055 #include "G4TouchableHandle.hh"
00056 #include "G4FieldTrack.hh"
00057 #include "G4MultiNavigator.hh"
00058 
00059 class G4PropagatorInField;
00060 
00061 class G4PathFinder
00062 {
00063 
00064  public:  // with description
00065 
00066    static G4PathFinder* GetInstance();
00067      //
00068      // Retrieve singleton instance
00069 
00070    G4double ComputeStep( const G4FieldTrack &pFieldTrack,
00071                          G4double  pCurrentProposedStepLength,
00072                          G4int     navigatorId, // Identifies the geometry
00073                          G4int     stepNo,      // See next step/check 
00074                          G4double &pNewSafety,  // Only for this geometry
00075                          ELimited &limitedStep,      
00076                          G4FieldTrack       &EndState, 
00077                          G4VPhysicalVolume*  currentVolume );
00078      //
00079      // Compute the next geometric Step  -- Curved or linear
00080      //   If it is called with a larger 'stepNo' it will execute a new step;
00081      //   if 'stepNo' is same as last call, then the results for 
00082      //   the geometry with Id. number 'navigatorId' will be returned. 
00083 
00084    void Locate( const G4ThreeVector& position, 
00085                 const G4ThreeVector& direction,
00086                       G4bool  relativeSearch=true); 
00087      //
00088      // Make primary relocation of global point in all navigators,
00089      // and update them.
00090 
00091    void ReLocate( const G4ThreeVector& position ); 
00092      //
00093      // Make secondary relocation of global point (within safety only) 
00094      // in all navigators, and update them.
00095 
00096    void PrepareNewTrack( const G4ThreeVector& position,
00097                          const G4ThreeVector& direction,
00098                                G4VPhysicalVolume* massStartVol=0); 
00099      //
00100      // Check and cache set of active navigators.
00101 
00102    G4TouchableHandle CreateTouchableHandle( G4int navId ) const;
00103    inline G4VPhysicalVolume* GetLocatedVolume( G4int navId ) const; 
00104 
00105    // -----------------------------------------------------------------
00106 
00107    inline void SetChargeMomentumMass( G4double charge,     // in e+ units
00108                                       G4double momentum,   // in Geant4 units
00109                                       G4double pMass );  
00110 
00111    inline G4bool   IsParticleLooping() const;
00112 
00113    inline G4double GetCurrentSafety() const;
00114      // Minimum value of safety after last ComputeStep
00115    inline G4double GetMinimumStep() const;      
00116      // Get the minimum step size from the last ComputeStep call
00117      //   - in case full step is taken, this is kInfinity
00118    inline unsigned int  GetNumberGeometriesLimitingStep() const; 
00119 
00120    G4double ComputeSafety( const G4ThreeVector& globalPoint); 
00121      // Recompute safety for the relevant point the endpoint of the last step!!
00122      // Maintain vector of individual safety values (for next method)
00123 
00124    G4double ObtainSafety( G4int navId, G4ThreeVector& globalCenterPoint );
00125      // Obtain safety for navigator/geometry navId for last point 'computed'
00126      //   --> last point for which ComputeSafety was called
00127      //   Returns the point (center) for which this safety is valid
00128 
00129    void EnableParallelNavigation( G4bool enableChoice=true ); 
00130      //
00131      // Must call it to ensure that PathFinder is prepared,  
00132      // especially for curved tracks. If true it switches PropagatorInField
00133      // to use MultiNavigator. Must call it with false to undo (=PiF use
00134      // Navigator for tracking!)
00135 
00136    inline G4int  SetVerboseLevel(G4int lev=-1);
00137 
00138  public:  // with description
00139 
00140    inline G4int   GetMaxLoopCount() const;
00141    inline void    SetMaxLoopCount( G4int new_max );
00142      //
00143      // A maximum for the number of steps that a (looping) particle can take.
00144 
00145  public:  // without description
00146 
00147    inline void MovePoint();
00148      //
00149      // Signal that location will be moved -- internal use primarily
00150 
00151    // To provide best compatibility between Coupled and Old Transportation
00152    //   the next two methods are provided:
00153    G4double LastPreSafety( G4int navId, G4ThreeVector& globalCenterPoint, G4double& minSafety ); 
00154      // Obtain last safety needed in ComputeStep (for geometry navId)
00155      //   --> last point at which ComputeStep recalculated safety
00156      //   Returns the point (center) for which this safety is valid
00157      //    and also the minimum safety over all navigators (ie full)
00158 
00159    void PushPostSafetyToPreSafety(); 
00160      // Tell PathFinder to copy PostStep Safety to PreSafety (for use at next step)
00161 
00162    G4String& LimitedString( ELimited lim );
00163      // Convert ELimited to string
00164 
00165  protected:  // without description
00166 
00167   G4double  DoNextLinearStep(  const G4FieldTrack  &FieldTrack,
00168                                G4double            proposedStepLength); 
00169 
00170   G4double  DoNextCurvedStep(  const G4FieldTrack  &FieldTrack,
00171                                G4double            proposedStepLength,
00172                                G4VPhysicalVolume*  pCurrentPhysVolume); 
00173 
00174   void WhichLimited();
00175   void PrintLimited();
00176   //
00177   // Print key details out - for debugging
00178 
00179   // void ClearState();
00180   //
00181   // Clear all the State of this class and its current associates
00182 
00183   inline G4bool UseSafetyForOptimization( G4bool );
00184   //
00185   // Whether use safety to discard unneccesary calls to navigator
00186 
00187   void ReportMove( const G4ThreeVector& OldV, const G4ThreeVector& NewV, const G4String& Quantity ) const; 
00188   // Helper method to report movement (likely of initial point)
00189 
00190  protected:
00191 
00192    G4PathFinder();  //  Singleton 
00193   ~G4PathFinder();
00194 
00195   inline G4Navigator* GetNavigator(G4int n) const;
00196 
00197  private:
00198 
00199   // ----------------------------------------------------------------------
00200   //  DATA Members
00201   // ----------------------------------------------------------------------
00202 
00203    G4MultiNavigator *fpMultiNavigator; 
00204    //
00205    //  Object that enables G4PropagatorInField to see many geometries
00206 
00207    G4int   fNoActiveNavigators; 
00208    G4bool  fNewTrack;               // Flag a new track (ensure first step)
00209 
00210    static const G4int fMaxNav = 8;  // rename to kMaxNoNav ??
00211 
00212    // Global state (retained during stepping for one track)
00213 
00214    G4Navigator*  fpNavigator[fMaxNav];
00215 
00216    // State changed in a step computation
00217 
00218    ELimited      fLimitedStep[fMaxNav];
00219    G4bool        fLimitTruth[fMaxNav];
00220    G4double      fCurrentStepSize[fMaxNav]; 
00221    G4int         fNoGeometriesLimiting;  //  How many processes contribute to limit
00222 
00223    G4ThreeVector fPreSafetyLocation;    //  last initial position for which safety evaluated
00224    G4double      fPreSafetyMinValue;    //   /\ corresponding value of full safety
00225    G4double      fPreSafetyValues[ fMaxNav ]; //   Safeties for the above point
00226    // This part of the state can be retained for severall calls --> CARE
00227 
00228    G4ThreeVector fPreStepLocation;      //  point where last ComputeStep called
00229    G4double      fMinSafety_PreStepPt;  //   /\ corresponding value of full safety
00230    G4double      fCurrentPreStepSafety[ fMaxNav ]; //   Safeties for the above point
00231    // This changes at each step, 
00232    //   so it can differ when steps inside min-safety are made
00233 
00234    G4bool        fPreStepCenterRenewed;   // Whether PreSafety coincides with PreStep point 
00235 
00236    G4double      fMinStep;      // As reported by Navigators -- can be kInfinity
00237    G4double      fTrueMinStep;  // Corrected in case >= proposed
00238 
00239    // State after calling 'locate'
00240 
00241    G4VPhysicalVolume* fLocatedVolume[fMaxNav];
00242    G4ThreeVector      fLastLocatedPosition; 
00243 
00244    // State after calling 'ComputeStep' (others member variables will be affected)
00245    G4FieldTrack    fEndState;           // Point, velocity, ... at proposed step end
00246    G4bool          fFieldExertedForce;  // In current proposed step
00247 
00248    G4bool fRelocatedPoint;   //  Signals that point was or is being moved 
00249                              //  from the position of the last location
00250                              //   or the endpoint resulting from ComputeStep 
00251                              //   -- invalidates fEndState
00252 
00253    // State for 'ComputeSafety' and related methods
00254    G4ThreeVector fSafetyLocation;       //  point where ComputeSafety is called
00255    G4double      fMinSafety_atSafLocation; // /\ corresponding value of safety
00256    G4double      fNewSafetyComputed[ fMaxNav ];  // Safeties for last ComputeSafety
00257 
00258    // State for Step numbers 
00259    G4int         fLastStepNo, fCurrentStepNo; 
00260 
00261    G4int         fVerboseLevel;            // For debuging purposes
00262 
00263    G4TransportationManager* fpTransportManager; // Cache for frequent use
00264    G4PropagatorInField* fpFieldPropagator;
00265 
00266    G4double kCarTolerance;
00267 
00268    static G4PathFinder* fpPathFinder;
00269 };
00270 
00271 // ********************************************************************
00272 // Inline methods.
00273 // ********************************************************************
00274 
00275 inline G4VPhysicalVolume* G4PathFinder::GetLocatedVolume( G4int navId ) const
00276 {
00277   G4VPhysicalVolume* vol=0;  
00278   if( (navId < fMaxNav) && (navId >=0) ) { vol= fLocatedVolume[navId]; }
00279   return vol; 
00280 }
00281 
00282 inline G4int  G4PathFinder::SetVerboseLevel(G4int newLevel)
00283 {
00284   G4int old= fVerboseLevel;  fVerboseLevel= newLevel; return old;
00285 }
00286 
00287 inline G4double G4PathFinder::GetMinimumStep() const
00288 { 
00289   return fMinStep; 
00290 } 
00291 
00292 inline unsigned int G4PathFinder::GetNumberGeometriesLimitingStep() const
00293 {
00294   unsigned int noGeometries=fNoGeometriesLimiting;
00295   return noGeometries; 
00296 }
00297 
00298 inline G4double G4PathFinder::GetCurrentSafety() const
00299 {
00300   return fMinSafety_PreStepPt;
00301 }
00302 
00303 inline void G4PathFinder::MovePoint()
00304 {
00305   fRelocatedPoint= true;
00306 }
00307 
00308 inline G4Navigator* G4PathFinder::GetNavigator(G4int n) const
00309 { 
00310   if( (n>fNoActiveNavigators)||(n<0)) { n=0; }
00311   return fpNavigator[n];
00312 }
00313 
00314 inline G4double      G4PathFinder::ObtainSafety( G4int navId, G4ThreeVector& globalCenterPoint )
00315 {
00316   globalCenterPoint= fSafetyLocation; 
00317   //  navId = std::min( navId, fMaxNav-1 ); 
00318   return  fNewSafetyComputed[ navId ];
00319 }
00320 
00321 inline G4double  G4PathFinder::LastPreSafety( G4int navId, 
00322                                               G4ThreeVector& globalCenterPoint, 
00323                                               G4double& minSafety )
00324 {
00325   globalCenterPoint= fPreSafetyLocation;
00326   minSafety=         fPreSafetyMinValue;
00327   //  navId = std::min( navId, fMaxNav-1 ); 
00328   return  fPreSafetyValues[ navId ];
00329 }
00330 #endif 

Generated on Mon May 27 17:49:17 2013 for Geant4 by  doxygen 1.4.7