File indexing completed on 2026-09-16 08:29:40
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
0034
0035
0036
0037
0038
0039
0040
0041 #include "DetectorConstruction.hh"
0042
0043 #include "CheckVolumeSD.hh"
0044 #include "DetectorMessenger.hh"
0045 #include "HistoManager.hh"
0046 #include "TargetSD.hh"
0047
0048 #include "G4Colour.hh"
0049 #include "G4GeometryManager.hh"
0050 #include "G4LogicalVolume.hh"
0051 #include "G4LogicalVolumeStore.hh"
0052 #include "G4NistManager.hh"
0053 #include "G4PVPlacement.hh"
0054 #include "G4PhysicalConstants.hh"
0055 #include "G4PhysicalVolumeStore.hh"
0056 #include "G4RunManager.hh"
0057 #include "G4SDManager.hh"
0058 #include "G4SolidStore.hh"
0059 #include "G4SystemOfUnits.hh"
0060 #include "G4Tubs.hh"
0061 #include "G4UnitsTable.hh"
0062 #include "G4VisAttributes.hh"
0063 #include "G4ios.hh"
0064
0065
0066
0067 DetectorConstruction::DetectorConstruction()
0068 : G4VUserDetectorConstruction(),
0069 fTargetMaterial(nullptr),
0070 fWorldMaterial(nullptr),
0071 fSolidW(nullptr),
0072 fSolidA(nullptr),
0073 fSolidC(nullptr),
0074 fLogicTarget(nullptr),
0075 fLogicCheck(nullptr),
0076 fLogicWorld(nullptr),
0077 fPhysWorld(nullptr),
0078 fInitialized(false)
0079 {
0080 fDetectorMessenger = new DetectorMessenger(this);
0081 G4NistManager* nist = G4NistManager::Instance();
0082 fTargetMaterial = nist->FindOrBuildMaterial("G4_Al");
0083 fWorldMaterial = nist->FindOrBuildMaterial("G4_Galactic");
0084
0085
0086
0087 G4Element* elH = nist->FindOrBuildElement(1);
0088 G4Element* elLi = nist->FindOrBuildElement(3);
0089 G4Element* elC = nist->FindOrBuildElement(6);
0090 G4Element* elO = nist->FindOrBuildElement(8);
0091 G4Element* elAl = nist->FindOrBuildElement(13);
0092 G4Element* elTi = nist->FindOrBuildElement(22);
0093 G4Element* elCo = nist->FindOrBuildElement(27);
0094 G4Element* elCu = nist->FindOrBuildElement(29);
0095 G4Material* bat = new G4Material("Battery", 2.165 * CLHEP::g / CLHEP::cm3, 8);
0096 bat->AddElement(elC, 0.19518445618745);
0097 bat->AddElement(elAl, 0.398);
0098 bat->AddElement(elTi, 0.02);
0099 bat->AddElement(elCu, 0.084);
0100 bat->AddElement(elLi, 0.0170098229419813);
0101 bat->AddElement(elCo, 0.144570016541753);
0102 bat->AddElement(elO, 0.134206611504321);
0103 bat->AddElement(elH, 0.0070290928244947);
0104 bat->GetIonisation()->SetMeanExcitationEnergy(144.88 * eV);
0105
0106 ComputeGeomParameters();
0107 }
0108
0109
0110
0111 DetectorConstruction::~DetectorConstruction()
0112 {
0113 delete fDetectorMessenger;
0114 }
0115
0116 void DetectorConstruction::ComputeGeomParameters()
0117 {
0118 HistoManager* histo = HistoManager::GetPointer();
0119
0120 fRadius = histo->Radius();
0121 fCheckR = fRadius + CLHEP::mm;
0122 fWorldR = fRadius + CLHEP::cm;
0123 fTargetZ = histo->Length() * 0.5;
0124 fCheckZ = fTargetZ + CLHEP::mm;
0125 fWorldZ = fTargetZ + CLHEP::cm;
0126
0127 fSlices = histo->NumberOfSlices();
0128 fSliceZ = fTargetZ / G4double(fSlices);
0129 if (fPhysWorld) {
0130 fSolidW->SetOuterRadius(fWorldR);
0131 fSolidW->SetZHalfLength(fWorldZ);
0132 fSolidA->SetOuterRadius(fRadius);
0133 fSolidA->SetZHalfLength(fSliceZ);
0134 fSolidC->SetOuterRadius(fCheckR);
0135 fSolidC->SetZHalfLength(fCheckZ);
0136 }
0137 }
0138
0139 G4VPhysicalVolume* DetectorConstruction::Construct()
0140 {
0141 if (nullptr != fPhysWorld) {
0142 return fPhysWorld;
0143 }
0144 ComputeGeomParameters();
0145
0146
0147
0148
0149 fSolidW = new G4Tubs("World", 0., fWorldR, fWorldZ, 0., twopi);
0150 fLogicWorld = new G4LogicalVolume(fSolidW, fWorldMaterial, "World");
0151 fPhysWorld =
0152 new G4PVPlacement(nullptr, G4ThreeVector(0., 0., 0.), fLogicWorld, "World", nullptr, false, 0);
0153
0154
0155
0156 fSolidC = new G4Tubs("Check", 0., fCheckR, fCheckZ, 0., twopi);
0157 fLogicCheck = new G4LogicalVolume(fSolidC, fWorldMaterial, "Check");
0158 new G4PVPlacement(nullptr, G4ThreeVector(0., 0., 0.), fLogicCheck, "Check", fLogicWorld, false,
0159 0);
0160
0161
0162
0163
0164 fSolidA = new G4Tubs("Target", 0., fRadius, fSliceZ, 0., twopi);
0165 fLogicTarget = new G4LogicalVolume(fSolidA, fTargetMaterial, "Target");
0166
0167 G4double z = fSliceZ - fTargetZ;
0168
0169 for (G4int i = 0; i < fSlices; ++i) {
0170
0171 new G4PVPlacement(nullptr, G4ThreeVector(0.0, 0.0, z), fLogicTarget, "Target", fLogicCheck,
0172 false, i);
0173 z += 2.0 * fSliceZ;
0174 }
0175 G4cout << "### Target consist of " << fSlices << " disks of " << fTargetMaterial->GetName()
0176 << " with R(mm)= " << fRadius / mm << " Width(mm)= " << 2.0 * fSliceZ / mm
0177 << " Total Length(mm)= " << 2.0 * fTargetZ / mm << " ###" << G4endl;
0178
0179
0180 G4VisAttributes zero = G4VisAttributes::GetInvisible();
0181 fLogicWorld->SetVisAttributes(zero);
0182
0183 G4VisAttributes regWcolor(G4Colour(0.3, 0.3, 0.3));
0184 fLogicCheck->SetVisAttributes(regWcolor);
0185
0186 G4VisAttributes regCcolor(G4Colour(0., 0.3, 0.7));
0187 fLogicTarget->SetVisAttributes(regCcolor);
0188
0189 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0190
0191 return fPhysWorld;
0192 }
0193
0194 void DetectorConstruction::ConstructSDandField()
0195 {
0196 if (!fInitialized) {
0197
0198 CheckVolumeSD* fCheckSD = new CheckVolumeSD("checkSD");
0199 (G4SDManager::GetSDMpointer())->AddNewDetector(fCheckSD);
0200 fLogicCheck->SetSensitiveDetector(fCheckSD);
0201
0202 TargetSD* fTargetSD = new TargetSD("targetSD");
0203 (G4SDManager::GetSDMpointer())->AddNewDetector(fTargetSD);
0204 fLogicTarget->SetSensitiveDetector(fTargetSD);
0205 fInitialized = true;
0206 }
0207 }
0208
0209
0210 void DetectorConstruction::SetTargetMaterial(const G4String& mat)
0211 {
0212
0213 G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
0214
0215 if (material && material != fTargetMaterial) {
0216 fTargetMaterial = material;
0217 if (fLogicTarget) {
0218 fLogicTarget->SetMaterial(fTargetMaterial);
0219 }
0220 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0221 }
0222 }
0223
0224
0225
0226 void DetectorConstruction::SetWorldMaterial(const G4String& mat)
0227 {
0228
0229 G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
0230
0231 if (material && material != fWorldMaterial) {
0232 fWorldMaterial = material;
0233 if (fLogicWorld) {
0234 fLogicWorld->SetMaterial(fWorldMaterial);
0235 }
0236 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0237 }
0238 }
0239
0240