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