ROOT  6.06/09
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 //
19 // BEGIN_HTML
20 // Class RooFoamGenerator is a generic toy monte carlo generator that implement
21 // the TFOAM sampling technique on any positively valued function.
22 // The RooFoamGenerator generator is used by the various generator context
23 // classes to take care of generation of observables for which p.d.fs
24 // do not define internal methods
25 // END_HTML
26 //
27 
28 
29 #include "RooFit.h"
30 #include "Riostream.h"
31 
32 #include "RooFoamGenerator.h"
33 #include "RooAbsReal.h"
34 #include "RooCategory.h"
35 #include "RooRealVar.h"
36 #include "RooDataSet.h"
37 #include "RooRandom.h"
38 #include "RooErrorHandler.h"
39 
40 #include "TString.h"
41 #include "TIterator.h"
42 #include "RooMsgService.h"
43 #include "TClass.h"
44 #include "TFoam.h"
45 #include "RooTFoamBinding.h"
46 #include "RooNumGenFactory.h"
47 #include "RooNumGenConfig.h"
48 
49 #include <assert.h>
50 
51 using namespace std;
52 
54  ;
55 
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// Register RooIntegrator1D, is parameters and capabilities with RooNumIntFactory
59 
61 {
62  // Register RooIntegrator1D, is parameters and capabilities with RooNumIntFactory
63  RooRealVar nSample("nSample","Number of samples per cell",200,0,1e6) ;
64  RooRealVar nCell1D("nCell1D","Number of cells for 1-dim generation",30,0,1e6) ;
65  RooRealVar nCell2D("nCell2D","Number of cells for 2-dim generation",500,0,1e6) ;
66  RooRealVar nCell3D("nCell3D","Number of cells for 3-dim generation",5000,0,1e6) ;
67  RooRealVar nCellND("nCellND","Number of cells for N-dim generation",10000,0,1e6) ;
68  RooRealVar chatLevel("chatLevel","TFOAM 'chat level' (verbosity)",0,0,2) ;
69 
70  RooFoamGenerator* proto = new RooFoamGenerator ;
71  fact.storeProtoSampler(proto,RooArgSet(nSample,nCell1D,nCell2D,nCell3D,nCellND,chatLevel)) ;
72 }
73 
74 
75 
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 
79 RooFoamGenerator::RooFoamGenerator(const RooAbsReal &func, const RooArgSet &genVars, const RooNumGenConfig& config, Bool_t verbose, const RooAbsReal* maxFuncVal) :
80  RooAbsNumGenerator(func,genVars,verbose,maxFuncVal)
81 {
84 
85  _tfoam = new TFoam("TFOAM") ;
89  switch(_realVars.getSize()) {
90  case 1:_tfoam->SetnCells((Int_t)config.getConfigSection("RooFoamGenerator").getRealValue("nCell1D")) ; break ;
91  case 2:_tfoam->SetnCells((Int_t)config.getConfigSection("RooFoamGenerator").getRealValue("nCell2D")) ; break ;
92  case 3:_tfoam->SetnCells((Int_t)config.getConfigSection("RooFoamGenerator").getRealValue("nCell3D")) ; break ;
93  default:_tfoam->SetnCells((Int_t)config.getConfigSection("RooFoamGenerator").getRealValue("nCellND")) ; break ;
94  }
95  _tfoam->SetnSampl((Int_t)config.getConfigSection("RooFoamGenerator").getRealValue("nSample")) ;
97  _tfoam->SetChat((Int_t)config.getConfigSection("RooFoamGenerator").getRealValue("chatLevel")) ;
98  _tfoam->Initialize() ;
99 
100  _vec = new Double_t[_realVars.getSize()] ;
101  _xmin = new Double_t[_realVars.getSize()] ;
102  _range = new Double_t[_realVars.getSize()] ;
103 
105  RooRealVar* var ;
106  Int_t i(0) ;
107  while((var=(RooRealVar*)iter->Next())) {
108  _xmin[i] = var->getMin() ;
109  _range[i] = var->getMax() - var->getMin() ;
110  i++ ;
111  }
112  delete iter ;
113 
114 }
115 
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 /// Destructor
119 
121 {
122  delete[] _vec ;
123  delete[] _xmin ;
124  delete[] _range ;
125  delete _tfoam ;
126  delete _binding ;
127  delete _rvIter ;
128 }
129 
130 
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// are we actually generating anything? (the cache always contains at least our function value)
134 
135 const RooArgSet *RooFoamGenerator::generateEvent(UInt_t /*remaining*/, Double_t& /*resampleRatio*/)
136 {
137  const RooArgSet *event= _cache->get();
138  if(event->getSize() == 1) return event;
139 
140  _tfoam->MakeEvent() ;
141  _tfoam->GetMCvect(_vec) ;
142 
143  // Transfer contents to dataset
144  RooRealVar* var ;
145  _rvIter->Reset() ;
146  Int_t i(0) ;
147  while((var=(RooRealVar*)_rvIter->Next())) {
148  var->setVal(_xmin[i] + _range[i]*_vec[i]) ;
149  i++ ;
150  }
151  return &_realVars ;
152 }
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
virtual void Reset()=0
const RooArgSet * generateEvent(UInt_t remaining, Double_t &resampleRatio)
are we actually generating anything? (the cache always contains at least our function value) ...
RooTFoamBinding * _binding
virtual Double_t getMin(const char *name=0) const
int Int_t
Definition: RtypesCore.h:41
virtual void MakeEvent()
User subprogram.
Definition: TFoam.cxx:1183
bool Bool_t
Definition: RtypesCore.h:59
virtual void SetChat(Int_t Chat)
Definition: TFoam.h:131
STL namespace.
Iterator abstract base class.
Definition: TIterator.h:32
virtual ~RooFoamGenerator()
Destructor.
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
TIterator * createIterator(Bool_t dir=kIterForward) const
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition: RooRandom.cxx:53
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:202
ClassImp(RooFoamGenerator)
virtual void GetMCvect(Double_t *)
User may get generated MC point/vector with help of this method.
Definition: TFoam.cxx:1233
unsigned int UInt_t
Definition: RtypesCore.h:42
bool verbose
virtual void Initialize()
Basic initialization of FOAM invoked by the user.
Definition: TFoam.cxx:370
Bool_t storeProtoSampler(RooAbsNumGenerator *proto, const RooArgSet &defConfig)
Method accepting registration of a prototype numeric integrator along with a RooArgSet of its default...
static void registerSampler(RooNumGenFactory &fact)
Register RooIntegrator1D, is parameters and capabilities with RooNumIntFactory.
virtual void SetnSampl(Long_t nSampl)
Definition: TFoam.h:129
virtual void SetnCells(Long_t nCells)
Definition: TFoam.h:128
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
double func(double *x, double *p)
Definition: stressTF1.cxx:213
virtual void SetPseRan(TRandom *PseRan)
Definition: TFoam.h:124
virtual Double_t getMax(const char *name=0) const
virtual TObject * Next()=0
Int_t getSize() const
virtual const RooArgSet * get(Int_t index) const
Return RooArgSet with coordinates of event 'index'.
virtual void SetRho(TFoamIntegrand *Rho)
User may use this method to set the distribution object.
Definition: TFoam.cxx:1062
TIterator * _rvIter
Definition: TFoam.h:29
Double_t getRealValue(const char *name, Double_t defVal=0, Bool_t verbose=kFALSE) const
Get value of a RooAbsReal stored in set with given name.
Definition: RooArgSet.cxx:527
virtual void SetkDim(Int_t kDim)
Definition: TFoam.h:127