File indexing completed on 2026-05-03 07:44:16
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 "G4RunManager.hh"
0042 #include "G4SolidStore.hh"
0043 #include "G4SystemOfUnits.hh"
0044 #include "G4UniformMagField.hh"
0045 #include "G4UnitsTable.hh"
0046 #include "G4UserLimits.hh"
0047
0048
0049
0050 DetectorConstruction::DetectorConstruction()
0051 : G4VUserDetectorConstruction(),
0052 fP_Box(0),
0053 fL_Box(0),
0054 fBoxSize(500 * m),
0055 fMaterial(0),
0056 fMagField(0),
0057 fUserLimits(0),
0058 fDetectorMessenger(0)
0059 {
0060 DefineMaterials();
0061 SetMaterial("Iron");
0062
0063
0064 fUserLimits = new G4UserLimits();
0065
0066
0067 fDetectorMessenger = new DetectorMessenger(this);
0068 }
0069
0070
0071
0072 DetectorConstruction::~DetectorConstruction()
0073 {
0074 delete fDetectorMessenger;
0075 }
0076
0077
0078
0079 G4VPhysicalVolume* DetectorConstruction::Construct()
0080 {
0081 return ConstructVolumes();
0082 }
0083
0084
0085
0086 void DetectorConstruction::DefineMaterials()
0087 {
0088 G4double a, z, density;
0089
0090 new G4Material("Beryllium", z = 4., a = 9.012182 * g / mole, density = 1.848 * g / cm3);
0091 new G4Material("Carbon", z = 6., a = 12.011 * g / mole, density = 2.265 * g / cm3);
0092 new G4Material("Iron", z = 26., a = 55.85 * g / mole, density = 7.870 * g / cm3);
0093
0094 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0095 }
0096
0097
0098
0099 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
0100 {
0101 G4GeometryManager::GetInstance()->OpenGeometry();
0102 G4PhysicalVolumeStore::GetInstance()->Clean();
0103 G4LogicalVolumeStore::GetInstance()->Clean();
0104 G4SolidStore::GetInstance()->Clean();
0105
0106 G4Box* sBox = new G4Box("Container",
0107 fBoxSize / 2, fBoxSize / 2, fBoxSize / 2);
0108
0109 fL_Box = new G4LogicalVolume(sBox,
0110 fMaterial,
0111 fMaterial->GetName());
0112
0113 fL_Box->SetUserLimits(fUserLimits);
0114
0115 fP_Box = new G4PVPlacement(0,
0116 G4ThreeVector(),
0117 fL_Box,
0118 fMaterial->GetName(),
0119 0,
0120 false,
0121 0);
0122
0123 PrintParameters();
0124
0125
0126
0127
0128 return fP_Box;
0129 }
0130
0131
0132
0133 void DetectorConstruction::PrintParameters()
0134 {
0135 G4cout << "\n The Box is " << G4BestUnit(fBoxSize, "Length") << " of " << fMaterial->GetName()
0136 << G4endl;
0137 }
0138
0139
0140
0141 void DetectorConstruction::SetMaterial(const G4String& name)
0142 {
0143 G4cout << "###SetMaterial" << G4endl;
0144
0145
0146 G4Material* mat = G4Material::GetMaterial(name, false);
0147
0148
0149 if (!mat) {
0150 mat = G4NistManager::Instance()->FindOrBuildMaterial(name);
0151 }
0152
0153 if (mat && mat != fMaterial) {
0154 G4cout << "### New target material: " << mat->GetName() << G4endl;
0155 fMaterial = mat;
0156 if (fL_Box) {
0157 fL_Box->SetMaterial(mat);
0158 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0159 }
0160 }
0161 }
0162
0163
0164
0165 void DetectorConstruction::SetSize(G4double value)
0166 {
0167 fBoxSize = value;
0168 }
0169
0170
0171
0172 #include "G4FieldManager.hh"
0173 #include "G4TransportationManager.hh"
0174
0175 void DetectorConstruction::SetMagField(G4double fieldValue)
0176 {
0177
0178 G4FieldManager* fieldMgr = G4TransportationManager::GetTransportationManager()->GetFieldManager();
0179
0180 if (fMagField) delete fMagField;
0181
0182 if (fieldValue != 0.)
0183 {
0184 fMagField = new G4UniformMagField(G4ThreeVector(0., 0., fieldValue));
0185 fieldMgr->SetDetectorField(fMagField);
0186 fieldMgr->CreateChordFinder(fMagField);
0187 }
0188 else {
0189 fMagField = 0;
0190 fieldMgr->SetDetectorField(fMagField);
0191 }
0192 }
0193
0194
0195
0196 void DetectorConstruction::SetMaxStepSize(G4double val)
0197 {
0198
0199
0200 if (val <= DBL_MIN) {
0201 G4cout << "\n --->warning from SetMaxStepSize: maxStep " << val
0202 << " out of range. Command refused" << G4endl;
0203 return;
0204 }
0205 fUserLimits->SetMaxAllowedStep(val);
0206 }
0207
0208
0209
0210 #include "G4RunManager.hh"
0211
0212 void DetectorConstruction::UpdateGeometry()
0213 {
0214 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
0215 }
0216
0217