File indexing completed on 2026-04-09 07:52:47
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 #include "DetectorConstruction.hh"
0030
0031 #include "DetectorMessenger.hh"
0032
0033 #include "G4Box.hh"
0034 #include "G4GeometryManager.hh"
0035 #include "G4LogicalVolume.hh"
0036 #include "G4LogicalVolumeStore.hh"
0037 #include "G4Material.hh"
0038 #include "G4NistManager.hh"
0039 #include "G4PVPlacement.hh"
0040 #include "G4PhysicalVolumeStore.hh"
0041 #include "G4PolarizationManager.hh"
0042 #include "G4RunManager.hh"
0043 #include "G4SolidStore.hh"
0044 #include "G4SystemOfUnits.hh"
0045 #include "G4UnitsTable.hh"
0046
0047
0048
0049 DetectorConstruction::DetectorConstruction()
0050 : G4VUserDetectorConstruction(), fWorld(0), fBox(0), fTargetMaterial(0), fWorldMaterial(0)
0051 {
0052 fBoxSizeXY = 50 * mm;
0053 fBoxSizeZ = 5 * mm;
0054 fWorldSize = 1. * m;
0055 ConstructMaterials();
0056 fMessenger = new DetectorMessenger(this);
0057 }
0058
0059
0060
0061 DetectorConstruction::~DetectorConstruction()
0062 {
0063 delete fMessenger;
0064 }
0065
0066
0067 void DetectorConstruction::ConstructMaterials()
0068 {
0069 auto nistManager = G4NistManager::Instance();
0070
0071 fTargetMaterial = nistManager->FindOrBuildMaterial("G4_Fe");
0072 if (fTargetMaterial == nullptr) {
0073 G4cerr << "### ERROR - Material: <"
0074 << "G4_Fe"
0075 << "> not found" << G4endl;
0076 }
0077
0078 fWorldMaterial = nistManager->FindOrBuildMaterial("G4_Galactic");
0079 if (fWorldMaterial == nullptr) {
0080 G4cerr << "### ERROR - Material: <"
0081 << "G4_Galactic"
0082 << "> not found" << G4endl;
0083 }
0084 }
0085
0086
0087
0088 G4LogicalVolume* lBox;
0089
0090 G4VPhysicalVolume* DetectorConstruction::Construct()
0091 {
0092
0093
0094
0095
0096 G4Box* sWorld = new G4Box("World",
0097 fWorldSize / 2, fWorldSize / 2, fWorldSize / 2);
0098
0099 G4LogicalVolume* lWorld = new G4LogicalVolume(sWorld,
0100 fWorldMaterial,
0101 "World");
0102
0103 fWorld = new G4PVPlacement(0,
0104 G4ThreeVector(),
0105 lWorld,
0106 "World",
0107 0,
0108 false,
0109 0);
0110
0111
0112
0113 G4Box* sBox = new G4Box("Container",
0114 fBoxSizeXY / 2., fBoxSizeXY / 2., fBoxSizeZ / 2.);
0115
0116
0117 lBox = new G4LogicalVolume(sBox,
0118 fTargetMaterial,
0119 "theBox");
0120
0121 fBox = new G4PVPlacement(0,
0122 G4ThreeVector(),
0123 lBox,
0124 fTargetMaterial->GetName(),
0125 lWorld,
0126 false,
0127 0);
0128
0129 PrintParameters();
0130
0131
0132
0133 return fWorld;
0134 }
0135
0136
0137
0138 void DetectorConstruction::ConstructSDandField()
0139 {
0140
0141 G4PolarizationManager* polMgr = G4PolarizationManager::GetInstance();
0142 polMgr->SetVolumePolarization(lBox, G4ThreeVector(0., 0., 0.));
0143 }
0144
0145
0146
0147 void DetectorConstruction::PrintParameters()
0148 {
0149 G4cout << "\n The Box is " << G4BestUnit(fBoxSizeXY, "Length") << " x "
0150 << G4BestUnit(fBoxSizeXY, "Length") << " x " << G4BestUnit(fBoxSizeZ, "Length") << " of "
0151 << fTargetMaterial->GetName() << G4endl;
0152 }
0153
0154
0155
0156 void DetectorConstruction::SetTargetMaterial(G4String materialChoice)
0157 {
0158
0159 G4Material* mat = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0160 if (mat != fTargetMaterial) {
0161 if (mat) {
0162 fTargetMaterial = mat;
0163 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0164 UpdateGeometry();
0165 }
0166 else {
0167 G4cout << "### Warning! Target material: <" << materialChoice << "> not found" << G4endl;
0168 }
0169 }
0170 }
0171
0172
0173
0174 void DetectorConstruction::SetWorldMaterial(G4String materialChoice)
0175 {
0176
0177 G4Material* mat = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0178 if (mat != fWorldMaterial) {
0179 if (mat) {
0180 fWorldMaterial = mat;
0181 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0182 UpdateGeometry();
0183 }
0184 else {
0185 G4cout << "### Warning! World material: <" << materialChoice << "> not found" << G4endl;
0186 }
0187 }
0188 }
0189
0190
0191
0192 void DetectorConstruction::SetSizeXY(G4double value)
0193 {
0194 fBoxSizeXY = value;
0195 if (fWorldSize < fBoxSizeXY) fWorldSize = 1.2 * fBoxSizeXY;
0196 UpdateGeometry();
0197 }
0198
0199 void DetectorConstruction::SetSizeZ(G4double value)
0200 {
0201 fBoxSizeZ = value;
0202 if (fWorldSize < fBoxSizeZ) fWorldSize = 1.2 * fBoxSizeZ;
0203 UpdateGeometry();
0204 }
0205
0206
0207
0208 #include "G4RunManager.hh"
0209
0210 void DetectorConstruction::UpdateGeometry()
0211 {
0212
0213
0214 G4RunManager::GetRunManager()->GeometryHasBeenModified();
0215 }
0216
0217