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 // Author: Vladimir Ivanchenko (Vladimir.Ivantchenko@cern.ch) 00028 // 00029 // History: 00030 // ----------- 00031 // 29 May 2002 VI Created 00032 // 00033 // ------------------------------------------------------------------- 00034 00035 #include "G4LinLogLogInterpolation.hh" 00036 00037 // Constructor 00038 00039 G4LinLogLogInterpolation::G4LinLogLogInterpolation() 00040 { } 00041 00042 // Destructor 00043 00044 G4LinLogLogInterpolation::~G4LinLogLogInterpolation() 00045 { } 00046 00047 G4VDataSetAlgorithm* G4LinLogLogInterpolation::Clone() const 00048 { return new G4LinLogLogInterpolation; } 00049 00050 00051 G4double G4LinLogLogInterpolation::Calculate(G4double x, G4int bin, 00052 const G4DataVector& points, 00053 const G4DataVector& data) const 00054 { 00055 //G4cout << "G4LinLogLogInterpolation is performed (2 arguments) " << G4endl; 00056 G4int nBins = data.size() - 1; 00057 G4double value = 0.; 00058 if (x < points[0]) 00059 { 00060 value = 0.; 00061 } 00062 else if (bin < nBins) 00063 { 00064 G4double e1 = points[bin]; 00065 G4double e2 = points[bin+1]; 00066 G4double d1 = data[bin]; 00067 G4double d2 = data[bin+1]; 00068 if(d1 > 0.0 && d2 > 0.0) { 00069 value = (std::log10(d1)*std::log10(e2/x) + std::log10(d2)*std::log10(x/e1)) / std::log10(e2/e1); 00070 value = std::pow(10.,value); 00071 } else { 00072 value = (d1*std::log10(e2/x) + d2*std::log10(x/e1)) / std::log10(e2/e1); 00073 } 00074 } 00075 else 00076 { 00077 value = data[nBins]; 00078 } 00079 00080 return value; 00081 } 00082 00083 G4double G4LinLogLogInterpolation::Calculate(G4double x, G4int bin, 00084 const G4DataVector& points, 00085 const G4DataVector& data, 00086 const G4DataVector& log_points, 00087 const G4DataVector& log_data) const 00088 { 00089 //G4cout << "G4LinLogLogInterpolation is performed(4 arguments) " << G4endl; 00090 G4int nBins = data.size() - 1; 00091 G4double value = 0.; 00092 G4double log_x = std::log10(x); 00093 if (x < points[0]) 00094 { 00095 value = 0.; 00096 } 00097 else if (bin < nBins) 00098 { 00099 G4double e1 = points[bin]; 00100 G4double e2 = points[bin+1]; 00101 G4double d1 = data[bin]; 00102 G4double d2 = data[bin+1]; 00103 G4double log_e1 = log_points[bin]; 00104 G4double log_e2 = log_points[bin+1]; 00105 G4double log_d1 = log_data[bin]; 00106 G4double log_d2 = log_data[bin+1]; 00107 //G4cout << "x = " << x << " , log_x = " << log_x << " , bin = " << bin << G4endl; 00108 //G4cout << "e1 = " << e1 << " , d1 = " << d1 << G4endl; 00109 //G4cout << "e2 = " << e2 << " , d2 = " << d2 << G4endl; 00110 //G4cout << "log_e1 = " << log_e1 << " , log_d1 = " << log_d1 << G4endl; 00111 //G4cout << "log_e2 = " << log_e2 << " , log_d2 = " << log_d2 <<G4endl; 00112 if (d1 > 0.0 && d2 > 0.0) 00113 { 00114 // Values e1, e2, d1 and d2 are the log values of the corresponding 00115 // original energy and data values. Simple linear interpolation performed 00116 // on loagarithmic data should be equivalent to log-log interpolation 00117 value = log_d1 + (log_d2 - log_d1)*(log_x - log_e1)/(log_e2 - log_e1); 00118 00119 //G4cout << "Case of normal log-log interpolation" << G4endl; 00120 //G4cout << "Temp log interpolated value: log_value = " << value << G4endl; 00121 00122 // Delogarithmize to obtain interpolated value 00123 value = std::pow(10.,value); 00124 00125 //G4cout << "Final Interpolated value: " << value << G4endl << G4endl; 00126 } 00127 else 00128 { 00129 // Case of semi log-log interpolation 00130 //G4cout << "G4LinLogLogInterpolation - Case of SemiLogInterpolation" << G4endl; 00131 if (e1 == 0.0) e1 = 1e-300; 00132 if (e2 == 0.0) e2 = 1e-300; 00133 value = d1 + (d2 - d1)*(log_x - log_e1)/(log_e2 - log_e1); 00134 //G4cout << "LinLogInterpolation: Final Interpolated value: " << value << G4endl << G4endl; 00135 } 00136 } 00137 else 00138 { 00139 value = data[nBins]; 00140 } 00141 return value; 00142 }