Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ParticleHPInterpolator.hh
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 //
27 // 080809 Change interpolation scheme of "histogram", now using LinearLinear
28 // For multidimensional interpolations By T. Koi
29 //
30 // P. Arce, June-2014 Conversion neutron_hp to particle_hp
31 //
32 #ifndef G4ParticleHPInterpolator_h
33 #define G4ParticleHPInterpolator_h 1
34 
35 #include "globals.hh"
36 #include "G4InterpolationScheme.hh"
37 #include "Randomize.hh"
38 #include "G4ios.hh"
39 #include "G4Exp.hh"
40 #include "G4Log.hh"
41 #include "G4HadronicException.hh"
42 
43 
45 {
46  public:
47 
50  {
51  // G4cout <<"deleted the interpolator"<<G4endl;
52  }
53 
55  {
56  G4double slope=0, off=0;
57  if(x2-x1==0) return (y2+y1)/2.;
58  slope = (y2-y1)/(x2-x1);
59  off = y2-x2*slope;
60  G4double y = x*slope+off;
61  return y;
62  }
63 
65  G4double x, G4double x1, G4double x2,
66  G4double y1, G4double y2) const;
68  G4double x, G4double x1, G4double x2,
69  G4double y1, G4double y2) const;
70 
71  G4double
72  GetBinIntegral(const G4InterpolationScheme & aScheme,
73  const G4double x1,const G4double x2,const G4double y1,const G4double y2);
74 
75  G4double
77  const G4double x1,const G4double x2,const G4double y1,const G4double y2);
78 
79  private:
80 
81  inline G4double Histogram(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
82  inline G4double LinearLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
83  inline G4double LinearLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
84  inline G4double LogarithmicLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
85  inline G4double LogarithmicLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
86  inline G4double Random(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
87 
88 };
89 
92  G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
93 {
94  G4double result(0);
95  G4int theScheme = aScheme;
96  theScheme = theScheme%CSTART_;
97  switch(theScheme)
98  {
99  case 1:
100  //080809
101  //result = Histogram(x, x1, x2, y1, y2);
102  result = LinearLinear(x, x1, x2, y1, y2);
103  break;
104  case 2:
105  result = LinearLinear(x, x1, x2, y1, y2);
106  break;
107  case 3:
108  result = LinearLogarithmic(x, x1, x2, y1, y2);
109  break;
110  case 4:
111  result = LogarithmicLinear(x, x1, x2, y1, y2);
112  break;
113  case 5:
114  result = LogarithmicLogarithmic(x, x1, x2, y1, y2);
115  break;
116  case 6:
117  result = Random(x, x1, x2, y1, y2);
118  break;
119  default:
120  G4cout << "theScheme = "<<theScheme<<G4endl;
121  throw G4HadronicException(__FILE__, __LINE__, "G4ParticleHPInterpolator::Carthesian Invalid InterpolationScheme");
122  break;
123  }
124  return result;
125 }
126 
129  G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
130 {
131  G4double result(0);
132  G4int theScheme = aScheme;
133  theScheme = theScheme%CSTART_;
134  switch(theScheme)
135  {
136  case 1:
137  result = Histogram(x, x1, x2, y1, y2);
138  break;
139  case 2:
140  result = LinearLinear(x, x1, x2, y1, y2);
141  break;
142  case 3:
143  result = LinearLogarithmic(x, x1, x2, y1, y2);
144  break;
145  case 4:
146  result = LogarithmicLinear(x, x1, x2, y1, y2);
147  break;
148  case 5:
149  result = LogarithmicLogarithmic(x, x1, x2, y1, y2);
150  break;
151  case 6:
152  result = Random(x, x1, x2, y1, y2);
153  break;
154  default:
155  G4cout << "theScheme = "<<theScheme<<G4endl;
156  throw G4HadronicException(__FILE__, __LINE__, "G4ParticleHPInterpolator::Carthesian Invalid InterpolationScheme");
157  break;
158  }
159  return result;
160 }
161 
162 inline G4double G4ParticleHPInterpolator::
163 Histogram(G4double , G4double , G4double , G4double y1, G4double ) const
164 {
166  result = y1;
167  return result;
168 }
169 
170 inline G4double G4ParticleHPInterpolator::
171 LinearLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
172 {
173  G4double slope=0, off=0;
174  if(x2-x1==0) return (y2+y1)/2.;
175  slope = (y2-y1)/(x2-x1);
176  off = y2-x2*slope;
177  G4double y = x*slope+off;
178  return y;
179 }
180 
181 inline G4double G4ParticleHPInterpolator::
182 LinearLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
183 {
185  if(x==0) result = y1+y2/2.;
186  else if(x1==0) result = y1;
187  else if(x2==0) result = y2;
188  else result = LinearLinear(G4Log(x), G4Log(x1), G4Log(x2), y1, y2);
189  return result;
190 }
191 
192 inline G4double G4ParticleHPInterpolator::
193 LogarithmicLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
194 {
196  if(y1==0||y2==0) result = 0;
197  else
198  {
199  result = LinearLinear(x, x1, x2, G4Log(y1), G4Log(y2));
200  result = G4Exp(result);
201  }
202  return result;
203 }
204 
205 inline G4double G4ParticleHPInterpolator::
206 LogarithmicLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
207 {
208  if(x==0) return y1+y2/2.;
209  else if(x1==0) return y1;
210  else if(x2==0) return y2;
212  if(y1==0||y2==0) result = 0;
213  else
214  {
215  result = LinearLinear(G4Log(x), G4Log(x1), G4Log(x2), G4Log(y1), G4Log(y2));
216  result = G4Exp(result);
217  }
218  return result;
219 }
220 
221 inline G4double G4ParticleHPInterpolator::
222 Random(G4double , G4double , G4double , G4double y1, G4double y2) const
223 {
225  result = y1+G4UniformRand()*(y2-y1);
226  return result;
227 }
228 
229 #endif
G4double G4ParticleHPJENDLHEData::G4double result
G4double Lin(G4double x, G4double x1, G4double x2, G4double y1, G4double y2)
G4double Interpolate2(G4InterpolationScheme aScheme, G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
tuple x
Definition: test.py:50
int G4int
Definition: G4Types.hh:78
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
G4double GetWeightedBinIntegral(const G4InterpolationScheme &aScheme, const G4double x1, const G4double x2, const G4double y1, const G4double y2)
G4double Interpolate(G4InterpolationScheme aScheme, G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
G4double G4Log(G4double x)
Definition: G4Log.hh:230
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition: G4Exp.hh:183
G4InterpolationScheme
#define G4endl
Definition: G4ios.hh:61
G4double GetBinIntegral(const G4InterpolationScheme &aScheme, const G4double x1, const G4double x2, const G4double y1, const G4double y2)
double G4double
Definition: G4Types.hh:76