Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4LinInterpolation Class Reference

#include <G4LinInterpolation.hh>

+ Inheritance diagram for G4LinInterpolation:

Public Member Functions

 G4LinInterpolation ()
 
 ~G4LinInterpolation ()
 
G4double Calculate (G4double point, G4int bin, const G4DataVector &energies, const G4DataVector &data) const override
 
G4double Calculate (G4double point, G4int bin, const G4DataVector &energies, const G4DataVector &data, const G4DataVector &log_energies, const G4DataVector &log_data) const override
 
G4VDataSetAlgorithmClone () const override
 
- Public Member Functions inherited from G4VDataSetAlgorithm
 G4VDataSetAlgorithm ()
 
virtual ~G4VDataSetAlgorithm ()
 
 G4VDataSetAlgorithm (const G4VDataSetAlgorithm &)=delete
 
G4VDataSetAlgorithmoperator= (const G4VDataSetAlgorithm &right)=delete
 

Detailed Description

Definition at line 51 of file G4LinInterpolation.hh.

Constructor & Destructor Documentation

◆ G4LinInterpolation()

G4LinInterpolation::G4LinInterpolation ( )
explicit

Definition at line 42 of file G4LinInterpolation.cc.

43{ }

Referenced by Clone().

◆ ~G4LinInterpolation()

G4LinInterpolation::~G4LinInterpolation ( )

Definition at line 47 of file G4LinInterpolation.cc.

48{ }

Member Function Documentation

◆ Calculate() [1/2]

G4double G4LinInterpolation::Calculate ( G4double point,
G4int bin,
const G4DataVector & energies,
const G4DataVector & data ) const
overridevirtual

Implements G4VDataSetAlgorithm.

Definition at line 55 of file G4LinInterpolation.cc.

58{
59 //G4cout << "G4LinInterpolation is performed (2 arguments)" << G4endl;
60 G4int nBins = G4int(data.size() - 1);
61 G4double value = 0.;
62 if (x < points[0])
63 {
64 value = 0.;
65 }
66 else if (bin < nBins)
67 {
68 G4double e1 = points[bin];
69 G4double e2 = points[bin+1];
70 G4double d1 = data[bin];
71 G4double d2 = data[bin+1];
72 value = d1 + (d2 - d1)*(x - e1)/(e2 - e1);
73 }
74 else
75 {
76 value = data[nBins];
77 }
78 return value;
79}
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85

Referenced by G4DataSet::RandomSelect(), and G4EMDataSet::RandomSelect().

◆ Calculate() [2/2]

G4double G4LinInterpolation::Calculate ( G4double point,
G4int bin,
const G4DataVector & energies,
const G4DataVector & data,
const G4DataVector & log_energies,
const G4DataVector & log_data ) const
overridevirtual

Implements G4VDataSetAlgorithm.

Definition at line 85 of file G4LinInterpolation.cc.

90{
91//Linear Interpolation is performed on loagarithmic data set
92//Equivalent to log-log interpolation on non-loagarithmic data set
93 //G4cout << "G4LinInterpolation is performed - (4 arguments)" << G4endl;
94 G4int nBins = G4int(data.size() - 1);
95 G4double value = 0.;
96 G4double log_x = std::log10(x);
97 if (x < points[0])
98 {
99 value = 0.;
100 }
101 else if (bin < nBins)
102 {
103 G4double log_e1 = log_points[bin];
104 G4double log_e2 = log_points[bin+1];
105 G4double log_d1 = log_data[bin];
106 G4double log_d2 = log_data[bin+1];
107
108// Values e1, e2, d1 and d2 are the log values of the corresponding
109// original energy and data values. Simple linear interpolation performed
110// on loagarithmic data should be equivalent to log-log interpolation
111 value = log_d1 + (log_d2 - log_d1)*(log_x - log_e1)/(log_e2 - log_e1);
112
113// Delogarithmize to obtain interpolated value
114 value = std::pow(10.,value);
115 }
116 else
117 {
118 value = data[nBins];
119 }
120 return value;
121}

◆ Clone()

G4VDataSetAlgorithm * G4LinInterpolation::Clone ( ) const
overridevirtual

Implements G4VDataSetAlgorithm.

Definition at line 51 of file G4LinInterpolation.cc.


The documentation for this class was generated from the following files: