source: trunk/examples/advanced/hadrontherapy/src/HadrontherapyDetectorConstruction.cc @ 812

Last change on this file since 812 was 807, checked in by garnier, 16 years ago

update

File size: 10.0 KB
Line 
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// $Id: HadrontherapyDetectorConstruction.cc; Version 4.0 May 2005
27// ----------------------------------------------------------------------------
28//                 GEANT 4 - Hadrontherapy example
29// ----------------------------------------------------------------------------
30// Code developed by:
31//
32// G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
33//
34// (a) Laboratori Nazionali del Sud
35//     of the INFN, Catania, Italy
36// (b) INFN Section of Genova, Genova, Italy
37//
38// * cirrone@lns.infn.it
39// ----------------------------------------------------------------------------
40
41#include "G4SDManager.hh"
42#include "G4RunManager.hh"
43#include "G4Box.hh"
44#include "G4LogicalVolume.hh"
45#include "G4ThreeVector.hh"
46#include "G4PVPlacement.hh"
47#include "globals.hh"
48#include "G4Transform3D.hh"
49#include "G4RotationMatrix.hh"
50#include "G4Colour.hh"
51#include "G4UserLimits.hh"
52#include "G4VisAttributes.hh"
53#include "HadrontherapyPhantomROGeometry.hh"
54#include "HadrontherapyDetectorMessenger.hh"
55#include "HadrontherapyPhantomSD.hh"
56#include "HadrontherapyDetectorConstruction.hh"
57#include "HadrontherapyMaterial.hh"
58#include "HadrontherapyBeamLine.hh"
59#include "HadrontherapyModulator.hh"
60
61HadrontherapyDetectorConstruction::HadrontherapyDetectorConstruction()
62  : phantomSD(0), phantomROGeometry(0), beamLine(0), modulator(0),
63    physicalTreatmentRoom(0),
64    patientPhysicalVolume(0), 
65    phantomLogicalVolume(0), 
66    phantomPhysicalVolume(0)
67{
68  // Messenger to change parameters of the geometry
69  detectorMessenger = new HadrontherapyDetectorMessenger(this);
70
71  material = new HadrontherapyMaterial();
72
73  // Phantom sizes
74  phantomSizeX = 20.*mm;
75  phantomSizeY = 20.*mm;
76  phantomSizeZ = 20.*mm;
77
78  // Number of the phantom voxels 
79  numberOfVoxelsAlongX = 200;
80  numberOfVoxelsAlongY = 200;
81  numberOfVoxelsAlongZ = 200;
82}
83
84HadrontherapyDetectorConstruction::~HadrontherapyDetectorConstruction()
85{ 
86  delete material;
87  if (phantomROGeometry) delete phantomROGeometry; 
88  delete detectorMessenger;
89}
90
91G4VPhysicalVolume* HadrontherapyDetectorConstruction::Construct()
92{ 
93  // Define the materials of the experimental set-up
94  material -> DefineMaterials();
95 
96  // Define the geometry components
97  ConstructBeamLine();
98  ConstructPhantom();
99 
100  // Set the sensitive detector where the energy deposit is collected
101  ConstructSensitiveDetector();
102 
103  return physicalTreatmentRoom;
104}
105
106void HadrontherapyDetectorConstruction::ConstructBeamLine()
107{ 
108  G4Material* air = material -> GetMat("Air") ;
109  G4Material* water = material -> GetMat("Water");
110
111  // ---------------------
112  // Treatment room - World volume
113  //---------------------
114
115  // Treatment room sizes
116  const G4double worldX = 400.0 *cm;
117  const G4double worldY = 400.0 *cm;
118  const G4double worldZ = 400.0 *cm;
119
120  G4Box* treatmentRoom = new G4Box("TreatmentRoom",worldX,worldY,worldZ);
121
122  G4LogicalVolume* logicTreatmentRoom = new G4LogicalVolume(treatmentRoom, 
123                                                            air, 
124                                                            "logicTreatmentRoom", 
125                                                            0,0,0);
126
127
128
129  physicalTreatmentRoom = new G4PVPlacement(0,
130                                            G4ThreeVector(),
131                                            "physicalTreatmentRoom", 
132                                            logicTreatmentRoom, 
133                                            0,false,0);
134
135  G4double maxStepTreatmentRoom = 0.1 *mm;
136  logicTreatmentRoom -> SetUserLimits(new G4UserLimits(maxStepTreatmentRoom));
137
138  // The treatment room is invisible in the Visualisation
139  logicTreatmentRoom -> SetVisAttributes (G4VisAttributes::Invisible);
140 
141  beamLine = new HadrontherapyBeamLine(physicalTreatmentRoom);
142  beamLine -> HadrontherapyBeamLineSupport();
143  beamLine -> HadrontherapyBeamScatteringFoils();
144  beamLine -> HadrontherapyBeamCollimators();
145  beamLine -> HadrontherapyBeamMonitoring();
146  beamLine -> HadrontherapyBeamNozzle();
147  beamLine -> HadrontherapyBeamFinalCollimator();
148
149  modulator = new HadrontherapyModulator();
150  modulator -> BuildModulator(physicalTreatmentRoom);
151
152  // Patient - Mother volume of the phantom
153  G4Box* patient = new G4Box("patient",20 *cm, 20 *cm, 20 *cm);
154
155  G4LogicalVolume* patientLogicalVolume = new G4LogicalVolume(patient,
156                                                              water, 
157                                                              "patientLog", 0, 0, 0);
158
159  patientPhysicalVolume = new G4PVPlacement(0,G4ThreeVector(0., 0., 0.),
160                                            "patientPhys",
161                                            patientLogicalVolume,
162                                            physicalTreatmentRoom,
163                                            false,0);
164 
165  // Visualisation attributes of the patient
166  G4VisAttributes * redWire = new G4VisAttributes(G4Colour(1. ,0. ,0.));
167  redWire -> SetVisibility(true);
168  redWire -> SetForceWireframe(true);
169  patientLogicalVolume -> SetVisAttributes(redWire); 
170}
171
172void HadrontherapyDetectorConstruction::ConstructPhantom()
173{
174  G4Colour  lightBlue   (0.0, 0.0, .75);
175
176  G4Material* water = material -> GetMat("Water");
177
178  //ComputeVoxelSize();
179
180  //----------------------
181  // Water phantom 
182  //----------------------
183  G4Box* phantom = new G4Box("Phantom",phantomSizeX,phantomSizeY,phantomSizeZ);
184
185  phantomLogicalVolume = new G4LogicalVolume(phantom,
186                                             water,
187                                             "PhantomLog",
188                                             0,0,0);
189
190  // Fixing the max step allowed in the phantom
191  G4double maxStep = 0.01 *mm;
192  phantomLogicalVolume -> SetUserLimits(new G4UserLimits(maxStep));
193
194  G4double phantomXtranslation = -180.*mm;
195  phantomPhysicalVolume = new G4PVPlacement(0,
196                                            G4ThreeVector(phantomXtranslation, 0.0 *mm, 0.0 *mm),
197                                            "PhantomPhys",
198                                            phantomLogicalVolume,
199                                            patientPhysicalVolume,
200                                            false,0);
201 
202  // Visualisation attributes of the phantom
203  G4VisAttributes* simpleBoxVisAttributes = new G4VisAttributes(lightBlue);
204  simpleBoxVisAttributes -> SetVisibility(true);
205  simpleBoxVisAttributes -> SetForceSolid(true);
206  phantomLogicalVolume -> SetVisAttributes(simpleBoxVisAttributes);
207
208  // **************
209  // Cut per Region
210  // **************
211 
212  // A smaller cut is fixed in the phantom to calculate the energy deposit with the
213  // required accuracy
214  G4Region* aRegion = new G4Region("PhantomLog");
215  phantomLogicalVolume -> SetRegion(aRegion);
216  aRegion -> AddRootLogicalVolume(phantomLogicalVolume);
217}
218
219void  HadrontherapyDetectorConstruction::ConstructSensitiveDetector()
220{ 
221  // Sensitive Detector and ReadOut geometry definition
222  G4SDManager* sensitiveDetectorManager = G4SDManager::GetSDMpointer();
223
224  G4String sensitiveDetectorName = "Phantom"; 
225
226  if(!phantomSD)
227    {
228      // The sensitive detector is instantiated
229      phantomSD = new HadrontherapyPhantomSD(sensitiveDetectorName);
230     
231      // The Read Out Geometry is instantiated
232      G4String ROGeometryName = "PhantomROGeometry";
233      phantomROGeometry = new HadrontherapyPhantomROGeometry(ROGeometryName,
234                                                             phantomSizeX,
235                                                             phantomSizeY,
236                                                             phantomSizeZ,
237                                                             numberOfVoxelsAlongX,
238                                                             numberOfVoxelsAlongY,
239                                                             numberOfVoxelsAlongZ);
240      phantomROGeometry -> BuildROGeometry();
241      phantomSD -> SetROgeometry(phantomROGeometry);
242      sensitiveDetectorManager -> AddNewDetector(phantomSD);
243      phantomLogicalVolume -> SetSensitiveDetector(phantomSD);
244    }
245}
246
247void HadrontherapyDetectorConstruction::SetModulatorAngle(G4double value)
248{ 
249  modulator -> SetModulatorAngle(value);
250  G4RunManager::GetRunManager() -> GeometryHasBeenModified();
251}
252
253void HadrontherapyDetectorConstruction::SetRangeShifterXPosition(G4double value)
254{
255  beamLine -> SetRangeShifterXPosition(value);
256  G4RunManager::GetRunManager() -> GeometryHasBeenModified();
257}
258
259void HadrontherapyDetectorConstruction::SetRangeShifterXSize(G4double value)
260{
261  beamLine -> SetRangeShifterXSize(value);
262  G4RunManager::GetRunManager() -> GeometryHasBeenModified();
263}
264
265void HadrontherapyDetectorConstruction::SetFirstScatteringFoilSize(G4double value)
266{
267  beamLine -> SetFirstScatteringFoilXSize(value); 
268  G4RunManager::GetRunManager() -> GeometryHasBeenModified();
269}
270
271void HadrontherapyDetectorConstruction::SetSecondScatteringFoilSize(G4double value)
272{
273  beamLine -> SetSecondScatteringFoilXSize(value);
274  G4RunManager::GetRunManager() -> GeometryHasBeenModified();
275}
276
277void HadrontherapyDetectorConstruction::SetOuterRadiusStopper(G4double value)
278{
279  beamLine -> SetOuterRadiusStopper(value); 
280  G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 
281}
282
283void HadrontherapyDetectorConstruction::SetInnerRadiusFinalCollimator(G4double value)
284{
285  beamLine -> SetInnerRadiusFinalCollimator(value);
286  G4RunManager::GetRunManager() -> GeometryHasBeenModified();
287}
288
289void HadrontherapyDetectorConstruction::SetRSMaterial(G4String materialChoice)
290{
291  beamLine -> SetRSMaterial(materialChoice);
292}
293
294
295
Note: See TracBrowser for help on using the repository browser.