44 int n_terms =
_terms.size();
45 std::string coeff_name =
Form(
"%s_c%d",
GetName(), n_terms);
46 std::string term_name =
Form(
"%s_t%d",
GetName(), n_terms);
47 auto termList = std::make_unique<RooListProxy>(term_name.c_str(), term_name.c_str(),
this);
48 auto coeff =
new RooRealVar(coeff_name.c_str(), coeff_name.c_str(), coefficient);
51 for (
const auto &var :
_vars) {
52 std::string exponent_name =
Form(
"%s_%s^%d",
GetName(), var->GetName(), 0);
53 auto exponent =
new RooRealVar(exponent_name.c_str(), exponent_name.c_str(), 0);
54 exponents->add(*exponent);
57 termList->addOwned(*exponents);
58 termList->addOwned(*coeff);
59 this->
_terms.push_back(move(termList));
64 int n_terms =
_terms.size();
65 std::string coeff_name =
Form(
"%s_c%d",
GetName(), n_terms);
66 std::string term_name =
Form(
"%s_t%d",
GetName(), n_terms);
67 auto termList = std::make_unique<RooListProxy>(term_name.c_str(), term_name.c_str(),
this);
68 auto coeff =
new RooRealVar(coeff_name.c_str(), coeff_name.c_str(), coefficient);
72 for (
const auto &var :
_vars) {
74 if (strcmp(var1.
GetName(), var->GetName()) == 0)
76 std::string exponent_name =
Form(
"%s_%s^%d",
GetName(), var->GetName(), exp);
77 auto exponent =
new RooRealVar(exponent_name.c_str(), exponent_name.c_str(), exp);
78 exponents->add(*exponent);
81 termList->addOwned(*exponents);
82 termList->addOwned(*coeff);
83 this->
_terms.push_back(move(termList));
89 int n_terms =
_terms.size();
90 std::string coeff_name =
Form(
"%s_c%d",
GetName(), n_terms);
91 std::string term_name =
Form(
"%s_t%d",
GetName(), n_terms);
92 auto termList = std::make_unique<RooListProxy>(term_name.c_str(), term_name.c_str(),
this);
93 auto coeff =
new RooRealVar(coeff_name.c_str(), coeff_name.c_str(), coefficient);
96 for (
const auto &var :
_vars) {
98 if (strcmp(var1.
GetName(), var->GetName()) == 0)
100 if (strcmp(var2.
GetName(), var->GetName()) == 0)
102 std::string exponent_name =
Form(
"%s_%s^%d",
GetName(), var->GetName(), exp);
103 auto exponent =
new RooRealVar(exponent_name.c_str(), exponent_name.c_str(), exp);
104 exponents->add(*exponent);
106 termList->addOwned(*exponents);
107 termList->addOwned(*coeff);
108 this->
_terms.push_back(move(termList));
115 << exponents.
size() <<
") provided do not match the number of variables (" <<
_vars.
size()
118 int n_terms =
_terms.size();
119 std::string coeff_name =
Form(
"%s_c%d",
GetName(), n_terms);
120 std::string term_name =
Form(
"%s_t%d",
GetName(), n_terms);
121 auto termList = std::make_unique<RooListProxy>(term_name.c_str(), term_name.c_str(),
this);
122 auto coeff =
new RooRealVar(coeff_name.c_str(), coeff_name.c_str(), coefficient);
123 termList->addOwned(exponents);
124 termList->addOwned(*coeff);
125 this->
_terms.push_back(move(termList));
137 :
RooAbsReal(
name, title), _vars(
"x",
"list of dependent variables", this)
139 for (
const auto &var : vars) {
141 std::stringstream ss;
142 ss <<
"RooPolyFunc::ctor(" <<
GetName() <<
") ERROR: coefficient " << var->
GetName()
143 <<
" is not of type RooAbsReal";
144 const std::string errorMsg = ss.str();
146 throw std::runtime_error(errorMsg);
158 for (
auto const &term : other.
_terms) {
159 this->
_terms.emplace_back(std::make_unique<RooListProxy>(term->GetName(),
this, *term));
171 for (
auto const &term : other.
_terms) {
172 this->
_terms.emplace_back(std::make_unique<RooListProxy>(term->GetName(),
this, *term));
182 double poly_sum(0.0);
183 for (
const auto &term :
_terms) {
184 double poly_term(1.0);
185 size_t n_vars = term->size() - 1;
186 for (
size_t i_var = 0; i_var < n_vars; ++i_var) {
188 auto exp =
dynamic_cast<RooRealVar *
>(term->at(i_var));
189 poly_term *= pow(var->getVal(), exp->getVal());
191 auto coef =
dynamic_cast<RooRealVar *
>(term->at(n_vars));
192 poly_sum += coef->
getVal() * poly_term;
200 std::size_t iObs = 0;
201 for (
auto *var : static_range_cast<RooRealVar *>(observables)) {
202 var->setVal(observableValues[iObs++]);
208 for (
auto *var : static_range_cast<RooRealVar *>(observables)) {
209 var->setConstant(
true);
221std::unique_ptr<RooAbsReal>
223 std::vector<double>
const &observableValues,
int order,
double eps1,
double eps2)
226 auto taylor_poly = std::make_unique<RooPolyFunc>(
name, title, observables);
229 if (order >= 3 || order <= 0) {
230 std::stringstream errorMsgStream;
231 errorMsgStream <<
"RooPolyFunc::taylorExpand(" <<
name <<
") ERROR: order must be 0, 1, or 2";
232 const auto errorMsg = errorMsgStream.str();
234 throw std::invalid_argument(errorMsg);
245 for (
int i_order = 0; i_order <= order; ++i_order) {
248 taylor_poly->addTerm(func.
getVal());
252 for (
auto *var : static_range_cast<RooRealVar *>(observables)) {
253 double var1_val = var->getVal();
255 double deriv_val = deriv->
getVal();
257 taylor_poly->addTerm(deriv_val, *var, 1);
258 if (var1_val != 0.0) {
259 taylor_poly->addTerm(deriv_val * var1_val * -1.0);
265 for (
auto *var1 : static_range_cast<RooRealVar *>(observables)) {
266 double var1_val = var1->getVal();
267 auto deriv1 = func.
derivative(*var1, 1, eps1);
268 for (
auto *var2 : static_range_cast<RooRealVar *>(observables)) {
269 double var2_val = var2->
getVal();
270 double deriv_val = 0.0;
271 if (strcmp(var1->GetName(), var2->GetName()) == 0) {
272 auto deriv2 = func.
derivative(*var2, 2, eps2);
273 deriv_val = 0.5 * deriv2->
getVal();
276 auto deriv2 = deriv1->derivative(*var2, 1, eps2);
277 deriv_val = 0.5 * deriv2->getVal();
280 taylor_poly->addTerm(deriv_val, *var1, 1, *var2, 1);
281 if (var1_val != 0.0 || var2_val != 0.0) {
282 taylor_poly->addTerm(deriv_val * var1_val * var2_val);
283 taylor_poly->addTerm(deriv_val * var2_val * -1.0, *var1, 1);
284 taylor_poly->addTerm(deriv_val * var1_val * -1.0, *var2, 1);
300 int order,
double eps1,
double eps2)
303 std::vector<double>(observables.
size(), observablesValue), order, eps1, eps2);
void fixObservables(const RooAbsCollection &observables)
void setCoordinates(const RooAbsCollection &observables, std::vector< double > const &observableValues)
char * Form(const char *fmt,...)
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
Storage_t::size_type size() const
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
RooDerivative * derivative(RooRealVar &obs, Int_t order=1, Double_t eps=0.001)
Return function representing first, second or third order derivative of this function.
RooAbsReal & operator=(const RooAbsReal &other)
Assign values, name and configs from another RooAbsReal.
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Reimplementation of standard RooArgList::add()
RooPolyFunc implements a polynomial function in multi-variables.
static std::unique_ptr< RooAbsReal > taylorExpand(const char *name, const char *title, RooAbsReal &func, const RooAbsCollection &observables, std::vector< double > const &observableValues, int order=1, double eps1=1e-6, double eps2=1e-3)
RooPolyFunc()
Default constructor.
void addTerm(double coefficient)
coverity[UNINIT_CTOR]
RooPolyFunc & operator=(const RooPolyFunc &other)
Assignment operator.
std::vector< std::unique_ptr< RooListProxy > > _terms
double evaluate() const
Evaluation.
RooRealVar represents a variable that can be changed from the outside.
virtual const char * GetName() const
Returns name of object.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...