File indexing completed on 2025-02-23 09:22:19
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 #include "DetectorConstruction.hh"
0031
0032 #include "G4Box.hh"
0033 #include "G4GeometryManager.hh"
0034 #include "G4LogicalVolume.hh"
0035 #include "G4LogicalVolumeStore.hh"
0036 #include "G4Material.hh"
0037 #include "G4NistManager.hh"
0038 #include "G4PVPlacement.hh"
0039 #include "G4PhysicalVolumeStore.hh"
0040 #include "G4RunManager.hh"
0041 #include "G4SolidStore.hh"
0042 #include "G4SystemOfUnits.hh"
0043 #include "G4UnitsTable.hh"
0044
0045 #include "DetectorMessenger.hh"
0046 #include "VoxelizedSensitiveDetector.hh"
0047
0048 #include <sstream>
0049
0050 namespace RadioBio
0051 {
0052
0053
0054
0055 DetectorConstruction::DetectorConstruction()
0056 {
0057
0058 SetMaterial("G4_WATER");
0059
0060
0061 fDetectorMessenger = new DetectorMessenger(this);
0062
0063
0064 VoxelizedSensitiveDetector::CreateInstance(this, 0.1 * m, 1 * m, 1 * m);
0065 }
0066
0067
0068
0069 DetectorConstruction::~DetectorConstruction()
0070 {
0071 delete fDetectorMessenger;
0072 }
0073
0074
0075
0076 G4VPhysicalVolume* DetectorConstruction::Construct()
0077 {
0078 return ConstructVolumes();
0079 }
0080
0081
0082
0083 void DetectorConstruction::ConstructSDandField()
0084 {
0085 VoxelizedSensitiveDetector::GetInstance()->ConstructSD();
0086 }
0087
0088
0089
0090 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
0091 {
0092
0093 G4GeometryManager::GetInstance()->OpenGeometry();
0094 G4PhysicalVolumeStore::GetInstance()->Clean();
0095 G4LogicalVolumeStore::GetInstance()->Clean();
0096 G4SolidStore::GetInstance()->Clean();
0097
0098 G4Box* sBox = new G4Box("Container",
0099 fBoxSizeX / 2, fBoxSizeY / 2, fBoxSizeZ / 2);
0100
0101 fLBox = new G4LogicalVolume(sBox,
0102 fMaterial,
0103 fMaterial->GetName());
0104
0105 fPBox = new G4PVPlacement(0,
0106 G4ThreeVector(),
0107 fLBox,
0108 fMaterial->GetName(),
0109 0,
0110 false,
0111 0);
0112
0113
0114
0115
0116
0117 VoxelizedSensitiveDetector::GetInstance()->InitializeWorldPtr(fPBox);
0118
0119
0120 VoxelizedSensitiveDetector::GetInstance()->Construct();
0121
0122
0123 return fPBox;
0124 }
0125
0126
0127
0128 void DetectorConstruction::PrintParameters()
0129 {
0130 G4cout << "\n The Box dimensions are: " << G4endl << "x: " << G4BestUnit(fBoxSizeX, "Length")
0131 << G4endl << "y: " << G4BestUnit(fBoxSizeY, "Length") << G4endl
0132 << "z: " << G4BestUnit(fBoxSizeZ, "Length") << G4endl;
0133
0134 G4cout << "And its volume therefore is: "
0135 << fPBox->GetLogicalVolume()->GetSolid()->GetCubicVolume() / m3 << " m3" << G4endl;
0136 }
0137
0138
0139
0140 void DetectorConstruction::SetMaterial(G4String materialChoice)
0141 {
0142
0143 G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0144
0145 if (pttoMaterial) {
0146 if (fMaterial != pttoMaterial) {
0147 fMaterial = pttoMaterial;
0148 if (fLBox) {
0149 fLBox->SetMaterial(pttoMaterial);
0150 }
0151 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0152 }
0153 }
0154 else {
0155
0156 std::stringstream sstr;
0157 sstr << "material " << +materialChoice << " does not exist, keeping material "
0158 << fMaterial->GetName();
0159
0160 G4Exception("DetectorConstruction::SetMaterial", "NoWorldMat", JustWarning, sstr.str().c_str());
0161 }
0162 }
0163
0164
0165
0166 void DetectorConstruction::SetSize(G4double value)
0167 {
0168 SetSizeX(value);
0169 SetSizeY(value);
0170 SetSizeZ(value);
0171 }
0172
0173
0174
0175 void DetectorConstruction::SetSize(G4ThreeVector size)
0176 {
0177 SetSizeX(size.getX());
0178 SetSizeY(size.getY());
0179 SetSizeZ(size.getZ());
0180 }
0181
0182
0183
0184 void DetectorConstruction::SetSizeX(G4double sizeX)
0185 {
0186 fBoxSizeX = sizeX;
0187 }
0188
0189
0190
0191 void DetectorConstruction::SetSizeY(G4double sizeY)
0192 {
0193 fBoxSizeY = sizeY;
0194 }
0195
0196
0197
0198 void DetectorConstruction::SetSizeZ(G4double sizeZ)
0199 {
0200 fBoxSizeZ = sizeZ;
0201 }
0202
0203
0204
0205 }