Interpolator.h

Go to the documentation of this file.
00001 #ifndef INTERPOLATOR_H
00002 #define INTERPOLATOR_H 
00003 
00004 #include <iostream>
00005 #include <fstream>
00006 #include <sstream>
00007 #include <string>
00008 #include <vector>
00009 #include <deque>
00010 #include <map>
00011 #include <utility>
00012 
00013 using std::vector;
00014 using std::deque;
00015 using std::map;
00016 using std::ifstream;
00017 using std::istringstream;
00018 using std::string;
00019 using std::pair;
00020 
00021 namespace Atlfast{
00022   
00023   // Interpolator is a class for doing linear interpolations
00024   // for a given quantity between points in any number of dimensions 
00025   // (ie.. efficiency between various eta,pT points would be 2 dimensions.
00026   // The input file must have a particular layout for Interpolator to
00027   // work (3 dimensional example):
00028 
00029   // pt eta phi                 <== Quantity names (optional)
00030   // 1                          <== 1st point in 1st dim.
00031   //   3                        <== 1st point in 2nd dim. (whitespace is ignored)
00032   //     12  23  34  45  56     <== All points in 3rd dim.
00033   //     0.4 0.5 0.6 0.7 0.8    <== Values of quantity at (1,3,12),(1,3,23),etc..
00034   //   4                        <== 2nd point in 2nd dim.
00035   //     12  23  34  45  56     <== All points in 3rd dim.
00036   //     0.1 0.2 0.4 0.5 0.6    <== Values of quantity at (1,4,12),(1,4,23),etc..
00037   //                            <== Empty lines are ignored
00038   // 2                          <== 2nd point in 1st dim.
00039   //   3                        <== 1st point in 2nd dim.
00040   //     12  23  34  45  56     <== All points in 3rd dim.
00041   //     0.1 0.2 0.3 0.2 0.1    <== Values of quantity at (2,3,12),(2,3,23),etc..
00042   //   4                        <== 2nd point in 2nd dim.
00043   //     12  23  34  45  56     <== All points in 3rd dim.
00044   //     0.6 0.9 0.7 0.1 0.1    <== Values of quantity at (2,4,12),(2,4,23),etc..
00045 
00046   // Points should be listed in ascending numerical order. For each dimension, 
00047   // Interpolator recursively makes a vector of Interpolators
00048   // corresponding to the next dimension down. Interpolation is performed by 
00049   // passing in a vector of values (in dimension order, ie.. (1st dim. value, 
00050   // 2nd dim. value, 3rd dim. value) ) to the 'interpolate' method. interpolate 
00051   // checks whether the values are in the range of held points and returns the
00052   // interpolation result if so, or zero if not. Each Interpolator holds a value
00053   // which is its point value in that Interpolator's dimension
00054 
00055   class Interpolator{
00056   public:
00057     Interpolator(string);
00058     double interpolate(deque<double>,bool performedchecks = false);
00059     double getValue(){return m_value;}
00060     void   setDefault(double);
00061     void   setDefault(int,double);
00062     void   setDefault(string,double);
00063     void   setDefault(int,double,double);
00064     void   setDefault(string,double,double);
00065     void   setContinuousBoundaries(){m_contBounds = true;}
00066     double getNearestValue(deque<double>);
00067     void   dump();
00068   private:
00069     Interpolator(double,ifstream&, int&, int&, vector<int>&, int&);
00070     void   Setup(ifstream&, int&, int&, vector<int>&, int&);
00071     void   findLimits(deque<pair<double,double> >&);
00072     void   nDimensionsToJump(ifstream&,int&,int&);
00073     bool   inLimits(deque<double>,double&);
00074     void   exitParseWithMessage(string, int, string);
00075     vector<pair<double,double> >   m_pairs;
00076     vector<Interpolator>           m_interpolators;
00077     double                         m_value;
00078     deque<pair<double,double> >    m_limits;
00079     deque<pair<double,double> >    m_defaults;
00080     map<string,int>                m_levelnames;
00081     bool                           m_contBounds;
00082   };
00083   
00084   // ClosestInterpolators is a binary predicate class to find the two adjacent 
00085   // Interpolators whose point values fall either side of an input value
00086 
00087   class ClosestInterpolators{
00088   public:
00089     ClosestInterpolators(double value);
00090     bool operator()(Interpolator&, Interpolator&);
00091   private:
00092     double m_value;
00093   };
00094   
00095   // ClosestDoublePairs is a binary predicate class to find the two adjacent 
00096   // pairs whose point values fall either side of an input value
00097 
00098   class ClosestDoublePairs{
00099   public:
00100     ClosestDoublePairs(double value);
00101     bool operator()(pair<double,double>&, pair<double,double>&);
00102   private:
00103     double m_value;
00104   };
00105 
00106 }
00107 
00108 #endif

Generated on Fri Sep 21 13:00:08 2007 for AtlfastEvent by  doxygen 1.5.1