G4CascadeInterpolator.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 //
00028 // Author:  Michael Kelsey <kelsey@slac.stanford.edu>
00029 //
00030 // Simple linear interpolation class, more lightweight than
00031 // G4PhysicsVector.  Templated on number of X-axis (usually energy)
00032 // bins, constructor takes a C-array of bin edges as input, and an
00033 // optional flag whether to extrapolate (the default) or truncate values
00034 // beyond the bin boundaries.  
00035 //
00036 // The interpolation action returns a simple double: the integer part
00037 // is the bin index, and the fractional part is, obviously, the
00038 // fractional part.
00039 //
00040 // 20100803  M. Kelsey -- Add printBins() function for debugging
00041 // 20110923  M. Kelsey -- Add optional ostream& argument to printBins()
00042 
00043 #ifndef G4CASCADE_INTERPOLATOR_HH
00044 #define G4CASCADE_INTERPOLATOR_HH
00045 
00046 #include "globals.hh"
00047 #include <cfloat>
00048 #include <iosfwd>
00049 
00050 
00051 template <int NBINS>
00052 class G4CascadeInterpolator {
00053 public:
00054   enum { nBins=NBINS, last=NBINS-1 };
00055 
00056   G4CascadeInterpolator(const G4double (&xb)[nBins], G4bool extrapolate=true)
00057     : xBins(xb), doExtrapolation(extrapolate),
00058       lastX(-DBL_MAX), lastVal(-DBL_MAX) {}
00059 
00060   virtual ~G4CascadeInterpolator() {}
00061 
00062   // Find bin position (index and fraction) from input argument
00063   G4double getBin(const G4double x) const;
00064 
00065   // Apply bin position from first input to second (array)
00066   G4double interpolate(const G4double x, const G4double (&yb)[nBins]) const;
00067   G4double interpolate(const G4double (&yb)[nBins]) const;
00068 
00069   void printBins(std::ostream& os) const;       // Show bin edges for debugging
00070 
00071 private:
00072   const G4double (&xBins)[nBins];
00073   G4bool doExtrapolation;
00074 
00075   mutable G4double lastX;               // Buffers to remember previous call
00076   mutable G4double lastVal;
00077 };
00078 
00079 // NOTE:  G4 requires template function definitions in .hh file
00080 #include "G4CascadeInterpolator.icc"
00081 
00082 #endif  /* G4CASCADE_INTERPOLATOR_HH */

Generated on Mon May 27 17:47:49 2013 for Geant4 by  doxygen 1.4.7