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 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 33 34 #include "DetectorConstruction.hh" 35 36 #include "DetectorMessenger.hh" 37 #include "PrimaryGeneratorAction.hh" 38 39 #include "G4Box.hh" 40 #include "G4GeometryManager.hh" 41 #include "G4LogicalVolume.hh" 42 #include "G4LogicalVolumeStore.hh" 43 #include "G4Material.hh" 44 #include "G4NistManager.hh" 45 #include "G4PVPlacement.hh" 46 #include "G4PhysicalConstants.hh" 47 #include "G4PhysicalVolumeStore.hh" 48 #include "G4RunManager.hh" 49 #include "G4SolidStore.hh" 50 #include "G4Sphere.hh" 51 #include "G4SystemOfUnits.hh" 52 #include "G4ThreeVector.hh" 53 #include "globals.hh" 54 55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 56 57 DetectorConstruction::DetectorConstruction() 58 : fMaterialTracker(nullptr), 59 fMaterialEmCalo(nullptr), 60 fMaterialHadCalo(nullptr), 61 fExperimentalHall_log(nullptr), 62 fExperimentalHall_phys(nullptr), 63 fLogicTrackerShell(nullptr), 64 fPhysiTrackerShell(nullptr), 65 fLogicEmCaloShell(nullptr), 66 fPhysiEmCaloShell(nullptr), 67 fLogicHadCaloShell(nullptr), 68 fPhysiHadCaloShell(nullptr), 69 fLogicScoringTrackerShell(nullptr), 70 fPhysiScoringTrackerShell(nullptr), 71 fLogicScoringEmCaloShell(nullptr), 72 fPhysiScoringEmCaloShell(nullptr), 73 fLogicScoringHadCaloShell(nullptr), 74 fPhysiScoringHadCaloShell(nullptr), 75 fDetectorMessenger(nullptr), 76 fInnerRadiusTracker(10.0 * cm), 77 fOuterRadiusTracker(20.0 * cm), //***LOOKHERE*** Default radii 78 fInnerRadiusEmCalo(30.0 * cm), 79 fOuterRadiusEmCalo(60.0 * cm), 80 fInnerRadiusHadCalo(70.0 * cm), 81 fOuterRadiusHadCalo(170.0 * cm) 82 { 83 // G4cout << " BEGIN DetectorConstruction::DetectorConstruction()" << G4endl; 84 fMaterialTracker = G4NistManager::Instance()->FindOrBuildMaterial("G4_Si"); //***LOOKHERE*** 85 // Default material 86 fMaterialEmCalo = G4NistManager::Instance()->FindOrBuildMaterial("G4_PbWO4"); 87 fMaterialHadCalo = G4NistManager::Instance()->FindOrBuildMaterial("G4_Fe"); 88 fDetectorMessenger = new DetectorMessenger(this); 89 // G4cout << " END DetectorConstruction::DetectorConstruction()" << G4endl; 90 } 91 92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 93 94 DetectorConstruction::~DetectorConstruction() 95 { 96 delete fDetectorMessenger; 97 } 98 99 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 100 101 G4VPhysicalVolume* DetectorConstruction::Construct() 102 { 103 // G4cout << " BEGIN DetectorConstruction::Construct()" << G4endl; 104 return ConstructDetector(); 105 } 106 107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 108 109 G4VPhysicalVolume* DetectorConstruction::ConstructDetector() 110 { 111 // G4cout << " BEGIN DetectorConstruction::ConstructDetector()" << G4endl; 112 113 // Clean old geometry, if any. 114 G4GeometryManager::GetInstance()->OpenGeometry(); 115 116 G4PhysicalVolumeStore::GetInstance()->Clean(); 117 G4LogicalVolumeStore::GetInstance()->Clean(); 118 G4SolidStore::GetInstance()->Clean(); 119 120 // Check that the radii are resonable 121 G4bool isOK = true; 122 if (fInnerRadiusTracker < 0.0 || fOuterRadiusTracker < fInnerRadiusTracker 123 || fInnerRadiusEmCalo < fOuterRadiusTracker + fScoringThickness 124 || fOuterRadiusEmCalo < fInnerRadiusEmCalo 125 || fInnerRadiusHadCalo < fOuterRadiusEmCalo + fScoringThickness 126 || fOuterRadiusHadCalo < fInnerRadiusHadCalo) 127 { 128 isOK = false; 129 } 130 if (!isOK) { 131 G4cerr << G4endl << "ERROR: the radii are inconsistent !" << G4endl 132 << " InnerRadiusTracker = " << fInnerRadiusTracker << " mm" << G4endl 133 << " OuterRadiusTracker = " << fOuterRadiusTracker << " mm" << G4endl 134 << " InnerRadiusEmCalo = " << fInnerRadiusEmCalo << " mm" << G4endl 135 << " OuterRadiusEmCalo = " << fOuterRadiusEmCalo << " mm" << G4endl 136 << " InnerRadiusHadCalo = " << fInnerRadiusHadCalo << " mm" << G4endl 137 << " OuterRadiusHadCalo = " << fOuterRadiusHadCalo << " mm" << G4endl 138 << " ScoringThickness = " << fScoringThickness << " mm" << G4endl << G4endl; 139 return nullptr; 140 } 141 142 // The detector consists of 3 concentric full spherical shells (G4Sphere), 143 // positioned at the center, (0.0, 0.0, 0.0). 144 // The world volume (experimental hall) is a box 10% bigger than the outmost 145 // spherical shell. 146 // and it is filled of "G4_Galactic" material. 147 148 G4double expHall_x = 1.1 * fOuterRadiusHadCalo; // half dimension along x 149 G4double expHall_y = 1.1 * fOuterRadiusHadCalo; // half dimension along y 150 G4double expHall_z = 1.1 * fOuterRadiusHadCalo; // half dimension along z 151 152 G4Material* vacuum = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic"); 153 154 G4Box* experimentalHall_box = new G4Box("expHall_box", expHall_x, expHall_y, expHall_z); 155 156 fExperimentalHall_log = new G4LogicalVolume(experimentalHall_box, // solid 157 vacuum, // material 158 "expHall_log", // name 159 0, // field manager 160 0, // sensitive detector 161 0); // user limits 162 163 fExperimentalHall_phys = new G4PVPlacement(0, // rotation 164 G4ThreeVector(), // translation 165 "expHall", // name 166 fExperimentalHall_log, // logical volume 167 0, // mother physical volume 168 false, // boolean operation 169 0); // copy number 170 171 // 1st (innermost) spherical shell: Tracker 172 G4Sphere* solidTrackerShell = new G4Sphere("solidTrackerShell", // name 173 fInnerRadiusTracker, // Inner radius 174 fOuterRadiusTracker, // Outer radius 175 0.0, // Starting Phi angle of the 176 // segment in radians 177 2.0 * CLHEP::pi, // Delta Phi angle of the 178 // segment in radians 179 0.0, // Starting Theta angle of 180 // the segment in radians 181 CLHEP::pi); // Delta Theta angle of the 182 // segment in radians 183 fLogicTrackerShell = new G4LogicalVolume(solidTrackerShell, // solid 184 fMaterialTracker, // material 185 "logicTrackerShell", // name 186 0, // field manager 187 0, // sensitive detector 188 0); // user limits 189 fPhysiTrackerShell = new G4PVPlacement(0, // rotation 190 G4ThreeVector(), // translation 191 "physiTrackerShell", // name 192 fLogicTrackerShell, // logical volume 193 fExperimentalHall_phys, // mother physical volume 194 false, // boolean operation 195 0); // copy number 196 197 // Scoring tracker shell (a thin vacuum layer, immediately outside the Tracker shell) 198 G4Sphere* solidScoringTrackerShell = 199 new G4Sphere("solidScoringTrackerShell", // name 200 fOuterRadiusTracker, // Inner radius 201 fOuterRadiusTracker + fScoringThickness, // Outer radius 202 0.0, // Starting Phi angle of the segment 203 // in radians 204 2.0 * CLHEP::pi, // Delta Phi angle of the segment 205 // in radians 206 0.0, // Starting Theta angle of the segment 207 // in radians 208 CLHEP::pi); // Delta Theta angle of the segment 209 // in radians 210 fLogicScoringTrackerShell = new G4LogicalVolume(solidScoringTrackerShell, // solid 211 vacuum, // material 212 "logicScoringTrackerShell", // name 213 0, // field manager 214 0, // sensitive 215 // detector 216 0); // user limits 217 fPhysiScoringTrackerShell = new G4PVPlacement(0, // rotation 218 G4ThreeVector(), // translation 219 "physiScoringTrackerShell", // name 220 fLogicScoringTrackerShell, // logical volume 221 fExperimentalHall_phys, // mother physical 222 // volume 223 false, // boolean 224 // operation 225 0); // copy number 226 227 // 2nd (middle) spherical shell: EM Calo 228 G4Sphere* solidEmCaloShell = new G4Sphere("solidEmCaloShell", // name 229 fInnerRadiusEmCalo, // Inner radius 230 fOuterRadiusEmCalo, // Outer radius 231 0.0, // Starting Phi angle of the 232 // segment in radians 233 2.0 * CLHEP::pi, // Delta Phi angle of the 234 // segment in radians 235 0.0, // Starting Theta angle of the 236 // segment in radians 237 CLHEP::pi); // Delta Theta angle of the 238 // segment in radians 239 fLogicEmCaloShell = new G4LogicalVolume(solidEmCaloShell, // solid 240 fMaterialEmCalo, // material 241 "logicEmCaloShell", // name 242 0, // field manager 243 0, // sensitive detector 244 0); // user limits 245 fPhysiEmCaloShell = new G4PVPlacement(0, // rotation 246 G4ThreeVector(), // translation 247 "physiEmCaloShell", // name 248 fLogicEmCaloShell, // logical volume 249 fExperimentalHall_phys, // mother physical volume 250 false, // boolean operation 251 0); // copy number 252 253 // Scoring EmCalo shell (a thin vacuum layer, immediately outside the EmCalo shell) 254 G4Sphere* solidScoringEmCaloShell = 255 new G4Sphere("solidScoringEmCaloShell", // name 256 fOuterRadiusEmCalo, // Inner radius 257 fOuterRadiusEmCalo + fScoringThickness, // Outer radius 258 0.0, // Starting Phi angle of the segment 259 // in radians 260 2.0 * CLHEP::pi, // Delta Phi angle of the segment 261 // in radians 262 0.0, // Starting Theta angle of the 263 // segment in radians 264 CLHEP::pi); // Delta Theta angle of the segment 265 // in radians 266 fLogicScoringEmCaloShell = new G4LogicalVolume(solidScoringEmCaloShell, // solid 267 vacuum, // material 268 "logicScoringEmCaloShell", // name 269 0, // field manager 270 0, // sensitive 271 // detector 272 0); // user limits 273 fPhysiScoringEmCaloShell = new G4PVPlacement(0, // rotation 274 G4ThreeVector(), // translation 275 "physiScoringEmCaloShell", // name 276 fLogicScoringEmCaloShell, // logical volume 277 fExperimentalHall_phys, // mother physical 278 // volume 279 false, // boolean operation 280 0); // copy number 281 282 // 3rd (outmost) spherical shell: HAD Calo 283 G4Sphere* solidHadCaloShell = new G4Sphere("solidHadCaloShell", // name 284 fInnerRadiusHadCalo, // Inner radius 285 fOuterRadiusHadCalo, // Outer radius 286 0.0, // Starting Phi angle of the 287 // segment in radians 288 2.0 * CLHEP::pi, // Delta Phi angle of the 289 // segment in radians 290 0.0, // Starting Theta angle of 291 // the segment in radians 292 CLHEP::pi); // Delta Theta angle of the 293 // segment in radians 294 fLogicHadCaloShell = new G4LogicalVolume(solidHadCaloShell, // solid 295 fMaterialHadCalo, // material 296 "logicHadCaloShell", // name 297 0, // field manager 298 0, // sensitive detector 299 0); // user limits 300 fPhysiHadCaloShell = new G4PVPlacement(0, // rotation 301 G4ThreeVector(), // translation 302 "physiHadCaloShell", // name 303 fLogicHadCaloShell, // logical volume 304 fExperimentalHall_phys, // mother physical volume 305 false, // boolean operation 306 0); // copy number 307 308 // Scoring HadCalo shell (a thin vacuum layer, immediately outside the HadCalo shell) 309 G4Sphere* solidScoringHadCaloShell = 310 new G4Sphere("solidScoringHadCaloShell", // name 311 fOuterRadiusHadCalo, // Inner radius 312 fOuterRadiusHadCalo + fScoringThickness, // Outer radius 313 0.0, // Starting Phi angle of the 314 // segment in radians 315 2.0 * CLHEP::pi, // Delta Phi angle of the segment 316 // in radians 317 0.0, // Starting Theta angle of the 318 // segment in radians 319 CLHEP::pi); // Delta Theta angle of the segment 320 // in radians 321 fLogicScoringHadCaloShell = new G4LogicalVolume(solidScoringHadCaloShell, // solid 322 vacuum, // material 323 "logicScoringHadCaloShell", // name 324 0, // field manager 325 0, // sensitive 326 // detector 327 0); // user limits 328 fPhysiScoringHadCaloShell = new G4PVPlacement(0, // rotation 329 G4ThreeVector(), // translation 330 "physiScoringHadCaloShell", // name 331 fLogicScoringHadCaloShell, // logical volume 332 fExperimentalHall_phys, // mother physical 333 // volume 334 false, // boolean 335 // operation 336 0); // copy number 337 338 G4cout << "DetectorConstruction::ConstructSphere() : " << G4endl 339 << "\t World (box) size: " << G4endl << "\t \t x : -/+ " << expHall_x << " mm ;" 340 << "\t y : -/+ " << expHall_y << " mm ;" 341 << "\t z : -/+ " << expHall_z << " mm ;" << G4endl << G4endl; 342 PrintParameters(); 343 // G4cout << " END DetectorConstruction::ConstructDetector() 344 345 return fExperimentalHall_phys; 346 } 347 348 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 349 350 void DetectorConstruction::SetMaterialTracker(const G4String name) 351 { 352 fMaterialTracker = G4NistManager::Instance()->FindOrBuildMaterial(name); 353 if (!fMaterialTracker) { 354 G4cout << G4endl << G4endl << "WARNING: the name of the material has not been recognized!" 355 << G4endl << " ===> the default * G4_Si * will be used." << G4endl << G4endl; 356 fMaterialTracker = G4NistManager::Instance()->FindOrBuildMaterial("G4_Si"); 357 } 358 if (fLogicTrackerShell) fLogicTrackerShell->SetMaterial(fMaterialTracker); 359 } 360 361 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 362 363 void DetectorConstruction::SetMaterialEmCalo(const G4String name) 364 { 365 fMaterialEmCalo = G4NistManager::Instance()->FindOrBuildMaterial(name); 366 if (!fMaterialEmCalo) { 367 G4cout << G4endl << G4endl << "WARNING: the name of the material has not been recognized!" 368 << G4endl << " ===> the default * G4_Pb * will be used." << G4endl << G4endl; 369 fMaterialEmCalo = G4NistManager::Instance()->FindOrBuildMaterial("G4_Pb"); 370 } 371 if (fLogicEmCaloShell) fLogicEmCaloShell->SetMaterial(fMaterialEmCalo); 372 } 373 374 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 375 376 void DetectorConstruction::SetMaterialHadCalo(const G4String name) 377 { 378 fMaterialHadCalo = G4NistManager::Instance()->FindOrBuildMaterial(name); 379 if (fMaterialHadCalo == nullptr) { 380 G4cout << G4endl << G4endl << "WARNING: the name of the material has not been recognized!" 381 << G4endl << " ===> the default * G4_Fe * will be used." << G4endl << G4endl; 382 fMaterialHadCalo = G4NistManager::Instance()->FindOrBuildMaterial("G4_Fe"); 383 } 384 if (fLogicHadCaloShell) fLogicHadCaloShell->SetMaterial(fMaterialHadCalo); 385 } 386 387 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 388 389 void DetectorConstruction::UpdateGeometry() 390 { 391 // G4cout << " BEGIN DetectorConstruction::UpdateGeometry" << G4endl; 392 G4RunManager::GetRunManager()->ReinitializeGeometry(); 393 PrintParameters(); 394 // Update also the position of the gun 395 const PrimaryGeneratorAction* pPrimaryAction = dynamic_cast<const PrimaryGeneratorAction*>( 396 G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction()); 397 if (pPrimaryAction) pPrimaryAction->SetGunPosition(); 398 // G4cout << " END DetectorConstruction::UpdateGeometry" << G4endl; 399 } 400 401 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 402 403 void DetectorConstruction::PrintParameters() 404 { 405 G4cout << G4endl << " ------ DetectorConstruction::PrintParameters() ------ " << G4endl 406 << " MaterialTracker = " << fMaterialTracker->GetName() << G4endl 407 << " MaterialEmCalo = " << fMaterialEmCalo->GetName() << G4endl 408 << " MaterialHadCalo = " << fMaterialHadCalo->GetName() << G4endl 409 << " InnerRadiusTracker = " << fInnerRadiusTracker << " mm" << G4endl 410 << " OuterRadiusTracker = " << fOuterRadiusTracker << " mm" << G4endl 411 << " InnerRadiusEmCalo = " << fInnerRadiusEmCalo << " mm" << G4endl 412 << " OuterRadiusEmCalo = " << fOuterRadiusEmCalo << " mm" << G4endl 413 << " InnerRadiusHadCalo = " << fInnerRadiusHadCalo << " mm" << G4endl 414 << " OuterRadiusHadCalo = " << fOuterRadiusHadCalo << " mm" << G4endl 415 << " ScoringThickness = " << fScoringThickness << " mm" << G4endl 416 << " -------------------------------------------------------- " << G4endl << G4endl; 417 } 418 419 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 420