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 /// \file medical/electronScattering/src/DetectorConstruction.cc 27 /// \brief Implementation of the DetectorConstruction class 28 // 29 // 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 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........oooOO0OOooo........oooOO0OOooo...... 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 definition of the calorimeter 71 fDetectorMessenger = new DetectorMessenger(this); 72 } 73 74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 75 76 DetectorConstruction::~DetectorConstruction() 77 { 78 delete fDetectorMessenger; 79 } 80 81 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 82 83 G4VPhysicalVolume* DetectorConstruction::Construct() 84 { 85 return ConstructVolumes(); 86 } 87 88 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 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", z = 1, a = 1.0079 * g / mole); 100 G4Element* He = new G4Element("Helium", "He", z = 2, a = 4.0026 * g / mole); 101 G4Element* Be = new G4Element("Beryllium", "Be", z = 4, a = 9.1218 * g / mole); 102 G4Element* C = new G4Element("Carbon", "C", z = 6, a = 12.0107 * g / mole); 103 G4Element* N = new G4Element("Nitrogen", "N", z = 7, a = 14.0067 * g / mole); 104 G4Element* O = new G4Element("Oxygen", "O", z = 8, a = 15.9994 * g / mole); 105 G4Element* Al = new G4Element("Aluminium", "Al", z = 13, a = 26.9815 * g / mole); 106 G4Element* Ar = new G4Element("Argon", "Ar", z = 18, a = 39.9480 * g / mole); 107 G4Element* Ti = new G4Element("Titanium", "Ti", z = 22, a = 47.8670 * g / mole); 108 G4Element* Va = new G4Element("Vanadium", "Va", z = 23, a = 50.9415 * g / mole); 109 G4Element* Cu = new G4Element("Copper", "Cu", z = 29, a = 63.5460 * g / mole); 110 G4Element* Ta = new G4Element("Tantalum", "Ta", z = 73, a = 180.9479 * g / mole); 111 G4Element* Au = new G4Element("Gold", "Au", z = 79, a = 196.9666 * g / mole); 112 113 // Air 114 // 115 G4Material* Air = new G4Material("Air", density = 1.205 * mg / cm3, ncomponents = 4, kStateGas, 116 293. * kelvin, 1. * atmosphere); 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("Titanium", density = 4.42 * g / cm3, ncomponents = 3); 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", density = 1.40 * g / cm3, ncomponents = 3); 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", density = 0.166 * mg / cm3, ncomponents = 1, 139 kStateGas, 293. * kelvin, 1. * atmosphere); 140 Helium->AddElement(He, fractionmass = 1.0); 141 142 // Aluminium 143 // 144 G4Material* Aluminium = new G4Material("Aluminium", density = 2.7 * g / cm3, ncomponents = 1); 145 Aluminium->AddElement(Al, fractionmass = 1.0); 146 147 // Beryllium 148 // 149 G4Material* Beryllium = new G4Material("Beryllium", density = 1.85 * g / cm3, ncomponents = 1); 150 Beryllium->AddElement(Be, fractionmass = 1.0); 151 152 // Graphite 153 // 154 G4Material* Graphite = new G4Material("Graphite", density = 2.18 * g / cm3, ncomponents = 1); 155 Graphite->AddElement(C, fractionmass = 1.0); 156 157 // Copper 158 // 159 G4Material* Copper = new G4Material("Copper", density = 8.92 * g / cm3, ncomponents = 1); 160 Copper->AddElement(Cu, fractionmass = 1.0); 161 162 // Tantalum 163 // 164 G4Material* Tantalum = new G4Material("Tantalum", density = 16.65 * g / cm3, ncomponents = 1); 165 Tantalum->AddElement(Ta, fractionmass = 1.0); 166 167 // Gold 168 // 169 G4Material* Gold = new G4Material("Gold", density = 19.30 * g / cm3, ncomponents = 1); 170 Gold->AddElement(Au, fractionmass = 1.0); 171 172 // example of vacuum 173 // 174 density = universe_mean_density; // from PhysicalConstants.h 175 pressure = 3.e-18 * pascal; 176 temperature = 2.73 * kelvin; 177 G4Material* Vacuum = new G4Material("Galactic", z = 1, a = 1.01 * g / mole, density, kStateGas, 178 temperature, pressure); 179 180 // print 181 // 182 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 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........oooOO0OOooo........oooOO0OOooo...... 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 + fThickness_Frame; 221 fRadius_World = 23.3 * cm; 222 } 223 224 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 225 226 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() 227 { 228 // Cleanup old geometry 229 // 230 G4GeometryManager::GetInstance()->OpenGeometry(); 231 G4PhysicalVolumeStore::GetInstance()->Clean(); 232 G4LogicalVolumeStore::GetInstance()->Clean(); 233 G4SolidStore::GetInstance()->Clean(); 234 235 // World 236 // 237 G4Tubs* svol_World = new G4Tubs("World", // name 238 0 * cm, fRadius_World, // r1, r2 239 0.5 * fThickness_World, // half-length 240 0., twopi); // theta1, theta2 241 242 G4LogicalVolume* lvol_World = new G4LogicalVolume(svol_World, // its solid 243 fMaterial_World, // its material 244 "World"); // its name 245 246 fPvol_World = new G4PVPlacement(0, // no rotation 247 G4ThreeVector(), // no translation 248 lvol_World, // its logical volume 249 "World", // its name 250 0, // its mother volume 251 false, // no boolean operation 252 0); // copy number 253 254 // Frame 255 // 256 G4Tubs* svol_Frame = new G4Tubs("Frame", // name 257 0 * cm, fRadius_World, // r1, r2 258 0.5 * fThickness_Frame, // half-length 259 0., twopi); // theta1, theta2 260 261 G4LogicalVolume* lvol_Frame = new G4LogicalVolume(svol_Frame, // its solid 262 fMaterial_Frame, // its material 263 "Frame"); // its name 264 265 G4double zpos = fZfront_Frame; 266 267 fPvol_Frame = new G4PVPlacement(0, // no rotation 268 G4ThreeVector(0, 0, zpos), // translation 269 lvol_Frame, // its logical volume 270 "Frame", // its name 271 lvol_World, // its mother volume 272 false, // no boolean operation 273 0); // copy number 274 275 // ExitWindow 276 // 277 G4Tubs* svol_ExitWindow = new G4Tubs("ExitWindow", // name 278 0 * cm, fRadius_World, // r1, r2 279 0.5 * fThickness_ExitWindow, // half-length 280 0., twopi); // theta1, theta2 281 282 G4LogicalVolume* lvol_ExitWindow = new G4LogicalVolume(svol_ExitWindow, // solid 283 fMaterial_ExitWindow, // material 284 "ExitWindow"); // name 285 286 zpos = fZfront_ExitWindow + 0.5 * fThickness_ExitWindow - 0.5 * fThickness_Frame; 287 288 new G4PVPlacement(0, // no rotation 289 G4ThreeVector(0, 0, zpos), // translation 290 lvol_ExitWindow, // logical volume 291 "ExitWindow", // name 292 lvol_Frame, // mother volume 293 false, // no boolean operation 294 0); // copy number 295 296 // Monitor Chamber 297 // 298 G4Tubs* svol_MonitorChbr = new G4Tubs("MonitorChbr", // name 299 0 * cm, fRadius_World, // r1, r2 300 0.5 * fThickness_MonitorChbr, // half-length 301 0., twopi); // theta1, theta2 302 303 G4LogicalVolume* lvol_MonitorChbr = new G4LogicalVolume(svol_MonitorChbr, // solid 304 fMaterial_MonitorChbr, // material 305 "MonitorChbr"); // name 306 307 zpos = fZfront_MonitorChbr + 0.5 * fThickness_MonitorChbr - 0.5 * fThickness_Frame; 308 309 new G4PVPlacement(0, // no rotation 310 G4ThreeVector(0, 0, zpos), // translation 311 lvol_MonitorChbr, // logical volume 312 "MonitorChbr", // name 313 lvol_Frame, // mother volume 314 false, // no boolean operation 315 0); // copy number 316 317 // Bag 318 // 319 G4Tubs* svol_Bag = new G4Tubs("Bag", // name 320 0 * cm, fRadius_World, // r1, r2 321 0.5 * fThickness_Bag, // half-length 322 0., twopi); // theta1, theta2 323 324 G4LogicalVolume* lvol_Bag = new G4LogicalVolume(svol_Bag, // solid 325 fMaterial_Bag, // material 326 "Bag"); // name 327 328 zpos = fZfront_Bag + 0.5 * fThickness_Bag - 0.5 * fThickness_Frame; 329 330 new G4PVPlacement(0, // no rotation 331 G4ThreeVector(0, 0, zpos), // translation 332 lvol_Bag, // logical volume 333 "Bag", // name 334 lvol_Frame, // mother volume 335 false, // no boolean operation 336 0); // copy number 337 338 // Gas 339 // 340 G4Tubs* svol_Gas = new G4Tubs("Gas", // name 341 0 * cm, fRadius_World, // r1, r2 342 0.5 * fThickness_Gas, // half-length 343 0., twopi); // theta1, theta2 344 345 G4LogicalVolume* lvol_Gas = new G4LogicalVolume(svol_Gas, // solid 346 fMaterial_Gas, // material 347 "Gas"); // name 348 349 new G4PVPlacement(0, // no rotation 350 G4ThreeVector(), // no translation 351 lvol_Gas, // logical volume 352 "Gas", // name 353 lvol_Bag, // mother volume 354 false, // no boolean operation 355 0); // copy number 356 357 // Rings 358 // 359 G4Tubs* svol_Ring = new G4Tubs("Ring", // name 360 fInnerRadius_Ring, fRadius_World, // r1, r2 361 0.5 * fThickness_Ring, // half-length 362 0., twopi); // theta1, theta2 363 364 G4LogicalVolume* lvol_Ring = new G4LogicalVolume(svol_Ring, // solid 365 fMaterial_Ring, // material 366 "Ring"); // name 367 368 zpos = 0.5 * (fThickness_Gas - fThickness_Ring); 369 370 new G4PVPlacement(0, // no rotation 371 G4ThreeVector(0, 0, zpos), // translation 372 lvol_Ring, // logical volume 373 "Ring", // name 374 lvol_Gas, // mother volume 375 false, // no boolean operation 376 1); // copy number 377 378 new G4PVPlacement(0, // no rotation 379 G4ThreeVector(0, 0, -zpos), // translation 380 lvol_Ring, // logical volume 381 "Ring", // name 382 lvol_Gas, // mother volume 383 false, // no boolean operation 384 2); // copy number 385 386 // ScatterFoil (only if it is not Air) 387 // 388 if ((fMaterial_ScatterFoil != fMaterial_Frame) && (fThickness_ScatterFoil > 0.)) { 389 G4Tubs* svol_ScatterFoil = new G4Tubs("ScatterFoil", // name 390 0 * cm, fRadius_World, // r1, r2 391 0.5 * fThickness_ScatterFoil, // half-length 392 0., twopi); // theta1, theta2 393 394 G4LogicalVolume* lvol_ScatterFoil = new G4LogicalVolume(svol_ScatterFoil, // solid 395 fMaterial_ScatterFoil, // material 396 "ScatterFoil"); // name 397 398 zpos = fZfront_ScatterFoil + 0.5 * fThickness_ScatterFoil - 0.5 * fThickness_Frame; 399 400 new G4PVPlacement(0, // no rotation 401 G4ThreeVector(0, 0, zpos), // translation 402 lvol_ScatterFoil, // logical volume 403 "ScatterFoil", // name 404 lvol_Frame, // mother volume 405 false, // no boolean operation 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........oooOO0OOooo........oooOO0OOooo...... 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::floatfield); 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_ExitWindow->GetName() << "\t" 431 << G4BestUnit(fZfront_ExitWindow, "Length") << "\t" 432 << G4BestUnit(fThickness_ExitWindow, "Length"); 433 434 if (fMaterial_ScatterFoil != fMaterial_Frame) { 435 G4cout << "\n ScatterFoil \t" << fMaterial_ScatterFoil->GetName() << "\t" 436 << "\t" << G4BestUnit(fZfront_ScatterFoil, "Length") << "\t" 437 << G4BestUnit(fThickness_ScatterFoil, "Length"); 438 } 439 440 G4cout << "\n MonitorChbr \t" << fMaterial_MonitorChbr->GetName() << "\t" 441 << "\t" << G4BestUnit(fZfront_MonitorChbr, "Length") << "\t" 442 << G4BestUnit(fThickness_MonitorChbr, "Length"); 443 444 G4double thickBagWindow = 0.5 * (fThickness_Bag - fThickness_Gas); 445 G4double zfrontGas = fZfront_Bag + thickBagWindow; 446 G4double zfrontBagWindow2 = zfrontGas + fThickness_Gas; 447 448 G4cout << "\n BagWindow1 \t" << fMaterial_Bag->GetName() << "\t" 449 << "\t" << G4BestUnit(fZfront_Bag, "Length") << "\t" 450 << G4BestUnit(thickBagWindow, "Length"); 451 452 G4cout << "\n Gas \t" << fMaterial_Gas->GetName() << "\t" 453 << "\t" << G4BestUnit(zfrontGas, "Length") << "\t" << G4BestUnit(fThickness_Gas, "Length"); 454 455 G4cout << "\n BagWindow2 \t" << fMaterial_Bag->GetName() << "\t" 456 << "\t" << G4BestUnit(zfrontBagWindow2, "Length") << "\t" 457 << G4BestUnit(thickBagWindow, "Length"); 458 459 G4cout << "\n ScoringPlane \t" << fMaterial_Frame->GetName() << "\t" 460 << "\t" << G4BestUnit(fThickness_Frame, "Length") << "\n" 461 << G4endl; 462 463 // restaure default formats 464 G4cout.setf(mode, std::ios::floatfield); 465 G4cout.precision(prec); 466 } 467 468 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 469 470 void DetectorConstruction::SetMaterialScatter(G4String material) 471 { 472 // search the material by its name 473 G4Material* pMaterial = G4Material::GetMaterial(material); 474 475 if (pMaterial) fMaterial_ScatterFoil = pMaterial; 476 } 477 478 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 479 480 void DetectorConstruction::SetThicknessScatter(G4double val) 481 { 482 fThickness_ScatterFoil = val; 483 } 484 485 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 486 487 #include "G4RunManager.hh" 488 489 void DetectorConstruction::UpdateGeometry() 490 { 491 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes()); 492 } 493 494 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 495