Logo ROOT   6.14/05
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 }
virtual Double_t getMin(const char *name=0) const
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
void generateEvent(Int_t code)
Implement internal generator.
Definition: RooUniform.cxx:127
virtual Double_t getMax(const char *name=0) const
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:86
virtual void randomize(const char *rangeName=0)
Set a new value sampled from a uniform distribution over the fit range.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
STL namespace.
#define coutW(a)
Definition: RooMsgService.h:33
Int_t getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char *rangeName=0) const
Advertise analytical integral.
Definition: RooUniform.cxx:65
Double_t x[n]
Definition: legend1.C:17
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
Double_t analyticalIntegral(Int_t code, const char *rangeName=0) const
Implement analytical integral.
Definition: RooUniform.cxx:88
Int_t getSize() const
RooListProxy x
Definition: RooUniform.h:40
RooAbsArg * at(Int_t idx) const
Definition: RooArgList.h:84
Double_t evaluate() const
Definition: RooUniform.cxx:57
Flat p.d.f.
Definition: RooUniform.h:24
const Bool_t kFALSE
Definition: RtypesCore.h:88
#define ClassImp(name)
Definition: Rtypes.h:359
RooAbsArg * find(const char *name) const
Find object with given name in list.
double Double_t
Definition: RtypesCore.h:55
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
const Bool_t kTRUE
Definition: RtypesCore.h:87
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, Bool_t staticInitOK=kTRUE) const
Advertise internal generator.
Definition: RooUniform.cxx:103
char name[80]
Definition: TGX11.cxx:109