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