注意:
cp /opt/Geant4/geant41004/share/Geant4-10.4.0/examples/basic /home/username/
cd /home/username/B1
mkdir build
cd build
cmake ..
make -j8
make install
./exampleB1
建议学习一下cmake语法及其相关功能
运行结果如图:
run1.mac
init_vis.mac
vis.mac
核心:我们是使用Geant4代码,不要造轮子,关键在于找到Geant4中需要的代码!!!
Shape1 and Shape2
即World中有Envelop,Envelop中有两个Shape
solid volume
logcial volume
physical volume
相关具体代码以及使用说明请查看Geant4说明书
知识点-如何判断粒子已经死亡
调用类:G4Material
Define a Material from the Geant4 Material Database-利用G4的材料库(B1用的此方法)
G4NistManager* man = G4NistManager::Instance();
G4Material* H2O = man->FindOrBuildMaterial("G4_WATER");
G4Material* Air = man->FindOrBuildMaterial("G4_AIR");
Define a Material from the Base Material-利用Material类自己定义
G4double density;
density = 1.05*mg/cm3;
G4Material* water1 = new G4Material("Water_1.05",density,"G4_WATER");
density = 1.03*mg/cm3;
G4NistManager* man = G4NistManager::Instance();
G4Material* water2 = man->BuildMaterialWithNewDensity("Water_1.03","G4_WATER",density);
调用类:G4Isotope(同位素)和G4Element(元素),根据需求自己定义
Define by number of atoms per each element in the molecule
a = 1.01*g/mole;
G4Element* ele_H = new G4Element("Hydrogen",symbol="H",z=1.,a);
a = 16.00*g/mole;
G4Element* ele_O = new G4Element("Oxygen",symbol="O",z=8.,a);
density = 1.000*g/cm3;
G4Material* H2O = new G4Material("Water",density,ncomp=2);
G4int natoms;
H2O->AddElement(ele_H, natoms = 2);
H2O->AddElement(ele_O, natoms = 1);
Define by fraction of mass of each element in the material
a = 14.01*g/mole;
G4Element* ele_N = new G4Element(name="Nitrogen",symbol="N",z=7.,a);
a = 16.00*g/mole;
G4Element* ele_O = new G4Element(name="Oxygen",symbol="O",z=8.,a);
density = 1.290*g/cm3;
G4Material* Air = new G4Material(name="Air",density,ncomponents=2);
G4double fracMass;
Air->AddElement(ele_N, fracMass = 70.0*perCent);
Air->AddElement(ele_O, fracMass = 30.0*perCent);
//G4Isotope* [Isoname] = new G4Isotope(...);
//Air->AddMaterial(...);
可查看G4中自带的示例:examples/extended/electromagnetic/TestEm0/
B1PrimaryGeneratorAction.cc实现粒子发射
B1中发射粒子代码
fParticleGun->SetParticleDefinition(particle);//粒子种类
fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));//粒子方向
fParticleGun->SetParticleEnergy(6.*MeV);//粒子能量
fParticleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));//粒子发射位置
在run1.mac中也可以修改发射粒子种类、能量,前提需要在代码中留出对应的代码功能!
set(YB_LIB_DIR /[filepath]/sim/yblib)
set(ROOT_INCLUDE_DIR /opt/root61600/include)
cmake ..
运行`make -j8',生成可执行文件sim
运行./sim
运行 ./sim vis结果如图:
!jupyter nbconvert geant4note_xi.ipynb --to html