前面介绍的 RunAction 和 StepingAction 都只能用来提取数据,不能改变粒子的模拟状态,而这里 StackingAction 则可以改变粒子模拟的先后顺序,甚至直接 kill 该粒子。
#include "G4ClassificationOfNewTrack.hh"
class G4UserStackingAction
{
public:
G4UserStackingAction();
virtual ~G4UserStackingAction();
protected:
G4StackManager * stackManager;
public:
//---------------------------------------------------------------
// virtual methods to be implemented by user
//---------------------------------------------------------------
//
virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track*);
virtual void NewStage();
virtual void PrepareNewEvent();
};
这个类有三个虚函数,ClassifyNewTrack、NewStage 和 PrepareNewEvent,用户可以重写它们来控制各种模拟 track 堆叠机制。
每当 G4EventManager 将新的 G4Track 对象 “推” 到堆栈上时,G4StackManager 就会调用 ClassifyNewTrack()。ClassifyNewTrack() 返回枚举器 G4ClassificationOfNewTrack,其值指示 track 将发送到哪个堆栈(如果有)。该值应由用户确定。
G4ClassificationOfNewTrack 有四个可能的值:
#include "G4VProcess.hh"
G4ClassificationOfNewTrack wuStackingActionAll::ClassifyNewTrack(const G4Track* aTrack)
{
G4int parent_ID = aTrack->get_parentID();
// parent_ID = 0 : primary particle
// > 0 : secondary particle
// < 0 : postponed from the previous event
return fUrgent;
}
典型示例
// 保留初级粒子
if (aTrack->GetParentID() == 0) return fUrgent;
// 杀掉所有次级粒子
return fKill;
常用筛选条件
// 需要添加头文件
#include "G4VProcess.hh"
G4String PName = aTrack->GetDefinition()->GetParticleName();
G4int TrackID = aTrack->GetTrackID();
G4int ParentID = aTrack->GetParentID();
G4String CreatorProcess;
const G4VProcess* pcr = aTrack->GetCreatorProcess();
if(pcr) CreatorProcess = pcr->GetProcessName();
else CreatorProcess = "##";
// 不模拟所有非中子粒子
if(PName[0] != 'n') return fKill;
return fUrgent;
// 不模拟生成时间大于 100 ns 的粒子
if(aTrack->GetGlobalTime() > 100*ns) return fKill;
aTrack->GetTrackID();//G4int
aTrack->GetParentID();//G4int
aTrack->GetWeight();//G4double These are methods for manipulating a weight for this track.
aTrack->GetCreatorModelID();//G4int
aTrack->GetCreatorModelName();//G4String&
aTrack->GetCreatorProcess();//G4VProcess*
const G4VProcess* pcr = aTrack->GetCreatorProcess();
if(pcr) G4String CreatorProcess = pcr->GetProcessName();// Returns the name of the process.
else G4String CreatorProcess = "##";
pcr->GetProcessType();//G4ProcessType Returns the process type.
pcr->GetProcessSubType();//G4int Returns the process sub type.
aTrack->GetTrackLength();//G4double
// Before the end of the AlongStepDoIt loop,StepLength keeps the initial value which is determined by the shortest geometrical Step proposed by a physics process. After finishing the AlongStepDoIt, it will be set equal to 'StepLength' in G4Step.
aTrack->GetStepLength();//G4double
aTrack->GetCurrentStepNumber();//G4int
aTrack->GetStep();//G4Step*
// The flag of "GoodForTracking" is set by processes if this track should be tracked even if the energy is below threshold
aTrack->IsGoodForTracking();//G4bool
// The flag of "BelowThreshold" is set to true if this track energy is below threshold energy in this material determined by the range cut value
aTrack->IsBelowThreshold();//G4bool
aTrack->GetTrackStatus();//G4TrackStatus track status, flags for tracking
aTrack->GetPolarization();//G4ThreeVector&
aTrack->UseGivenVelocity();//G4bool
aTrack->CalculateVelocity();//G4double
aTrack->CalculateVelocityForOpticalPhoton();//G4double
aTrack->GetVelocity();//G4double
aTrack->GetMomentum();//G4ThreeVector
aTrack->GetMomentumDirection();//G4ThreeVector&
aTrack->GetTotalEnergy();//G4double
aTrack->GetKineticEnergy();//G4double
aTrack->GetVolume();//G4VPhysicalVolume*
aTrack->GetNextVolume();//G4VPhysicalVolume*
aTrack->GetMaterial();//G4Material*
aTrack->GetNextMaterial();//G4Material*
aTrack->GetMaterialCutsCouple();//G4MaterialCutsCouple*
aTrack->GetNextMaterialCutsCouple();//G4MaterialCutsCouple*
aTrack->GetTouchable();//G4VTouchable*
aTrack->GetTouchableHandle();//G4TouchableHandle&
aTrack->GetNextTouchable();//G4VTouchable*
aTrack->GetNextTouchableHandle();//G4TouchableHandle&
aTrack->GetOriginTouchable();//G4VTouchable*
aTrack->GetOriginTouchableHandle();//G4TouchableHandle&
aTrack->GetPosition();//G4ThreeVector&
aTrack->GetGlobalTime();//G4double Time since the event in which the track belongs is created.
aTrack->GetLocalTime();//G4double Time since the current track is created.
aTrack->GetProperTime();//G4double Proper time of the current track
aTrack->GetDynamicParticle();//G4DynamicParticle* dynamic particle
aTrack->GetParticleDefinition();//G4ParticleDefinition* particle definition
// vertex (,where this track was created) information
aTrack->GetVertexPosition();//G4ThreeVector&
aTrack->GetVertexMomentumDirection();//G4ThreeVector&
aTrack->GetVertexKineticEnergy();//G4double
aTrack->GetLogicalVolumeAtVertex();//G4LogicalVolume*
aTrack->GetUserInformation();// G4VUserTrackInformation*
aTrack->SetUserInformation(/*G4VUserTrackInformation* aValue*/);
!date
!jupyter nbconvert StackingAction.ipynb --to html
2022年 05月 08日 星期日 11:06:39 CST [NbConvertApp] Converting notebook StackingAction.ipynb to html [NbConvertApp] Writing 580937 bytes to StackingAction.html