source: trunk/examples/advanced/brachytherapy/src/BrachyDetectorConstruction.cc @ 1319

Last change on this file since 1319 was 1230, checked in by garnier, 14 years ago

update to geant4.9.3

File size: 9.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// --------------------------------------------------------------
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// $Id: BrachyDetectorConstruction.cc,v 1.29 2006/06/29 15:48:09 gunter Exp $
41// GEANT4 tag $Name: geant4-09-03-cand-01 $
42//
43#include "G4CSGSolid.hh"
44#include "G4MaterialPropertyVector.hh"
45#include "G4SDManager.hh"
46#include "G4RunManager.hh"
47#include "G4Box.hh"
48#include "G4LogicalVolume.hh"
49#include "G4ThreeVector.hh"
50#include "G4PVPlacement.hh"
51#include "globals.hh"
52#include "G4MaterialTable.hh"
53#include "G4TransportationManager.hh"
54#include "G4Colour.hh"
55#include "G4UserLimits.hh"
56#include "G4VisAttributes.hh"
57#include "BrachyMaterial.hh"
58#include "BrachyFactoryLeipzig.hh"
59#include "BrachyFactoryIr.hh"
60#include "BrachyFactoryI.hh"
61#include "BrachyPhantomROGeometry.hh"
62#include "BrachyPhantomSD.hh"
63#include "BrachyDetectorMessenger.hh"
64#include "BrachyDetectorConstruction.hh"
65
66BrachyDetectorConstruction::BrachyDetectorConstruction(G4String &SDName)
67: detectorChoice(0), phantomSD(0), phantomROGeometry(0), factory(0),
68  World(0), WorldLog(0), WorldPhys(0),
69  Phantom(0), PhantomLog(0), PhantomPhys(0),
70  phantomAbsorberMaterial(0)
71{
72  // Define half size of the phantom along the x, y, z axis
73  phantomSizeX = 15.*cm ;
74  phantomSizeY = 15.*cm;
75  phantomSizeZ = 15.*cm;
76
77  // Define the number of voxels the phantom is subdivided along the
78  // three axis
79  // Each voxel is 1 mm wide
80  numberOfVoxelsAlongX = 300;
81  numberOfVoxelsAlongY = 300;
82  numberOfVoxelsAlongZ = 300;
83
84  ComputeDimVoxel();
85 
86  // Define the sizes of the World volume contaning the phantom
87  worldSizeX = 4.0*m;
88  worldSizeY = 4.0*m;
89  worldSizeZ = 4.0*m;
90
91  sensitiveDetectorName = SDName;
92
93  // Define the messenger of the Detector component
94  // It is possible to modify geometrical parameters through UI
95  detectorMessenger = new BrachyDetectorMessenger(this);
96
97  // Define the Iridium source as default source modelled in the geometry
98  factory = new BrachyFactoryIr();
99
100  // BrachyMaterial defined the all the materials necessary
101  // for the experimental set-up
102  pMaterial = new BrachyMaterial();
103}
104
105BrachyDetectorConstruction::~BrachyDetectorConstruction()
106{ 
107  delete pMaterial;
108  delete factory;
109  delete detectorMessenger;
110  if (phantomROGeometry) delete phantomROGeometry;
111}
112
113G4VPhysicalVolume* BrachyDetectorConstruction::Construct()
114{
115  pMaterial -> DefineMaterials();
116 
117  // Model the phantom (water box) 
118  ConstructPhantom();
119
120  // Model the source in the phantom
121  factory -> CreateSource(PhantomPhys); //Build the source inside the phantom
122 
123  // Define the sensitive volume: phantom
124  ConstructSensitiveDetector();
125
126  return WorldPhys;
127}
128
129void BrachyDetectorConstruction::SwitchBrachytherapicSeed()
130{
131  // Change the source in the water phantom
132  factory -> CleanSource();
133  delete factory;
134
135  switch(detectorChoice)
136  { 
137    case 1:
138      factory = new BrachyFactoryI();
139      break;
140    case 2:
141      factory = new BrachyFactoryLeipzig();
142      break;
143    case 3:
144      factory = new BrachyFactoryIr();
145      break;   
146    default:
147      factory = new BrachyFactoryIr();
148      break;
149  }
150
151  factory -> CreateSource(PhantomPhys);
152
153  // Notify run manager that the new geometry has been built
154  G4RunManager::GetRunManager() -> DefineWorldVolume( WorldPhys );
155}
156
157void BrachyDetectorConstruction::SelectBrachytherapicSeed(G4String val)
158{
159  if(val == "Iodium") 
160  {
161   detectorChoice = 1;
162  }
163  else
164  {
165    if(val=="Leipzig")
166    {
167      detectorChoice = 2;
168    }
169    else
170    {
171      if(val=="Iridium")
172      {
173        detectorChoice = 3;
174      }
175    }
176  }
177
178  G4cout << "Now the source is " << val << G4endl;
179}
180
181void BrachyDetectorConstruction::ConstructPhantom()
182{
183  // Model the water phantom
184 
185  // Define the light blue color
186  G4Colour  lblue   (0.0, 0.0, .75);
187
188  G4Material* air = pMaterial -> GetMat("Air") ;
189  G4Material* water = pMaterial -> GetMat("Water");
190
191  ComputeDimVoxel();
192
193  // World volume
194  World = new G4Box("World",worldSizeX,worldSizeY,worldSizeZ);
195  WorldLog = new G4LogicalVolume(World,air,"WorldLog",0,0,0);
196  WorldPhys = new G4PVPlacement(0,G4ThreeVector(),
197                                "WorldPhys",WorldLog,0,false,0);
198
199  // Water Box
200  Phantom = new G4Box("Phantom",phantomSizeX,phantomSizeY,
201                       phantomSizeZ);
202
203  // Logical volume
204  PhantomLog = new G4LogicalVolume(Phantom,water,"PhantomLog",0,0,0);
205
206  // Physical volume
207  PhantomPhys = new G4PVPlacement(0,G4ThreeVector(), // Position: rotation and translation
208                                  "PhantomPhys", // Name
209                                  PhantomLog, // Associated logical volume
210                                  WorldPhys, // Mother volume
211                                  false,0); 
212
213  WorldLog -> SetVisAttributes (G4VisAttributes::Invisible);
214
215  // Visualization attributes of the phantom
216  G4VisAttributes* simpleBoxVisAtt = new G4VisAttributes(lblue);
217  simpleBoxVisAtt -> SetVisibility(true);
218  simpleBoxVisAtt -> SetForceWireframe(true);
219  PhantomLog -> SetVisAttributes(simpleBoxVisAtt);
220}
221
222void  BrachyDetectorConstruction::ConstructSensitiveDetector()
223// Sensitive Detector and ReadOut geometry definition
224{ 
225  G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
226
227  if(!phantomSD)
228  {
229    phantomSD = new BrachyPhantomSD(sensitiveDetectorName);
230    G4String ROGeometryName = "PhantomROGeometry";
231    phantomROGeometry = new BrachyPhantomROGeometry(ROGeometryName,
232                                phantomSizeX, 
233                                phantomSizeY, 
234                                phantomSizeZ,
235                                numberOfVoxelsAlongX,
236                                numberOfVoxelsAlongY,               
237                                numberOfVoxelsAlongZ);
238    phantomROGeometry -> BuildROGeometry();
239    phantomSD -> SetROgeometry(phantomROGeometry);
240    pSDManager -> AddNewDetector(phantomSD);
241   
242    PhantomLog -> SetSensitiveDetector(phantomSD);
243  }
244}
245
246void BrachyDetectorConstruction::PrintDetectorParameters()
247{
248  G4cout << "-----------------------------------------------------------------------"
249         << G4endl
250         << "the phantom is a water box whose size is: " << G4endl
251         << phantomSizeX *2./cm
252         << " cm * "
253         << phantomSizeY *2./cm
254         << " cm * "
255         << phantomSizeZ *2./cm
256         << " cm" << G4endl
257         << "number of Voxel: "
258         << numberOfVoxelsAlongX <<G4endl
259         << "Voxel size: "
260         << dimVoxel * 2/mm
261         << "mm" << G4endl
262         << "The phantom is made of "
263         << phantomAbsorberMaterial -> GetName() <<G4endl
264         << "the source is at the center of the phantom" << G4endl
265         << "-------------------------------------------------------------------------"
266         << G4endl;
267}
268
269void BrachyDetectorConstruction::SetPhantomMaterial(G4String materialChoice)
270{
271  // It is possible to change the material of the phantom
272  // interactively
273
274  // Search the material by its name   
275  G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);     
276  if (pttoMaterial)
277  {
278    phantomAbsorberMaterial = pttoMaterial;
279    PhantomLog -> SetMaterial(pttoMaterial); 
280    PrintDetectorParameters();
281  } 
282  else
283    G4cout << "WARNING: material '" << materialChoice
284           << "' not available!" << G4endl;           
285}
Note: See TracBrowser for help on using the repository browser.