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 // 26 // 27 /// \file B4/B4d/src/DetectorConstruction.cc 28 /// \brief Implementation of the B4d::Detector 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 "G4MultiFunctionalDetector.hh" 39 #include "G4NistManager.hh" 40 #include "G4PSEnergyDeposit.hh" 41 #include "G4PSTrackLength.hh" 42 #include "G4PVPlacement.hh" 43 #include "G4PVReplica.hh" 44 #include "G4PhysicalConstants.hh" 45 #include "G4SDChargedFilter.hh" 46 #include "G4SDManager.hh" 47 #include "G4SystemOfUnits.hh" 48 #include "G4VPrimitiveScorer.hh" 49 #include "G4VisAttributes.hh" 50 51 namespace B4d 52 { 53 54 //....oooOO0OOooo........oooOO0OOooo........oo 55 56 G4ThreadLocal G4GlobalMagFieldMessenger* Detec 57 58 //....oooOO0OOooo........oooOO0OOooo........oo 59 60 G4VPhysicalVolume* DetectorConstruction::Const 61 { 62 // Define materials 63 DefineMaterials(); 64 65 // Define volumes 66 return DefineVolumes(); 67 } 68 69 //....oooOO0OOooo........oooOO0OOooo........oo 70 71 void DetectorConstruction::DefineMaterials() 72 { 73 // Lead material defined using NIST Manager 74 auto nistManager = G4NistManager::Instance() 75 nistManager->FindOrBuildMaterial("G4_Pb"); 76 77 // Liquid argon material 78 G4double a; // mass of a mole; 79 G4double z; // z=mean number of protons; 80 G4double density; 81 new G4Material("liquidArgon", z = 18., a = 3 82 // The argon by NIST Manager is a gas with a 83 84 // Vacuum 85 new G4Material("Galactic", z = 1., a = 1.01 86 kStateGas, 2.73 * kelvin, 3.e 87 88 // Print materials 89 G4cout << *(G4Material::GetMaterialTable()) 90 } 91 92 //....oooOO0OOooo........oooOO0OOooo........oo 93 94 G4VPhysicalVolume* DetectorConstruction::Defin 95 { 96 // Geometry parameters 97 G4int nofLayers = 10; 98 G4double absoThickness = 10. * mm; 99 G4double gapThickness = 5. * mm; 100 G4double calorSizeXY = 10. * cm; 101 102 auto layerThickness = absoThickness + gapThi 103 auto calorThickness = nofLayers * layerThick 104 auto worldSizeXY = 1.2 * calorSizeXY; 105 auto worldSizeZ = 1.2 * calorThickness; 106 107 // Get materials 108 auto defaultMaterial = G4Material::GetMateri 109 auto absorberMaterial = G4Material::GetMater 110 auto gapMaterial = G4Material::GetMaterial(" 111 112 if (!defaultMaterial || !absorberMaterial || 113 G4ExceptionDescription msg; 114 msg << "Cannot retrieve materials already 115 G4Exception("DetectorConstruction::DefineV 116 } 117 118 // 119 // World 120 // 121 auto worldS = new G4Box("World", // its nam 122 worldSizeXY / 2, wor 123 124 auto worldLV = new G4LogicalVolume(worldS, 125 defaultMa 126 "World"); 127 128 auto worldPV = new G4PVPlacement(nullptr, / 129 G4ThreeVect 130 worldLV, / 131 "World", / 132 nullptr, / 133 false, // 134 0, // copy 135 fCheckOverl 136 137 // 138 // Calorimeter 139 // 140 auto calorimeterS = new G4Box("Calorimeter", 141 calorSizeXY / 142 143 auto calorLV = new G4LogicalVolume(calorimet 144 defaultMa 145 "Calorime 146 147 new G4PVPlacement(nullptr, // no rotation 148 G4ThreeVector(), // at (0 149 calorLV, // its logical v 150 "Calorimeter", // its nam 151 worldLV, // its mother v 152 false, // no boolean oper 153 0, // copy number 154 fCheckOverlaps); // check 155 156 // 157 // Layer 158 // 159 auto layerS = new G4Box("Layer", // its nam 160 calorSizeXY / 2, cal 161 162 auto layerLV = new G4LogicalVolume(layerS, 163 defaultMa 164 "Layer"); 165 166 new G4PVReplica("Layer", // its name 167 layerLV, // its logical vol 168 calorLV, // its mother 169 kZAxis, // axis of replicat 170 nofLayers, // number of rep 171 layerThickness); // witdth 172 173 // 174 // Absorber 175 // 176 auto absorberS = new G4Box("Abso", // its n 177 calorSizeXY / 2, 178 179 auto absorberLV = new G4LogicalVolume(absorb 180 absorb 181 "AbsoL 182 183 new G4PVPlacement(nullptr, // no rotation 184 G4ThreeVector(0., 0., -gap 185 absorberLV, // its logica 186 "Abso", // its name 187 layerLV, // its mother v 188 false, // no boolean oper 189 0, // copy number 190 fCheckOverlaps); // check 191 192 // 193 // Gap 194 // 195 auto gapS = new G4Box("Gap", // its name 196 calorSizeXY / 2, calor 197 198 auto gapLV = new G4LogicalVolume(gapS, // i 199 gapMaterial 200 "GapLV"); 201 202 new G4PVPlacement(nullptr, // no rotation 203 G4ThreeVector(0., 0., abso 204 gapLV, // its logical vol 205 "Gap", // its name 206 layerLV, // its mother v 207 false, // no boolean oper 208 0, // copy number 209 fCheckOverlaps); // check 210 211 // 212 // print parameters 213 // 214 G4cout << G4endl << "----------------------- 215 << "---> The calorimeter is " << nofL 216 << "mm of " << absorberMaterial->GetN 217 << gapMaterial->GetName() << " ] " << 218 << "--------------------------------- 219 220 // 221 // Visualization attributes 222 // 223 worldLV->SetVisAttributes(G4VisAttributes::G 224 calorLV->SetVisAttributes(G4VisAttributes(G4 225 226 // 227 // Always return the physical World 228 // 229 return worldPV; 230 } 231 232 //....oooOO0OOooo........oooOO0OOooo........oo 233 234 void DetectorConstruction::ConstructSDandField 235 { 236 G4SDManager::GetSDMpointer()->SetVerboseLeve 237 // 238 // Scorers 239 // 240 241 // declare Absorber as a MultiFunctionalDete 242 // 243 auto absDetector = new G4MultiFunctionalDete 244 G4SDManager::GetSDMpointer()->AddNewDetector 245 246 G4VPrimitiveScorer* primitive; 247 primitive = new G4PSEnergyDeposit("Edep"); 248 absDetector->RegisterPrimitive(primitive); 249 250 primitive = new G4PSTrackLength("TrackLength 251 auto charged = new G4SDChargedFilter("charge 252 primitive->SetFilter(charged); 253 absDetector->RegisterPrimitive(primitive); 254 255 SetSensitiveDetector("AbsoLV", absDetector); 256 257 // declare Gap as a MultiFunctionalDetector 258 // 259 auto gapDetector = new G4MultiFunctionalDete 260 G4SDManager::GetSDMpointer()->AddNewDetector 261 262 primitive = new G4PSEnergyDeposit("Edep"); 263 gapDetector->RegisterPrimitive(primitive); 264 265 primitive = new G4PSTrackLength("TrackLength 266 primitive->SetFilter(charged); 267 gapDetector->RegisterPrimitive(primitive); 268 269 SetSensitiveDetector("GapLV", gapDetector); 270 271 // 272 // Magnetic field 273 // 274 // Create global magnetic field messenger. 275 // Uniform magnetic field is then created au 276 // the field value is not zero. 277 G4ThreeVector fieldValue; 278 fMagFieldMessenger = new G4GlobalMagFieldMes 279 fMagFieldMessenger->SetVerboseLevel(1); 280 281 // Register the field messenger for deleting 282 G4AutoDelete::Register(fMagFieldMessenger); 283 } 284 285 //....oooOO0OOooo........oooOO0OOooo........oo 286 287 } // namespace B4d 288