G4SemiLogInterpolation.cc

Go to the documentation of this file.
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 //
00035 // -------------------------------------------------------------------
00036 
00037 #include "G4SemiLogInterpolation.hh"
00038 
00039 // Constructor
00040 
00041 G4SemiLogInterpolation::G4SemiLogInterpolation()
00042 { }
00043 
00044 
00045 // Destructor
00046 
00047 G4SemiLogInterpolation::~G4SemiLogInterpolation()
00048 { }
00049 
00050 G4VDataSetAlgorithm* G4SemiLogInterpolation::Clone() const 
00051 { return new G4SemiLogInterpolation; }
00052 
00053 
00054 G4double G4SemiLogInterpolation::Calculate(G4double x, G4int bin, 
00055                                           const G4DataVector& points, 
00056                                           const G4DataVector& data) const
00057 {
00058   //G4cout << "G4SemiLogInterpolation is performed(2 arguments) " << G4endl;
00059   G4int nBins = data.size() - 1;
00060   G4double value = 0.;
00061   if (x < points[0])
00062     {
00063       value = 0.;
00064     }
00065   else if (bin < nBins)
00066     {
00067       G4double e1 = points[bin];
00068       G4double e2 = points[bin+1];
00069       G4double d1 = data[bin];
00070       G4double d2 = data[bin+1];
00071       value = (d1*std::log10(e2/x) + d2*std::log10(x/e1)) / std::log10(e2/e1);
00072     }
00073   else
00074     {
00075       value = data[nBins];
00076     }
00077   return value;
00078 }
00079 
00080 G4double G4SemiLogInterpolation::Calculate(G4double x, G4int bin, 
00081                                            const G4DataVector& points,
00082                                            const G4DataVector& data,
00083                                            const G4DataVector& log_points, 
00084                                            const G4DataVector& /*log_data*/) const
00085 {
00086 //A combination of logarithmic interpolation on energy set and 
00087 //linear Interpolation on data set
00088   //G4cout << "G4SemiLogInterpolation is performed (4 arguments)" << G4endl;
00089   G4int nBins = data.size() - 1;
00090   G4double value = 0.;
00091   G4double log_x = std::log10(x);
00092   if (x < points[0])
00093     {
00094       value = 0.;
00095     }
00096   else if (bin < nBins)
00097     {
00098       G4double e1 = points[bin];
00099       G4double e2 = points[bin+1];
00100       G4double d1 = data[bin];
00101       G4double d2 = data[bin+1];      
00102       G4double log_e1 = log_points[bin];
00103       G4double log_e2 = log_points[bin+1];
00104       //G4double log_d1 = log_data[bin];
00105       //G4double log_d2 = log_data[bin+1];
00106       //G4cout << "x = " << x << " , log_x = " << log_x << " , bin = " << bin << G4endl;
00107       //G4cout << "e1 = " << e1 << " , d1 = " << d1 << G4endl;
00108       //G4cout << "e2 = " << e2 << " , d2 = " << d2 << G4endl;
00109 // Values log_e1 and log_e2 are the log values of the corresponding
00110 // original energy actual values. Original d1 and d2 values are used.
00111 // Simple linear interpolation performed on loagarithmic data 
00112 // should be equivalent to semi log-log interpolation
00113       if (e1 == 0.0) log_e1 = -300;
00114       if (e2 == 0.0) log_e2 = -300;
00115       value = d1 + (d2 - d1)*(log_x - log_e1)/(log_e2 - log_e1);
00116       //G4cout << "G4SemiLogInterpolation - Final Interpolated Value: " << value << G4endl << G4endl;
00117    }
00118  else
00119    {
00120      value = data[nBins];
00121    }
00122   return value;
00123 }
00124 

Generated on Mon May 27 17:49:49 2013 for Geant4 by  doxygen 1.4.7