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 "G4Tubs.hh" 50 #include "G4UnitsTable.hh" 51 52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 53 54 DetectorConstruction::DetectorConstruction() 55 { 56 fAbsorRadius = 15 * mm; 57 fAbsorLength = 60 * mm; 58 fContainThickness = 2.4 * mm; 59 DefineMaterials(); 60 SetAbsorMaterial("BeO"); 61 SetContainMaterial("Stainless-Steel"); 62 fDetectorMessenger = new DetectorMessenger(this); 63 } 64 65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 66 67 DetectorConstruction::~DetectorConstruction() 68 { 69 delete fDetectorMessenger; 70 } 71 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 73 74 G4VPhysicalVolume* DetectorConstruction::Construct() 75 { 76 return ConstructVolumes(); 77 } 78 79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 80 81 void DetectorConstruction::DefineMaterials() 82 { 83 G4int ncomponents, natoms; 84 85 G4Element* Be = new G4Element("Beryllium", "Be", 4., 9.01 * g / mole); 86 G4Element* N = new G4Element("Nitrogen", "N", 7., 14.01 * g / mole); 87 G4Element* O = new G4Element("Oxygen", "O", 8., 16.00 * g / mole); 88 G4Element* Cr = new G4Element("Chromium", "Cr", 24., 51.99 * g / mole); 89 G4Element* Fe = new G4Element("Iron", "Fe", 26., 55.84 * g / mole); 90 G4Element* Ni = new G4Element("Nickel", "Ni", 28., 58.69 * g / mole); 91 92 G4Material* BeO = new G4Material("BeO", 3.05 * g / cm3, ncomponents = 2); 93 BeO->AddElement(Be, natoms = 1); 94 BeO->AddElement(O, natoms = 1); 95 96 G4Material* inox = new G4Material("Stainless-Steel", 8 * g / cm3, ncomponents = 3); 97 inox->AddElement(Fe, 74 * perCent); 98 inox->AddElement(Cr, 18 * perCent); 99 inox->AddElement(Ni, 8 * perCent); 100 101 G4Material* Air = new G4Material("Air", 1.290 * mg / cm3, ncomponents = 2); 102 Air->AddElement(N, 70. * perCent); 103 Air->AddElement(O, 30. * perCent); 104 105 fWorldMaterial = Air; 106 107 /// G4cout << *(G4Material::GetMaterialTable()) << G4endl; 108 } 109 110 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 111 112 G4Material* DetectorConstruction::MaterialWithSingleIsotope(G4String name, G4String symbol, 113 G4double density, G4int Z, G4int A) 114 { 115 // define a material from an isotope 116 // 117 G4int ncomponents; 118 G4double abundance, massfraction; 119 120 G4Isotope* isotope = new G4Isotope(symbol, Z, A); 121 122 G4Element* element = new G4Element(name, symbol, ncomponents = 1); 123 element->AddIsotope(isotope, abundance = 100. * perCent); 124 125 G4Material* material = new G4Material(name, density, ncomponents = 1); 126 material->AddElement(element, massfraction = 100. * perCent); 127 128 return material; 129 } 130 131 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 132 133 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() 134 { 135 // Cleanup old geometry 136 G4GeometryManager::GetInstance()->OpenGeometry(); 137 G4PhysicalVolumeStore::GetInstance()->Clean(); 138 G4LogicalVolumeStore::GetInstance()->Clean(); 139 G4SolidStore::GetInstance()->Clean(); 140 141 // compute dimensions 142 G4double ContainRadius = fAbsorRadius + fContainThickness; 143 G4double ContainLength = fAbsorLength + 2 * fContainThickness; 144 145 G4double WorldSizeXY = 2.4 * ContainRadius; 146 G4double WorldSizeZ = 1.2 * ContainLength; 147 148 // World 149 // 150 G4Box* sWorld = new G4Box("World", // name 151 0.5 * WorldSizeXY, 0.5 * WorldSizeXY, 0.5 * WorldSizeZ); // dimensions 152 153 G4LogicalVolume* lWorld = new G4LogicalVolume(sWorld, // shape 154 fWorldMaterial, // material 155 "World"); // name 156 157 fPWorld = new G4PVPlacement(0, // no rotation 158 G4ThreeVector(), // at (0,0,0) 159 lWorld, // logical volume 160 "World", // name 161 0, // mother volume 162 false, // no boolean operation 163 0); // copy number 164 165 // Container 166 // 167 G4Tubs* sContain = new G4Tubs("Container", // name 168 0., ContainRadius, 0.5 * ContainLength, 0., twopi); // dimensions 169 170 fLContain = new G4LogicalVolume(sContain, // shape 171 fContainMaterial, // material 172 fContainMaterial->GetName()); // name 173 174 new G4PVPlacement(0, // no rotation 175 G4ThreeVector(), // at (0,0,0) 176 fLContain, // logical volume 177 fContainMaterial->GetName(), // name 178 lWorld, // mother volume 179 false, // no boolean operation 180 0); // copy number 181 182 // Absorber 183 // 184 G4Tubs* sAbsor = new G4Tubs("Absorber", // name 185 0., fAbsorRadius, 0.5 * fAbsorLength, 0., twopi); // dimensions 186 187 fLAbsor = new G4LogicalVolume(sAbsor, // shape 188 fAbsorMaterial, // material 189 fAbsorMaterial->GetName()); // name 190 191 new G4PVPlacement(0, // no rotation 192 G4ThreeVector(), // at (0,0,0) 193 fLAbsor, // logical volume 194 fAbsorMaterial->GetName(), // name 195 fLContain, // mother volume 196 false, // no boolean operation 197 0); // copy number 198 199 PrintParameters(); 200 201 // always return the root volume 202 // 203 return fPWorld; 204 } 205 206 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 207 208 void DetectorConstruction::PrintParameters() 209 { 210 G4cout << "\n The Absorber is a cylinder of " << fAbsorMaterial->GetName() 211 << " radius = " << G4BestUnit(fAbsorRadius, "Length") 212 << " length = " << G4BestUnit(fAbsorLength, "Length") << G4endl; 213 G4cout << " The Container is a cylinder of " << fContainMaterial->GetName() 214 << " thickness = " << G4BestUnit(fContainThickness, "Length") << G4endl; 215 216 G4cout << "\n" << fAbsorMaterial << G4endl; 217 G4cout << "\n" << fContainMaterial << G4endl; 218 } 219 220 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 221 222 void DetectorConstruction::SetAbsorMaterial(G4String materialChoice) 223 { 224 // search the material by its name 225 G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 226 227 if (pttoMaterial) { 228 fAbsorMaterial = pttoMaterial; 229 if (fLAbsor) { 230 fLAbsor->SetMaterial(fAbsorMaterial); 231 } 232 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 233 } 234 else { 235 G4cout << "\n--> warning from DetectorConstruction::SetAbsorMaterial : " << materialChoice 236 << " not found" << G4endl; 237 } 238 } 239 240 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 241 242 void DetectorConstruction::SetContainMaterial(G4String materialChoice) 243 { 244 // search the material by its name 245 G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 246 247 if (pttoMaterial) { 248 fContainMaterial = pttoMaterial; 249 if (fLContain) { 250 fLContain->SetMaterial(fContainMaterial); 251 } 252 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 253 } 254 else { 255 G4cout << "\n--> warning from DetectorConstruction::SetContainMaterial : " << materialChoice 256 << " not found" << G4endl; 257 } 258 } 259 260 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 261 262 void DetectorConstruction::SetAbsorRadius(G4double value) 263 { 264 fAbsorRadius = value; 265 G4RunManager::GetRunManager()->ReinitializeGeometry(); 266 } 267 268 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 269 270 void DetectorConstruction::SetAbsorLength(G4double value) 271 { 272 fAbsorLength = value; 273 G4RunManager::GetRunManager()->ReinitializeGeometry(); 274 } 275 276 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 277 278 void DetectorConstruction::SetContainThickness(G4double value) 279 { 280 fContainThickness = value; 281 G4RunManager::GetRunManager()->ReinitializeGeometry(); 282 } 283 284 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 285