File indexing completed on 2026-03-30 07:50:39
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 "G4Colour.hh"
0034 #include "G4GeometryManager.hh"
0035 #include "G4LogicalVolume.hh"
0036 #include "G4LogicalVolumeStore.hh"
0037 #include "G4NistManager.hh"
0038 #include "G4PSEnergyDeposit.hh"
0039 #include "G4PVPlacement.hh"
0040 #include "G4PhysicalVolumeStore.hh"
0041 #include "G4ProductionCuts.hh"
0042 #include "G4RunManager.hh"
0043 #include "G4SolidStore.hh"
0044 #include "G4Sphere.hh"
0045 #include "G4SubtractionSolid.hh"
0046 #include "G4SystemOfUnits.hh"
0047 #include "G4Tubs.hh"
0048 #include "G4UnitsTable.hh"
0049 #include "G4UserLimits.hh"
0050 #include "G4VPhysicalVolume.hh"
0051 #include "G4VisAttributes.hh"
0052
0053
0054
0055 DetectorConstruction::DetectorConstruction()
0056 : G4VUserDetectorConstruction() {
0057 DefineMaterials();
0058 SetNPMaterial("G4_Au");
0059 SetAbsMaterial("G4_WATER");
0060
0061 fDetectorMessenger = std::make_unique<DetectorMessenger>(this);
0062 }
0063
0064
0065
0066 G4VPhysicalVolume *DetectorConstruction::Construct() {
0067 return ConstructVolumes();
0068 }
0069
0070
0071
0072 void DetectorConstruction::DefineMaterials() {
0073 G4NistManager *man = G4NistManager::Instance();
0074 man->FindOrBuildMaterial("G4_Au");
0075 man->FindOrBuildMaterial("G4_WATER");
0076 }
0077
0078
0079
0080 G4VPhysicalVolume *DetectorConstruction::ConstructVolumes() {
0081 constexpr G4bool check_overlap = false;
0082 G4GeometryManager::GetInstance()->OpenGeometry();
0083 G4PhysicalVolumeStore::GetInstance()->Clean();
0084 G4LogicalVolumeStore::GetInstance()->Clean();
0085 G4SolidStore::GetInstance()->Clean();
0086
0087
0088 const auto Vacuum =
0089 new G4Material("Galactic", 1., 1.01 * g / mole, CLHEP::universe_mean_density,
0090 kStateGas, 2.73 * kelvin, 3.e-18 * pascal);
0091
0092 const auto sWorld =
0093 new G4Sphere("World", 0., fAbsRadius*1.5, 0., 2*CLHEP::pi*rad, 0., CLHEP::pi);
0094 const auto lWorld = new G4LogicalVolume(sWorld, Vacuum, "World");
0095 pWorld = new G4PVPlacement(nullptr, G4ThreeVector(), lWorld,
0096 "World", 0, false, 0);
0097
0098
0099 const auto sNP =
0100 new G4Sphere("NanoParticle", 0., fNPRadius, 0., 2*CLHEP::pi*rad, 0., CLHEP::pi);
0101
0102 fLogicalNP = new G4LogicalVolume(sNP, fNPMaterial, "NanoParticle");
0103
0104 fNP = new G4PVPlacement(nullptr, G4ThreeVector(), fLogicalNP,
0105 "NanoParticle", lWorld, false, 0, check_overlap);
0106
0107
0108
0109
0110 const auto sAbsorber0 =
0111 new G4Sphere("Absorber0", 0., fAbsRadius*1.2, 0., 2*CLHEP::pi*rad, 0., CLHEP::pi);
0112 const auto sAbsorber =
0113 new G4SubtractionSolid("Absorber", sAbsorber0, sNP, 0, G4ThreeVector());
0114
0115 fLogicalAbs = new G4LogicalVolume(sAbsorber, fAbsMaterial, "Absorber");
0116 fAbs = new G4PVPlacement(nullptr, G4ThreeVector(), fLogicalAbs,
0117 "Absorber", lWorld, false, 0, check_overlap);
0118
0119
0120 const auto visWorld = new G4VisAttributes(true, G4Colour::Gray());
0121 const auto visNP = new G4VisAttributes(true, G4Colour::Yellow());
0122 const auto visAbs = new G4VisAttributes(true, G4Colour::Cyan());
0123
0124 lWorld->SetVisAttributes(visWorld);
0125 fLogicalNP->SetVisAttributes(visNP);
0126 fLogicalAbs->SetVisAttributes(visAbs);
0127
0128 PrintParameters();
0129
0130 G4double maxStep = fNPRadius / 2.;
0131 fLogicalNP->SetUserLimits(new G4UserLimits(maxStep, DBL_MAX, DBL_MAX, fTrackingCut));
0132
0133 fRegion = new G4Region("NP");
0134
0135 const auto cuts = new G4ProductionCuts();
0136 constexpr G4double defCut = 0.1 * nm;
0137 cuts->SetProductionCut(defCut, "gamma");
0138 cuts->SetProductionCut(defCut, "e-");
0139 cuts->SetProductionCut(defCut, "e+");
0140 cuts->SetProductionCut(defCut, "proton");
0141 fRegion->SetProductionCuts(cuts);
0142 fRegion->AddRootLogicalVolume(fLogicalNP);
0143
0144 return pWorld;
0145 }
0146
0147
0148
0149 void DetectorConstruction::PrintParameters() const {
0150 G4cout << "\n=========================================================\n";
0151 G4cout << "---> The tracking cut to all particles is set to "
0152 << G4BestUnit(fTrackingCut, "Energy") << G4endl;
0153 G4cout << "\n---------------------------------------------------------\n";
0154 G4cout << "---> The Nano-Particle is a sphere of "
0155 << G4BestUnit(fNPRadius, "Length")
0156 << " radius of " << fNPMaterial->GetName() << " made of"
0157 << "\n \n"
0158 << fNPMaterial << G4endl;
0159 G4cout << "\n---------------------------------------------------------\n";
0160 G4cout << "---> The Absorber is a sphere of "
0161 << G4BestUnit(fAbsRadius, "Length") << " radius of "
0162 << fAbsMaterial->GetName() << " made of"
0163 << "\n \n"
0164 << fAbsMaterial << G4endl;
0165 G4cout << "\n=========================================================\n";
0166 }
0167
0168
0169
0170 void DetectorConstruction::SetTrackingCut(G4double value) {
0171 fTrackingCut = value;
0172 G4RunManager::GetRunManager()->ReinitializeGeometry();
0173 }
0174
0175
0176
0177 void DetectorConstruction::SetAbsRadius(G4double value) {
0178 fAbsRadius = value;
0179 G4RunManager::GetRunManager()->ReinitializeGeometry();
0180 }
0181
0182 void DetectorConstruction::SetNPRadius(G4double value) {
0183 fNPRadius = value;
0184 G4RunManager::GetRunManager()->ReinitializeGeometry();
0185 }
0186
0187
0188
0189 void DetectorConstruction::SetAbsMaterial(const G4String& materialChoice) {
0190 G4Material *pttoMaterial = G4Material::GetMaterial(materialChoice);
0191 if (pttoMaterial) {
0192 fAbsMaterial = pttoMaterial;
0193 }
0194 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0195 }
0196
0197 void DetectorConstruction::SetNPMaterial(const G4String& materialChoice) {
0198 G4Material *pttoMaterial = G4Material::GetMaterial(materialChoice);
0199 if (pttoMaterial) {
0200 fNPMaterial = pttoMaterial;
0201 }
0202 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0203 }
0204
0205
0206
0207 void DetectorConstruction::SetNReplicaR(G4int value) {
0208 fNreplicaR = value;
0209 G4RunManager::GetRunManager()->ReinitializeGeometry();
0210 }
0211
0212 void DetectorConstruction::SetNReplicaAzm(G4int value) {
0213 fNreplicaAzm = value;
0214 G4RunManager::GetRunManager()->ReinitializeGeometry();
0215 }