Geant4 Cross Reference |
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 // 27 // 28 // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch) 29 // Sebastian Incerti (incerti@cenbg.in2p3.fr) 30 // Nicolas A. Karakatsanis (knicolas@mail.ntua.gr) 31 // History: 32 // ----------- 33 // 31 Jul 2001 MGP Created 34 // 27 Jun 2008 SI Add check to avoid FPE errors 35 // 08 Dec 2008 NAK Log-Log interpolation math formula streamlined, 36 // self-test function 37 // 14 Jun 2008 NAK New implementation for log-log interpolation 38 // after directly loading 39 // logarithmic values from G4EMLOW dataset 40 // ------------------------------------------------------------------- 41 42 #include "G4LogLogInterpolation.hh" 43 44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 45 // Constructor 46 G4LogLogInterpolation::G4LogLogInterpolation() 47 { } 48 49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 50 // Destructor 51 G4LogLogInterpolation::~G4LogLogInterpolation() 52 { } 53 54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 55 G4VDataSetAlgorithm* G4LogLogInterpolation::Clone() const 56 { return new G4LogLogInterpolation; } 57 58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 59 G4double G4LogLogInterpolation::Calculate(G4double x, G4int bin, 60 const G4DataVector& points, 61 const G4DataVector& data) const 62 { 63 G4int nBins = G4int(data.size() - 1); 64 G4double value = 0.; 65 if (x < points[0]) 66 { 67 value = 0.; 68 } 69 else if (bin < nBins) 70 { 71 G4double e1 = points[bin]; 72 G4double e2 = points[bin+1]; 73 G4double d1 = data[bin]; 74 G4double d2 = data[bin+1]; 75 // Check of e1, e2, d1 and d2 values to avoid floating-point errors when estimating the 76 // interpolated value below 77 if ((d1 > 0.) && (d2 > 0.) && (e1 > 0.) && (e2 > 0.)) 78 { 79 80 value = std::log10(d1)+(std::log10(d2/d1)/std::log10(e2/e1)*std::log10(x/e1)); 81 value = std::pow(10.,value); 82 } 83 else value = 0.; 84 } 85 else 86 { 87 value = data[nBins]; 88 } 89 return value; 90 } 91 92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 93 // Nicolas A. Karakatsanis: New implementation of log-log interpolation after directly loading 94 // logarithmic values from G4EMLOW dataset 95 G4double G4LogLogInterpolation::Calculate(G4double x, G4int bin, 96 const G4DataVector& points, 97 const G4DataVector& data, 98 const G4DataVector& log_points, 99 const G4DataVector& log_data) const 100 { 101 G4int nBins = G4int(data.size() - 1); 102 G4double value = 0.; 103 G4double log_x = std::log10(x); 104 if (x < points[0]) 105 { 106 value = 0.; 107 } 108 else if (bin < nBins) 109 { 110 G4double log_e1 = log_points[bin]; 111 G4double log_e2 = log_points[bin+1]; 112 G4double log_d1 = log_data[bin]; 113 G4double log_d2 = log_data[bin+1]; 114 115 // Values e1, e2, d1 and d2 are the log values of the corresponding 116 // original energy and data values. Simple linear interpolation performed 117 // on loagarithmic data should be equivalent to log-log interpolation 118 value = log_d1 + (log_d2 - log_d1)*(log_x - log_e1)/(log_e2 - log_e1); 119 120 // Delogarithmize to obtain interpolated value 121 value = std::pow(10.,value); 122 } 123 else 124 { 125 value = data[nBins]; 126 } 127 return value; 128 } 129