49using std::endl, std::cerr;
57 RooRealVar nTrial0D(
"nTrial0D",
"Number of trial samples for cat-only generation",100,0,1e9) ;
58 RooRealVar nTrial1D(
"nTrial1D",
"Number of trial samples for 1-dim generation",1000,0,1e9) ;
59 RooRealVar nTrial2D(
"nTrial2D",
"Number of trial samples for 2-dim generation",100000,0,1e9) ;
60 RooRealVar nTrial3D(
"nTrial3D",
"Number of trial samples for N-dim generation",10000000,0,1e9) ;
76 :
RooAbsNumGenerator(func, genVars, verbose, maxFuncVal), _realSampleDim(_realVars.
size()), _catSampleMult(1)
83 for (
auto * cat : static_range_cast<RooAbsCategory*>(
_catVars)) {
94 <<
" variables with accept-reject may not be accurate" << endl;
101 <<
") WARNING: performing accept/reject sampling on a p.d.f in "
102 <<
_realSampleDim <<
" dimensions without prior knowledge on maximum value "
103 <<
"of p.d.f. Determining maximum value by taking " <<
_minTrials
104 <<
" trial samples. If p.d.f contains sharp peaks smaller than average "
105 <<
"distance between trial sampling points these may be missed and p.d.f. "
106 <<
"may be sampled incorrectly." << endl ;
115 oocoutW(
nullptr, Generation) <<
"RooAcceptReject::ctor(" << func.
GetName() <<
"): WARNING: " <<
_minTrials <<
" trial samples requested by p.d.f for "
116 <<
_realSampleDim <<
"-dimensional accept/reject sampling, this may take some time" << endl ;
121 oocoutI(
nullptr, Generation) << func.
GetName() <<
"::RooAcceptReject" <<
":" << endl
122 <<
" Initializing accept-reject generator for" << endl <<
" ";
125 ooccoutI(
nullptr, Generation) <<
" Function maximum provided, no trial sampling performed" << endl ;
132 ooccoutI(
nullptr, Generation) <<
" Will generate category vars "<<
_catVars << endl ;
135 ooccoutI(
nullptr, Generation) <<
" Will generate real vars " <<
_realVars << endl ;
156 if(event->size() == 1)
return event;
168 if (
_cache->numEntries()>1000000) {
169 oocoutI(
nullptr, Generation) <<
"RooAcceptReject::generateEvent: resetting event cache" << std::endl;
177 while(
nullptr == event) {
180 oocxcoutD(
nullptr, Generation) <<
"RooAcceptReject::generateEvent maxFuncVal has changed, need to resample already accepted events by factor"
193 oocoutE(
nullptr, Generation) <<
"RooAcceptReject::generateEvent: cannot estimate efficiency...giving up" << endl;
199 oocxcoutD(
nullptr, Generation) <<
"RooAcceptReject::generateEvent: adding " << extra <<
" events to the cache, eff = " << eff << endl;
204 oocxcoutD(
nullptr, Generation) <<
"RooAcceptReject::generateEvent: estimated function maximum increased from "
224 while(
nullptr==event) {
256 cerr <<
"RooAcceptReject: accepted event (used " <<
_eventsUsed <<
" of "
257 <<
_cache->numEntries() <<
" so far)" << endl;
274 for(
auto * cat : static_range_cast<RooCategory*>(
_catVars)) cat->randomize();
277 for(
auto * real : static_range_cast<RooRealVar*>(
_realVars)) real->randomize();
294 cerr <<
"RooAcceptReject: generated " <<
_totalEvents <<
" events so far." << endl ;
310 if (
_cache->numEntries()>1000000) {
311 oocoutI(
nullptr, Generation) <<
"RooAcceptReject::getFuncMax: resetting event cache" << endl ;
321 static const std::string
name =
"RooAcceptReject";
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
double getRealValue(const char *name, double defVal=0.0, bool verbose=false) const
Get value of a RooAbsReal stored in set with given name.
Storage_t const & get() const
Const access to the underlying stl container.
Abstract base class for MC event generator implementations like RooAcceptReject and RooFoam.
RooArgSet _catVars
Set of discrete observabeles.
RooArgSet _realVars
Set of real valued observabeles.
const RooAbsReal * _funcMaxVal
Container for maximum function value.
RooAbsReal * _funcClone
Pointer to top level node of cloned function.
bool _verbose
Verbose flag.
RooRealVar * _funcValPtr
RRV storing function value in output dataset.
std::unique_ptr< RooDataSet > _cache
Dataset holding generared values of observables.
Abstract base class for objects that represent a real value and implements functionality common to al...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Generic Monte Carlo toy generator implement the accept/reject sampling technique on any positively va...
UInt_t _minTrialsArray[4]
Minimum number of trials samples for 1,2,3 dimensional problems.
UInt_t _minTrials
Minimum number of max.finding trials, total number of samples.
static void registerSampler(RooNumGenFactory &fact)
Register RooIntegrator1D, is parameters and capabilities with RooNumIntFactory.
double getFuncMax() override
const RooArgSet * nextAcceptedEvent()
Scan through events in the cache which have not been used yet, looking for the first accepted one whi...
void addEventToCache()
Add a trial event to our cache and update our estimates of the function maximum value and integral.
double _funcSum
Maximum function value found, and sum of all samples made.
UInt_t _realSampleDim
Number of real dimensions to be sampled.
std::string const & generatorName() const override
Return unique name of generator implementation.
UInt_t _totalEvents
Total number of function samples.
UInt_t _catSampleMult
Number of discrete dimensions to be sampled.
const RooArgSet * generateEvent(UInt_t remaining, double &resampleRatio) override
Return a pointer to a generated event.
UInt_t _eventsUsed
Accepted number of function samples.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Holds the configuration parameters of the various numeric integrators used by RooRealIntegral.
const RooArgSet & getConfigSection(const char *name) const
Retrieve configuration information specific to integrator with given name.
Factory to instantiate numeric integrators from a given function binding and a given configuration.
bool storeProtoSampler(RooAbsNumGenerator *proto, const RooArgSet &defConfig)
Method accepting registration of a prototype numeric integrator along with a RooArgSet of its default...
virtual void printStream(std::ostream &os, Int_t contents, StyleOption style, TString indent="") const
Print description of object on ostream, printing contents set by contents integer,...
static double uniform(TRandom *generator=randomGenerator())
Return a number uniformly distributed from (0,1)
Variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
const char * GetName() const override
Returns name of object.