GEANT4学习 输出粒子信息小计
写了一个简单的模型,并在step里面输出粒子的信息,通过这些验证G4在粒子输出信息上的规则。
我原本想的是输出
eventID、trackID、stepID、particle name、prepoint process name、postpoint process name、creator name、prepoint Kinetic Energy、postpoint Kinetic Energy、prepoint volume name、postpoint volume name以及energy deposit。
第一次尝试的时候出现了问题,个别的信息输出时会遇到“段错误”,网上解释段错误是栈溢出,但是我感觉好多都是信息的逻辑提取出现了问题,这个我之后讲。
第一次输出信息的代码如下所示:
G4int eventID = (G4EventManager::GetEventManager())->GetConstCurrentEvent()->GetEventID();
// 因为在step里面,我使用EventManager这个类去获取EventID
G4int trackID = step->GetTrack()->GetTrackID();
G4String particleName = step->GetTrack()->GetDefinition()->GetParticleName();
G4String postProcessName = step->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName();
G4String preName = step->GetPreStepPoint()->GetTouchableHandle()->GetVolume()->GetName();
G4double postKE = step->GetPostStepPoint()->GetKineticEnergy();
G4double preKE = step->GetPreStepPoint()->GetKineticEnergy();
G4double edepStep = step->GetTotalEnergyDeposit();
输出语句如下所示:
outfileInfo<<std::setw(10)<<std::setfill(' ') <<std::left <<particleName
<<std::setw(4)<<std::setfill(' ') <<std::left <<eventID
<<std::setw(4)<<std::setfill(' ') <<std::left <<trackID
<<std::setw(8)<<std::setfill(' ') <<std::left <<preName
<<std::setw(20)<<std::setfill(' ') <<std::left <<preKE
<<std::setw(20)<<std::setfill(' ') <<std::left <<postProcessName
<<std::setw(20)<<std::setfill(' ') <<std::left <<postKE
<<std::setw(20)<<std::setfill(' ') <<std::left <<edepStep
<<G4endl;
输出信息的文件如下所示:
particleN eID tID preN preKE postProName postKE edepStep
neutron 0 1 World 14 Transportation 14 0
neutron 0 1 A1 14 Transportation 14 0
neutron 0 1 A2 14 hadElastic 13.5434 0
neutron 0 1 A2 13.5434 hadElastic 9.21031 0
neutron 0 1 A2 9.21031 hadElastic 5.6599 0
neutron 0 1 A2 5.6599 hadElastic 3.56607 0
neutron 0 1 A2 3.56607 hadElastic 2.93008 0
neutron 0 1 A2 2.93008 Transportation 2.93008 0
neutron 0 1 World 2.93008 Transportation 2.93008 0
O16 0 6 A2 0.63616 ionIoni 0 0.63616
O16 0 6 A2 0 RadioactiveDecay 0 0
proton 0 5 A2 2.09497 hIoni 1.38174 0.713232
proton 0 5 A2 1.38174 hIoni 0.580998 0.800742
proton 0 5 A2 0.580998 hIoni 0.0178738 0.563124
proton 0 5 A2 0.0178738 hIoni 0.0114283 0.00644545
proton 0 5 A2 0.0114283 hIoni 0.00879221 0.00263613
proton 0 5 A2 0.00879221 hIoni 0 0.00879221
proton 0 4 A2 3.55233 hIoni 2.98914 0.563191
proton 0 4 A2 2.98914 hIoni 2.34926 0.639877
proton 0 4 A2 2.34926 hIoni 1.67271 0.676547
proton 0 4 A2 1.67271 hIoni 0.877513 0.7952
proton 0 4 A2 0.877513 hIoni 0.0726702 0.804843
proton 0 4 A2 0.0726702 hIoni 0 0.0726702
proton 0 3 A2 4.33546 hIoni 3.72805 0.607402
proton 0 3 A2 3.72805 hIoni 3.15269 0.575363
proton 0 3 A2 3.15269 hIoni 2.55276 0.599933
proton 0 3 A2 2.55276 hIoni 1.88505 0.667708
proton 0 3 A2 1.88505 hIoni 1.15731 0.727738
proton 0 3 A2 1.15731 hIoni 0.0440143 1.1133
proton 0 3 A2 0.0440143 hIoni 0 0.0440143
proton 0 2 A2 0.456834 hIoni 0.0206327 0.436202
proton 0 2 A2 0.0206327 hIoni 0.0198335 0.00079924
proton 0 2 A2 0.0198335 hIoni 0.0121395 0.007694
proton 0 2 A2 0.0121395 hIoni 0.00741999 0.00471949
proton 0 2 A2 0.00741999 hIoni 0 0.00741999
我想输出的信息有很多还没办法实现,接下来来一个一个讲:
stepID:同学说没有stepID这个讲法,官网上好像确实没有相关的语句;
preProcessName:
G4String preProcessName = step->GetPreStepPoint()->GetProcessDefinedStep()->GetProcessName();
这段一放上去就会出现段错误,我判断是初始粒子的preProcessName是没有的,因为是初始粒子,由初始粒子生成器生成的。
因此我加了一句来判断是否是初始粒子:
G4String preProcessName;
if (trackID==1) preProcessName="primary";
else preProcessName = step->GetPreStepPoint()->GetProcessDefinedStep()->GetProcessName();
但是还是会出现“段错误”,有可能这个prePoint就没有processname。
所以在输出的时候我又换成下面的语句。对于一个step 前点使用creatorProcessName,后点使用postPointProcessName。
G4String creatorName;
if (trackID==1) creatorName="primary";
else creatorName = step->GetTrack()->GetCreatorProcess()->GetProcessName();
postPointVolumName:
后点volume的名字出现问题,我觉得是当粒子输运接触world边界时,无法获取后点的volume,因此我也加一个判断:
G4String postName;
if (step->GetPostStepPoint()->GetStepStatus() == fWorldBoundary) postName="out";
else postName = step->GetPostStepPoint()->GetTouchableHandle()->GetVolume()->GetName();
这样就可以把想要的信息输出了,摘录部分输出结果:
neutron 6 1 primary World 14 Transportation A1 14 0
neutron 6 1 primary A1 14 Transportation A2 14 0
neutron 6 1 primary A2 14 neutronInelastic A2 0 0
gamma 6 7 neutronInelastic A2 0.0210016 phot A2 0 2.834e-05
e- 6 9 phot A2 0.00050894 msc A2 0.00050894 0
e- 6 9 phot A2 0.00050894 eIoni A2 0 0.00050894
e- 6 8 phot A2 0.0204643 msc A2 0.000334888 0.0201294
e- 6 8 phot A2 0.000334888 eIoni A2 0 0.000334888
gamma 6 6 neutronInelastic A2 0.0210016 phot A2 0 4.338e-05
e- 6 11 phot A2 0.0004939 msc A2 0.000458443 3.54571e-05
e- 6 11 phot A2 0.000458443 eIoni A2 0 0.000458443
e- 6 10 phot A2 0.0204643 msc A2 0.0190617 0.00140257
e- 6 10 phot A2 0.0190617 eIoni A2 0 0.0190617
gamma 6 5 neutronInelastic A2 0.00267715 phot A2 0 5.846e-05
e- 6 13 phot A2 0.00047882 msc A2 0.00047882 0
e- 6 13 phot A2 0.00047882 eIoni A2 0 0.00047882
e- 6 12 phot A2 0.00213987 msc A2 0.00186088 0.000278987
e- 6 12 phot A2 0.00186088 eIoni A2 0 0.00186088
gamma 6 4 neutronInelastic A2 3.85317 Transportation World 3.85317 0
gamma 6 4 neutronInelastic World 3.85317 Transportation out 3.85317 0
C13 6 3 neutronInelastic A2 1.38632 ionIoni A2 0.272673 1.11365
C13 6 3 neutronInelastic A2 0.272673 ionIoni A2 0 0.272673
C13 6 3 neutronInelastic A2 0 RadioactiveDecay A2 0 0
alpha 6 2 neutronInelastic A2 6.5013 ionIoni A2 3.15038 3.35092
alpha 6 2 neutronInelastic A2 3.15038 ionIoni A2 0 3.15038