|
||||
File indexing completed on 2025-01-18 09:58:00
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 // 0027 // Author: Michael Kelsey <kelsey@slac.stanford.edu> 0028 // 0029 // Simple linear interpolation class, more lightweight than 0030 // G4PhysicsVector. Templated on number of X-axis (usually energy) 0031 // bins, constructor takes a C-array of bin edges as input, and an 0032 // optional flag whether to extrapolate (the default) or truncate values 0033 // beyond the bin boundaries. 0034 // 0035 // The interpolation action returns a simple double: the integer part 0036 // is the bin index, and the fractional part is, obviously, the 0037 // fractional part. 0038 // 0039 // 20100803 M. Kelsey -- Add printBins() function for debugging 0040 // 20110923 M. Kelsey -- Add optional ostream& argument to printBins() 0041 0042 #ifndef G4CASCADE_INTERPOLATOR_HH 0043 #define G4CASCADE_INTERPOLATOR_HH 0044 0045 #include "globals.hh" 0046 #include <cfloat> 0047 #include <iosfwd> 0048 0049 0050 template <int NBINS> 0051 class G4CascadeInterpolator { 0052 public: 0053 enum { nBins=NBINS, last=NBINS-1 }; 0054 0055 G4CascadeInterpolator(const G4double (&xb)[nBins], G4bool extrapolate=true) 0056 : xBins(xb), doExtrapolation(extrapolate), 0057 lastX(-DBL_MAX), lastVal(-DBL_MAX) {} 0058 0059 virtual ~G4CascadeInterpolator() {} 0060 0061 // Find bin position (index and fraction) from input argument 0062 G4double getBin(const G4double x) const; 0063 0064 // Apply bin position from first input to second (array) 0065 G4double interpolate(const G4double x, const G4double (&yb)[nBins]) const; 0066 G4double interpolate(const G4double (&yb)[nBins]) const; 0067 0068 void printBins(std::ostream& os) const; // Show bin edges for debugging 0069 0070 private: 0071 const G4double (&xBins)[nBins]; 0072 G4bool doExtrapolation; 0073 0074 mutable G4double lastX; // Buffers to remember previous call 0075 mutable G4double lastVal; 0076 }; 0077 0078 // NOTE: G4 requires template function definitions in .hh file 0079 #include "G4CascadeInterpolator.icc" 0080 0081 #endif /* G4CASCADE_INTERPOLATOR_HH */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |