Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BrachyDetectorConstruction.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 // GEANT 4 - Brachytherapy example
28 // --------------------------------------------------------------
29 //
30 // Code developed by:
31 // S. Agostinelli, F. Foppiano, S. Garelli , M. Tropeano, S.Guatelli
32 //
33 //
34 // ****************************************
35 // * *
36 // * BrachyDetectorConstruction.cc *
37 // * *
38 // ****************************************
39 //
40 #include "G4SystemOfUnits.hh"
41 #include "G4CSGSolid.hh"
43 #include "G4SDManager.hh"
44 #include "G4RunManager.hh"
45 #include "G4Box.hh"
46 #include "G4LogicalVolume.hh"
47 #include "G4ThreeVector.hh"
48 #include "G4PVPlacement.hh"
49 #include "globals.hh"
50 #include "G4MaterialTable.hh"
52 #include "G4Colour.hh"
53 #include "G4UserLimits.hh"
54 #include "G4VisAttributes.hh"
55 #include "BrachyMaterial.hh"
56 #include "BrachyFactoryLeipzig.hh"
57 #include "BrachyFactoryIr.hh"
58 #include "BrachyFactoryI.hh"
61 
63 : detectorChoice(0), factory(0),
64  World(0), WorldLog(0), WorldPhys(0),
65  Phantom(0), PhantomLog(0), PhantomPhys(0),
66  phantomAbsorberMaterial(0)
67 {
68  // Define half size of the phantom along the x, y, z axis
69  phantomSizeX = 15.*cm ;
70  phantomSizeY = 15.*cm;
71  phantomSizeZ = 15.*cm;
72 
73  // Define the sizes of the World volume containing the phantom
74  worldSizeX = 4.0*m;
75  worldSizeY = 4.0*m;
76  worldSizeZ = 4.0*m;
77 
78  // Define the messenger of the Detector component
79  // It is possible to modify geometrical parameters through UI
80  detectorMessenger = new BrachyDetectorMessenger(this);
81 
82  // Define the Iridium source as default source modelled in the geometry
83  factory = new BrachyFactoryIr();
84 
85  // BrachyMaterial defined the all the materials necessary
86  // for the experimental set-up
87  pMaterial = new BrachyMaterial();
88 }
89 
91 {
92  delete pMaterial;
93  delete factory;
94  delete detectorMessenger;
95 }
96 
98 {
99  pMaterial -> DefineMaterials();
100 
101  // Model the phantom (water box)
103 
104  // Model the source in the phantom
105  factory -> CreateSource(PhantomPhys);
106 
107  return WorldPhys;
108 }
109 
111 {
112  // Change the source in the water phantom
113  factory -> CleanSource();
114  delete factory;
115 
116  switch(detectorChoice)
117  {
118  case 1:
119  factory = new BrachyFactoryI();
120  break;
121  case 2:
122  factory = new BrachyFactoryLeipzig();
123  break;
124  case 3:
125  factory = new BrachyFactoryIr();
126  break;
127  default:
128  factory = new BrachyFactoryIr();
129  break;
130  }
131 
132  factory -> CreateSource(PhantomPhys);
133 
134  // Notify run manager that the new geometry has been built
135  G4RunManager::GetRunManager() -> DefineWorldVolume( WorldPhys );
136 }
137 
139 {
140  if(val == "Iodium")
141  {
142  detectorChoice = 1;
143  }
144  else
145  {
146  if(val=="Leipzig")
147  {
148  detectorChoice = 2;
149  }
150  else
151  {
152  if(val=="Iridium")
153  {
154  detectorChoice = 3;
155  }
156  }
157  }
158 
159  G4cout << "Now the source is " << val << G4endl;
160 }
161 
163 {
164  // Model the water phantom
165 
166  // Define the light blue color
167  G4Colour lblue (0.0, 0.0, .75);
168 
169  G4Material* air = pMaterial -> GetMat("Air") ;
170  G4Material* water = pMaterial -> GetMat("Water");
171 
172  // World volume
173  World = new G4Box("World",worldSizeX,worldSizeY,worldSizeZ);
174  WorldLog = new G4LogicalVolume(World,air,"WorldLog",0,0,0);
175  WorldPhys = new G4PVPlacement(0,G4ThreeVector(),
176  "WorldPhys",WorldLog,0,false,0);
177 
178  // Water Box
179  Phantom = new G4Box("Phantom",phantomSizeX,phantomSizeY,
180  phantomSizeZ);
181 
182  // Logical volume
183  PhantomLog = new G4LogicalVolume(Phantom,water,"PhantomLog",0,0,0);
184 
185  // Physical volume
186  PhantomPhys = new G4PVPlacement(0,G4ThreeVector(), // Position: rotation and translation
187  "PhantomPhys", // Name
188  PhantomLog, // Associated logical volume
189  WorldPhys, // Mother volume
190  false,0);
191 
192  WorldLog -> SetVisAttributes (G4VisAttributes::Invisible);
193 
194  // Visualization attributes of the phantom
195  G4VisAttributes* simpleBoxVisAtt = new G4VisAttributes(lblue);
196  simpleBoxVisAtt -> SetVisibility(true);
197  simpleBoxVisAtt -> SetForceWireframe(true);
198  PhantomLog -> SetVisAttributes(simpleBoxVisAtt);
199 }
200 
201 
203 {
204  G4cout << "-----------------------------------------------------------------------"
205  << G4endl
206  << "the phantom is a water box whose size is: " << G4endl
207  << phantomSizeX *2./cm
208  << " cm * "
209  << phantomSizeY *2./cm
210  << " cm * "
211  << phantomSizeZ *2./cm
212  << " cm" << G4endl
213  << "The phantom is made of "
214  << phantomAbsorberMaterial -> GetName() <<G4endl
215  << "the source is at the center of the phantom" << G4endl
216  << "-------------------------------------------------------------------------"
217  << G4endl;
218 }
219 
221 {
222  // It is possible to change the material of the phantom
223  // interactively
224 
225  // Search the material by its name
226  G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
227  if (pttoMaterial)
228  {
229  phantomAbsorberMaterial = pttoMaterial;
230  PhantomLog -> SetMaterial(pttoMaterial);
232  }
233  else
234  G4cout << "WARNING: material '" << materialChoice
235  << "' not available!" << G4endl;
236 }