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