File indexing completed on 2026-06-14 07:53:17
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 "G4MonopoleFieldSetup.hh"
0039 #include "G4NistManager.hh"
0040 #include "G4PVPlacement.hh"
0041 #include "G4PhysicalVolumeStore.hh"
0042 #include "G4SolidStore.hh"
0043 #include "G4StateManager.hh"
0044 #include "G4UniformMagField.hh"
0045 #include "G4UnitsTable.hh"
0046 #include "G4UserLimits.hh"
0047
0048
0049 #include "G4AutoDelete.hh"
0050 #include "G4GlobalMagFieldMessenger.hh"
0051 #include "G4RunManager.hh"
0052 #include "G4SystemOfUnits.hh"
0053 #include "G4ThreeVector.hh"
0054
0055
0056
0057 DetectorConstruction::DetectorConstruction()
0058 : G4VUserDetectorConstruction(),
0059 fWorldMaterial(0),
0060 fAbsorMaterial(0),
0061 fLogAbsor(0),
0062 fMonFieldSetup(),
0063 fDetectorMessenger(0)
0064 {
0065
0066 fAbsorSizeX = fAbsorSizeYZ = 10 * cm;
0067 fWorldSizeX = fWorldSizeYZ = 1.2 * fAbsorSizeX;
0068 fMaxStepSize = 5 * mm;
0069
0070 SetMaterial("G4_Al");
0071 fWorldMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
0072
0073
0074 fDetectorMessenger = new DetectorMessenger(this);
0075 }
0076
0077
0078
0079 DetectorConstruction::~DetectorConstruction()
0080 {
0081 delete fDetectorMessenger;
0082
0083 }
0084
0085
0086
0087 G4VPhysicalVolume* DetectorConstruction::Construct()
0088 {
0089 G4GeometryManager::GetInstance()->OpenGeometry();
0090 G4PhysicalVolumeStore::GetInstance()->Clean();
0091 G4LogicalVolumeStore::GetInstance()->Clean();
0092 G4SolidStore::GetInstance()->Clean();
0093
0094
0095 G4Box* sWorld = new G4Box("world", fWorldSizeX / 2, fWorldSizeYZ / 2, fWorldSizeYZ / 2);
0096
0097 G4LogicalVolume* lWorld = new G4LogicalVolume(sWorld, fWorldMaterial, "world");
0098
0099 G4VPhysicalVolume* pWorld = new G4PVPlacement(0,
0100 G4ThreeVector(),
0101 lWorld,
0102 "world",
0103 0,
0104 false,
0105 0);
0106
0107
0108 G4Box* sAbsor = new G4Box("Absorber", fAbsorSizeX / 2, fAbsorSizeYZ / 2, fAbsorSizeYZ / 2);
0109
0110 fLogAbsor = new G4LogicalVolume(sAbsor, fAbsorMaterial, "Absorber");
0111
0112 new G4PVPlacement(0,
0113 G4ThreeVector(),
0114 fLogAbsor,
0115 "Absorber",
0116 lWorld,
0117 false,
0118 0);
0119 fLogAbsor->SetUserLimits(new G4UserLimits(fMaxStepSize));
0120
0121 PrintParameters();
0122
0123
0124 return pWorld;
0125 }
0126
0127
0128
0129 void DetectorConstruction::PrintParameters()
0130 {
0131 G4cout << "\n---------------------------------------------------------\n";
0132 G4cout << "---> The Absorber is " << G4BestUnit(fAbsorSizeX, "Length") << " of "
0133 << fAbsorMaterial->GetName() << G4endl;
0134 G4cout << "\n---------------------------------------------------------\n";
0135 }
0136
0137
0138
0139 void DetectorConstruction::SetSizeX(G4double value)
0140 {
0141 if (value > 0.0) {
0142 fAbsorSizeX = value;
0143 fWorldSizeX = 1.2 * fAbsorSizeX;
0144 if (G4StateManager::GetStateManager()->GetCurrentState() != G4State_PreInit) {
0145 G4RunManager::GetRunManager()->ReinitializeGeometry();
0146 }
0147 }
0148 }
0149
0150
0151
0152 void DetectorConstruction::SetSizeYZ(G4double value)
0153 {
0154 if (value > 0.0) {
0155 fAbsorSizeYZ = value;
0156 fWorldSizeYZ = 1.2 * fAbsorSizeYZ;
0157 if (G4StateManager::GetStateManager()->GetCurrentState() != G4State_PreInit) {
0158 G4RunManager::GetRunManager()->ReinitializeGeometry();
0159 }
0160 }
0161 }
0162
0163
0164
0165 void DetectorConstruction::SetMaterial(const G4String& namemat)
0166 {
0167
0168 G4Material* mat = G4NistManager::Instance()->FindOrBuildMaterial(namemat);
0169 if (!mat) {
0170 G4cout << "!!! DetectorConstruction::SetMaterial: WARNING Material <" << namemat
0171 << "> does not exist in DB" << G4endl;
0172 return;
0173 }
0174
0175 if (mat != fAbsorMaterial) {
0176 fAbsorMaterial = mat;
0177 if (fLogAbsor) {
0178 fLogAbsor->SetMaterial(mat);
0179 }
0180 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0181 }
0182 }
0183
0184
0185
0186 void DetectorConstruction::ConstructSDandField()
0187 {
0188
0189 if (!fMonFieldSetup.Get()) {
0190 G4MonopoleFieldSetup* fieldSetup = new G4MonopoleFieldSetup();
0191 G4AutoDelete::Register(fieldSetup);
0192 fMonFieldSetup.Put(fieldSetup);
0193 }
0194 fMonFieldSetup.Get()->ConstructMagField();
0195 }
0196
0197
0198
0199 void DetectorConstruction::SetMaxStepSize(G4double step)
0200 {
0201 fMaxStepSize = step;
0202 if (fLogAbsor) {
0203 fLogAbsor->SetUserLimits(new G4UserLimits(fMaxStepSize));
0204 }
0205 }
0206
0207