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