File indexing completed on 2026-04-10 07:53: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 #include "DetectorConstruction.hh"
0030
0031 #include "DetectorMessenger.hh"
0032
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 "G4PhysicalConstants.hh"
0040 #include "G4PhysicalVolumeStore.hh"
0041 #include "G4RunManager.hh"
0042 #include "G4SolidStore.hh"
0043 #include "G4SystemOfUnits.hh"
0044 #include "G4Tubs.hh"
0045 #include "G4UnitsTable.hh"
0046
0047
0048
0049 DetectorConstruction::DetectorConstruction()
0050 {
0051 fTargetLength = 1 * cm;
0052 fTargetRadius = 0.5 * cm;
0053 fDetectorLength = 5 * cm;
0054 fDetectorThickness = 2 * cm;
0055
0056 fWorldLength = std::max(fTargetLength, fDetectorLength);
0057 fWorldRadius = fTargetRadius + fDetectorThickness;
0058
0059 DefineMaterials();
0060
0061 fDetectorMessenger = new DetectorMessenger(this);
0062 }
0063
0064
0065
0066 DetectorConstruction::~DetectorConstruction()
0067 {
0068 delete fDetectorMessenger;
0069 }
0070
0071
0072
0073 G4VPhysicalVolume* DetectorConstruction::Construct()
0074 {
0075 return ConstructVolumes();
0076 }
0077
0078
0079
0080 void DetectorConstruction::DefineMaterials()
0081 {
0082
0083
0084 fDetectorMater = new G4Material("Germanium", 32, 72.61 * g / mole, 5.323 * g / cm3);
0085
0086 G4Element* N = new G4Element("Nitrogen", "N", 7, 14.01 * g / mole);
0087 G4Element* O = new G4Element("Oxygen", "O", 8, 16.00 * g / mole);
0088
0089 G4int ncomponents;
0090 G4double fractionmass;
0091 G4Material* Air20 = new G4Material("Air", 1.205 * mg / cm3, ncomponents = 2, kStateGas,
0092 293. * kelvin, 1. * atmosphere);
0093 Air20->AddElement(N, fractionmass = 0.7);
0094 Air20->AddElement(O, fractionmass = 0.3);
0095
0096 fWorldMater = Air20;
0097
0098
0099
0100 G4NistManager* man = G4NistManager::Instance();
0101 fTargetMater = man->FindOrBuildMaterial("G4_CESIUM_IODIDE");
0102
0103
0104 }
0105
0106
0107
0108 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
0109 {
0110
0111 G4GeometryManager::GetInstance()->OpenGeometry();
0112 G4PhysicalVolumeStore::GetInstance()->Clean();
0113 G4LogicalVolumeStore::GetInstance()->Clean();
0114 G4SolidStore::GetInstance()->Clean();
0115
0116
0117
0118
0119 fWorldLength = std::max(fTargetLength, fDetectorLength);
0120 fWorldRadius = fTargetRadius + fDetectorThickness;
0121
0122 G4Tubs* sWorld = new G4Tubs("World",
0123 0., fWorldRadius, 0.5 * fWorldLength, 0., twopi);
0124
0125 G4LogicalVolume* lWorld = new G4LogicalVolume(sWorld,
0126 fWorldMater,
0127 "World");
0128
0129 fPhysiWorld = new G4PVPlacement(0,
0130 G4ThreeVector(),
0131 lWorld,
0132 "World",
0133 0,
0134 false,
0135 0);
0136
0137
0138
0139 G4Tubs* sTarget = new G4Tubs("Target",
0140 0., fTargetRadius, 0.5 * fTargetLength, 0., twopi);
0141
0142 fLogicTarget = new G4LogicalVolume(sTarget,
0143 fTargetMater,
0144 "Target");
0145
0146 new G4PVPlacement(0,
0147 G4ThreeVector(),
0148 fLogicTarget,
0149 "Target",
0150 lWorld,
0151 false,
0152 0);
0153
0154
0155
0156 G4Tubs* sDetector =
0157 new G4Tubs("Detector", fTargetRadius, fWorldRadius, 0.5 * fDetectorLength, 0., twopi);
0158
0159 fLogicDetector = new G4LogicalVolume(sDetector,
0160 fDetectorMater,
0161 "Detector");
0162
0163 new G4PVPlacement(0,
0164 G4ThreeVector(),
0165 fLogicDetector,
0166 "Detector",
0167 lWorld,
0168 false,
0169 0);
0170
0171 PrintParameters();
0172
0173
0174
0175 return fPhysiWorld;
0176 }
0177
0178
0179
0180 void DetectorConstruction::PrintParameters()
0181 {
0182 G4cout << "\n Target : Length = " << G4BestUnit(fTargetLength, "Length")
0183 << " Radius = " << G4BestUnit(fTargetRadius, "Length")
0184 << " Material = " << fTargetMater->GetName();
0185 G4cout << "\n Detector : Length = " << G4BestUnit(fDetectorLength, "Length")
0186 << " Tickness = " << G4BestUnit(fDetectorThickness, "Length")
0187 << " Material = " << fDetectorMater->GetName() << G4endl;
0188 G4cout << "\n" << fTargetMater << "\n" << fDetectorMater << G4endl;
0189 }
0190
0191
0192
0193 void DetectorConstruction::SetTargetMaterial(G4String materialChoice)
0194 {
0195
0196 G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0197
0198 if (pttoMaterial) {
0199 fTargetMater = pttoMaterial;
0200 if (fLogicTarget) {
0201 fLogicTarget->SetMaterial(fTargetMater);
0202 }
0203 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0204 }
0205 else {
0206 G4cout << "\n--> warning from DetectorConstruction::SetTargetMaterial : " << materialChoice
0207 << " not found" << G4endl;
0208 }
0209 }
0210
0211
0212
0213 void DetectorConstruction::SetDetectorMaterial(G4String materialChoice)
0214 {
0215
0216 G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0217
0218 if (pttoMaterial) {
0219 fDetectorMater = pttoMaterial;
0220 if (fLogicDetector) {
0221 fLogicDetector->SetMaterial(fDetectorMater);
0222 }
0223 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0224 }
0225 else {
0226 G4cout << "\n--> warning from DetectorConstruction::SetDetectorMaterial : " << materialChoice
0227 << " not found" << G4endl;
0228 }
0229 }
0230
0231
0232
0233 void DetectorConstruction::SetTargetRadius(G4double value)
0234 {
0235 fTargetRadius = value;
0236 G4RunManager::GetRunManager()->ReinitializeGeometry();
0237 }
0238
0239
0240
0241 void DetectorConstruction::SetTargetLength(G4double value)
0242 {
0243 fTargetLength = value;
0244 G4RunManager::GetRunManager()->ReinitializeGeometry();
0245 }
0246
0247
0248
0249 void DetectorConstruction::SetDetectorThickness(G4double value)
0250 {
0251 fDetectorThickness = value;
0252 G4RunManager::GetRunManager()->ReinitializeGeometry();
0253 }
0254
0255
0256
0257 void DetectorConstruction::SetDetectorLength(G4double value)
0258 {
0259 fDetectorLength = value;
0260 G4RunManager::GetRunManager()->ReinitializeGeometry();
0261 }
0262
0263
0264
0265 G4double DetectorConstruction::GetTargetLength()
0266 {
0267 return fTargetLength;
0268 }
0269
0270
0271
0272 G4double DetectorConstruction::GetTargetRadius()
0273 {
0274 return fTargetRadius;
0275 }
0276
0277
0278
0279 G4Material* DetectorConstruction::GetTargetMaterial()
0280 {
0281 return fTargetMater;
0282 }
0283
0284
0285
0286 G4LogicalVolume* DetectorConstruction::GetLogicTarget()
0287 {
0288 return fLogicTarget;
0289 }
0290
0291
0292
0293 G4double DetectorConstruction::GetDetectorLength()
0294 {
0295 return fDetectorLength;
0296 }
0297
0298
0299
0300 G4double DetectorConstruction::GetDetectorThickness()
0301 {
0302 return fDetectorThickness;
0303 }
0304
0305
0306
0307 G4Material* DetectorConstruction::GetDetectorMaterial()
0308 {
0309 return fDetectorMater;
0310 }
0311
0312
0313
0314 G4LogicalVolume* DetectorConstruction::GetLogicDetector()
0315 {
0316 return fLogicDetector;
0317 }
0318
0319