Logo ROOT  
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 
20 Flat 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 
35 using namespace std;
36 
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 
41 RooUniform::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 
50 RooUniform::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 
65 Int_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 
88 Double_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 
103 Int_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)) {
137  RooAbsRealLValue* var = (RooAbsRealLValue*)x.at(i) ;
138  var->randomize() ;
139  }
140  }
141 }
RooUniform
Definition: RooUniform.h:24
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooAbsReal.h
RooAbsRealLValue::getMax
virtual Double_t getMax(const char *name=0) const
Get maximum of currently defined range.
Definition: RooAbsRealLValue.h:83
RooFit.h
RooArgSet.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
coutW
#define coutW(a)
Definition: RooMsgService.h:32
RooAbsCollection::find
RooAbsArg * find(const char *name) const
Find object with given name in list.
Definition: RooAbsCollection.cxx:813
x
Double_t x[n]
Definition: legend1.C:17
RooArgSet::add
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
RooArgList::at
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition: RooArgList.h:88
bool
RooAbsRealLValue::getMin
virtual Double_t getMin(const char *name=0) const
Get miniminum of currently defined range.
Definition: RooAbsRealLValue.h:80
RooUniform::getAnalyticalIntegral
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
Advertise analytical integral.
Definition: RooUniform.cxx:65
RooUniform::analyticalIntegral
Double_t analyticalIntegral(Int_t code, const char *rangeName=0) const
Implement analytical integral.
Definition: RooUniform.cxx:88
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooRandom.h
RooUniform::x
RooListProxy x
Definition: RooUniform.h:40
RooUniform::getGenerator
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, Bool_t staticInitOK=kTRUE) const
Advertise internal generator.
Definition: RooUniform.cxx:103
RooListProxy::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
Definition: RooListProxy.cxx:104
RooRealVar.h
RooUniform::evaluate
Double_t evaluate() const
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
Definition: RooUniform.cxx:57
Double_t
double Double_t
Definition: RtypesCore.h:59
RooUniform::RooUniform
RooUniform()
Definition: RooUniform.h:26
RooUniform::generateEvent
void generateEvent(Int_t code)
Implement internal generator.
Definition: RooUniform.cxx:127
name
char name[80]
Definition: TGX11.cxx:110
RooAbsRealLValue::randomize
virtual void randomize(const char *rangeName=0)
Set a new value sampled from a uniform distribution over the fit range.
Definition: RooAbsRealLValue.cxx:413
RooAbsPdf
Definition: RooAbsPdf.h:40
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
RooFit::Integration
@ Integration
Definition: RooGlobalFunc.h:67
Riostream.h
RooAbsRealLValue
Definition: RooAbsRealLValue.h:31
RooMath.h
RooAbsCollection::getSize
Int_t getSize() const
Definition: RooAbsCollection.h:171
RooUniform.h
RooArgSet
Definition: RooArgSet.h:28
int