Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooUniform.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitModels *
4 * @(#)root/roofit:$Id$
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-2005, 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/** \class RooUniform
18 \ingroup Roofit
19
20Flat p.d.f. in N dimensions
21**/
22
23#include "RooArgSet.h"
24#include "RooRealVar.h"
25#include "RooUniform.h"
26
27
29
30////////////////////////////////////////////////////////////////////////////////
31
32RooUniform::RooUniform(const char *name, const char *title, const RooArgSet& _x) :
33 RooAbsPdf(name,title),
34 x("x","Observables",this,true,false)
35{
36 x.add(_x) ;
37}
38
39////////////////////////////////////////////////////////////////////////////////
40
41RooUniform::RooUniform(const RooUniform& other, const char* name) :
42 RooAbsPdf(other,name), x("x",this,other.x)
43{
44}
45
46////////////////////////////////////////////////////////////////////////////////
47
49{
50 return 1 ;
51}
52
54{
55 ctx.addResult(this, "1.0");
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// Advertise analytical integral
60
61Int_t RooUniform::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const
62{
63 Int_t nx = x.size() ;
64 if (nx>31) {
65 // Warn that analytical integration is only provided for the first 31 observables
66 coutW(Integration) << "RooUniform::getAnalyticalIntegral(" << GetName() << ") WARNING: p.d.f. has " << x.size()
67 << " observables, analytical integration is only implemented for the first 31 observables" << std::endl ;
68 nx=31 ;
69 }
70
71 Int_t code(0) ;
72 for (std::size_t i=0 ; i<x.size() ; i++) {
73 if (allVars.find(x.at(i)->GetName())) {
74 code |= (1<<i) ;
75 analVars.add(*allVars.find(x.at(i)->GetName())) ;
76 }
77 }
78 return code ;
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// Implement analytical integral
83
84double RooUniform::analyticalIntegral(Int_t code, const char* rangeName) const
85{
86 double ret(1) ;
87 for (int i=0 ; i<32 ; i++) {
88 if (code&(1<<i)) {
89 RooAbsRealLValue* var = static_cast<RooAbsRealLValue*>(x.at(i)) ;
90 ret *= (var->getMax(rangeName) - var->getMin(rangeName)) ;
91 }
92 }
93 return ret ;
94}
95
96std::string RooUniform::buildCallToAnalyticIntegral(Int_t code, const char *rangeName,
98{
99 // The integral of a uniform distribution is static, so we can just hardcode
100 // the result in a string.
101 return std::to_string(analyticalIntegral(code, rangeName));
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// Advertise internal generator
106
107Int_t RooUniform::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, bool /*staticInitOK*/) const
108{
109 Int_t nx = x.size() ;
110 if (nx>31) {
111 // Warn that analytical integration is only provided for the first 31 observables
112 coutW(Integration) << "RooUniform::getGenerator(" << GetName() << ") WARNING: p.d.f. has " << x.size()
113 << " observables, internal integrator is only implemented for the first 31 observables" << std::endl ;
114 nx=31 ;
115 }
116
117 Int_t code(0) ;
118 for (std::size_t i=0 ; i<x.size() ; i++) {
119 if (directVars.find(x.at(i)->GetName())) {
120 code |= (1<<i) ;
121 generateVars.add(*directVars.find(x.at(i)->GetName())) ;
122 }
123 }
124 return code ;
125}
126
127////////////////////////////////////////////////////////////////////////////////
128/// Implement internal generator
129
131{
132 // Fast-track handling of one-observable case
133 if (code==1) {
134 (static_cast<RooAbsRealLValue*>(x.at(0)))->randomize() ;
135 return ;
136 }
137
138 for (int i=0 ; i<32 ; i++) {
139 if (code&(1<<i)) {
140 RooAbsRealLValue* var = static_cast<RooAbsRealLValue*>(x.at(i)) ;
141 var->randomize() ;
142 }
143 }
144}
#define coutW(a)
#define ClassImp(name)
Definition Rtypes.h:382
char name[80]
Definition TGX11.cxx:110
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
void randomize(const char *rangeName=nullptr) override
Set a new value sampled from a uniform distribution over the fit range.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition RooArgList.h:110
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
A class to maintain the context for squashing of RooFit models into code.
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.
Flat p.d.f.
Definition RooUniform.h:24
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=nullptr) const override
Advertise analytical integral.
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
std::string buildCallToAnalyticIntegral(Int_t code, const char *rangeName, RooFit::Detail::CodeSquashContext &ctx) const override
This function defines the analytical integral translation for the class.
double analyticalIntegral(Int_t code, const char *rangeName=nullptr) const override
Implement analytical integral.
RooListProxy x
Definition RooUniform.h:43
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, bool staticInitOK=true) const override
Advertise internal generator.
void generateEvent(Int_t code) override
Implement internal generator.
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 ...
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Double_t x[n]
Definition legend1.C:17