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