|
|
|||
File indexing completed on 2026-09-20 08:29:32
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 /// \file GB03BOptnSplitOrKillOnBoundary.cc 0027 /// \brief Implementation of the GB03BOptnSplitOrKillOnBoundary class 0028 0029 #include "GB03BOptnSplitOrKillOnBoundary.hh" 0030 0031 #include "Randomize.hh" 0032 0033 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0034 0035 GB03BOptnSplitOrKillOnBoundary::GB03BOptnSplitOrKillOnBoundary(G4String name) 0036 : G4VBiasingOperation(name), fParticleChange(), fParticleChangeForNothing() 0037 {} 0038 0039 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0040 0041 GB03BOptnSplitOrKillOnBoundary::~GB03BOptnSplitOrKillOnBoundary() = default; 0042 0043 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0044 0045 G4double GB03BOptnSplitOrKillOnBoundary::DistanceToApplyOperation(const G4Track*, G4double, 0046 G4ForceCondition* condition) 0047 { 0048 // -- return "infinite" distance for interaction, but asks for GenerateBiasingFinalState 0049 // -- being called anyway at the end of the step, by returning the "Forced" condition 0050 // -- flag. 0051 *condition = Forced; 0052 return DBL_MAX; 0053 } 0054 0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0056 0057 G4VParticleChange* GB03BOptnSplitOrKillOnBoundary::GenerateBiasingFinalState(const G4Track* track, 0058 const G4Step* step) 0059 { 0060 // Check if step is limited by the geometry: as we attached the biasing operator 0061 // to the absorber layer, this volume boundary is the one of the absorber. 0062 // (check of current step # of track is inelegant, but is to fix a "feature" 0063 // that a cloned track can wrongly be seen in the wrong volume, because of numerical 0064 // precision issue. In this case it makes a tiny step, which should be disregarded). 0065 if ((step->GetPostStepPoint()->GetStepStatus() == fGeomBoundary) 0066 && (track->GetCurrentStepNumber() != 1)) 0067 { 0068 // -- Before deciding for killing or splitting, we make decision on applying 0069 // -- the technique or not: 0070 G4double trial = G4UniformRand(); // -- Note: G4UniformRand() is thread-safe 0071 // -- engine for random numbers 0072 if (trial <= fApplyProbability) { 0073 // -- Get z component of track, to see if it moves forward or backward: 0074 G4double pz = track->GetMomentum().z(); 0075 0076 if (pz > 0.0) { 0077 // ------------------------------------------------- 0078 // Here, we are moving "forward". We do "splitting": 0079 // ------------------------------------------------- 0080 0081 // Get track weight: 0082 G4double initialWeight = track->GetWeight(); 0083 // Define the tracks weight: 0084 G4double weightOfTrack = initialWeight / fSplittingFactor; 0085 0086 // The "particle change" is the object to be used to communicate to 0087 // the tracking the update of the primary state and/or creation 0088 // secondary tracks. 0089 fParticleChange.Initialize(*track); 0090 0091 // ask currect track weight to be changed to new value: 0092 fParticleChange.ProposeParentWeight(weightOfTrack); 0093 0094 // Now make clones of this track (this is the actual splitting): 0095 // we will then have the primary and N-1 clones of it, hence the 0096 // splitting by a factor N: 0097 fParticleChange.SetNumberOfSecondaries(fSplittingFactor - 1); 0098 for (G4int iSplit = 1; iSplit < fSplittingFactor; iSplit++) { 0099 auto clone = new G4Track(*track); 0100 clone->SetWeight(weightOfTrack); 0101 fParticleChange.AddSecondary(clone); 0102 } 0103 fParticleChange.SetSecondaryWeightByProcess(true); // -- tricky 0104 // -- take it as is ;) [though not necessary here, put for safety] 0105 0106 // this new final state is returned to the tracking; 0107 return &fParticleChange; 0108 } 0109 0110 else { 0111 // -------------------------------------------------------------- 0112 // Here, we are moving backward. We do killing, playing a russian 0113 // roulette, killing 1/fSplittingFactor of the tracks in average: 0114 // -------------------------------------------------------------- 0115 0116 // Get track weight: 0117 G4double initialWeight = track->GetWeight(); 0118 0119 // The "particle change" is the object to be used to communicate to 0120 // the tracking the update of the primary state and/or creation 0121 // secondary tracks. 0122 fParticleChange.Initialize(*track); 0123 0124 // Shoot a random number (in ]0,1[ segment): 0125 G4double random = G4UniformRand(); 0126 0127 // Decide to kill, keeping 1/fSplittingFactor of tracks: 0128 G4double survivingProbability = 1.0 / fSplittingFactor; 0129 if (random > survivingProbability) { 0130 // We ask for the the track to be killed: 0131 fParticleChange.ProposeTrackStatus(fStopAndKill); 0132 } 0133 else { 0134 // In this case, the track survives. We change its weight 0135 // to conserve weight among killed and survival tracks: 0136 fParticleChange.ProposeParentWeight(initialWeight * fSplittingFactor); 0137 } 0138 0139 // this new final state is returned to the tracking; 0140 return &fParticleChange; 0141 } 0142 } // -- end of : if ( trial > probaForApplying ) 0143 } // -- end of : if ( ( step->GetPostStepPoint()->GetStepStatus() == 0144 // fGeomBoundary ) ... 0145 0146 // Here, the step was not limited by the geometry (but certainly by a physics 0147 // process). We do nothing: ie we make no change to the current track. 0148 fParticleChangeForNothing.Initialize(*track); 0149 return &fParticleChangeForNothing; 0150 } 0151 0152 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|