File indexing completed on 2026-04-05 07:50:04
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
0035
0036
0037
0038
0039
0040 #include "DetectorConstruction.hh"
0041
0042 #include "DetectorMessenger.hh"
0043
0044 #include "G4Colour.hh"
0045 #include "G4GeometryManager.hh"
0046 #include "G4LogicalVolume.hh"
0047 #include "G4LogicalVolumeStore.hh"
0048 #include "G4NistManager.hh"
0049 #include "G4PVPlacement.hh"
0050 #include "G4PhysicalConstants.hh"
0051 #include "G4PhysicalVolumeStore.hh"
0052 #include "G4RunManager.hh"
0053 #include "G4SolidStore.hh"
0054 #include "G4SystemOfUnits.hh"
0055 #include "G4Tubs.hh"
0056 #include "G4UnitsTable.hh"
0057 #include "G4VisAttributes.hh"
0058 #include "G4ios.hh"
0059
0060
0061
0062 DetectorConstruction::DetectorConstruction()
0063 : G4VUserDetectorConstruction(),
0064 fTargetMaterial(nullptr),
0065 fWorldMaterial(nullptr),
0066 fSolidW(nullptr),
0067 fSolidA(nullptr),
0068 fLogicTarget(nullptr),
0069 fLogicWorld(nullptr),
0070 fPhysWorld(nullptr),
0071 fPhysList(nullptr)
0072 {
0073 fDetectorMessenger = new DetectorMessenger(this);
0074
0075 fRadius = 5. * cm;
0076 fLength = 10. * cm;
0077
0078 fTargetMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Al");
0079 fWorldMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
0080
0081 ComputeGeomParameters();
0082 }
0083
0084
0085
0086 DetectorConstruction::~DetectorConstruction()
0087 {
0088 delete fDetectorMessenger;
0089 }
0090
0091 void DetectorConstruction::ComputeGeomParameters()
0092 {
0093
0094 fWorldR = fRadius + CLHEP::cm;
0095 fWorldZ = fLength + CLHEP::cm;
0096 if (fPhysWorld) {
0097 fSolidW->SetOuterRadius(fWorldR);
0098 fSolidW->SetZHalfLength(fWorldZ * 0.5);
0099 fSolidA->SetOuterRadius(fRadius);
0100 fSolidA->SetZHalfLength(fLength * 0.5);
0101 }
0102 }
0103
0104 G4VPhysicalVolume* DetectorConstruction::Construct()
0105 {
0106 if (fPhysWorld) {
0107 return fPhysWorld;
0108 }
0109 ComputeGeomParameters();
0110
0111
0112
0113
0114 fSolidW = new G4Tubs("World", 0., fWorldR, 0.5 * fWorldZ, 0., twopi);
0115 fLogicWorld = new G4LogicalVolume(fSolidW, fWorldMaterial, "World");
0116 fPhysWorld =
0117 new G4PVPlacement(nullptr, G4ThreeVector(0., 0., 0.), fLogicWorld, "World", nullptr, false, 0);
0118
0119
0120
0121
0122 fSolidA = new G4Tubs("Target", 0., fRadius, 0.5 * fLength, 0., twopi);
0123 fLogicTarget = new G4LogicalVolume(fSolidA, fTargetMaterial, "Target");
0124 new G4PVPlacement(nullptr, G4ThreeVector(), fLogicTarget, "Target", fLogicWorld, false, 0);
0125
0126 G4cout << "### Target consist of " << fTargetMaterial->GetName()
0127 << " disks with R(mm)= " << fRadius / mm << " fLength(mm)= " << fLength / mm << " ###"
0128 << G4endl;
0129
0130
0131 fLogicWorld->SetVisAttributes(G4VisAttributes::GetInvisible());
0132
0133 G4VisAttributes* regCcolor = new G4VisAttributes(G4Colour(0., 0.3, 0.7));
0134 fLogicTarget->SetVisAttributes(regCcolor);
0135
0136 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0137
0138 return fPhysWorld;
0139 }
0140
0141
0142
0143 void DetectorConstruction::SetTargetMaterial(const G4String& mat)
0144 {
0145
0146 G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
0147
0148 if (material && material != fTargetMaterial) {
0149 fTargetMaterial = material;
0150 if (fLogicTarget) {
0151 fLogicTarget->SetMaterial(fTargetMaterial);
0152 }
0153 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0154 }
0155 }
0156
0157
0158
0159 void DetectorConstruction::SetWorldMaterial(const G4String& mat)
0160 {
0161
0162 G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
0163
0164 if (material && material != fWorldMaterial) {
0165 fWorldMaterial = material;
0166 if (fLogicWorld) {
0167 fLogicWorld->SetMaterial(fWorldMaterial);
0168 }
0169 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0170 }
0171 }
0172
0173 void DetectorConstruction::SetTargetRadius(G4double val)
0174 {
0175 if (val > 0.0 && val != fRadius) {
0176 fRadius = val;
0177 ComputeGeomParameters();
0178 }
0179 }
0180
0181
0182
0183 void DetectorConstruction::SetTargetLength(G4double val)
0184 {
0185 if (val > 0.0 && val != fLength) {
0186 fLength = val;
0187 ComputeGeomParameters();
0188 }
0189 }
0190
0191