source: trunk/source/processes/hadronic/models/cascade/cascade/include/G4CascadeInterpolator.hh @ 1316

Last change on this file since 1316 was 1316, checked in by garnier, 14 years ago

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 3.2 KB
Line 
1#ifndef G4CASCADE_INTERPOLATOR_HH
2#define G4CASCADE_INTERPOLATOR_HH
3//
4// ********************************************************************
5// * License and Disclaimer                                           *
6// *                                                                  *
7// * The  Geant4 software  is  copyright of the Copyright Holders  of *
8// * the Geant4 Collaboration.  It is provided  under  the terms  and *
9// * conditions of the Geant4 Software License,  included in the file *
10// * LICENSE and available at  http://cern.ch/geant4/license .  These *
11// * include a list of copyright holders.                             *
12// *                                                                  *
13// * Neither the authors of this software system, nor their employing *
14// * institutes,nor the agencies providing financial support for this *
15// * work  make  any representation or  warranty, express or implied, *
16// * regarding  this  software system or assume any liability for its *
17// * use.  Please see the license in the file  LICENSE  and URL above *
18// * for the full disclaimer and the limitation of liability.         *
19// *                                                                  *
20// * This  code  implementation is the result of  the  scientific and *
21// * technical work of the GEANT4 collaboration.                      *
22// * By using,  copying,  modifying or  distributing the software (or *
23// * any work based  on the software)  you  agree  to acknowledge its *
24// * use  in  resulting  scientific  publications,  and indicate your *
25// * acceptance of all terms of the Geant4 Software license.          *
26// ********************************************************************
27// $Id: G4CascadeInterpolator.hh,v 1.1 2010/05/14 18:01:28 mkelsey Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-cand-01 $
29//
30// Author:  Michael Kelsey <kelsey@slac.stanford.edu>
31//
32// Simple linear interpolation class, more lightweight than
33// G4PhysicsVector.  Templated on number of X-axis (usually energy)
34// bins, constructor takes a C-array of bin edges as input, and an
35// optional flag whether to extrapolate (the default) or truncate values
36// beyond the bin boundaries. 
37//
38// The interpolation action returns a simple double: the integer part
39// is the bin index, and the fractional part is, obviously, the
40// fractional part.
41
42#include "globals.hh"
43#include <cfloat>
44
45
46template <int NBINS>
47class G4CascadeInterpolator {
48public:
49  enum { nBins=NBINS, last=NBINS-1 };
50
51  G4CascadeInterpolator(const G4double (&xb)[nBins], G4bool extrapolate=true)
52    : xBins(xb), doExtrapolation(extrapolate),
53      lastX(-DBL_MAX), lastVal(-DBL_MAX) {}
54
55  virtual ~G4CascadeInterpolator() {}
56
57  // Find bin position (index and fraction) from input argument
58  G4double getBin(const G4double x) const;
59
60  // Apply bin position from first input to second (array)
61  G4double interpolate(const G4double x, const G4double (&yb)[nBins]) const;
62  G4double interpolate(const G4double (&yb)[nBins]) const;
63
64private:
65  const G4double (&xBins)[nBins];
66  G4bool doExtrapolation;
67
68  mutable G4double lastX;               // Buffers to remember previous call
69  mutable G4double lastVal;
70};
71
72// NOTE:  G4 requires template function definitions in .hh file
73#include "G4CascadeInterpolator.icc"
74
75#endif  /* G4CASCADE_INTERPOLATOR_HH */
Note: See TracBrowser for help on using the repository browser.