Geant4  10.01.p02
HadrontherapyDetectorROGeometry.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 // Visit the Hadrontherapy web site (http://www.lns.infn.it/link/Hadrontherapy) to request
27 // the *COMPLETE* version of this program, together with its documentation;
28 // Hadrontherapy (both basic and full version) are supported by the Italian INFN
29 // Institute in the framework of the MC-INFN Group
30 //
31 #include "G4UnitsTable.hh"
32 #include "G4SystemOfUnits.hh"
33 #include "G4LogicalVolume.hh"
34 #include "G4VPhysicalVolume.hh"
35 #include "G4PVPlacement.hh"
36 #include "G4PVReplica.hh"
37 #include "G4Box.hh"
38 #include "G4ThreeVector.hh"
39 #include "G4Material.hh"
40 #include "G4NistManager.hh"
41 #include "G4GeometryManager.hh"
42 #include "G4SolidStore.hh"
43 #include "G4LogicalVolumeStore.hh"
44 
45 
46 
47 #include "G4SDManager.hh"
48 #include "G4RunManager.hh"
49 
50 #include "G4PhysicalVolumeStore.hh"
51 
52 #include "G4ThreeVector.hh"
53 
54 #include "globals.hh"
55 #include "G4Transform3D.hh"
56 #include "G4RotationMatrix.hh"
57 #include "G4Colour.hh"
58 #include "G4UserLimits.hh"
59 
60 #include "G4VisAttributes.hh"
61 
63 #include "HadrontherapyDummySD.hh"
65 
68  : G4VUserParallelWorld(aString),RODetector(0),RODetectorXDivision(0),
69  RODetectorYDivision(0),RODetectorZDivision(0),worldLogical(0),RODetectorLog(0),
70  RODetectorXDivisionLog(0),RODetectorYDivisionLog(0),RODetectorZDivisionLog(0),
71  sensitiveLogicalVolume(0)
72 {
73  isBuilt = false;
74  isInitialized = false;
75 }
76 
78 
80  G4double detectorDimX,
81  G4double detectorDimY,
82  G4double detectorDimZ,
83  G4int numberOfVoxelsX,
84  G4int numberOfVoxelsY,
85  G4int numberOfVoxelsZ)
86 {
88  detectorSizeX = detectorDimX;
89  detectorSizeY= detectorDimY;
90  detectorSizeZ=detectorDimZ;
91  numberOfVoxelsAlongX=numberOfVoxelsX;
92  numberOfVoxelsAlongY=numberOfVoxelsY;
93  numberOfVoxelsAlongZ=numberOfVoxelsZ;
94 
95  isInitialized = true;
96 
97 
98 
99 }
100 
102 {
103  //Nothing happens if the RO geometry is not built. But parameters are properly set.
104  if (!isBuilt)
105  {
106  //G4Exception("HadrontherapyDetectorROGeometry::UpdateROGeometry","had001",
107  // JustWarning,"Cannot update geometry before it is built");
108  return;
109  }
110 
111  //1) Update the dimensions of the G4Boxes
112  G4double halfDetectorSizeX = detectorSizeX;
113  G4double halfDetectorSizeY = detectorSizeY;
114  G4double halfDetectorSizeZ = detectorSizeZ;
115 
116  RODetector->SetXHalfLength(halfDetectorSizeX);
117  RODetector->SetYHalfLength(halfDetectorSizeY);
118  RODetector->SetZHalfLength(halfDetectorSizeZ);
119 
120  G4double halfXVoxelSizeX = halfDetectorSizeX/numberOfVoxelsAlongX;
121  G4double halfXVoxelSizeY = halfDetectorSizeY;
122  G4double halfXVoxelSizeZ = halfDetectorSizeZ;
123  G4double voxelXThickness = 2*halfXVoxelSizeX;
124 
125  RODetectorXDivision->SetXHalfLength(halfXVoxelSizeX);
126  RODetectorXDivision->SetYHalfLength(halfXVoxelSizeY);
127  RODetectorXDivision->SetZHalfLength(halfXVoxelSizeZ);
128 
129  G4double halfYVoxelSizeX = halfXVoxelSizeX;
130  G4double halfYVoxelSizeY = halfDetectorSizeY/numberOfVoxelsAlongY;
131  G4double halfYVoxelSizeZ = halfDetectorSizeZ;
132  G4double voxelYThickness = 2*halfYVoxelSizeY;
133 
134  RODetectorYDivision->SetXHalfLength(halfYVoxelSizeX);
135  RODetectorYDivision->SetYHalfLength(halfYVoxelSizeY);
136  RODetectorYDivision->SetZHalfLength(halfYVoxelSizeZ);
137 
138  G4double halfZVoxelSizeX = halfXVoxelSizeX;
139  G4double halfZVoxelSizeY = halfYVoxelSizeY;
140  G4double halfZVoxelSizeZ = halfDetectorSizeZ/numberOfVoxelsAlongZ;
141  G4double voxelZThickness = 2*halfZVoxelSizeZ;
142 
143  RODetectorZDivision->SetXHalfLength(halfZVoxelSizeX);
144  RODetectorZDivision->SetYHalfLength(halfZVoxelSizeY);
145  RODetectorZDivision->SetZHalfLength(halfZVoxelSizeZ);
146 
147  //Delete and re-build the relevant physical volumes
148  G4PhysicalVolumeStore* store =
150 
151  //Delete...
152  G4VPhysicalVolume* myVol = store->GetVolume("RODetectorPhys");
153  store->DeRegister(myVol);
154  //..and rebuild
155  G4VPhysicalVolume *RODetectorPhys = new G4PVPlacement(0,
158  "RODetectorPhys",
159  worldLogical,
160  false,0);
161 
162  myVol = store->GetVolume("RODetectorXDivisionPhys");
163  store->DeRegister(myVol);
164  G4VPhysicalVolume *RODetectorXDivisionPhys = new G4PVReplica("RODetectorXDivisionPhys",
166  RODetectorPhys,
167  kXAxis,
169  voxelXThickness);
170  myVol = store->GetVolume("RODetectorYDivisionPhys");
171  store->DeRegister(myVol);
172  G4VPhysicalVolume *RODetectorYDivisionPhys = new G4PVReplica("RODetectorYDivisionPhys",
174  RODetectorXDivisionPhys,
175  kYAxis,
177  voxelYThickness);
178 
179  myVol = store->GetVolume("RODetectorZDivisionPhys");
180  store->DeRegister(myVol);
181  new G4PVReplica("RODetectorZDivisionPhys",
183  RODetectorYDivisionPhys,
184  kZAxis,
186  voxelZThickness);
187 
188  return;
189 
190 }
191 
194 {;}
195 
198 {
199  // A dummy material is used to fill the volumes of the readout geometry.
200  // (It will be allowed to set a NULL pointer in volumes of such virtual
201  // division in future, since this material is irrelevant for tracking.)
202 
203 
204  //
205  // World
206  //
207  G4VPhysicalVolume* ghostWorld = GetWorld();
208  worldLogical = ghostWorld->GetLogicalVolume();
209 
210  if (!isInitialized)
211  {
212  G4Exception("HadrontherapyDetectorROGeometry::Construct","had001",
213  FatalException,"Parameters of the RO geometry are not initialized");
214  return;
215  }
216 
217 
218  G4double halfDetectorSizeX = detectorSizeX;
219  G4double halfDetectorSizeY = detectorSizeY;
220  G4double halfDetectorSizeZ = detectorSizeZ;
221 
222  // World volume of ROGeometry ... SERVE SOLO PER LA ROG
223 
224  // Detector ROGeometry
225  RODetector = new G4Box("RODetector",
226  halfDetectorSizeX,
227  halfDetectorSizeY,
228  halfDetectorSizeZ);
229 
231  0,
232  "RODetectorLog",
233  0,0,0);
234 
235 
236 
237  G4VPhysicalVolume *RODetectorPhys = new G4PVPlacement(0,
239  "RODetectorPhys",
240  worldLogical,
241  false,0);
242 
243 
244 
245 
246  // Division along X axis: the detector is divided in slices along the X axis
247 
248  G4double halfXVoxelSizeX = halfDetectorSizeX/numberOfVoxelsAlongX;
249  G4double halfXVoxelSizeY = halfDetectorSizeY;
250  G4double halfXVoxelSizeZ = halfDetectorSizeZ;
251  G4double voxelXThickness = 2*halfXVoxelSizeX;
252 
253 
254  RODetectorXDivision = new G4Box("RODetectorXDivision",
255  halfXVoxelSizeX,
256  halfXVoxelSizeY,
257  halfXVoxelSizeZ);
258 
260  0,
261  "RODetectorXDivisionLog",
262  0,0,0);
263 
264  G4VPhysicalVolume *RODetectorXDivisionPhys = new G4PVReplica("RODetectorXDivisionPhys",
266  RODetectorPhys,
267  kXAxis,
269  voxelXThickness);
270 
271  // Division along Y axis: the slices along the X axis are divided along the Y axis
272 
273  G4double halfYVoxelSizeX = halfXVoxelSizeX;
274  G4double halfYVoxelSizeY = halfDetectorSizeY/numberOfVoxelsAlongY;
275  G4double halfYVoxelSizeZ = halfDetectorSizeZ;
276  G4double voxelYThickness = 2*halfYVoxelSizeY;
277 
278  RODetectorYDivision = new G4Box("RODetectorYDivision",
279  halfYVoxelSizeX,
280  halfYVoxelSizeY,
281  halfYVoxelSizeZ);
282 
284  0,
285  "RODetectorYDivisionLog",
286  0,0,0);
287 
288  G4VPhysicalVolume *RODetectorYDivisionPhys = new G4PVReplica("RODetectorYDivisionPhys",
290  RODetectorXDivisionPhys,
291  kYAxis,
293  voxelYThickness);
294 
295  // Division along Z axis: the slices along the Y axis are divided along the Z axis
296 
297  G4double halfZVoxelSizeX = halfXVoxelSizeX;
298  G4double halfZVoxelSizeY = halfYVoxelSizeY;
299  G4double halfZVoxelSizeZ = halfDetectorSizeZ/numberOfVoxelsAlongZ;
300  G4double voxelZThickness = 2*halfZVoxelSizeZ;
301 
302  RODetectorZDivision = new G4Box("RODetectorZDivision",
303  halfZVoxelSizeX,
304  halfZVoxelSizeY,
305  halfZVoxelSizeZ);
306 
308  0,
309  "RODetectorZDivisionLog",
310  0,0,0);
311 
312  new G4PVReplica("RODetectorZDivisionPhys",
314  RODetectorYDivisionPhys,
315  kZAxis,
317  voxelZThickness);
318 
320  isBuilt = true;
321 }
322 
324 {
325 
326  G4String sensitiveDetectorName = "RODetector";
327 
328  HadrontherapyDetectorSD* detectorSD = new HadrontherapyDetectorSD(sensitiveDetectorName);
329 
331 
332 
333 }
334 
void SetZHalfLength(G4double dz)
Definition: G4Box.cc:171
CLHEP::Hep3Vector G4ThreeVector
G4VPhysicalVolume * GetWorld()
Definition: G4Box.hh:64
void Initialize(G4ThreeVector detectorPos, G4double detectorDimX, G4double detectorDimY, G4double detectorDimZ, G4int numberOfVoxelsX, G4int numberOfVoxelsY, G4int numberOfVoxelsZ)
int G4int
Definition: G4Types.hh:78
static void DeRegister(G4VPhysicalVolume *pSolid)
static G4PhysicalVolumeStore * GetInstance()
void SetSensitiveDetector(const G4String &logVolName, G4VSensitiveDetector *aSD, G4bool multi=false)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4LogicalVolume * GetLogicalVolume() const
void SetYHalfLength(G4double dy)
Definition: G4Box.cc:151
void SetXHalfLength(G4double dx)
Definition: G4Box.cc:131
double G4double
Definition: G4Types.hh:76
G4VPhysicalVolume * GetVolume(const G4String &name, G4bool verbose=true) const
static const G4double pos