File indexing completed on 2026-09-23 08:29:24
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 "G4Box.hh"
0034 #include "G4GeometryManager.hh"
0035 #include "G4LogicalVolume.hh"
0036 #include "G4LogicalVolumeStore.hh"
0037 #include "G4Material.hh"
0038 #include "G4NistManager.hh"
0039 #include "G4PVPlacement.hh"
0040 #include "G4PhysicalVolumeStore.hh"
0041 #include "G4RunManager.hh"
0042 #include "G4SolidStore.hh"
0043 #include "G4SystemOfUnits.hh"
0044 #include "G4UnitsTable.hh"
0045
0046
0047
0048 DetectorConstruction::DetectorConstruction()
0049 {
0050 fBoxSize = 10 * m;
0051 DefineMaterials();
0052 SetMaterial("Molybdenum98");
0053 fDetectorMessenger = new DetectorMessenger(this);
0054 }
0055
0056
0057
0058 DetectorConstruction::~DetectorConstruction()
0059 {
0060 delete fDetectorMessenger;
0061 }
0062
0063
0064
0065 G4VPhysicalVolume* DetectorConstruction::Construct()
0066 {
0067 return ConstructVolumes();
0068 }
0069
0070
0071
0072 void DetectorConstruction::DefineMaterials()
0073 {
0074
0075
0076 MaterialWithSingleIsotope("Molybdenum98", "Mo98", 10.28 * g / cm3, 42, 98);
0077
0078
0079 G4Element* H = new G4Element("Hydrogen", "H", 1., 1.01 * g / mole);
0080 G4Element* C = new G4Element("Carbon", "C", 6., 12.00 * g / mole);
0081 G4Material* ne213 = new G4Material("NE213", 0.874 * g / cm3, 2);
0082 ne213->AddElement(H, 9.2 * perCent);
0083 ne213->AddElement(C, 90.8 * perCent);
0084
0085 G4Material* hydrogen = new G4Material("hydrogen", 1.0 * g / cm3, 1);
0086 hydrogen->AddElement(H, 1);
0087
0088 G4Material* carbon = new G4Material("carbon", 1.0 * g / cm3, 1);
0089 carbon->AddElement(C, 1);
0090
0091 G4Material* plastic = new G4Material("plastic", 1.0 * g / cm3, 2);
0092 plastic->AddElement(H, 1);
0093 plastic->AddElement(C, 1);
0094
0095
0096
0097 G4NistManager* man = G4NistManager::Instance();
0098 man->FindOrBuildMaterial("G4_B");
0099
0100 G4Element* O = man->FindOrBuildElement("O");
0101 G4Element* Hf = man->FindOrBuildElement("Hf");
0102
0103 G4Material* HfO2 = new G4Material("HfO2", 9.68 * g / cm3, 2);
0104 HfO2->AddElement(Hf, 1);
0105 HfO2->AddElement(O, 2);
0106
0107
0108 }
0109
0110
0111
0112 G4Material* DetectorConstruction::MaterialWithSingleIsotope(G4String name, G4String symbol,
0113 G4double density, G4int Z, G4int A)
0114 {
0115
0116
0117 G4int ncomponents;
0118 G4double abundance, massfraction;
0119
0120 G4Isotope* isotope = new G4Isotope(symbol, Z, A);
0121
0122 G4Element* element = new G4Element(name, symbol, ncomponents = 1);
0123 element->AddIsotope(isotope, abundance = 100. * perCent);
0124
0125 G4Material* material = new G4Material(name, density, ncomponents = 1);
0126 material->AddElement(element, massfraction = 100. * perCent);
0127
0128 return material;
0129 }
0130
0131
0132
0133 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
0134 {
0135
0136 G4GeometryManager::GetInstance()->OpenGeometry();
0137 G4PhysicalVolumeStore::GetInstance()->Clean();
0138 G4LogicalVolumeStore::GetInstance()->Clean();
0139 G4SolidStore::GetInstance()->Clean();
0140
0141 G4Box* sBox = new G4Box("Container",
0142 fBoxSize / 2, fBoxSize / 2, fBoxSize / 2);
0143
0144 fLBox = new G4LogicalVolume(sBox,
0145 fMaterial,
0146 fMaterial->GetName());
0147
0148 fPBox = new G4PVPlacement(0,
0149 G4ThreeVector(),
0150 fLBox,
0151 fMaterial->GetName(),
0152 0,
0153 false,
0154 0);
0155
0156 PrintParameters();
0157
0158
0159
0160 return fPBox;
0161 }
0162
0163
0164
0165 void DetectorConstruction::PrintParameters()
0166 {
0167 G4cout << "\n The Box is " << G4BestUnit(fBoxSize, "Length") << " of " << fMaterial->GetName()
0168 << "\n \n"
0169 << fMaterial << G4endl;
0170 }
0171
0172
0173
0174 void DetectorConstruction::SetMaterial(G4String materialChoice)
0175 {
0176
0177 G4Material* pttoMaterial = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
0178
0179 if (pttoMaterial) {
0180 if (fMaterial != pttoMaterial) {
0181 fMaterial = pttoMaterial;
0182 if (fLBox) {
0183 fLBox->SetMaterial(pttoMaterial);
0184 }
0185 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0186 }
0187 }
0188 else {
0189 G4cout << "\n--> warning from DetectorConstruction::SetMaterial : " << materialChoice
0190 << " not found" << G4endl;
0191 }
0192 }
0193
0194
0195
0196 void DetectorConstruction::SetSize(G4double value)
0197 {
0198 fBoxSize = value;
0199 G4RunManager::GetRunManager()->ReinitializeGeometry();
0200 }
0201
0202