Loading...
Searching...
No Matches
VoxelizedSensitiveDetector.cc
Go to the documentation of this file.
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//
27/// \file radiobiology/src/VoxelizedSensitiveDetector.cc
28/// \brief Implementation of the RadioBio::VoxelizedSensitiveDetector class
29
31
32#include "G4Box.hh"
33#include "G4LogicalVolume.hh"
34#include "G4PVReplica.hh"
35#include "G4PhysicalVolumeStore.hh"
36#include "G4RunManager.hh"
37#include "G4SDManager.hh"
38#include "G4SystemOfUnits.hh"
39#include "G4TransportationManager.hh"
40#include "G4VPhysicalVolume.hh"
41
42#include "DetectorConstruction.hh"
43#include "SD.hh"
45
46namespace RadioBio
47{
48
49//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50
51VoxelizedSensitiveDetector* VoxelizedSensitiveDetector::fInstance = nullptr;
52
53//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54
56 double xWidth, double yWidth,
57 double zWidth)
58{
59 if (fInstance) {
60 delete fInstance;
61 G4Exception("VoxelizedSensitiveDetector::createInstance", "RecreatingVoxelization",
62 FatalException, "Creating another, new, instance of VoxelizedSensitiveDetector");
63 }
64 fInstance = new VoxelizedSensitiveDetector(det, xWidth, yWidth, zWidth);
65 return fInstance;
66}
67
68//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
69
74
75//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76
78 double yWidth, double zWidth)
79 : fDetector(det), fVoxelWidthX(xWidth), fVoxelWidthY(yWidth), fVoxelWidthZ(zWidth)
80{
84}
85
86//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
87
92
93//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
94
101
102//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
103
105{
106 fVoxelWidthX = voxWidth.getX();
107 fVoxelWidthY = voxWidth.getY();
108 fVoxelWidthZ = voxWidth.getZ();
110}
111
112//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
113
115{
116 if (fVoxelWidthX == voxWidthX) return;
117 fVoxelWidthX = voxWidthX;
119}
120
121//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
122
124{
125 if (fVoxelWidthY == voxWidthY) return;
126 fVoxelWidthY = voxWidthY;
128}
129
130//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
131
133{
134 if (fVoxelWidthZ == voxWidthZ) return;
135 fVoxelWidthZ = voxWidthZ;
137}
138
139//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
140
141// Calculte number of voxel approximating for an integer number of voxels
142// Then recalculates voxels size according to approximations
144{
147
150
153
154 if (fVoxelNumberAlongY % 2 == 0)
155 G4Exception("VoxelizedSensitiveDetector::CalculateVoxelNumber", "VoxelNumberYEven", JustWarning,
156 "Trying to voxelize with an even number of voxels along the Y axis."
157 "Please select an odd number to prevent from warnings due to tracking");
158
159 if (fVoxelNumberAlongZ % 2 == 0)
160 G4Exception("VoxelizedSensitiveDetector::CalculateVoxelNumber", "VoxelNumberZEven", JustWarning,
161 "Trying to voxelize with an even number of voxels along the Z axis."
162 "Please select an odd number to prevent from warnings due to tracking");
163
165
167}
168
169//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
170
172{
173 if (fWorldLogical == nullptr)
174 G4Exception("VoxelizedSensitiveDetector::ConstructXDivision", "WorldNotInit", FatalException,
175 "Voxelizing without having a pointer to world logical volume!");
176
177 if (!fDetector)
178 G4Exception("VoxelizedSensitiveDetector::ConstructXDivision", "DetConstInit", FatalException,
179 "Voxelizing without having a pointer to DetectorConstruction!");
180
181 fVoxelizedDetectorXDivision = new G4Box("VoxelizedDetectorXDivision", fVoxelWidthX / 2,
182 fDetector->GetSizeY() / 2, fDetector->GetSizeZ() / 2);
183
186 "VoxelizedDetectorXDivisionLog", 0, 0, 0);
187
189 new G4PVReplica("VoxelizedDetectorXDivisionPhys", fVoxelizedDetectorXDivisionLog, fWorldLogical,
191}
192
193//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
194
196{
197 fVoxelizedDetectorYDivision = new G4Box("VoxelizedDetectorYDivision", fVoxelWidthX / 2,
198 fVoxelWidthY / 2, fDetector->GetSizeZ() / 2);
199
202 "VoxelizedDetectorYDivisionLog", 0, 0, 0);
203
205 new G4PVReplica("VoxelizedDetectorYDivisionPhys", fVoxelizedDetectorYDivisionLog,
207}
208
209//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
210
226
227//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
228
229// First voxelize along X, then Y, then Z
231{
232 // Creating X division
234
235 // Creating Y division
237
238 // Creating Z division
240
241 // Set last, smallest volumes as sensitive
243 fIsBuilt = true;
244
245 return true;
246}
247
248//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
249
251{
252 // Nothing happens if the voxelized geometry is not built. But parameters are properly set.
253 if (!fIsBuilt) {
254 return;
255 }
256
258
259 // Volume that will be deleted in order to update
260 G4VPhysicalVolume* myVol;
261
262 G4PhysicalVolumeStore* store = G4PhysicalVolumeStore::GetInstance();
263
264 myVol = store->GetVolume("VoxelizedDetectorXDivisionPhys");
265 store->DeRegister(myVol);
266 myVol = store->GetVolume("VoxelizedDetectorYDivisionPhys");
267 store->DeRegister(myVol);
268 myVol = store->GetVolume("VoxelizedDetectorZDivisionPhys");
269 store->DeRegister(myVol);
271 new G4PVReplica("VoxelizedDetectorXDivisionPhys", fVoxelizedDetectorXDivisionLog, fWorldLogical,
273
275 new G4PVReplica("VoxelizedDetectorYDivisionPhys", fVoxelizedDetectorYDivisionLog,
277
279 new G4PVReplica("VoxelizedDetectorZDivisionPhys", fVoxelizedDetectorZDivisionLog,
281
282 G4RunManager::GetRunManager()->GeometryHasBeenModified();
283 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
284}
285
286//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
287
289{
290 G4String sensitiveDetectorName = "VoxelizedDetector";
291 G4String HCname = "LETdata";
292
293 SD* detectorSD = new SD(sensitiveDetectorName, HCname);
294 G4SDManager::GetSDMpointer()->AddNewDetector(detectorSD);
295 fSensitiveLogicalVolume->SetSensitiveDetector(detectorSD);
296}
297
298//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
299
304
305//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
306
308{
309 if (pWorld == nullptr)
310 G4Exception("VoxelizedSensitiveDetector::InitializeWorldPtr", "WorldinitNull", FatalException,
311 "Initializing Voxelization Class with a Null Pointer to World!");
312 fWorldLogical = pWorld->GetLogicalVolume();
313}
314
315//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
316
317// Returns absolute voxel index given matrix indexes
318G4int VoxelizedSensitiveDetector::GetThisVoxelNumber(G4int x, G4int y, G4int z) const
319{
320 G4int nz = GetVoxelNumberAlongZ();
321 G4int ny = GetVoxelNumberAlongY();
322
323 return z + nz * (y + ny * (x));
324}
325
326//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
327
328} // namespace RadioBio
Definition of the RadioBio::SD class.
Definition of the RadioBio::VoxelizedSensitiveDetectorMessenger class.
Definition of the RadioBio::VoxelizedSensitiveDetector class.
Mandatory class for the construction of geometry.
G4Material * GetMaterial()
Returns a pointer to the world material.
RadioBio sensitive detector class.
Singleton class performing the voxelization of the world volume and tracking of a voxel index given t...
void InitializeWorldPtr(G4VPhysicalVolume *pWorld)
Method to properly initialize the pointer to the World physical volume.
static VoxelizedSensitiveDetector * GetInstance()
Static method to retrieve a pointer to the only object existing in the simulation.
G4double GetVoxelNumberAlongZ() const
Method to get the voxel number along Z axis.
G4bool ConstructVoxelizedDetector()
Private method to construct the voxelized detector.
void UpdateVoxelVolume()
Private method to calculate the total volume of a voxel given the parameters saved inside the object.
VoxelizedSensitiveDetectorMessenger * fVoxelizedSensitiveDetectorMessenger
void ConstructSD()
Method to make the proper volume sensitive to allow scoring.
G4int GetThisVoxelNumber(G4int x, G4int j, G4int k) const
Method to get the absolute voxel index given its indexes in the three dimensions.
void SetVoxelWidthY(G4double voxWidthY)
Method to set the voxel Y width.
static VoxelizedSensitiveDetector * fInstance
void CalculateVoxelNumber()
Private method to calculate the total voxel number given the parameters saved inside the object.
static VoxelizedSensitiveDetector * CreateInstance(DetectorConstruction *det, double xWidth, double yWidth, double zWidth)
Static method to create the pointer to the only object existing in the simulation.
void ConstructZDivision()
Private method to further slice the Y columns along the Z axis, creating some boxes of material.
G4double GetVoxelNumberAlongY() const
Method to get the voxel number along Y axis.
VoxelizedSensitiveDetector(DetectorConstruction *det, double xWidth, double yWidth, double zWidth)
Private constructor using a pointer to DetectorConstruction and the three dimensions for one voxel.
void ConstructYDivision()
Private method to further slice the X slices along the Y axis, creating some "columns" of material.
void Construct()
Method to construct all the volumes for the voxelization of the geometry.
void SetVoxelWidth(G4ThreeVector voxWidth)
Method to set the voxel shape to be a box with given sides.
void UpdateVoxelizedGeometry()
Method to update voxelized geometry.
void SetVoxelWidthX(G4double voxWidthX)
Method to set the voxel X width.
void SetVoxelWidthZ(G4double voxWidthZ)
Method to set the voxel Z width.
void ConstructXDivision()
Private method to slice the world volume along the X axis.

Applications | User Support | Publications | Collaboration