// // function_container.cpp // mc_electron // // Created by Christian Reiling on 15.03.19. // Copyright © 2019 Christian Reiling. All rights reserved. // #include "function_container.hpp" #include "myexeption.h" #include #include using namespace std; Func_Container::Func_Container() { } Func_Container::Func_Container(std::string loadFilePath) { readFromCSV(loadFilePath); } double Func_Container::interpolate(double x) { if (Map.empty()) { throw MyException("Func_Container: Container is empty."); } if (Map.begin() == Map.lower_bound(x) ) { return (Map.begin()->second); } else if (Map.end() == Map.lower_bound(x)){ return ( (--Map.end())->second ); } dim1Map::iterator lowAnker_Itr = --Map.lower_bound(x); dim1Map::iterator upAnker_Itr = Map.lower_bound(x); double lowAnker_x = lowAnker_Itr->first; double lowAnker_fx = lowAnker_Itr->second; double upAnker_x = upAnker_Itr->first; double upAnker_fx = upAnker_Itr->second; double res = lowAnker_fx + (x-lowAnker_x)/(upAnker_x-lowAnker_x) * (upAnker_fx-lowAnker_fx); return (res); } void Func_Container::add_ankerpoint(double x, double fx) { if ( Map.find(x)!=Map.end() ) { stringstream ss; ss<<"Func_Container::add_ankerpoint: Key x="<> xTemp) && (file >> fxTemp)) { add_ankerpoint(xTemp, fxTemp); } file.close(); return; }