File indexing completed on 2026-09-16 08:29:51
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 "PrimaryGeneratorAction.hh"
0033
0034 #include "G4Box.hh"
0035 #include "G4FieldManager.hh"
0036 #include "G4GeometryManager.hh"
0037 #include "G4LogicalVolume.hh"
0038 #include "G4LogicalVolumeStore.hh"
0039 #include "G4Material.hh"
0040 #include "G4NistManager.hh"
0041 #include "G4PVPlacement.hh"
0042 #include "G4PhysicalConstants.hh"
0043 #include "G4PhysicalVolumeStore.hh"
0044 #include "G4RunManager.hh"
0045 #include "G4SolidStore.hh"
0046 #include "G4SystemOfUnits.hh"
0047 #include "G4ThreeVector.hh"
0048 #include "G4TransportationManager.hh"
0049 #include "G4Tubs.hh"
0050 #include "G4UniformMagField.hh"
0051 #include "globals.hh"
0052
0053
0054
0055 DetectorConstruction::DetectorConstruction()
0056 : G4VUserDetectorConstruction(),
0057 fTargetMaterial(nullptr),
0058 fLogicExperimentalHall(nullptr),
0059 fPhysExperimentalHall(nullptr),
0060 fLogicTargetLayer(nullptr),
0061 fPhysTargetLayer(nullptr),
0062 fFieldMgr(nullptr),
0063 fUniformMagField(nullptr),
0064 fDetectorMessenger(nullptr),
0065 fTargetInnerRadius(9.0 * mm),
0066 fTargetOuterRadius(11.0 * mm)
0067 {
0068 fFieldMgr = G4TransportationManager::GetTransportationManager()->GetFieldManager();
0069
0070 fTargetMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Be");
0071 fDetectorMessenger = new DetectorMessenger(this);
0072 }
0073
0074
0075
0076 DetectorConstruction::~DetectorConstruction()
0077 {
0078 delete fUniformMagField;
0079 delete fDetectorMessenger;
0080 }
0081
0082
0083
0084 G4VPhysicalVolume* DetectorConstruction::Construct()
0085 {
0086 return ConstructLayer();
0087 }
0088
0089
0090
0091 G4VPhysicalVolume* DetectorConstruction::ConstructLayer()
0092 {
0093
0094 G4GeometryManager::GetInstance()->OpenGeometry();
0095 G4PhysicalVolumeStore::GetInstance()->Clean();
0096 G4LogicalVolumeStore::GetInstance()->Clean();
0097 G4SolidStore::GetInstance()->Clean();
0098
0099
0100
0101
0102
0103 const G4double halfLength = 1.0 * m;
0104 const G4double expHall_x = 1.01 * halfLength;
0105 const G4double expHall_y = 1.01 * halfLength;
0106 const G4double expHall_z = 1.01 * halfLength;
0107 G4Material* vacuum = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
0108 G4Box* experimentalHallBox = new G4Box("expHallBox", expHall_x, expHall_y, expHall_z);
0109 fLogicExperimentalHall = new G4LogicalVolume(experimentalHallBox,
0110 vacuum,
0111 "logicExpHall",
0112 0,
0113 0,
0114 0);
0115 fPhysExperimentalHall = new G4PVPlacement(0,
0116 G4ThreeVector(),
0117 "expHall",
0118 fLogicExperimentalHall,
0119 0,
0120 false,
0121 0);
0122
0123 G4Tubs* solidTargetLayer = new G4Tubs("solidTargetLayer",
0124 fTargetInnerRadius,
0125 fTargetOuterRadius,
0126 halfLength,
0127 0.0,
0128 2.0 * pi);
0129 fLogicTargetLayer = new G4LogicalVolume(solidTargetLayer,
0130 fTargetMaterial,
0131 "logicTargetLayer",
0132 0,
0133 0,
0134 0);
0135 fPhysTargetLayer = new G4PVPlacement(0,
0136 G4ThreeVector(),
0137 "physTargetLayer",
0138 fLogicTargetLayer,
0139 fPhysExperimentalHall,
0140 false,
0141 0);
0142 PrintParameters();
0143 G4cout << G4endl << "DetectorConstruction::ConstructLayer() : " << G4endl
0144 << "\t World (box) size: " << G4endl << "\t \t x : -/+ " << expHall_x << " mm ;"
0145 << "\t y : -/+ " << expHall_y << " mm ;"
0146 << "\t z : -/+ " << expHall_z << " mm ;" << G4endl
0147 << "\t Layer (cylinder) size : " << G4endl << "\t \t radii : " << fTargetInnerRadius
0148 << " , " << fTargetOuterRadius << " mm ;"
0149 << "\t \t length (along z) : " << 2.0 * halfLength << " mm ;" << G4endl << G4endl
0150 << G4endl;
0151 return fPhysExperimentalHall;
0152 }
0153
0154
0155
0156 void DetectorConstruction::SetTargetMaterial(const G4String name)
0157 {
0158 fTargetMaterial = G4NistManager::Instance()->FindOrBuildMaterial(name);
0159 if (!fTargetMaterial) {
0160 G4cout << G4endl << G4endl << "WARNING: the name of the material has not been recognized!"
0161 << G4endl << " ===> the default * G4_Be * will be used." << G4endl << G4endl;
0162
0163 fTargetMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Be");
0164 }
0165 if (fLogicTargetLayer) fLogicTargetLayer->SetMaterial(fTargetMaterial);
0166 }
0167
0168
0169
0170 void DetectorConstruction::UpdateGeometry()
0171 {
0172 G4RunManager::GetRunManager()->ReinitializeGeometry();
0173 PrintParameters();
0174
0175 const PrimaryGeneratorAction* pPrimaryAction = dynamic_cast<const PrimaryGeneratorAction*>(
0176 G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
0177 if (pPrimaryAction) pPrimaryAction->SetGunPosition();
0178 }
0179
0180
0181
0182 void DetectorConstruction::PrintParameters()
0183 {
0184 G4cout << G4endl << G4endl << " ------ DetectorConstruction::PrintParameters() ------ " << G4endl
0185 << " Material = " << fTargetMaterial->GetName() << G4endl
0186 << " Target Inner Radius = " << fTargetInnerRadius << " mm" << G4endl
0187 << " Target Outer Radius = " << fTargetOuterRadius << " mm" << G4endl
0188 << " B [T] = "
0189 << (fUniformMagField ? fUniformMagField->GetConstantFieldValue() / CLHEP::tesla
0190 : G4ThreeVector(0.0, 0.0, 0.0))
0191 << G4endl << " ------------------------------------------------------ " << G4endl
0192 << G4endl;
0193 }
0194
0195
0196
0197 void DetectorConstruction::SetMagField(const G4double fieldValue)
0198 {
0199 if (fUniformMagField) delete fUniformMagField;
0200 if (std::abs(fieldValue) > 0.0) {
0201
0202 fUniformMagField = new G4UniformMagField(G4ThreeVector(0.0, 0.0, fieldValue));
0203 fFieldMgr->SetDetectorField(fUniformMagField);
0204 fFieldMgr->CreateChordFinder(fUniformMagField);
0205 }
0206 }
0207
0208