File indexing completed on 2025-12-16 09:30: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
0030
0031
0032
0033 #include "DetectorConstruction.hh"
0034
0035 #include "DetectorMessenger.hh"
0036
0037 #include "G4GeometryManager.hh"
0038 #include "G4LogicalVolume.hh"
0039 #include "G4LogicalVolumeStore.hh"
0040 #include "G4NistManager.hh"
0041 #include "G4PVPlacement.hh"
0042 #include "G4PVReplica.hh"
0043 #include "G4PhysicalConstants.hh"
0044 #include "G4PhysicalVolumeStore.hh"
0045 #include "G4RunManager.hh"
0046 #include "G4SolidStore.hh"
0047 #include "G4Sphere.hh"
0048 #include "G4SystemOfUnits.hh"
0049 #include "G4UnitsTable.hh"
0050 #include "G4VPhysicalVolume.hh"
0051
0052
0053
0054 DetectorConstruction::DetectorConstruction()
0055 {
0056
0057 fAbsorRadius = 3 * cm;
0058 fNbOfLayers = 1;
0059
0060 DefineMaterials();
0061 SetMaterial("G4_WATER");
0062
0063
0064 fDetectorMessenger = new DetectorMessenger(this);
0065 }
0066
0067
0068
0069 DetectorConstruction::~DetectorConstruction()
0070 {
0071 delete fDetectorMessenger;
0072 }
0073
0074
0075
0076 void DetectorConstruction::DefineMaterials()
0077 {
0078 G4NistManager* man = G4NistManager::Instance();
0079
0080 man->FindOrBuildMaterial("G4_Al");
0081 man->FindOrBuildMaterial("G4_Si");
0082 man->FindOrBuildMaterial("G4_Fe");
0083 man->FindOrBuildMaterial("G4_Ge");
0084 man->FindOrBuildMaterial("G4_Gd");
0085 man->FindOrBuildMaterial("G4_W");
0086 man->FindOrBuildMaterial("G4_Pb");
0087
0088 man->FindOrBuildMaterial("G4_AIR");
0089 man->FindOrBuildMaterial("G4_WATER");
0090 man->FindOrBuildMaterial("G4_ALUMINUM_OXIDE");
0091
0092
0093 }
0094
0095
0096
0097 G4VPhysicalVolume* DetectorConstruction::Construct()
0098 {
0099
0100
0101 G4Sphere* sAbsor = new G4Sphere("Absorber",
0102 0., fAbsorRadius, 0., twopi, 0., pi);
0103
0104 fSpheres.push_back(sAbsor);
0105
0106 G4LogicalVolume* lAbsor = new G4LogicalVolume(sAbsor,
0107 fAbsorMaterial,
0108 "Absorber");
0109 fLVolumes.push_back(lAbsor);
0110
0111 fAbsor = new G4PVPlacement(0,
0112 G4ThreeVector(),
0113 lAbsor,
0114 "Absorber",
0115 0,
0116 false,
0117 0);
0118
0119
0120
0121 fLayerThickness = fAbsorRadius / fNbOfLayers;
0122
0123 for (G4int i = 1; i <= fNbOfLayers; i++) {
0124 G4Sphere* sLayer =
0125 new G4Sphere("Layer", (i - 1) * fLayerThickness, i * fLayerThickness, 0., twopi, 0., pi);
0126
0127 fSpheres.push_back(sLayer);
0128
0129 G4LogicalVolume* lLayer = new G4LogicalVolume(sLayer,
0130 fAbsorMaterial,
0131 "Layer");
0132 fLVolumes.push_back(lLayer);
0133
0134 new G4PVPlacement(0,
0135 G4ThreeVector(),
0136 lLayer,
0137 "Layer",
0138 lAbsor,
0139 false,
0140 i);
0141 }
0142
0143 PrintParameters();
0144
0145
0146
0147
0148 return fAbsor;
0149 }
0150
0151
0152
0153 void DetectorConstruction::PrintParameters()
0154 {
0155 G4cout << "\n---------------------------------------------------------\n";
0156 G4cout << "---> The Absorber is a sphere of " << G4BestUnit(fAbsorRadius, "Length")
0157 << " radius of " << fAbsorMaterial->GetName() << " divided in " << fNbOfLayers
0158 << " slices of " << G4BestUnit(fLayerThickness, "Length") << "\n \n"
0159 << fAbsorMaterial << G4endl;
0160 G4cout << "\n---------------------------------------------------------\n";
0161 }
0162
0163
0164
0165 void DetectorConstruction::SetRadius(G4double value)
0166 {
0167
0168 if (fAbsor) {
0169 G4double scale = value / fAbsorRadius;
0170 for (auto solid : fSpheres) {
0171 if (scale > 1.0) {
0172 solid->SetOuterRadius(solid->GetOuterRadius() * scale);
0173 solid->SetInnerRadius(solid->GetInnerRadius() * scale);
0174 }
0175 else {
0176 solid->SetInnerRadius(solid->GetInnerRadius() * scale);
0177 solid->SetOuterRadius(solid->GetOuterRadius() * scale);
0178 }
0179 }
0180 }
0181 fAbsorRadius = value;
0182 }
0183
0184
0185
0186 void DetectorConstruction::SetMaterial(G4String materialChoice)
0187 {
0188
0189 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
0190
0191 if (pttoMaterial && pttoMaterial != fAbsorMaterial) {
0192 fAbsorMaterial = pttoMaterial;
0193 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0194
0195
0196 if (fAbsor) {
0197 for (auto lv : fLVolumes) {
0198 lv->SetMaterial(fAbsorMaterial);
0199 }
0200 }
0201 }
0202 }
0203
0204
0205
0206 void DetectorConstruction::SetNbOfLayers(G4int value)
0207 {
0208 fNbOfLayers = value;
0209 }
0210
0211