Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "RooMsgService.h"
29#include "RooRealVar.h"
30#include "RooTrace.h"
31#include "RooBatchCompute.h"
32
33#include "TMath.h"
34
35#include <math.h>
36
38
40
41RooRatio::RooRatio(const char *name, const char *title, RooAbsReal &nr,
42 RooAbsReal &dr)
43 : RooAbsReal(name, title), _numerator("numerator", "numerator", this, nr),
44 _denominator("denominator", "denominator", this, dr){TRACE_CREATE}
45
46 RooRatio::RooRatio(const char *name, const char *title, RooAbsReal &nr,
47 double dr)
48 : RooAbsReal(name, title), _numerator("numerator", "numerator", this, nr),
49 _denominator("denominator", "denominator", this) {
50 auto drvar = new RooRealVar(Form("%s_dr", name), Form("%s_dr", name), dr);
51 _denominator.setArg(*drvar);
54}
55
56RooRatio::RooRatio(const char *name, const char *title, double nr,
57 RooAbsReal &dr)
58 : RooAbsReal(name, title), _numerator("numerator", "numerator", this),
59 _denominator("denominator", "denominator", this, dr) {
60 auto nrvar = new RooRealVar(Form("%s_nr", name), Form("%s_nr", name), nr);
61 _numerator.setArg(*nrvar);
64}
65
66RooRatio::RooRatio(const char *name, const char *title, double nr,
67 double dr)
68 : RooAbsReal(name, title), _numerator("numerator", "numerator", this),
69 _denominator("denominator", "denominator", this) {
70 auto nrvar = new RooRealVar(Form("%s_nr", name), Form("%s_nr", name), nr);
71 auto drvar = new RooRealVar(Form("%s_dr", name), Form("%s_dr", name), dr);
72 _numerator.setArg(*nrvar);
73 _denominator.setArg(*drvar);
74 addOwnedComponents(RooArgSet(*nrvar, *drvar));
76}
77
78RooRatio::RooRatio(const char *name, const char *title,
79 const RooArgList &nrlist, const RooArgList &drlist)
80 : RooAbsReal(name, title), _numerator("numerator", "numerator", this),
81 _denominator("denominator", "denominator", this) {
82 auto nrprod =
83 new RooProduct(Form("%s_nr", name), Form("%s_nr", name), nrlist);
84 auto drprod =
85 new RooProduct(Form("%s_dr", name), Form("%s_dr", name), drlist);
86 _numerator.setArg(*nrprod);
87 _denominator.setArg(*drprod);
88 addOwnedComponents(RooArgSet(*nrprod, *drprod));
90}
91
93
94RooRatio::RooRatio(const RooRatio &other, const char *name)
95 : RooAbsReal(other, name), _numerator("numerator", this, other._numerator),
96 _denominator("denominator", this, other._denominator){TRACE_CREATE}
97
98 double RooRatio::evaluate() const {
99
100 if (_denominator == 0.0) {
101 if (_numerator == 0.0)
102 return std::numeric_limits<double>::quiet_NaN();
103 else
104 return (_numerator > 0.0) ? RooNumber::infinity()
105 : -1.0 * RooNumber::infinity();
106 } else
107 return _numerator / _denominator;
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// Evaluate in batch mode.
112void RooRatio::computeBatch(cudaStream_t* stream, double* output, size_t nEvents, RooFit::Detail::DataMap const& dataMap) const
113{
115 dispatch->compute(stream, RooBatchCompute::Ratio, output, nEvents, {dataMap.at(_numerator), dataMap.at(_denominator)});
116}
#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:2467
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:62
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
virtual void compute(cudaStream_t *, Computer, RestrictArr, size_t, const VarVector &, ArgVector &)=0
RooSpan< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
Definition DataMap.cxx:21
static constexpr double infinity()
Return internal infinity representation.
Definition RooNumber.h:24
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
void computeBatch(cudaStream_t *, double *output, size_t nEvents, RooFit::Detail::DataMap const &) const override
Evaluate in batch mode.
Definition RooRatio.cxx:112
RooRealProxy _numerator
Definition RooRatio.h:55
~RooRatio() override
Definition RooRatio.cxx:92
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition RooRatio.cxx:98
RooRealProxy _denominator
Definition RooRatio.h:56
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
R__EXTERN RooBatchComputeInterface * dispatchCPU
This dispatch pointer points to an implementation of the compute library, provided one has been loade...
static void output()