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 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 "G4Box.hh" 38 #include "G4GeometryManager.hh" 39 #include "G4LogicalVolume.hh" 40 #include "G4LogicalVolumeStore.hh" 41 #include "G4Material.hh" 42 #include "G4NistManager.hh" 43 #include "G4PVPlacement.hh" 44 #include "G4PhysicalConstants.hh" 45 #include "G4PhysicalVolumeStore.hh" 46 #include "G4RunManager.hh" 47 #include "G4SolidStore.hh" 48 #include "G4SystemOfUnits.hh" 49 #include "G4UnitsTable.hh" 50 51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 52 53 DetectorConstruction::DetectorConstruction() 54 { 55 // default geometrical parameters 56 fAbsorThickness = 1 * cm; 57 fAbsorSizeYZ = 1 * cm; 58 fWorldSizeX = 1.2 * fAbsorThickness; 59 fWorldSizeYZ = 1.2 * fAbsorSizeYZ; 60 61 // materials 62 DefineMaterials(); 63 SetAbsorMaterial("G4_Co"); 64 65 // create commands for interactive definition of the geometry 66 fDetectorMessenger = new DetectorMessenger(this); 67 } 68 69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 70 71 DetectorConstruction::~DetectorConstruction() 72 { 73 delete fDetectorMessenger; 74 } 75 76 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 77 78 G4VPhysicalVolume* DetectorConstruction::Construct() 79 { 80 return ConstructVolumes(); 81 } 82 83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 84 85 void DetectorConstruction::DefineMaterials() 86 { 87 // specific element name for thermal neutronHP 88 // (see G4ParticleHPThermalScatteringNames.cc) 89 90 G4int ncomponents, natoms; 91 92 // pressurized water 93 G4Element* H = new G4Element("TS_H_of_Water", "H", 1., 1.0079 * g / mole); 94 G4Element* O = new G4Element("Oxygen", "O", 8., 16.00 * g / mole); 95 G4Material* H2O = new G4Material("Water_ts", 1.000 * g / cm3, ncomponents = 2, kStateLiquid, 96 593 * kelvin, 150 * bar); 97 H2O->AddElement(H, natoms = 2); 98 H2O->AddElement(O, natoms = 1); 99 H2O->GetIonisation()->SetMeanExcitationEnergy(78.0 * eV); 100 101 // heavy water 102 G4Isotope* H2 = new G4Isotope("H2", 1, 2); 103 G4Element* D = new G4Element("TS_D_of_Heavy_Water", "D", 1); 104 D->AddIsotope(H2, 100 * perCent); 105 G4Material* D2O = new G4Material("HeavyWater", 1.11 * g / cm3, ncomponents = 2, kStateLiquid, 106 293.15 * kelvin, 1 * atmosphere); 107 D2O->AddElement(D, natoms = 2); 108 D2O->AddElement(O, natoms = 1); 109 110 // graphite 111 G4Isotope* C12 = new G4Isotope("C12", 6, 12); 112 G4Element* C = new G4Element("TS_C_of_Graphite", "C", ncomponents = 1); 113 C->AddIsotope(C12, 100. * perCent); 114 G4Material* graphite = new G4Material("graphite", 2.27 * g / cm3, ncomponents = 1, kStateSolid, 115 293 * kelvin, 1 * atmosphere); 116 graphite->AddElement(C, natoms = 1); 117 118 // example of vacuum 119 fWorldMaterial = new G4Material("Galactic", 1, 1.01 * g / mole, universe_mean_density, kStateGas, 120 2.73 * kelvin, 3.e-18 * pascal); 121 122 /// G4cout << *(G4Material::GetMaterialTable()) << G4endl; 123 } 124 125 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 126 127 G4Material* DetectorConstruction::MaterialWithSingleIsotope(G4String name, G4String symbol, 128 G4double density, G4int Z, G4int A) 129 { 130 // define a material from an isotope 131 // 132 G4int ncomponents; 133 G4double abundance, massfraction; 134 135 G4Isotope* isotope = new G4Isotope(symbol, Z, A); 136 137 G4Element* element = new G4Element(name, symbol, ncomponents = 1); 138 element->AddIsotope(isotope, abundance = 100. * perCent); 139 140 G4Material* material = new G4Material(name, density, ncomponents = 1); 141 material->AddElement(element, massfraction = 100. * perCent); 142 143 return material; 144 } 145 146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 147 148 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() 149 { 150 // Cleanup old geometry 151 G4GeometryManager::GetInstance()->OpenGeometry(); 152 G4PhysicalVolumeStore::GetInstance()->Clean(); 153 G4LogicalVolumeStore::GetInstance()->Clean(); 154 G4SolidStore::GetInstance()->Clean(); 155 156 // World 157 // 158 fWorldSizeX = 1.2 * fAbsorThickness; 159 fWorldSizeYZ = 1.2 * fAbsorSizeYZ; 160 161 G4Box* sWorld = new G4Box("World", // name 162 fWorldSizeX / 2, fWorldSizeYZ / 2, fWorldSizeYZ / 2); // dimensions 163 164 G4LogicalVolume* lWorld = new G4LogicalVolume(sWorld, // shape 165 fWorldMaterial, // material 166 "World"); // name 167 168 fWorldVolume = new G4PVPlacement(0, // no rotation 169 G4ThreeVector(), // at (0,0,0) 170 lWorld, // logical volume 171 "World", // name 172 0, // mother volume 173 false, // no boolean operation 174 0); // copy number 175 176 // Absorber 177 // 178 G4Box* sAbsor = new G4Box("Absorber", // name 179 fAbsorThickness / 2, fAbsorSizeYZ / 2, fAbsorSizeYZ / 2); // dimensions 180 181 fLAbsor = new G4LogicalVolume(sAbsor, // shape 182 fAbsorMaterial, // material 183 fAbsorMaterial->GetName()); // name 184 185 new G4PVPlacement(0, // no rotation 186 G4ThreeVector(), // at (0,0,0) 187 fLAbsor, // logical volume 188 fAbsorMaterial->GetName(), // name 189 lWorld, // mother volume 190 false, // no boolean operation 191 0); // copy number 192 193 PrintParameters(); 194 195 // always return the root volume 196 // 197 return fWorldVolume; 198 } 199 200 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 201 202 void DetectorConstruction::PrintParameters() 203 { 204 G4cout << "\n The Absorber is " << G4BestUnit(fAbsorThickness, "Length") << " of " 205 << fAbsorMaterial->GetName() << "\n \n" 206 << fAbsorMaterial << G4endl; 207 } 208 209 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 210 211 void DetectorConstruction::SetAbsorMaterial(G4String materialChoice) 212 { 213 // search the material by its name 214 G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 215 216 if (pttoMaterial) { 217 fAbsorMaterial = pttoMaterial; 218 if (fLAbsor) { 219 fLAbsor->SetMaterial(fAbsorMaterial); 220 } 221 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 222 } 223 else { 224 G4cout << "\n--> warning from DetectorConstruction::SetMaterial : " << materialChoice 225 << " not found" << G4endl; 226 } 227 } 228 229 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 230 231 void DetectorConstruction::SetAbsorThickness(G4double value) 232 { 233 fAbsorThickness = value; 234 G4RunManager::GetRunManager()->ReinitializeGeometry(); 235 } 236 237 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 238 239 void DetectorConstruction::SetAbsorSizeYZ(G4double value) 240 { 241 fAbsorSizeYZ = value; 242 G4RunManager::GetRunManager()->ReinitializeGeometry(); 243 } 244 245 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 246