Geant4  10.00.p01
G4ILawTruncatedExp.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 //
26 #include "G4ILawTruncatedExp.hh"
27 #include "Randomize.hh"
28 #include "G4Track.hh"
29 
30 //#include "G4Exception.hh"
31 
34  fMaximumDistance(0.0),
35  fCrossSection(0.0),
36  fCrossSectionDefined(false),
37  fIsSingular(false)
38 {}
39 
41 {}
42 
44 {
45  if (crossSection < 0.0)
46  {
47  G4Exception("G4ILawTruncatedExp::SetForceCrossSection(..)",
48  "BIAS.GEN.09",
50  "Cross-section value passed is negative. It is set to zero !");
51  fIsSingular = true;
52  crossSection = 0.0;
53  }
54  fIsSingular = false;
55  fCrossSectionDefined = true;
56  fCrossSection = crossSection;
57 }
58 
60 {
61  if ( !fCrossSectionDefined )
62  {
63  G4Exception("G4ILawTruncatedExp::ComputeEffectiveCrossSection(..)",
64  "BIAS.GEN.10",
66  "Cross-section value requested, but has not been defined yet. Assumes 0 !");
67  // -- zero cross-section, returns the limit form of the effective cross-section:
68  return 1.0 / ( fMaximumDistance - distance );
69  }
70  G4double denum = 1.0 - std::exp( -fCrossSection * ( fMaximumDistance - distance) );
71  return fCrossSection / denum;
72 }
73 
75 {
77  {
78  G4Exception("G4ILawTruncatedExp::ComputeNonInteractionProbability(..)",
79  "BIAS.GEN.11",
81  "Non interaction probability value requested, but cross section has not been defined yet. Assumes it to be 0 !");
82  // -- return limit case of null cross-section:
83  return 1.0 - distance / fMaximumDistance;
84  }
85  G4double num = 1.0 - std::exp( -fCrossSection*distance);
86  G4double denum = 1.0 - std::exp( -fCrossSection*fMaximumDistance);
87  return 1.0 - num/denum;
88 }
89 
91 {
92  if ( !fCrossSectionDefined )
93  {
94  G4Exception("G4ILawTruncatedExp::Sample(..)",
95  "BIAS.GEN.12",
97  "Trying to sample while cross-section is not defined, assuming 0 !");
99  return fInteractionDistance;
100  }
101  fInteractionDistance = -std::log(1.0 - G4UniformRand()* (1.0 - std::exp(-fCrossSection*fMaximumDistance)))/fCrossSection;
102  return fInteractionDistance;
103 }
104 
105 
107 {
108  fInteractionDistance -= truePathLength;
109  fMaximumDistance -= truePathLength;
110 
111  if ( fInteractionDistance < 0 )
112  {
114  ed << " Negative number of interaction length for `" << GetName() << "' " << fInteractionDistance << ", set it to zero !" << G4endl;
115  G4Exception("G4ILawTruncatedExp::UpdateInteractionLengthForStep(...)",
116  "BIAS.GEN.13",
117  JustWarning,
118  "Trying to sample while cross-section is not defined, assuming 0 !");
120  }
121 
122  return fInteractionDistance;
123 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
virtual G4double ComputeNonInteractionProbabilityAt(G4double length) const
G4String name
Definition: TRTMaterials.hh:40
virtual G4double SampleInteractionLength()
G4ILawTruncatedExp(G4String name="expForceInteractionLaw")
#define G4UniformRand()
Definition: Randomize.hh:87
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual G4double UpdateInteractionLengthForStep(G4double truePathLength)
#define G4endl
Definition: G4ios.hh:61
const G4String & GetName() const
double G4double
Definition: G4Types.hh:76
virtual G4double ComputeEffectiveCrossSectionAt(G4double length) const
void SetForceCrossSection(G4double xs)