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 /// \file DetectorConstruction.cc 27 /// \brief Implementation of the DetectorConst 28 29 //....oooOO0OOooo........oooOO0OOooo........oo 30 //....oooOO0OOooo........oooOO0OOooo........oo 31 32 #include "DetectorConstruction.hh" 33 34 #include "DetectorMessenger.hh" 35 36 #include "G4Box.hh" 37 #include "G4Colour.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 "G4PVReplica.hh" 45 #include "G4PhysicalVolumeStore.hh" 46 #include "G4RunManager.hh" 47 #include "G4SolidStore.hh" 48 #include "G4StateManager.hh" 49 #include "G4SystemOfUnits.hh" 50 #include "G4VisAttributes.hh" 51 52 //....oooOO0OOooo........oooOO0OOooo........oo 53 54 DetectorConstruction::DetectorConstruction() 55 { 56 ComputeCalorParameters(); 57 58 // materials 59 DefineMaterials(); 60 SetAbsorberMaterial("G4_Pb"); 61 SetGapMaterial("G4_lAr"); 62 63 // create commands for interactive definitio 64 fDetectorMessenger = new DetectorMessenger(t 65 } 66 67 //....oooOO0OOooo........oooOO0OOooo........oo 68 69 DetectorConstruction::~DetectorConstruction() 70 { 71 delete fDetectorMessenger; 72 } 73 74 //....oooOO0OOooo........oooOO0OOooo........oo 75 76 G4VPhysicalVolume* DetectorConstruction::Const 77 { 78 return ConstructCalorimeter(); 79 } 80 81 //....oooOO0OOooo........oooOO0OOooo........oo 82 83 void DetectorConstruction::DefineMaterials() 84 { 85 // use G4-NIST materials data base 86 // 87 G4NistManager* man = G4NistManager::Instance 88 fDefaultMaterial = man->FindOrBuildMaterial( 89 man->FindOrBuildMaterial("G4_Pb"); 90 man->FindOrBuildMaterial("G4_lAr"); 91 92 // print table 93 // 94 G4cout << *(G4Material::GetMaterialTable()) 95 } 96 97 //....oooOO0OOooo........oooOO0OOooo........oo 98 99 G4VPhysicalVolume* DetectorConstruction::Const 100 { 101 // Clean old geometry, if any 102 // 103 G4GeometryManager::GetInstance()->OpenGeomet 104 G4PhysicalVolumeStore::GetInstance()->Clean( 105 G4LogicalVolumeStore::GetInstance()->Clean() 106 G4SolidStore::GetInstance()->Clean(); 107 108 // complete the Calor parameters definition 109 ComputeCalorParameters(); 110 111 // 112 // World 113 // 114 fSolidWorld = new G4Box("World", // its nam 115 fWorldSizeX / 2, fWo 116 117 fLogicWorld = new G4LogicalVolume(fSolidWorl 118 fDefaultMa 119 "World"); 120 121 fPhysiWorld = new G4PVPlacement(nullptr, // 122 G4ThreeVecto 123 fLogicWorld, 124 "World", // 125 nullptr, // 126 false, // n 127 0); // copy 128 129 // 130 // Calorimeter 131 // 132 fSolidCalor = nullptr; 133 fLogicCalor = nullptr; 134 fPhysiCalor = nullptr; 135 fSolidLayer = nullptr; 136 fLogicLayer = nullptr; 137 fPhysiLayer = nullptr; 138 139 if (fCalorThickness > 0.) { 140 fSolidCalor = new G4Box("Calorimeter", // 141 fCalorThickness / 142 143 fLogicCalor = new G4LogicalVolume(fSolidCa 144 fDefault 145 "Calorim 146 147 fPhysiCalor = new G4PVPlacement(nullptr, 148 G4ThreeVec 149 fLogicCalo 150 "Calorimet 151 fLogicWorl 152 false, // 153 0); // co 154 155 // 156 // Layer 157 // 158 fSolidLayer = new G4Box("Layer", // its n 159 fLayerThickness / 160 161 fLogicLayer = new G4LogicalVolume(fSolidLa 162 fDefault 163 "Layer") 164 if (fNbOfLayers > 1) { 165 fPhysiLayer = new G4PVReplica("Layer", 166 fLogicLaye 167 fLogicCalo 168 kXAxis, / 169 fNbOfLayer 170 fLayerThic 171 } 172 else { 173 fPhysiLayer = new G4PVPlacement(nullptr, 174 G4ThreeV 175 fLogicLa 176 "Layer", 177 fLogicCa 178 false, 179 0); // 180 } 181 } 182 183 // 184 // Absorber 185 // 186 fSolidAbsorber = nullptr; 187 fLogicAbsorber = nullptr; 188 fPhysiAbsorber = nullptr; 189 190 if (fAbsorberThickness > 0.) { 191 fSolidAbsorber = new G4Box("Absorber", // 192 fAbsorberThickn 193 194 fLogicAbsorber = new G4LogicalVolume(fSoli 195 fAbso 196 fAbso 197 198 fPhysiAbsorber = new G4PVPlacement(nullptr 199 G4Three 200 fLogicA 201 fAbsorb 202 fLogicL 203 false, 204 0); // 205 } 206 207 // 208 // Gap 209 // 210 fSolidGap = nullptr; 211 fLogicGap = nullptr; 212 fPhysiGap = nullptr; 213 214 if (fGapThickness > 0.) { 215 fSolidGap = new G4Box("Gap", fGapThickness 216 217 fLogicGap = new G4LogicalVolume(fSolidGap, 218 219 fPhysiGap = new G4PVPlacement(nullptr, // 220 G4ThreeVecto 221 fLogicGap, 222 fGapMaterial 223 fLogicLayer, 224 false, // n 225 0); // copy 226 } 227 228 PrintCalorParameters(); 229 230 // 231 // Visualization attributes 232 // 233 fLogicWorld->SetVisAttributes(G4VisAttribute 234 235 auto simpleBoxVisAtt = new G4VisAttributes(G 236 simpleBoxVisAtt->SetVisibility(true); 237 fLogicCalor->SetVisAttributes(simpleBoxVisAt 238 239 // 240 // always return the physical World 241 // 242 return fPhysiWorld; 243 } 244 245 //....oooOO0OOooo........oooOO0OOooo........oo 246 247 void DetectorConstruction::PrintCalorParameter 248 { 249 G4cout << "\n------------------------------- 250 << "\n---> The calorimeter is " << fN 251 << fAbsorberThickness / mm << "mm of 252 << fGapThickness / mm << "mm of " << 253 << "\n------------------------------- 254 } 255 256 //....oooOO0OOooo........oooOO0OOooo........oo 257 258 void DetectorConstruction::SetAbsorberMaterial 259 { 260 // search the material by its name 261 auto material = G4NistManager::Instance()->F 262 if (material != nullptr) { 263 fAbsorberMaterial = material; 264 if (fLogicAbsorber != nullptr) { 265 fLogicAbsorber->SetMaterial(fAbsorberMat 266 G4RunManager::GetRunManager()->PhysicsHa 267 } 268 } 269 } 270 271 //....oooOO0OOooo........oooOO0OOooo........oo 272 273 void DetectorConstruction::SetGapMaterial(cons 274 { 275 auto material = G4NistManager::Instance()->F 276 if (material != nullptr) { 277 fGapMaterial = material; 278 if (fLogicGap != nullptr) { 279 fLogicGap->SetMaterial(fGapMaterial); 280 G4RunManager::GetRunManager()->PhysicsHa 281 } 282 } 283 } 284 285 //....oooOO0OOooo........oooOO0OOooo........oo 286 287 void DetectorConstruction::SetAbsorberThicknes 288 { 289 // change Absorber thickness and recompute t 290 fAbsorberThickness = value; 291 if (G4StateManager::GetStateManager()->GetCu 292 G4RunManager::GetRunManager()->Reinitializ 293 } 294 } 295 296 //....oooOO0OOooo........oooOO0OOooo........oo 297 298 void DetectorConstruction::SetGapThickness(G4d 299 { 300 // change Gap thickness and recompute the ca 301 fGapThickness = value; 302 if (G4StateManager::GetStateManager()->GetCu 303 G4RunManager::GetRunManager()->Reinitializ 304 } 305 } 306 307 //....oooOO0OOooo........oooOO0OOooo........oo 308 309 void DetectorConstruction::SetCalorSizeYZ(G4do 310 { 311 // change the transverse size and recompute 312 fCalorSizeYZ = value; 313 if (G4StateManager::GetStateManager()->GetCu 314 G4RunManager::GetRunManager()->Reinitializ 315 } 316 } 317 318 //....oooOO0OOooo........oooOO0OOooo........oo 319 320 void DetectorConstruction::SetNbOfLayers(G4int 321 { 322 fNbOfLayers = value; 323 if (G4StateManager::GetStateManager()->GetCu 324 G4RunManager::GetRunManager()->Reinitializ 325 } 326 } 327 328 //....oooOO0OOooo........oooOO0OOooo........oo 329