File indexing completed on 2026-09-11 08:29:36
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 "G4GDMLParser.hh"
0035 #include "G4GeometryManager.hh"
0036 #include "G4LogicalVolume.hh"
0037 #include "G4LogicalVolumeStore.hh"
0038 #include "G4Material.hh"
0039 #include "G4PVPlacement.hh"
0040 #include "G4PhysicalVolumeStore.hh"
0041 #include "G4PropagatorInField.hh"
0042 #include "G4RunManager.hh"
0043 #include "G4SolidStore.hh"
0044 #include "G4SystemOfUnits.hh"
0045 #include "G4TransportationManager.hh"
0046 #include "G4UnitsTable.hh"
0047 #include "G4UserLimits.hh"
0048
0049
0050
0051 DetectorConstruction::DetectorConstruction() : G4VUserDetectorConstruction(), fBoxSize(500 * m)
0052 {
0053 DefineMaterials();
0054 SetMaterial("Iron");
0055
0056
0057 fUserLimits = new G4UserLimits();
0058
0059
0060 fDetectorMessenger = new DetectorMessenger(this);
0061 }
0062
0063
0064
0065 G4VPhysicalVolume* DetectorConstruction::Construct()
0066 {
0067 return ConstructVolumes();
0068 }
0069
0070
0071
0072 void DetectorConstruction::DefineMaterials()
0073 {
0074 G4double a, z, density;
0075
0076 new G4Material("Beryllium", z = 4., a = 9.012182 * g / mole, density = 1.848 * g / cm3);
0077 new G4Material("Carbon", z = 6., a = 12.011 * g / mole, density = 2.265 * g / cm3);
0078 new G4Material("Iron", z = 26., a = 55.85 * g / mole, density = 7.870 * g / cm3);
0079
0080
0081 G4double const Torr = atmosphere / 760.;
0082 G4double pressure = 10e-9 * Torr,
0083 temperature = 296.150 * kelvin;
0084 new G4Material("Vacuum", z = 7., a = 14.01 * g / mole, density = 1.516784e-11 * kg / m3,
0085 kStateGas, temperature, pressure);
0086 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0087 }
0088
0089
0090
0091 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
0092 {
0093 G4GeometryManager::GetInstance()->OpenGeometry();
0094 G4PhysicalVolumeStore::GetInstance()->Clean();
0095 G4LogicalVolumeStore::GetInstance()->Clean();
0096 G4SolidStore::GetInstance()->Clean();
0097
0098 if (fGeomFileName == G4String()) {
0099 auto sBox = new G4Box("Container", fBoxSize / 2, fBoxSize / 2, fBoxSize / 2);
0100 fLBox = new G4LogicalVolume(sBox, fMaterial, fMaterial->GetName());
0101 fLBox->SetUserLimits(fUserLimits);
0102 fBox = new G4PVPlacement(0, G4ThreeVector(), fLBox, fMaterial->GetName(), 0, false, 0);
0103 PrintParameters();
0104 }
0105 else {
0106 G4GDMLParser parser;
0107 std::size_t nmat = G4Material::GetNumberOfMaterials();
0108 parser.Read(fGeomFileName.c_str());
0109 if (G4Material::GetNumberOfMaterials() > nmat) {
0110 const std::vector<G4Material*> MatPtrVec = *G4Material::GetMaterialTable();
0111 if (G4Material::GetNumberOfMaterials() > nmat)
0112 G4cout << "Materials defined by " << fGeomFileName << " :" << G4endl;
0113 for (std::size_t imat = nmat; imat < MatPtrVec.size(); ++imat)
0114 G4cout << MatPtrVec[imat] << G4endl;
0115 }
0116 fBox = parser.GetWorldVolume();
0117 }
0118 return fBox;
0119 }
0120
0121
0122
0123 void DetectorConstruction::PrintParameters()
0124 {
0125 G4cout << "\n The Box is " << G4BestUnit(fBoxSize, "Length") << " of " << fMaterial->GetName()
0126 << G4endl;
0127 }
0128
0129
0130
0131 void DetectorConstruction::SetMaterial(G4String materialChoice)
0132 {
0133
0134 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
0135 if (pttoMaterial) {
0136 fMaterial = pttoMaterial;
0137 if (fLBox) fLBox->SetMaterial(fMaterial);
0138 }
0139 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0140 }
0141
0142
0143
0144 void DetectorConstruction::SetSize(G4double value)
0145 {
0146 fBoxSize = value;
0147 G4RunManager::GetRunManager()->ReinitializeGeometry();
0148 }
0149
0150
0151
0152 #include "G4AutoDelete.hh"
0153 #include "G4GlobalMagFieldMessenger.hh"
0154
0155 void DetectorConstruction::ConstructSDandField()
0156 {
0157 if (fFieldMessenger.Get() == 0) {
0158
0159
0160
0161 G4ThreeVector fieldValue = G4ThreeVector();
0162 auto msg = new G4GlobalMagFieldMessenger(fieldValue);
0163
0164 G4AutoDelete::Register(msg);
0165 fFieldMessenger.Put(msg);
0166 }
0167 }
0168
0169
0170
0171 void DetectorConstruction::SetMaxStepSize(G4double val)
0172 {
0173
0174
0175 if (val <= DBL_MIN) {
0176 G4cout << "\n --->warning from SetMaxStepSize: maxStep " << val
0177 << " out of range. Command refused" << G4endl;
0178 return;
0179 }
0180 fUserLimits->SetMaxAllowedStep(val);
0181 }
0182
0183
0184
0185 void DetectorConstruction::SetMaxStepLength(G4double val)
0186 {
0187
0188
0189 if (val <= DBL_MIN) {
0190 G4cout << "\n --->warning from SetMaxStepLength: maxStep " << val
0191 << " out of range. Command refused" << G4endl;
0192 return;
0193 }
0194 G4TransportationManager* tmanager = G4TransportationManager::GetTransportationManager();
0195 tmanager->GetPropagatorInField()->SetLargestAcceptableStep(val);
0196 }
0197
0198 void DetectorConstruction::SetGeomFileName(G4String GeomFileName)
0199 {
0200 fGeomFileName = GeomFileName;
0201 }
0202
0203