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 // g 26 /// \file persistency/gdml/G02/src/G02Detector 27 /// \brief Implementation of the G02DetectorCo 28 // 29 // 30 // 31 // Class G02DetectorConstruction implementatio 32 // 33 // ------------------------------------------- 34 35 #include "G02DetectorConstruction.hh" 36 37 // Geant4 includes 38 // 39 #include "G4GeometryManager.hh" 40 #include "G4VisAttributes.hh" 41 #include "globals.hh" 42 43 // Materials 44 // 45 #include "G4Material.hh" 46 47 // Geometry includes 48 // 49 #include "G4Box.hh" 50 #include "G4LogicalVolume.hh" 51 #include "G4PVParameterised.hh" 52 #include "G4PVPlacement.hh" 53 #include "G4Tubs.hh" 54 #include "G4VPhysicalVolume.hh" 55 56 // Reflected solids 57 // 58 #include "G4AffineTransform.hh" 59 #include "G4DisplacedSolid.hh" 60 #include "G4ReflectedSolid.hh" 61 #include "G4ReflectionFactory.hh" 62 #include "G4RotationMatrix.hh" 63 #include "G4Transform3D.hh" 64 65 // Assembly volumes 66 // 67 #include "G4AssemblyVolume.hh" 68 69 // Volume parameterisations 70 // 71 #include "G02ChamberParameterisation.hh" 72 73 // Messenger 74 // 75 #include "G02DetectorMessenger.hh" 76 77 // GDML parser include 78 // 79 #include "G4GDMLParser.hh" 80 #include "G4PhysicalConstants.hh" 81 #include "G4SystemOfUnits.hh" 82 83 //....oooOO0OOooo........oooOO0OOooo........oo 84 // 85 // Constructor 86 // 87 G02DetectorConstruction::G02DetectorConstructi 88 : G4VUserDetectorConstruction(), fAir(0), fA 89 { 90 fExpHall_x = 5. * m; 91 92 fReadFile = "test.gdml"; 93 fWriteFile = "wtest.gdml"; 94 fStepFile = "mbb"; 95 fWritingChoice = 1; 96 97 fDetectorMessenger = new G02DetectorMessenge 98 } 99 100 //....oooOO0OOooo........oooOO0OOooo........oo 101 // 102 // Destructor 103 // 104 G02DetectorConstruction::~G02DetectorConstruct 105 { 106 if (fDetectorMessenger) delete fDetectorMess 107 } 108 109 //....oooOO0OOooo........oooOO0OOooo........oo 110 // 111 // Constructs geometries and materials 112 // 113 G4VPhysicalVolume* G02DetectorConstruction::Co 114 { 115 // Writing or Reading of Geometry using G4GD 116 117 G4VPhysicalVolume* fWorldPhysVol; 118 119 if (fWritingChoice == 0) { 120 // **** LOOK HERE*** FOR READING GDML FILE 121 // 122 123 // ACTIVATING OVERLAP CHECK when read volu 124 // Can take long time in case of complex g 125 // 126 // fParser.SetOverlapCheck(true); 127 128 fParser.Read(fReadFile); 129 130 // READING GDML FILES OPTION: 2nd Boolean 131 // Flag to "false" disables check with the 132 // See the GDML Documentation for more inf 133 // 134 // fParser.Read(fReadFile,false); 135 136 // Prints the material information 137 // 138 G4cout << *(G4Material::GetMaterialTable() 139 140 // Giving World Physical Volume from GDML 141 // 142 fWorldPhysVol = fParser.GetWorldVolume(); 143 } 144 else if (fWritingChoice == 1) { 145 // **** LOOK HERE*** FOR WRITING GDML FILE 146 // Detector Construction and WRITING to GD 147 // 148 ListOfMaterials(); 149 fWorldPhysVol = ConstructDetector(); 150 151 // OPTION: TO ADD MODULE AT DEPTH LEVEL .. 152 // 153 // Can be a integer or a pointer to the to 154 // 155 // G4int depth=1; 156 // fParser.AddModule(depth); 157 158 // OPTION: SETTING ADDITION OF POINTER TO 159 // 160 // By default, written names in GDML consi 161 // appended the pointer reference to it, i 162 // Naming policy can be changed by using t 163 // calling Write with additional Boolean a 164 // NOTE: you have to be sure not to have d 165 // Geometry Setup. 166 // 167 // fParser.SetAddPointerToName(false); 168 // 169 // or 170 // 171 // fParser.Write(fWriteFile, fWorldPhysVol 172 173 // OPTION: SET MAXIMUM LEVEL TO EXPORT (RE 174 // 175 // Can be a integer greater than zero: 176 // 177 // G4int maxlevel=3; 178 // fParser.SetMaxExportLevel(maxlevel); 179 180 // Writing Geometry to GDML File 181 // 182 fParser.Write(fWriteFile, fWorldPhysVol); 183 184 // OPTION: SPECIFYING THE SCHEMA LOCATION 185 // 186 // When writing GDML file the default the 187 // GDML web site will be used: 188 // "http://cern.ch/service-spi/app/release 189 // 190 // NOTE: GDML Schema is distributed in Gea 191 // $G4INSTALL/source/persistency/gdml/s 192 // 193 // You can change the Schema path by addin 194 // command, as follows: 195 // 196 // fParser.Write(fWriteFile, fWorldPhysVol 197 } 198 else // Demonstration how to Read STEP file 199 { 200 // Some printout... 201 // 202 ListOfMaterials(); 203 204 // Arbitrary values that should enclose an 205 // 206 const G4double expHall_y = fExpHall_x / 50 207 const G4double expHall_z = fExpHall_x / 50 208 209 // Create the hall 210 // 211 G4Box* experimentalHallBox = new G4Box("Ex 212 G4LogicalVolume* experimentalHallLV = 213 new G4LogicalVolume(experimentalHallBox, 214 fWorldPhysVol = new G4PVPlacement(0, G4Thr 215 "ExpHall 216 217 // G02DetectorConstruction via reading STE 218 // 219 G4LogicalVolume* LogicalVolST = fParser.Pa 220 221 // Placement inside of the hall 222 // 223 new G4PVPlacement(0, G4ThreeVector(10.0, 0 224 experimentalHallLV, fals 225 } 226 227 // Set Visualization attributes to world 228 // 229 G4VisAttributes* BoxVisAtt = new G4VisAttrib 230 fWorldPhysVol->GetLogicalVolume()->SetVisAtt 231 232 return fWorldPhysVol; 233 } 234 235 //....oooOO0OOooo........oooOO0OOooo........oo 236 // 237 // Utility to build and list necessary materia 238 // 239 void G02DetectorConstruction::ListOfMaterials( 240 { 241 G4double a; // atomic mass 242 G4double z; // atomic number 243 G4double density, temperature, pressure; 244 G4double fractionmass; 245 G4String name, symbol; 246 G4int ncomponents; 247 248 // Elements needed for the materials 249 250 a = 14.01 * g / mole; 251 G4Element* elN = new G4Element(name = "Nitro 252 253 a = 16.00 * g / mole; 254 G4Element* elO = new G4Element(name = "Oxyge 255 256 a = 26.98 * g / mole; 257 G4Element* elAl = new G4Element(name = "Alum 258 259 // Print the Element information 260 // 261 G4cout << *(G4Element::GetElementTable()) << 262 263 // Air 264 // 265 density = 1.29 * mg / cm3; 266 fAir = new G4Material(name = "Air", density, 267 fAir->AddElement(elN, fractionmass = 0.7); 268 fAir->AddElement(elO, fractionmass = 0.3); 269 270 // Aluminum 271 // 272 density = 2.70 * g / cm3; 273 fAluminum = new G4Material(name = "Aluminum" 274 fAluminum->AddElement(elAl, fractionmass = 1 275 276 // Lead 277 // 278 fPb = new G4Material("Lead", z = 82., a = 20 279 280 // Xenon gas 281 // 282 fXenon = new G4Material("XenonGas", z = 54., 283 kStateGas, temperatu 284 285 // Prints the material information 286 // 287 G4cout << *(G4Material::GetMaterialTable()) 288 } 289 290 //....oooOO0OOooo........oooOO0OOooo........oo 291 // 292 // Detector Construction 293 // 294 // Detector consist from DetectorBox, Conrol R 295 // SubDetectors1 and 2 show how to use Reflect 296 // SubDetectors 3 and 4 show how to use Parame 297 // 298 G4VPhysicalVolume* G02DetectorConstruction::Co 299 { 300 // Arbitary values that should enclose any r 301 // 302 const G4double expHall_y = fExpHall_x; 303 const G4double expHall_z = fExpHall_x; 304 305 // Create the hall 306 // 307 G4Box* experimentalHallBox = new G4Box("ExpH 308 G4LogicalVolume* experimentalHallLV = new G4 309 G4PVPlacement* experimentalHallPhys = new G4 310 0, G4ThreeVector(0.0, 0.0, 0.0), experimen 311 312 // G02DetectorConstruction 313 314 const G4double det_x = fExpHall_x * 0.8; 315 const G4double det_y = fExpHall_x * 0.7; 316 const G4double det_z = det_y; 317 318 // Create the detector box 319 // 320 G4Box* detectorBox = new G4Box("detectorBox" 321 G4LogicalVolume* detectorLV = new G4LogicalV 322 // G4PVPlacement * detectorPhys = 323 new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, 324 false, 0); 325 326 // Create the Control room box 327 // 328 const G4double room_x = fExpHall_x / 20.; 329 const G4double room_y = room_x; 330 const G4double room_z = room_x; 331 332 G4Box* roomBox = new G4Box("roomBox", room_x 333 G4LogicalVolume* roomLV = new G4LogicalVolum 334 // G4PVPlacement * roomPhys = 335 new G4PVPlacement(0, G4ThreeVector(fExpHall_ 336 experimentalHallLV, false, 337 338 // SubDetector1 339 // 340 const G4double bigL = fExpHall_x / 5. + 50.; 341 G4LogicalVolume* subDetectorLV1 = ConstructS 342 // G4PVPlacement * detPhys1 = 343 new G4PVPlacement(0, G4ThreeVector(bigL, 0.0 344 detectorLV, false, 0); 345 346 // 347 // LOOK HERE FOR REFLECTIONS 348 // 349 350 // SubDetector2 351 // 352 G4Translate3D translation(-bigL, 0., 0.); 353 G4RotationMatrix* rotD3 = new G4RotationMatr 354 G4Transform3D rotation = G4Rotate3D(*rotD3); 355 G4ReflectX3D reflection; 356 G4Transform3D transform = translation * rota 357 358 // Place the reflected part using G4Reflecti 359 // 360 G4ReflectionFactory::Instance()->Place(trans 361 false 362 363 // SubDetector3 364 // 365 G4LogicalVolume* subDetectorLV3 = ConstructS 366 // G4PVPlacement * detPhys3 = 367 new G4PVPlacement(0, G4ThreeVector(0.0, bigL 368 detectorLV, false, 0); 369 370 // SubDetector4, placement of parameterised 371 // 372 G4LogicalVolume* subDetectorLV4 = ConstructS 373 G4LogicalVolume* subChamberLV = ConstructPar 374 // G4PVPlacement * detChamb = 375 new G4PVPlacement(0, G4ThreeVector(0, 0.0, 0 376 false, 0); 377 // G4PVPlacement * detPhys4 = 378 new G4PVPlacement(0, G4ThreeVector(0.0, -big 379 detectorLV, false, 0); 380 381 return experimentalHallPhys; 382 } 383 384 //....oooOO0OOooo........oooOO0OOooo........oo 385 // 386 // SubDetector1 387 // 388 G4LogicalVolume* G02DetectorConstruction::Cons 389 { 390 const G4double sub_x = fExpHall_x / 5.; 391 const G4double sub_y = sub_x; 392 393 // Create the hall 394 // 395 G4Tubs* subTub = new G4Tubs("subTub", 0., su 396 G4LogicalVolume* subTubLV = new G4LogicalVol 397 G4LogicalVolume* AssemblyLV = ConstructAssem 398 // G4PVPlacement * detAss = 399 new G4PVPlacement(0, G4ThreeVector(sub_x / 3 400 false, 0); 401 return subTubLV; 402 } 403 404 //....oooOO0OOooo........oooOO0OOooo........oo 405 // 406 // SubDetector2 407 // 408 G4LogicalVolume* G02DetectorConstruction::Cons 409 { 410 const G4double sub_x = fExpHall_x / 10.; 411 const G4double sub_y = sub_x * 2.; 412 const G4double sub_z = sub_x; 413 414 // Create the hall 415 // 416 G4Box* detHallBox = new G4Box("detHallBox", 417 G4LogicalVolume* detHallLV = new G4LogicalVo 418 419 return detHallLV; 420 } 421 422 //....oooOO0OOooo........oooOO0OOooo........oo 423 // 424 // Assembly 425 // 426 G4LogicalVolume* G02DetectorConstruction::Cons 427 { 428 const G4double big_x = fExpHall_x / 17; 429 const G4double big_y = big_x; 430 const G4double big_z = big_x; 431 432 // Create the Box 433 // 434 G4Box* OuterBox = new G4Box("OuterBox", big_ 435 G4LogicalVolume* OuterBoxLV = new G4LogicalV 436 // G4PVPlacement * OuterBoxPhys = 437 new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, 438 439 // The aluminum object's logical volume 440 // 441 const G4double bigL = big_x / 2.5; 442 const G4double medL = big_x / 8; 443 const G4double smalL = big_x / 12; 444 445 G4Box* BigBox = new G4Box("BBox", bigL, bigL 446 G4LogicalVolume* BigBoxLV = new G4LogicalVol 447 G4Box* MedBox = new G4Box("MBox", medL, medL 448 G4LogicalVolume* MedBoxLV1 = new G4LogicalVo 449 G4Box* SmallBox = new G4Box("SBox", smalL, s 450 G4LogicalVolume* SmallBoxLV = new G4LogicalV 451 452 const G4double bigPlace = bigL + 10.; 453 const G4double medPlace = medL + 10.; 454 // G4PVPlacement * BigBoxPhys = 455 new G4PVPlacement(0, G4ThreeVector(bigPlace, 456 0); 457 458 // Construction of Tub 459 // 460 G4Tubs* BigTube = new G4Tubs("BTube", 0, sma 461 462 // Construction of Reflection of Tub 463 // 464 G4ReflectX3D Xreflection; 465 G4Translate3D translation(-bigPlace, 0., 0.) 466 G4Transform3D transform = Xreflection; 467 468 G4ReflectedSolid* ReflBig = new G4ReflectedS 469 G4LogicalVolume* ReflBigLV = new G4LogicalVo 470 new G4PVPlacement(0, G4ThreeVector(0., 0.0, 471 0); 472 // 473 // LOOK HERE FOR ASSEMBLY 474 // 475 476 // create Assembly of Boxes and Tubs 477 // 478 G4AssemblyVolume* assembly = new G4AssemblyV 479 G4RotationMatrix* rot = new G4RotationMatrix 480 G4ThreeVector posBig(-bigPlace, 0, 0); 481 G4ThreeVector posBig0(bigPlace / 4, 0, 0); 482 G4ThreeVector posMed(-medPlace, 0, 0); 483 G4ThreeVector posMed0(medPlace, 0, 0); 484 G4ThreeVector position(0., 0., 0.); 485 486 // Add to Assembly the MediumBox1 487 // 488 assembly->AddPlacedVolume(MedBoxLV1, posMed0 489 490 // Add to Assembly the Small Box 491 // 492 assembly->AddPlacedVolume(SmallBoxLV, posMed 493 494 // Place the Assembly 495 // 496 assembly->MakeImprint(BigBoxLV, posBig0, rot 497 498 // 499 // LOOK HERE FOR ASSEMBLY with REFLECTION 500 // 501 502 G4Translate3D translation1(-bigPlace, 0., 0. 503 G4RotationMatrix* rotD3 = new G4RotationMatr 504 G4Transform3D rotation = G4Rotate3D(*rotD3); 505 G4ReflectX3D reflection; 506 G4Transform3D transform1 = translation1 * ro 507 508 assembly->MakeImprint(OuterBoxLV, transform1 509 510 return OuterBoxLV; 511 } 512 513 //....oooOO0OOooo........oooOO0OOooo........oo 514 // 515 // Parameterised Chamber 516 // 517 G4LogicalVolume* G02DetectorConstruction::Cons 518 { 519 const G4double chamber_x = fExpHall_x / 12.; 520 const G4double chamber_y = chamber_x; 521 const G4double chamber_z = chamber_x; 522 523 // Create the hall 524 // 525 G4Box* paramChamberBox = new G4Box("ChamberB 526 G4LogicalVolume* paramChamberLV = new G4Logi 527 528 // Parametrisation Chamber (taken from N02 n 529 // 530 G4int NbOfChambers = 5; 531 G4double ChamberWidth = 2 * cm; 532 G4double ChamberSpacing = 8 * cm; 533 G4double fTrackerLength = (NbOfChambers + 1) 534 G4double trackerSize = 0.5 * fTrackerLength; 535 536 // An example of parameterised volume 537 // dummy values for G4Box -- modified by par 538 // 539 G4Box* solidChamber = new G4Box("chamber", 1 540 G4LogicalVolume* logicChamber = new G4Logica 541 542 G4double firstPosition = -trackerSize + 0.5 543 G4double firstLength = fTrackerLength / 10; 544 G4double lastLength = fTrackerLength; 545 546 G4VPVParameterisation* chamberParam = 547 new G02ChamberParameterisation(NbOfChamber 548 firstPositi 549 ChamberSpac 550 ChamberWidt 551 firstLength 552 lastLength) 553 // G4VPhysicalVolume* physiChamber = 554 new G4PVParameterised("Chamber", // their n 555 logicChamber, // thei 556 paramChamberLV, // mo 557 kZAxis, // Are placed 558 NbOfChambers, // Numb 559 chamberParam); // The 560 return paramChamberLV; 561 } 562 563 //....oooOO0OOooo........oooOO0OOooo........oo 564 // 565 // SetReadFile 566 // 567 void G02DetectorConstruction::SetReadFile(cons 568 { 569 fReadFile = File; 570 fWritingChoice = 0; 571 } 572 573 //....oooOO0OOooo........oooOO0OOooo........oo 574 // 575 // SetWriteFile 576 // 577 void G02DetectorConstruction::SetWriteFile(con 578 { 579 fWriteFile = File; 580 fWritingChoice = 1; 581 } 582 583 //....oooOO0OOooo........oooOO0OOooo........oo 584 // 585 // SetStepFile 586 // 587 void G02DetectorConstruction::SetStepFile(cons 588 { 589 fStepFile = File; 590 fWritingChoice = 3; 591 } 592