Logo ROOT   6.16/01
Reference Guide
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 "RooFit.h"
24
25#include "Riostream.h"
26#include <math.h>
27
28#include "RooUniform.h"
29#include "RooAbsReal.h"
30#include "RooRealVar.h"
31#include "RooRandom.h"
32#include "RooMath.h"
33#include "RooArgSet.h"
34
35using namespace std;
36
38
39////////////////////////////////////////////////////////////////////////////////
40
41RooUniform::RooUniform(const char *name, const char *title, const RooArgSet& _x) :
42 RooAbsPdf(name,title),
43 x("x","Observables",this,kTRUE,kFALSE)
44{
45 x.add(_x) ;
46}
47
48////////////////////////////////////////////////////////////////////////////////
49
50RooUniform::RooUniform(const RooUniform& other, const char* name) :
51 RooAbsPdf(other,name), x("x",this,other.x)
52{
53}
54
55////////////////////////////////////////////////////////////////////////////////
56
58{
59 return 1 ;
60}
61
62////////////////////////////////////////////////////////////////////////////////
63/// Advertise analytical integral
64
65Int_t RooUniform::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const
66{
67 Int_t nx = x.getSize() ;
68 if (nx>31) {
69 // Warn that analytical integration is only provided for the first 31 observables
70 coutW(Integration) << "RooUniform::getAnalyticalIntegral(" << GetName() << ") WARNING: p.d.f. has " << x.getSize()
71 << " observables, analytical integration is only implemented for the first 31 observables" << endl ;
72 nx=31 ;
73 }
74
75 Int_t code(0) ;
76 for (int i=0 ; i<x.getSize() ; i++) {
77 if (allVars.find(x.at(i)->GetName())) {
78 code |= (1<<i) ;
79 analVars.add(*allVars.find(x.at(i)->GetName())) ;
80 }
81 }
82 return code ;
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// Implement analytical integral
87
88Double_t RooUniform::analyticalIntegral(Int_t code, const char* rangeName) const
89{
90 Double_t ret(1) ;
91 for (int i=0 ; i<32 ; i++) {
92 if (code&(1<<i)) {
94 ret *= (var->getMax(rangeName) - var->getMin(rangeName)) ;
95 }
96 }
97 return ret ;
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Advertise internal generator
102
103Int_t RooUniform::getGenerator(const RooArgSet& directVars, RooArgSet &generateVars, Bool_t /*staticInitOK*/) const
104{
105 Int_t nx = x.getSize() ;
106 if (nx>31) {
107 // Warn that analytical integration is only provided for the first 31 observables
108 coutW(Integration) << "RooUniform::getGenerator(" << GetName() << ") WARNING: p.d.f. has " << x.getSize()
109 << " observables, internal integrator is only implemented for the first 31 observables" << endl ;
110 nx=31 ;
111 }
112
113 Int_t code(0) ;
114 for (int i=0 ; i<x.getSize() ; i++) {
115 if (directVars.find(x.at(i)->GetName())) {
116 code |= (1<<i) ;
117 generateVars.add(*directVars.find(x.at(i)->GetName())) ;
118 }
119 }
120 return code ;
121 return 0 ;
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Implement internal generator
126
128{
129 // Fast-track handling of one-observable case
130 if (code==1) {
131 ((RooAbsRealLValue*)x.at(0))->randomize() ;
132 return ;
133 }
134
135 for (int i=0 ; i<32 ; i++) {
136 if (code&(1<<i)) {
138 var->randomize() ;
139 }
140 }
141}
#define coutW(a)
Definition: RooMsgService.h:33
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:363
Int_t getSize() const
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual Double_t getMax(const char *name=0) const
virtual void randomize(const char *rangeName=0)
Set a new value sampled from a uniform distribution over the fit range.
virtual Double_t getMin(const char *name=0) const
RooAbsArg * at(Int_t idx) const
Definition: RooArgList.h:84
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:88
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
Flat p.d.f.
Definition: RooUniform.h:24
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
Advertise analytical integral.
Definition: RooUniform.cxx:65
Double_t analyticalIntegral(Int_t code, const char *rangeName=0) const
Implement analytical integral.
Definition: RooUniform.cxx:88
void generateEvent(Int_t code)
Implement internal generator.
Definition: RooUniform.cxx:127
Double_t evaluate() const
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition: RooUniform.cxx:57
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, Bool_t staticInitOK=kTRUE) const
Advertise internal generator.
Definition: RooUniform.cxx:103
RooListProxy x
Definition: RooUniform.h:40
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Double_t x[n]
Definition: legend1.C:17
@ Integration
Definition: RooGlobalFunc.h:57
STL namespace.