Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:32:53

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 /// \file radiobiology/include/VoxelizedSensitiveDetector.hh
0027 /// \brief Definition of the RadioBio::VoxelizedSensitiveDetector class
0028 
0029 #ifndef RadiobiologyVoxelizedSensitiveDetector_h
0030 #define RadiobiologyVoxelizedSensitiveDetector_h 1
0031 
0032 #include "G4ThreeVector.hh"
0033 
0034 class G4Box;
0035 class G4LogicalVolume;
0036 class G4VPhysicalVolume;
0037 
0038 namespace RadioBio
0039 {
0040 
0041 // Forward declariation of other radiobiology classes
0042 class DetectorConstruction;
0043 class VoxelizedSensitiveDetectorMessenger;
0044 
0045 /**
0046  * @brief Singleton class performing the voxelization of the
0047  * world volume and tracking of a voxel index given the three-dimensional
0048  * coordinates
0049  *
0050  * This class is used to voxelize the world volume created in
0051  * DetectorConstruction class. It works only if the world already exists:
0052  * the constructor needs a pointer to DetectorConstruction.
0053  *
0054  * This class does not insert a further material, but uses the same
0055  * material saved in DetectorConstruction class. It is responsible
0056  * for the voxelization of the space and for the tracking of voxels
0057  * index.
0058  *
0059  * Internally, the voxel volume, mass and density are updated every
0060  * time something relevant changes in the geometry
0061  *
0062  * @note Although in this class the word \a "sensitive" appears,
0063  * this is class is not an implementation of the sensitive detector,
0064  * nevertheless it crates the environment for sensitiveness. It is
0065  * meant to be similar to a DetectorConstruction class, providing
0066  * voxelization of the world.
0067  */
0068 
0069 class VoxelizedSensitiveDetector
0070 {
0071     // This class has a 'singleton' structure
0072 
0073   private:
0074     /** @brief Private constructor using a pointer to
0075      * DetectorConstruction and the three dimensions for one voxel */
0076     VoxelizedSensitiveDetector(DetectorConstruction* det, double xWidth, double yWidth,
0077                                double zWidth);
0078     static VoxelizedSensitiveDetector* fInstance;
0079 
0080   public:
0081     /** @brief Static method to retrieve a pointer
0082      * to the only object existing in the simulation */
0083     static VoxelizedSensitiveDetector* GetInstance();
0084 
0085     /** @brief Static method to create the pointer
0086      * to the only object existing in the simulation
0087      *
0088      * @param det A pointer to the DetectorConstruction object
0089      * @param xWidth X dimension of a single voxel
0090      * @param yWidth Y dimension of a single voxel
0091      * @param zWidth Z dimension of a single voxel
0092      * */
0093     static VoxelizedSensitiveDetector* CreateInstance(DetectorConstruction* det, double xWidth,
0094                                                       double yWidth, double zWidth);
0095 
0096     /** Destructor */
0097     ~VoxelizedSensitiveDetector();
0098 
0099     // Setting of parameters
0100     /** @brief Method to set the voxel shape
0101      *  to be a box with given sides
0102      *
0103      * @param voxWidth ThreeVector containing the
0104      * three-dimensionals sides for the voxel
0105      */
0106     void SetVoxelWidth(G4ThreeVector voxWidth);
0107 
0108     /** @brief Method to set the voxel X width
0109      *
0110      * @param voxWidthX X width for the voxel
0111      */
0112     void SetVoxelWidthX(G4double voxWidthX);
0113 
0114     /** @brief Method to set the voxel Y width
0115      *
0116      * @param voxWidthY Y width for the voxel
0117      */
0118     void SetVoxelWidthY(G4double voxWidthY);
0119 
0120     /** @brief Method to set the voxel Z width
0121      *
0122      * @param voxWidthZ Z width for the voxel
0123      */
0124     void SetVoxelWidthZ(G4double voxWidthZ);
0125 
0126     /** @brief Method to update voxelized geometry.
0127      * If voxelized geometry is not built, it returns
0128      * immediately.
0129      * Otherwise, geometrical parameters are re-calculated and
0130      * voxelized geometry is destroyed, de-registered
0131      *  and built once again from scratch.
0132      *
0133      */
0134     void UpdateVoxelizedGeometry();
0135 
0136     // Initialize pointer to the world
0137     // Should be called only from DetectorConstruction
0138     /** @brief Method to properly initialize the pointer
0139      * to the World physical volume. It is meant
0140      * to be called **only** by DetectorConstruction
0141      * itself.
0142      *
0143      * @param pWorld Pointer to the world physical volume
0144      *
0145      */
0146     void InitializeWorldPtr(G4VPhysicalVolume* pWorld);
0147 
0148     // 'Construct' methods
0149     /** Method to construct all the volumes for the
0150      * voxelization of the geometry. */
0151     void Construct();
0152 
0153     /** Method to make the proper volume
0154      * sensitive to allow scoring. */
0155     void ConstructSD();
0156 
0157     // List of 'Get' methods
0158   public:
0159     /** Method to get the three vector
0160      * containing the dimensions for the voxel */
0161     G4ThreeVector GetVoxelWidth() const
0162     {
0163       return G4ThreeVector{fVoxelWidthX, fVoxelWidthY, fVoxelWidthZ};
0164     }
0165 
0166     /** Method to get X width of the voxel. */
0167     G4double GetVoxelWidthX() const { return fVoxelWidthX; }
0168 
0169     /** Method to get Y width of the voxel. */
0170     G4double GetVoxelWidthY() const { return fVoxelWidthY; }
0171 
0172     /** Method to get Z width of the voxel. */
0173     G4double GetVoxelWidthZ() const { return fVoxelWidthZ; }
0174 
0175     /** Method to get total voxel volume. */
0176     G4double GetVoxelVolume() const { return fVoxelVolume; }
0177 
0178     /** Method to get the voxel number along X axis. */
0179     G4double GetVoxelNumberAlongX() const { return fVoxelNumberAlongX; }
0180 
0181     /** Method to get the voxel number along Y axis. */
0182     G4double GetVoxelNumberAlongY() const { return fVoxelNumberAlongY; }
0183 
0184     /** Method to get the voxel number along Z axis. */
0185     G4double GetVoxelNumberAlongZ() const { return fVoxelNumberAlongZ; }
0186 
0187     /** Method to get the total voxel number. */
0188     G4int GetTotalVoxelNumber() const { return fTotalVoxelNumber; }
0189 
0190     /** Method to get the mass of a voxel.
0191      *
0192      * @note In this implementation, there is only
0193      * one material for the whole simulation. This
0194      * means that all the voxels (that already share the
0195      * same shape and dimensions) also share the same
0196      * mass and density
0197      */
0198     G4double GetVoxelMass() const { return fVoxelMass; }
0199 
0200     /** Method to get the density of a voxel.
0201      *
0202      * @note In this implementation, there is only
0203      * one material for the whole simulation. This
0204      * means that all the voxels (that already share the
0205      * same shape and dimensions) also share the same
0206      * mass and density
0207      */
0208     G4double GetVoxelDensity() const { return fVoxelDensity; }
0209 
0210     // To get the onedimensional voxel number given the three indexes
0211     // This function will be used from other classes as well, and
0212     // is defined only here for clarity purpose
0213     /** Method to get the absolute voxel index given its
0214      * indexes in the three dimensions.
0215      *
0216      * This helper function is heavily used throughout
0217      * the simulation and is here because the voxelized
0218      * detector is meant to know how many voxels there
0219      * are and how they are ordered.
0220      */
0221     G4int GetThisVoxelNumber(G4int x, G4int j, G4int k) const;
0222 
0223   private:
0224     /** Private method to construct the voxelized
0225      * detector
0226      */
0227     G4bool ConstructVoxelizedDetector();
0228 
0229     DetectorConstruction* fDetector = nullptr;
0230 
0231     G4double fVoxelWidthX = -1.;
0232     G4double fVoxelWidthY = -1.;
0233     G4double fVoxelWidthZ = -1.;
0234 
0235     G4double fVoxelVolume = -1.;
0236 
0237     G4int fVoxelNumberAlongX = 1;
0238     G4int fVoxelNumberAlongY = 1;
0239     G4int fVoxelNumberAlongZ = 1;
0240 
0241     G4int fTotalVoxelNumber = 1;
0242     G4double fVoxelMass = 0.;
0243     G4double fVoxelDensity = 0.;
0244 
0245     // Voxelized objects
0246     G4Box* fVoxelizedDetectorXDivision = nullptr;
0247     G4Box* fVoxelizedDetectorYDivision = nullptr;
0248     G4Box* fVoxelizedDetectorZDivision = nullptr;
0249 
0250     G4LogicalVolume* fVoxelizedDetectorXDivisionLog = nullptr;
0251     G4LogicalVolume* fVoxelizedDetectorYDivisionLog = nullptr;
0252     G4LogicalVolume* fVoxelizedDetectorZDivisionLog = nullptr;
0253     G4LogicalVolume* fSensitiveLogicalVolume = nullptr;
0254 
0255     G4VPhysicalVolume* fVoxelizedDetectorXDivisionPhys = nullptr;
0256     G4VPhysicalVolume* fVoxelizedDetectorYDivisionPhys = nullptr;
0257     G4VPhysicalVolume* fVoxelizedDetectorZDivisionPhys = nullptr;
0258 
0259     // Pointer to world
0260     G4LogicalVolume* fWorldLogical = nullptr;
0261 
0262     G4bool fIsBuilt = false;
0263 
0264     /** Private method to calculate
0265      * the total volume of a voxel given the
0266      * parameters saved inside the object
0267      */
0268     void UpdateVoxelVolume();
0269 
0270     /** Private method to calculate
0271      * the total voxel number given the
0272      * parameters saved inside the object
0273      */
0274     void CalculateVoxelNumber();
0275 
0276     /** Private method to slice
0277      * the world volume along the X
0278      * axis.
0279      */
0280     void ConstructXDivision();
0281 
0282     /** Private method to further slice
0283      * the X slices along the Y
0284      * axis, creating some "columns" of material.
0285      */
0286     void ConstructYDivision();
0287 
0288     /** Private method to further slice
0289      * the Y columns along the Z
0290      * axis, creating some boxes of material.
0291      *
0292      * This is the final step for voxelization
0293      * of space.
0294      */
0295     void ConstructZDivision();
0296 
0297     VoxelizedSensitiveDetectorMessenger* fVoxelizedSensitiveDetectorMessenger = nullptr;
0298 };
0299 
0300 }  // namespace RadioBio
0301 
0302 #endif  // VoxelizedSensitiveDetector_h