Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // ------------------------------------------- 26 // -------------------------------------------------------------- 27 // GEANT 4 - Brachytherapy exa 27 // GEANT 4 - Brachytherapy example 28 // ------------------------------------------- 28 // -------------------------------------------------------------- 29 // 29 // 30 // Code developed by: S. Guatelli, D. Cutajar, << 30 // Code developed by: 31 // Past developers: S. Agostinelli, F. Foppian << 31 // S. Agostinelli, F. Foppiano, S. Garelli , M. Tropeano, S.Guatelli 32 // 32 // 33 // 33 // 34 // **************************************** 34 // **************************************** 35 // * * 35 // * * 36 // * BrachyDetectorConstruction.cc * 36 // * BrachyDetectorConstruction.cc * 37 // * * 37 // * * 38 // **************************************** 38 // **************************************** 39 // 39 // 40 #include "BrachyFactoryLeipzig.hh" << 40 // $Id: BrachyDetectorConstruction.cc,v 1.29 2006/06/29 15:48:09 gunter Exp $ 41 #include "BrachyFactoryTG186.hh" << 41 // GEANT4 tag $Name: geant4-09-02-patch-04 $ 42 #include "BrachyFactoryI.hh" << 42 // 43 #include "BrachyFactoryFlexi.hh" << 44 #include "BrachyFactoryOncura6711.hh" << 45 #include "BrachyDetectorMessenger.hh" << 46 #include "BrachyDetectorConstruction.hh" << 47 #include "G4SystemOfUnits.hh" << 48 #include "G4CSGSolid.hh" 43 #include "G4CSGSolid.hh" 49 #include "G4MaterialPropertyVector.hh" 44 #include "G4MaterialPropertyVector.hh" 50 #include "G4SDManager.hh" 45 #include "G4SDManager.hh" 51 #include "G4RunManager.hh" 46 #include "G4RunManager.hh" 52 #include "G4Box.hh" 47 #include "G4Box.hh" 53 #include "G4LogicalVolume.hh" 48 #include "G4LogicalVolume.hh" 54 #include "G4ThreeVector.hh" 49 #include "G4ThreeVector.hh" 55 #include "G4PVPlacement.hh" 50 #include "G4PVPlacement.hh" 56 #include "globals.hh" 51 #include "globals.hh" 57 #include "G4MaterialTable.hh" 52 #include "G4MaterialTable.hh" 58 #include "G4TransportationManager.hh" 53 #include "G4TransportationManager.hh" 59 #include "G4Colour.hh" 54 #include "G4Colour.hh" 60 #include "G4UserLimits.hh" 55 #include "G4UserLimits.hh" 61 #include "G4VisAttributes.hh" 56 #include "G4VisAttributes.hh" 62 #include "G4NistManager.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" 63 65 64 BrachyDetectorConstruction::BrachyDetectorCons << 66 BrachyDetectorConstruction::BrachyDetectorConstruction(G4String &SDName) 65 fFactory(nullptr), fWorld(nullptr), fWorldLo << 67 : detectorChoice(0), phantomSD(0), phantomROGeometry(0), factory(0), 66 fPhantom(nullptr), fPhantomLog(nullptr), fPh << 68 World(0), WorldLog(0), WorldPhys(0), 67 fDetectorChoice(0) << 69 Phantom(0), PhantomLog(0), PhantomPhys(0), 68 { << 70 phantomAbsorberMaterial(0) 69 // Define the messenger of the Detector compo << 71 { 70 fDetectorMessenger = new BrachyDetectorMessen << 72 // Define half size of the phantom along the x, y, z axis 71 << 73 phantomSizeX = 15.*cm ; 72 // Define half size of the phantom along the << 74 phantomSizeY = 15.*cm; 73 fPhantomSizeX = 15.*cm; << 75 phantomSizeZ = 15.*cm; 74 fPhantomSizeY = 15.*cm; << 76 75 fPhantomSizeZ = 15.*cm; << 77 // Define the number of voxels the phantom is subdivided along the 76 << 78 // three axis 77 // Define the sizes of the World volume conta << 79 // Each voxel is 1 mm wide 78 fWorldSizeX = 4.0*m; << 80 numberOfVoxelsAlongX = 300; 79 fWorldSizeY = 4.0*m; << 81 numberOfVoxelsAlongY = 300; 80 fWorldSizeZ = 4.0*m; << 82 numberOfVoxelsAlongZ = 300; 81 83 82 // Define the Flexi source as default source << 84 ComputeDimVoxel(); 83 fFactory = new BrachyFactoryFlexi(); << 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(); 84 } 103 } 85 104 86 BrachyDetectorConstruction::~BrachyDetectorCon 105 BrachyDetectorConstruction::~BrachyDetectorConstruction() 87 { 106 { 88 delete fDetectorMessenger; << 107 delete pMaterial; 89 delete fFactory; << 108 delete factory; >> 109 delete detectorMessenger; >> 110 if (phantomROGeometry) delete phantomROGeometry; 90 } 111 } 91 112 92 G4VPhysicalVolume* BrachyDetectorConstruction: 113 G4VPhysicalVolume* BrachyDetectorConstruction::Construct() 93 { 114 { 94 // Model the phantom (water box) << 115 pMaterial -> DefineMaterials(); 95 ConstructPhantom(); << 116 >> 117 // Model the phantom (water box) >> 118 ConstructPhantom(); 96 119 97 // Model the source in the phantom << 120 // Model the source in the phantom 98 fFactory -> CreateSource(fPhantomPhys); << 121 factory -> CreateSource(PhantomPhys); //Build the source inside the phantom >> 122 >> 123 // Define the sensitive volume: phantom >> 124 ConstructSensitiveDetector(); 99 125 100 return fWorldPhys; << 126 return WorldPhys; 101 } 127 } 102 128 103 void BrachyDetectorConstruction::SwitchBrachyt 129 void BrachyDetectorConstruction::SwitchBrachytherapicSeed() 104 { 130 { 105 // Change the source in the water phantom 131 // Change the source in the water phantom 106 fFactory -> CleanSource(); << 132 factory -> CleanSource(); 107 G4cout << "Old brachy source is deleted ..." << 133 delete factory; 108 delete fFactory; << 109 134 110 switch(fDetectorChoice) << 135 switch(detectorChoice) 111 { 136 { 112 case 1: << 137 case 1: 113 fFactory = new BrachyFactoryI(); << 138 factory = new BrachyFactoryI(); 114 break; 139 break; 115 case 2: << 140 case 2: 116 fFactory = new BrachyFactoryLeipzig(); << 141 factory = new BrachyFactoryLeipzig(); 117 break; 142 break; 118 case 3: << 143 case 3: 119 fFactory = new BrachyFactoryTG186(); << 144 factory = new BrachyFactoryIr(); >> 145 break; >> 146 default: >> 147 factory = new BrachyFactoryIr(); 120 break; 148 break; 121 case 4: << 149 } 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 150 132 fFactory -> CreateSource(fPhantomPhys); << 151 factory -> CreateSource(PhantomPhys); 133 G4cout << "New brachy source is created ..." << 134 152 135 // Notify run manager that the new geometry 153 // Notify run manager that the new geometry has been built 136 G4RunManager::GetRunManager() -> GeometryHas << 154 G4RunManager::GetRunManager() -> DefineWorldVolume( WorldPhys ); 137 } 155 } 138 156 139 void BrachyDetectorConstruction::SelectBrachyt 157 void BrachyDetectorConstruction::SelectBrachytherapicSeed(G4String val) 140 { 158 { 141 if (val == "Iodine") << 159 if(val == "Iodium") 142 fDetectorChoice = 1; << 160 { 143 else << 161 detectorChoice = 1; 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 << va << 161 } << 162 } << 163 } << 164 } 162 } 165 G4cout << "Now the brachy source is " << val << 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; 166 } 179 } 167 180 168 void BrachyDetectorConstruction::ConstructPhan 181 void BrachyDetectorConstruction::ConstructPhantom() 169 { 182 { 170 // Model the water phantom 183 // Model the water phantom 171 << 184 172 // Define the light blue color 185 // Define the light blue color 173 G4Colour lblue (0.0, 0.0, .75); 186 G4Colour lblue (0.0, 0.0, .75); 174 << 187 175 //Get nist material manager << 188 G4Material* air = pMaterial -> GetMat("Air") ; 176 G4NistManager* nist = G4NistManager::Instanc << 189 G4Material* water = pMaterial -> GetMat("Water"); 177 G4Material* air = nist -> FindOrBuildMateria << 190 178 G4Material* water = nist -> FindOrBuildMater << 191 ComputeDimVoxel(); 179 192 180 // World volume 193 // World volume 181 fWorld = new G4Box("World", fWorldSizeX, fWo << 194 World = new G4Box("World",worldSizeX,worldSizeY,worldSizeZ); 182 fWorldLog = new G4LogicalVolume(fWorld,air," << 195 WorldLog = new G4LogicalVolume(World,air,"WorldLog",0,0,0); 183 fWorldPhys = new G4PVPlacement(nullptr,G4Thr << 196 WorldPhys = new G4PVPlacement(0,G4ThreeVector(), >> 197 "WorldPhys",WorldLog,0,false,0); 184 198 185 // Water Box 199 // Water Box 186 fPhantom = new G4Box("Phantom", fPhantomSize << 200 Phantom = new G4Box("Phantom",phantomSizeX,phantomSizeY, >> 201 phantomSizeZ); 187 202 188 // Logical volume 203 // Logical volume 189 fPhantomLog = new G4LogicalVolume(fPhantom,w << 204 PhantomLog = new G4LogicalVolume(Phantom,water,"PhantomLog",0,0,0); 190 205 191 // Physical volume 206 // Physical volume 192 fPhantomPhys = new G4PVPlacement(nullptr,G4T << 207 PhantomPhys = new G4PVPlacement(0,G4ThreeVector(), // Position: rotation and translation 193 "PhantomPhys 208 "PhantomPhys", // Name 194 fPhantomLog, << 209 PhantomLog, // Associated logical volume 195 fWorldPhys, << 210 WorldPhys, // Mother volume 196 false,0); << 211 false,0); 197 212 198 fWorldLog -> SetVisAttributes (G4VisAttribut << 213 WorldLog -> SetVisAttributes (G4VisAttributes::Invisible); 199 214 200 // Visualization attributes of the phantom 215 // Visualization attributes of the phantom 201 auto simpleBoxVisAtt = new G4VisAttributes(l << 216 G4VisAttributes* simpleBoxVisAtt = new G4VisAttributes(lblue); 202 simpleBoxVisAtt -> SetVisibility(true); 217 simpleBoxVisAtt -> SetVisibility(true); 203 simpleBoxVisAtt -> SetForceWireframe(true); 218 simpleBoxVisAtt -> SetForceWireframe(true); 204 fPhantomLog -> SetVisAttributes(simpleBoxVis << 219 PhantomLog -> SetVisAttributes(simpleBoxVisAtt); >> 220 } >> 221 >> 222 void 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 } 205 } 244 } 206 245 207 void BrachyDetectorConstruction::PrintDetector 246 void BrachyDetectorConstruction::PrintDetectorParameters() 208 { 247 { 209 G4cout << "----------------" << G4endl << 248 G4cout << "-----------------------------------------------------------------------" >> 249 << G4endl 210 << "the phantom is a water box whose 250 << "the phantom is a water box whose size is: " << G4endl 211 << fPhantomSizeX *2./cm << 251 << phantomSizeX *2./cm 212 << " cm * " 252 << " cm * " 213 << fPhantomSizeY *2./cm << 253 << phantomSizeY *2./cm 214 << " cm * " 254 << " cm * " 215 << fPhantomSizeZ *2./cm << 255 << phantomSizeZ *2./cm 216 << " cm" << G4endl 256 << " cm" << G4endl >> 257 << "number of Voxel: " >> 258 << numberOfVoxelsAlongX <<G4endl >> 259 << "Voxel size: " >> 260 << dimVoxel * 2/mm >> 261 << "mm" << G4endl 217 << "The phantom is made of " 262 << "The phantom is made of " 218 << fPhantomLog -> GetMaterial() -> Ge << 263 << phantomAbsorberMaterial -> GetName() <<G4endl 219 << "the source is at the center of th 264 << "the source is at the center of the phantom" << G4endl 220 << "----------------" << 265 << "-------------------------------------------------------------------------" 221 << G4endl; 266 << G4endl; 222 } 267 } 223 268 224 void BrachyDetectorConstruction::SetPhantomMat 269 void BrachyDetectorConstruction::SetPhantomMaterial(G4String materialChoice) 225 { 270 { 226 // Method to change the material of the phan << 271 // It is possible to change the material of the phantom 227 << 272 // interactively 228 G4NistManager* nist = G4NistManager::Instanc << 229 << 230 // Search the material by its name << 231 G4Material* pttoMaterial = nist -> FindOrBu << 232 273 >> 274 // Search the material by its name >> 275 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice); 233 if (pttoMaterial) 276 if (pttoMaterial) 234 { 277 { 235 fPhantomLog -> SetMaterial(pttoMaterial); << 278 phantomAbsorberMaterial = pttoMaterial; >> 279 PhantomLog -> SetMaterial(pttoMaterial); 236 PrintDetectorParameters(); 280 PrintDetectorParameters(); 237 } else G4cout << "WARNING: material '" << m << 281 } >> 282 else >> 283 G4cout << "WARNING: material '" << materialChoice >> 284 << "' not available!" << G4endl; 238 } 285 } 239 286