File indexing completed on 2026-09-11 08:30:11
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 "DetectorMessenger.hh"
0044 #include "HistoManager.hh"
0045 #include "TargetSD.hh"
0046
0047 #include "G4Colour.hh"
0048 #include "G4GeometryManager.hh"
0049 #include "G4LogicalVolume.hh"
0050 #include "G4LogicalVolumeStore.hh"
0051 #include "G4NistManager.hh"
0052 #include "G4PVPlacement.hh"
0053 #include "G4PhysicalConstants.hh"
0054 #include "G4PhysicalVolumeStore.hh"
0055 #include "G4RunManager.hh"
0056 #include "G4SDManager.hh"
0057 #include "G4SolidStore.hh"
0058 #include "G4SystemOfUnits.hh"
0059 #include "G4Tubs.hh"
0060 #include "G4UnitsTable.hh"
0061 #include "G4VisAttributes.hh"
0062 #include "G4ios.hh"
0063
0064
0065
0066 DetectorConstruction::DetectorConstruction()
0067 : G4VUserDetectorConstruction(),
0068 fRadius(10. * cm),
0069 fTargetMaterial(0),
0070 fWorldMaterial(0),
0071 fTargetSD(0),
0072 fLogicTarget(0),
0073 fLogicWorld(0),
0074 fDetectorMessenger(0)
0075
0076 {
0077 fDetectorMessenger = new DetectorMessenger(this);
0078
0079 fTargetMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Al");
0080 fWorldMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
0081 HistoManager::GetPointer()->SetTargetMaterial(fTargetMaterial);
0082
0083
0084 fTargetSD = new TargetSD("targetSD");
0085 G4SDManager::GetSDMpointer()->AddNewDetector(fTargetSD);
0086 }
0087
0088
0089
0090 DetectorConstruction::~DetectorConstruction()
0091 {
0092 delete fDetectorMessenger;
0093 }
0094
0095 G4VPhysicalVolume* DetectorConstruction::Construct()
0096 {
0097
0098 G4GeometryManager::GetInstance()->OpenGeometry();
0099 G4PhysicalVolumeStore::GetInstance()->Clean();
0100 G4LogicalVolumeStore::GetInstance()->Clean();
0101 G4SolidStore::GetInstance()->Clean();
0102
0103
0104 G4double checkR = fRadius + mm;
0105 G4double worldR = fRadius + cm;
0106 G4double targetZ = HistoManager::GetPointer()->Length() * 0.5;
0107 G4double checkZ = targetZ + mm;
0108 G4double worldZ = targetZ + cm;
0109
0110 G4int nSlices = HistoManager::GetPointer()->NumberOfSlices();
0111 G4double sliceZ = targetZ / G4double(nSlices);
0112
0113
0114
0115 G4Tubs* solidW = new G4Tubs("World", 0., worldR, worldZ, 0., twopi);
0116 fLogicWorld = new G4LogicalVolume(solidW, fWorldMaterial, "World");
0117 G4VPhysicalVolume* world =
0118 new G4PVPlacement(0, G4ThreeVector(), fLogicWorld, "World", 0, false, 0);
0119
0120
0121
0122 G4Tubs* solidC = new G4Tubs("Check", 0., checkR, checkZ, 0., twopi);
0123 G4LogicalVolume* logicCheck = new G4LogicalVolume(solidC, fWorldMaterial, "World");
0124 new G4PVPlacement(0, G4ThreeVector(), logicCheck, "World", fLogicWorld, false, 0);
0125
0126
0127
0128
0129 G4Tubs* solidA = new G4Tubs("Target", 0., fRadius, sliceZ, 0., twopi);
0130 fLogicTarget = new G4LogicalVolume(solidA, fTargetMaterial, "Target");
0131 fLogicTarget->SetSensitiveDetector(fTargetSD);
0132
0133 G4double z = sliceZ - targetZ;
0134
0135 for (G4int i = 0; i < nSlices; i++) {
0136
0137 new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, z), fLogicTarget, "Target", logicCheck, false, i);
0138 z += 2.0 * sliceZ;
0139 }
0140 G4cout << "### Target consist of " << nSlices << " of " << fTargetMaterial->GetName()
0141 << " disks with R(mm)= " << fRadius / mm << " Width(mm)= " << 2.0 * sliceZ / mm
0142 << " Total Length(mm)= " << 2.0 * targetZ / mm << " ###" << G4endl;
0143
0144
0145 G4VisAttributes zero = G4VisAttributes::GetInvisible();
0146 fLogicWorld->SetVisAttributes(zero);
0147
0148 G4VisAttributes regWcolor(G4Colour(0.3, 0.3, 0.3));
0149 logicCheck->SetVisAttributes(regWcolor);
0150
0151 G4VisAttributes regCcolor(G4Colour(0., 0.3, 0.7));
0152 fLogicTarget->SetVisAttributes(regCcolor);
0153
0154 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0155
0156 return world;
0157 }
0158
0159
0160
0161 void DetectorConstruction::SetTargetMaterial(const G4String& mat)
0162 {
0163
0164 G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
0165
0166 if (material && material != fTargetMaterial) {
0167 HistoManager::GetPointer()->SetTargetMaterial(material);
0168 fTargetMaterial = material;
0169 if (fLogicTarget) {
0170 fLogicTarget->SetMaterial(fTargetMaterial);
0171 }
0172 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0173 }
0174 }
0175
0176
0177
0178 void DetectorConstruction::SetWorldMaterial(const G4String& mat)
0179 {
0180
0181 G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
0182
0183 if (material && material != fWorldMaterial) {
0184 fWorldMaterial = material;
0185 if (fLogicWorld) {
0186 fLogicWorld->SetMaterial(fWorldMaterial);
0187 }
0188 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0189 }
0190 }
0191
0192
0193
0194 void DetectorConstruction::SetTargetRadius(G4double val)
0195 {
0196 if (val > 0.0) {
0197 fRadius = val;
0198 G4RunManager::GetRunManager()->GeometryHasBeenModified();
0199 }
0200 }
0201
0202