Geant4  10.01.p02
G4NeutronHPInterpolator.cc
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 // neutron_hp -- source file
27 // J.P. Wellisch, Nov-1996
28 // A prototype of the low energy neutron transport model.
29 //
31 
34  const G4double x1,const G4double x2,const G4double y1,const G4double y2)
35  { // inline again later on @@@@
36  G4double result = 0;
37  if(aScheme==HISTO||aScheme==CHISTO||aScheme==UHISTO)
38  {
39  result = y1*(x2-x1);
40  }
41  else if(aScheme==LINLIN||aScheme==CLINLIN||aScheme==ULINLIN)
42  {
43  result = 0.5*(y2+y1)*(x2-x1);
44  }
45  else if(aScheme==LINLOG||aScheme==CLINLOG||aScheme==ULINLOG)
46  {
47  if(x1==0) result = y1;
48  else if(x2==0) result = y2;
49  else
50  {
51  G4double b = (y2-y1)/(std::log(x2)-std::log(x1));
52  G4double a = y1 - b*std::log(x1);
53  result = (a-b)*(x2-x1) + b*(x2*std::log(x2)-x1*std::log(x1));
54  }
55  }
56  else if(aScheme==LOGLIN||aScheme==CLOGLIN||aScheme==ULOGLIN)
57  {
58  if ( y1==0||y2==0 ) {
59  result =0;
60  } else {
61  // G4double b = (std::log(y2)-std::log(y1))/(x2-x1);
62  // G4double a = std::log(y1) - b*x1;
63  //***************************************************************
64  //EMendoza:
65  //result = (std::exp(a)/b)*(std::exp(b*x2)-std::exp(b*x1));
66  //***************************************************************
67  if ( y1!=y2 ) {
68  result = (x2-x1)*(y2-y1)/std::log(y2/y1);
69  } else {
70  result = y2*(x2-x1);
71  }
72  //***************************************************************
73  }
74  }
75  else if(aScheme==LOGLOG||aScheme==CLOGLOG||aScheme==ULOGLOG)
76  {
77  if(x1==0) result = y1;
78  else if(x2==0) result = y2;
79  else if(y1==0||y2==0) result =0;
80  else
81  {
82  G4double b = (std::log(y2)-std::log(y1))/(std::log(x2)-std::log(x1));
83  G4double a = std::log(y1) - b*std::log(x1);;
84  result = (std::exp(a)/(b+1))*(std::pow(x2,b+1)-std::pow(x1,b+1));
85  }
86  }
87  else
88  {
89  throw G4HadronicException(__FILE__, __LINE__, "Unknown interpolation scheme in G4NeutronHPVector::Integrate");
90  }
91  return result;
92  }
95  const G4double x1,const G4double x2,const G4double y1,const G4double y2)
96  { // inline again later on @@@@
97  G4double result = 0;
98  if(aScheme==HISTO||aScheme==CHISTO||aScheme==UHISTO)
99  {
100  result = 0.5*y1*(x2*x2-x1*x1);
101  }
102  else if(aScheme==LINLIN||aScheme==CLINLIN||aScheme==ULINLIN)
103  {
104  // G4double b = (y2-y1)/(x2-x1);
105  // G4double a = y1 - b*x1;
106  // result = 0.5*a*(x2*x2-x1*x1) + (b/3.)*(x2*x2*x2-x1*x1*x1);
107  // Factor out x2-x1 to avoid divide by zero
108 
109  result = (y1*x2 - y2*x1)*(x2 + x1)/2. + (y2-y1)*(x2*x2 + x2*x1 + x1*x1)/3.;
110  }
111  else if(aScheme==LINLOG||aScheme==CLINLOG||aScheme==ULINLOG)
112  {
113  if(x1==0) result = y1;
114  else if(x2==0) result = y2;
115  else
116  {
117  G4double b = (y2-y1)/(std::log(x2)-std::log(x1));
118  G4double a = y1 - b*std::log(x1);
119  result = ( x2*x2/2. * (a-b/2.+b*std::log(x2)) )
120  -( x1*x1/2. * (a-b/2.+b*std::log(x1)) );
121  }
122  }
123  else if(aScheme==LOGLIN||aScheme==CLOGLIN||aScheme==ULOGLIN)
124  {
125  if(y1==0||y2==0) result = 0;
126  else
127  {
128  G4double b = (std::log(y2)-std::log(y1))/(x2-x1);
129  G4double a = std::log(y1) - b*x1;
130  result = std::exp(a)/(b*b)*( std::exp(b*x2)*(b*x2-1.) - std::exp(b*x1)*(b*x1-1.) );
131  }
132  }
133  else if(aScheme==LOGLOG||aScheme==CLOGLOG||aScheme==ULOGLOG)
134  {
135  if(x1==0) result = y1;
136  else if(x2==0) result = y2;
137  if(y1==0||y2==0) result = 0;
138  else
139  {
140  G4double b = (std::log(y2)-std::log(y1))/(std::log(x2)-std::log(x1));
141  G4double a = std::log(y1) - b*std::log(x1);;
142  result = std::exp(a)/(b+2.)*( std::pow(x2, b+2.) - std::pow(x1, b+2) );
143  }
144  }
145  else
146  {
147  throw G4HadronicException(__FILE__, __LINE__, "Unknown interpolation scheme in G4NeutronHPVector::Integrate");
148  }
149  return result;
150  }
G4double a
Definition: TRTMaterials.hh:39
G4double GetWeightedBinIntegral(const G4InterpolationScheme &aScheme, const G4double x1, const G4double x2, const G4double y1, const G4double y2)
G4double GetBinIntegral(const G4InterpolationScheme &aScheme, const G4double x1, const G4double x2, const G4double y1, const G4double y2)
G4InterpolationScheme
double G4double
Definition: G4Types.hh:76