Geant4 Cross Reference |
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: S. Guatelli, D. Cutajar, A. Le 31 // Past developers: S. Agostinelli, F. Foppiano, S. Garelli , M. Tropeano 32 // 33 // 34 // **************************************** 35 // * * 36 // * BrachyDetectorConstruction.cc * 37 // * * 38 // **************************************** 39 // 40 #include "BrachyFactoryLeipzig.hh" 41 #include "BrachyFactoryTG186.hh" 42 #include "BrachyFactoryI.hh" 43 #include "BrachyFactoryFlexi.hh" 44 #include "BrachyFactoryOncura6711.hh" 45 #include "BrachyDetectorMessenger.hh" 46 #include "BrachyDetectorConstruction.hh" 47 #include "G4SystemOfUnits.hh" 48 #include "G4CSGSolid.hh" 49 #include "G4MaterialPropertyVector.hh" 50 #include "G4SDManager.hh" 51 #include "G4RunManager.hh" 52 #include "G4Box.hh" 53 #include "G4LogicalVolume.hh" 54 #include "G4ThreeVector.hh" 55 #include "G4PVPlacement.hh" 56 #include "globals.hh" 57 #include "G4MaterialTable.hh" 58 #include "G4TransportationManager.hh" 59 #include "G4Colour.hh" 60 #include "G4UserLimits.hh" 61 #include "G4VisAttributes.hh" 62 #include "G4NistManager.hh" 63 64 BrachyDetectorConstruction::BrachyDetectorConstruction(): 65 fFactory(nullptr), fWorld(nullptr), fWorldLog(nullptr), fWorldPhys(nullptr), 66 fPhantom(nullptr), fPhantomLog(nullptr), fPhantomPhys(nullptr), 67 fDetectorChoice(0) 68 { 69 // Define the messenger of the Detector component 70 fDetectorMessenger = new BrachyDetectorMessenger(this); 71 72 // Define half size of the phantom along the x, y, z axis 73 fPhantomSizeX = 15.*cm; 74 fPhantomSizeY = 15.*cm; 75 fPhantomSizeZ = 15.*cm; 76 77 // Define the sizes of the World volume containing the phantom 78 fWorldSizeX = 4.0*m; 79 fWorldSizeY = 4.0*m; 80 fWorldSizeZ = 4.0*m; 81 82 // Define the Flexi source as default source modelled in the geometry 83 fFactory = new BrachyFactoryFlexi(); 84 } 85 86 BrachyDetectorConstruction::~BrachyDetectorConstruction() 87 { 88 delete fDetectorMessenger; 89 delete fFactory; 90 } 91 92 G4VPhysicalVolume* BrachyDetectorConstruction::Construct() 93 { 94 // Model the phantom (water box) 95 ConstructPhantom(); 96 97 // Model the source in the phantom 98 fFactory -> CreateSource(fPhantomPhys); 99 100 return fWorldPhys; 101 } 102 103 void BrachyDetectorConstruction::SwitchBrachytherapicSeed() 104 { 105 // Change the source in the water phantom 106 fFactory -> CleanSource(); 107 G4cout << "Old brachy source is deleted ..." << G4endl; 108 delete fFactory; 109 110 switch(fDetectorChoice) 111 { 112 case 1: 113 fFactory = new BrachyFactoryI(); 114 break; 115 case 2: 116 fFactory = new BrachyFactoryLeipzig(); 117 break; 118 case 3: 119 fFactory = new BrachyFactoryTG186(); 120 break; 121 case 4: 122 fFactory = new BrachyFactoryFlexi(); 123 break; 124 case 5: 125 fFactory = new BrachyFactoryOncura6711(); 126 break; 127 default: 128 fFactory = new BrachyFactoryFlexi(); 129 break; 130 } 131 132 fFactory -> CreateSource(fPhantomPhys); 133 G4cout << "New brachy source is created ..." << G4endl; 134 135 // Notify run manager that the new geometry has been built 136 G4RunManager::GetRunManager() -> GeometryHasBeenModified(); 137 } 138 139 void BrachyDetectorConstruction::SelectBrachytherapicSeed(G4String val) 140 { 141 if (val == "Iodine") 142 fDetectorChoice = 1; 143 else 144 { 145 if(val=="Leipzig") 146 fDetectorChoice = 2; 147 else 148 { 149 if(val=="TG186") 150 fDetectorChoice = 3; 151 else 152 { 153 if(val=="Flexi") 154 fDetectorChoice = 4; 155 else 156 { 157 if(val=="Oncura") 158 fDetectorChoice = 5; 159 else 160 G4cout << val << "is not available!!!!" << G4endl; 161 } 162 } 163 } 164 } 165 G4cout << "Now the brachy source is " << val << G4endl; 166 } 167 168 void BrachyDetectorConstruction::ConstructPhantom() 169 { 170 // Model the water phantom 171 172 // Define the light blue color 173 G4Colour lblue (0.0, 0.0, .75); 174 175 //Get nist material manager 176 G4NistManager* nist = G4NistManager::Instance(); 177 G4Material* air = nist -> FindOrBuildMaterial("G4_AIR"); 178 G4Material* water = nist -> FindOrBuildMaterial("G4_WATER"); 179 180 // World volume 181 fWorld = new G4Box("World", fWorldSizeX, fWorldSizeY, fWorldSizeZ); 182 fWorldLog = new G4LogicalVolume(fWorld,air,"WorldLog",nullptr,nullptr,nullptr); 183 fWorldPhys = new G4PVPlacement(nullptr,G4ThreeVector(),"WorldPhys",fWorldLog,nullptr,false,0); 184 185 // Water Box 186 fPhantom = new G4Box("Phantom", fPhantomSizeX, fPhantomSizeY, fPhantomSizeZ); 187 188 // Logical volume 189 fPhantomLog = new G4LogicalVolume(fPhantom,water,"PhantomLog",nullptr,nullptr,nullptr); 190 191 // Physical volume 192 fPhantomPhys = new G4PVPlacement(nullptr,G4ThreeVector(), // Position: rotation and translation 193 "PhantomPhys", // Name 194 fPhantomLog, // Associated logical volume 195 fWorldPhys, // Mother volume 196 false,0); 197 198 fWorldLog -> SetVisAttributes (G4VisAttributes::GetInvisible()); 199 200 // Visualization attributes of the phantom 201 auto simpleBoxVisAtt = new G4VisAttributes(lblue); 202 simpleBoxVisAtt -> SetVisibility(true); 203 simpleBoxVisAtt -> SetForceWireframe(true); 204 fPhantomLog -> SetVisAttributes(simpleBoxVisAtt); 205 } 206 207 void BrachyDetectorConstruction::PrintDetectorParameters() 208 { 209 G4cout << "----------------" << G4endl 210 << "the phantom is a water box whose size is: " << G4endl 211 << fPhantomSizeX *2./cm 212 << " cm * " 213 << fPhantomSizeY *2./cm 214 << " cm * " 215 << fPhantomSizeZ *2./cm 216 << " cm" << G4endl 217 << "The phantom is made of " 218 << fPhantomLog -> GetMaterial() -> GetName() <<G4endl 219 << "the source is at the center of the phantom" << G4endl 220 << "----------------" 221 << G4endl; 222 } 223 224 void BrachyDetectorConstruction::SetPhantomMaterial(G4String materialChoice) 225 { 226 // Method to change the material of the phantom 227 228 G4NistManager* nist = G4NistManager::Instance(); 229 230 // Search the material by its name 231 G4Material* pttoMaterial = nist -> FindOrBuildMaterial(materialChoice); 232 233 if (pttoMaterial) 234 { 235 fPhantomLog -> SetMaterial(pttoMaterial); 236 PrintDetectorParameters(); 237 } else G4cout << "WARNING: material '" << materialChoice << "' not available!" << G4endl; 238 } 239