File indexing completed on 2026-04-05 07:50:31
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 "ChemistryWorld.hh"
0032 #include "PeriodicBoundaryBuilder.hh"
0033 #include "Scorer.hh"
0034
0035 #include "G4Box.hh"
0036 #include "G4Electron_aq.hh"
0037 #include "G4LogicalVolume.hh"
0038 #include "G4MultiFunctionalDetector.hh"
0039 #include "G4NistManager.hh"
0040 #include "G4PVPlacement.hh"
0041 #include "G4SDManager.hh"
0042 #include "G4UnitsTable.hh"
0043 #include "G4VPrimitiveScorer.hh"
0044 #include "G4VisAttributes.hh"
0045
0046
0047
0048 DetectorConstruction::DetectorConstruction() : G4VUserDetectorConstruction()
0049 {
0050 fpChemistryWorld = std::make_unique<ChemistryWorld>();
0051 fpChemistryWorld->ConstructChemistryBoundary();
0052 DefineCommands();
0053 }
0054
0055
0056
0057 G4VPhysicalVolume* DetectorConstruction::Construct()
0058 {
0059 auto water = G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER");
0060 auto boudingBox = fpChemistryWorld->GetChemistryBoundary();
0061 G4double world_sizeXYZ = 2 * boudingBox->halfSideLengthInY();
0062
0063 G4cout << "Volume size : " << G4BestUnit(world_sizeXYZ, "Length") << G4endl;
0064
0065 G4double buffer;
0066 if (fPBC) {
0067 G4cout << "PeriodicBoundaryCondition is applied " << G4endl;
0068 buffer = 0.01 * nanometer;
0069 }
0070 else {
0071 buffer = 0;
0072 G4cout << "PeriodicBoundaryCondition is not applied " << G4endl;
0073 }
0074
0075 auto solidWorld = new G4Box("World", 0.5 * (world_sizeXYZ - buffer),
0076 0.5 * (world_sizeXYZ - buffer), 0.5 * (world_sizeXYZ - buffer));
0077
0078 auto logicWorld = new G4LogicalVolume(solidWorld, water, "World");
0079
0080 if (fPBC) {
0081 auto pbb = std::make_unique<PeriodicBoundaryBuilder>();
0082 fpPBCLogicVolume = pbb->Construct(logicWorld);
0083 }
0084
0085 fpPhysWorld = new G4PVPlacement(nullptr,
0086 G4ThreeVector(),
0087 logicWorld,
0088 "World",
0089 nullptr,
0090 false,
0091 0,
0092 true);
0093
0094 return fpPhysWorld;
0095 }
0096
0097
0098
0099 void DetectorConstruction::ConstructSDandField()
0100 {
0101 G4SDManager::GetSDMpointer()->SetVerboseLevel(1);
0102 auto mfDetector = new G4MultiFunctionalDetector("mfDetector");
0103
0104 G4VPrimitiveScorer* pDose = new Scorer<Dose>();
0105 dynamic_cast<Scorer<Dose>*>(pDose)->SetChemistryWorld(fpChemistryWorld.get());
0106 mfDetector->RegisterPrimitive(pDose);
0107 G4VPrimitiveScorer* gValues = new Scorer<Gvalues>();
0108 dynamic_cast<Scorer<Gvalues>*>(gValues)->SetChemistryWorld(fpChemistryWorld.get());
0109 mfDetector->RegisterPrimitive(gValues);
0110 G4SDManager::GetSDMpointer()->AddNewDetector(mfDetector);
0111 G4String SDName;
0112 if (fPBC) {
0113 SDName = fpPBCLogicVolume->GetName();
0114 }
0115 else {
0116 SDName = fpPhysWorld->GetName();
0117 }
0118 SetSensitiveDetector(SDName, mfDetector);
0119 }
0120
0121
0122
0123 void DetectorConstruction::DefineCommands()
0124 {
0125 fPBCMessenger =
0126 std::make_unique<G4GenericMessenger>(this, "/UHDR/Detector/", "Periodic Boundary Condition");
0127 auto& PBC = fPBCMessenger->DeclareProperty("PBC", fPBC);
0128 PBC.SetParameterName("PeriodicBoundaryCondition", true);
0129 PBC.SetDefaultValue("false");
0130 }
0131
0132