#include "DetectorConstruction.hh" #include "G4AutoDelete.hh" #include "G4Box.hh" #include "G4Colour.hh" #include "G4GlobalMagFieldMessenger.hh" #include "G4LogicalVolume.hh" #include "G4Material.hh" #include "G4NistManager.hh" #include "G4PVPlacement.hh" #include "G4PhysicalConstants.hh" #include "G4SystemOfUnits.hh" #include "G4VisAttributes.hh" #include "G4Tubs.hh" #include "G4Element.hh" #include "G4SubtractionSolid.hh" namespace B4 { //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... G4ThreadLocal G4GlobalMagFieldMessenger* DetectorConstruction::fMagFieldMessenger = nullptr; //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... G4VPhysicalVolume* DetectorConstruction::Construct() { DefineMaterials(); return DefineVolumes(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void DetectorConstruction::DefineMaterials() { auto nistManager = G4NistManager::Instance(); // Pre-defined materials nistManager->FindOrBuildMaterial("G4_AIR"); nistManager->FindOrBuildMaterial("G4_Al"); // --- MODIFICATION: Define BC-501A using official datasheet values --- // Get the necessary elements G4Element* elH = nistManager->FindOrBuildElement("H"); G4Element* elC = nistManager->FindOrBuildElement("C"); // Define the density of BC-501A from the official datasheet G4double density = 0.874 * g/cm3; // Create the BC-501A material with its density and 2 constituent elements G4Material* detectorMaterial = new G4Material("BC501A", density, 2); // Add the elements by their calculated mass fraction for highest accuracy detectorMaterial->AddElement(elH, 0.0921); // Hydrogen mass fraction (9.21%) detectorMaterial->AddElement(elC, 0.9079); // Carbon mass fraction (90.79%) // Print the material table to verify the new material is loaded G4cout << *(G4Material::GetMaterialTable()) << G4endl; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... G4VPhysicalVolume* DetectorConstruction::DefineVolumes() { // Get materials auto airMaterial = G4Material::GetMaterial("G4_AIR"); auto housingMaterial = G4Material::GetMaterial("G4_Al"); // --- Ensure this line uses the correct material name --- auto detectorMaterial = G4Material::GetMaterial("BC501A"); // World Volume (still required) auto worldSize = 15. * m; auto worldS = new G4Box("World", worldSize/2, worldSize/2, worldSize/2); auto worldLV = new G4LogicalVolume(worldS, airMaterial, "World"); auto worldPV = new G4PVPlacement(nullptr, G4ThreeVector(), worldLV, "World", nullptr, false, 0, fCheckOverlaps); // --- Simplified Geometry: No concrete room --- // Detector Geometry Definitions (Unchanged) G4double scintRadius = (5. * 2.54 * cm) / 2.0; G4double scintHalfLength = (5. * 2.54 * cm) / 2.0; G4double sleeveThickness = 1.5 * mm; G4double backplateThickness = 1.5 * mm; // 1. The Cylindrical Sleeve (the walls) auto sleeveS = new G4Tubs("Sleeve", scintRadius, scintRadius + sleeveThickness, scintHalfLength, 0., 360.*deg); auto sleeveLV = new G4LogicalVolume(sleeveS, housingMaterial, "Sleeve"); // 2. The Backplate (a thin solid disk) auto backplateS = new G4Tubs("Backplate", 0., scintRadius + sleeveThickness, backplateThickness/2.0, 0., 360.*deg); auto backplateLV = new G4LogicalVolume(backplateS, housingMaterial, "Backplate"); // 3. The Scintillator Liquid auto scintS = new G4Tubs("Scintillator", 0., scintRadius, scintHalfLength, 0., 360.*deg); auto scintLV = new G4LogicalVolume(scintS, detectorMaterial, "Scintillator"); // Detector Placement (Position is unchanged) G4double distanceFromSource = 1.5 * m; G4double detectorCenterZ = distanceFromSource + scintHalfLength; G4ThreeVector detectorPosition(0, 0, detectorCenterZ); G4ThreeVector backplatePosition = detectorPosition - G4ThreeVector(0, 0, scintHalfLength + backplateThickness/2.0); // --- Place the components directly INSIDE the World Volume --- new G4PVPlacement(nullptr, detectorPosition, sleeveLV, "Sleeve", worldLV, false, 0, fCheckOverlaps); auto scintPV = new G4PVPlacement(nullptr, detectorPosition, scintLV, "Scintillator", worldLV, false, 0, fCheckOverlaps); new G4PVPlacement(nullptr, backplatePosition, backplateLV, "Backplate", worldLV, false, 0, fCheckOverlaps); // Visualization Attributes worldLV->SetVisAttributes(G4VisAttributes::GetInvisible()); sleeveLV->SetVisAttributes(new G4VisAttributes(G4Colour(0.5, 0.5, 0.5))); // Dark Grey backplateLV->SetVisAttributes(new G4VisAttributes(G4Colour(0.5, 0.5, 0.5))); // Dark Grey scintLV->SetVisAttributes(new G4VisAttributes(G4Colour(0.0, 1.0, 1.0))); // Cyan // Assign Scoring Volume (Unchanged) fAbsorberPV = scintPV; fGapPV = nullptr; return worldPV; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void DetectorConstruction::ConstructSDandField() { G4ThreeVector fieldValue; fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue); fMagFieldMessenger->SetVerboseLevel(1); G4AutoDelete::Register(fMagFieldMessenger); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... } // namespace B4