Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-22 08:51:50

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 // G4PhantomParameterisation
0027 //
0028 // Class description:
0029 // 
0030 // Describes regular parameterisations: a set of boxes of equal dimension
0031 // in the x, y and z dimensions. The G4PVParameterised volume using this
0032 // class must be placed inside a volume that is completely filled by these
0033 // boxes.
0034 
0035 // Author: Pedro Arce (CIEMAT), May 2007
0036 //---------------------------------------------------------------------
0037 #ifndef G4PhantomParameterisation_HH
0038 #define G4PhantomParameterisation_HH 1
0039 
0040 #include <vector>
0041 
0042 #include "G4Types.hh"
0043 #include "G4VPVParameterisation.hh"
0044 #include "G4AffineTransform.hh"
0045 #include "G4VTouchable.hh" 
0046 
0047 class G4VPhysicalVolume;
0048 class G4VSolid;
0049 class G4Material;
0050 
0051 // Dummy forward declarations ...
0052 
0053 class G4Box;
0054 class G4Tubs;
0055 class G4Trd;
0056 class G4Trap;
0057 class G4Cons;
0058 class G4Orb;
0059 class G4Sphere;
0060 class G4Ellipsoid;
0061 class G4Torus;
0062 class G4Para;
0063 class G4Hype;
0064 class G4Polycone;
0065 class G4Polyhedra;
0066 
0067 /**
0068  * @brief G4PhantomParameterisation describes regular parameterisations: a set
0069  * of boxes of equal dimension in the x, y and z dimensions.
0070  * The G4PVParameterised volume using this class must be placed inside a volume
0071  * that is completely filled by these boxes.
0072  */
0073 
0074 class G4PhantomParameterisation : public G4VPVParameterisation
0075 {
0076   public:
0077 
0078     /**
0079      * Constructor and Destructor.
0080      */
0081     G4PhantomParameterisation();
0082    ~G4PhantomParameterisation() override;
0083 
0084     void ComputeTransformation(const G4int, G4VPhysicalVolume *) const override;
0085   
0086     G4VSolid* ComputeSolid(const G4int, G4VPhysicalVolume *) override;
0087   
0088     G4Material* ComputeMaterial(const G4int repNo, 
0089                                              G4VPhysicalVolume* currentVol,
0090                                        const G4VTouchable* parentTouch=nullptr) override;
0091     /**
0092      * Dummy declarations ...
0093      */
0094     void ComputeDimensions (G4Box &, const G4int,
0095                             const G4VPhysicalVolume*) const override {}
0096     void ComputeDimensions (G4Tubs&, const G4int,
0097                             const G4VPhysicalVolume*) const override {}
0098     void ComputeDimensions (G4Trd&, const G4int,
0099                             const G4VPhysicalVolume*) const override {}
0100     void ComputeDimensions (G4Trap&, const G4int,
0101                             const G4VPhysicalVolume*) const override {}
0102     void ComputeDimensions (G4Cons&, const G4int,
0103                             const G4VPhysicalVolume*) const override {}
0104     void ComputeDimensions (G4Orb&, const G4int,
0105                             const G4VPhysicalVolume*) const override {}
0106     void ComputeDimensions (G4Sphere&, const G4int,
0107                             const G4VPhysicalVolume*) const override {}
0108     void ComputeDimensions (G4Ellipsoid&,const G4int,
0109                             const G4VPhysicalVolume*) const override {}
0110     void ComputeDimensions (G4Torus&, const G4int,
0111                             const G4VPhysicalVolume*) const override {}
0112     void ComputeDimensions (G4Para&, const G4int,
0113                             const G4VPhysicalVolume*) const override {}
0114     void ComputeDimensions (G4Hype&, const G4int,
0115                             const G4VPhysicalVolume*) const override {}
0116     void ComputeDimensions (G4Polycone&, const G4int,
0117                             const G4VPhysicalVolume*) const override {}
0118     void ComputeDimensions (G4Polyhedra&, const G4int,
0119                             const G4VPhysicalVolume*) const override {}
0120   
0121     /**
0122      * Saves as container solid the parent of the voxels.
0123      * Checks that the voxels fill it completely.
0124      */
0125     void BuildContainerSolid( G4VPhysicalVolume* pPhysicalVol );
0126     void BuildContainerSolid( G4VSolid* pMotherSolid );
0127 
0128   
0129     /**
0130      * Gets the voxel number corresponding to the point in the container
0131      * frame. Uses 'localDir' to avoid precision problems at the surfaces.
0132      */
0133     virtual G4int GetReplicaNo( const G4ThreeVector& localPoint,
0134                                 const G4ThreeVector& localDir );
0135 
0136     /** Set and Get methods */
0137 
0138     inline void SetMaterials(std::vector<G4Material*>& mates );
0139 
0140     inline void SetMaterialIndices( std::size_t* matInd );
0141 
0142     void SetVoxelDimensions( G4double halfx, G4double halfy, G4double halfz );
0143     void SetNoVoxels( std::size_t nx, std::size_t ny, std::size_t nz );
0144     
0145     inline G4double GetVoxelHalfX() const;
0146     inline G4double GetVoxelHalfY() const;
0147     inline G4double GetVoxelHalfZ() const;
0148     inline std::size_t GetNoVoxelsX() const;
0149     inline std::size_t GetNoVoxelsY() const;
0150     inline std::size_t GetNoVoxelsZ() const;
0151     inline std::size_t GetNoVoxels() const;
0152 
0153     inline std::vector<G4Material*> GetMaterials() const;
0154     inline std::size_t* GetMaterialIndices() const;
0155     inline G4VSolid* GetContainerSolid() const;
0156 
0157     G4ThreeVector GetTranslation(const G4int copyNo ) const;
0158 
0159     G4bool SkipEqualMaterials() const;
0160     void SetSkipEqualMaterials( G4bool skip );
0161 
0162     std::size_t GetMaterialIndex( std::size_t nx, std::size_t ny, std::size_t nz) const;
0163     std::size_t GetMaterialIndex( std::size_t copyNo) const;
0164 
0165     G4Material* GetMaterial( std::size_t nx, std::size_t ny, std::size_t nz) const;
0166     G4Material* GetMaterial( std::size_t copyNo ) const;
0167 
0168     /**
0169      * Checks that the voxels fill it completely.
0170      */
0171     void CheckVoxelsFillContainer( G4double contX, G4double contY,
0172                                    G4double contZ ) const;
0173 
0174   private:
0175 
0176     /**
0177      * Converts the copyNo to voxel numbers in x, y and z.
0178      */
0179     void ComputeVoxelIndices(const G4int copyNo, std::size_t& nx,
0180                                    std::size_t& ny, std::size_t& nz ) const;
0181 
0182     /**
0183      * Checks that the copy number is within limits.
0184      */
0185     void CheckCopyNo( const G4long copyNo ) const;
0186 
0187   protected:
0188 
0189     /** Half dimension of voxels (assume they are boxes). */
0190     G4double fVoxelHalfX = 0.0, fVoxelHalfY = 0.0, fVoxelHalfZ = 0.0;
0191 
0192     /** Number of voxel in x, y and z dimensions. */
0193     std::size_t fNoVoxelsX = 0, fNoVoxelsY = 0, fNoVoxelsZ = 0;
0194 
0195     /** Number of voxels in x times number of voxels in y (for speed-up). */
0196     std::size_t fNoVoxelsXY = 0;
0197 
0198     /** Total number of voxels (for speed-up). */
0199     std::size_t fNoVoxels = 0;
0200 
0201     /** List of materials of the voxels. */
0202     std::vector<G4Material*> fMaterials;
0203 
0204     /** Index in fMaterials that correspond to each voxel. */
0205     std::size_t* fMaterialIndices = nullptr;
0206 
0207     /** Saves as container solid the parent of the voxels. */
0208     G4VSolid* fContainerSolid = nullptr;
0209 
0210     /** Save position of container wall for speed-up. */
0211     G4double fContainerWallX=0.0, fContainerWallY=0.0, fContainerWallZ=0.0;
0212 
0213     /** Relative surface tolerance. */
0214     G4double kCarTolerance;
0215 
0216     /** Flag to skip surface when two voxel have same material or not. */
0217     G4bool bSkipEqualMaterials = true;
0218 };
0219 
0220 #include "G4PhantomParameterisation.icc"
0221 
0222 #endif