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 field/field02/src/F02DetectorConstruction.cc 27 /// \brief Implementation of the F02DetectorConstruction class 28 // 29 // 30 // 31 // 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 34 35 #include "F02DetectorConstruction.hh" 36 37 #include "F02CalorimeterSD.hh" 38 #include "F02DetectorMessenger.hh" 39 40 #include "G4AutoDelete.hh" 41 #include "G4GeometryManager.hh" 42 #include "G4FieldBuilder.hh" 43 #include "G4LogicalVolume.hh" 44 #include "G4LogicalVolumeStore.hh" 45 #include "G4Material.hh" 46 #include "G4PVPlacement.hh" 47 #include "G4PhysicalConstants.hh" 48 #include "G4PhysicalVolumeStore.hh" 49 #include "G4RunManager.hh" 50 #include "G4SDManager.hh" 51 #include "G4SolidStore.hh" 52 #include "G4SystemOfUnits.hh" 53 #include "G4Tubs.hh" 54 #include "G4UniformElectricField.hh" 55 56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 57 58 F02DetectorConstruction::F02DetectorConstruction() 59 { 60 // create commands for interactive definition of the calorimeter 61 62 fDetectorMessenger = new F02DetectorMessenger(this); 63 64 // create field builder 65 // this will create commands for field configuration 66 G4FieldBuilder::Instance(); 67 // G4FieldBuilder::Instance()->SetVerboseLevel(2); 68 69 // create materials 70 DefineMaterials(); 71 } 72 73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 74 75 F02DetectorConstruction::~F02DetectorConstruction() 76 { 77 delete fDetectorMessenger; 78 } 79 80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 81 82 G4VPhysicalVolume* F02DetectorConstruction::Construct() 83 { 84 return ConstructCalorimeter(); 85 } 86 87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 88 89 void F02DetectorConstruction::DefineMaterials() 90 { 91 // This function illustrates the possible ways to define materials 92 93 G4String name, symbol; // a=mass of a mole; 94 G4double a, z, density; // z=mean number of protons; 95 G4int nel; 96 G4int ncomponents; 97 G4double fractionmass, pressure, temperature; 98 99 // 100 // define Elements 101 // 102 103 a = 1.01 * g / mole; 104 auto elH = new G4Element(name = "Hydrogen", symbol = "H", z = 1., a); 105 106 a = 12.01 * g / mole; 107 auto elC = new G4Element(name = "Carbon", symbol = "C", z = 6., a); 108 109 a = 14.01 * g / mole; 110 auto elN = new G4Element(name = "Nitrogen", symbol = "N", z = 7., a); 111 112 a = 16.00 * g / mole; 113 auto elO = new G4Element(name = "Oxygen", symbol = "O", z = 8., a); 114 115 a = 39.948 * g / mole; 116 auto elAr = new G4Element(name = "Argon", symbol = "Ar", z = 18., a); 117 118 // 119 // define simple materials 120 // 121 122 // Mylar 123 124 density = 1.39 * g / cm3; 125 auto mylar = new G4Material(name = "Mylar", density, nel = 3); 126 mylar->AddElement(elO, 2); 127 mylar->AddElement(elC, 5); 128 mylar->AddElement(elH, 4); 129 130 // Polypropelene 131 132 auto CH2 = new G4Material("Polypropelene", 0.91 * g / cm3, 2); 133 CH2->AddElement(elH, 2); 134 CH2->AddElement(elC, 1); 135 136 // Krypton as detector gas, STP 137 138 density = 3.700 * mg / cm3; 139 a = 83.80 * g / mole; 140 auto Kr = new G4Material(name = "Kr", z = 36., a, density); 141 142 // Dry air (average composition) 143 144 density = 1.7836 * mg / cm3; // STP 145 auto argon = new G4Material(name = "Argon", density, ncomponents = 1); 146 argon->AddElement(elAr, 1); 147 148 density = 1.25053 * mg / cm3; // STP 149 auto nitrogen = new G4Material(name = "N2", density, ncomponents = 1); 150 nitrogen->AddElement(elN, 2); 151 152 density = 1.4289 * mg / cm3; // STP 153 auto oxygen = new G4Material(name = "O2", density, ncomponents = 1); 154 oxygen->AddElement(elO, 2); 155 156 density = 1.2928 * mg / cm3; // STP 157 158 temperature = STP_Temperature; 159 pressure = 1.0e-0 * STP_Pressure; 160 161 auto air = 162 new G4Material(name = "Air", density, ncomponents = 3, kStateGas, temperature, pressure); 163 air->AddMaterial(nitrogen, fractionmass = 0.7557); 164 air->AddMaterial(oxygen, fractionmass = 0.2315); 165 air->AddMaterial(argon, fractionmass = 0.0128); 166 167 // Xenon as detector gas, STP 168 169 density = 5.858 * mg / cm3; 170 a = 131.29 * g / mole; 171 auto Xe = new G4Material(name = "Xenon", z = 54., a, density); 172 173 // Carbon dioxide, STP 174 175 density = 1.842 * mg / cm3; 176 auto CarbonDioxide = new G4Material(name = "CO2", density, nel = 2); 177 CarbonDioxide->AddElement(elC, 1); 178 CarbonDioxide->AddElement(elO, 2); 179 180 // 80% Xe + 20% CO2, STP 181 182 density = 5.0818 * mg / cm3; 183 auto Xe20CO2 = new G4Material(name = "Xe20CO2", density, ncomponents = 2); 184 Xe20CO2->AddMaterial(Xe, fractionmass = 0.922); 185 Xe20CO2->AddMaterial(CarbonDioxide, fractionmass = 0.078); 186 187 // 80% Kr + 20% CO2, STP 188 189 density = 3.601 * mg / cm3; 190 auto Kr20CO2 = new G4Material(name = "Kr20CO2", density, ncomponents = 2); 191 Kr20CO2->AddMaterial(Kr, fractionmass = 0.89); 192 Kr20CO2->AddMaterial(CarbonDioxide, fractionmass = 0.11); 193 194 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 195 196 // default materials of the calorimeter 197 198 fAbsorberMaterial = Kr20CO2; // XeCO2CF4; 199 200 fWorldMaterial = air; 201 } 202 203 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 204 205 G4VPhysicalVolume* F02DetectorConstruction::ConstructCalorimeter() 206 { 207 // Cleanup old geometry 208 209 if (fPhysiWorld) { 210 G4GeometryManager::GetInstance()->OpenGeometry(); 211 G4PhysicalVolumeStore::GetInstance()->Clean(); 212 G4LogicalVolumeStore::GetInstance()->Clean(); 213 G4SolidStore::GetInstance()->Clean(); 214 } 215 216 // complete the Calor parameters definition and Print 217 218 ComputeCalorParameters(); 219 PrintCalorParameters(); 220 221 // World 222 223 fSolidWorld = new G4Tubs("World", // its name 224 0., fWorldSizeR, fWorldSizeZ / 2., 0., twopi); // its size 225 226 fLogicWorld = new G4LogicalVolume(fSolidWorld, // its solid 227 fWorldMaterial, // its material 228 "World"); // its name 229 230 fPhysiWorld = new G4PVPlacement(nullptr, // no rotation 231 G4ThreeVector(), // at (0,0,0) 232 "World", // its name 233 fLogicWorld, // its logical volume 234 nullptr, // its mother volume 235 false, // no boolean op. 236 0); // copy number 237 // Absorber 238 239 fSolidAbsorber = new G4Tubs("Absorber", 0., fAbsorberRadius, fAbsorberThickness / 2., 0.0, twopi); 240 241 fLogicAbsorber = new G4LogicalVolume(fSolidAbsorber, fAbsorberMaterial, "Absorber"); 242 243 fPhysiAbsorber = new G4PVPlacement(nullptr, G4ThreeVector(0., 0., fZAbsorber), "Absorber", 244 fLogicAbsorber, fPhysiWorld, false, 0); 245 246 return fPhysiWorld; 247 } 248 249 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 250 251 void F02DetectorConstruction::PrintCalorParameters() 252 { 253 G4cout << "\n The WORLD is made of " << fWorldSizeZ / mm << "mm of " 254 << fWorldMaterial->GetName(); 255 G4cout << ", the transverse size (R) of the world is " << fWorldSizeR / mm << " mm. " << G4endl; 256 G4cout << " The ABSORBER is made of " << fAbsorberThickness / mm << "mm of " 257 << fAbsorberMaterial->GetName(); 258 G4cout << ", the transverse size (R) is " << fAbsorberRadius / mm << " mm. " << G4endl; 259 G4cout << " Z position of the (middle of the) absorber " << fZAbsorber / mm << " mm." << G4endl; 260 G4cout << G4endl; 261 } 262 263 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 264 265 void F02DetectorConstruction::SetAbsorberMaterial(G4String materialChoice) 266 { 267 // get the pointer to the material table 268 const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable(); 269 270 // search the material by its name 271 G4Material* material; 272 for (size_t j = 0; j < theMaterialTable->size(); j++) { 273 material = (*theMaterialTable)[j]; 274 if (material->GetName() == materialChoice) { 275 fAbsorberMaterial = material; 276 fLogicAbsorber->SetMaterial(material); 277 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 278 } 279 } 280 } 281 282 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 283 284 void F02DetectorConstruction::SetWorldMaterial(G4String materialChoice) 285 { 286 // get the pointer to the material table 287 const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable(); 288 289 // search the material by its name 290 G4Material* material; 291 for (size_t j = 0; j < theMaterialTable->size(); j++) { 292 material = (*theMaterialTable)[j]; 293 if (material->GetName() == materialChoice) { 294 fWorldMaterial = material; 295 fLogicWorld->SetMaterial(material); 296 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 297 } 298 } 299 } 300 301 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 302 303 void F02DetectorConstruction::SetAbsorberThickness(G4double val) 304 { 305 // change Absorber thickness and recompute the calorimeter parameters 306 fAbsorberThickness = val; 307 ComputeCalorParameters(); 308 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 309 } 310 311 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 312 313 void F02DetectorConstruction::SetAbsorberRadius(G4double val) 314 { 315 // change the transverse size and recompute the calorimeter parameters 316 fAbsorberRadius = val; 317 ComputeCalorParameters(); 318 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 319 } 320 321 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 322 323 void F02DetectorConstruction::SetWorldSizeZ(G4double val) 324 { 325 fWorldChanged = true; 326 fWorldSizeZ = val; 327 ComputeCalorParameters(); 328 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 329 } 330 331 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 332 333 void F02DetectorConstruction::SetWorldSizeR(G4double val) 334 { 335 fWorldChanged = true; 336 fWorldSizeR = val; 337 ComputeCalorParameters(); 338 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 339 } 340 341 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 342 343 void F02DetectorConstruction::SetAbsorberZpos(G4double val) 344 { 345 fZAbsorber = val; 346 ComputeCalorParameters(); 347 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 348 } 349 350 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 351 352 void F02DetectorConstruction::SetFieldValue(G4ThreeVector value) 353 { 354 fFieldVector = value; 355 356 G4UniformElectricField* elField = nullptr; 357 if (fFieldVector != G4ThreeVector(0.,0.,0.)) { 358 elField = new G4UniformElectricField(fFieldVector); 359 } 360 361 // Set field to the field builder 362 auto fieldBuilder = G4FieldBuilder::Instance(); 363 fieldBuilder->SetGlobalField(elField); 364 } 365 366 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 367 368 void F02DetectorConstruction::ConstructSDandField() 369 { 370 // Sensitive Detectors: Absorber 371 372 if (!fCalorimeterSD.Get()) { 373 auto calorimeterSD = new F02CalorimeterSD("CalorSD", this); 374 fCalorimeterSD.Put(calorimeterSD); 375 } 376 G4SDManager::GetSDMpointer()->AddNewDetector(fCalorimeterSD.Get()); 377 SetSensitiveDetector(fLogicAbsorber, fCalorimeterSD.Get()); 378 379 // Create detector field 380 SetFieldValue(fFieldVector); 381 382 // Construct all Geant4 field objects 383 auto fieldBuilder = G4FieldBuilder::Instance(); 384 fieldBuilder->SetFieldType(kElectroMagnetic); 385 fieldBuilder->ConstructFieldSetup(); 386 } 387 388 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 389