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