#include "ZjnDetectorConstruction.hh" #include #include #include #include #include //继承G4VPhysicalVolum #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... //初始化 ZjnDetectorConstruction::ZjnDetectorConstruction() : G4VUserDetectorConstruction(),checkOverlaps(true),fVisAttributes(),WorldLogic(0) { } ZjnDetectorConstruction::~ZjnDetectorConstruction() { //释放可视化界面的颜色设置变量 for (G4int i=0; i FindOrBuildMaterial("G4_AIR"); G4Material* EnclosureMaterial = Nist -> FindOrBuildMaterial("G4_ALANINE"); G4Element* La = new G4Element("Lanthanum", "La", 57., 138.91*g/mole); G4Element* Br = new G4Element("Bromine", "Br", 35., 79.904*g/mole); LaBr -> AddElement(La, 1); LaBr -> AddElement(Br, 3); //调用G4自身定义好的材料 G4cout << *(G4Material::GetMaterialTable()) << G4endl; } G4VPhysicalVolume* ZjnDetectorConstruction::DefineVolumes() { //通过G4Material::GetMaterial()获取DefineMaterials()中定义的材料! G4Material* WorldMaterial = G4Material::GetMaterial("G4_AIR"); G4Material* DetectorMaterial = G4Material::GetMaterial("LaBr3"); G4Material* EnclosureMaterial = G4Material::GetMaterial("G4_ALANINE"); // // World // G4Box* WorldSolid = new G4Box("World", // 世界名字 1.2 * 0.5 * WorldX, 1.2 * 0.5 * WorldY, 1.2 * 0.5 * WorldZ); // 世界大小 WorldLogic = new G4LogicalVolume(WorldSolid, //世界物理体 WorldMaterial, //世界材料体 "World"); //世界名字,世界的名字只能是世界 WorldPhys = new G4PVPlacement(nullptr, //转角 G4ThreeVector(), //位置(0,0,0) WorldLogic, //世界逻辑体 "World", //世界名字 nullptr, // its moher volume false, // no boolean operation 0, // copy number checkOverlaps); // overlaps checking // // Envelope // G4Box* EnvSolid = new G4Box("Envelope", // 环境,必须 0.5 * WorldX, 0.5 * WorldY, 0.5 * WorldZ); EnvLogic = new G4LogicalVolume(EnvSolid, WorldMaterial, "Envelope"); EnvPhys = new G4PVPlacement(nullptr, G4ThreeVector(), EnvLogic, "Envelope", WorldLogic, //母体,必须 false, 0, checkOverlaps); // // 探测器 // G4Box* DetectorSolid = new G4Box("LaBr", // 尽量每个探测器一个名字,方便后面判断和调用,也就是说,需要多个一样的探测器时,需要写for循环来生成,并确保名字不同,有规律会更好的调用。 0.5 * DetectorX, 0.5 * DetectorY, 0.5 * DetectorZ); DetectorLogic = new G4LogicalVolume(DetectorSolid, DetectorMaterial, "Detector1"); DetectordPhys = new G4PVPlacement(nullptr, G4ThreeVector(0, 0, 0.5 * WorldZ - 0.5 * DetectorZ - 0.5 * CLHEP::cm), DetectorLogic, "Detector1", EnvLogic, false, 0, checkOverlaps); // // 外壳,使用了布尔实体,给探测侧边套铝壳,两个小正方形面单独套铝板,以分别得到到两块铝板的gamma的数量,gamma的总能量,电子的数量,电子的总能量 // G4Box* Whole = new G4Box("Whole", // 环境,必须 0.5 * DetectorX + 0.5 * CLHEP::cm, 0.5 * DetectorY + 0.5 * CLHEP::cm, 0.5 * DetectorZ + 0.5 * CLHEP::cm); //构造函数 G4SubtractionSolid* EnclosureSolid = new G4SubtractionSolid("Enclosure", //名称 Whole,//实体1指针 DetectorSolid,//实体2指针 nullptr,//实体2的旋转方式,不需要旋转 G4ThreeVector()//实体2的平移方式,不需要平移 ); EnclosureLogic = new G4LogicalVolume(EnclosureSolid, EnclosureMaterial, "DetectorEnclosure"); EnclosurePhys = new G4PVPlacement(nullptr, G4ThreeVector(0, 0, 0.5 * WorldZ - 0.5 * DetectorZ - 0.5 * CLHEP::cm), EnclosureLogic, "DetectorEnclosure", EnvLogic, false, 0, checkOverlaps); G4Box* SiSolid[2]; for(G4int i = 0; i < 2; i++) { SiSolid[i] = new G4Box("Si" + std::to_string(i), // 环境,必须 0.5 * DetectorX, 0.25 * CLHEP::cm, 0.5 * DetectorZ); SiLogic[i] = new G4LogicalVolume(SiSolid[i], EnclosureMaterial, "Si" + std::to_string(i)); SiPhys[i] = new G4PVPlacement(nullptr, G4ThreeVector(0, 0.5 * (DetectorY + 0.5 * CLHEP::cm) * (2 * i - 1), 0.5 * WorldZ - 0.5 * DetectorZ - 0.5 * CLHEP::cm), SiLogic[i], "SiDetector" + std::to_string(i), EnvLogic, false, 0, checkOverlaps); } //=============================== // visualization attributes ------------------------------------------------ //可视化界面几何体颜色设置(可有可无) G4VisAttributes* visAttributes = new G4VisAttributes(G4Colour(1.0,1.0,1.0)); //visAttributes->SetVisibility(false);//不显示边框 WorldLogic -> SetVisAttributes(visAttributes); EnvLogic -> SetVisAttributes(visAttributes); fVisAttributes.push_back(visAttributes); visAttributes = new G4VisAttributes(G4Colour(1.0,1.0,0.0)); DetectorLogic -> SetVisAttributes(visAttributes); fVisAttributes.push_back(visAttributes); visAttributes = new G4VisAttributes(G4Colour(0.0,0.0,1.0)); EnclosureLogic -> SetVisAttributes(visAttributes); fVisAttributes.push_back(visAttributes); visAttributes = new G4VisAttributes(G4Colour(0.0,0.0,1.0)); SiLogic[0] -> SetVisAttributes(visAttributes); SiLogic[1] -> SetVisAttributes(visAttributes); fVisAttributes.push_back(visAttributes); // G4Colour white (1.0, 1.0, 1.0) ; // G4Colour grey (0.5, 0.5, 0.5) ; // G4Colour lgrey (.85, .85, .85) ; // G4Colour red (1.0, 0.0, 0.0) ; // G4Colour blue (0.0, 0.0, 1.0) ; // G4Colour cyan (0.0, 1.0, 1.0) ; // G4Colour magenta (1.0, 0.0, 1.0) ; // G4Colour yellow (1.0, 1.0, 0.0) ; // G4Colour orange (.75, .55, 0.0) ; // G4Colour lblue (0.0, 0.0, .75) ; // G4Colour lgreen (0.0, .75, 0.0) ; // G4Colour green (0.0, 1.0, 0.0) ; // G4Colour brown (0.7, 0.4, 0.1) ; // //always return the physical World // DefineMaterPropertiesTable(); return WorldPhys; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void ZjnDetectorConstruction::BuildSensitiveDetector(G4LogicalVolume* lv) { // if(!lv){ // G4cout<<"$$No given logical volume, no SD built"<GetName()); // // SDman->AddNewDetector(sd1); // lv->SetSensitiveDetector(sd1); } void ZjnDetectorConstruction::DefineMaterPropertiesTable()//定义各种光学属性 { const G4int NEntry = 2; G4double PhotonEnergy[NEntry] = {1 * eV, 700.0 * eV}; G4double LaBrRefractionIndex[NEntry] = {1.9, 1.9}; G4double LaBrAbsorptionLength[NEntry] = {50. * CLHEP::cm, 50. * CLHEP::cm}; G4double ScintFast[NEntry] = {1.0, 1.0}; LaBrMPT -> AddProperty("RINDEX", PhotonEnergy, LaBrRefractionIndex, NEntry); LaBrMPT -> AddProperty("ABSLENGTH", PhotonEnergy, LaBrAbsorptionLength, NEntry); LaBrMPT -> AddProperty("SCINTILLATIONCOMPONENT1", PhotonEnergy, ScintFast, NEntry); LaBrMPT -> AddConstProperty("SCINTILLATIONYIELD", 68./keV); //光产额 LaBrMPT -> AddConstProperty("RESOLUTIONSCALE", 1.); //晶体本征分辨(宽度) LaBrMPT -> AddConstProperty("SCINTILLATIONRISETIME1", 16. * ns); //时间常数 LaBrMPT -> AddConstProperty("SCINTILLATIONYIELD1", 1.); //快慢时间之比 LaBr -> SetMaterialPropertiesTable(LaBrMPT); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......