Geant4  10.02
G4BOptnForceCommonTruncatedExp.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
28 #include "G4ILawForceFreeFlight.hh"
30 
31 #include "Randomize.hh"
33 
35  : G4VBiasingOperation(name),
36  fInteractionOccured(false)
37 {
38  fCommonTruncatedExpLaw = new G4ILawCommonTruncatedExp("ExpLawForOperation"+name);
39  fForceFreeFlightLaw = new G4ILawForceFreeFlight ("FFFLawForOperation"+name);
40 
41  fTotalCrossSection = 0.0;
42 }
43 
45 {
48 }
49 
51  G4ForceCondition& proposeForceCondition )
52 {
53  if ( callingProcess->GetWrappedProcess() == fProcessToApply )
54  {
55  proposeForceCondition = Forced;
57  }
58  else
59  {
60  proposeForceCondition = Forced;
61  return fForceFreeFlightLaw;
62  }
63 }
64 
65 
67 {
69 }
70 
71 
73  const G4Track* track,
74  const G4Step* step,
75  G4bool& forceFinalState )
76 {
77  if ( callingProcess->GetWrappedProcess() != fProcessToApply )
78  {
79  forceFinalState = true;
81  return &fDummyParticleChange;
82  }
83  if ( fInteractionOccured )
84  {
85  forceFinalState = true;
87  return &fDummyParticleChange;
88  }
89 
90  // -- checks if process won the GPIL race:
91  G4double processGPIL = callingProcess->GetPostStepGPIL() < callingProcess->GetAlongStepGPIL() ?
92  callingProcess->GetPostStepGPIL() : callingProcess->GetAlongStepGPIL() ;
93  if ( processGPIL <= step->GetStepLength() )
94  {
95  // -- if process won, wrapped process produces the final state.
96  // -- In this case, the weight for occurence biasing is applied
97  // -- by the callingProcess, at exit of present method. This is
98  // -- selected by "forceFinalState = false":
99  forceFinalState = false;
100  fInteractionOccured = true;
101  return callingProcess->GetWrappedProcess()->PostStepDoIt( *track, *step );
102  }
103  else
104  {
105  forceFinalState = true;
107  return &fDummyParticleChange;
108  }
109 }
110 
111 
113 {
114  fTotalCrossSection += crossSection;
115  fCrossSections[process] = crossSection;
117 }
118 
119 
121 {
122  fCrossSections.clear();
123  fTotalCrossSection = 0.0;
124  fNumberOfSharing = 0;
125  fProcessToApply = 0;
126  fInteractionOccured = false;
127  fInitialMomentum = track->GetMomentum();
128 
129  G4VSolid* currentSolid = track->GetVolume()->GetLogicalVolume()->GetSolid();
131  GetNavigatorForTracking()->
132  GetGlobalToLocalTransform()).TransformPoint(track->GetPosition());
134  GetNavigatorForTracking()->
135  GetGlobalToLocalTransform()).TransformAxis(track->GetMomentumDirection());
136  fMaximumDistance = currentSolid->DistanceToOut(localPosition, localDirection);
137  if ( fMaximumDistance <= DBL_MIN ) fMaximumDistance = 0.0;
139 }
140 
141 
143 {
144  fCrossSections.clear();
145  fTotalCrossSection = 0.0;
146  fNumberOfSharing = 0;
147  fProcessToApply = 0;
148 
151 }
152 
153 
155 {
160 }
161 
162 
164 {
165  G4double sigmaRand = G4UniformRand() * fTotalCrossSection;
166  G4double sigmaSelect = 0.0;
167  for ( std::map< const G4VProcess*, G4double>::const_iterator it = fCrossSections.begin();
168  it != fCrossSections.end();
169  it++)
170  {
171  sigmaSelect += (*it).second;
172  if ( sigmaRand <= sigmaSelect )
173  {
174  fProcessToApply = (*it).first;
175  break;
176  }
177  }
178 }
virtual void Initialize(const G4Track &track)
std::map< const G4VProcess *, G4double > fCrossSections
virtual G4VParticleChange * ApplyFinalStateBiasing(const G4BiasingProcessInterface *, const G4Track *, const G4Step *, G4bool &)
virtual const G4VBiasingInteractionLaw * ProvideOccurenceBiasingInteractionLaw(const G4BiasingProcessInterface *, G4ForceCondition &)
CLHEP::Hep3Vector G4ThreeVector
G4double GetStepLength() const
void SetSelectedProcessXSfraction(G4double fXS)
G4String name
Definition: TRTMaterials.hh:40
void AddCrossSection(const G4VProcess *, G4double)
const G4ThreeVector & GetPosition() const
G4VProcess * GetWrappedProcess() const
#define G4UniformRand()
Definition: Randomize.hh:97
bool G4bool
Definition: G4Types.hh:79
Definition: G4Step.hh:76
static G4TransportationManager * GetTransportationManager()
G4ThreeVector GetMomentum() const
const G4ThreeVector & GetMomentumDirection() const
G4LogicalVolume * GetLogicalVolume() const
G4ILawCommonTruncatedExp * fCommonTruncatedExpLaw
#define DBL_MIN
Definition: templates.hh:75
G4double UpdateForStep(G4double truePathLength)
G4VPhysicalVolume * GetVolume() const
double G4double
Definition: G4Types.hh:76
virtual G4VParticleChange * PostStepDoIt(const G4Track &track, const G4Step &stepData)=0
virtual G4GPILSelection ProposeGPILSelection(const G4GPILSelection processSelection)
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const =0
G4ForceCondition
G4VSolid * GetSolid() const
G4GPILSelection