source: trunk/source/processes/hadronic/models/neutron_hp/include/G4NeutronHPInterpolator.hh@ 830

Last change on this file since 830 was 819, checked in by garnier, 17 years ago

import all except CVS

File size: 6.1 KB
Line 
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: G4NeutronHPInterpolator.hh,v 1.19 2006/06/29 20:48:13 gunter Exp $
28// GEANT4 tag $Name: $
29//
30#ifndef G4NeutronHPInterpolator_h
31#define G4NeutronHPInterpolator_h 1
32
33#include "globals.hh"
34#include "G4InterpolationScheme.hh"
35#include "Randomize.hh"
36#include "G4ios.hh"
37#include "G4HadronicException.hh"
38
39
40class G4NeutronHPInterpolator
41{
42 public:
43
44 G4NeutronHPInterpolator(){}
45 ~G4NeutronHPInterpolator()
46 {
47 // G4cout <<"deleted the interpolator"<<G4endl;
48 }
49
50 inline G4double Lin(G4double x,G4double x1,G4double x2,G4double y1,G4double y2)
51 {
52 G4double slope=0, off=0;
53 if(x2-x1==0) return (y2+y1)/2.;
54 slope = (y2-y1)/(x2-x1);
55 off = y2-x2*slope;
56 G4double y = x*slope+off;
57 return y;
58 }
59
60 inline G4double Interpolate(G4InterpolationScheme aScheme,
61 G4double x, G4double x1, G4double x2,
62 G4double y1, G4double y2) const;
63
64 G4double
65 GetBinIntegral(const G4InterpolationScheme & aScheme,
66 const G4double x1,const G4double x2,const G4double y1,const G4double y2);
67
68 G4double
69 GetWeightedBinIntegral(const G4InterpolationScheme & aScheme,
70 const G4double x1,const G4double x2,const G4double y1,const G4double y2);
71
72 private:
73
74 inline G4double Histogram(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
75 inline G4double LinearLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
76 inline G4double LinearLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
77 inline G4double LogarithmicLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
78 inline G4double LogarithmicLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
79 inline G4double Random(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const;
80
81};
82
83inline G4double G4NeutronHPInterpolator::
84Interpolate(G4InterpolationScheme aScheme,
85 G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
86{
87 G4double result(0);
88 G4int theScheme = aScheme;
89 theScheme = theScheme%CSTART_;
90 switch(theScheme)
91 {
92 case 1:
93 result = Histogram(x, x1, x2, y1, y2);
94 break;
95 case 2:
96 result = LinearLinear(x, x1, x2, y1, y2);
97 break;
98 case 3:
99 result = LinearLogarithmic(x, x1, x2, y1, y2);
100 break;
101 case 4:
102 result = LogarithmicLinear(x, x1, x2, y1, y2);
103 break;
104 case 5:
105 result = LogarithmicLogarithmic(x, x1, x2, y1, y2);
106 break;
107 case 6:
108 result = Random(x, x1, x2, y1, y2);
109 break;
110 default:
111 G4cout << "theScheme = "<<theScheme<<G4endl;
112 throw G4HadronicException(__FILE__, __LINE__, "G4NeutronHPInterpolator::Carthesian Invalid InterpolationScheme");
113 break;
114 }
115 return result;
116}
117
118inline G4double G4NeutronHPInterpolator::
119Histogram(G4double , G4double , G4double , G4double y1, G4double ) const
120{
121 G4double result;
122 result = y1;
123 return result;
124}
125
126inline G4double G4NeutronHPInterpolator::
127LinearLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
128{
129 G4double slope=0, off=0;
130 if(x2-x1==0) return (y2+y1)/2.;
131 slope = (y2-y1)/(x2-x1);
132 off = y2-x2*slope;
133 G4double y = x*slope+off;
134 return y;
135}
136
137inline G4double G4NeutronHPInterpolator::
138LinearLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
139{
140 G4double result;
141 if(x==0) result = y1+y2/2.;
142 else if(x1==0) result = y1;
143 else if(x2==0) result = y2;
144 else result = LinearLinear(std::log(x), std::log(x1), std::log(x2), y1, y2);
145 return result;
146}
147
148inline G4double G4NeutronHPInterpolator::
149LogarithmicLinear(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
150{
151 G4double result;
152 if(y1==0||y2==0) result = 0;
153 else
154 {
155 result = LinearLinear(x, x1, x2, std::log(y1), std::log(y2));
156 result = std::exp(result);
157 }
158 return result;
159}
160
161inline G4double G4NeutronHPInterpolator::
162LogarithmicLogarithmic(G4double x, G4double x1, G4double x2, G4double y1, G4double y2) const
163{
164 G4double result;
165 if(x==0) result = y1+y2/2.;
166 else if(x1==0) result = y1;
167 else if(x2==0) result = y2;
168 if(y1==0||y2==0) result = 0;
169 else
170 {
171 result = LinearLinear(std::log(x), std::log(x1), std::log(x2), std::log(y1), std::log(y2));
172 result = std::exp(result);
173 }
174 return result;
175}
176
177inline G4double G4NeutronHPInterpolator::
178Random(G4double , G4double , G4double , G4double y1, G4double y2) const
179{
180 G4double result;
181 result = y1+G4UniformRand()*(y2-y1);
182 return result;
183}
184
185#endif
Note: See TracBrowser for help on using the repository browser.