Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooRatio.cxx
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Author:
4 * Rahul Balasubramanian, Nikhef 01 Apr 2021
5 *
6 * Copyright (c) 2023, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
13/**
14\file RooRatio.cxx
15\class RooRatio
16\ingroup Roofitcore
17
18Represents the ratio of two RooAbsReal objects.
19
20**/
21
22#include <RooRatio.h>
23
24#include <RooBatchCompute.h>
25#include <RooMsgService.h>
26#include <RooProduct.h>
27#include <RooRealVar.h>
28#include <RooTrace.h>
29
31
32#include <Riostream.h>
33
34#include <TMath.h>
35
36#include <cmath>
37
39
41{
43}
44
45RooRatio::RooRatio(const char *name, const char *title, RooAbsReal &nr, RooAbsReal &dr)
46 : RooAbsReal(name, title),
47 _numerator("numerator", "numerator", this, nr),
48 _denominator("denominator", "denominator", this, dr)
49{
51}
52
53RooRatio::RooRatio(const char *name, const char *title, RooAbsReal &nr, double dr)
54 : RooAbsReal(name, title),
55 _numerator("numerator", "numerator", this, nr),
56 _denominator("denominator", "denominator", this)
57{
58 auto drvar = new RooRealVar(Form("%s_dr", name), Form("%s_dr", name), dr);
59 _denominator.setArg(*drvar);
62}
63
64RooRatio::RooRatio(const char *name, const char *title, double nr, RooAbsReal &dr)
65 : RooAbsReal(name, title),
66 _numerator("numerator", "numerator", this),
67 _denominator("denominator", "denominator", this, dr)
68{
69 auto nrvar = new RooRealVar(Form("%s_nr", name), Form("%s_nr", name), nr);
70 _numerator.setArg(*nrvar);
73}
74
75RooRatio::RooRatio(const char *name, const char *title, double nr, double dr)
76 : RooAbsReal(name, title),
77 _numerator("numerator", "numerator", this),
78 _denominator("denominator", "denominator", this)
79{
80 auto nrvar = new RooRealVar(Form("%s_nr", name), Form("%s_nr", name), nr);
81 auto drvar = new RooRealVar(Form("%s_dr", name), Form("%s_dr", name), dr);
82 _numerator.setArg(*nrvar);
83 _denominator.setArg(*drvar);
84 addOwnedComponents(RooArgSet(*nrvar, *drvar));
86}
87
88RooRatio::RooRatio(const char *name, const char *title, const RooArgList &nrlist, const RooArgList &drlist)
89 : RooAbsReal(name, title),
90 _numerator("numerator", "numerator", this),
91 _denominator("denominator", "denominator", this)
92{
93 auto nrprod = new RooProduct(Form("%s_nr", name), Form("%s_nr", name), nrlist);
94 auto drprod = new RooProduct(Form("%s_dr", name), Form("%s_dr", name), drlist);
95 _numerator.setArg(*nrprod);
96 _denominator.setArg(*drprod);
97 addOwnedComponents(RooArgSet(*nrprod, *drprod));
99}
100
102{
104}
105
106RooRatio::RooRatio(const RooRatio &other, const char *name)
107 : RooAbsReal(other, name),
108 _numerator("numerator", this, other._numerator),
109 _denominator("denominator", this, other._denominator)
110{
112}
113
114double RooRatio::evaluate() const
115{
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// Evaluate in batch mode.
122{
124 {ctx.at(_numerator), ctx.at(_denominator)});
125}
126
128{
129 ctx.addResult(this, ctx.buildCall("RooFit::Detail::MathFuncs::ratio", _numerator, _denominator));
130}
#define TRACE_DESTROY
Definition RooTrace.h:24
#define TRACE_CREATE
Definition RooTrace.h:23
#define ClassImp(name)
Definition Rtypes.h:377
char name[80]
Definition TGX11.cxx:110
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
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:55
A class to maintain the context for squashing of RooFit models into code.
std::string buildCall(std::string const &funcname, Args_t const &...args)
Build the code to call the function with name funcname, passing some arguments.
void addResult(RooAbsArg const *key, std::string const &value)
A function to save an expression that includes/depends on the result of the input node.
std::span< double > output()
RooBatchCompute::Config config(RooAbsArg const *arg) const
Represents the product of a given set of RooAbsReal objects.
Definition RooProduct.h:29
Represents the ratio of two RooAbsReal objects.
Definition RooRatio.h:21
RooRealProxy _numerator
Definition RooRatio.h:41
~RooRatio() override
Definition RooRatio.cxx:101
void translate(RooFit::Detail::CodeSquashContext &ctx) const override
This function defines a translation for each RooAbsReal based object that can be used to express the ...
Definition RooRatio.cxx:127
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition RooRatio.cxx:114
void doEval(RooFit::EvalContext &) const override
Evaluate in batch mode.
Definition RooRatio.cxx:121
RooRealProxy _denominator
Definition RooRatio.h:42
Variable that can be changed from the outside.
Definition RooRealVar.h:37
bool setArg(T &newRef)
Change object held in proxy into newRef.
void compute(Config cfg, Computer comp, std::span< double > output, VarSpan vars, ArgSpan extraArgs={})
double ratio(double numerator, double denominator)
Definition MathFuncs.h:94