Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 /// \file medical/electronScattering/src/Detec 27 /// \brief Implementation of the DetectorConst 28 // 29 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 31 //....oooOO0OOooo........oooOO0OOooo........oo 32 33 #include "DetectorConstruction.hh" 34 35 #include "DetectorMessenger.hh" 36 37 #include "G4GeometryManager.hh" 38 #include "G4LogicalVolume.hh" 39 #include "G4LogicalVolumeStore.hh" 40 #include "G4Material.hh" 41 #include "G4PVPlacement.hh" 42 #include "G4PhysicalConstants.hh" 43 #include "G4PhysicalVolumeStore.hh" 44 #include "G4SolidStore.hh" 45 #include "G4SystemOfUnits.hh" 46 #include "G4Tubs.hh" 47 #include "G4UnitsTable.hh" 48 49 //....oooOO0OOooo........oooOO0OOooo........oo 50 51 DetectorConstruction::DetectorConstruction() 52 : fMaterial_World(0), 53 fMaterial_Frame(0), 54 fMaterial_ExitWindow(0), 55 fMaterial_ScatterFoil(0), 56 fMaterial_MonitorChbr(0), 57 fMaterial_Bag(0), 58 fMaterial_Gas(0), 59 fMaterial_Ring(0), 60 fPvol_World(0), 61 fPvol_Frame(0), 62 fDetectorMessenger(0) 63 { 64 // materials 65 DefineMaterials(); 66 67 // geometry 68 GeometryParameters(); 69 70 // create commands for interactive definitio 71 fDetectorMessenger = new DetectorMessenger(t 72 } 73 74 //....oooOO0OOooo........oooOO0OOooo........oo 75 76 DetectorConstruction::~DetectorConstruction() 77 { 78 delete fDetectorMessenger; 79 } 80 81 //....oooOO0OOooo........oooOO0OOooo........oo 82 83 G4VPhysicalVolume* DetectorConstruction::Const 84 { 85 return ConstructVolumes(); 86 } 87 88 //....oooOO0OOooo........oooOO0OOooo........oo 89 90 void DetectorConstruction::DefineMaterials() 91 { 92 G4double a, z, density; 93 G4int ncomponents, natoms; 94 G4double fractionmass; 95 G4double temperature, pressure; 96 97 // define Elements 98 // 99 G4Element* H = new G4Element("Hydrogen", "H" 100 G4Element* He = new G4Element("Helium", "He" 101 G4Element* Be = new G4Element("Beryllium", " 102 G4Element* C = new G4Element("Carbon", "C", 103 G4Element* N = new G4Element("Nitrogen", "N" 104 G4Element* O = new G4Element("Oxygen", "O", 105 G4Element* Al = new G4Element("Aluminium", " 106 G4Element* Ar = new G4Element("Argon", "Ar", 107 G4Element* Ti = new G4Element("Titanium", "T 108 G4Element* Va = new G4Element("Vanadium", "V 109 G4Element* Cu = new G4Element("Copper", "Cu" 110 G4Element* Ta = new G4Element("Tantalum", "T 111 G4Element* Au = new G4Element("Gold", "Au", 112 113 // Air 114 // 115 G4Material* Air = new G4Material("Air", dens 116 293. * kelv 117 Air->AddElement(C, fractionmass = 0.000124); 118 Air->AddElement(N, fractionmass = 0.755267); 119 Air->AddElement(O, fractionmass = 0.231782); 120 Air->AddElement(Ar, fractionmass = 0.012827) 121 122 // Titanium 123 // 124 G4Material* Titanium = new G4Material("Titan 125 Titanium->AddElement(Ti, fractionmass = 0.90 126 Titanium->AddElement(Al, fractionmass = 0.06 127 Titanium->AddElement(Va, fractionmass = 0.04 128 129 // Mylar 130 // 131 G4Material* Mylar = new G4Material("Mylar", 132 Mylar->AddElement(H, natoms = 4); 133 Mylar->AddElement(C, natoms = 5); 134 Mylar->AddElement(O, natoms = 2); 135 136 // Helium 137 // 138 G4Material* Helium = new G4Material("Helium" 139 kStateGa 140 Helium->AddElement(He, fractionmass = 1.0); 141 142 // Aluminium 143 // 144 G4Material* Aluminium = new G4Material("Alum 145 Aluminium->AddElement(Al, fractionmass = 1.0 146 147 // Beryllium 148 // 149 G4Material* Beryllium = new G4Material("Bery 150 Beryllium->AddElement(Be, fractionmass = 1.0 151 152 // Graphite 153 // 154 G4Material* Graphite = new G4Material("Graph 155 Graphite->AddElement(C, fractionmass = 1.0); 156 157 // Copper 158 // 159 G4Material* Copper = new G4Material("Copper" 160 Copper->AddElement(Cu, fractionmass = 1.0); 161 162 // Tantalum 163 // 164 G4Material* Tantalum = new G4Material("Tanta 165 Tantalum->AddElement(Ta, fractionmass = 1.0) 166 167 // Gold 168 // 169 G4Material* Gold = new G4Material("Gold", de 170 Gold->AddElement(Au, fractionmass = 1.0); 171 172 // example of vacuum 173 // 174 density = universe_mean_density; // from Ph 175 pressure = 3.e-18 * pascal; 176 temperature = 2.73 * kelvin; 177 G4Material* Vacuum = new G4Material("Galacti 178 temperat 179 180 // print 181 // 182 G4cout << *(G4Material::GetMaterialTable()) 183 184 // assign materials 185 // 186 fMaterial_World = Vacuum; 187 fMaterial_Frame = Air; 188 fMaterial_ExitWindow = Titanium; 189 fMaterial_ScatterFoil = fMaterial_Frame; 190 fMaterial_MonitorChbr = Mylar; 191 fMaterial_Bag = Mylar; 192 fMaterial_Gas = Helium; 193 fMaterial_Ring = Aluminium; 194 } 195 196 //....oooOO0OOooo........oooOO0OOooo........oo 197 198 void DetectorConstruction::GeometryParameters( 199 { 200 fZfront_ExitWindow = 0.0 * um; 201 fThickness_ExitWindow = 41.2 * um; 202 203 fZfront_ScatterFoil = 2.65 * cm; 204 fThickness_ScatterFoil = 0.0 * um; 205 206 fZfront_MonitorChbr = 50. * mm; 207 fThickness_MonitorChbr = 112.7 * um; 208 209 fZfront_Bag = 64.975 * mm; 210 fThickness_Bag = 110.0050 * cm; 211 212 fThickness_Gas = 110. * cm; 213 214 fThickness_Ring = 14. * mm; 215 fInnerRadius_Ring = 20. * cm; 216 217 fZfront_Frame = 2.0 * um; 218 fThickness_Frame = 118.2 * cm; 219 220 fThickness_World = fZfront_Frame + fThicknes 221 fRadius_World = 23.3 * cm; 222 } 223 224 //....oooOO0OOooo........oooOO0OOooo........oo 225 226 G4VPhysicalVolume* DetectorConstruction::Const 227 { 228 // Cleanup old geometry 229 // 230 G4GeometryManager::GetInstance()->OpenGeomet 231 G4PhysicalVolumeStore::GetInstance()->Clean( 232 G4LogicalVolumeStore::GetInstance()->Clean() 233 G4SolidStore::GetInstance()->Clean(); 234 235 // World 236 // 237 G4Tubs* svol_World = new G4Tubs("World", // 238 0 * cm, fRad 239 0.5 * fThick 240 0., twopi); 241 242 G4LogicalVolume* lvol_World = new G4LogicalV 243 244 245 246 fPvol_World = new G4PVPlacement(0, // no ro 247 G4ThreeVecto 248 lvol_World, 249 "World", // 250 0, // its m 251 false, // n 252 0); // copy 253 254 // Frame 255 // 256 G4Tubs* svol_Frame = new G4Tubs("Frame", // 257 0 * cm, fRad 258 0.5 * fThick 259 0., twopi); 260 261 G4LogicalVolume* lvol_Frame = new G4LogicalV 262 263 264 265 G4double zpos = fZfront_Frame; 266 267 fPvol_Frame = new G4PVPlacement(0, // no ro 268 G4ThreeVecto 269 lvol_Frame, 270 "Frame", // 271 lvol_World, 272 false, // n 273 0); // copy 274 275 // ExitWindow 276 // 277 G4Tubs* svol_ExitWindow = new G4Tubs("ExitWi 278 0 * cm, 279 0.5 * f 280 0., two 281 282 G4LogicalVolume* lvol_ExitWindow = new G4Log 283 284 285 286 zpos = fZfront_ExitWindow + 0.5 * fThickness 287 288 new G4PVPlacement(0, // no rotation 289 G4ThreeVector(0, 0, zpos), 290 lvol_ExitWindow, // logic 291 "ExitWindow", // name 292 lvol_Frame, // mother vol 293 false, // no boolean oper 294 0); // copy number 295 296 // Monitor Chamber 297 // 298 G4Tubs* svol_MonitorChbr = new G4Tubs("Monit 299 0 * cm 300 0.5 * 301 0., tw 302 303 G4LogicalVolume* lvol_MonitorChbr = new G4Lo 304 305 306 307 zpos = fZfront_MonitorChbr + 0.5 * fThicknes 308 309 new G4PVPlacement(0, // no rotation 310 G4ThreeVector(0, 0, zpos), 311 lvol_MonitorChbr, // logi 312 "MonitorChbr", // name 313 lvol_Frame, // mother vol 314 false, // no boolean oper 315 0); // copy number 316 317 // Bag 318 // 319 G4Tubs* svol_Bag = new G4Tubs("Bag", // nam 320 0 * cm, fRadiu 321 0.5 * fThickne 322 0., twopi); / 323 324 G4LogicalVolume* lvol_Bag = new G4LogicalVol 325 326 327 328 zpos = fZfront_Bag + 0.5 * fThickness_Bag - 329 330 new G4PVPlacement(0, // no rotation 331 G4ThreeVector(0, 0, zpos), 332 lvol_Bag, // logical volu 333 "Bag", // name 334 lvol_Frame, // mother vol 335 false, // no boolean oper 336 0); // copy number 337 338 // Gas 339 // 340 G4Tubs* svol_Gas = new G4Tubs("Gas", // nam 341 0 * cm, fRadiu 342 0.5 * fThickne 343 0., twopi); / 344 345 G4LogicalVolume* lvol_Gas = new G4LogicalVol 346 347 348 349 new G4PVPlacement(0, // no rotation 350 G4ThreeVector(), // no tr 351 lvol_Gas, // logical volu 352 "Gas", // name 353 lvol_Bag, // mother volum 354 false, // no boolean oper 355 0); // copy number 356 357 // Rings 358 // 359 G4Tubs* svol_Ring = new G4Tubs("Ring", // n 360 fInnerRadius_ 361 0.5 * fThickn 362 0., twopi); 363 364 G4LogicalVolume* lvol_Ring = new G4LogicalVo 365 366 367 368 zpos = 0.5 * (fThickness_Gas - fThickness_Ri 369 370 new G4PVPlacement(0, // no rotation 371 G4ThreeVector(0, 0, zpos), 372 lvol_Ring, // logical vol 373 "Ring", // name 374 lvol_Gas, // mother volum 375 false, // no boolean oper 376 1); // copy number 377 378 new G4PVPlacement(0, // no rotation 379 G4ThreeVector(0, 0, -zpos) 380 lvol_Ring, // logical vol 381 "Ring", // name 382 lvol_Gas, // mother volum 383 false, // no boolean oper 384 2); // copy number 385 386 // ScatterFoil (only if it is not Air) 387 // 388 if ((fMaterial_ScatterFoil != fMaterial_Fram 389 G4Tubs* svol_ScatterFoil = new G4Tubs("Sca 390 0 * 391 0.5 392 0., 393 394 G4LogicalVolume* lvol_ScatterFoil = new G4 395 396 397 398 zpos = fZfront_ScatterFoil + 0.5 * fThickn 399 400 new G4PVPlacement(0, // no rotation 401 G4ThreeVector(0, 0, zpos 402 lvol_ScatterFoil, // lo 403 "ScatterFoil", // name 404 lvol_Frame, // mother v 405 false, // no boolean op 406 0); // copy number 407 } 408 409 PrintGeometry(); 410 411 // always return the physical World 412 // 413 return fPvol_World; 414 } 415 416 //....oooOO0OOooo........oooOO0OOooo........oo 417 418 void DetectorConstruction::PrintGeometry() 419 { 420 // choose printing format 421 std::ios::fmtflags mode = G4cout.flags(); 422 G4cout.setf(std::ios::fixed, std::ios::float 423 G4int prec = G4cout.precision(6); 424 425 G4cout << "\n \t \t" 426 << "Material \t" 427 << "Z_front \t" 428 << "Thickness \n"; 429 430 G4cout << "\n ExitWindow \t" << fMaterial_E 431 << G4BestUnit(fZfront_ExitWindow, "Le 432 << G4BestUnit(fThickness_ExitWindow, 433 434 if (fMaterial_ScatterFoil != fMaterial_Frame 435 G4cout << "\n ScatterFoil \t" << fMateria 436 << "\t" << G4BestUnit(fZfront_Scatt 437 << G4BestUnit(fThickness_ScatterFoi 438 } 439 440 G4cout << "\n MonitorChbr \t" << fMaterial_ 441 << "\t" << G4BestUnit(fZfront_Monitor 442 << G4BestUnit(fThickness_MonitorChbr, 443 444 G4double thickBagWindow = 0.5 * (fThickness_ 445 G4double zfrontGas = fZfront_Bag + thickBagW 446 G4double zfrontBagWindow2 = zfrontGas + fThi 447 448 G4cout << "\n BagWindow1 \t" << fMaterial_B 449 << "\t" << G4BestUnit(fZfront_Bag, "L 450 << G4BestUnit(thickBagWindow, "Length 451 452 G4cout << "\n Gas \t" << fMaterial_Ga 453 << "\t" << G4BestUnit(zfrontGas, "Len 454 455 G4cout << "\n BagWindow2 \t" << fMaterial_B 456 << "\t" << G4BestUnit(zfrontBagWindow 457 << G4BestUnit(thickBagWindow, "Length 458 459 G4cout << "\n ScoringPlane \t" << fMaterial 460 << "\t" << G4BestUnit(fThickness_Fram 461 << G4endl; 462 463 // restaure default formats 464 G4cout.setf(mode, std::ios::floatfield); 465 G4cout.precision(prec); 466 } 467 468 //....oooOO0OOooo........oooOO0OOooo........oo 469 470 void DetectorConstruction::SetMaterialScatter( 471 { 472 // search the material by its name 473 G4Material* pMaterial = G4Material::GetMater 474 475 if (pMaterial) fMaterial_ScatterFoil = pMate 476 } 477 478 //....oooOO0OOooo........oooOO0OOooo........oo 479 480 void DetectorConstruction::SetThicknessScatter 481 { 482 fThickness_ScatterFoil = val; 483 } 484 485 //....oooOO0OOooo........oooOO0OOooo........oo 486 487 #include "G4RunManager.hh" 488 489 void DetectorConstruction::UpdateGeometry() 490 { 491 G4RunManager::GetRunManager()->DefineWorldVo 492 } 493 494 //....oooOO0OOooo........oooOO0OOooo........oo 495