Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id: G4LogLogInterpolation.cc,v 1.7 2006/06/29 19:40:09 gunter Exp $ >> 28 // GEANT4 tag $Name: geant4-08-02 $ 27 // 29 // 28 // Author: Maria Grazia Pia (Maria.Grazia.Pia@ 30 // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch) 29 // Sebastian Incerti (incerti@cenbg.in << 31 // 30 // Nicolas A. Karakatsanis (knicolas@m << 31 // History: 32 // History: 32 // ----------- 33 // ----------- 33 // 31 Jul 2001 MGP Created 34 // 31 Jul 2001 MGP Created 34 // 27 Jun 2008 SI Add check to avoid << 35 // 35 // 08 Dec 2008 NAK Log-Log interpolat << 36 // self-test functi << 37 // 14 Jun 2008 NAK New implementation << 38 // after directly lo << 39 // logarithmic value << 40 // ------------------------------------------- 36 // ------------------------------------------------------------------- 41 37 42 #include "G4LogLogInterpolation.hh" 38 #include "G4LogLogInterpolation.hh" 43 39 44 //....oooOO0OOooo........oooOO0OOooo........oo << 45 // Constructor 40 // Constructor >> 41 46 G4LogLogInterpolation::G4LogLogInterpolation() 42 G4LogLogInterpolation::G4LogLogInterpolation() 47 { } 43 { } 48 44 49 //....oooOO0OOooo........oooOO0OOooo........oo << 50 // Destructor 45 // Destructor >> 46 51 G4LogLogInterpolation::~G4LogLogInterpolation( 47 G4LogLogInterpolation::~G4LogLogInterpolation() 52 { } 48 { } 53 49 54 //....oooOO0OOooo........oooOO0OOooo........oo << 55 G4VDataSetAlgorithm* G4LogLogInterpolation::Cl 50 G4VDataSetAlgorithm* G4LogLogInterpolation::Clone() const 56 { return new G4LogLogInterpolation; } 51 { return new G4LogLogInterpolation; } 57 52 58 //....oooOO0OOooo........oooOO0OOooo........oo << 53 59 G4double G4LogLogInterpolation::Calculate(G4do 54 G4double G4LogLogInterpolation::Calculate(G4double x, G4int bin, 60 const G4DataVector& points, 55 const G4DataVector& points, 61 const G4DataVector& data) const 56 const G4DataVector& data) const 62 { 57 { 63 G4int nBins = G4int(data.size() - 1); << 58 G4int nBins = data.size() - 1; 64 G4double value = 0.; 59 G4double value = 0.; 65 if (x < points[0]) 60 if (x < points[0]) 66 { 61 { 67 value = 0.; 62 value = 0.; 68 } 63 } 69 else if (bin < nBins) 64 else if (bin < nBins) 70 { 65 { 71 G4double e1 = points[bin]; 66 G4double e1 = points[bin]; 72 G4double e2 = points[bin+1]; 67 G4double e2 = points[bin+1]; 73 G4double d1 = data[bin]; 68 G4double d1 = data[bin]; 74 G4double d2 = data[bin+1]; 69 G4double d2 = data[bin+1]; 75 // Check of e1, e2, d1 and d2 values to << 70 value = (std::log10(d1)*std::log10(e2/x) + std::log10(d2)*std::log10(x/e1)) / std::log10(e2/e1); 76 // interpolated value below << 71 value = std::pow(10.,value); 77 if ((d1 > 0.) && (d2 > 0.) && (e1 > 0.) << 78 { << 79 << 80 value = std::log10(d1)+(std::log10(d2/d1)/ << 81 value = std::pow(10.,value); << 82 } << 83 else value = 0.; << 84 } 72 } 85 else 73 else 86 { 74 { 87 value = data[nBins]; 75 value = data[nBins]; 88 } 76 } 89 return value; << 90 } << 91 << 92 //....oooOO0OOooo........oooOO0OOooo........oo << 93 // Nicolas A. Karakatsanis: New implementation << 94 // logarithmic values << 95 G4double G4LogLogInterpolation::Calculate(G4do << 96 const G4DataVector& points, << 97 cons << 98 cons << 99 const G4DataVector& log_data) cons << 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 << 116 // original energy and data values. Simp << 117 // on loagarithmic data should be equiva << 118 value = log_d1 + (log_d2 - log_d1)*(log_ << 119 77 120 // Delogarithmize to obtain interpolated << 121 value = std::pow(10.,value); << 122 } << 123 else << 124 { << 125 value = data[nBins]; << 126 } << 127 return value; 78 return value; 128 } 79 } 129 80