Day 09(下) B2a实例解说----exampleB2a.cc+ActionInitialization+PrimaryGeneratorAction

Day 09(下)exampleB2a.cc+ActionInitialization+PrimaryGeneratorAction

一、exampleB2a.cc

拿到实例怎么样运行(没有类似于cline的软件):首先打开程序所在的文件夹,新建文件夹,进入新文件夹,在终端打开,再cmake

c++ 复制代码
// 打开所在文件夹,进入终端
// 创建新文件夹"b2a",名字任意
mkdir b2a
// 进入文件夹
cd b2a/
// 准备编译
cmake ..
// 编译,正常最好不要出现warning
make
// 打开并可视化生成的范例文件exampleB2a
./exampleB2a  // 此时参数个数为1
./exampleB2a test.mac // 此时参数大于1,运行自写的mac文件test

exampleB2a.cc

c++ 复制代码
// 定义了step max,并且使用了G4写好的physicslist,若不使用,就自写step max
physicsList->RegisterPhysics(new G4StepLimiterPhysics());
// 给可视化界面+一个菜单gui.mac
if (ui->IsGUI()) {
      UImanager->ApplyCommand("/control/execute gui.mac");
    }
二、ActionInitialization

该程序中的所有Action类需要在此中进行初始化

c++ 复制代码
// 初始化
void ActionInitialization::BuildForMaster() const
{
  SetUserAction(new RunAction);//针对于多线程的设置
}
void ActionInitialization::Build() const
{
  SetUserAction(new PrimaryGeneratorAction);
  SetUserAction(new RunAction);
  SetUserAction(new EventAction);
}
三、PrimaryGeneratorAction

G4单位定义上是一个数值,所以设置时的单位都是带上的用*连接,其中

Mev<<Gev<<mm<<cm<<G4endl

c++ 复制代码
// 设置相关数值
G4ParticleDefinition* particleDefinition =
    G4ParticleTable::GetParticleTable()->FindParticle("proton");//"proton"发射的为质子

  fParticleGun->SetParticleDefinition(particleDefinition);//发射的是一个质子
  fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0., 0., 1.));//发射方向001
  fParticleGun->SetParticleEnergy(3.0 * GeV);//发射能量3Gev

void PrimaryGeneratorAction::GeneratePrimaries(G4Event* event)
{
  G4double worldZHalfLength = 0;
  //设置粒子枪大小时,根据世界大小进行设置,该方法获得设置的世界的logicalvolume
  G4LogicalVolume* worldLV = G4LogicalVolumeStore::GetInstance()->GetVolume("World");
  G4Box* worldBox = nullptr;
  //根据logicalvolume获取solidvolume,也就是worldBox
  if (worldLV) worldBox = dynamic_cast<G4Box*>(worldLV->GetSolid());
  //然后根据solidvolume获取一半的长度,然后就可以设置粒子枪的位置,一半初始在边界的位置
  if (worldBox)
    worldZHalfLength = worldBox->GetZHalfLength();
  else {
    G4cerr << "World volume of box not found." << G4endl;
    G4cerr << "Perhaps you have changed geometry." << G4endl;
    G4cerr << "The gun will be place in the center." << G4endl;
  }
  //粒子枪的位置
  fParticleGun->SetParticlePosition(G4ThreeVector(0., 0., -worldZHalfLength + 1 * um));
//发射event
  fParticleGun->GeneratePrimaryVertex(event);
}
相关推荐
西岸行者5 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习
starlaky5 天前
Django入门笔记
笔记·django
勇气要爆发5 天前
吴恩达《LangChain LLM 应用开发精读笔记》1-Introduction_介绍
笔记·langchain·吴恩达
悠哉悠哉愿意5 天前
【单片机学习笔记】串口、超声波、NE555的同时使用
笔记·单片机·学习
勇气要爆发5 天前
吴恩达《LangChain LLM 应用开发精读笔记》2-Models, Prompts and Parsers 模型、提示和解析器
android·笔记·langchain
qq_459234425 天前
【题库】| 商用密码应用安全性评估从业人员考核题库(四十)
职场和发展·密码学·学习方法·考核·商用密码·商用密码应用安全性评估·密评
AKA__Zas5 天前
初识基本排序
java·数据结构·学习方法·排序
qianshanxue115 天前
计算机操作的一些笔记标题
笔记
土拨鼠烧电路5 天前
笔记11:数据中台:不是数据仓库,是业务能力复用的引擎
数据仓库·笔记
土拨鼠烧电路5 天前
笔记14:集成与架构:连接孤岛,构建敏捷响应能力
笔记·架构