File indexing completed on 2025-04-10 08:06:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #include "DetectorConstruction.hh"
0035
0036 #include "DetectorMessenger.hh"
0037 #include "PrimaryGeneratorAction.hh"
0038
0039 #include "G4Box.hh"
0040 #include "G4GeometryManager.hh"
0041 #include "G4LogicalVolume.hh"
0042 #include "G4LogicalVolumeStore.hh"
0043 #include "G4Material.hh"
0044 #include "G4NistManager.hh"
0045 #include "G4Orb.hh"
0046 #include "G4PVPlacement.hh"
0047 #include "G4PhysicalConstants.hh"
0048 #include "G4PhysicalVolumeStore.hh"
0049 #include "G4RunManager.hh"
0050 #include "G4SolidStore.hh"
0051 #include "G4Sphere.hh"
0052 #include "G4SystemOfUnits.hh"
0053 #include "G4ThreeVector.hh"
0054 #include "globals.hh"
0055
0056
0057
0058 DetectorConstruction::DetectorConstruction()
0059 : fMaterial(nullptr),
0060 fExperimentalHall_log(nullptr),
0061 fExperimentalHall_phys(nullptr),
0062 fLogicSphere(nullptr),
0063 fPhysiSphere(nullptr),
0064 fLogicScoringShell(nullptr),
0065 fPhysiScoringShell(nullptr),
0066 fDetectorMessenger(nullptr),
0067 fRadius(1.0 * CLHEP::m)
0068 {
0069
0070 fMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Fe");
0071
0072 fDetectorMessenger = new DetectorMessenger(this);
0073
0074 }
0075
0076
0077
0078 DetectorConstruction::~DetectorConstruction()
0079 {
0080 delete fDetectorMessenger;
0081 }
0082
0083
0084
0085 G4VPhysicalVolume* DetectorConstruction::Construct()
0086 {
0087
0088 return ConstructSphere();
0089 }
0090
0091
0092
0093 G4VPhysicalVolume* DetectorConstruction::ConstructSphere()
0094 {
0095
0096
0097
0098 G4GeometryManager::GetInstance()->OpenGeometry();
0099
0100 G4PhysicalVolumeStore::GetInstance()->Clean();
0101 G4LogicalVolumeStore::GetInstance()->Clean();
0102 G4SolidStore::GetInstance()->Clean();
0103
0104
0105
0106
0107
0108 G4double expHall_x = 1.1 * fRadius;
0109 G4double expHall_y = 1.1 * fRadius;
0110 G4double expHall_z = 1.1 * fRadius;
0111
0112 G4Material* vacuum = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
0113
0114
0115 G4Box* experimentalHall_box = new G4Box("expHall_box", expHall_x, expHall_y, expHall_z);
0116 fExperimentalHall_log = new G4LogicalVolume(experimentalHall_box,
0117 vacuum,
0118 "expHall_log",
0119 0,
0120 0,
0121 0);
0122 fExperimentalHall_phys = new G4PVPlacement(0,
0123 G4ThreeVector(),
0124 "expHall",
0125 fExperimentalHall_log,
0126 0,
0127 false,
0128 0);
0129
0130
0131 G4Orb* solidSphere = new G4Orb("solidSphere",
0132 fRadius);
0133 fLogicSphere = new G4LogicalVolume(solidSphere,
0134 fMaterial,
0135 "logicSphere",
0136 0,
0137 0,
0138 0);
0139 fPhysiSphere = new G4PVPlacement(0,
0140 G4ThreeVector(),
0141 "physiSphere",
0142 fLogicSphere,
0143 fExperimentalHall_phys,
0144 false,
0145 0);
0146
0147
0148 G4Sphere* solidScoringShell = new G4Sphere("solidScoringShell",
0149 fRadius,
0150
0151 fRadius + fScoringThickness,
0152 0.0,
0153
0154 2.0 * CLHEP::pi,
0155
0156 0.0,
0157
0158 CLHEP::pi);
0159
0160 fLogicScoringShell = new G4LogicalVolume(solidScoringShell,
0161 vacuum,
0162 "logicScoringShell",
0163 0,
0164 0,
0165 0);
0166 fPhysiScoringShell = new G4PVPlacement(0,
0167 G4ThreeVector(),
0168 "physiScoringShell",
0169 fLogicScoringShell,
0170 fExperimentalHall_phys,
0171 false,
0172 0);
0173
0174 G4cout << G4endl << "DetectorConstruction::ConstructSphere() : " << G4endl
0175 << "\t World (box) size: " << G4endl << "\t \t x : -/+ " << expHall_x << " mm ;"
0176 << "\t y : -/+ " << expHall_y << " mm ;"
0177 << "\t z : -/+ " << expHall_z << " mm ;" << G4endl << G4endl << G4endl;
0178
0179
0180
0181 return fExperimentalHall_phys;
0182 }
0183
0184
0185
0186 void DetectorConstruction::SetMaterial(const G4String name)
0187 {
0188 fMaterial = G4NistManager::Instance()->FindOrBuildMaterial(name);
0189 if (fMaterial == nullptr) {
0190 G4cout << G4endl << G4endl << "WARNING: the name of the material has not been recognized!"
0191 << G4endl << " ===> the default * G4_Fe * will be used." << G4endl << G4endl;
0192 fMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Fe");
0193 }
0194 if (fLogicSphere) fLogicSphere->SetMaterial(fMaterial);
0195
0196 }
0197
0198
0199
0200 void DetectorConstruction::UpdateGeometry()
0201 {
0202
0203 G4RunManager::GetRunManager()->ReinitializeGeometry();
0204 PrintParameters();
0205
0206 const PrimaryGeneratorAction* pPrimaryAction = dynamic_cast<const PrimaryGeneratorAction*>(
0207 G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
0208 if (pPrimaryAction) pPrimaryAction->SetGunPosition();
0209
0210 }
0211
0212
0213
0214 void DetectorConstruction::PrintParameters()
0215 {
0216 G4cout << G4endl << G4endl << " ------ DetectorConstruction::PrintParameters() ------ " << G4endl
0217 << " Material = " << fMaterial->GetName() << G4endl
0218 << " Radius = " << fRadius << " mm" << G4endl
0219 << " ScoringThickness = " << fScoringThickness << " mm" << G4endl
0220 << " -------------------------------------------------------- " << G4endl << G4endl;
0221 }
0222
0223