TrackInformation

G4VUserTrackInformation 是一个抽象类,用户可以从中派生出自己的具体类,用于存储与 G4Track 类对象关联的用户信息。用户需要构造一个具体的类对象,并将指针设置为正确的 G4Track 对象。

在 G4UserTrackingAction 的具体实现中,G4TrackingManager 的 SetUserTrackInformation() 函数可用于将具体类对象的指针设置为G4Track,因为 G4Track 对象只能通过“指向常量的指针”使用。

将 G4VUserTrackingInformation 对象从母粒子复制到子粒子的理想位置是 G4UserTrackingAction::PositUserTrackingAction()。

class G4VUserTrackInformation
{
  public:

    G4VUserTrackInformation();
    G4VUserTrackInformation(const G4String& infoType);
      // String is provided to indicate the Type of UserTrackInfo class
      // User is recommended to set the type of his/her class

    G4VUserTrackInformation(const G4VUserTrackInformation&);
    G4VUserTrackInformation& operator=(const G4VUserTrackInformation&);

    virtual ~G4VUserTrackInformation();

    virtual void Print() const {};

    const G4String& GetType() const;
      // Get Type of this UserTrackInfo

  protected:

    G4String* pType = nullptr;
};

典型的应用

中子增殖

neutronU

同理,第几代 $\gamma$ 也是类似处理

中子墙的中子多重性

需要进行遗传信息标记的均可通过该方式传递

示例代码

以下示例代码中,我们添加了一个标记变量 flag。

wuTrackInformation.hh

#ifndef _WUTRACKINFORMATION_H_
#define _WUTRACKINFORMATION_H_

#include "G4VUserTrackInformation.hh"
#include "G4Allocator.hh"
#include "globals.hh"
#include "G4Track.hh"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class wuTrackInformation : public G4VUserTrackInformation
{
public:
  wuTrackInformation();
  virtual ~wuTrackInformation();
  wuTrackInformation(const G4Track* aTrack);//未完待续
  wuTrackInformation(const wuTrackInformation* Info);
  inline virtual void Print() const{};

  inline void *operator new(size_t);
  inline void operator delete(void *aTrackInfo);

  void SetFlagType(G4String& infoType);
  const G4String& GetFlagType() const;

  //想传递什么信息都可通过Set Get 函数实现
  G4bool AddFlag(G4int ss);
  G4int PrintFlag()const { return fFlag; }

  // Check if a certain flag is on
  G4bool IsFlag(G4int ss)
  {return ss != 0 ? true : false; }

private:
  G4int fFlag;//默认0
  G4String* fFlagType; 
};

extern G4ThreadLocal G4Allocator<wuTrackInformation> * aTrackInformationAllocator;

inline void* wuTrackInformation::operator new(size_t)
{
  if(!aTrackInformationAllocator)
    aTrackInformationAllocator = new G4Allocator<wuTrackInformation>;
  return (void*)aTrackInformationAllocator->MallocSingle();
}

inline void wuTrackInformation::operator delete(void *aTrackInfo)
{ aTrackInformationAllocator->FreeSingle((wuTrackInformation*)aTrackInfo);}


#endif /* _WUTRACKINFORMATION_H_ */

wuTrackInformation.cc

#include "wuTrackInformation.hh"
#include "G4ios.hh"
#include "G4SystemOfUnits.hh"    

G4ThreadLocal G4Allocator<wuTrackInformation> * aTrackInformationAllocator = 0;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
wuTrackInformation::wuTrackInformation()
  :G4VUserTrackInformation(), fFlagType(0)
{
  fFlag=0;
}
wuTrackInformation:: wuTrackInformation(const G4Track* aTrack)
  :G4VUserTrackInformation(), fFlagType(0)
{

}

wuTrackInformation::wuTrackInformation(const wuTrackInformation* Info)
  :G4VUserTrackInformation(), fFlagType(0)
{
  fFlag=Info->fFlag;
  if (fFlagType==0) fFlagType=Info->fFlagType;
}
wuTrackInformation::~wuTrackInformation()
{
  if (fFlagType!=0) delete fFlagType;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4bool wuTrackInformation::AddFlag(G4int ss)
{
  //预留接口
  fFlag=ss;
  return true;
}

void wuTrackInformation::SetFlagType(G4String& infoType)
{
    fFlagType = new G4String(infoType) ;
}

const G4String& wuTrackInformation::GetFlagType() const
{
  static const G4String NOTYPE="NONE";
  if(fFlagType!=0) return *fFlagType;
  else return NOTYPE;
}