Logo ROOT  
Reference Guide
RooFoamGenerator.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$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/**
18\file RooFoamGenerator.cxx
19\class RooFoamGenerator
20\ingroup Roofitcore
21
22Class RooFoamGenerator is a generic toy monte carlo generator that implement
23the TFOAM sampling technique on any positively valued function.
24The RooFoamGenerator generator is used by the various generator context
25classes to take care of generation of observables for which p.d.fs
26do not define internal methods.
27
28The foam generator reacts to the following config options:
29- nCell[123N]D
30- nSample
31- chatLevel
32Access those using:
33 myPdf->specialGeneratorConfig()->getConfigSection("RooFoamGenerator").setRealValue("nSample",1e4);
34
35\see rf902_numgenconfig.C
36**/
37
38#include "Riostream.h"
39
40#include "RooFoamGenerator.h"
41#include "RooAbsReal.h"
42#include "RooCategory.h"
43#include "RooRealVar.h"
44#include "RooDataSet.h"
45#include "RooRandom.h"
46#include "RooErrorHandler.h"
47
48#include "TString.h"
49#include "TIterator.h"
50#include "RooMsgService.h"
51#include "TClass.h"
52#include "TFoam.h"
53#include "RooTFoamBinding.h"
54#include "RooNumGenFactory.h"
55#include "RooNumGenConfig.h"
56
57#include <assert.h>
58
59using namespace std;
60
62 ;
63
64
65////////////////////////////////////////////////////////////////////////////////
66/// Register RooIntegrator1D, is parameters and capabilities with RooNumIntFactory
67
69{
70 // Register RooIntegrator1D, is parameters and capabilities with RooNumIntFactory
71 RooRealVar nSample("nSample","Number of samples per cell",200,0,1e6) ;
72 RooRealVar nCell1D("nCell1D","Number of cells for 1-dim generation",30,0,1e6) ;
73 RooRealVar nCell2D("nCell2D","Number of cells for 2-dim generation",500,0,1e6) ;
74 RooRealVar nCell3D("nCell3D","Number of cells for 3-dim generation",5000,0,1e6) ;
75 RooRealVar nCellND("nCellND","Number of cells for N-dim generation",10000,0,1e6) ;
76 RooRealVar chatLevel("chatLevel","TFOAM 'chat level' (verbosity)",0,0,2) ;
77
79 fact.storeProtoSampler(proto,RooArgSet(nSample,nCell1D,nCell2D,nCell3D,nCellND,chatLevel)) ;
80}
81
82
83
84
85////////////////////////////////////////////////////////////////////////////////
86
87RooFoamGenerator::RooFoamGenerator(const RooAbsReal &func, const RooArgSet &genVars, const RooNumGenConfig& config, bool verbose, const RooAbsReal* maxFuncVal) :
88 RooAbsNumGenerator(func,genVars,verbose,maxFuncVal)
89{
91
92 _tfoam = new TFoam("TFOAM") ;
96 switch(_realVars.getSize()) {
97 case 1:_tfoam->SetnCells((Int_t)config.getConfigSection("RooFoamGenerator").getRealValue("nCell1D")) ; break ;
98 case 2:_tfoam->SetnCells((Int_t)config.getConfigSection("RooFoamGenerator").getRealValue("nCell2D")) ; break ;
99 case 3:_tfoam->SetnCells((Int_t)config.getConfigSection("RooFoamGenerator").getRealValue("nCell3D")) ; break ;
100 default:_tfoam->SetnCells((Int_t)config.getConfigSection("RooFoamGenerator").getRealValue("nCellND")) ; break ;
101 }
102 _tfoam->SetnSampl((Int_t)config.getConfigSection("RooFoamGenerator").getRealValue("nSample")) ;
104 _tfoam->SetChat((Int_t)config.getConfigSection("RooFoamGenerator").getRealValue("chatLevel")) ;
105 _tfoam->Initialize() ;
106
107 _vec = new double[_realVars.getSize()] ;
108 _xmin = new double[_realVars.getSize()] ;
109 _range = new double[_realVars.getSize()] ;
110
111 Int_t i(0) ;
112 for (const auto arg : _realVars) {
113 auto var = static_cast<const RooRealVar*>(arg);
114 _xmin[i] = var->getMin() ;
115 _range[i] = var->getMax() - var->getMin() ;
116 i++ ;
117 }
118}
119
120
121////////////////////////////////////////////////////////////////////////////////
122/// Destructor
123
125{
126 delete[] _vec ;
127 delete[] _xmin ;
128 delete[] _range ;
129 delete _tfoam ;
130 delete _binding ;
131}
132
133
134
135////////////////////////////////////////////////////////////////////////////////
136/// are we actually generating anything? (the cache always contains at least our function value)
137
138const RooArgSet *RooFoamGenerator::generateEvent(UInt_t /*remaining*/, double& /*resampleRatio*/)
139{
140 const RooArgSet *event= _cache->get();
141 if(event->getSize() == 1) return event;
142
143 _tfoam->MakeEvent() ;
145
146 // Transfer contents to dataset
147 Int_t i(0) ;
148 for (auto arg : _realVars) {
149 auto var = static_cast<RooRealVar*>(arg);
150 var->setVal(_xmin[i] + _range[i]*_vec[i]) ;
151 i++ ;
152 }
153 return &_realVars ;
154}
#define ClassImp(name)
Definition: Rtypes.h:375
const char * proto
Definition: civetweb.c:17493
Int_t getSize() const
Return the number of elements in the collection.
double getRealValue(const char *name, double defVal=0, bool verbose=false) const
Get value of a RooAbsReal stored in set with given name.
Class RooAbsNumGenerator is the abstract base class for MC event generator implementations like RooAc...
RooArgSet _realVars
Sets of discrete and real valued observabeles.
RooDataSet * _cache
Dataset holding generared values of observables.
RooAbsReal * _funcClone
Pointer to top level node of cloned function.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:64
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:57
const RooArgSet * get(Int_t index) const override
Return RooArgSet with coordinates of event 'index'.
Class RooFoamGenerator is a generic toy monte carlo generator that implement the TFOAM sampling techn...
const RooArgSet * generateEvent(UInt_t remaining, double &resampleRatio) override
are we actually generating anything? (the cache always contains at least our function value)
double * _range
Range of observables to be generated ;.
~RooFoamGenerator() override
Destructor.
RooTFoamBinding * _binding
Binding of RooAbsReal to TFoam function interface.
double * _xmin
Lower bound of observables to be generated ;.
TFoam * _tfoam
Instance of TFOAM generator.
static void registerSampler(RooNumGenFactory &fact)
Register RooIntegrator1D, is parameters and capabilities with RooNumIntFactory.
double * _vec
Transfer array for FOAM output.
RooNumGenConfig holds the configuration parameters of the various numeric integrators used by RooReal...
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
RooNumGenFactory is a factory to instantiate numeric integrators from a given function binding and a ...
bool storeProtoSampler(RooAbsNumGenerator *proto, const RooArgSet &defConfig)
Method accepting registration of a prototype numeric integrator along with a RooArgSet of its default...
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition: RooRandom.cxx:51
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
void setVal(double value) override
Set value of variable to 'value'.
Definition: RooRealVar.cxx:281
Lightweight interface adaptor that binds a RooAbsPdf to TFOAM.
TFoam is the main class of the multi-dimensional general purpose Monte Carlo event generator (integra...
Definition: TFoam.h:21
virtual void GetMCvect(Double_t *)
User may get generated MC point/vector with help of this method.
Definition: TFoam.cxx:1174
virtual void MakeEvent()
User method.
Definition: TFoam.cxx:1124
virtual void Initialize()
Basic initialization of FOAM invoked by the user.
Definition: TFoam.cxx:323
virtual void SetnSampl(Long_t nSampl)
Definition: TFoam.h:117
virtual void SetChat(Int_t Chat)
Definition: TFoam.h:119
virtual void SetnCells(Long_t nCells)
Definition: TFoam.h:116
virtual void SetRho(TFoamIntegrand *Rho)
User may use this method to set the distribution object.
Definition: TFoam.cxx:1020
virtual void SetPseRan(TRandom *PseRan)
Definition: TFoam.h:112
virtual void SetkDim(Int_t kDim)
Definition: TFoam.h:115