Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // >> 26 // $Id$ 26 // 27 // 27 /// \file GB05BOptnSplitAndKillByCrossSection. 28 /// \file GB05BOptnSplitAndKillByCrossSection.cc 28 /// \brief Implementation of the GB05BOptnSpli 29 /// \brief Implementation of the GB05BOptnSplitAndKillByCrossSection class 29 30 30 #include "GB05BOptnSplitAndKillByCrossSection. << 31 << 32 #include "Randomize.hh" 31 #include "Randomize.hh" >> 32 #include "GB05BOptnSplitAndKillByCrossSection.hh" 33 33 34 //....oooOO0OOooo........oooOO0OOooo........oo 34 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 35 35 36 GB05BOptnSplitAndKillByCrossSection::GB05BOptn 36 GB05BOptnSplitAndKillByCrossSection::GB05BOptnSplitAndKillByCrossSection(G4String name) 37 : G4VBiasingOperation(name), fParticleChange << 37 : G4VBiasingOperation(name), >> 38 fParticleChange(), >> 39 fInteractionLength(-1.0) 38 {} 40 {} 39 41 40 //....oooOO0OOooo........oooOO0OOooo........oo 42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 41 43 42 GB05BOptnSplitAndKillByCrossSection::~GB05BOpt << 44 GB05BOptnSplitAndKillByCrossSection::~GB05BOptnSplitAndKillByCrossSection() >> 45 {} 43 46 44 //....oooOO0OOooo........oooOO0OOooo........oo 47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 45 48 46 G4double GB05BOptnSplitAndKillByCrossSection:: << 49 G4double GB05BOptnSplitAndKillByCrossSection:: 47 << 50 DistanceToApplyOperation( const G4Track*, >> 51 G4double, >> 52 G4ForceCondition* condition) 48 { 53 { 49 *condition = NotForced; 54 *condition = NotForced; 50 55 51 // -- Sample the exponential law using the t 56 // -- Sample the exponential law using the total interaction length of processes 52 // -- to couterbalance for: 57 // -- to couterbalance for: 53 G4double proposedStepLength = -std::log(G4Un << 58 G4double proposedStepLength = -std::log( G4UniformRand() ) * fInteractionLength; 54 << 59 55 return proposedStepLength; 60 return proposedStepLength; 56 } 61 } 57 62 58 //....oooOO0OOooo........oooOO0OOooo........oo 63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 59 64 60 G4VParticleChange* << 65 G4VParticleChange* 61 GB05BOptnSplitAndKillByCrossSection::GenerateB << 66 GB05BOptnSplitAndKillByCrossSection::GenerateBiasingFinalState( const G4Track* track, >> 67 const G4Step* ) 62 { 68 { >> 69 63 // -- This method is called if we have limit 70 // -- This method is called if we have limited the step. 64 // -- We hence make the splitting or killing 71 // -- We hence make the splitting or killing. 65 72 66 // Get track weight: 73 // Get track weight: 67 G4double initialWeight = track->GetWeight(); 74 G4double initialWeight = track->GetWeight(); 68 << 75 69 // The "particle change" is the object to be 76 // The "particle change" is the object to be used to communicate to 70 // the tracking the update of the primary st 77 // the tracking the update of the primary state and/or creation 71 // secondary tracks. 78 // secondary tracks. 72 fParticleChange.Initialize(*track); 79 fParticleChange.Initialize(*track); 73 80 74 // -- Splitting and killing factors. 81 // -- Splitting and killing factors. 75 // -- They are taken the same, but the killi 82 // -- They are taken the same, but the killing factor can be make bigger. 76 G4double splittingFactor = 2.0; << 83 G4double splittingFactor = 2.0; 77 G4double killingFactor = 2.0; << 84 G4double killingFactor = 2.0; 78 85 79 if (track->GetMomentumDirection().z() > 0) { << 80 // -- We split if the track is moving forw << 81 86 82 // Define the tracks weight: << 87 if ( track->GetMomentumDirection().z() > 0 ) 83 G4double weightOfTrack = initialWeight / s << 88 { 84 << 89 // -- We split if the track is moving forward: 85 // Ask currect track weight to be changed << 90 86 fParticleChange.ProposeParentWeight(weight << 91 // Define the tracks weight: 87 // Now make clones of this track (this is << 92 G4double weightOfTrack = initialWeight/splittingFactor; 88 // we will then have the primary and clone << 93 89 // splitting by a factor 2: << 94 // Ask currect track weight to be changed to new value: 90 G4Track* clone = new G4Track(*track); << 95 fParticleChange.ProposeParentWeight( weightOfTrack ); 91 clone->SetWeight(weightOfTrack); << 96 // Now make clones of this track (this is the actual splitting): 92 fParticleChange.AddSecondary(clone); << 97 // we will then have the primary and clone of it, hence the 93 // -- Below's call added for safety & illu << 98 // splitting by a factor 2: 94 // -- modify the clone (ie : daughter) wei << 99 G4Track* clone = new G4Track( *track ); 95 // -- primary. Here call not mandatory and << 100 clone->SetWeight( weightOfTrack ); 96 fParticleChange.SetSecondaryWeightByProces << 101 fParticleChange.AddSecondary( clone ); 97 } << 102 // -- Below's call added for safety & illustration : inform particle change to not 98 else { << 103 // -- modify the clone (ie : daughter) weight to male it that of the 99 // -- We apply Russian roulette if the tra << 104 // -- primary. Here call not mandatory and both tracks have same weights. 100 << 105 fParticleChange.SetSecondaryWeightByProcess(true); 101 // Shoot a random number (in ]0,1[ segment << 102 G4double random = G4UniformRand(); << 103 G4double killingProbability = 1.0 - 1.0 / << 104 if (random < killingProbability) { << 105 // We ask for the the track to be killed << 106 fParticleChange.ProposeTrackStatus(fStop << 107 } 106 } 108 else { << 107 else 109 // In this case, the track survives. We << 108 { 110 // to conserve weight among killed and s << 109 // -- We apply Russian roulette if the track is moving backward: 111 fParticleChange.ProposeParentWeight(init << 110 >> 111 // Shoot a random number (in ]0,1[ segment): >> 112 G4double random = G4UniformRand(); >> 113 G4double killingProbability = 1.0 - 1.0/killingFactor; >> 114 if ( random < killingProbability ) >> 115 { >> 116 // We ask for the the track to be killed: >> 117 fParticleChange.ProposeTrackStatus(fStopAndKill); >> 118 } >> 119 else >> 120 { >> 121 // In this case, the track survives. We change its weight >> 122 // to conserve weight among killed and survival tracks: >> 123 fParticleChange.ProposeParentWeight( initialWeight*killingFactor ); >> 124 } 112 } 125 } 113 } << 126 114 << 115 return &fParticleChange; 127 return &fParticleChange; >> 128 116 } 129 } 117 130 118 //....oooOO0OOooo........oooOO0OOooo........oo 131 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 119 132