commit
f36f321539
@ -0,0 +1 @@ |
||||
build/ |
@ -0,0 +1,24 @@ |
||||
{ |
||||
"configurations": [ |
||||
{ |
||||
"name": "Win32", |
||||
"includePath": [ |
||||
"${default}", |
||||
"${workspaceFolder}/include", |
||||
"D:/Geant4/dist/include/Geant4" |
||||
], |
||||
"defines": [ |
||||
"_DEBUG", |
||||
"UNICODE", |
||||
"_UNICODE" |
||||
], |
||||
"windowsSdkVersion": "10.0.19041.0", |
||||
"compilerPath": "D:/Microsoft/VisualStudio/2022/Community/VC/Tools/MSVC/14.31.31103/bin/Hostx64/x64/cl.exe", |
||||
"cStandard": "c17", |
||||
"cppStandard": "c++17", |
||||
"intelliSenseMode": "windows-msvc-x64", |
||||
"configurationProvider": "ms-vscode.cmake-tools" |
||||
} |
||||
], |
||||
"version": 4 |
||||
} |
@ -0,0 +1,5 @@ |
||||
{ |
||||
"cmake.configureSettings": { |
||||
"CMAKE_TOOLCHAIN_FILE": "D:/Microsoft/vcpkg/scripts/buildsystems/vcpkg.cmake" |
||||
} |
||||
} |
@ -0,0 +1,33 @@ |
||||
cmake_minimum_required(VERSION 3.16) |
||||
set(Geant4_DIR D:/Geant4/dist/lib/Geant4-11.0.1) |
||||
|
||||
project(exampleB0) |
||||
|
||||
option(WITH_GEANT4_UIVIS "Build example with Geant4 UI and Vis drivers" ON) |
||||
if(WITH_GEANT4_UIVIS) |
||||
find_package(Geant4 REQUIRED ui_all vis_all) |
||||
else() |
||||
find_package(Geant4 REQUIRED) |
||||
endif() |
||||
|
||||
include(${Geant4_USE_FILE}) |
||||
include_directories(${PROJECT_SOURCE_DIR}/include) |
||||
|
||||
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cpp) |
||||
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.h) |
||||
|
||||
add_executable(exampleB0 main.cpp ${sources} ${headers}) |
||||
target_link_libraries(exampleB0 ${Geant4_LIBRARIES}) |
||||
|
||||
set(exampleB0_SCRIPTS |
||||
auto.mac |
||||
vis.mac |
||||
) |
||||
|
||||
foreach(_script ${exampleB0_SCRIPTS}) |
||||
configure_file( |
||||
${PROJECT_SOURCE_DIR}/${_script} |
||||
${PROJECT_BINARY_DIR}/Release/${_script} |
||||
COPYONLY |
||||
) |
||||
endforeach() |
@ -0,0 +1,12 @@ |
||||
{ |
||||
"folders": [ |
||||
{ |
||||
"path": "." |
||||
} |
||||
], |
||||
"settings": { |
||||
"files.associations": { |
||||
"*.icc": "cpp" |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,15 @@ |
||||
# 多线程设置 |
||||
/run/numberOfThreads 1 |
||||
|
||||
# verbose |
||||
/control/verbose 2 |
||||
/run/verbose 2 |
||||
/event/verbose 2 |
||||
/tracking/verbose 2 |
||||
|
||||
# 初始化 |
||||
/run/initialize |
||||
|
||||
/gun/particle gamma |
||||
/gun/energy 6 MeV |
||||
/run/beamOn 3 |
@ -0,0 +1,11 @@ |
||||
#ifndef GEOMETRY |
||||
#define GEOMETRY |
||||
|
||||
#include "G4VUserDetectorConstruction.hh" |
||||
|
||||
class DetectorConstruction : public G4VUserDetectorConstruction { |
||||
public: |
||||
virtual G4VPhysicalVolume* Construct(); |
||||
}; |
||||
|
||||
#endif |
@ -0,0 +1,19 @@ |
||||
#ifndef SOURCE |
||||
#define SOURCE |
||||
|
||||
#include "G4VUserPrimaryGeneratorAction.hh" |
||||
#include "G4ParticleGun.hh" |
||||
|
||||
class G4Event; |
||||
|
||||
class GeneratorAction : public G4VUserPrimaryGeneratorAction { |
||||
public: |
||||
GeneratorAction(); |
||||
~GeneratorAction(); |
||||
virtual void GeneratePrimaries(G4Event* e); |
||||
|
||||
private: |
||||
G4ParticleGun* particleGun; |
||||
}; |
||||
|
||||
#endif |
@ -0,0 +1,45 @@ |
||||
#include "QGSP_BERT.hh" |
||||
#include "G4MTRunManager.hh" |
||||
#include "G4VUserActionInitialization.hh" |
||||
#include "G4UImanager.hh" |
||||
#include "G4UIExecutive.hh" |
||||
#include "G4VisExecutive.hh" |
||||
|
||||
#include "Geometry.h" |
||||
#include "ParticleSource.h" |
||||
|
||||
class ActionInitialzation : public G4VUserActionInitialization { |
||||
public: |
||||
virtual void Build() const{ |
||||
SetUserAction(new GeneratorAction); |
||||
} |
||||
}; |
||||
|
||||
int main(int argc, char** argv) { |
||||
G4UIExecutive* ui = nullptr; |
||||
if (argc == 1) |
||||
ui = new G4UIExecutive(argc, argv); |
||||
|
||||
auto runManager = new G4MTRunManager; |
||||
auto visManager = new G4VisExecutive; |
||||
auto UIManager = G4UImanager::GetUIpointer(); |
||||
|
||||
runManager->SetUserInitialization(new DetectorConstruction()); |
||||
runManager->SetUserInitialization(new QGSP_BERT()); |
||||
runManager->SetUserInitialization(new ActionInitialzation()); |
||||
|
||||
visManager->Initialize(); |
||||
if ( !ui ) { |
||||
G4String command = "/control/execute"; |
||||
G4String fileName = argv[1]; |
||||
UIManager->ApplyCommand(command + fileName); |
||||
} else { |
||||
UIManager->ApplyCommand("/control/execute vis.mac"); |
||||
ui->SessionStart(); |
||||
delete ui; |
||||
} |
||||
|
||||
delete runManager; |
||||
delete visManager; |
||||
return 0; |
||||
} |
@ -0,0 +1,27 @@ |
||||
#include "Geometry.h" |
||||
|
||||
#include "G4Box.hh" |
||||
#include "G4NistManager.hh" |
||||
#include "G4LogicalVolume.hh" |
||||
#include "G4SystemOfUnits.hh" |
||||
#include "G4PVPlacement.hh" |
||||
|
||||
G4VPhysicalVolume* DetectorConstruction::Construct() { |
||||
// Solid
|
||||
auto solid_world = new G4Box("world", 638 / 2 * mm, 630 / 2 * mm, 555. / 2 * mm); |
||||
// Logic
|
||||
auto nist = G4NistManager::Instance(); |
||||
auto logic_world = new G4LogicalVolume(solid_world, nist->FindOrBuildMaterial("G4_WATER"), "world"); |
||||
// Physics
|
||||
auto physics_world = new G4PVPlacement( |
||||
0, |
||||
G4ThreeVector(0, 0, 0), |
||||
logic_world, |
||||
"world", |
||||
0, |
||||
false, |
||||
0, |
||||
true |
||||
); |
||||
return physics_world; |
||||
} |
@ -0,0 +1,22 @@ |
||||
#include "ParticleSource.h" |
||||
|
||||
#include "G4ParticleTable.hh" |
||||
#include "G4SystemOfUnits.hh" |
||||
|
||||
GeneratorAction::GeneratorAction() { |
||||
auto table = G4ParticleTable::GetParticleTable(); |
||||
|
||||
particleGun = new G4ParticleGun(1); |
||||
particleGun->SetParticleDefinition(table->FindParticle("gamma")); |
||||
particleGun->SetParticlePosition(G4ThreeVector(0, 0, 555. / 2 * mm)); |
||||
particleGun->SetParticleMomentumDirection(G4ThreeVector(0, 0, -1)); |
||||
particleGun->SetParticleEnergy(1 * MeV); |
||||
} |
||||
|
||||
GeneratorAction::~GeneratorAction() { |
||||
delete particleGun; |
||||
} |
||||
|
||||
void GeneratorAction::GeneratePrimaries(G4Event* e) { |
||||
particleGun->GeneratePrimaryVertex(e); |
||||
} |
@ -0,0 +1,30 @@ |
||||
# 多线程设置 |
||||
/run/numberOfThreads 1 |
||||
|
||||
# verbose |
||||
/control/verbose 2 |
||||
/control/saveHistory |
||||
/run/verbose 2 |
||||
|
||||
# 初始化 |
||||
/run/initialize |
||||
|
||||
# 设置视图,使用OpenGL |
||||
/vis/open OGL 800x800-0+0 |
||||
|
||||
# 禁止自动刷新,消息静音(除错误外) |
||||
/vis/viewer/set/autoRefresh false |
||||
/vis/verbose errors |
||||
|
||||
# 绘制集合体 |
||||
/vis/drawVolume |
||||
|
||||
# 绘制轨迹 类型为平滑 |
||||
/vis/scene/add/trajectories smooth |
||||
# 根据粒子ID进行绘制 |
||||
/vis/modeling/trajectories/create/drawByParticleID |
||||
# 以2px的宽度绘制节点 |
||||
/vis/modeling/trajectories/drawByParticleID-0/default/setDrawStepPts true |
||||
/vis/modeling/trajectories/drawByParticleID-0/default/setStepPtsSize 2 |
||||
# 保留、叠加所有事例 |
||||
/vis/scene/endOfEventAction accumulate |
Loading…
Reference in new issue