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 // $Id$ 00028 // 00029 // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch) 00030 // 00031 // History: 00032 // ----------- 00033 // 31 Jul 2001 MGP Created 00034 // 14 JUn 2009 NAK New Calculation method implemented to which logarithmic values 00035 // from the G4EMLOW dataset are loaded directly to enhance performance 00036 // 00037 // ------------------------------------------------------------------- 00038 00039 #include "G4LinInterpolation.hh" 00040 00041 // Constructor 00042 00043 G4LinInterpolation::G4LinInterpolation() 00044 { } 00045 00046 // Destructor 00047 00048 G4LinInterpolation::~G4LinInterpolation() 00049 { } 00050 00051 00052 G4VDataSetAlgorithm* G4LinInterpolation::Clone() const 00053 { return new G4LinInterpolation; } 00054 00055 G4double G4LinInterpolation::Calculate(G4double x, G4int bin, 00056 const G4DataVector& points, 00057 const G4DataVector& data) const 00058 { 00059 //G4cout << "G4LinInterpolation is performed (2 arguments)" << G4endl; 00060 G4int nBins = data.size() - 1; 00061 G4double value = 0.; 00062 if (x < points[0]) 00063 { 00064 value = 0.; 00065 } 00066 else if (bin < nBins) 00067 { 00068 G4double e1 = points[bin]; 00069 G4double e2 = points[bin+1]; 00070 G4double d1 = data[bin]; 00071 G4double d2 = data[bin+1]; 00072 value = d1 + (d2 - d1)*(x - e1)/(e2 - e1); 00073 } 00074 else 00075 { 00076 value = data[nBins]; 00077 } 00078 return value; 00079 } 00080 00081 00082 //Nicolas A. Karakatsanis: New Calculation method implemented to which logarithmic values 00083 // from the G4EMLOW dataset are loaded directly to enhance performance 00084 00085 G4double G4LinInterpolation::Calculate(G4double x, G4int bin, 00086 const G4DataVector& points, 00087 const G4DataVector& data, 00088 const G4DataVector& log_points, 00089 const G4DataVector& log_data) const 00090 { 00091 //Linear Interpolation is performed on loagarithmic data set 00092 //Equivalent to log-log interpolation on non-loagarithmic data set 00093 //G4cout << "G4LinInterpolation is performed - (4 arguments)" << G4endl; 00094 G4int nBins = data.size() - 1; 00095 G4double value = 0.; 00096 G4double log_x = std::log10(x); 00097 if (x < points[0]) 00098 { 00099 value = 0.; 00100 } 00101 else if (bin < nBins) 00102 { 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 00108 // Values e1, e2, d1 and d2 are the log values of the corresponding 00109 // original energy and data values. Simple linear interpolation performed 00110 // on loagarithmic data should be equivalent to log-log interpolation 00111 value = log_d1 + (log_d2 - log_d1)*(log_x - log_e1)/(log_e2 - log_e1); 00112 00113 // Delogarithmize to obtain interpolated value 00114 value = std::pow(10.,value); 00115 } 00116 else 00117 { 00118 value = data[nBins]; 00119 } 00120 return value; 00121 }