Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4NeutronHPInterpolator.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 // $Id$
28 //
29 // 080809 Change interpolation scheme of "histogram", now using LinearLinear
30 // For multidimensional interpolations By T. Koi
31 //
32 #ifndef G4NeutronHPInterpolator_h
33 #define G4NeutronHPInterpolator_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 
64  G4double y1, G4double y2) const;
65 
66  G4double
67  GetBinIntegral(const G4InterpolationScheme & aScheme,
68  const G4double x1,const G4double x2,const G4double y1,const G4double y2);
69 
70  G4double
72  const G4double x1,const G4double x2,const G4double y1,const G4double y2);
73 
74  private:
75 
76  inline G4double Histogram(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
77  inline G4double LinearLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
78  inline G4double LinearLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
79  inline G4double LogarithmicLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
80  inline G4double LogarithmicLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
81  inline G4double Random(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
82 
83 };
84 
88 {
89  G4double result(0);
90  G4int theScheme = aScheme;
91  theScheme = theScheme%CSTART_;
92  switch(theScheme)
93  {
94  case 1:
95  //080809
96  //result = Histogram(x, x1, x2, y1, y2);
97  result = LinearLinear(x, x1, x2, y1, y2);
98  break;
99  case 2:
100  result = LinearLinear(x, x1, x2, y1, y2);
101  break;
102  case 3:
103  result = LinearLogarithmic(x, x1, x2, y1, y2);
104  break;
105  case 4:
106  result = LogarithmicLinear(x, x1, x2, y1, y2);
107  break;
108  case 5:
109  result = LogarithmicLogarithmic(x, x1, x2, y1, y2);
110  break;
111  case 6:
112  result = Random(x, x1, x2, y1, y2);
113  break;
114  default:
115  G4cout << "theScheme = "<<theScheme<<G4endl;
116  throw G4HadronicException(__FILE__, __LINE__, "G4NeutronHPInterpolator::Carthesian Invalid InterpolationScheme");
117  break;
118  }
119  return result;
120 }
121 
122 inline G4double G4NeutronHPInterpolator::
123 Histogram(G4double , G4double , G4double , G4double y1, G4double ) const
124 {
125  G4double result;
126  result = y1;
127  return result;
128 }
129 
130 inline G4double G4NeutronHPInterpolator::
131 LinearLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
132 {
133  G4double slope=0, off=0;
134  if(x2-x1==0) return (y2+y1)/2.;
135  slope = (y2-y1)/(x2-x1);
136  off = y2-x2*slope;
137  G4double y = x*slope+off;
138  return y;
139 }
140 
141 inline G4double G4NeutronHPInterpolator::
142 LinearLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
143 {
144  G4double result;
145  if(x==0) result = y1+y2/2.;
146  else if(x1==0) result = y1;
147  else if(x2==0) result = y2;
148  else result = LinearLinear(std::log(x), std::log(x1), std::log(x2), y1, y2);
149  return result;
150 }
151 
152 inline G4double G4NeutronHPInterpolator::
153 LogarithmicLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
154 {
155  G4double result;
156  if(y1==0||y2==0) result = 0;
157  else
158  {
159  result = LinearLinear(x, x1, x2, std::log(y1), std::log(y2));
160  result = std::exp(result);
161  }
162  return result;
163 }
164 
165 inline G4double G4NeutronHPInterpolator::
166 LogarithmicLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
167 {
168  G4double result;
169  if(x==0) result = y1+y2/2.;
170  else if(x1==0) result = y1;
171  else if(x2==0) result = y2;
172  if(y1==0||y2==0) result = 0;
173  else
174  {
175  result = LinearLinear(std::log(x), std::log(x1), std::log(x2), std::log(y1), std::log(y2));
176  result = std::exp(result);
177  }
178  return result;
179 }
180 
181 inline G4double G4NeutronHPInterpolator::
182 Random(G4double , G4double , G4double , G4double y1, G4double y2) const
183 {
184  G4double result;
185  result = y1+G4UniformRand()*(y2-y1);
186  return result;
187 }
188 
189 #endif