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p3 ] [ 10.5 ] [ 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 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 /// \file radiobiology/include/VoxelizedSensitiveDetector.hh
 27 /// \brief Definition of the RadioBio::VoxelizedSensitiveDetector class
 28 
 29 #ifndef RadiobiologyVoxelizedSensitiveDetector_h
 30 #define RadiobiologyVoxelizedSensitiveDetector_h 1
 31 
 32 #include "G4ThreeVector.hh"
 33 
 34 class G4Box;
 35 class G4LogicalVolume;
 36 class G4VPhysicalVolume;
 37 
 38 namespace RadioBio
 39 {
 40 
 41 // Forward declariation of other radiobiology classes
 42 class DetectorConstruction;
 43 class VoxelizedSensitiveDetectorMessenger;
 44 
 45 /**
 46  * @brief Singleton class performing the voxelization of the
 47  * world volume and tracking of a voxel index given the three-dimensional
 48  * coordinates
 49  *
 50  * This class is used to voxelize the world volume created in
 51  * DetectorConstruction class. It works only if the world already exists:
 52  * the constructor needs a pointer to DetectorConstruction.
 53  *
 54  * This class does not insert a further material, but uses the same
 55  * material saved in DetectorConstruction class. It is responsible
 56  * for the voxelization of the space and for the tracking of voxels
 57  * index.
 58  *
 59  * Internally, the voxel volume, mass and density are updated every
 60  * time something relevant changes in the geometry
 61  *
 62  * @note Although in this class the word \a "sensitive" appears,
 63  * this is class is not an implementation of the sensitive detector,
 64  * nevertheless it crates the environment for sensitiveness. It is
 65  * meant to be similar to a DetectorConstruction class, providing
 66  * voxelization of the world.
 67  */
 68 
 69 class VoxelizedSensitiveDetector
 70 {
 71     // This class has a 'singleton' structure
 72 
 73   private:
 74     /** @brief Private constructor using a pointer to
 75      * DetectorConstruction and the three dimensions for one voxel */
 76     VoxelizedSensitiveDetector(DetectorConstruction* det, double xWidth, double yWidth,
 77                                double zWidth);
 78     static VoxelizedSensitiveDetector* fInstance;
 79 
 80   public:
 81     /** @brief Static method to retrieve a pointer
 82      * to the only object existing in the simulation */
 83     static VoxelizedSensitiveDetector* GetInstance();
 84 
 85     /** @brief Static method to create the pointer
 86      * to the only object existing in the simulation
 87      *
 88      * @param det A pointer to the DetectorConstruction object
 89      * @param xWidth X dimension of a single voxel
 90      * @param yWidth Y dimension of a single voxel
 91      * @param zWidth Z dimension of a single voxel
 92      * */
 93     static VoxelizedSensitiveDetector* CreateInstance(DetectorConstruction* det, double xWidth,
 94                                                       double yWidth, double zWidth);
 95 
 96     /** Destructor */
 97     ~VoxelizedSensitiveDetector();
 98 
 99     // Setting of parameters
100     /** @brief Method to set the voxel shape
101      *  to be a box with given sides
102      *
103      * @param voxWidth ThreeVector containing the
104      * three-dimensionals sides for the voxel
105      */
106     void SetVoxelWidth(G4ThreeVector voxWidth);
107 
108     /** @brief Method to set the voxel X width
109      *
110      * @param voxWidthX X width for the voxel
111      */
112     void SetVoxelWidthX(G4double voxWidthX);
113 
114     /** @brief Method to set the voxel Y width
115      *
116      * @param voxWidthY Y width for the voxel
117      */
118     void SetVoxelWidthY(G4double voxWidthY);
119 
120     /** @brief Method to set the voxel Z width
121      *
122      * @param voxWidthZ Z width for the voxel
123      */
124     void SetVoxelWidthZ(G4double voxWidthZ);
125 
126     /** @brief Method to update voxelized geometry.
127      * If voxelized geometry is not built, it returns
128      * immediately.
129      * Otherwise, geometrical parameters are re-calculated and
130      * voxelized geometry is destroyed, de-registered
131      *  and built once again from scratch.
132      *
133      */
134     void UpdateVoxelizedGeometry();
135 
136     // Initialize pointer to the world
137     // Should be called only from DetectorConstruction
138     /** @brief Method to properly initialize the pointer
139      * to the World physical volume. It is meant
140      * to be called **only** by DetectorConstruction
141      * itself.
142      *
143      * @param pWorld Pointer to the world physical volume
144      *
145      */
146     void InitializeWorldPtr(G4VPhysicalVolume* pWorld);
147 
148     // 'Construct' methods
149     /** Method to construct all the volumes for the
150      * voxelization of the geometry. */
151     void Construct();
152 
153     /** Method to make the proper volume
154      * sensitive to allow scoring. */
155     void ConstructSD();
156 
157     // List of 'Get' methods
158   public:
159     /** Method to get the three vector
160      * containing the dimensions for the voxel */
161     G4ThreeVector GetVoxelWidth() const
162     {
163       return G4ThreeVector{fVoxelWidthX, fVoxelWidthY, fVoxelWidthZ};
164     }
165 
166     /** Method to get X width of the voxel. */
167     G4double GetVoxelWidthX() const { return fVoxelWidthX; }
168 
169     /** Method to get Y width of the voxel. */
170     G4double GetVoxelWidthY() const { return fVoxelWidthY; }
171 
172     /** Method to get Z width of the voxel. */
173     G4double GetVoxelWidthZ() const { return fVoxelWidthZ; }
174 
175     /** Method to get total voxel volume. */
176     G4double GetVoxelVolume() const { return fVoxelVolume; }
177 
178     /** Method to get the voxel number along X axis. */
179     G4double GetVoxelNumberAlongX() const { return fVoxelNumberAlongX; }
180 
181     /** Method to get the voxel number along Y axis. */
182     G4double GetVoxelNumberAlongY() const { return fVoxelNumberAlongY; }
183 
184     /** Method to get the voxel number along Z axis. */
185     G4double GetVoxelNumberAlongZ() const { return fVoxelNumberAlongZ; }
186 
187     /** Method to get the total voxel number. */
188     G4int GetTotalVoxelNumber() const { return fTotalVoxelNumber; }
189 
190     /** Method to get the mass of a voxel.
191      *
192      * @note In this implementation, there is only
193      * one material for the whole simulation. This
194      * means that all the voxels (that already share the
195      * same shape and dimensions) also share the same
196      * mass and density
197      */
198     G4double GetVoxelMass() const { return fVoxelMass; }
199 
200     /** Method to get the density of a voxel.
201      *
202      * @note In this implementation, there is only
203      * one material for the whole simulation. This
204      * means that all the voxels (that already share the
205      * same shape and dimensions) also share the same
206      * mass and density
207      */
208     G4double GetVoxelDensity() const { return fVoxelDensity; }
209 
210     // To get the onedimensional voxel number given the three indexes
211     // This function will be used from other classes as well, and
212     // is defined only here for clarity purpose
213     /** Method to get the absolute voxel index given its
214      * indexes in the three dimensions.
215      *
216      * This helper function is heavily used throughout
217      * the simulation and is here because the voxelized
218      * detector is meant to know how many voxels there
219      * are and how they are ordered.
220      */
221     G4int GetThisVoxelNumber(G4int x, G4int j, G4int k) const;
222 
223   private:
224     /** Private method to construct the voxelized
225      * detector
226      */
227     G4bool ConstructVoxelizedDetector();
228 
229     DetectorConstruction* fDetector = nullptr;
230 
231     G4double fVoxelWidthX = -1.;
232     G4double fVoxelWidthY = -1.;
233     G4double fVoxelWidthZ = -1.;
234 
235     G4double fVoxelVolume = -1.;
236 
237     G4int fVoxelNumberAlongX = 1;
238     G4int fVoxelNumberAlongY = 1;
239     G4int fVoxelNumberAlongZ = 1;
240 
241     G4int fTotalVoxelNumber = 1;
242     G4double fVoxelMass = 0.;
243     G4double fVoxelDensity = 0.;
244 
245     // Voxelized objects
246     G4Box* fVoxelizedDetectorXDivision = nullptr;
247     G4Box* fVoxelizedDetectorYDivision = nullptr;
248     G4Box* fVoxelizedDetectorZDivision = nullptr;
249 
250     G4LogicalVolume* fVoxelizedDetectorXDivisionLog = nullptr;
251     G4LogicalVolume* fVoxelizedDetectorYDivisionLog = nullptr;
252     G4LogicalVolume* fVoxelizedDetectorZDivisionLog = nullptr;
253     G4LogicalVolume* fSensitiveLogicalVolume = nullptr;
254 
255     G4VPhysicalVolume* fVoxelizedDetectorXDivisionPhys = nullptr;
256     G4VPhysicalVolume* fVoxelizedDetectorYDivisionPhys = nullptr;
257     G4VPhysicalVolume* fVoxelizedDetectorZDivisionPhys = nullptr;
258 
259     // Pointer to world
260     G4LogicalVolume* fWorldLogical = nullptr;
261 
262     G4bool fIsBuilt = false;
263 
264     /** Private method to calculate
265      * the total volume of a voxel given the
266      * parameters saved inside the object
267      */
268     void UpdateVoxelVolume();
269 
270     /** Private method to calculate
271      * the total voxel number given the
272      * parameters saved inside the object
273      */
274     void CalculateVoxelNumber();
275 
276     /** Private method to slice
277      * the world volume along the X
278      * axis.
279      */
280     void ConstructXDivision();
281 
282     /** Private method to further slice
283      * the X slices along the Y
284      * axis, creating some "columns" of material.
285      */
286     void ConstructYDivision();
287 
288     /** Private method to further slice
289      * the Y columns along the Z
290      * axis, creating some boxes of material.
291      *
292      * This is the final step for voxelization
293      * of space.
294      */
295     void ConstructZDivision();
296 
297     VoxelizedSensitiveDetectorMessenger* fVoxelizedSensitiveDetectorMessenger = nullptr;
298 };
299 
300 }  // namespace RadioBio
301 
302 #endif  // VoxelizedSensitiveDetector_h
303