Geant4  10.01.p03
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 "G4HadronicException.hh"
40 
41 
43 {
44  public:
45 
48  {
49  // G4cout <<"deleted the interpolator"<<G4endl;
50  }
51 
53  {
54  G4double slope=0, off=0;
55  if(x2-x1==0) return (y2+y1)/2.;
56  slope = (y2-y1)/(x2-x1);
57  off = y2-x2*slope;
58  G4double y = x*slope+off;
59  return y;
60  }
61 
63  G4double x, G4double x1, G4double x2,
64  G4double y1, G4double y2) const;
66  G4double x, G4double x1, G4double x2,
67  G4double y1, G4double y2) const;
68 
69  G4double
70  GetBinIntegral(const G4InterpolationScheme & aScheme,
71  const G4double x1,const G4double x2,const G4double y1,const G4double y2);
72 
73  G4double
75  const G4double x1,const G4double x2,const G4double y1,const G4double y2);
76 
77  private:
78 
79  inline G4double Histogram(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
80  inline G4double LinearLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
81  inline G4double LinearLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
82  inline G4double LogarithmicLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
84  inline G4double Random(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
85 
86 };
87 
90  G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
91 {
92  G4double result(0);
93  G4int theScheme = aScheme;
94  theScheme = theScheme%CSTART_;
95  switch(theScheme)
96  {
97  case 1:
98  //080809
99  //result = Histogram(x, x1, x2, y1, y2);
100  result = LinearLinear(x, x1, x2, y1, y2);
101  break;
102  case 2:
103  result = LinearLinear(x, x1, x2, y1, y2);
104  break;
105  case 3:
106  result = LinearLogarithmic(x, x1, x2, y1, y2);
107  break;
108  case 4:
109  result = LogarithmicLinear(x, x1, x2, y1, y2);
110  break;
111  case 5:
112  result = LogarithmicLogarithmic(x, x1, x2, y1, y2);
113  break;
114  case 6:
115  result = Random(x, x1, x2, y1, y2);
116  break;
117  default:
118  G4cout << "theScheme = "<<theScheme<<G4endl;
119  throw G4HadronicException(__FILE__, __LINE__, "G4ParticleHPInterpolator::Carthesian Invalid InterpolationScheme");
120  break;
121  }
122  return result;
123 }
124 
127  G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
128 {
129  G4double result(0);
130  G4int theScheme = aScheme;
131  theScheme = theScheme%CSTART_;
132  switch(theScheme)
133  {
134  case 1:
135  result = Histogram(x, x1, x2, y1, y2);
136  break;
137  case 2:
138  result = LinearLinear(x, x1, x2, y1, y2);
139  break;
140  case 3:
141  result = LinearLogarithmic(x, x1, x2, y1, y2);
142  break;
143  case 4:
144  result = LogarithmicLinear(x, x1, x2, y1, y2);
145  break;
146  case 5:
147  result = LogarithmicLogarithmic(x, x1, x2, y1, y2);
148  break;
149  case 6:
150  result = Random(x, x1, x2, y1, y2);
151  break;
152  default:
153  G4cout << "theScheme = "<<theScheme<<G4endl;
154  throw G4HadronicException(__FILE__, __LINE__, "G4ParticleHPInterpolator::Carthesian Invalid InterpolationScheme");
155  break;
156  }
157  return result;
158 }
159 
162 {
163  G4double result;
164  result = y1;
165  return result;
166 }
167 
170 {
171  G4double slope=0, off=0;
172  if(x2-x1==0) return (y2+y1)/2.;
173  slope = (y2-y1)/(x2-x1);
174  off = y2-x2*slope;
175  G4double y = x*slope+off;
176  return y;
177 }
178 
181 {
182  G4double result;
183  if(x==0) result = y1+y2/2.;
184  else if(x1==0) result = y1;
185  else if(x2==0) result = y2;
186  else result = LinearLinear(std::log(x), std::log(x1), std::log(x2), y1, y2);
187  return result;
188 }
189 
192 {
193  G4double result;
194  if(y1==0||y2==0) result = 0;
195  else
196  {
197  result = LinearLinear(x, x1, x2, std::log(y1), std::log(y2));
198  result = std::exp(result);
199  }
200  return result;
201 }
202 
205 {
206  G4double result;
207  if(x==0) result = y1+y2/2.;
208  else if(x1==0) result = y1;
209  else if(x2==0) result = y2;
210  if(y1==0||y2==0) result = 0;
211  else
212  {
213  result = LinearLinear(std::log(x), std::log(x1), std::log(x2), std::log(y1), std::log(y2));
214  result = std::exp(result);
215  }
216  return result;
217 }
218 
221 {
222  G4double result;
223  result = y1+G4UniformRand()*(y2-y1);
224  return result;
225 }
226 
227 #endif
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
G4double Random(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
int G4int
Definition: G4Types.hh:78
#define G4UniformRand()
Definition: Randomize.hh:93
G4GLOB_DLL std::ostream G4cout
G4double LogarithmicLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
G4double LinearLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
G4double LinearLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
G4double Histogram(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
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
G4InterpolationScheme
#define G4endl
Definition: G4ios.hh:61
G4double GetBinIntegral(const G4InterpolationScheme &aScheme, const G4double x1, const G4double x2, const G4double y1, const G4double y2)
G4double LogarithmicLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
double G4double
Definition: G4Types.hh:76