Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:29

0001 #ifndef PhysicTools_Utilities_RootFunctionAdapter_h
0002 #define PhysicTools_Utilities_RootFunctionAdapter_h
0003 #include <vector>
0004 #include <memory>
0005 
0006 #include "PhysicsTools/Utilities/interface/RootVarsAdapter.h"
0007 
0008 namespace root {
0009   namespace helper {
0010 
0011     template <typename F, unsigned int args>
0012     struct RootFunctionAdapter {
0013       RootFunctionAdapter() : f_(nullptr) {}
0014       RootFunctionAdapter(F& f) : f_(&f) {}
0015       void addParameter(const std::shared_ptr<double>& par) { pars_.push_back(par); }
0016       void setParameters(const double* pars) {
0017         for (size_t i = 0; i < pars_.size(); ++i) {
0018           *pars_[i] = pars[i];
0019         }
0020       }
0021       double operator()(const double* var) const { return RootVarsAdapter<F, args>::value(*f_, var); }
0022       size_t numberOfParameters() const { return pars_.size(); }
0023 
0024     private:
0025       F* f_;
0026       std::vector<std::shared_ptr<double> > pars_;
0027     };
0028 
0029   }  // namespace helper
0030 
0031 }  // namespace root
0032 
0033 #endif