00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // 00028 // Author: Vladimir Ivanchenko (Vladimir.Ivantchenko@cern.ch) 00029 // 00030 // History: 00031 // ----------- 00032 // 27 May 2002 VI Created 00033 // 00034 // ------------------------------------------------------------------- 00035 00036 #include "G4LinLogInterpolation.hh" 00037 00038 // Constructor 00039 00040 G4LinLogInterpolation::G4LinLogInterpolation() 00041 { } 00042 00043 00044 // Destructor 00045 00046 G4LinLogInterpolation::~G4LinLogInterpolation() 00047 { } 00048 00049 00050 G4double G4LinLogInterpolation::Calculate(G4double x, G4int bin, 00051 const G4DataVector& points, 00052 const G4DataVector& data) const 00053 { 00054 //G4cout << "G4LinLogInterpolation is performed on dataset (2 arguments) " << G4endl; 00055 G4int nBins = data.size() - 1; 00056 G4double value = 0.; 00057 if (x < points[0]) 00058 { 00059 value = 0.; 00060 } 00061 else if (bin < nBins) 00062 { 00063 G4double e1 = points[bin]; 00064 G4double e2 = points[bin+1]; 00065 G4double d1 = std::log(data[bin]); 00066 G4double d2 = std::log(data[bin+1]); 00067 value = std::exp(d1 + (d2 - d1)*(x - e1)/ (e2 - e1)); 00068 } 00069 else 00070 { 00071 value = data[nBins]; 00072 } 00073 return value; 00074 } 00075 00076 G4double G4LinLogInterpolation::Calculate(G4double x, G4int bin, 00077 const G4DataVector& points, 00078 const G4DataVector& data, 00079 const G4DataVector& /*log_points*/, 00080 const G4DataVector& log_data) const 00081 { 00082 //G4cout << "G4LinLogInterpolation is performed on dataset (4 arguments) " << G4endl; 00083 G4int nBins = data.size() - 1; 00084 G4double value = 0.; 00085 //G4double log_x = std::log10(x); 00086 if (x < points[0]) 00087 { 00088 value = 0.; 00089 } 00090 else if (bin < nBins) 00091 { 00092 G4double e1 = points[bin]; 00093 G4double e2 = points[bin+1]; 00094 G4double d1 = data[bin]; 00095 G4double d2 = data[bin+1]; 00096 //G4double log_e1 = log_points[bin]; 00097 //G4double log_e2 = log_points[bin+1]; 00098 G4double log_d1 = log_data[bin]; 00099 G4double log_d2 = log_data[bin+1]; 00100 if (d1 > 0.0 && d2 > 0.0) 00101 { 00102 // Values e1, e2, d1 and d2 are the log values of the corresponding 00103 // original energy and data values. Simple linear interpolation performed 00104 // on loagarithmic data should be equivalent to log-log interpolation 00105 //value = log_d1 + (log_d2 - log_d1)*(log_x - log_e1)/(log_e2 - log_e1); 00106 value = std::exp(log_d1 + (log_d2 - log_d1)*(x - e1)/(e2 - e1)); 00107 } 00108 else 00109 { 00110 if (d1 == 0.0) log_d1 = -300; 00111 if (d2 == 0.0) log_d2 = -300; 00112 value = std::exp(log_d1 + (log_d2 - log_d1)*(x - e1)/(e2 - e1)); 00113 } 00114 } 00115 else 00116 { 00117 value = data[nBins]; 00118 } 00119 return value; 00120 } 00121