Logo ROOT  
Reference Guide
RooRatio.cxx
Go to the documentation of this file.
1// Author: Rahul Balasubramanian, Nikhef 01 Apr 2021
2
3/*****************************************************************************
4 * RooFit
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2019, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17/**
18\file RooRatio.cxx
19\class RooRatio
20\ingroup Roofitcore
21
22A RooRatio represents the ratio of two given RooAbsReal objects.
23
24**/
25
26#include "RooRatio.h"
27#include "Riostream.h"
28#include "RooAbsArg.h"
29#include "RooMsgService.h"
30#include "RooRealVar.h"
31#include "RooTrace.h"
32#include "RooBatchCompute.h"
33
34#include "TMath.h"
35
36#include <math.h>
37
39
41
42RooRatio::RooRatio(const char *name, const char *title, RooAbsReal &nr,
43 RooAbsReal &dr)
44 : RooAbsReal(name, title), _numerator("numerator", "numerator", this, nr),
45 _denominator("denominator", "denominator", this, dr){TRACE_CREATE}
46
47 RooRatio::RooRatio(const char *name, const char *title, RooAbsReal &nr,
48 Double_t dr)
49 : RooAbsReal(name, title), _numerator("numerator", "numerator", this, nr),
50 _denominator("denominator", "denominator", this) {
51 auto drvar = new RooRealVar(Form("%s_dr", name), Form("%s_dr", name), dr);
52 _denominator.setArg(*drvar);
55}
56
57RooRatio::RooRatio(const char *name, const char *title, Double_t nr,
58 RooAbsReal &dr)
59 : RooAbsReal(name, title), _numerator("numerator", "numerator", this),
60 _denominator("denominator", "denominator", this, dr) {
61 auto nrvar = new RooRealVar(Form("%s_nr", name), Form("%s_nr", name), nr);
62 _numerator.setArg(*nrvar);
65}
66
67RooRatio::RooRatio(const char *name, const char *title, Double_t nr,
68 Double_t dr)
69 : RooAbsReal(name, title), _numerator("numerator", "numerator", this),
70 _denominator("denominator", "denominator", this) {
71 auto nrvar = new RooRealVar(Form("%s_nr", name), Form("%s_nr", name), nr);
72 auto drvar = new RooRealVar(Form("%s_dr", name), Form("%s_dr", name), dr);
73 _numerator.setArg(*nrvar);
74 _denominator.setArg(*drvar);
75 addOwnedComponents(RooArgSet(*nrvar, *drvar));
77}
78
79RooRatio::RooRatio(const char *name, const char *title,
80 const RooArgList &nrlist, const RooArgList &drlist)
81 : RooAbsReal(name, title), _numerator("numerator", "numerator", this),
82 _denominator("denominator", "denominator", this) {
83 auto nrprod =
84 new RooProduct(Form("%s_nr", name), Form("%s_nr", name), nrlist);
85 auto drprod =
86 new RooProduct(Form("%s_dr", name), Form("%s_dr", name), drlist);
87 _numerator.setArg(*nrprod);
88 _denominator.setArg(*drprod);
89 addOwnedComponents(RooArgSet(*nrprod, *drprod));
91}
92
94
95RooRatio::RooRatio(const RooRatio &other, const char *name)
96 : RooAbsReal(other, name), _numerator("numerator", this, other._numerator),
97 _denominator("denominator", this, other._denominator){TRACE_CREATE}
98
100
101 if (_denominator == 0.0) {
102 if (_numerator == 0.0)
103 return std::numeric_limits<double>::quiet_NaN();
104 else
105 return (_numerator > 0.0) ? RooNumber::infinity()
106 : -1.0 * RooNumber::infinity();
107 } else
108 return _numerator / _denominator;
109}
110
111////////////////////////////////////////////////////////////////////////////////
112/// Evaluate in batch mode.
113void RooRatio::computeBatch(cudaStream_t* stream, double* output, size_t nEvents, RooBatchCompute::DataMap& dataMap) const
114{
116 dispatch->compute(stream, RooBatchCompute::Ratio, output, nEvents, dataMap, {&*_numerator, &*_denominator});
117}
#define TRACE_DESTROY
Definition: RooTrace.h:24
#define TRACE_CREATE
Definition: RooTrace.h:23
#define ClassImp(name)
Definition: Rtypes.h:375
char name[80]
Definition: TGX11.cxx:110
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition: TString.cxx:2447
friend class RooArgSet
Definition: RooAbsArg.h:651
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
Definition: RooAbsArg.cxx:2275
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:63
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:22
virtual void compute(cudaStream_t *, Computer, RestrictArr, size_t, const DataMap &, const VarVector &, const ArgVector &={})=0
static Double_t infinity()
Return internal infinity representation.
Definition: RooNumber.cxx:48
A RooProduct represents the product of a given set of RooAbsReal objects.
Definition: RooProduct.h:29
A RooRatio represents the ratio of two given RooAbsReal objects.
Definition: RooRatio.h:30
Double_t evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition: RooRatio.cxx:99
RooRealProxy _numerator
Definition: RooRatio.h:55
~RooRatio() override
Definition: RooRatio.cxx:93
RooRatio()
Definition: RooRatio.cxx:40
RooRealProxy _denominator
Definition: RooRatio.h:56
void computeBatch(cudaStream_t *, double *output, size_t nEvents, RooBatchCompute::DataMap &) const override
Evaluate in batch mode.
Definition: RooRatio.cxx:113
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
bool setArg(T &newRef)
Change object held in proxy into newRef.
R__EXTERN RooBatchComputeInterface * dispatchCUDA
std::map< DataKey, RooSpan< const double > > DataMap
R__EXTERN RooBatchComputeInterface * dispatchCPU
This dispatch pointer points to an implementation of the compute library, provided one has been loade...
static void output()