Geant4 入射粒子设置

在 PrimaryGeneratorAction 中设置 G4ParticleGun.

注意:关于粒子种类的定义,有两个位置可以定义,第一是在 PrimaryGeneratorAction 类的构造函数中定义,第二是在 GeneratePrimaries() 函数中定义。

在 PrimaryGeneratorAction 类的构造函数中定义,粒子种类可以在 .mac 文件中修改,举例代码取自 example B2:

1 B2PrimaryGeneratorAction::B2PrimaryGeneratorAction()2 : G4VUserPrimaryGeneratorAction()3 {4 G4int nofParticles = 1;5 fParticleGun = newG4ParticleGun(nofParticles);6

7 //default particle kinematic

8

9 G4ParticleDefinition*particleDefinition10 = G4ParticleTable::GetParticleTable()->FindParticle("proton");11

12 fParticleGun->SetParticleDefinition(particleDefinition);13 fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));14 fParticleGun->SetParticleEnergy(3.0*GeV);15 }

在 GeneratePrimaries() 函数中定义,粒子种类可以在 .mac 文件中修改,举例代码取自 example B5:

1 #include "B5PrimaryGeneratorAction.hh"

2

3 #include "G4Event.hh"

4 #include "G4ParticleGun.hh"

5 #include "G4ParticleTable.hh"

6 #include "G4ParticleDefinition.hh"

7 #include "G4GenericMessenger.hh"

8 #include "G4SystemOfUnits.hh"

9 #include "Randomize.hh"

10

11 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

12

13 B5PrimaryGeneratorAction::B5PrimaryGeneratorAction()14 : G4VUserPrimaryGeneratorAction(),15 fParticleGun(nullptr), fMessenger(nullptr),16 fPositron(nullptr), fMuon(nullptr), fPion(nullptr),17 fKaon(nullptr), fProton(nullptr),18 fMomentum(1000.*MeV),19 fSigmaMomentum(50.*MeV),20 fSigmaAngle(2.*deg),21 fRandomizePrimary(true)22 {23 G4int nofParticles = 1;24 fParticleGun = newG4ParticleGun(nofParticles);25

26 auto particleTable =G4ParticleTable::GetParticleTable();27 fPositron = particleTable->FindParticle("e+");28 fMuon = particleTable->FindParticle("mu+");29 fPion = particleTable->FindParticle("pi+");30 fKaon = particleTable->FindParticle("kaon+");31 fProton = particleTable->FindParticle("proton");32

33 //default particle kinematics

34 fParticleGun->SetParticlePosition(G4ThreeVector(0.,0.,-8.*m));35 fParticleGun->SetParticleDefinition(fPositron);36

37 //define commands for this class

38 DefineCommands();39 }40

41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

42

43 B5PrimaryGeneratorAction::~B5PrimaryGeneratorAction()44 {45 deletefParticleGun;46 deletefMessenger;47 }48

49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

50

51 void B5PrimaryGeneratorAction::GeneratePrimaries(G4Event* event)52 {53 G4ParticleDefinition*particle;54 if(fRandomizePrimary) {55 G4int i = (int)(5.*G4UniformRand());56 switch(i) {57 case 0:58 particle =fPositron;59 break;60 case 1:61 particle =fMuon;62 break;63 case 2:64 particle =fPion;65 break;66 case 3:67 particle =fKaon;68 break;69 default:70 particle =fProton;71 break;72 }73 fParticleGun->SetParticleDefinition(particle);74 }75 else{76 particle = fParticleGun->GetParticleDefinition();77 }78

79 auto pp = fMomentum + (G4UniformRand()-0.5)*fSigmaMomentum;80 auto mass = particle->GetPDGMass();81 auto ekin = std::sqrt(pp*pp+mass*mass)-mass;82 fParticleGun->SetParticleEnergy(ekin);83

84 auto angle = (G4UniformRand()-0.5)*fSigmaAngle;85 fParticleGun->SetParticleMomentumDirection(86 G4ThreeVector(std::sin(angle),0.,std::cos(angle)));87

88 fParticleGun->GeneratePrimaryVertex(event);89 }90

91 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

92

93 voidB5PrimaryGeneratorAction::DefineCommands()94 {95 //Define /B5/generator command directory using generic messenger class

96 fMessenger97 = new G4GenericMessenger(this,98 "/B5/generator/",99 "Primary generator control");100

101 //momentum command

102 auto&momentumCmd103 = fMessenger->DeclarePropertyWithUnit("momentum", "GeV", fMomentum,104 "Mean momentum of primaries.");105 momentumCmd.SetParameterName("p", true);106 momentumCmd.SetRange("p>=0.");107 momentumCmd.SetDefaultValue("1.");108 //ok109 //momentumCmd.SetParameterName("p", true);110 //momentumCmd.SetRange("p>=0.");111

112 //sigmaMomentum command

113 auto&sigmaMomentumCmd114 = fMessenger->DeclarePropertyWithUnit("sigmaMomentum",115 "MeV", fSigmaMomentum, "Sigma momentum of primaries.");116 sigmaMomentumCmd.SetParameterName("sp", true);117 sigmaMomentumCmd.SetRange("sp>=0.");118 sigmaMomentumCmd.SetDefaultValue("50.");119

120 //sigmaAngle command

121 auto&sigmaAngleCmd122 = fMessenger->DeclarePropertyWithUnit("sigmaAngle", "deg", fSigmaAngle,123 "Sigma angle divergence of primaries.");124 sigmaAngleCmd.SetParameterName("t", true);125 sigmaAngleCmd.SetRange("t>=0.");126 sigmaAngleCmd.SetDefaultValue("2.");127

128 //randomizePrimary command

129 auto&randomCmd130 = fMessenger->DeclareProperty("randomizePrimary", fRandomizePrimary);131 G4String guidance132 = "Boolean flag for randomizing primary particle types.\n";133 guidance134 += "In case this flag is false, you can select the primary particle\n";135 guidance += "with /gun/particle command.";136 randomCmd.SetGuidance(guidance);137 randomCmd.SetParameterName("flg", true);138 randomCmd.SetDefaultValue("true");139 }140

141 //..oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

第 54 - 72 行,粒子源随机出射一种粒子。

DefineCommands() 函数中定义了 macro 文件中使用的一些命令,有待研究。

可以使用 G4GeneralParticleSource 替代 G4ParticleGun

“For many applications G4ParticleGun is a suitable particle generator. However if you want to generate primary particles in more sophisticated manner, you can utilize G4GeneralParticleSource, the GEANT4 General Particle Source module (GPS), discussed in the next section ( General Particle Source).” Geant4 手册原话。

代码举例,取自 HPGe_60Co

PrimaryGeneratorAction.hh 文件

1 #ifndef PrimaryGeneratorAction_h2 #define PrimaryGeneratorAction_h 1

3

4 #include "G4VUserPrimaryGeneratorAction.hh"

5 #include "globals.hh"

6

7 classG4GeneralParticleSource;8 classG4Event;9

10 class PrimaryGeneratorAction : publicG4VUserPrimaryGeneratorAction11 {12 public:13 PrimaryGeneratorAction();14 virtual ~PrimaryGeneratorAction();15

16 virtual void GeneratePrimaries(G4Event*);17

18 const G4GeneralParticleSource* GetParticleGun() const {returnfParticleGun;}19

20 //Set methods

21 voidSetRandomFlag(G4bool );22

23 private:24 G4GeneralParticleSource* fParticleGun; //G4 particle gun

25 };26

27 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

28

29 #endif

1 #include "PrimaryGeneratorAction.hh"

2

3 #include "G4LogicalVolumeStore.hh"

4 #include "G4LogicalVolume.hh"

5 #include "G4Box.hh"

6 #include "G4Event.hh"

7 #include "G4ParticleGun.hh"

8 #include "G4GeneralParticleSource.hh"

9 #include "G4ParticleTable.hh"

10 #include "G4ParticleDefinition.hh"

11 #include "G4SystemOfUnits.hh"

12 #include "G4RandomDirection.hh"

13 #include "G4IonTable.hh"

14 #include "G4Geantino.hh"

15

16 #include "Randomize.hh"

17

18 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

19

20 PrimaryGeneratorAction::PrimaryGeneratorAction()21 : G4VUserPrimaryGeneratorAction()22 {23 fParticleGun = newG4GeneralParticleSource();24 }25

26 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

27

28 PrimaryGeneratorAction::~PrimaryGeneratorAction()29 {30 deletefParticleGun;31 }32

33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

34

35 void PrimaryGeneratorAction::GeneratePrimaries(G4Event*anEvent)36 {37 fParticleGun->GeneratePrimaryVertex(anEvent);38 }39

40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

使用 G4GeneralParticleSource 的 PrimaryGeneratorAction 很简单。

1 /run/initialize2 /tracking/verbose 0

3

4

5 /gps/particle ion6 /gps/ion 27 60 0 0

7 /gps/pos/centre 0 0 0mm8

9 /run/beamOn 10000

有关 gps的 macro 文件

得到 60Co 的相关能谱,这个能谱比较好理解。

得到 241Am 能谱,这个就不好理解,241Am alpha 能量约为 5.486 MeV,但得到的能谱却很奇怪。

我认为这是我对使用 gps 产生 alpha 源不熟悉导致的,在 G4 的论坛中有类似的问题,回答中提供的图也有类似的问题,我不理解。https://geant4-forum.web.cern.ch/top/monthly

geant4构造粒子_Geant4 入射粒子设置相关推荐

  1. geant4构造粒子_Geant4基础知识

    可复制.编制,期待你的好评与关注! Geant4 基础知识 G4 模拟粒子过程 : 建立一次模拟,在 G4 中称为一次 Run : Run 建立后,需要对几何结构.物理过 程进行初始化: 初始化完成后 ...

  2. geant4构造粒子_Geant4包罗万象——目录

    Geant4 基础篇 基础0--准备与安装 0 Geant4安装 0.1 系统准备 0.2 安装步骤 1 Geant4知识储备 1.1 核物理学基本知识 1.2 C++堪可:Geant4 基础0--准 ...

  3. geant4构造粒子_Geant4 程序编写中的常用代码

    G4RandGauss::shoot(double mean, double stdDev); //产生高斯分布随机数,等同于CLHEP::RandGaussQ::shoot(double mean, ...

  4. geant4 射线源定义_Geant4 编程基础

    建立一次模拟,在 G4 中称为一次Run:Run 建立后,需要对几何结构.物理过程进行初始化:初始化完成后就开始模拟过程了,首先发射一个粒子.在G4 中,发射一个(或一系列)粒子到所有次级粒子死亡的过 ...

  5. geant4 射线源定义_Geant4入门讲解篇-1

    文|梁佐佐 Geant4,是模拟辐射粒子与物质相互作用的可靠软件工具,有着丰富的物理过程截面库,涉及中子.伽玛(X).电子.质子.各种重离子乃至可衰变核素等各种辐射粒子. 模拟的意义在于通过计算机平台 ...

  6. php webview referer,WebView构造中间页自由设置Referrer

    三.伪造Referrer.增加中间页空白跳转 业务需求:在接入一个第三方支付时,基本流程是生产一个订单,然后后端返回一个URL用浏览器打开,之后就是打开原生的微信或支付宝支付,但其中一家支付厂商的支付 ...

  7. geant4 射线源定义_Geant4基础知识讲解.doc

    Geant4基础 G4模拟粒子过程: 建立一次模拟,在 G4 中称为一次Run:Run 建立后,需要对几何结构.物理过程进行初始化:初始化完成后就开始模拟过程了,首先发射一个粒子.在G4 中,发射一个 ...

  8. html粒子动画效果设置为背景,canvas粒子动画背景的实现示例

    效果 :) 不带连线效果: 带连线的效果: 教程 要实现这样的效果其实很简单,大概分为这么几个步骤: 创建canvas 首先需要在需要展示粒子背景的父元素中创建一个canvas标签, 指定width和 ...

  9. 一个菜鸟的Geant4入门之路:alpha粒子轰击金箔的例子

    一个菜鸟的Geant4入门之路:α\alphaα粒子轰击金箔的例子 文章目录 一个菜鸟的Geant4入门之路:α\alphaα粒子轰击金箔的例子 前言 去哪里找资料: 几个重要的类 一个活的G4程序需 ...

最新文章

  1. AttributeError: 'dict' object has no attribute 'status_code'
  2. 一个不定宽高的元素如何在父元素中垂直水平居中
  3. History(历史)命令用法 15 例
  4. 乙肝疫苗该怎么打(转)
  5. 龙芯派启用串口3-5
  6. 我的HTML总结之常用基础便签
  7. php7.2 函数安装,讲解PHP7.2源码安装
  8. 怎么批量查找关键词-批量查找关键词软件工具
  9. 数字逻辑实验一--组合逻辑电路的设计
  10. [Mac]如何卸载McAfee
  11. crmeb单商户4.4开目录结构 crmeb二开文档 crmeb二开目录结构
  12. cents 7.0命令
  13. 可视化行程管理app_可视化流量:时间行程,扭矩和时间图
  14. 「操作系统」深入理解死锁(什么是死锁?死锁形成条件?如何避免死锁?如何排查死锁?)
  15. 闪光网-彭亮《学后感——彭亮总结》
  16. 计算机机房abc标准,ABC级数据中机房建设要求.doc
  17. 扫地机器人杂牌的怎么样_扫地机器人贵的和便宜的之间有何区别?
  18. LeetCode 518 Coin Change 2 (python)
  19. android手机可以换字体吗,最新版安卓手机怎么换字体?
  20. python sql语句异常捕获_python异常处理

热门文章

  1. 一个40岁老程序员的前端学习之路|2021 年中总结
  2. 一个计算水文质量变化产生的负荷变形的Matlab代码
  3. 安装好mysql后怎么使用_mysql安装后怎么使用
  4. yuv420 YUV422 YUV444格式及存储排列
  5. 2022-2028全球与中国镀镍钢片市场现状及未来发展趋势
  6. 听懂李宗盛的人,未必能听懂毛不易
  7. 关于偶阶幻方双向对称填写方法的探讨
  8. Iphone水货市场要死!
  9. 一文透彻了解缺页异常
  10. java图片如何上传_Java如何将图片上传到服务器