source: trunk/source/processes/hadronic/models/neutron_hp/src/G4NeutronHPInterpolator.cc @ 1340

Last change on this file since 1340 was 819, checked in by garnier, 16 years ago

import all except CVS

File size: 5.4 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// neutron_hp -- source file
27// J.P. Wellisch, Nov-1996
28// A prototype of the low energy neutron transport model.
29//
30#include "G4NeutronHPInterpolator.hh"
31
32  G4double G4NeutronHPInterpolator::
33  GetBinIntegral(const G4InterpolationScheme & aScheme, 
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) result =0;
59      else
60      {
61        G4double b = (std::log(y2)-std::log(y1))/(x2-x1);
62        G4double a = std::log(y1) - b*x1;
63        result = (std::exp(a)/b)*(std::exp(b*x2)-std::exp(b*x1));
64      }
65    }
66    else if(aScheme==LOGLOG||aScheme==CLOGLOG||aScheme==ULOGLOG)
67    {
68      if(x1==0) result = y1;
69      else if(x2==0) result = y2;
70      else if(y1==0||y2==0) result =0;
71      else
72      {     
73        G4double b = (std::log(y2)-std::log(y1))/(std::log(x2)-std::log(x1));
74        G4double a = std::log(y1) - b*std::log(x1);;
75        result = (std::exp(a)/(b+1))*(std::pow(x2,b+1)-std::pow(x1,b+1));
76      }
77    }
78    else
79    {
80      throw G4HadronicException(__FILE__, __LINE__, "Unknown interpolation scheme in G4NeutronHPVector::Integrate");
81    }
82    return result;
83  }
84  G4double G4NeutronHPInterpolator::
85  GetWeightedBinIntegral(const G4InterpolationScheme & aScheme, 
86                         const G4double x1,const G4double x2,const G4double y1,const G4double y2)
87  { // inline again later on @@@@
88    G4double result = 0;
89    if(aScheme==HISTO||aScheme==CHISTO||aScheme==UHISTO)
90    {
91      result = 0.5*y1*(x2*x2-x1*x1);
92    }
93    else if(aScheme==LINLIN||aScheme==CLINLIN||aScheme==ULINLIN)
94    {
95      //        G4double b = (y2-y1)/(x2-x1);
96      //        G4double a = y1 - b*x1;
97      //        result = 0.5*a*(x2*x2-x1*x1) + (b/3.)*(x2*x2*x2-x1*x1*x1);
98      //  Factor out x2-x1 to avoid divide by zero
99     
100      result = (y1*x2 - y2*x1)*(x2 + x1)/2. + (y2-y1)*(x2*x2 + x2*x1 + x1*x1)/3.;
101    }
102    else if(aScheme==LINLOG||aScheme==CLINLOG||aScheme==ULINLOG)
103    {
104      if(x1==0) result = y1;
105      else if(x2==0) result = y2;
106      else
107      {
108        G4double b = (y2-y1)/(std::log(x2)-std::log(x1));
109        G4double a = y1 - b*std::log(x1);
110        result = ( x2*x2/2. * (a-b/2.+b*std::log(x2)) )
111                -( x1*x1/2. * (a-b/2.+b*std::log(x1)) );
112      }
113    }
114    else if(aScheme==LOGLIN||aScheme==CLOGLIN||aScheme==ULOGLIN)
115    {
116      if(y1==0||y2==0) result = 0;
117      else
118      {
119        G4double b = (std::log(y2)-std::log(y1))/(x2-x1);
120        G4double a = std::log(y1) - b*x1;
121        result = std::exp(a)/(b*b)*( std::exp(b*x2)*(b*x2-1.) - std::exp(b*x1)*(b*x1-1.) );
122      }
123    }
124    else if(aScheme==LOGLOG||aScheme==CLOGLOG||aScheme==ULOGLOG)
125    {
126      if(x1==0) result = y1;
127      else if(x2==0) result = y2;
128      if(y1==0||y2==0) result = 0;
129      else
130      {
131        G4double b = (std::log(y2)-std::log(y1))/(std::log(x2)-std::log(x1));
132        G4double a = std::log(y1) - b*std::log(x1);;
133        result = std::exp(a)/(b+2.)*( std::pow(x2, b+2.) - std::pow(x1, b+2) );
134      }
135    }
136    else
137    {
138      throw G4HadronicException(__FILE__, __LINE__, "Unknown interpolation scheme in G4NeutronHPVector::Integrate");
139    }
140    return result;
141  }
Note: See TracBrowser for help on using the repository browser.