File indexing completed on 2026-04-19 07:54:22
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
0033 #include "G4Box.hh"
0034 #include "G4Element.hh"
0035 #include "G4LogicalBorderSurface.hh"
0036 #include "G4LogicalSkinSurface.hh"
0037 #include "G4LogicalVolume.hh"
0038 #include "G4Material.hh"
0039 #include "G4NistManager.hh"
0040 #include "G4OpticalSurface.hh"
0041 #include "G4PVPlacement.hh"
0042 #include "G4SystemOfUnits.hh"
0043 #include "G4ThreeVector.hh"
0044
0045
0046
0047 DetectorConstruction::DetectorConstruction()
0048 : G4VUserDetectorConstruction(), fDetectorMessenger(nullptr)
0049 {
0050 fTankMPT = new G4MaterialPropertiesTable();
0051 fWorldMPT = new G4MaterialPropertiesTable();
0052 fSurfaceMPT = new G4MaterialPropertiesTable();
0053
0054 fSurface = new G4OpticalSurface("Surface");
0055 fSurface->SetType(dielectric_dielectric);
0056 fSurface->SetFinish(ground);
0057 fSurface->SetModel(unified);
0058 fSurface->SetMaterialPropertiesTable(fSurfaceMPT);
0059
0060 fTankMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER");
0061 fWorldMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_AIR");
0062
0063 fDetectorMessenger = new DetectorMessenger(this);
0064 }
0065
0066
0067
0068 DetectorConstruction::~DetectorConstruction()
0069 {
0070 delete fTankMPT;
0071 delete fWorldMPT;
0072 delete fSurfaceMPT;
0073 delete fSurface;
0074 delete fDetectorMessenger;
0075 }
0076
0077
0078
0079 G4VPhysicalVolume* DetectorConstruction::Construct()
0080 {
0081 fTankMaterial->SetMaterialPropertiesTable(fTankMPT);
0082 fTankMaterial->GetIonisation()->SetBirksConstant(0.126 * mm / MeV);
0083
0084 fWorldMaterial->SetMaterialPropertiesTable(fWorldMPT);
0085
0086
0087
0088 auto world_box = new G4Box("World", fExpHall_x, fExpHall_y, fExpHall_z);
0089
0090 fWorld_LV = new G4LogicalVolume(world_box, fWorldMaterial, "World");
0091
0092 G4VPhysicalVolume* world_PV =
0093 new G4PVPlacement(nullptr, G4ThreeVector(), fWorld_LV, "World", nullptr, false, 0);
0094
0095
0096 auto tank_box = new G4Box("Tank", fTank_x, fTank_y, fTank_z);
0097
0098 fTank_LV = new G4LogicalVolume(tank_box, fTankMaterial, "Tank");
0099
0100 fTank = new G4PVPlacement(nullptr, G4ThreeVector(), fTank_LV, "Tank", fWorld_LV, false, 0);
0101
0102
0103
0104 auto surface = new G4LogicalBorderSurface("Surface", fTank, world_PV, fSurface);
0105
0106 auto opticalSurface =
0107 dynamic_cast<G4OpticalSurface*>(surface->GetSurface(fTank, world_PV)->GetSurfaceProperty());
0108 G4cout << "****** opticalSurface->DumpInfo:" << G4endl;
0109 if (opticalSurface) {
0110 opticalSurface->DumpInfo();
0111 }
0112 G4cout << "****** end of opticalSurface->DumpInfo" << G4endl;
0113
0114 return world_PV;
0115 }
0116
0117
0118 void DetectorConstruction::SetSurfaceSigmaAlpha(G4double v)
0119 {
0120 fSurface->SetSigmaAlpha(v);
0121 G4RunManager::GetRunManager()->GeometryHasBeenModified();
0122
0123 G4cout << "Surface sigma alpha set to: " << fSurface->GetSigmaAlpha() << G4endl;
0124 }
0125
0126
0127 void DetectorConstruction::SetSurfacePolish(G4double v)
0128 {
0129 fSurface->SetPolish(v);
0130 G4RunManager::GetRunManager()->GeometryHasBeenModified();
0131
0132 G4cout << "Surface polish set to: " << fSurface->GetPolish() << G4endl;
0133 }
0134
0135
0136 void DetectorConstruction::AddTankMPV(const G4String& prop, G4MaterialPropertyVector* mpv)
0137 {
0138 fTankMPT->AddProperty(prop, mpv);
0139 G4cout << "The MPT for the box is now: " << G4endl;
0140 fTankMPT->DumpTable();
0141 G4cout << "............." << G4endl;
0142 }
0143
0144
0145 void DetectorConstruction::AddWorldMPV(const G4String& prop, G4MaterialPropertyVector* mpv)
0146 {
0147 fWorldMPT->AddProperty(prop, mpv);
0148 G4cout << "The MPT for the world is now: " << G4endl;
0149 fWorldMPT->DumpTable();
0150 G4cout << "............." << G4endl;
0151 }
0152
0153
0154 void DetectorConstruction::AddSurfaceMPV(const G4String& prop, G4MaterialPropertyVector* mpv)
0155 {
0156 fSurfaceMPT->AddProperty(prop, mpv);
0157 G4cout << "The MPT for the surface is now: " << G4endl;
0158 fSurfaceMPT->DumpTable();
0159 G4cout << "............." << G4endl;
0160 }
0161
0162
0163 void DetectorConstruction::AddTankMPC(const G4String& prop, G4double v)
0164 {
0165 fTankMPT->AddConstProperty(prop, v);
0166 G4cout << "The MPT for the box is now: " << G4endl;
0167 fTankMPT->DumpTable();
0168 G4cout << "............." << G4endl;
0169 }
0170
0171
0172 void DetectorConstruction::AddWorldMPC(const G4String& prop, G4double v)
0173 {
0174 fWorldMPT->AddConstProperty(prop, v);
0175 G4cout << "The MPT for the world is now: " << G4endl;
0176 fWorldMPT->DumpTable();
0177 G4cout << "............." << G4endl;
0178 }
0179
0180 void DetectorConstruction::AddSurfaceMPC(const G4String& prop, G4double v)
0181 {
0182 fSurfaceMPT->AddConstProperty(prop, v);
0183 G4cout << "The MPT for the surface is now: " << G4endl;
0184 fSurfaceMPT->DumpTable();
0185 G4cout << "............." << G4endl;
0186 }
0187
0188
0189 void DetectorConstruction::SetWorldMaterial(const G4String& mat)
0190 {
0191 G4Material* pmat = G4NistManager::Instance()->FindOrBuildMaterial(mat);
0192 if (pmat && fWorldMaterial != pmat) {
0193 fWorldMaterial = pmat;
0194 if (fWorld_LV) {
0195 fWorld_LV->SetMaterial(fWorldMaterial);
0196 fWorldMaterial->SetMaterialPropertiesTable(fWorldMPT);
0197 }
0198 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0199 G4cout << "World material set to " << fWorldMaterial->GetName() << G4endl;
0200 }
0201 }
0202
0203
0204 void DetectorConstruction::SetTankMaterial(const G4String& mat)
0205 {
0206 G4Material* pmat = G4NistManager::Instance()->FindOrBuildMaterial(mat);
0207 if (pmat && fTankMaterial != pmat) {
0208 fTankMaterial = pmat;
0209 if (fTank_LV) {
0210 fTank_LV->SetMaterial(fTankMaterial);
0211 fTankMaterial->SetMaterialPropertiesTable(fTankMPT);
0212 fTankMaterial->GetIonisation()->SetBirksConstant(0.126 * mm / MeV);
0213 }
0214 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0215 G4cout << "Tank material set to " << fTankMaterial->GetName() << G4endl;
0216 }
0217 }