Geant4的几何边界判断代码解析

2020-09-04 17:29:56 浏览数 (1)

来不及解释了,“几何边界的信息抽取”加班加点写给大家。

目 录

1.事件示范step信息

2.几何边界的判断

a) 抽取track的nextvolume

b) 抽取PostStepPoint的所属volume

c) 抽取Pre/PostStepPoint的status

1. 事件示范step信息

图1. 1MeV gamma入射到1cm3 BGO闪烁体的step信息

图2. 1 MeV gamma入射事件的几何记录信息

2. 几何边界的判断

以伽玛在Boundary2处做讲解分析。首先判断PreStepPoint所在的physicalvolume是否为”phybgo”,然后通过以下三种方式给出Boundary2的定义:

a) 抽取当前step所属track的nextvolume

代码语言:javascript复制
void B1SteppingAction::UserSteppingAction(const G4Step* step)
{ /* const*/ G4StepPoint* prePoint = step->GetPreStepPoint();
/* const*/ G4StepPoint* endPoint = step->GetPostStepPoint();
G4String nowvolumename= prePoint->GetTouchableHandle()->GetVolume()->GetName();
G4Track *aTrack = step->GetTrack();
G4VPhysicalVolume* nextpv=aTrack->GetNextVolume();
if (nextpv!=NULL)
  {
  G4String nextvolumename = nextpv->GetName();
  if(nowvolumename=="phybgo"&&nextvolumename=="World")
    {G4double E=aTrack->GetKineticEnergy();
    G4cout<<"boundaryenergy is "<< E<<G4endl;
    }
  }
}

b) 抽取当前step的PostStepPoint的所属volume

代码语言:javascript复制
void B1SteppingAction::UserSteppingAction(const G4Step* step)
{ /* const*/ G4StepPoint* prePoint = step->GetPreStepPoint();
/* const*/ G4StepPoint* endPoint = step->GetPostStepPoint();
G4Track *aTrack = step->GetTrack();
G4String nowvolumename= prePoint->GetTouchableHandle()->GetVolume()->GetName();
G4VPhysicalVolume* nextpv= endPoint ->GetTouchableHandle()->GetVolume();
if (nextpv!=NULL)
  {
  G4String nextvolumename = nextpv->GetName();
  if(nowvolumename=="phybgo"&&nextvolumename=="World")
    {G4double E=aTrack->GetKineticEnergy();
    G4cout<<"boundaryenergy is "<< E<<G4endl;
    }
  }
}

c) 抽取当前step的PreStepPoint或PostStepPoint的status

代码语言:javascript复制
void B1SteppingAction::UserSteppingAction(const G4Step* step)
{ /* const*/ G4StepPoint* prePoint = step->GetPreStepPoint();
/* const*/ G4StepPoint* endPoint = step->GetPostStepPoint();
G4Track *aTrack = step->GetTrack();
G4String nowvolumename= prePoint->GetTouchableHandle()->GetVolume()->GetName();
if ( nowvolumename=="phybgo"&&endPoint->GetStepStatus() == fGeomBoundary)
  {G4double E=aTrack->GetKineticEnergy();
  G4cout<<"boundary energy is "<<E<<G4endl;
  }
}

图3. 三种方法均能给出gamma逃出BGO时的判断

下一篇将给出step的信息抽取代码示范,特别给出Segmentationfault (core dumped)段错误的常见情况分析。

本公众号的教程本着给代码、给特例的初衷,助力大家的科研,严谨、用心,力争做到最实用、无BUG,成为值得备份的学习资料。

进入公众号点击“看看圈子”,Geant4问题可以留言交流~

喜欢的话,分享一下吧~^o^~

0 人点赞