File indexing completed on 2025-02-23 09:21:11
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 #include "TargetSD.hh"
0037
0038 #include "G4Box.hh"
0039 #include "G4FieldManager.hh"
0040 #include "G4GeometryManager.hh"
0041 #include "G4LogicalVolume.hh"
0042 #include "G4Material.hh"
0043 #include "G4NistManager.hh"
0044 #include "G4PVPlacement.hh"
0045 #include "G4RunManager.hh"
0046 #include "G4SDManager.hh"
0047 #include "G4SystemOfUnits.hh"
0048 #include "G4ThreeVector.hh"
0049 #include "G4UnitsTable.hh"
0050
0051
0052
0053 DetectorConstruction::DetectorConstruction()
0054 : G4VUserDetectorConstruction(), fAbsorMaterial(nullptr), fLogAbsor(nullptr), fWorld(nullptr)
0055 {
0056
0057 fAbsorSizeZ = fAbsorSizeXY = 10 * cm;
0058 fWorldSizeZ = fWorldSizeXY = 1.2 * fAbsorSizeZ;
0059
0060 SetMaterial("G4_Al");
0061 fWorldMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
0062
0063
0064 fDetectorMessenger = new DetectorMessenger(this);
0065 }
0066
0067
0068
0069 DetectorConstruction::~DetectorConstruction()
0070 {
0071 delete fDetectorMessenger;
0072 }
0073
0074
0075
0076 G4VPhysicalVolume* DetectorConstruction::Construct()
0077 {
0078 if (fWorld) {
0079 return fWorld;
0080 }
0081
0082
0083 G4Box* sWorld = new G4Box("world", fWorldSizeXY / 2, fWorldSizeXY / 2, fWorldSizeZ / 2);
0084
0085 G4LogicalVolume* lWorld = new G4LogicalVolume(sWorld, fWorldMaterial, "world");
0086
0087 fWorld = new G4PVPlacement(0,
0088 G4ThreeVector(),
0089 lWorld,
0090 "world",
0091 0,
0092 false,
0093 0);
0094
0095
0096
0097 G4Box* sAbsor = new G4Box("Absorber", fAbsorSizeXY / 2, fAbsorSizeXY / 2, fAbsorSizeZ / 2);
0098
0099 fLogAbsor = new G4LogicalVolume(sAbsor, fAbsorMaterial, "Absorber");
0100
0101 new G4PVPlacement(0,
0102 G4ThreeVector(),
0103 fLogAbsor,
0104 "Absorber",
0105 lWorld,
0106 false,
0107 0);
0108
0109 PrintParameters();
0110
0111
0112 return fWorld;
0113 }
0114
0115
0116
0117 void DetectorConstruction::PrintParameters()
0118 {
0119 G4cout << "\n---------------------------------------------------------\n";
0120 G4cout << "---> The Absorber is " << G4BestUnit(fAbsorSizeZ, "Length") << " of "
0121 << fAbsorMaterial->GetName() << G4endl;
0122 G4cout << "\n---------------------------------------------------------\n";
0123 }
0124
0125
0126
0127 void DetectorConstruction::SetSizeZ(G4double value)
0128 {
0129 if (value > 0.0) {
0130 fAbsorSizeZ = value;
0131 fWorldSizeZ = 1.2 * fAbsorSizeZ;
0132 }
0133 }
0134
0135
0136
0137 void DetectorConstruction::SetSizeXY(G4double value)
0138 {
0139 if (value > 0.0) {
0140 fAbsorSizeXY = value;
0141 fWorldSizeXY = 1.2 * fAbsorSizeXY;
0142 }
0143 }
0144
0145
0146
0147 void DetectorConstruction::SetMaterial(const G4String& namemat)
0148 {
0149
0150
0151 G4Material* mat = G4NistManager::Instance()->FindOrBuildMaterial(namemat);
0152 if (!mat) {
0153 G4cout << "!!! DetectorConstruction::SetMaterial: WARNING Material <" << namemat
0154 << "> does not exist in DB" << G4endl;
0155 return;
0156 }
0157
0158 if (mat != fAbsorMaterial) {
0159 fAbsorMaterial = mat;
0160 if (fLogAbsor) {
0161 fLogAbsor->SetMaterial(mat);
0162 }
0163 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0164 }
0165 }
0166
0167
0168
0169 void DetectorConstruction::ConstructSDandField()
0170 {
0171 auto sd = new TargetSD("Target");
0172 G4SDManager::GetSDMpointer()->AddNewDetector(sd);
0173 SetSensitiveDetector(fLogAbsor, sd);
0174 }
0175
0176