G4-ExampleB1/exampleB1.cc

68 lines
2.2 KiB
C++
Raw Normal View History

2022-04-29 13:24:29 +08:00
#include "ActionInitialization.hh" // 用户初始化
#include "DetectorConstruction.hh" // 探测器构建文件
#include "G4RunManagerFactory.hh" // 管理类
#include "G4SteppingVerbose.hh" // step信息管理 verbose越大输出越丰富
#include "G4UIExecutive.hh" // UI操作
#include "G4UImanager.hh" // UI管理
#include "G4VisExecutive.hh" // 可视化
#include "QBBC.hh" // 物理过程
#include "Randomize.hh" // 随机数
using namespace B1;
int main(int argc, char** argv) {
// argc 为 1 时说明参数只有可执行文件本身运行在GUI模式下
// 如果 argc 不为 1则运行在 batch mode例如 example.exe run1.mac
G4UIExecutive* ui = nullptr;
if (argc == 1) {
ui = new G4UIExecutive(argc, argv);
}
// 调整 step 的输出信息
G4int precision = 4;
G4SteppingVerbose::UseBestUnit(precision);
// 构建运行管理器
auto* runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
// 进行强制类的初始化
//
// 探测器构建
runManager->SetUserInitialization(new DetectorConstruction());
// 物理过程列表
G4VModularPhysicsList* physicsList = new QBBC;
physicsList->SetVerboseLevel(1);
runManager->SetUserInitialization(physicsList);
// 用户初始化
runManager->SetUserInitialization(new ActionInitialization());
// 可视化初始化
// G4VisExecutive 可以输入 verbose 参数,用于控制输出的详细程度
// https://www.hep.ph.ic.ac.uk/~yoshiu/COMET/comet_g4HTMLdoc/_vis_.html
G4VisManager* visManager = new G4VisExecutive;
visManager->Initialize();
// 用户界面管理器的指针
G4UImanager* UImanager = G4UImanager::GetUIpointer();
// 根据模式选择开始进行模拟或打开GUI
//
if (!ui) {
// batch mode
G4String command = "/control/execute ";
G4String fileName = argv[1];
UImanager->ApplyCommand(command + fileName);
} else {
// interactive mode
UImanager->ApplyCommand("/control/execute init_vis.mac");
ui->SessionStart();
delete ui;
}
// 释放指针
delete visManager;
delete runManager;
}