File indexing completed on 2026-03-28 07:50: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 #include "DetectorConstruction.hh"
0030
0031 #include "G4Box.hh"
0032 #include "G4GeometryManager.hh"
0033 #include "G4LogicalVolume.hh"
0034 #include "G4Material.hh"
0035 #include "G4NistManager.hh"
0036 #include "G4PVPlacement.hh"
0037 #include "G4ProductionCuts.hh"
0038 #include "G4RunManager.hh"
0039 #include "G4SystemOfUnits.hh"
0040 #include "G4ThreeVector.hh"
0041 #include "G4Tubs.hh"
0042 #include "G4UnitsTable.hh"
0043 #include "G4VPhysicalVolume.hh"
0044 #include "G4VisAttributes.hh"
0045
0046 const bool check_intersections = true;
0047
0048
0049 const G4double ug = 1.e-6 * g;
0050
0051
0052
0053 G4VPhysicalVolume* DetectorConstruction::Construct()
0054 {
0055 auto man = G4NistManager::Instance();
0056
0057
0058 new G4UnitDefinition("microgram", "ug", "Mass", ug);
0059
0060
0061 G4double worldSize = 8 * cm;
0062 G4double worldDensity = 0.15 * mg / m3;
0063
0064 G4double IV_diameter = 10 * mm;
0065 G4double IV_height = 20 * mm;
0066 G4double IV_vertical_offset = -5 * mm;
0067 G4double IV_density = 0.45 * ug / cm3;
0068
0069 G4double wall_tot_mass_thickness = 0.98 * mg / cm2;
0070 G4double wall_inner_layer_mass_thickness =
0071 0.02 * mg / cm2;
0072
0073 fCollDiameter = 3 * mm;
0074 fCollLength = 23 * mm;
0075 fCollExitPosition = -5.5 * mm;
0076
0077 G4double enDet_diameter = 10 * mm;
0078 G4double enDet_thickness = 150 * um;
0079 G4double enDet_distance = 10 * mm;
0080
0081
0082 auto worldMaterial =
0083 man->BuildMaterialWithNewDensity("WORLD_WATER_VACUUM", "G4_WATER", worldDensity);
0084 auto targetMaterial = man->BuildMaterialWithNewDensity("TARGET_WATER", "G4_WATER", IV_density);
0085 auto wallMaterial = man->FindOrBuildMaterial("G4_MYLAR");
0086 auto collMaterial = man->FindOrBuildMaterial("G4_BRASS");
0087 auto enDetMaterial = man->FindOrBuildMaterial("G4_Si");
0088
0089
0090 G4ThreeVector origin(0, 0, 0);
0091 G4ThreeVector IV_centre(0, 0, IV_vertical_offset);
0092 G4ThreeVector enDet_centre(enDet_distance + IV_diameter / 2., 0, 0);
0093
0094 G4double mylarDensity = wallMaterial->GetDensity();
0095 G4double wall_total_thickness = wall_tot_mass_thickness / mylarDensity;
0096 G4double wall_inner_layer_thickness = wall_inner_layer_mass_thickness / mylarDensity;
0097
0098
0099 auto innerWallMaterial = man->BuildMaterialWithNewDensity("WALL_WATER", "G4_WATER", mylarDensity);
0100
0101
0102 auto filename = "SIM_GEOMETRY_SETTINGS.txt";
0103 std::ofstream TextFile;
0104 TextFile.open(filename, std::fstream::out);
0105 TextFile << "worldSize = " << worldSize / cm << " cm\n";
0106 TextFile << "worldDensity = " << worldDensity / (mg / m3) << " mg/m3\n";
0107 TextFile << "IV_diameter = " << IV_diameter / mm << " mm\n";
0108 TextFile << "IV_height = " << IV_height / mm << " mm\n";
0109 TextFile << "IV_vertical_offset = " << IV_vertical_offset / mm << " mm\n";
0110 TextFile << "IV_density = " << IV_density / (ug / cm3) << " ug/cm3\n";
0111 TextFile << "wall_tot_mass_thickness = " << wall_tot_mass_thickness / (mg / cm2) << " mg/cm2\n";
0112 TextFile << "wall_inner_layer_mass_thickness = " << wall_inner_layer_mass_thickness / (mg / cm2)
0113 << " mg/cm2\n";
0114 TextFile << "fCollDiameter = " << fCollDiameter / mm << " mm\n";
0115 TextFile << "fCollLength = " << fCollLength / mm << " mm\n";
0116 TextFile << "fCollExitPosition = " << fCollExitPosition / mm << " mm\n";
0117 TextFile << "enDet_diameter = " << enDet_diameter / mm << " mm\n";
0118 TextFile << "enDet_thickness = " << enDet_thickness / mm << " mm\n";
0119 TextFile << "enDet_distance = " << enDet_distance / mm << " mm\n";
0120 TextFile << "worldMaterial: " << worldMaterial->GetName() << "\n";
0121 TextFile << "targetMaterial: " << targetMaterial->GetName() << "\n";
0122 TextFile << "wallMaterial: " << wallMaterial->GetName() << "\n";
0123 TextFile << "collMaterial: " << collMaterial->GetName() << "\n";
0124 TextFile << "enDetMaterial: " << enDetMaterial->GetName() << "\n";
0125 TextFile << "innerWallMaterial: " << innerWallMaterial->GetName() << "\n";
0126
0127
0128
0129 auto worldSolid = new G4Box("worldSolid",
0130 worldSize / 2, worldSize / 2,
0131 worldSize / 2);
0132
0133 auto worldLogic = new G4LogicalVolume(worldSolid,
0134 worldMaterial,
0135 "worldLogic");
0136
0137 auto worldPhys = new G4PVPlacement(nullptr,
0138 G4ThreeVector(0, 0, 0),
0139 worldLogic,
0140 "worldPhys",
0141 nullptr,
0142 false,
0143 0,
0144 check_intersections);
0145
0146
0147 auto chamberSolid = new G4Tubs("chamberSolid",
0148 0,
0149 IV_diameter / 2.,
0150 IV_height / 2.,
0151 0 * deg,
0152 360 * deg);
0153
0154 auto chamberLogic = new G4LogicalVolume(chamberSolid,
0155 targetMaterial,
0156 "chamberLogic");
0157
0158 new G4PVPlacement(nullptr, IV_centre, chamberLogic, "chamberPhys", worldLogic, false, 0,
0159 check_intersections);
0160
0161
0162
0163
0164 auto targetSolid = new G4Tubs("targetSolid",
0165 0,
0166 IV_diameter / 2.,
0167 IV_height / 2.,
0168 0 * deg,
0169 360 * deg);
0170
0171 auto targetLogic = new G4LogicalVolume(targetSolid, targetMaterial, "targetLogic");
0172
0173 new G4PVPlacement(nullptr, origin, targetLogic, "targetPhys", chamberLogic, false, 0,
0174 check_intersections);
0175
0176
0177
0178
0179 auto wallSolid = new G4Tubs("wallSolid",
0180 IV_diameter / 2.,
0181 IV_diameter / 2. + wall_total_thickness,
0182 IV_height / 2.,
0183 0 * deg,
0184 360 * deg);
0185
0186 auto wallLogic = new G4LogicalVolume(wallSolid, wallMaterial, "wallSolid");
0187 new G4PVPlacement(nullptr, IV_centre, wallLogic, "wallPhys", worldLogic, false, 0,
0188 check_intersections);
0189
0190
0191 auto innerWallSolid = new G4Tubs("innerWallSolid",
0192 IV_diameter / 2.,
0193 IV_diameter / 2. + wall_inner_layer_thickness,
0194 IV_height / 2.,
0195 0 * deg,
0196 360 * deg);
0197
0198 auto innerWallLogic = new G4LogicalVolume(innerWallSolid, innerWallMaterial, "innerWallLogic");
0199 new G4PVPlacement(nullptr, origin, innerWallLogic, "innerWallPhys", wallLogic, false, 0,
0200 check_intersections);
0201
0202
0203 auto collSolid = new G4Tubs("collSolid",
0204 fCollDiameter / 2.,
0205 fCollDiameter,
0206 fCollLength / 2.,
0207 0 * deg,
0208 360 * deg);
0209
0210 auto collLogic = new G4LogicalVolume(collSolid, collMaterial, "collSolid");
0211
0212 auto rot = new G4RotationMatrix();
0213 rot->rotateY(90 * deg);
0214 new G4PVPlacement(rot, G4ThreeVector(-fCollLength / 2 + fCollExitPosition, 0, 0), collLogic,
0215 "collPhys", worldLogic, false, 0, check_intersections);
0216
0217
0218
0219 auto enDetSolid = new G4Tubs("enDetSolid",
0220 0,
0221 enDet_diameter / 2.,
0222 enDet_thickness / 2.,
0223 0 * deg, 360 * deg);
0224
0225 auto enDetLogic = new G4LogicalVolume(enDetSolid, enDetMaterial, "enDetLogic");
0226 new G4PVPlacement(rot, enDet_centre, enDetLogic, "enDetPhys", worldLogic, false, 0,
0227 check_intersections);
0228
0229
0230
0231 auto worldVisAtt = new G4VisAttributes(G4Colour(1, 1, 1, 0.1));
0232 worldLogic->SetVisAttributes(worldVisAtt);
0233
0234 auto targetVisAtt = new G4VisAttributes(G4Colour(0.1, 0.5, 1, 0.7));
0235 targetLogic->SetVisAttributes(targetVisAtt);
0236
0237 auto innerWallVisAtt = new G4VisAttributes(G4Colour(0, 1, 1, 0.7));
0238 innerWallLogic->SetVisAttributes(innerWallVisAtt);
0239
0240 auto collVisAtt = new G4VisAttributes(G4Colour(0.7, 0.65, .25, 0.5));
0241 collLogic->SetVisAttributes(collVisAtt);
0242
0243 auto enDetVisAtt = new G4VisAttributes(G4Colour(0.5, 0.7, .5, 1.));
0244 enDetLogic->SetVisAttributes(enDetVisAtt);
0245
0246
0247
0248 auto region = new G4Region("Target");
0249
0250 auto cuts = new G4ProductionCuts();
0251
0252 G4double defCut = 1 * nanometer;
0253 cuts->SetProductionCut(defCut, "gamma");
0254 cuts->SetProductionCut(defCut, "e-");
0255 cuts->SetProductionCut(defCut, "e+");
0256 cuts->SetProductionCut(defCut, "proton");
0257
0258 region->SetProductionCuts(cuts);
0259 region->AddRootLogicalVolume(chamberLogic);
0260 region->AddRootLogicalVolume(targetLogic);
0261 region->AddRootLogicalVolume(innerWallLogic);
0262
0263 return worldPhys;
0264 }
0265