G4-ExampleB1/src/DetectorConstruction.cc

136 lines
5.9 KiB
C++
Raw Permalink Normal View History

2022-04-29 13:24:29 +08:00
#include "DetectorConstruction.hh"
#include "G4Box.hh"
#include "G4Cons.hh"
#include "G4LogicalVolume.hh"
#include "G4NistManager.hh"
#include "G4Orb.hh"
#include "G4PVPlacement.hh"
#include "G4RunManager.hh"
#include "G4Sphere.hh"
#include "G4SystemOfUnits.hh"
#include "G4Trd.hh"
namespace B1 {
// 构造函数
DetectorConstruction::DetectorConstruction() {}
// 构析函数
DetectorConstruction::~DetectorConstruction() {}
// 描述函数
G4VPhysicalVolume* DetectorConstruction::Construct() {
// NIST 材料查找表
G4NistManager* nist = G4NistManager::Instance();
// Envelope 的参数
// 外层的水箱
G4double env_sizeXY = 20 * cm, env_sizeZ = 30 * cm;
G4Material* env_mat = nist->FindOrBuildMaterial("G4_WATER");
// 检查几何体之间是否重叠
G4bool checkOverlaps = true;
// World
// 整个大环境,超出环境则认为逃逸
G4double world_sizeXY = 1.2 * env_sizeXY;
G4double world_sizeZ = 1.2 * env_sizeZ;
G4Material* world_mat = nist->FindOrBuildMaterial("G4_AIR");
// 描述几何体
// solid 几何框架 -> logic 材料 -> physical 放置等操作
// 定义 World 的框架大小,注意尺寸是半尺寸
G4Box* solidWorld = new G4Box("World", // 名称
0.5 * world_sizeXY, 0.5 * world_sizeXY, 0.5 * world_sizeZ); // 尺寸
G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld, // 几何框架
world_mat, // 材料
"World"); // 名称
G4VPhysicalVolume* physWorld = new G4PVPlacement(0, // 旋转
G4ThreeVector(), // 中心位置,必须在 (0,0,0)
logicWorld, // 材料
"World", // 名称
0, // 母体环境Mother Volume
false, // no boolean operation
0, // copy number
checkOverlaps); // overlaps checking
// Envelope
// World 中的小环境
G4Box* solidEnv = new G4Box("Envelope", // 名称
0.5 * env_sizeXY, 0.5 * env_sizeXY, 0.5 * env_sizeZ); // 尺寸
G4LogicalVolume* logicEnv = new G4LogicalVolume(solidEnv, // 几何框架
env_mat, // 材料
"Envelope"); // 名称
new G4PVPlacement(0, // no rotation
G4ThreeVector(), // at (0,0,0)
2022-04-30 21:39:54 +08:00
logicEnv, // logical volume
"Envelope", // name
logicWorld, // Mother Logical Volumes即 World
2022-04-29 13:24:29 +08:00
false, // no boolean operation
0, // copy number
checkOverlaps); // overlaps checking
// Shape 1
G4Material* shape1_mat = nist->FindOrBuildMaterial("G4_A-150_TISSUE");
G4ThreeVector pos1 = G4ThreeVector(0, 2 * cm, -7 * cm);
// 圆锥状 Conical section
G4double shape1_rmina = 0. * cm, shape1_rmaxa = 2. * cm;
G4double shape1_rminb = 0. * cm, shape1_rmaxb = 4. * cm;
G4double shape1_hz = 3. * cm;
G4double shape1_phimin = 0. * deg, shape1_phimax = 360. * deg;
G4Cons* solidShape1 = new G4Cons("Shape1", shape1_rmina, shape1_rmaxa, shape1_rminb, shape1_rmaxb, shape1_hz,
shape1_phimin, shape1_phimax);
2022-04-30 21:39:54 +08:00
G4LogicalVolume* logicShape1 = new G4LogicalVolume(solidShape1, // solid
shape1_mat, // material
"Shape1"); // name
2022-04-29 13:24:29 +08:00
new G4PVPlacement(0, // no rotation
pos1, // at position
2022-04-30 21:39:54 +08:00
logicShape1, // logical volume
"Shape1", // name
logicEnv, // mother volume
2022-04-29 13:24:29 +08:00
false, // no boolean operation
0, // copy number
checkOverlaps); // overlaps checking
// Shape 2
G4Material* shape2_mat = nist->FindOrBuildMaterial("G4_BONE_COMPACT_ICRU");
G4ThreeVector pos2 = G4ThreeVector(0, -1 * cm, 7 * cm);
// 梯形 Trapezoid
G4double shape2_dxa = 12 * cm, shape2_dxb = 12 * cm;
G4double shape2_dya = 10 * cm, shape2_dyb = 16 * cm;
G4double shape2_dz = 6 * cm;
2022-04-30 21:39:54 +08:00
G4Trd* solidShape2 = new G4Trd("Shape2", // name
2022-04-29 13:24:29 +08:00
0.5 * shape2_dxa, 0.5 * shape2_dxb, 0.5 * shape2_dya, 0.5 * shape2_dyb,
2022-04-30 21:39:54 +08:00
0.5 * shape2_dz); // size
2022-04-29 13:24:29 +08:00
2022-04-30 21:39:54 +08:00
G4LogicalVolume* logicShape2 = new G4LogicalVolume(solidShape2, // solid
shape2_mat, // material
"Shape2"); // name
2022-04-29 13:24:29 +08:00
new G4PVPlacement(0, // no rotation
pos2, // at position
2022-04-30 21:39:54 +08:00
logicShape2, // logical volume
"Shape2", // name
logicEnv, // mother volume
2022-04-29 13:24:29 +08:00
false, // no boolean operation
0, // copy number
checkOverlaps); // overlaps checking
// 设置 Shape2 用于计算剂量
fScoringVolume = logicShape2;
// 总是返回大环境的物理体
return physWorld;
}
} // namespace B1