Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // 23 // >> 24 // $Id: G4LogLogInterpolation.cc,v 1.4 2002/05/28 09:20:19 pia Exp $ >> 25 // GEANT4 tag $Name: geant4-04-01 $ 27 // 26 // 28 // Author: Maria Grazia Pia (Maria.Grazia.Pia@ 27 // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch) 29 // Sebastian Incerti (incerti@cenbg.in << 28 // 30 // Nicolas A. Karakatsanis (knicolas@m << 31 // History: 29 // History: 32 // ----------- 30 // ----------- 33 // 31 Jul 2001 MGP Created 31 // 31 Jul 2001 MGP Created 34 // 27 Jun 2008 SI Add check to avoid << 32 // 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 // ------------------------------------------- 33 // ------------------------------------------------------------------- 41 34 42 #include "G4LogLogInterpolation.hh" 35 #include "G4LogLogInterpolation.hh" 43 36 44 //....oooOO0OOooo........oooOO0OOooo........oo << 45 // Constructor 37 // Constructor >> 38 46 G4LogLogInterpolation::G4LogLogInterpolation() 39 G4LogLogInterpolation::G4LogLogInterpolation() 47 { } 40 { } 48 41 49 //....oooOO0OOooo........oooOO0OOooo........oo << 50 // Destructor 42 // Destructor >> 43 51 G4LogLogInterpolation::~G4LogLogInterpolation( 44 G4LogLogInterpolation::~G4LogLogInterpolation() 52 { } 45 { } 53 46 54 //....oooOO0OOooo........oooOO0OOooo........oo << 55 G4VDataSetAlgorithm* G4LogLogInterpolation::Cl 47 G4VDataSetAlgorithm* G4LogLogInterpolation::Clone() const 56 { return new G4LogLogInterpolation; } 48 { return new G4LogLogInterpolation; } 57 49 58 //....oooOO0OOooo........oooOO0OOooo........oo << 50 59 G4double G4LogLogInterpolation::Calculate(G4do 51 G4double G4LogLogInterpolation::Calculate(G4double x, G4int bin, 60 const G4DataVector& points, 52 const G4DataVector& points, 61 const G4DataVector& data) const 53 const G4DataVector& data) const 62 { 54 { 63 G4int nBins = G4int(data.size() - 1); << 55 G4int nBins = data.size() - 1; 64 G4double value = 0.; 56 G4double value = 0.; 65 if (x < points[0]) 57 if (x < points[0]) 66 { 58 { 67 value = 0.; 59 value = 0.; 68 } 60 } 69 else if (bin < nBins) 61 else if (bin < nBins) 70 { 62 { 71 G4double e1 = points[bin]; 63 G4double e1 = points[bin]; 72 G4double e2 = points[bin+1]; 64 G4double e2 = points[bin+1]; 73 G4double d1 = data[bin]; 65 G4double d1 = data[bin]; 74 G4double d2 = data[bin+1]; 66 G4double d2 = data[bin+1]; 75 // Check of e1, e2, d1 and d2 values to << 67 value = (log10(d1)*log10(e2/x) + log10(d2)*log10(x/e1)) / log10(e2/e1); 76 // interpolated value below << 68 value = 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 } 69 } 85 else 70 else 86 { 71 { 87 value = data[nBins]; 72 value = data[nBins]; 88 } 73 } 89 return value; << 90 } << 91 74 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 << 120 // Delogarithmize to obtain interpolated << 121 value = std::pow(10.,value); << 122 } << 123 else << 124 { << 125 value = data[nBins]; << 126 } << 127 return value; 75 return value; 128 } 76 } 129 77