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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 ]

Diff markup

Differences between /examples/extended/medical/radiobiology/src/VoxelizedSensitiveDetector.cc (Version 11.3.0) and /examples/extended/medical/radiobiology/src/VoxelizedSensitiveDetector.cc (Version 9.0.p2)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 //                                                
 27 /// \file radiobiology/src/VoxelizedSensitiveD    
 28 /// \brief Implementation of the RadioBio::Vox    
 29                                                   
 30 #include "VoxelizedSensitiveDetector.hh"          
 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"                                  
 44 #include "VoxelizedSensitiveDetectorMessenger.    
 45                                                   
 46 namespace RadioBio                                
 47 {                                                 
 48                                                   
 49 //....oooOO0OOooo........oooOO0OOooo........oo    
 50                                                   
 51 VoxelizedSensitiveDetector* VoxelizedSensitive    
 52                                                   
 53 //....oooOO0OOooo........oooOO0OOooo........oo    
 54                                                   
 55 VoxelizedSensitiveDetector* VoxelizedSensitive    
 56                                                   
 57                                                   
 58 {                                                 
 59   if (fInstance) {                                
 60     delete fInstance;                             
 61     G4Exception("VoxelizedSensitiveDetector::c    
 62                 FatalException, "Creating anot    
 63   }                                               
 64   fInstance = new VoxelizedSensitiveDetector(d    
 65   return fInstance;                               
 66 }                                                 
 67                                                   
 68 //....oooOO0OOooo........oooOO0OOooo........oo    
 69                                                   
 70 VoxelizedSensitiveDetector* VoxelizedSensitive    
 71 {                                                 
 72   return fInstance;                               
 73 }                                                 
 74                                                   
 75 //....oooOO0OOooo........oooOO0OOooo........oo    
 76                                                   
 77 VoxelizedSensitiveDetector::VoxelizedSensitive    
 78                                                   
 79   : fDetector(det), fVoxelWidthX(xWidth), fVox    
 80 {                                                 
 81   fVoxelizedSensitiveDetectorMessenger = new V    
 82   UpdateVoxelVolume();                            
 83   CalculateVoxelNumber();                         
 84 }                                                 
 85                                                   
 86 //....oooOO0OOooo........oooOO0OOooo........oo    
 87                                                   
 88 VoxelizedSensitiveDetector::~VoxelizedSensitiv    
 89 {                                                 
 90   delete fVoxelizedSensitiveDetectorMessenger;    
 91 }                                                 
 92                                                   
 93 //....oooOO0OOooo........oooOO0OOooo........oo    
 94                                                   
 95 void VoxelizedSensitiveDetector::UpdateVoxelVo    
 96 {                                                 
 97   fVoxelVolume = fVoxelWidthX * fVoxelWidthY *    
 98   fVoxelDensity = fDetector->GetMaterial()->Ge    
 99   fVoxelMass = fVoxelVolume * fVoxelDensity;      
100 }                                                 
101                                                   
102 //....oooOO0OOooo........oooOO0OOooo........oo    
103                                                   
104 void VoxelizedSensitiveDetector::SetVoxelWidth    
105 {                                                 
106   fVoxelWidthX = voxWidth.getX();                 
107   fVoxelWidthY = voxWidth.getY();                 
108   fVoxelWidthZ = voxWidth.getZ();                 
109   CalculateVoxelNumber();                         
110 }                                                 
111                                                   
112 //....oooOO0OOooo........oooOO0OOooo........oo    
113                                                   
114 void VoxelizedSensitiveDetector::SetVoxelWidth    
115 {                                                 
116   if (fVoxelWidthX == voxWidthX) return;          
117   fVoxelWidthX = voxWidthX;                       
118   CalculateVoxelNumber();                         
119 }                                                 
120                                                   
121 //....oooOO0OOooo........oooOO0OOooo........oo    
122                                                   
123 void VoxelizedSensitiveDetector::SetVoxelWidth    
124 {                                                 
125   if (fVoxelWidthY == voxWidthY) return;          
126   fVoxelWidthY = voxWidthY;                       
127   CalculateVoxelNumber();                         
128 }                                                 
129                                                   
130 //....oooOO0OOooo........oooOO0OOooo........oo    
131                                                   
132 void VoxelizedSensitiveDetector::SetVoxelWidth    
133 {                                                 
134   if (fVoxelWidthZ == voxWidthZ) return;          
135   fVoxelWidthZ = voxWidthZ;                       
136   CalculateVoxelNumber();                         
137 }                                                 
138                                                   
139 //....oooOO0OOooo........oooOO0OOooo........oo    
140                                                   
141 // Calculte number of voxel approximating for     
142 // Then recalculates voxels size according to     
143 void VoxelizedSensitiveDetector::CalculateVoxe    
144 {                                                 
145   fVoxelNumberAlongX = G4int(fDetector->GetSiz    
146   fVoxelWidthX = fDetector->GetSizeX() / G4dou    
147                                                   
148   fVoxelNumberAlongY = G4int(fDetector->GetSiz    
149   fVoxelWidthY = fDetector->GetSizeY() / G4dou    
150                                                   
151   fVoxelNumberAlongZ = G4int(fDetector->GetSiz    
152   fVoxelWidthZ = fDetector->GetSizeZ() / G4dou    
153                                                   
154   if (fVoxelNumberAlongY % 2 == 0)                
155     G4Exception("VoxelizedSensitiveDetector::C    
156                 "Trying to voxelize with an ev    
157                 "Please select an odd number t    
158                                                   
159   if (fVoxelNumberAlongZ % 2 == 0)                
160     G4Exception("VoxelizedSensitiveDetector::C    
161                 "Trying to voxelize with an ev    
162                 "Please select an odd number t    
163                                                   
164   fTotalVoxelNumber = fVoxelNumberAlongX * fVo    
165                                                   
166   UpdateVoxelVolume();                            
167 }                                                 
168                                                   
169 //....oooOO0OOooo........oooOO0OOooo........oo    
170                                                   
171 void VoxelizedSensitiveDetector::ConstructXDiv    
172 {                                                 
173   if (fWorldLogical == nullptr)                   
174     G4Exception("VoxelizedSensitiveDetector::C    
175                 "Voxelizing without having a p    
176                                                   
177   if (!fDetector)                                 
178     G4Exception("VoxelizedSensitiveDetector::C    
179                 "Voxelizing without having a p    
180                                                   
181   fVoxelizedDetectorXDivision = new G4Box("Vox    
182                                           fDet    
183                                                   
184   fVoxelizedDetectorXDivisionLog =                
185     new G4LogicalVolume(fVoxelizedDetectorXDiv    
186                         "VoxelizedDetectorXDiv    
187                                                   
188   fVoxelizedDetectorXDivisionPhys =               
189     new G4PVReplica("VoxelizedDetectorXDivisio    
190                     kXAxis, fVoxelNumberAlongX    
191 }                                                 
192                                                   
193 //....oooOO0OOooo........oooOO0OOooo........oo    
194                                                   
195 void VoxelizedSensitiveDetector::ConstructYDiv    
196 {                                                 
197   fVoxelizedDetectorYDivision = new G4Box("Vox    
198                                           fVox    
199                                                   
200   fVoxelizedDetectorYDivisionLog =                
201     new G4LogicalVolume(fVoxelizedDetectorYDiv    
202                         "VoxelizedDetectorYDiv    
203                                                   
204   fVoxelizedDetectorYDivisionPhys =               
205     new G4PVReplica("VoxelizedDetectorYDivisio    
206                     fVoxelizedDetectorXDivisio    
207 }                                                 
208                                                   
209 //....oooOO0OOooo........oooOO0OOooo........oo    
210                                                   
211 void VoxelizedSensitiveDetector::ConstructZDiv    
212 {                                                 
213   fVoxelizedDetectorZDivision =                   
214     new G4Box("VoxelizedDetectorZDivision", fV    
215                                                   
216   fVoxelizedDetectorZDivisionLog =                
217     new G4LogicalVolume(fVoxelizedDetectorZDiv    
218                         "VoxelizedDetectorZDiv    
219                                                   
220   fVoxelizedDetectorZDivisionPhys =               
221     new G4PVReplica("VoxelizedDetectorZDivisio    
222                     fVoxelizedDetectorYDivisio    
223                                                   
224   fSensitiveLogicalVolume = fVoxelizedDetector    
225 }                                                 
226                                                   
227 //....oooOO0OOooo........oooOO0OOooo........oo    
228                                                   
229 // First voxelize along X, then Y, then Z         
230 G4bool VoxelizedSensitiveDetector::ConstructVo    
231 {                                                 
232   // Creating X division                          
233   ConstructXDivision();                           
234                                                   
235   // Creating Y division                          
236   ConstructYDivision();                           
237                                                   
238   // Creating Z division                          
239   ConstructZDivision();                           
240                                                   
241   // Set last, smallest volumes as sensitive      
242   fSensitiveLogicalVolume = fVoxelizedDetector    
243   fIsBuilt = true;                                
244                                                   
245   return true;                                    
246 }                                                 
247                                                   
248 //....oooOO0OOooo........oooOO0OOooo........oo    
249                                                   
250 void VoxelizedSensitiveDetector::UpdateVoxeliz    
251 {                                                 
252   // Nothing happens if the voxelized geometry    
253   if (!fIsBuilt) {                                
254     return;                                       
255   }                                               
256                                                   
257   CalculateVoxelNumber();                         
258                                                   
259   // Volume that will be deleted in order to u    
260   G4VPhysicalVolume* myVol;                       
261                                                   
262   G4PhysicalVolumeStore* store = G4PhysicalVol    
263                                                   
264   myVol = store->GetVolume("VoxelizedDetectorX    
265   store->DeRegister(myVol);                       
266   myVol = store->GetVolume("VoxelizedDetectorY    
267   store->DeRegister(myVol);                       
268   myVol = store->GetVolume("VoxelizedDetectorZ    
269   store->DeRegister(myVol);                       
270   fVoxelizedDetectorXDivisionPhys =               
271     new G4PVReplica("VoxelizedDetectorXDivisio    
272                     kXAxis, fVoxelNumberAlongX    
273                                                   
274   fVoxelizedDetectorYDivisionPhys =               
275     new G4PVReplica("VoxelizedDetectorYDivisio    
276                     fVoxelizedDetectorXDivisio    
277                                                   
278   fVoxelizedDetectorZDivisionPhys =               
279     new G4PVReplica("VoxelizedDetectorZDivisio    
280                     fVoxelizedDetectorYDivisio    
281                                                   
282   G4RunManager::GetRunManager()->GeometryHasBe    
283   G4RunManager::GetRunManager()->PhysicsHasBee    
284 }                                                 
285                                                   
286 //....oooOO0OOooo........oooOO0OOooo........oo    
287                                                   
288 void VoxelizedSensitiveDetector::ConstructSD()    
289 {                                                 
290   G4String sensitiveDetectorName = "VoxelizedD    
291   G4String HCname = "LETdata";                    
292                                                   
293   SD* detectorSD = new SD(sensitiveDetectorNam    
294   G4SDManager::GetSDMpointer()->AddNewDetector    
295   fSensitiveLogicalVolume->SetSensitiveDetecto    
296 }                                                 
297                                                   
298 //....oooOO0OOooo........oooOO0OOooo........oo    
299                                                   
300 void VoxelizedSensitiveDetector::Construct()      
301 {                                                 
302   ConstructVoxelizedDetector();                   
303 }                                                 
304                                                   
305 //....oooOO0OOooo........oooOO0OOooo........oo    
306                                                   
307 void VoxelizedSensitiveDetector::InitializeWor    
308 {                                                 
309   if (pWorld == nullptr)                          
310     G4Exception("VoxelizedSensitiveDetector::I    
311                 "Initializing Voxelization Cla    
312   fWorldLogical = pWorld->GetLogicalVolume();     
313 }                                                 
314                                                   
315 //....oooOO0OOooo........oooOO0OOooo........oo    
316                                                   
317 // Returns absolute voxel index given matrix i    
318 G4int VoxelizedSensitiveDetector::GetThisVoxel    
319 {                                                 
320   G4int nz = GetVoxelNumberAlongZ();              
321   G4int ny = GetVoxelNumberAlongY();              
322                                                   
323   return z + nz * (y + ny * (x));                 
324 }                                                 
325                                                   
326 //....oooOO0OOooo........oooOO0OOooo........oo    
327                                                   
328 }  // namespace RadioBio                          
329