Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:15

0001 #include "FWCore/Utilities/interface/Exception.h"
0002 
0003 #include "CondFormats/HcalObjects/interface/HcalChebyshevFunctor.h"
0004 
0005 HcalChebyshevFunctor::HcalChebyshevFunctor() : xmin_(-1.0), xmax_(1.0), outOfRangeValue_(0.0) {}
0006 
0007 HcalChebyshevFunctor::HcalChebyshevFunctor(const std::vector<double>& coeffs,
0008                                            const double xmin,
0009                                            const double xmax,
0010                                            const double outOfRangeValue)
0011     : coeffs_(coeffs), xmin_(xmin), xmax_(xmax), outOfRangeValue_(outOfRangeValue) {
0012   if (xmin_ >= xmax_)
0013     throw cms::Exception("In HcalChebyshevFunctor constructor: invalid interval specification");
0014 }
0015 
0016 double HcalChebyshevFunctor::operator()(const double y) const {
0017   if (!(y >= xmin_ && y <= xmax_))
0018     return outOfRangeValue_;
0019 
0020   if (coeffs_.empty())
0021     return 0.0;
0022 
0023   const double x = 2.0 * (y - xmin_) / (xmax_ - xmin_) - 1.0;
0024   const double* a = &coeffs_[0];
0025   const double twox = 2.0 * x;
0026 
0027   // Clenshaw recursion
0028   double rp2 = 0.0, rp1 = 0.0, r = 0.0;
0029   for (unsigned k = coeffs_.size() - 1; k > 0U; --k) {
0030     r = twox * rp1 - rp2 + a[k];
0031     rp2 = rp1;
0032     rp1 = r;
0033   }
0034   return x * rp1 - rp2 + a[0];
0035 }
0036 
0037 BOOST_CLASS_EXPORT_IMPLEMENT(HcalChebyshevFunctor)