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