Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
CodegenImpl.cxx
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Garima Singh, CERN 2023
5 * Jonas Rembser, CERN 2024
6 *
7 * Copyright (c) 2024, CERN
8 *
9 * Redistribution and use in source and binary forms,
10 * with or without modification, are permitted according to the terms
11 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
12 */
13
14#include <RooFit/CodegenImpl.h>
15
17
18#include <RooAddPdf.h>
19#include <RooAddition.h>
20#include <RooBernstein.h>
21#include <RooBifurGauss.h>
22#include <RooCBShape.h>
23#include <RooCategory.h>
24#include <RooChebychev.h>
25#include <RooConstVar.h>
26#include <RooConstraintSum.h>
27#include <RooEffProd.h>
28#include <RooEfficiency.h>
29#include <RooExponential.h>
30#include <RooExtendPdf.h>
33#include <RooFormulaVar.h>
34#include <RooFunctor1DBinding.h>
35#include <RooFunctorBinding.h>
36#include <RooGamma.h>
37#include <RooGaussian.h>
38#include <RooGenericPdf.h>
39#include <RooHistFunc.h>
40#include <RooHistPdf.h>
41#include <RooLandau.h>
42#include <RooLognormal.h>
43#include <RooMultiPdf.h>
44#include <RooMultiVarGaussian.h>
45#include <RooONNXFunc.h>
46#include <RooParamHistFunc.h>
47#include <RooPoisson.h>
48#include <RooPolyVar.h>
49#include <RooPolynomial.h>
50#include <RooProdPdf.h>
51#include <RooProduct.h>
52#include <RooRatio.h>
53#include <RooRealIntegral.h>
54#include <RooRealSumFunc.h>
55#include <RooRealSumPdf.h>
56#include <RooRealVar.h>
58#include <RooSimultaneous.h>
62#include <RooUniform.h>
63#include <RooWrapperPdf.h>
64
65#include "RooFitImplHelpers.h"
66
67#include <TInterpreter.h>
68
69#include <locale>
70#include <unordered_set>
71
72namespace RooFit::Experimental {
73
74namespace {
75
76// Return a stringy-field version of the value, formatted to maximum precision.
77std::string doubleToString(double val)
78{
79 std::stringstream ss;
80 // The formatting must not depend on the global locale: a comma decimal
81 // separator (e.g. from a German locale) would corrupt the generated C++.
82 ss.imbue(std::locale::classic());
83 ss << std::setprecision(std::numeric_limits<double>::max_digits10) << val;
84 return ss.str();
85}
86
87std::string mathFunc(std::string const &name)
88{
89 return "RooFit::Detail::MathFuncs::" + name;
90}
91
92void rooHistTranslateImpl(RooAbsArg const &arg, CodegenContext &ctx, int intOrder, RooDataHist const &dataHist,
93 const RooArgSet &obs, bool correctForBinSize, bool cdfBoundaries)
94{
95 if (intOrder != 0 && !(!cdfBoundaries && !correctForBinSize && intOrder == 1 && obs.size() == 1)) {
96 ooccoutE(&arg, InputArguments) << "RooHistPdf::weight(" << arg.GetName()
97 << ") ERROR: codegen currently only supports non-interpolation cases."
98 << std::endl;
99 return;
100 }
101
102 if (intOrder == 1) {
103 RooAbsBinning const &binning = *dataHist.getBinnings()[0];
105 ctx.addResult(&arg, ctx.buildCall(mathFunc("interpolate1d"), binning.lowBound(), binning.highBound(), *obs[0],
106 binning.numBins(), weightArr));
107 return;
108 }
109 std::string const &offset = dataHist.calculateTreeIndexForCodeSquash(ctx, obs);
111 ctx.addResult(&arg, "(" + weightArr + ")[" + offset + "]");
112}
113
114std::string realSumPdfTranslateImpl(CodegenContext &ctx, RooAbsArg const &arg, RooArgList const &funcList,
115 RooArgList const &coefList, bool normalize)
116{
117 bool noLastCoeff = funcList.size() != coefList.size();
118
119 std::string const &funcName = ctx.buildArg(funcList);
120 std::string const &coeffName = ctx.buildArg(coefList);
121 std::string const &coeffSize = std::to_string(coefList.size());
122
123 std::string sum = ctx.getTmpVarName();
124 std::string coeffSum = ctx.getTmpVarName();
125 ctx.addToCodeBody(&arg, "double " + sum + " = 0;\ndouble " + coeffSum + "= 0;\n");
126
127 std::string iterator = "i_" + ctx.getTmpVarName();
128 std::string subscriptExpr = "[" + iterator + "]";
129
130 std::string code = "for(int " + iterator + " = 0; " + iterator + " < " + coeffSize + "; " + iterator + "++) {\n" +
131 sum + " += " + funcName + subscriptExpr + " * " + coeffName + subscriptExpr + ";\n";
132 code += coeffSum + " += " + coeffName + subscriptExpr + ";\n";
133 code += "}\n";
134
135 if (noLastCoeff) {
136 code += sum + " += " + funcName + "[" + coeffSize + "]" + " * (1 - " + coeffSum + ");\n";
137 } else if (normalize) {
138 code += sum + " /= " + coeffSum + ";\n";
139 }
140 ctx.addToCodeBody(&arg, code);
141
142 return sum;
143}
144
145} // namespace
146
148{
149 if (arg.isRearranged()) {
150 ctx.addResult(&arg, ctx.buildCall(mathFunc("ratio"), *arg.rearrangedNum(), *arg.rearrangedDen()));
151 } else {
152 ctx.addResult(&arg, ctx.buildCall(mathFunc("product"), *arg.partList(), arg.partList()->size()));
153 }
154}
155
157{
158 std::string const &idx = arg.dataHist().calculateTreeIndexForCodeSquash(ctx, arg.dataVars(), true);
159 std::string const &paramNames = ctx.buildArg(arg.paramList());
160
161 ctx.addResult(&arg, paramNames + "[" + idx + "]");
162}
163
165{
166 auto const &interpCodes = arg.interpolationCodes();
167
168 std::size_t n = interpCodes.size();
169
170 std::string resName = "total_" + ctx.getTmpVarName();
171 for (std::size_t i = 0; i < n; ++i) {
172 if (interpCodes[i] != interpCodes[0]) {
174 << "FlexibleInterpVar::evaluate ERROR: Code Squashing AD does not yet support having "
175 "different interpolation codes for the same class object "
176 << std::endl;
177 }
178 }
179
180 // The PiecewiseInterpolation class is used in the context of HistFactory
181 // models, where is is always used the same way: all RooAbsReals in _lowSet,
182 // _histSet, and also nominal are 1D RooHistFuncs with with same structure.
183 //
184 // Therefore, we can make a big optimization: we get the bin index only once
185 // here in the generated code for PiecewiseInterpolation. Then, we also
186 // rearrange the histogram data in such a way that we can always pass the
187 // same arrays to the free function that implements the interpolation, just
188 // with a dynamic offset calculated from the bin index.
189 RooDataHist const &nomHist = dynamic_cast<RooHistFunc const &>(*arg.nominalHist()).dataHist();
190 int nBins = nomHist.numEntries();
191 std::vector<double> valsNominal;
192 std::vector<double> valsLow;
193 std::vector<double> valsHigh;
194 for (int i = 0; i < nBins; ++i) {
195 valsNominal.push_back(nomHist.weight(i));
196 }
197 for (int i = 0; i < nBins; ++i) {
198 for (std::size_t iParam = 0; iParam < n; ++iParam) {
199 valsLow.push_back(dynamic_cast<RooHistFunc const &>(arg.lowList()[iParam]).dataHist().weight(i));
200 valsHigh.push_back(dynamic_cast<RooHistFunc const &>(arg.highList()[iParam]).dataHist().weight(i));
201 }
202 }
203 std::string idxName = ctx.getTmpVarName();
204 std::string valsNominalStr = ctx.buildArg(valsNominal);
205 std::string valsLowStr = ctx.buildArg(valsLow);
206 std::string valsHighStr = ctx.buildArg(valsHigh);
207 std::string nStr = std::to_string(n);
208 std::string code;
209
210 std::string lowName = ctx.getTmpVarName();
211 std::string highName = ctx.getTmpVarName();
212 std::string nominalName = ctx.getTmpVarName();
213 code +=
214 "unsigned int " + idxName + " = " +
215 nomHist.calculateTreeIndexForCodeSquash(ctx, dynamic_cast<RooHistFunc const &>(*arg.nominalHist()).variables()) +
216 ";\n";
217 code += "double const* " + lowName + " = " + valsLowStr + " + " + nStr + " * " + idxName + ";\n";
218 code += "double const* " + highName + " = " + valsHighStr + " + " + nStr + " * " + idxName + ";\n";
219 code += "double " + nominalName + " = *(" + valsNominalStr + " + " + idxName + ");\n";
220
221 std::string funcCall = ctx.buildCall(mathFunc("flexibleInterp"), interpCodes[0], arg.paramList(), n, lowName,
222 highName, 1.0, nominalName, 0.0);
223 code += "double " + resName + " = " + funcCall + ";\n";
224
225 if (arg.positiveDefinite()) {
226 code += resName + " = " + resName + " < 0 ? 0 : " + resName + ";\n";
227 }
228
229 ctx.addToCodeBody(&arg, code);
230 ctx.addResult(&arg, resName);
231}
232
233////////////////////////////////////////////////////////////////////////////////
234/// This function defines a translation for each RooAbsReal based object that can be used
235/// to express the class as simple C++ code. The function adds the code represented by
236/// each class as an std::string (that is later concatenated with code strings from translate calls)
237/// to form the C++ code that AD tools can understand. Any class that wants to support AD, has to
238/// implement this function.
239///
240/// \param[in] ctx An object to manage auxiliary information for code-squashing. Also takes the
241/// code string that this class outputs into the squashed code through the 'addToCodeBody' function.
243{
244 std::stringstream errorMsg;
245 errorMsg << "Translate function for class \"" << arg.ClassName() << "\" has not yet been implemented.";
246 oocoutE(&arg, Minimization) << errorMsg.str() << std::endl;
247 return ctx.addResult(&arg, "1.0");
248}
249
251{
252 ctx.addResult(&arg, realSumPdfTranslateImpl(ctx, arg, arg.pdfList(), arg.coefList(), true));
253}
254
256{
257 auto const &covI = arg.covarianceMatrixInverse();
258 std::span<const double> covISpan{covI.GetMatrixArray(), static_cast<size_t>(covI.GetNoElements())};
259 ctx.addResult(&arg,
260 ctx.buildCall(mathFunc("multiVarGaussian"), arg.xVec().size(), arg.xVec(), arg.muVec(), covISpan));
261}
262
264{
265 int numPdfs = arg.getNumPdfs();
266
267 // MathFunc call
268
269 // The value of this number should be discussed. Beyound a certain number of
270 // indices MathFunc call becomes more efficient.
271 if (numPdfs > 2) {
272 ctx.addResult(&arg, ctx.buildCall(mathFunc("multipdf"), arg.indexCategory(), arg.getPdfList()));
273
274 std::cout << "MathFunc call used\n";
275
276 } else {
277
278 // Ternary nested expression
279 std::string indexExpr = ctx.getResult(arg.indexCategory());
280
281 // int numPdfs = arg.getNumPdfs();
282 std::string expr;
283
284 for (int i = 0; i < numPdfs; ++i) {
285 RooAbsPdf *pdf = arg.getPdf(i);
286 std::string pdfExpr = ctx.getResult(*pdf);
287
288 expr += "(" + indexExpr + " == " + std::to_string(i) + " ? (" + pdfExpr + ") : ";
289 }
290
291 expr += "0.0";
292 expr += std::string(numPdfs, ')'); // Close all ternary operators
293
294 ctx.addResult(&arg, expr);
295 std::cout << "Ternary expression call used \n";
296 }
297}
298
300{
301 // A RooSimultaneous appears as a node in the compute graph only when its
302 // index category is not an observable (see the "switch mode" in
303 // RooSimultaneous::compileForNormSet()): its value is then the one of the
304 // component selected by the current category state, like for RooMultiPdf.
305 // With an observable index category, the likelihood is decomposed into
306 // per-channel terms and the RooSimultaneous itself is never translated.
307 if (arg.canBeExtended()) {
308 std::stringstream errorMsg;
309 errorMsg << "RooSimultaneous \"" << arg.GetName()
310 << "\" with extendable components and a non-observable index category can't be translated, because the "
311 "scalar evaluation applies a relative yield weight that code generation does not implement yet.";
312 oocoutE(&arg, Minimization) << errorMsg.str() << std::endl;
313 throw std::runtime_error(errorMsg.str());
314 }
315 if (!arg.indexCat().isFundamental()) {
316 std::stringstream errorMsg;
317 errorMsg << "RooSimultaneous \"" << arg.GetName()
318 << "\" with a derived, non-observable index category can't be translated.";
319 oocoutE(&arg, Minimization) << errorMsg.str() << std::endl;
320 throw std::runtime_error(errorMsg.str());
321 }
322
323 std::string const &indexExpr = ctx.getResult(arg.indexCat());
324
325 // Nested ternary expression that selects the pdf matching the category
326 // state, keyed on the state index numbers.
327 std::string expr;
328 std::size_t numStates = 0;
329 for (auto const &nameIdx : arg.indexCat()) {
330 RooAbsPdf *pdf = arg.getPdf(nameIdx.first.c_str());
331 if (!pdf) {
332 continue;
333 }
334 expr += "(" + indexExpr + " == " + std::to_string(nameIdx.second) + " ? (" + ctx.getResult(*pdf) + ") : ";
335 ++numStates;
336 }
337 expr += "0.0" + std::string(numStates, ')');
338
339 ctx.addResult(&arg, expr);
340}
341
342// RooCategory index added.
344{
345 int idx = ctx.observableIndexOf(arg);
346 if (idx < 0) {
347
348 idx = 1;
349 ctx.addVecObs(arg.GetName(), idx);
350 }
351
352 std::string result = std::to_string(arg.getCurrentIndex());
353 ctx.addResult(&arg, result);
354}
355
357{
358 if (arg.list().empty()) {
359 ctx.addResult(&arg, "0.0");
360 }
361 std::string result;
362 if (arg.list().size() > 1)
363 result += "(";
364
365 std::size_t i = 0;
366 for (auto *component : static_range_cast<RooAbsReal *>(arg.list())) {
367
368 if (!dynamic_cast<RooFit::Detail::RooNLLVarNew *>(component) || arg.list().size() == 1) {
369 result += ctx.getResult(*component);
370 ++i;
371 if (i < arg.list().size())
372 result += '+';
373 continue;
374 }
375 result += ctx.buildFunction(*component, ctx.dependsOnData()) + "(params, obs, xlArr)";
376 ++i;
377 if (i < arg.list().size())
378 result += '+';
379 }
380 if (arg.list().size() > 1)
381 result += ')';
382 ctx.addResult(&arg, result);
383}
384
386{
387 arg.fillBuffer();
388 ctx.addResult(&arg, ctx.buildCall(mathFunc("bernstein"), arg.x(), arg.xmin(), arg.xmax(), arg.coefList(),
389 arg.coefList().size()));
390}
391
393{
394 ctx.addResult(&arg,
395 ctx.buildCall(mathFunc("bifurGauss"), arg.getX(), arg.getMean(), arg.getSigmaL(), arg.getSigmaR()));
396}
397
399{
400 ctx.addResult(
401 &arg, ctx.buildCall(mathFunc("cbShape"), arg.getM(), arg.getM0(), arg.getSigma(), arg.getAlpha(), arg.getN()));
402}
403
405{
406 // first bring the range of the variable _x to the normalised range [-1, 1]
407 // calculate sum_k c_k T_k(x) where x is given in the normalised range,
408 // c_0 = 1, and the higher coefficients are given in _coefList
409 double xmax = static_cast<RooAbsRealLValue const &>(arg.x()).getMax(arg.refRangeName());
410 double xmin = static_cast<RooAbsRealLValue const &>(arg.x()).getMin(arg.refRangeName());
411
412 ctx.addResult(&arg,
413 ctx.buildCall(mathFunc("chebychev"), arg.coefList(), arg.coefList().size(), arg.x(), xmin, xmax));
414}
415
417{
418 ctx.addResult(&arg, doubleToString(arg.getVal()));
419}
420
422{
423 ctx.addResult(&arg, ctx.buildCall(mathFunc("constraintSum"), arg.list(), arg.list().size()));
424}
425
426// Generate RooFit codegen wrappers for RooFunctorBinding and similar objects,
427// emitting both the primal function call and its gradient pullback for
428// Clad-based AD.
429template <class RooArg_t>
431{
432 if (!arg.function()->HasGradient()) {
433 std::stringstream errorMsg;
434 errorMsg << "Functor wrapped by \"" << arg.GetName() << "\" doesn't provide a gradient function."
435 << " RooFit codegen is therefore not supported.";
436 oocoutE(&arg, InputArguments) << errorMsg.str() << std::endl;
437 throw std::runtime_error(errorMsg.str());
438 }
439
440 std::string funcAddrStr = TString::Format("0x%zx", reinterpret_cast<std::size_t>(arg.function())).Data();
441 std::string wrapperName = "roo_functor_" + funcAddrStr;
442
443 static std::unordered_set<std::string> wrapperNames;
444
445 if (wrapperNames.find(wrapperName) == wrapperNames.end()) {
446
448
449 std::string pullbackName = wrapperName + "_pullback";
450 std::string nStr = std::to_string(std::size(variables));
451
452 std::string type;
453 if constexpr (std::is_same_v<RooArg_t, RooFunctor1DBinding> || std::is_same_v<RooArg_t, RooFunctor1DPdfBinding>)
454 type = "::ROOT::Math::IGradientFunctionOneDim";
455 else
456 type = "::ROOT::Math::IGradientFunctionMultiDim";
457
458 std::string funcAddrCasted = "reinterpret_cast<" + type + " const *>(" + funcAddrStr + ")";
459
460 std::string code;
461
462 code += "double " + wrapperName +
463 "(double const *x) {\n"
464 " return " +
466 "->operator()(x);\n"
467 "}\n\n"
468 "namespace clad::custom_derivatives {\n\n"
469 "void " +
471 "(double const* x, double d_y, double *d_x) {\n"
472 " double output[" +
473 nStr +
474 "]{};\n"
475 " " +
477 "->Gradient(x, output);\n"
478 " for (int i = 0; i < " +
479 nStr +
480 "; ++i) {\n"
481 " d_x[i] += output[i] * d_y;\n"
482 " }\n"
483 "}\n"
484 "} // namespace clad::custom_derivatives\n";
485
486 gInterpreter->Declare(code.c_str());
487 }
488
489 ctx.addResult(&arg, ctx.buildCall(wrapperName, variables));
490}
491
496
501
506
511
513{
514 ctx.addResult(&arg, ctx.buildCall("TMath::GammaDist", arg.getX(), arg.getGamma(), arg.getMu(), arg.getBeta()));
515}
516
518{
519 arg.getVal(); // to trigger the creation of the TFormula
520 std::string funcName = arg.getUniqueFuncName();
521 ctx.collectFunction(funcName);
522 // We have to force the array type to be "double" because that's what the
523 // declared function wrapped by the TFormula expects.
524 auto inputVar = ctx.buildArg(arg.dependents(), /*arrayType=*/"double");
525 ctx.addResult(&arg, funcName + "(" + inputVar + ")");
526}
527
529{
530 ctx.addResult(&arg, ctx.buildCall(mathFunc("effProd"), arg.eff(), arg.pdf()));
531}
532
534{
535 RooAbsCategory const &cat = arg.cat();
536 int sigCatIndex = cat.lookupIndex(arg.sigCatName());
537 ctx.addResult(&arg, ctx.buildCall(mathFunc("efficiency"), arg.effFunc(), cat, sigCatIndex));
538}
539
541{
542 // Build a call to the stateless exponential defined later.
543 std::string coef;
544 if (arg.negateCoefficient()) {
545 coef += "-";
546 }
547 coef += ctx.getResult(arg.coefficient());
548 ctx.addResult(&arg, "std::exp(" + coef + " * " + ctx.getResult(arg.variable()) + ")");
549}
550
552{
553 // Use the result of the underlying pdf.
554 ctx.addResult(&arg, ctx.getResult(arg.pdf()));
555}
556
558{
559 // Build a call to the stateless gaussian defined later.
560 ctx.addResult(&arg, ctx.buildCall(mathFunc("gaussian"), arg.getX(), arg.getMean(), arg.getSigma()));
561}
562
564{
565 arg.getVal(); // to trigger the creation of the TFormula
566 std::string funcName = arg.getUniqueFuncName();
567 ctx.collectFunction(funcName);
568 // We have to force the array type to be "double" because that's what the
569 // declared function wrapped by the TFormula expects.
570 auto inputVar = ctx.buildArg(arg.dependents(), /*arrayType=*/"double");
571 ctx.addResult(&arg, funcName + "(" + inputVar + ")");
572}
573
575{
576 rooHistTranslateImpl(arg, ctx, arg.getInterpolationOrder(), arg.dataHist(), arg.variables(), false,
577 arg.getCdfBoundaries());
578}
579
585
587{
588 ctx.addResult(&arg, ctx.buildCall(mathFunc("landau"), arg.getX(), arg.getMean(), arg.getSigma()));
589}
590
592{
593 std::string funcName = arg.useStandardParametrization() ? "logNormalEvaluateStandard" : "logNormal";
594 ctx.addResult(&arg, ctx.buildCall(mathFunc(funcName), arg.getX(), arg.getShapeK(), arg.getMedian()));
595}
596
597namespace {
598
599void codegenChi2(RooFit::Detail::RooNLLVarNew &arg, CodegenContext &ctx)
600{
601 using FuncMode = RooFit::Detail::RooNLLVarNew::FuncMode;
602
603 std::string resName = RooFit::Detail::makeValidVarName(arg.GetName()) + "Result";
604 ctx.addResult(&arg, resName);
605 ctx.addToGlobalScope("double " + resName + " = 0.0;\n");
606
607 // DataError::None means "no errors": every bin contributes zero.
608 if (arg.chi2ErrorType() == RooDataHist::None) {
609 return;
610 }
611
612 // Compute the per-bin normalization factor (constant with respect to the
613 // loop).
614 std::string normFactor;
615 if (arg.funcMode() == FuncMode::Function) {
616 normFactor = "1.0";
617 } else if (arg.funcMode() == FuncMode::ExtendedPdf) {
618 normFactor = ctx.getResult(*arg.expectedEvents());
619 } else { // Pdf
620 std::string weightSumName = RooFit::Detail::makeValidVarName(arg.GetName()) + "WeightSum";
621 ctx.addToGlobalScope("double " + weightSumName + " = 0.0;\n");
622 {
623 auto scope = ctx.beginLoop(&arg);
624 ctx.addToCodeBody(weightSumName + " += " + ctx.getResult(arg.weightVar()) + ";\n");
625 }
627 }
628
629 auto scope = ctx.beginLoop(&arg);
630 const std::string mu =
631 "(" + ctx.getResult(arg.func()) + " * " + ctx.getResult(*arg.binVolumes()) + " * " + normFactor + ")";
632
633 std::string term;
634 switch (arg.chi2ErrorType()) {
635 case RooDataHist::Expected: term = ctx.buildCall(mathFunc("chi2Expected"), mu, arg.weightVar()); break;
637 term = ctx.buildCall(mathFunc("chi2Symmetric"), mu, arg.weightVar(), arg.weightSquaredVar());
638 break;
640 term = ctx.buildCall(mathFunc("chi2Asymmetric"), mu, arg.weightVar(), *arg.weightErrLo(), *arg.weightErrHi());
641 break;
642 default: break;
643 }
644 ctx.addToCodeBody(&arg, resName + " += " + term + ";");
645}
646
647} // namespace
648
649void codegenImpl(RooFit::Detail::RooNLLVarNew &arg, CodegenContext &ctx)
650{
651 if (arg.statistic() == RooFit::Detail::RooNLLVarNew::Statistic::Chi2) {
652 return codegenChi2(arg, ctx);
653 }
654
655 if (arg.binnedL() && !arg.func().getAttribute("BinnedLikelihoodActiveYields")) {
656 std::stringstream errorMsg;
657 errorMsg << "codegen: binned likelihood optimization is only supported when raw pdf "
658 "values can be interpreted as yields."
659 << " This is not the case for HistFactory models written with ROOT versions before 6.26.00";
660 oocoutE(&arg, InputArguments) << errorMsg.str() << std::endl;
661 throw std::runtime_error(errorMsg.str());
662 }
663
664 std::string weightSumName = RooFit::Detail::makeValidVarName(arg.GetName()) + "WeightSum";
665 std::string resName = RooFit::Detail::makeValidVarName(arg.GetName()) + "Result";
666 ctx.addResult(&arg, resName);
667 ctx.addToGlobalScope("double " + weightSumName + " = 0.0;\n");
668 ctx.addToGlobalScope("double " + resName + " = 0.0;\n");
669
670 const bool needWeightSum = arg.expectedEvents() || arg.simCount() > 1;
671
672 if (needWeightSum) {
673 auto scope = ctx.beginLoop(&arg);
674 ctx.addToCodeBody(weightSumName + " += " + ctx.getResult(arg.weightVar()) + ";\n");
675 }
676 if (arg.simCount() > 1) {
677 std::string simCountStr = std::to_string(static_cast<double>(arg.simCount()));
678 ctx.addToCodeBody(resName + " += " + weightSumName + " * std::log(" + simCountStr + ");\n");
679 }
680
681 // Begin loop scope for the observables and weight variable. If the weight
682 // is a scalar, the context will ignore it for the loop scope. The closing
683 // brackets of the loop is written at the end of the scopes lifetime.
684 {
685 auto scope = ctx.beginLoop(&arg);
686 std::string term = ctx.buildCall(mathFunc("nll"), arg.func(), arg.weightVar(), arg.binnedL(), 0);
687 ctx.addToCodeBody(&arg, resName + " += " + term + ";");
688 }
689 if (arg.expectedEvents()) {
690 std::string expected = ctx.getResult(*arg.expectedEvents());
691 ctx.addToCodeBody(resName + " += " + expected + " - " + weightSumName + " * std::log(" + expected + ");\n");
692 }
693}
694
696{
697 // For now just return function/normalization integral.
698 ctx.addResult(&arg, ctx.getResult(arg.pdf()) + "/" + ctx.getResult(arg.normIntegral()));
699}
700
702{
703 std::string const &idx = arg.dataHist().calculateTreeIndexForCodeSquash(ctx, arg.xList());
704 std::string arrName = ctx.buildArg(arg.paramList());
705 std::stringstream result;
706 result << arrName << "[" << idx << "]";
707 if (arg.relParam()) {
708 // get weight[idx] * binv[idx]. Here we get the bin volume for the first element as we assume the distribution to
709 // be binned uniformly.
710 double binV = arg.dataHist().binVolume(0);
711 std::string weightArr = arg.dataHist().declWeightArrayForCodeSquash(ctx, false);
712 result << " * *(" << weightArr << " + " << idx + ") * " << doubleToString(binV);
713 }
714 ctx.addResult(&arg, result.str());
715}
716
718{
719 std::string xName = ctx.getResult(arg.getX());
720 if (!arg.getNoRounding())
721 xName = "std::floor(" + xName + ")";
722
723 ctx.addResult(&arg, ctx.buildCall(mathFunc("poisson"), xName, arg.getMean()));
724}
725
727{
728 const unsigned sz = arg.coefList().size();
729 if (!sz) {
730 ctx.addResult(&arg, std::to_string(arg.lowestOrder() ? 1. : 0.));
731 return;
732 }
733
734 ctx.addResult(&arg, ctx.buildCall(mathFunc("polynomial"), arg.coefList(), sz, arg.lowestOrder(), arg.x()));
735}
736
738{
739 const unsigned sz = arg.coefList().size();
740 if (!sz) {
741 ctx.addResult(&arg, std::to_string(arg.lowestOrder() ? 1. : 0.));
742 return;
743 }
744
745 ctx.addResult(&arg, ctx.buildCall(mathFunc("polynomial<true>"), arg.coefList(), sz, arg.lowestOrder(), arg.x()));
746}
747
749{
750 ctx.addResult(&arg, ctx.buildCall(mathFunc("product"), arg.realComponents(), arg.realComponents().size()));
751}
752
754{
755 ctx.addResult(&arg, ctx.buildCall(mathFunc("ratio"), arg.numerator(), arg.denominator()));
756}
757
758namespace {
759
760std::string codegenIntegral(RooAbsReal &arg, int code, const char *rangeName, CodegenContext &ctx)
761{
762 using Func = std::string (*)(RooAbsReal &, int, const char *, CodegenContext &);
763
764 Func func;
765
766 TClass *tclass = arg.IsA();
767
768 // Cache the overload resolutions
769 static std::unordered_map<TClass *, Func> dispatchMap;
770
771 auto found = dispatchMap.find(tclass);
772
773 if (found != dispatchMap.end()) {
774 func = found->second;
775 } else {
776 // Can probably done with CppInterop in the future to avoid string manipulation.
777 std::stringstream cmd;
778 cmd << "&RooFit::Experimental::CodegenIntegralImplCaller<" << tclass->GetName() << ">::call;";
779 func = reinterpret_cast<Func>(gInterpreter->ProcessLine(cmd.str().c_str()));
780 dispatchMap[tclass] = func;
781 }
782
783 return func(arg, code, rangeName, ctx);
784}
785
786} // namespace
787
789{
790 if (arg.numIntCatVars().empty() && arg.numIntRealVars().empty()) {
791 ctx.addResult(&arg, codegenIntegral(const_cast<RooAbsReal &>(arg.integrand()), arg.mode(), arg.intRange(), ctx));
792 return;
793 }
794
795 if (arg.intVars().size() != 1 || arg.numIntRealVars().size() != 1) {
796 std::stringstream errorMsg;
797 errorMsg << "Only analytical integrals and 1D numeric integrals are supported for AD for class"
798 << arg.integrand().GetName();
799 oocoutE(&arg, Minimization) << errorMsg.str() << std::endl;
800 throw std::runtime_error(errorMsg.str().c_str());
801 }
802
803 auto &intVar = static_cast<RooAbsRealLValue &>(*arg.numIntRealVars()[0]);
804
805 std::string obsName = ctx.getTmpVarName();
806 std::string oldIntVarResult = ctx.getResult(intVar);
807 ctx.addResult(&intVar, "obs[0]");
808
809 std::string funcName = ctx.buildFunction(arg.integrand(), {});
810
811 std::stringstream ss;
812
813 ss << "double " << obsName << "[1];\n";
814
815 std::string resName = RooFit::Detail::makeValidVarName(arg.GetName()) + "Result";
816 ctx.addResult(&arg, resName);
817 ctx.addToGlobalScope("double " + resName + " = 0.0;\n");
818
819 // TODO: once Clad has support for higher-order functions (follow also the
820 // Clad issue #637), we could refactor this code into an actual function
821 // instead of hardcoding it here as a string.
822 ss << "{\n"
823 << " const int n = 1000; // number of sampling points\n"
824 << " double d = " << intVar.getMax(arg.intRange()) << " - " << intVar.getMin(arg.intRange()) << ";\n"
825 << " double eps = d / n;\n"
826 << " #pragma clad checkpoint loop\n"
827 << " for (int i = 0; i < n; ++i) {\n"
828 << " " << obsName << "[0] = " << intVar.getMin(arg.intRange()) << " + eps * i;\n"
829 << " double tmpA = " << funcName << "(params, " << obsName << ", xlArr);\n"
830 << " " << obsName << "[0] = " << intVar.getMin(arg.intRange()) << " + eps * (i + 1);\n"
831 << " double tmpB = " << funcName << "(params, " << obsName << ", xlArr);\n"
832 << " " << resName << " += (tmpA + tmpB) * 0.5 * eps;\n"
833 << " }\n"
834 << "}\n";
835
836 ctx.addToGlobalScope(ss.str());
837
838 ctx.addResult(&intVar, oldIntVarResult);
839}
840
842{
843 ctx.addResult(&arg, realSumPdfTranslateImpl(ctx, arg, arg.funcList(), arg.coefList(), false));
844}
845
847{
848 ctx.addResult(&arg, realSumPdfTranslateImpl(ctx, arg, arg.funcList(), arg.coefList(), false));
849}
850
852{
853 if (!arg.isConstant()) {
854 ctx.addResult(&arg, arg.GetName());
855 }
856 ctx.addResult(&arg, doubleToString(arg.getVal()));
857}
858
860{
861 ctx.addResult(&arg, ctx.buildCall(mathFunc("recursiveFraction"), arg.variables(), arg.variables().size()));
862}
863
865{
866 auto const &interpCodes = arg.interpolationCodes();
867
868 unsigned int n = interpCodes.size();
869
870 int interpCode = interpCodes[0];
871 // To get consistent codes with the PiecewiseInterpolation
872 if (interpCode == 4) {
873 interpCode = 5;
874 }
875
876 for (unsigned int i = 1; i < n; i++) {
877 if (interpCodes[i] != interpCodes[0]) {
879 << "FlexibleInterpVar::evaluate ERROR: Code Squashing AD does not yet support having "
880 "different interpolation codes for the same class object "
881 << std::endl;
882 }
883 }
884
885 std::string const &resName = ctx.buildCall(mathFunc("flexibleInterp"), interpCode, arg.variables(), n, arg.low(),
886 arg.high(), arg.globalBoundary(), arg.nominal(), 1.0);
887 ctx.addResult(&arg, resName);
888}
889
891{
892 ctx.addResult(&arg, "1.0");
893}
894
896{
897 ctx.addResult(&arg, ctx.getResult(arg.function()));
898}
899
900////////////////////////////////////////////////////////////////////////////////
901/// This function defines the analytical integral translation for the class.
902///
903/// \param[in] code The code that decides the integrands.
904/// \param[in] rangeName Name of the normalization range.
905/// \param[in] ctx An object to manage auxiliary information for code-squashing.
906///
907/// \returns The representative code string of the integral for the given object.
908std::string codegenIntegralImpl(RooAbsReal &arg, int, const char *, CodegenContext &)
909{
910 std::stringstream errorMsg;
911 errorMsg << "An analytical integral function for class \"" << arg.ClassName() << "\" has not yet been implemented.";
912 oocoutE(&arg, Minimization) << errorMsg.str() << std::endl;
913 throw std::runtime_error(errorMsg.str().c_str());
914}
915
916std::string codegenIntegralImpl(RooBernstein &arg, int, const char *rangeName, CodegenContext &ctx)
917{
918 arg.fillBuffer(); // to get the right xmin() and xmax()
919 auto &x = dynamic_cast<RooAbsRealLValue const &>(arg.x());
920 return ctx.buildCall(mathFunc("bernsteinIntegral"), x.getMin(rangeName), x.getMax(rangeName), arg.xmin(), arg.xmax(),
921 arg.coefList(), arg.coefList().size());
922}
923
924std::string codegenIntegralImpl(RooBifurGauss &arg, int code, const char *rangeName, CodegenContext &ctx)
925{
926 auto &constant = code == 1 ? arg.getMean() : arg.getX();
927 auto &integrand = dynamic_cast<RooAbsRealLValue const &>(code == 1 ? arg.getX() : arg.getMean());
928
929 return ctx.buildCall(mathFunc("bifurGaussIntegral"), integrand.getMin(rangeName), integrand.getMax(rangeName),
930 constant, arg.getSigmaL(), arg.getSigmaR());
931}
932
933std::string codegenIntegralImpl(RooCBShape &arg, int /*code*/, const char *rangeName, CodegenContext &ctx)
934{
935 auto &m = dynamic_cast<RooAbsRealLValue const &>(arg.getM());
936 return ctx.buildCall(mathFunc("cbShapeIntegral"), m.getMin(rangeName), m.getMax(rangeName), arg.getM0(),
937 arg.getSigma(), arg.getAlpha(), arg.getN());
938}
939
940std::string codegenIntegralImpl(RooChebychev &arg, int, const char *rangeName, CodegenContext &ctx)
941{
942 auto &x = dynamic_cast<RooAbsRealLValue const &>(arg.x());
943 double xmax = x.getMax(arg.refRangeName());
944 double xmin = x.getMin(arg.refRangeName());
945 unsigned int sz = arg.coefList().size();
946
947 return ctx.buildCall(mathFunc("chebychevIntegral"), arg.coefList(), sz, xmin, xmax, x.getMin(rangeName),
948 x.getMax(rangeName));
949}
950
951std::string codegenIntegralImpl(RooEfficiency &, int, const char *, CodegenContext &)
952{
953 return "1.0";
954}
955
956std::string codegenIntegralImpl(RooExponential &arg, int code, const char *rangeName, CodegenContext &ctx)
957{
958 bool isOverX = code == 1;
959
960 std::string constant;
961 if (arg.negateCoefficient() && isOverX) {
962 constant += "-";
963 }
964 constant += ctx.getResult(isOverX ? arg.coefficient() : arg.variable());
965
966 auto &integrand = dynamic_cast<RooAbsRealLValue const &>(isOverX ? arg.variable() : arg.coefficient());
967
968 double min = integrand.getMin(rangeName);
969 double max = integrand.getMax(rangeName);
970
971 if (!isOverX && arg.negateCoefficient()) {
972 std::swap(min, max);
973 min = -min;
974 max = -max;
975 }
976
977 return ctx.buildCall(mathFunc("exponentialIntegral"), min, max, constant);
978}
979
980std::string codegenIntegralImpl(RooGamma &arg, int, const char *rangeName, CodegenContext &ctx)
981{
982 auto &x = dynamic_cast<RooAbsRealLValue const &>(arg.getX());
983 const std::string a =
984 ctx.buildCall("ROOT::Math::gamma_cdf", x.getMax(rangeName), arg.getGamma(), arg.getBeta(), arg.getMu());
985 const std::string b =
986 ctx.buildCall("ROOT::Math::gamma_cdf", x.getMin(rangeName), arg.getGamma(), arg.getBeta(), arg.getMu());
987 return a + " - " + b;
988}
989
990std::string codegenIntegralImpl(RooGaussian &arg, int code, const char *rangeName, CodegenContext &ctx)
991{
992 auto &constant = code == 1 ? arg.getMean() : arg.getX();
993 auto &integrand = dynamic_cast<RooAbsRealLValue const &>(code == 1 ? arg.getX() : arg.getMean());
994
995 return ctx.buildCall(mathFunc("gaussianIntegral"), integrand.getMin(rangeName), integrand.getMax(rangeName),
996 constant, arg.getSigma());
997}
998
999namespace {
1000
1001std::string rooHistIntegralTranslateImpl(int code, RooAbsArg const &arg, RooDataHist const &dataHist,
1002 const RooArgSet &obs, bool histFuncMode)
1003{
1004 if (((2 << obs.size()) - 1) != code) {
1005 oocoutE(&arg, InputArguments) << "RooHistPdf::integral(" << arg.GetName()
1006 << ") ERROR: AD currently only supports integrating over all histogram observables."
1007 << std::endl;
1008 return "";
1009 }
1010 return doubleToString(dataHist.sum(histFuncMode));
1011}
1012
1013} // namespace
1014
1015std::string codegenIntegralImpl(RooHistFunc &arg, int code, const char *, CodegenContext &)
1016{
1017 return rooHistIntegralTranslateImpl(code, arg, arg.dataHist(), arg.variables(), true);
1018}
1019
1020std::string codegenIntegralImpl(RooHistPdf &arg, int code, const char *, CodegenContext &)
1021{
1022 return rooHistIntegralTranslateImpl(code, arg, arg.dataHist(), arg.variables(), false);
1023}
1024
1025std::string codegenIntegralImpl(RooLandau &arg, int, const char *rangeName, CodegenContext &ctx)
1026{
1027 // Don't do anything with "code". It can only be "1" anyway (see
1028 // implementation of getAnalyticalIntegral).
1029 auto &x = dynamic_cast<RooAbsRealLValue const &>(arg.getX());
1030 const std::string a = ctx.buildCall("ROOT::Math::landau_cdf", x.getMax(rangeName), arg.getSigma(), arg.getMean());
1031 const std::string b = ctx.buildCall("ROOT::Math::landau_cdf", x.getMin(rangeName), arg.getSigma(), arg.getMean());
1032 return ctx.getResult(arg.getSigma()) + " * " + "(" + a + " - " + b + ")";
1033}
1034
1035std::string codegenIntegralImpl(RooLognormal &arg, int, const char *rangeName, CodegenContext &ctx)
1036{
1037 std::string funcName = arg.useStandardParametrization() ? "logNormalIntegralStandard" : "logNormalIntegral";
1038 auto &x = dynamic_cast<RooAbsRealLValue const &>(arg.getX());
1039 return ctx.buildCall(mathFunc(funcName), x.getMin(rangeName), x.getMax(rangeName), arg.getMedian(), arg.getShapeK());
1040}
1041
1042std::string codegenIntegralImpl(RooMultiVarGaussian &arg, int code, const char *rangeName, CodegenContext &)
1043{
1044 if (code != -1) {
1045 std::stringstream errorMsg;
1046 errorMsg << "Partial integrals over RooMultiVarGaussian are not supported.";
1047 oocoutE(&arg, Minimization) << errorMsg.str() << std::endl;
1048 throw std::runtime_error(errorMsg.str().c_str());
1049 }
1050
1051 return doubleToString(arg.analyticalIntegral(code, rangeName));
1052}
1053
1055{
1056 std::stringstream ss;
1057 ss << arg.outerWrapperName() << "(";
1058 for (std::size_t i = 0; i < arg.nInputTensors(); ++i) {
1059 ss << ctx.buildArg(arg.inputTensorList(i)) << std::endl;
1060 if (i != arg.nInputTensors() - 1) {
1061 ss << ", ";
1062 }
1063 }
1064 ss << ")";
1065
1066 ctx.addResult(&arg, ss.str());
1067}
1068
1069std::string codegenIntegralImpl(RooPoisson &arg, int code, const char *rangeName, CodegenContext &ctx)
1070{
1071 assert(code == 1 || code == 2);
1072 std::string xName = ctx.getResult(arg.getX());
1073 if (!arg.getNoRounding())
1074 xName = "std::floor(" + xName + ")";
1075
1076 auto &integrand = dynamic_cast<RooAbsRealLValue const &>(code == 1 ? arg.getX() : arg.getMean());
1077 // Since the integral function is the same for both codes, we need to make sure the indexed observables do not appear
1078 // in the function if they are not required.
1079 xName = code == 1 ? "0" : xName;
1080 return ctx.buildCall(mathFunc("poissonIntegral"), code, arg.getMean(), xName, integrand.getMin(rangeName),
1081 integrand.getMax(rangeName), arg.getProtectNegativeMean());
1082}
1083
1084std::string codegenIntegralImpl(RooPolyVar &arg, int, const char *rangeName, CodegenContext &ctx)
1085{
1086 auto &x = dynamic_cast<RooAbsRealLValue const &>(arg.x());
1087 const double xmin = x.getMin(rangeName);
1088 const double xmax = x.getMax(rangeName);
1089 const unsigned sz = arg.coefList().size();
1090 if (!sz)
1091 return std::to_string(arg.lowestOrder() ? xmax - xmin : 0.0);
1092
1093 return ctx.buildCall(mathFunc("polynomialIntegral"), arg.coefList(), sz, arg.lowestOrder(), xmin, xmax);
1094}
1095
1096std::string codegenIntegralImpl(RooPolynomial &arg, int, const char *rangeName, CodegenContext &ctx)
1097{
1098 auto &x = dynamic_cast<RooAbsRealLValue const &>(arg.x());
1099 const double xmin = x.getMin(rangeName);
1100 const double xmax = x.getMax(rangeName);
1101 const unsigned sz = arg.coefList().size();
1102 if (!sz)
1103 return std::to_string(arg.lowestOrder() ? xmax - xmin : 0.0);
1104
1105 return ctx.buildCall(mathFunc("polynomialIntegral<true>"), arg.coefList(), sz, arg.lowestOrder(), xmin, xmax);
1106}
1107
1108std::string codegenIntegralImpl(RooRealSumPdf &arg, int code, const char *rangeName, CodegenContext &ctx)
1109{
1110 // Re-use translate, since integration is linear.
1111 return realSumPdfTranslateImpl(ctx, arg, arg.funcIntListFromCache(code, rangeName), arg.coefList(), false);
1112}
1113
1114std::string codegenIntegralImpl(RooUniform &arg, int code, const char *rangeName, CodegenContext &)
1115{
1116 // The integral of a uniform distribution is static, so we can just hardcode
1117 // the result in a string.
1118 return doubleToString(arg.analyticalIntegral(code, rangeName));
1119}
1120
1121} // namespace RooFit::Experimental
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
#define oocoutE(o, a)
#define ooccoutE(o, a)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:142
float xmin
float xmax
#define gInterpreter
A class which maps the current values of a RooRealVar (or a set of RooRealVars) to one of a number of...
const RooArgList & paramList() const
const RooArgList & dataVars() const
RooDataHist const & dataHist() const
The PiecewiseInterpolation is a class that can morph distributions into each other,...
const RooArgList & highList() const
const RooAbsReal * nominalHist() const
Return pointer to the nominal hist function.
const RooArgList & lowList() const
const RooArgList & paramList() const
const std::vector< int > & interpolationCodes() const
const_iterator end() const
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:76
bool isConstant() const
Check if the "Constant" attribute is set.
Definition RooAbsArg.h:283
Abstract base class for RooRealVar binning definitions.
Int_t numBins() const
Return number of bins.
virtual double highBound() const =0
virtual double lowBound() const =0
A space to attach TBranches.
value_type lookupIndex(const std::string &stateName) const
Find the index number corresponding to the state name.
Storage_t::size_type size() const
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:32
bool canBeExtended() const
If true, PDF can provide extended likelihood term.
Definition RooAbsPdf.h:214
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:107
TClass * IsA() const override
Definition RooAbsReal.h:553
Efficient implementation of a sum of PDFs of the form.
Definition RooAddPdf.h:32
const RooArgList & coefList() const
Definition RooAddPdf.h:73
const RooArgList & pdfList() const
Definition RooAddPdf.h:69
Calculates the sum of a set of RooAbsReal terms, or when constructed with two sets,...
Definition RooAddition.h:27
const RooArgList & list() const
Definition RooAddition.h:42
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Bernstein basis polynomials are positive-definite in the range [0,1].
void fillBuffer() const
RooAbsRealLValue const & x() const
RooArgList const & coefList() const
double xmax() const
double xmin() const
Bifurcated Gaussian p.d.f with different widths on left and right side of maximum value.
RooAbsReal const & getSigmaL() const
Get the left sigma parameter.
RooAbsReal const & getSigmaR() const
Get the right sigma parameter.
RooAbsReal const & getX() const
Get the x variable.
RooAbsReal const & getMean() const
Get the mean parameter.
PDF implementing the Crystal Ball line shape.
Definition RooCBShape.h:24
RooAbsReal const & getSigma() const
Definition RooCBShape.h:43
RooAbsReal const & getM() const
Definition RooCBShape.h:41
RooAbsReal const & getN() const
Definition RooCBShape.h:45
RooAbsReal const & getM0() const
Definition RooCBShape.h:42
RooAbsReal const & getAlpha() const
Definition RooCBShape.h:44
Object to represent discrete states.
Definition RooCategory.h:28
value_type getCurrentIndex() const final
Return current index.
Definition RooCategory.h:40
Chebychev polynomial p.d.f.
RooAbsReal const & x() const
RooArgList const & coefList() const
const char * refRangeName() const
Represents a constant real-valued object.
Definition RooConstVar.h:23
Calculates the sum of the -(log) likelihoods of a set of RooAbsPfs that represent constraint function...
const RooArgList & list() const
Container class to hold N-dimensional binned data.
Definition RooDataHist.h:40
double sum(bool correctForBinSize, bool inverseCorr=false) const
Return the sum of the weights of all bins in the histogram.
std::vector< std::unique_ptr< const RooAbsBinning > > const & getBinnings() const
std::string declWeightArrayForCodeSquash(RooFit::Experimental::CodegenContext &ctx, bool correctForBinSize) const
double weight(std::size_t i) const
Return weight of i-th bin.
std::string calculateTreeIndexForCodeSquash(RooFit::Experimental::CodegenContext &ctx, const RooAbsCollection &coords, bool reverse=false) const
The class RooEffProd implements the product of a PDF with an efficiency function.
Definition RooEffProd.h:19
RooAbsReal const & pdf() const
Definition RooEffProd.h:31
RooAbsReal const & eff() const
Definition RooEffProd.h:32
A PDF helper class to fit efficiencies parameterized by a supplied function F.
RooAbsCategory const & cat() const
RooAbsReal const & effFunc() const
std::string sigCatName() const
Exponential PDF.
bool negateCoefficient() const
RooAbsReal const & coefficient() const
Get the coefficient "c".
RooAbsReal const & variable() const
Get the x variable.
RooExtendPdf is a wrapper around an existing PDF that adds a parameteric extended likelihood term to ...
RooAbsPdf const & pdf() const
A RooProdPdf with a fixed normalization set can be replaced by this class.
Definition RooProdPdf.h:209
RooArgSet const * partList() const
Definition RooProdPdf.h:264
RooAbsReal const * rearrangedDen() const
Definition RooProdPdf.h:259
RooAbsReal const * rearrangedNum() const
Definition RooProdPdf.h:255
RooAbsReal const & normIntegral() const
RooAbsPdf const & pdf() const
A class to maintain the context for squashing of RooFit models into code.
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
const RooArgList & dependents() const
std::string getUniqueFuncName() const
RooCFunction1Binding is a templated implementation of class RooAbsReal that binds generic C(++) funct...
RooAbsReal const & variable() const
RooAbsReal const & variable() const
RooFunctorBinding makes math functions from ROOT usable in RooFit.
RooArgList const & variables() const
RooFunctorPdfBinding makes math functions from ROOT usable as PDFs in RooFit.
RooArgList const & variables() const
Implementation of the Gamma PDF for RooFit/RooStats.
Definition RooGamma.h:20
RooAbsReal const & getX() const
Definition RooGamma.h:34
RooAbsReal const & getGamma() const
Definition RooGamma.h:35
RooAbsReal const & getBeta() const
Definition RooGamma.h:36
RooAbsReal const & getMu() const
Definition RooGamma.h:37
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
RooAbsReal const & getX() const
Get the x variable.
Definition RooGaussian.h:45
RooAbsReal const & getMean() const
Get the mean parameter.
Definition RooGaussian.h:48
RooAbsReal const & getSigma() const
Get the sigma parameter.
Definition RooGaussian.h:51
Implementation of a probability density function that takes a RooArgList of servers and a C++ express...
const RooArgList & dependents() const
std::string getUniqueFuncName() const
A real-valued function sampled from a multidimensional histogram.
Definition RooHistFunc.h:29
Int_t getInterpolationOrder() const
Return histogram interpolation order.
Definition RooHistFunc.h:67
bool getCdfBoundaries() const
If true, special boundary conditions for c.d.f.s are used.
Definition RooHistFunc.h:83
RooDataHist & dataHist()
Return RooDataHist that is represented.
Definition RooHistFunc.h:43
RooArgSet const & variables() const
A probability density function sampled from a multidimensional histogram.
Definition RooHistPdf.h:29
Int_t getInterpolationOrder() const
Definition RooHistPdf.h:58
RooDataHist & dataHist()
Definition RooHistPdf.h:41
bool haveUnitNorm() const
Definition RooHistPdf.h:81
bool getCdfBoundaries() const
Definition RooHistPdf.h:72
RooArgSet const & variables() const
Definition RooHistPdf.h:97
Landau distribution p.d.f.
Definition RooLandau.h:24
RooAbsReal const & getSigma() const
Definition RooLandau.h:42
RooAbsReal const & getMean() const
Definition RooLandau.h:41
RooAbsReal const & getX() const
Definition RooLandau.h:40
RooFit Lognormal PDF.
bool useStandardParametrization() const
RooAbsReal const & getMedian() const
Get the median parameter.
RooAbsReal const & getShapeK() const
Get the shape parameter.
RooAbsReal const & getX() const
Get the x variable.
The class RooMultiPdf allows for the creation of a RooMultiPdf object, which can switch between previ...
Definition RooMultiPdf.h:9
const RooCategoryProxy & indexCategory() const
Definition RooMultiPdf.h:25
RooAbsPdf * getPdf(int index) const
Definition RooMultiPdf.h:31
int getNumPdfs() const
Definition RooMultiPdf.h:23
const RooListProxy & getPdfList() const
Definition RooMultiPdf.h:26
Multivariate Gaussian p.d.f.
double analyticalIntegral(Int_t code, const char *rangeName=nullptr) const override
Handle full integral here.
const RooArgList & xVec() const
const TMatrixDSym & covarianceMatrixInverse() const
const RooArgList & muVec() const
RooONNXFunc wraps an ONNX model as a RooAbsReal, allowing it to be used as a building block in likeli...
Definition RooONNXFunc.h:21
std::string outerWrapperName() const
Definition RooONNXFunc.h:37
std::size_t nInputTensors() const
Definition RooONNXFunc.h:33
RooArgList const & inputTensorList(int iTensor) const
Definition RooONNXFunc.h:34
A histogram function that assigns scale parameters to every bin.
const RooArgList & paramList() const
const RooArgList & xList() const
const RooDataHist & dataHist() const
bool relParam() const
Poisson pdf.
Definition RooPoisson.h:18
RooAbsReal const & getX() const
Get the x variable.
Definition RooPoisson.h:44
bool getProtectNegativeMean() const
Definition RooPoisson.h:41
bool getNoRounding() const
Definition RooPoisson.h:36
RooAbsReal const & getMean() const
Get the mean parameter.
Definition RooPoisson.h:47
A RooAbsReal implementing a polynomial in terms of a list of RooAbsReal coefficients.
Definition RooPolyVar.h:25
RooArgList const & coefList() const
Definition RooPolyVar.h:38
int lowestOrder() const
Definition RooPolyVar.h:39
RooAbsReal const & x() const
Definition RooPolyVar.h:37
RooPolynomial implements a polynomial p.d.f of the form.
RooAbsReal const & x() const
Get the x variable.
int lowestOrder() const
Return the order for the first coefficient in the list.
RooArgList const & coefList() const
Get the coefficient list.
Represents the product of a given set of RooAbsReal objects.
Definition RooProduct.h:29
const RooArgList & realComponents() const
Definition RooProduct.h:50
Represents the ratio of two RooAbsReal objects.
Definition RooRatio.h:21
RooAbsReal const & numerator() const
Definition RooRatio.h:34
RooAbsReal const & denominator() const
Definition RooRatio.h:35
Performs hybrid numerical/analytical integrals of RooAbsReal objects.
const RooArgSet & numIntRealVars() const
RooArgSet intVars() const
const RooAbsReal & integrand() const
const RooArgSet & numIntCatVars() const
const char * intRange() const
const RooArgList & coefList() const
const RooArgList & funcList() const
Implements a PDF constructed from a sum of functions:
const RooArgList & funcList() const
const RooArgList & funcIntListFromCache(Int_t code, const char *rangeName=nullptr) const
Collect the list of functions to be integrated from the cache.
const RooArgList & coefList() const
Variable that can be changed from the outside.
Definition RooRealVar.h:37
A RooAbsReal implementation that calculates the plain fraction of sum of RooAddPdf components from a ...
RooArgList const & variables() const
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
RooAbsPdf * getPdf(RooStringView catName) const
Return the p.d.f associated with the given index category name.
const RooAbsCategoryLValue & indexCat() const
const std::vector< int > & interpolationCodes() const
const RooListProxy & variables() const
const std::vector< double > & high() const
const std::vector< double > & low() const
Flat p.d.f.
Definition RooUniform.h:24
double analyticalIntegral(Int_t code, const char *rangeName=nullptr) const override
Implement analytical integral.
The RooWrapperPdf is a class that can be used to convert a function into a PDF.
RooAbsReal const & function() const
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:226
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2459
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
std::string makeValidVarName(std::string const &in)
void codegenImpl(RooFit::Detail::RooFixedProdPdf &arg, CodegenContext &ctx)
void functorCodegenImpl(RooArg_t &arg, RooArgList const &variables, CodegenContext &ctx)
std::string codegenIntegralImpl(RooAbsReal &arg, int code, const char *rangeName, CodegenContext &ctx)
This function defines the analytical integral translation for the class.
@ InputArguments
TMarker m
Definition textangle.C:8
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2335