【Geant4】Geometry
- 格式:pdf
- 大小:330.36 KB
- 文档页数:35
Geant4基础知识G4模拟粒子过程:建立一次模拟,在G4 中称为一次Run;Run 建立后,需要对几何结构、物理过程进行初始化;初始化完成后就开始模拟过程了,首先发射一个粒子。
在G4 中,发射一个(或一系列)粒子到所有次级粒子死亡的过程成为一次Event 。
而每次发射的初始粒子则有粒子发射器进行控制。
而在每一个event 过程中,粒子与材料反应后会可能生成多个次级粒子,每个粒子都会有一条径迹,称之为track ;而每一个粒子(初始的或次级的)的径迹又是由很多步组成的,称之为step 。
G4模拟的基本算法:A Run Start -> 初始化物理模型/ 几何模型-> An Event Start -> 调用粒子发射器发射粒子-> A Track Start-> A Step Start-> A Step End-> Next Step Start- > ,,-> All Step End-> A Track End-> Next Track Start-> ,,-> All Track End-> An Event End -> Next Event Start- > ,,-> All Event End(All Primaries Shot) -> A Run End -> Next Run Start- > ,,1) main() 中应该包括的内容Geant4 是一个探测器模拟工具, 但它对于某个特定的模拟程序没有固定的main() 函数, 用户在建立模拟程序的过程中需要提供自己的main() 函数. 一个最基本的main() 函数需要包括以下几个方面:G4RunManager( 模拟整个过程)G4VUserDetectorConstruction( 定义探测器材料, 几何形状, 灵敏区和读出方案)G4VUserPhysicsList( 定义粒子种类和物理过程, 还有截断参数)G4VUserPrimaryGeneratorAction( 定义了源粒子的种类, 能量, 出射方向等)一个最简单的main() 函数如下:#include "G4RunManager.hh"#include "G4UImanager.hh"#include "ExN01DetectorConstruction.hh"#include "ExN01PhysicsList.hh"#include "ExN01PrimaryGeneratorAction.hh"int main(){// Construct the default run managerG4RunManager* runManager = new G4RunManager;// set mandatory initialization classesrunManager->SetUserInitialization(new ExN01DetectorConstruction); runManager->SetUserInitialization(new ExN01PhysicsList);// set mandatory user action classrunManager->SetUserAction(new ExN01PrimaryGeneratorAction);// Initialize G4 kernelrunManager->Initialize();// get the pointer to the UI manager and set verbositiesG4UImanager* UI = G4UImanager::GetUIpointer();UI->ApplyCommand("/run/verbose 1");UI->ApplyCommand("/event/verbose 1");UI->ApplyCommand("/tracking/verbose 1");// start a runint numberOfEvent = 3;runManager->BeamOn(numberOfEvent);// job terminationdelete runManager;return 0;}main() 首先生成一个G4RunManager类,这个类是在主程序中用以初始化模拟信息,用来连接子程序,连接方式是通过Set 函数来完成。
Geant4基础知识G4模拟粒子过程:建立一次模拟,在 G4 中称为一次Run;Run 建立后,需要对几何结构、物理过程进行初始化;初始化完成后就开始模拟过程了,首先发射一个粒子。
在G4 中,发射一个(或一系列)粒子到所有次级粒子死亡的过程成为一次 Event。
而每次发射的初始粒子则有粒子发射器进行控制。
而在每一个event过程中,粒子与材料反应后会可能生成多个次级粒子,每个粒子都会有一条径迹,称之为 track;而每一个粒子(初始的或次级的)的径迹又是由很多步组成的,称之为step。
G4模拟的基本算法:A Run Start -> 初始化物理模型/几何模型-> An Event Start -> 调用粒子发射器发射粒子-> A Track Start-> A Step Start-> A Step End-> Next Step Start-> ……-> All Step End-> A Track End-> Next Track Start-> ……-> All Track End-> An Event End -> Next Event Start-> ……-> All Event End(All Primaries Shot) -> A Run End -> Next Run Start-> ……1) main()中应该包括的内容Geant4是一个探测器模拟工具, 但它对于某个特定的模拟程序没有固定的main()函数, 用户在建立模拟程序的过程中需要提供自己的main()函数. 一个最基本的main()函数需要包括以下几个方面:G4RunManager(模拟整个过程)G4VUserDetectorConstruction(定义探测器材料, 几何形状, 灵敏区和读出方案)G4VUserPhysicsList(定义粒子种类和物理过程, 还有截断参数)G4VUserPrimaryGeneratorAction(定义了源粒子的种类, 能量, 出射方向等)一个最简单的main()函数如下:#include "G4RunManager.hh"#include "G4UImanager.hh"#include "ExN01DetectorConstruction.hh"#include "ExN01PhysicsList.hh"#include "ExN01PrimaryGeneratorAction.hh"int main(){// Construct the default run managerG4RunManager* runManager = new G4RunManager;// set mandatory initialization classesrunManager->SetUserInitialization(new ExN01DetectorConstruction);runManager->SetUserInitialization(new ExN01PhysicsList);// set mandatory user action classrunManager->SetUserAction(new ExN01PrimaryGeneratorAction);// Initialize G4 kernelrunManager->Initialize();// get the pointer to the UI manager and set verbositiesG4UImanager* UI = G4UImanager::GetUIpointer();UI->ApplyCommand("/run/verbose 1");UI->ApplyCommand("/event/verbose 1");UI->ApplyCommand("/tracking/verbose 1");// start a runint numberOfEvent = 3;runManager->BeamOn(numberOfEvent); // job terminationdelete runManager;return 0;}main()首先生成一个 G4RunManager类,这个类是在主程序中用以初始化模拟信息,用来连接子程序,连接方式是通过 Set函数来完成。
ContentsIntroductionG4VUserDetectorConstruction class Solid and shapeLogical volumeIntroductionG4VUserDetectorConstructionUser classesmain()Geant4 does not provide main().Note : classes written in yellow are mandatory.Initialization classesUse G4RunManager::SetUserInitialization() to define.Invoked at the initializationG4VUserDetectorConstructionG4VUserPhysicsListAction classesUse G4RunManager::SetUserAction() to define.Invoked during an event loopG4VUserPrimaryGeneratorActionG4UserRunActionG4UserEventActionG4UserStackingActionG4UserTrackingActionG4UserSteppingActionConstruct() should return the pointer of the world physical volume. The world physical volume represents all of yourYour detector construction #ifndef MyDetctorConstruction_h#define MyDetctorConstruction_h1#include “G4VUserDetectorConstruction.hh”class MyDetctorConstruction: public G4VUserDetectorConstruction{public:G4VUserDetectorConstruction();virtual ~G4VUserDetectorConstruction();virtual G4VPhysicalVolume* Construct(); public:// set/get methods if neededprivate:// granular private methods if needed// data members if needed};#endifDescribe your detectorDerive your own concrete class from G4VUserDetectorConstruction abstract base class.Implement the method Construct()1)Construct all necessary materials2)Define shapes/solids3)Define logical volumes4)Place volumes of your detector geometry5)Associate (magnetic) field to geometry (optional)6)Instantiate sensitive detectors / scorers and set them to corres pondingvolumes (optional)7)Define visualization attributes for the detector elements (optional)8)Define regions (optional)Set your construction class to G4RunManagerIt is suggested to modularize Construct() method w.r.t. each component or sub-detector for easier maintenance of your code.Solid and shapeG4VSolidAbstract class. All solids in Geant4 are derived from itIt defines but does not implement all functions required to:compute distances between the shape and a given pointcheck whether a point is inside the shapecompute the extent of theshapecompute the surface normal to the shape at a given pointUser can create his/her own solid classSolidsSolids defined in Geant4:CSG (Constructed Solid Geometry) solidsG4Box, G4Tubs, G4Cons, G4Trd, …Analogous to simple GEANT3 CSG solids Specific solids (CSG like)G4Polycone, G4Polyhedra, G4Hype, …BREP (Boundary REPresented) solidsG4BREPSolidPolycone, G4BSplineSurface, …Any order surfaceBoolean solidsG4UnionSolid, G4SubtractionSolid, …Tessellated solid and Extruded solidCSG: G4Box, G4TubsG4Box(const G4String &pname, // nameG4double half_x, // X half sizeG4double half_y, // Y half sizeG4double half_z); // Z half sizeG4Tubs(const G4String &pname, // nameG4double pRmin, // inner radiusG4double pRmax, // outer radiusG4double pDz, // Z half lengthG4double pSphi, // starting PhiG4double pDphi); // segment angleOther CSG solidsG4ConsG4Para(parallelepiped)G4TrdG4TrapG4SphereG4OrbG4TorusConsult to Section 4.1.2 of Geant4Application Developers Guide forall available shapes.Specific CSG Solids: G4Polycone G4Polycone(const G4String& pName,G4double phiStart,G4double phiTotal,G4int numRZ,const G4double r[],const G4double z[]);numRZ-numbers of corners in the r,z spacer, z-coordinates of cornersOther Specific CSG solidsG4PolyhedraG4EllipticalTubeG4EllipsoidG4EllipticalConeG4HypeG4Tet (tetrahedra)G4TwistedBoxG4TwistedTrdG4TwistedTrapG4TwistedTubsConsult to Section 4.1.2 of Geant4 Application Developers Guide for all available shapes.BREP Solids BREP = Boundary REPresented SolidListing all its surfaces specifies a solide.g. 6 planes for a cubeSurfaces can beplanar, 2nd or higher orderelementary BREPSSplines, B-Splines,NURBS (Non-Uniform B-Splines)advanced BREPSFew elementary BREPS pre-definedbox, cons, tubs, sphere, torus, polycone, polyhedraAdvanced BREPS built through CAD systemsBoolean Solids -exampleG4VSolid* box = new G4Box(“Box",50*cm,60*cm,40*cm);G4VSolid* cylinder= new G4Tubs(“Cylinder”,0.,50.*cm,50.*cm,0.,2*M_PI*rad);G4VSolid* union= new G4UnionSolid("Box+Cylinder", box, cylinder);G4VSolid* subtract= new G4SubtractionSolid("Box-Cylinder", box, cylinder, 0, G4ThreeVector(30.*cm,0.,0.));G4RotationMatrix* rm= new G4RotationMatrix();rm->RotateX(30.*deg);G4VSolid* intersect= new G4IntersectionSolid("Box&&Cylinder",box, cylinder, rm, G4ThreeVector(0.,0.,0.));The origin and the coordinates of the combined solid are the sam e as those of the first solid.Tessellated solidsG4TessellatedSolid(since 8.1)Generic solid defined by a number of facets (G4VFacet)Facets can be triangular (G4TriangularFacet) or quadrangular(G4QuadrangularFacet)Constructs especially important for conversion of complex geometrical shapes imported from CAD systemsBut can also be explicitly defined:By providing the vertices of the facets in anti-clock wise order, inabsolute or relative reference frameGDML bindingA CAD imported assembly with tessellated solids -release 8.1G4ExtrudedSolid G4ExtrudedSolid, which wasintroduced in v8.3, is a specificcase of tessellated solid.G4ExtrudedSolid is a solid whichrepresents the extrusion of anarbitrary polygon with fixedoutline in the defined Z sections.The z-sides of the solid are thescaled versions of the samepolygon.The solid is implemented as aspecification ofG4TessellatedSolid.G4LogicalVolumeG4LogicalVolumeG4LogicalVolume(G4VSolid*pSolid,G4Material*pMaterial,const G4String &name,G4FieldManager *pFieldMgr=0,G4VSensitiveDetector *pSDetector=0,G4UserLimits *pULimits=0);Contains all information of volume except position and rotation Shape and dimension (G4VSolid)Material, sensitivity, visualization attributesPosition of daughter volumesMagnetic field, User limits,RegionPhysical volumes of same type can share the common logical volum e object. The pointers to solid must NOT be null.The pointers to material must NOT be null for tracking geometry.It is not meant to act as a base class.Computing volumes and weightsGeometrical volume of a generic solid or boolean composition can be computed from the solid:G4double GetCubicVolume();Exact volume is determinatively calculated for most of CSG solid s, while estimation based on Monte Carlo integration is given for other s olids.Overall weight of a geometry setup (sub-geometry) can be computed from the logical volume:G4double GetMass(G4bool forced=false,G4bool propagate=true, G4Material* pMaterial=0);The computation may require a considerable amount of time, depen ding on the complexity of the geometry.The return value is cached and reused until forced=true.Daughter volumes will be neglected if propagate=false.Backup (G4Region)RegionA region may have its uniqueProduction thresholds (cuts)If a region in the mass geometry does not have its own productio nthresholds, those of the default region are used (i.e., may not be thoseof the parent region).User limitsYou can set user limits directly to logical volume as well. If b oth logicalvolume and associated region have user limits, those of logical volumewins.User region informationE.g. to implement a fast Boolean method to identify the nature o f theregion.Fast simulation managerShower envelopeRegional user stepping action (new with version 9.0)Please note :World logical volume is recognized as the default region. User is not allowed to define a region to the world logical volume.G4RegionA region is instantiated and defined byG4Region* aRegion= new G4Region(“region_name”);aRegion->AddRootLogicalVolume(aLogicalVolume);Region propagates down to all geometrical hierarchy until the bottom or another root logical volume.Production thresholds (cuts) can be assigned to a region byG4Region* aRegionGetRegion(“region_name”);= G4RegionStore::GetInstance()->GetRegionG4ProductionCuts* cuts = new G4ProductionCuts;cuts->SetProductionCut(cutValue);aRegion->SetProductionCuts(cuts);。
应用Geant4计算光子外照射对人体产生的有效剂量李明生;欧向明;牛昊巍;程金生【摘要】在Geant4中构建ORNL程式化混合模体,应用此模体计算不同能量下平行光子入射的人体有效剂量.计算结果以吸收剂量与空气比释动能比值的形式呈现.计算结果与ICRP74值进行了对比验证.【期刊名称】《中国医学装备》【年(卷),期】2010(007)007【总页数】4页(P14-17)【关键词】ORNL模体;有效剂量;蒙特卡洛方法;光子【作者】李明生;欧向明;牛昊巍;程金生【作者单位】中国疾病预防控制中心辐射防护与核安全医学所,北京,100088;中国疾病预防控制中心辐射防护与核安全医学所,北京,100088;中国疾病预防控制中心辐射防护与核安全医学所,北京,100088;中国疾病预防控制中心辐射防护与核安全医学所,北京,100088【正文语种】中文【中图分类】R1441 引言有效剂量是辐射防护中的一个重要的危险评估量,有效剂量作为防护量,无法直接测量。
一种方法是应用蒙卡程序模拟出重要辐射敏感器官的当量剂量,根据ICRP60报告[1]中的辐射敏感器官组织权重因子得到有效剂量;另外一种是通过已经算好的器官剂量转化系数得到人体有效剂量,例如ICRP74报告[2]中的器官剂量转化系数。
在蒙卡软件Geant4中构建一个ORNL[3]混合模体,应用此模体计算人体侧面照射时的有效剂量。
混合模体是指把男性与女性的一些性器官组合到一起形成的模体,应用此模体可以直接计算各种几何条件下人体器官的当量剂量值和人体有效剂量。
模体主要器官体积与参考体积进行了对比,有效剂量值与ICRP74报告中的系数值进行了对比验证。
2 材料和方法2.1 Geant4中构建模体方法Geant是英文“几何与追踪”(Geometry And Tracking)的缩写,是一种利用蒙特卡洛模拟粒子通过物质整个物理过程的软件平台。
这个软件适用于几乎所有已知的物理粒子,并且可以覆盖绝大多数的粒子反映过程。
猪头Geant4讲座第六讲——几何模型管理提醒: 本帖被medphys 执行压帖操作(2009-10-03)本讲座为蒙卡学术论坛()专题讲座,任何人未经作者本人许可不得转载至其他论坛,作者保留追究转载者相关责任的权利!上一讲我们讲过了,几何结构类(DetectorConstruction)属于强制初始化类,其主要功能是构建模拟问题的几何结构,包括各部分的材料、形状、尺寸、位置等信息。
前面我讲了材料如何定义,今天我主要讲几何模型的建立以及各部分材料的设置。
在讲如何建立几何模型前我想首先讲一下Geant4中所采用的几何建模思想。
学过MCNP或Fluka的都知道MCNP和Fluka采用的是CG模型,所谓CG模型就是Co mbination Geometry,我习惯翻译为组合几何模型,CG模型顾名思义就是整个模型由一块块小模块组合而成,打个不恰当的比方就是搭积木。
这种模型的要求就是“不交不空”,既不能有相交的部分,也不能有空白的地方。
CG模型是粒子输运蒙卡模拟中非常常用的一种。
Geant4采用的模型则不同,目前我没看到有关此模型的确切名称,但我习惯将之称为嵌套模型或盒子模型,因为其建模的方式就如往大盒子里放小盒子。
在Geant4中首先我们要建立一个最大的盒子,称为World Volume,然后往这个大盒子里面放各种各样的小盒子(部件),然后每个小盒子(部件)里面还可以放更小的盒子(零件),放入的小盒子将自动代替大盒子原有部分。
在Geant4中,将大盒子称为Mother Volume(母体),小盒子称为Dau ghter Volume(子体)。
除了World Volume之外,每个Volume(体)都必须且只能有一个母体,但可以没有子体,也可以有多个子体。
Geant4的这种盒子模型的要求是:“不交不超”。
“不交”就是要求同一个大盒子里面的小盒子,即同一等级的子体不能有相交的部分;“不超”就是要求小盒子不能超过大盒子的范围,即子体不能超出母体。
Geant4的安装和入门引言Geant4是由CERN(欧洲核子研究委员会)开发的蒙特卡罗应用软件包, 主要用于模拟高能粒子在探测器中输运的物理过程. 它采用面向对象的C++语言编写, 可以构造复杂的探测器几何结构,定制感兴趣的粒子与物理过程模型, 并且能够跟踪粒子的过程, 显示粒子径迹, 处理在输运过程中产生的大量数据.一. Geant4的发展Geant4最初的发展可以追溯到CERN(European Organization for Nuclear Research)和K EK(High Energy Accelerator Research Organization Japan)在1993年的两个研究,他们都是研究如何在Geant3程序中使用现代化的计算技术。
最后CERN DRDC(Detector Research and Development Committee)听取了他们的建议,组织了来自欧洲、俄罗斯、加拿大、日本和美国的几十个实验室、学校和研究所的超过100位科学家和工程师进行了合作,基于C++语言,利用面向对象设计技术对已有的模拟程序进行了重新构造。
这项工程被称之为RD44,初步研究阶段在1998年12月完成,随后在1999年2月Geant4建立了起来,并且在不断的发展和完善的过程中得到了用户的支持和维护。
Geant4已经可以在多种常用操作系统下安装使用,如UNIX、Linux和Windows,需要注意的是在安装Geant4之前需要确定已经安装了相应的C++编译器。
目前正在开发对在MacOs 系统下的使用版本。
Geant4最新的版本是Geant4.6.2.p01,而且Geant4在不断升级的同时,科学家和工程师们也推出了很多基于Geant4,像MULASSIS(多层防护模拟工具)和GEMAT (Geant4微剂量学分析工具)的应用程序。
通过无数人的共同努力,Geant4已经发展成为核物理和空间物理等许多学科方面研究不可或缺的蒙特卡罗模拟工具。
geant4统计粒子通量GEANT4(GEometry ANd Tracking)是一个用于模拟粒子在物质中传输和相互作用的软件工具包。
在GEANT4中,可以通过用户编写的代码来实现对统计粒子通量的模拟和记录。
以下是一些通用的步骤,你可以根据实际需求进行调整:1.定义探测器:在你的GEANT4应用程序中,首先需要定义探测器来捕获和记录粒子通量。
探测器可以是一个体素网格、一个表面或一个体积,具体取决于你的模拟需求。
2.设置统计量:GEANT4提供了用于记录各种统计信息的工具。
你可以使用`G4SDManager`类来设置和管理探测器的统计信息,例如通量值、能谱等。
3.实现事件动作:在你的事件动作类中,你可以定义粒子在探测器中相互作用时应执行的动作。
这可能包括更新统计信息、记录粒子轨迹等。
4.运行模拟:运行GEANT4模拟并让粒子与你定义的探测器相互作用。
在每个事件结束时,相应的统计信息将被更新。
5.分析结果:在模拟运行结束后,你可以分析和提取已记录的统计信息。
这可能涉及到生成直方图、输出文件或以其他方式处理模拟结果。
下面是一个简化的例子,用于演示如何在GEANT4中记录和获取粒子通量:```cpp//在你的头文件中定义探测器class MyDetector:public G4VSensitiveDetector{public://实现你的探测器类,包括更新统计信息的方法};//在你的事件动作类中使用探测器class MyEventAction:public G4UserEventAction{public://实现事件动作,包括更新探测器的方法};//在你的主程序中初始化和运行GEANT4int main(){//初始化GEANT4//...//定义和设置探测器MyDetector*myDetector=new MyDetector("MyDetector");//...//设置统计信息G4SDManager*sdManager=G4SDManager::GetSDMpointer();sdManager->AddNewDetector(myDetector);//运行GEANT4模拟//...//分析结果//...}```请注意,这只是一个概念性的示例。
Geant4基础知识G4模拟粒子过程:建立一次模拟,在G4 中称为一次Run;Run 建立后,需要对几何结构、物理过程进行初始化;初始化完成后就开始模拟过程了,首先发射一个粒子。
在G4 中,发射一个(或一系列)粒子到所有次级粒子死亡的过程成为一次Event。
而每次发射的初始粒子则有粒子发射器进行控制。
而在每一个event过程中,粒子与材料反应后会可能生成多个次级粒子,每个粒子都会有一条径迹,称之为track;而每一个粒子(初始的或次级的)的径迹又是由很多步组成的,称之为step。
G4模拟的基本算法:A Run Start -> 初始化物理模型/几何模型-> An Event Start -> 调用粒子发射器发射粒子-> A Track Start-> A Step Start-> A Step End-> Next Step Start-> ……-> All Step End-> A Track End-> Next Track Start-> ……-> All Track End-> An Event End -> Next Event Start-> ……-> All Event End(All Primaries Shot) -> A Run End -> Next Run Start-> ……1) main()中应该包括的内容Geant4是一个探测器模拟工具, 但它对于某个特定的模拟程序没有固定的main()函数, 用户在建立模拟程序的过程中需要提供自己的main()函数. 一个最基本的main()函数需要包括以下几个方面:G4RunManager(模拟整个过程)G4VUserDetectorConstruction(定义探测器材料, 几何形状, 灵敏区和读出方案)G4VUserPhysicsList(定义粒子种类和物理过程, 还有截断参数)G4VUserPrimaryGeneratorAction(定义了源粒子的种类, 能量, 出射方向等)一个最简单的main()函数如下:#include ""#include ""#include ""#include ""#include ""int main(){Geant4的类结构Geant4程序代码是根据这个类结构建立起来的, 类结构如下图所示. 下面就是Geant4中每个类的简单说明.1) Run 和Event这些类与模拟事件相关, 产生次级粒子, 为粒子径迹模拟器提供粒子.2) Tracking 和Track根据粒子在探测器材料中的物理过程模拟粒子运行的轨迹, 给出粒子特定时间段在空间的位置, 或者粒子空间时间的分布.3) Geometry, Magnetic Field 和CAD-Interface这三个类就是用来描述探测器几何结构和探测器中电磁场的分布. 为了使探测器几何结构可以在CAD系统中进行修改, Geant4的几何体模型完全与ISO STEP标准一致. 将来Geant4中几何结构的设计将从程序设计中独立出来. 面向对象设计的方法可以让用户在不影响程序其他部分的同时改变几何参数和场. 4) Particle Definition 和Matter这两个类用于定义粒子和探测器材料.5) Physics它提供了粒子与探测器材料相互作用时所发生物理过程的模型, 允许用户为每次反应或每个反应道添加物理模型. 用户根据粒子的种类, 探测器材料和能量范围选择不同的物理模型. Geant4有电磁物理过程和强子物理过程模型, 同时也提供了散射截面数据库.6) Hits 和Digitization这个两个类用于对用户定义的灵敏区内的响应进行采样和分析.7) Visualization它显示了探测器几何形状, 粒子轨迹和碰撞过程. 由于采用了面向对象设计技术来设计可视化部分, 这允许用户独立开发可视化工具, 如: OpenGL 和OpenInventor(为X11和Windows设计), DAWN, Postscript(via DAWN)和VRML.8) Interfaces支持可视化用户界面以及和外加程序的交流(OODBMS, reconstruction等).①User Verbose output class,定义了一个verbosity 变量;②Run manager,定义了一个运行管理器runManager;③User Initialization class es (mandatory),设置两个强制类ExN02DetectorConstruction 和ExN02PhysicsList;④User Action classes,设置用户干涉类ExN02PrimaryGeneratorAction、ExN02RunAction、ExN02EventAction和ExN02SteppingAction;⑤Initialize G4 kernel,“runManager->Initialize()”,初始化GEANT4 内核。
Geant4程序的一点技巧总结Geant4程序的一点技巧总结1.使用IDE使用G4如果能有一个带代码提示功能的IDE,写程序的效率会高不少。
在Linux下,轻量级的IDE有Codelite、code::blocks等,重量一点的IDE如Eclipse和QtCreator这些。
我用过Codelite,后来改成Eclipse,配置方法大致相同,我在前面的Blog里写过。
QtCreator的配置可以参考cnscott的博客()。
我一直很建议学G4的朋友可以看看他写的一些东西,挺有用的。
2.自动配置G4环境因为G4要求每次运行G4编写的程序前都要手工配置G4WORKDIR变量和执行env.sh 配置其他环境变量。
有没办法省去这个步骤呢,办法是有的,我的方法如下:在用户目录下面建一个名叫g4env的文件,把下面的内容写进去:1export G4WORKDIR=$HOME/Geant4/g4work2export LD_LIBRARY_PATH=$HOME/Geant4/clhep/lib/:$LD_LIBRARY_PATH3exportLD_LIBRARY_PATH=$HOME/Geant4/geant4/geant4.9.3/lib/Linux-g++/:$LD_LIBRARY_PATH 4source$HOME/Geant4/geant4/geant4.9.3/env.sh保存,并将这个文件权限用chmod命令设成可执行。
然后在用户的.bashrc文件的末尾添上一行:5source~/g4env>~/.g4envsetting这样每次打开控制台就自动加载g4env脚本,并且把输出的内容存到一个隐藏的临时文件里。
不用每次输入这么多东西了,而且也不会在开启控制台时候显示一堆东西。
3.自定义常用的命令使用Linux的别名功能定义一些常用的“G4命令”,把这些想定义的命令写到上面提到的g4env文件后面,就可以在以后开启控制台直接用了。
Geant4基础知识G4模拟粒子过程:建立一次模拟,在G4 中称为一次Run;Run 建立后,需要对几何结构、物理过程进行初始化;初始化完成后就开始模拟过程了,首先发射一个粒子。
在G4 中,发射一个(或一系列)粒子到所有次级粒子死亡的过程成为一次Event。
而每次发射的初始粒子则有粒子发射器进行控制。
而在每一个event过程中,粒子与材料反应后会可能生成多个次级粒子,每个粒子都会有一条径迹,称之为track;而每一个粒子(初始的或次级的)的径迹又是由很多步组成的,称之为step。
G4模拟的基本算法:A Run Start -> 初始化物理模型/几何模型-> An Event Start -> 调用粒子发射器发射粒子-> A Track Start-> A Step Start-> A Step End-> Next Step Start-> ……-> All Step End-> A Track End-> Next Track Start-> ……-> All Track End-> An Event End -> Next Event Start-> ……-> All Event End(All Primaries Shot) -> A Run End -> Next Run Start -> ……1) main()中应该包括的内容Geant4是一个探测器模拟工具, 但它对于某个特定的模拟程序没有固定的main()函数, 用户在建立模拟程序的过程中需要提供自己的main()函数. 一个最基本的main()函数需要包括以下几个方面:G4RunManager(模拟整个过程)G4VUserDetectorConstruction(定义探测器材料, 几何形状, 灵敏区和读出方案)G4VUserPhysicsList(定义粒子种类和物理过程, 还有截断参数)G4VUserPrimaryGeneratorAction(定义了源粒子的种类, 能量, 出射方向等)一个最简单的main()函数如下:#include "G4RunManager.hh"#include "G4UImanager.hh"#include "ExN01DetectorConstruction.hh"#include "ExN01PhysicsList.hh"#include "ExN01PrimaryGeneratorAction.hh"int main(){// Construct the default run managerG4RunManager* runManager = new G4RunManager;// set mandatory initialization classesrunManager->SetUserInitialization(new ExN01DetectorConstruction); runManager->SetUserInitialization(new ExN01PhysicsList);// set mandatory user action classrunManager->SetUserAction(new ExN01PrimaryGeneratorAction);// Initialize G4 kernelrunManager->Initialize();// get the pointer to the UI manager and set verbositiesG4UImanager* UI = G4UImanager::GetUIpointer();UI->ApplyCommand("/run/verbose 1");UI->ApplyCommand("/event/verbose 1");UI->ApplyCommand("/tracking/verbose 1");// start a runint numberOfEvent = 3;runManager->BeamOn(numberOfEvent);// job terminationdelete runManager;return 0;}main()首先生成一个G4RunManager类,这个类是在主程序中用以初始化模拟信息,用来连接子程序,连接方式是通过Set函数来完成。