Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-27 09:14:58

0001 // lAger: General Purpose l/A-event Generator
0002 // Copyright (C) 2016-2021 Sylvester Joosten <sjoosten@anl.gov>
0003 // 
0004 // This file is part of lAger.
0005 // 
0006 // lAger is free software: you can redistribute it and/or modify
0007 // it under the terms of the GNU General Public License as published by
0008 // the Free Shoftware Foundation, either version 3 of the License, or
0009 // (at your option) any later version.
0010 // 
0011 // lAger is distributed in the hope that it will be useful,
0012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 // GNU General Public License for more details.
0015 // 
0016 // You should have received a copy of the GNU General Public License
0017 // along with lAger.  If not, see <https://www.gnu.org/licenses/>.
0018 // 
0019 
0020 #ifndef LAGER_CORE_SPLINE_LOADED
0021 #define LAGER_CORE_SPLINE_LOADED
0022 
0023 #include <TSpline.h>
0024 #include <lager/core/configuration.hh>
0025 #include <lager/core/interval.hh>
0026 
0027 namespace lager {
0028 
0029 // a 1D spline interpolation that uses datapoints obtained from a configuration
0030 // object
0031 class spline : public configurable {
0032 public:
0033   spline(const configuration& conf, const string_path& path)
0034       : configurable{conf, path}
0035       , x_{conf().get_vector<double>("x")}
0036       , y_{conf().get_vector<double>("y")}
0037       , spline_{path.str().c_str(), &x_[0], &y_[0], static_cast<int>(x_.size())}
0038       , xrange_{x_.front(), x_.back()} {}
0039 
0040   double eval(const double x) const {
0041     if (xrange_.includes(x)) {
0042       return spline_.Eval(x);
0043     } else {
0044       return 0.;
0045     }
0046   }
0047   double operator()(const double x) const { return eval(x); }
0048 
0049 private:
0050   std::vector<double> x_;
0051   std::vector<double> y_;
0052   TSpline3 spline_;
0053   interval<double> xrange_;
0054 };
0055 }
0056 
0057 #endif