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 // 27 /// \file B4/B4b/src/DetectorConstruction.cc 28 /// \brief Implementation of the B4::DetectorConstruction class 29 30 #include "DetectorConstruction.hh" 31 32 #include "G4AutoDelete.hh" 33 #include "G4Box.hh" 34 #include "G4Colour.hh" 35 #include "G4GlobalMagFieldMessenger.hh" 36 #include "G4LogicalVolume.hh" 37 #include "G4Material.hh" 38 #include "G4NistManager.hh" 39 #include "G4PVPlacement.hh" 40 #include "G4PVReplica.hh" 41 #include "G4PhysicalConstants.hh" 42 #include "G4SystemOfUnits.hh" 43 #include "G4VisAttributes.hh" 44 45 namespace B4 46 { 47 48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 49 50 G4ThreadLocal G4GlobalMagFieldMessenger* DetectorConstruction::fMagFieldMessenger = nullptr; 51 52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 53 54 G4VPhysicalVolume* DetectorConstruction::Construct() 55 { 56 // Define materials 57 DefineMaterials(); 58 59 // Define volumes 60 return DefineVolumes(); 61 } 62 63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 64 65 void DetectorConstruction::DefineMaterials() 66 { 67 // Lead material defined using NIST Manager 68 auto nistManager = G4NistManager::Instance(); 69 nistManager->FindOrBuildMaterial("G4_Pb"); 70 71 // Liquid argon material 72 G4double a; // mass of a mole; 73 G4double z; // z=mean number of protons; 74 G4double density; 75 new G4Material("liquidArgon", z = 18., a = 39.95 * g / mole, density = 1.390 * g / cm3); 76 // The argon by NIST Manager is a gas with a different density 77 78 // Vacuum 79 new G4Material("Galactic", z = 1., a = 1.01 * g / mole, density = universe_mean_density, 80 kStateGas, 2.73 * kelvin, 3.e-18 * pascal); 81 82 // Print materials 83 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 84 } 85 86 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 87 88 G4VPhysicalVolume* DetectorConstruction::DefineVolumes() 89 { 90 // Geometry parameters 91 G4int nofLayers = 10; 92 G4double absoThickness = 10. * mm; 93 G4double gapThickness = 5. * mm; 94 G4double calorSizeXY = 10. * cm; 95 96 auto layerThickness = absoThickness + gapThickness; 97 auto calorThickness = nofLayers * layerThickness; 98 auto worldSizeXY = 1.2 * calorSizeXY; 99 auto worldSizeZ = 1.2 * calorThickness; 100 101 // Get materials 102 auto defaultMaterial = G4Material::GetMaterial("Galactic"); 103 auto absorberMaterial = G4Material::GetMaterial("G4_Pb"); 104 auto gapMaterial = G4Material::GetMaterial("liquidArgon"); 105 106 if (!defaultMaterial || !absorberMaterial || !gapMaterial) { 107 G4ExceptionDescription msg; 108 msg << "Cannot retrieve materials already defined."; 109 G4Exception("DetectorConstruction::DefineVolumes()", "MyCode0001", FatalException, msg); 110 } 111 112 // 113 // World 114 // 115 auto worldS = new G4Box("World", // its name 116 worldSizeXY / 2, worldSizeXY / 2, worldSizeZ / 2); // its size 117 118 auto worldLV = new G4LogicalVolume(worldS, // its solid 119 defaultMaterial, // its material 120 "World"); // its name 121 122 auto worldPV = new G4PVPlacement(nullptr, // no rotation 123 G4ThreeVector(), // at (0,0,0) 124 worldLV, // its logical volume 125 "World", // its name 126 nullptr, // its mother volume 127 false, // no boolean operation 128 0, // copy number 129 fCheckOverlaps); // checking overlaps 130 131 // 132 // Calorimeter 133 // 134 auto calorimeterS = new G4Box("Calorimeter", // its name 135 calorSizeXY / 2, calorSizeXY / 2, calorThickness / 2); // its size 136 137 auto calorLV = new G4LogicalVolume(calorimeterS, // its solid 138 defaultMaterial, // its material 139 "Calorimeter"); // its name 140 141 new G4PVPlacement(nullptr, // no rotation 142 G4ThreeVector(), // at (0,0,0) 143 calorLV, // its logical volume 144 "Calorimeter", // its name 145 worldLV, // its mother volume 146 false, // no boolean operation 147 0, // copy number 148 fCheckOverlaps); // checking overlaps 149 150 // 151 // Layer 152 // 153 auto layerS = new G4Box("Layer", // its name 154 calorSizeXY / 2, calorSizeXY / 2, layerThickness / 2); // its size 155 156 auto layerLV = new G4LogicalVolume(layerS, // its solid 157 defaultMaterial, // its material 158 "Layer"); // its name 159 160 new G4PVReplica("Layer", // its name 161 layerLV, // its logical volume 162 calorLV, // its mother 163 kZAxis, // axis of replication 164 nofLayers, // number of replica 165 layerThickness); // witdth of replica 166 167 // 168 // Absorber 169 // 170 auto absorberS = new G4Box("Abso", // its name 171 calorSizeXY / 2, calorSizeXY / 2, absoThickness / 2); // its size 172 173 auto absorberLV = new G4LogicalVolume(absorberS, // its solid 174 absorberMaterial, // its material 175 "Abso"); // its name 176 177 fAbsorberPV = new G4PVPlacement(nullptr, // no rotation 178 G4ThreeVector(0., 0., -gapThickness / 2), // its position 179 absorberLV, // its logical volume 180 "Abso", // its name 181 layerLV, // its mother volume 182 false, // no boolean operation 183 0, // copy number 184 fCheckOverlaps); // checking overlaps 185 186 // 187 // Gap 188 // 189 auto gapS = new G4Box("Gap", // its name 190 calorSizeXY / 2, calorSizeXY / 2, gapThickness / 2); // its size 191 192 auto gapLV = new G4LogicalVolume(gapS, // its solid 193 gapMaterial, // its material 194 "Gap"); // its name 195 196 fGapPV = new G4PVPlacement(nullptr, // no rotation 197 G4ThreeVector(0., 0., absoThickness / 2), // its position 198 gapLV, // its logical volume 199 "Gap", // its name 200 layerLV, // its mother volume 201 false, // no boolean operation 202 0, // copy number 203 fCheckOverlaps); // checking overlaps 204 205 // 206 // print parameters 207 // 208 G4cout << G4endl << "------------------------------------------------------------" << G4endl 209 << "---> The calorimeter is " << nofLayers << " layers of: [ " << absoThickness / mm 210 << "mm of " << absorberMaterial->GetName() << " + " << gapThickness / mm << "mm of " 211 << gapMaterial->GetName() << " ] " << G4endl 212 << "------------------------------------------------------------" << G4endl; 213 214 // 215 // Visualization attributes 216 // 217 worldLV->SetVisAttributes(G4VisAttributes::GetInvisible()); 218 calorLV->SetVisAttributes(G4VisAttributes(G4Colour::White())); 219 220 // 221 // Always return the physical World 222 // 223 return worldPV; 224 } 225 226 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 227 228 void DetectorConstruction::ConstructSDandField() 229 { 230 // Create global magnetic field messenger. 231 // Uniform magnetic field is then created automatically if 232 // the field value is not zero. 233 G4ThreeVector fieldValue; 234 fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue); 235 fMagFieldMessenger->SetVerboseLevel(1); 236 237 // Register the field messenger for deleting 238 G4AutoDelete::Register(fMagFieldMessenger); 239 } 240 241 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 242 243 } // namespace B4 244