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. 【组队学习】【35期】吃瓜教程——西瓜书+南瓜书
  2. 昨天还在 for 循环里写加号拼接字符串的那个同事,今天已经不在了
  3. Python常用包的使用
  4. 最近一月的娱乐生活:看电影,玩游戏
  5. GDCM:生成标准SOP类的测试程序
  6. Callable接口
  7. javaheapspace解决方案_高手总结的9种 OOM 常见原因及解决方案
  8. 如何使用JavaScript控制台:超越console.log()
  9. 你需知道的MFI:mean, Median,Mode及Geometric Mean 之比较
  10. 永城职业学院计算机专业分类,计算机专业师资队伍
  11. 无法更新 TeamViewer 服务属性是什么意思?
  12. Redis详细使用文档记录
  13. 举个栗子~ Minitab 技巧(1):快速安装和激活 Minitab 统计软件
  14. Dart基础之Isolate
  15. 2023年京东炸年兽脚本《京东炸年兽活动脚本》
  16. python中怎么计数_python怎么计数
  17. 广西大学计算机考研资料汇总
  18. 【其它】Mac配置输入法切换快捷键
  19. 考虑交通网络流量的电动汽车充电站规划matlab 采用matlab软件参照相关资料完成电动汽车程序
  20. 十六、Linux驱动之块设备驱动

热门文章

  1. Flutter 语言国际化状态管理
  2. Java基础系列五之API
  3. 运维教程之Microsoft SQL server 2008 R2图文+视频安装
  4. 【愚公系列】2023年05月 攻防世界-Web(easyupload)
  5. mac 安装 brew 异常 fatal: unable to access ‘https://github.com/Homebrew/brew
  6. 冒泡php_php冒泡排序法
  7. Python绘制股票日K图(九)给折线图加标签
  8. tomcat8-maven-plugin依赖下载失败问题
  9. mac os 非活跃内存
  10. UML学习笔记(五)--顺序图