ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4CascadeInterpolator.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4CascadeInterpolator.hh
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 //
27 // Author: Michael Kelsey <kelsey@slac.stanford.edu>
28 //
29 // Simple linear interpolation class, more lightweight than
30 // G4PhysicsVector. Templated on number of X-axis (usually energy)
31 // bins, constructor takes a C-array of bin edges as input, and an
32 // optional flag whether to extrapolate (the default) or truncate values
33 // beyond the bin boundaries.
34 //
35 // The interpolation action returns a simple double: the integer part
36 // is the bin index, and the fractional part is, obviously, the
37 // fractional part.
38 //
39 // 20100803 M. Kelsey -- Add printBins() function for debugging
40 // 20110923 M. Kelsey -- Add optional ostream& argument to printBins()
41 
42 #ifndef G4CASCADE_INTERPOLATOR_HH
43 #define G4CASCADE_INTERPOLATOR_HH
44 
45 #include "globals.hh"
46 #include <cfloat>
47 #include <iosfwd>
48 
49 
50 template <int NBINS>
52 public:
53  enum { nBins=NBINS, last=NBINS-1 };
54 
55  G4CascadeInterpolator(const G4double (&xb)[nBins], G4bool extrapolate=true)
56  : xBins(xb), doExtrapolation(extrapolate),
58 
60 
61  // Find bin position (index and fraction) from input argument
62  G4double getBin(const G4double x) const;
63 
64  // Apply bin position from first input to second (array)
65  G4double interpolate(const G4double x, const G4double (&yb)[nBins]) const;
66  G4double interpolate(const G4double (&yb)[nBins]) const;
67 
68  void printBins(std::ostream& os) const; // Show bin edges for debugging
69 
70 private:
71  const G4double (&xBins)[nBins];
73 
74  mutable G4double lastX; // Buffers to remember previous call
75  mutable G4double lastVal;
76 };
77 
78 // NOTE: G4 requires template function definitions in .hh file
79 #include "G4CascadeInterpolator.icc"
80 
81 #endif /* G4CASCADE_INTERPOLATOR_HH */