Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-12 09:11:55

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 // 
0026 // G4VoxelNavigation
0027 //
0028 // Class description:
0029 //
0030 // Utility for navigation in volumes containing only G4PVPlacement
0031 // daughter volumes for which voxels have been constructed.
0032 
0033 // Author: Paul Kent (CERN), August 1996
0034 // --------------------------------------------------------------------
0035 #ifndef G4VOXELNAVIGATION_HH
0036 #define G4VOXELNAVIGATION_HH 1
0037 
0038 #include "geomdefs.hh"
0039 #include "G4VNavigation.hh"
0040 #include "G4NavigationHistory.hh"
0041 #include "G4NavigationLogger.hh"
0042 #include "G4AffineTransform.hh"
0043 #include "G4VPhysicalVolume.hh"
0044 #include "G4LogicalVolume.hh"
0045 #include "G4VSolid.hh"
0046 #include "G4ThreeVector.hh"
0047 
0048 #include "G4BlockingList.hh"
0049 
0050 class G4VoxelSafety; 
0051 
0052 // Required for inline implementation
0053 //
0054 #include "G4AuxiliaryNavServices.hh"
0055 
0056 // Required for voxel handling & voxel stack
0057 //
0058 #include <vector>
0059 #include "G4SmartVoxelProxy.hh"
0060 #include "G4SmartVoxelNode.hh"
0061 #include "G4SmartVoxelHeader.hh"
0062 
0063 /**
0064  * @brief G4VoxelNavigation is a concrete utility class for navigation in
0065  * volumes containing only G4PVPlacement daughter volumes for which voxels
0066  * have been constructed.
0067  */
0068 
0069 class G4VoxelNavigation : public G4VNavigation
0070 {
0071   public:
0072 
0073     /**
0074      * Constructor and Destructor.
0075      */
0076     G4VoxelNavigation();
0077     ~G4VoxelNavigation() override;
0078 
0079     /**
0080      * Locates voxel node based on given point.
0081      *  @param[in] pHead Pointer to header of nodes to look through.
0082      *  @param[in] localPoint Local point
0083      *  @returns Pointer to the node where the given point is located.
0084      */
0085     inline G4SmartVoxelNode* VoxelLocate( G4SmartVoxelHeader* pHead,
0086                                     const G4ThreeVector& localPoint );
0087 
0088     /**
0089      * Searches positioned volumes in mother at current top level of @p history
0090      * for volume containing @p globalPoint. Do not test against @p blockedVol.
0091      * If a containing volume is found, push it onto navigation history state.
0092      *  @param[in,out] history Navigation history.
0093      *  @param[in,out] blockedVol Blocked volume to be ignored in queries.
0094      *  @param[in,out] blockedNum Copy number for blocked replica volumes.
0095      *  @param[in,out] globalPoint Point in global coordinates system.
0096      *  @param[in,out] globalDirection Pointer to global direction or null.
0097      *  @param[in] pLocatedOnEdge Flag specifying if point is located on edge.
0098      *  @param[in,out] localPoint Point in local coordinates system.
0099      *  @returns Whether a containing volume has been found.
0100      */
0101     inline G4bool LevelLocate( G4NavigationHistory& history,
0102                          const G4VPhysicalVolume* blockedVol,
0103                          const G4int blockedNum,
0104                          const G4ThreeVector& globalPoint,
0105                          const G4ThreeVector* globalDirection,
0106                          const G4bool pLocatedOnEdge, 
0107                                G4ThreeVector& localPoint ) override;
0108 
0109     /**
0110      * Computes the length of a step to the next boundary.
0111      * Does not test against @p pBlockedPhysical. Identifies the next candidate
0112      * volume (if a daughter of the current volume), and returns it in:
0113      * pBlockedPhysical, blockedReplicaNo.
0114      *  @param[in] localPoint Local point.
0115      *  @param[in] localDirection Local direction vector.
0116      *  @param[in] currentProposedStepLength Current proposed step length.
0117      *  @param[in,out] newSafety New safety.
0118      *  @param[in,out] history Navigation history.
0119      *  @param[in,out] validExitNormal Flag to indicate whether exit normal is
0120      *                 valid or not.
0121      *  @param[in,out] exitNormal Exit normal.
0122      *  @param[in,out] exiting Flag to indicate whether exiting a volume.
0123      *  @param[in,out] entering Flag to indicate whether entering a volume.
0124      *  @param[in,out] pBlockedPhysical Blocked physical volume that should be
0125      *                 ignored in queries.
0126      *  @param[in,out] blockedReplicaNo Copy number for blocked replica volumes.
0127      *  @returns Length from current point to next boundary surface along
0128      *           @p localDirection.
0129      */
0130     G4double ComputeStep( const G4ThreeVector& localPoint,
0131                           const G4ThreeVector& localDirection,
0132                           const G4double currentProposedStepLength,
0133                                 G4double& newSafety,
0134                                 G4NavigationHistory& history,
0135                                 G4bool& validExitNormal,
0136                                 G4ThreeVector& exitNormal,
0137                                 G4bool& exiting,
0138                                 G4bool& entering,
0139                                 G4VPhysicalVolume* (*pBlockedPhysical),
0140                                 G4int& blockedReplicaNo ) override;
0141 
0142     /**
0143      * Calculates the isotropic distance to the nearest boundary from the
0144      * specified point in the local coordinate system. 
0145      * The localpoint utilised must be within the current volume.
0146      *  @param[in] localPoint Local point.
0147      *  @param[in] history Navigation history.
0148      *  @param[in] pMaxLength Maximum step length beyond which volumes
0149      *             need not be checked.
0150      *  @returns Length from current point to closest surface.
0151      */
0152     G4double ComputeSafety( const G4ThreeVector& localpoint,
0153                             const G4NavigationHistory& history,
0154                             const G4double pMaxLength = DBL_MAX ) override;
0155 
0156     /**
0157      * Updates internal navigation state to take into account that location
0158      * has been moved, but remains within the @p motherPhysical volume.
0159      *  @param[in] motherPhysical Current physical volume.
0160      *  @param[in] localPoint Local point.
0161      */
0162     void RelocateWithinVolume( G4VPhysicalVolume* motherPhysical,
0163                                const G4ThreeVector& localPoint ) override;
0164 
0165     /**
0166      * Verbosity control.
0167      *  @note If level>0 && G4VERBOSE, printout can occur.
0168      */
0169     inline G4int GetVerboseLevel() const override;
0170     void  SetVerboseLevel(G4int level) override;
0171 
0172     /**
0173      * Enables best-possible evaluation of isotropic safety.
0174      */
0175     inline void EnableBestSafety( G4bool flag = false );
0176 
0177   protected:
0178 
0179     /**
0180      * Computes safety from specified point to voxel boundaries using already
0181      * located point.
0182      *  @param[in] localPoint Local point.
0183      *  @returns Safety length from current point to voxel boundary.
0184      */
0185     G4double ComputeVoxelSafety( const G4ThreeVector& localPoint ) const;
0186 
0187     /**
0188      * Finds the next voxel from the current voxel and point in the specified
0189      * direction.
0190      *  @param[in] localPoint Local point.
0191      *  @param[in] localDirection Direction along which compute the distance.
0192      *  @param[in] currentStep Current step size.
0193      *  @returns false if all voxels considered
0194      *           [current Step ends inside same voxel or leaves all voxels]
0195      *           true  otherwise
0196      *           [the information on the next voxel is saved].
0197      */
0198     G4bool LocateNextVoxel( const G4ThreeVector& localPoint,
0199                             const G4ThreeVector& localDirection,
0200                             const G4double currentStep );
0201 
0202   private:  // Logging functions
0203 
0204     void PreComputeStepLog  (const G4VPhysicalVolume* motherPhysical,
0205                                    G4double motherSafety,
0206                              const G4ThreeVector& localPoint);
0207     void AlongComputeStepLog(const G4VSolid* sampleSolid,
0208                              const G4ThreeVector& samplePoint,
0209                              const G4ThreeVector& sampleDirection,
0210                              const G4ThreeVector& localDirection,
0211                                    G4double sampleSafety,
0212                                    G4double sampleStep);
0213     void PostComputeStepLog (const G4VSolid* motherSolid,
0214                              const G4ThreeVector& localPoint,
0215                              const G4ThreeVector& localDirection,
0216                                    G4double motherStep,
0217                                    G4double motherSafety);
0218     void ComputeSafetyLog   (const G4VSolid* solid,
0219                              const G4ThreeVector& point,
0220                                    G4double safety,
0221                                    G4bool banner);
0222     inline void PrintDaughterLog (const G4VSolid* sampleSolid,
0223                                   const G4ThreeVector& samplePoint,
0224                                         G4double sampleSafety,
0225                                         G4double sampleStep);   
0226   protected:
0227 
0228     /** Blocked volumes. */
0229     G4BlockingList fBList;
0230 
0231     // -----------------------------------------------------------------------
0232     // BEGIN Voxel Stack information
0233 
0234     /** Voxels depth.
0235      *   @note fVoxelDepth==0+ => fVoxelAxisStack(0+) contains axes of voxel
0236      *         fVoxelDepth==-1 -> not in voxel.
0237      */
0238     G4int fVoxelDepth = -1;
0239 
0240     /** Voxel axes. */
0241     std::vector<EAxis> fVoxelAxisStack;
0242 
0243     /** No slices per voxel at each level. */
0244     std::vector<G4int> fVoxelNoSlicesStack;
0245 
0246     /** Width of voxels at each level. */
0247     std::vector<G4double> fVoxelSliceWidthStack; 
0248 
0249     /** Node no point is inside at each level. */
0250     std::vector<G4int> fVoxelNodeNoStack;    
0251 
0252     /** Voxel headers at each level. */
0253     std::vector<G4SmartVoxelHeader*> fVoxelHeaderStack;
0254 
0255     /** Node containing last located point. */
0256     G4SmartVoxelNode* fVoxelNode = nullptr;
0257 
0258     // END Voxel Stack information
0259     // -----------------------------------------------------------------------
0260 
0261     /** Helper object for Voxel Safety. */
0262     G4VoxelSafety* fpVoxelSafety = nullptr;
0263 
0264     /** Surface tolerance. */
0265     G4double fHalfTolerance;
0266 
0267     /** Flag for best safety. */
0268     G4bool fBestSafety = false; 
0269 
0270     /** Verbosity logger. */
0271     G4NavigationLogger* fLogger;
0272 };
0273 
0274 #include "G4VoxelNavigation.icc"
0275 
0276 #endif