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

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

update ti head

File size: 3.4 KB
Line 
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,v 1.3 2010/08/03 23:09:36 mkelsey Exp $
27// GEANT4 tag $Name: hadr-casc-V09-03-85 $
28//
29// Author:  Michael Kelsey <kelsey@slac.stanford.edu>
30//
31// Simple linear interpolation class, more lightweight than
32// G4PhysicsVector.  Templated on number of X-axis (usually energy)
33// bins, constructor takes a C-array of bin edges as input, and an
34// optional flag whether to extrapolate (the default) or truncate values
35// beyond the bin boundaries. 
36//
37// The interpolation action returns a simple double: the integer part
38// is the bin index, and the fractional part is, obviously, the
39// fractional part.
40//
41// 20100803  M. Kelsey -- Add printBins() function for debugging
42
43#ifndef G4CASCADE_INTERPOLATOR_HH
44#define G4CASCADE_INTERPOLATOR_HH
45
46#include "globals.hh"
47#include <cfloat>
48
49
50template <int NBINS>
51class G4CascadeInterpolator {
52public:
53  enum { nBins=NBINS, last=NBINS-1 };
54
55  G4CascadeInterpolator(const G4double (&xb)[nBins], G4bool extrapolate=true)
56    : xBins(xb), doExtrapolation(extrapolate),
57      lastX(-DBL_MAX), lastVal(-DBL_MAX) {}
58
59  virtual ~G4CascadeInterpolator() {}
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() const;       // Show bin edges for debugging purposes
69
70private:
71  const G4double (&xBins)[nBins];
72  G4bool doExtrapolation;
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 */
Note: See TracBrowser for help on using the repository browser.