Geant4  10.02.p01
G4CascadeInterpolator.hh
Go to the documentation of this file.
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 // $Id: G4CascadeInterpolator.hh 66241 2012-12-13 18:34:42Z gunter $
27 //
28 // Author: Michael Kelsey <kelsey@slac.stanford.edu>
29 //
30 // Simple linear interpolation class, more lightweight than
31 // G4PhysicsVector. Templated on number of X-axis (usually energy)
32 // bins, constructor takes a C-array of bin edges as input, and an
33 // optional flag whether to extrapolate (the default) or truncate values
34 // beyond the bin boundaries.
35 //
36 // The interpolation action returns a simple double: the integer part
37 // is the bin index, and the fractional part is, obviously, the
38 // fractional part.
39 //
40 // 20100803 M. Kelsey -- Add printBins() function for debugging
41 // 20110923 M. Kelsey -- Add optional ostream& argument to printBins()
42 
43 #ifndef G4CASCADE_INTERPOLATOR_HH
44 #define G4CASCADE_INTERPOLATOR_HH
45 
46 #include "globals.hh"
47 #include <cfloat>
48 #include <iosfwd>
49 
50 
51 template <int NBINS>
53 public:
54  enum { nBins=NBINS, last=NBINS-1 };
55 
56  G4CascadeInterpolator(const G4double (&xb)[nBins], G4bool extrapolate=true)
57  : xBins(xb), doExtrapolation(extrapolate),
59 
61 
62  // Find bin position (index and fraction) from input argument
63  G4double getBin(const G4double x) const;
64 
65  // Apply bin position from first input to second (array)
66  G4double interpolate(const G4double x, const G4double (&yb)[nBins]) const;
67  G4double interpolate(const G4double (&yb)[nBins]) const;
68 
69  void printBins(std::ostream& os) const; // Show bin edges for debugging
70 
71 private:
72  const G4double (&xBins)[nBins];
74 
75  mutable G4double lastX; // Buffers to remember previous call
76  mutable G4double lastVal;
77 };
78 
79 // NOTE: G4 requires template function definitions in .hh file
81 
82 #endif /* G4CASCADE_INTERPOLATOR_HH */
G4double getBin(const G4double x) const
bool G4bool
Definition: G4Types.hh:79
G4double interpolate(const G4double x, const G4double(&yb)[nBins]) const
G4CascadeInterpolator(const G4double(&xb)[nBins], G4bool extrapolate=true)
const G4double x[NPOINTSGL]
double G4double
Definition: G4Types.hh:76
const G4double(& xBins)[nBins]
#define DBL_MAX
Definition: templates.hh:83
void printBins(std::ostream &os) const