File indexing completed on 2025-02-25 09:22:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 #include "G4ios.hh"
0047 #include "GRParallelWorldBiasingProcess.hh"
0048 #include "G4Step.hh"
0049 #include "G4Track.hh"
0050 #include "G4Navigator.hh"
0051 #include "G4PathFinder.hh"
0052 #include "G4VTouchable.hh"
0053 #include "G4VPhysicalVolume.hh"
0054 #include "G4ParticleChange.hh"
0055 #include "G4ParticleChangeForNothing.hh"
0056 #include "Randomize.hh"
0057 #include "G4Region.hh"
0058 #include "GRBiasingRegionInfo.hh"
0059
0060 GRParallelWorldBiasingProcess::
0061 GRParallelWorldBiasingProcess(const G4String& processName,G4ProcessType theType)
0062 :G4ParallelWorldProcess(processName,theType)
0063 {
0064 particleChange = new G4ParticleChange();
0065 emptyParticleChange = new G4ParticleChangeForNothing();
0066 }
0067
0068 GRParallelWorldBiasingProcess::~GRParallelWorldBiasingProcess()
0069 {;}
0070
0071 G4VParticleChange* GRParallelWorldBiasingProcess::PostStepDoIt(
0072 const G4Track& track,
0073 const G4Step& step)
0074 {
0075 fOldGhostTouchable = fGhostPostStepPoint->GetTouchableHandle();
0076 CopyStep(step);
0077
0078 if(fOnBoundary)
0079 {
0080 fNewGhostTouchable = fPathFinder->CreateTouchableHandle(fNavigatorID);
0081 }
0082 else
0083 {
0084 fNewGhostTouchable = fOldGhostTouchable;
0085 }
0086
0087 fGhostPreStepPoint->SetTouchableHandle(fOldGhostTouchable);
0088 fGhostPostStepPoint->SetTouchableHandle(fNewGhostTouchable);
0089
0090 if(fNewGhostTouchable->GetVolume() == nullptr)
0091 {
0092
0093 emptyParticleChange->Initialize(track);
0094 return emptyParticleChange;
0095 }
0096 if(fNewGhostTouchable->GetVolume() == fOldGhostTouchable->GetVolume())
0097 {
0098
0099 emptyParticleChange->Initialize(track);
0100 return emptyParticleChange;
0101 }
0102
0103 G4int preStepCopyNo = fOldGhostTouchable->GetReplicaNumber();
0104 G4int postStepCopyNo = fNewGhostTouchable->GetReplicaNumber();
0105
0106 GRBiasingRegionInfo* biasInfo = static_cast<GRBiasingRegionInfo*>
0107 (fNewGhostTouchable->GetVolume()->GetLogicalVolume()->GetRegion()->GetUserInformation());
0108 auto probability = biasInfo->GetProbability();
0109 if(probability < 1.)
0110 {
0111
0112 G4double ran = G4UniformRand();
0113 if(ran > probability)
0114 {
0115 emptyParticleChange->Initialize(track);
0116 return emptyParticleChange;
0117 }
0118 }
0119
0120 G4double trackWeight = track.GetWeight();
0121 particleChange->Initialize(track);
0122
0123 auto biasFactor = biasInfo->GetBiasingFactor();
0124 if(biasFactor==1)
0125 {
0126
0127 emptyParticleChange->Initialize(track);
0128 return emptyParticleChange;
0129 }
0130
0131 if(preStepCopyNo < postStepCopyNo)
0132 {
0133
0134 trackWeight /= biasFactor;
0135 particleChange->ProposeParentWeight(trackWeight);
0136 for(G4int iClone=1;iClone<biasFactor;iClone++)
0137 {
0138 G4Track* clonedTrack = new G4Track(track);
0139 clonedTrack->SetWeight(trackWeight);
0140 particleChange->AddSecondary(clonedTrack);
0141 }
0142 particleChange->SetSecondaryWeightByProcess(true);
0143 }
0144 else if(preStepCopyNo > postStepCopyNo)
0145 {
0146
0147 G4double survivalRate = 1.0/biasFactor;
0148 G4double ran = G4UniformRand();
0149 if(ran > survivalRate)
0150 {
0151
0152 particleChange->ProposeTrackStatus(fStopAndKill);
0153 }
0154 else
0155 {
0156
0157 trackWeight *= biasFactor;
0158 particleChange->ProposeParentWeight(trackWeight);
0159 }
0160 }
0161 else
0162 {
0163
0164 G4ExceptionDescription ed;
0165 ed << "pre step point : "<<fOldGhostTouchable->GetVolume()->GetName()<<" - copy no. "<<fOldGhostTouchable->GetReplicaNumber()<<"\n"
0166 << "post step point : "<<fNewGhostTouchable->GetVolume()->GetName()<<" - copy no. "<<fNewGhostTouchable->GetReplicaNumber();
0167 G4Exception("GRParallelWorldBiasingProcess::PostStepDoIt()","GoradProc0001",FatalException,ed);
0168 }
0169
0170 return particleChange;
0171 }
0172