49void RooAcceptReject::registerSampler(RooNumGenFactory& fact)
51 RooRealVar nTrial0D(
"nTrial0D",
"Number of trial samples for cat-only generation",100,0,1e9) ;
52 RooRealVar nTrial1D(
"nTrial1D",
"Number of trial samples for 1-dim generation",1000,0,1e9) ;
53 RooRealVar nTrial2D(
"nTrial2D",
"Number of trial samples for 2-dim generation",100000,0,1e9) ;
54 RooRealVar nTrial3D(
"nTrial3D",
"Number of trial samples for N-dim generation",10000000,0,1e9) ;
56 RooAcceptReject* proto =
new RooAcceptReject ;
57 fact.storeProtoSampler(proto,
RooArgSet(nTrial0D,nTrial1D,nTrial2D,nTrial3D)) ;
70 : RooAbsNumGenerator(func, genVars,
verbose, maxFuncVal), _realSampleDim(_realVars.
size()), _catSampleMult(1)
78 _catSampleMult *= cat->numTypes() ;
85 if(_realSampleDim > 3) {
86 _minTrials= _minTrialsArray[3]*_catSampleMult;
87 oocoutW(
nullptr, Generation) << _funcClone->GetName() <<
"::RooAcceptReject" <<
": WARNING: generating " << _realSampleDim
88 <<
" variables with accept-reject may not be accurate" << std::endl;
91 _minTrials= _minTrialsArray[_realSampleDim]*_catSampleMult;
93 if (_realSampleDim > 1) {
94 oocoutW(
nullptr, Generation) <<
"RooAcceptReject::ctor(" << _funcClone->GetName()
95 <<
") WARNING: performing accept/reject sampling on a p.d.f in "
96 << _realSampleDim <<
" dimensions without prior knowledge on maximum value "
97 <<
"of p.d.f. Determining maximum value by taking " << _minTrials
98 <<
" trial samples. If p.d.f contains sharp peaks smaller than average "
99 <<
"distance between trial sampling points these may be missed and p.d.f. "
100 <<
"may be sampled incorrectly." << std::endl ;
108 if (_minTrials>10000) {
109 oocoutW(
nullptr, Generation) <<
"RooAcceptReject::ctor(" << func.
GetName() <<
"): WARNING: " << _minTrials <<
" trial samples requested by p.d.f for "
110 << _realSampleDim <<
"-dimensional accept/reject sampling, this may take some time" << std::endl ;
115 oocoutI(
nullptr, Generation) << func.
GetName() <<
"::RooAcceptReject" <<
":" << std::endl
116 <<
" Initializing accept-reject generator for" << std::endl <<
" ";
119 ooccoutI(
nullptr, Generation) <<
" Function maximum provided, no trial sampling performed" << std::endl ;
121 ooccoutI(
nullptr, Generation) <<
" Real sampling dimension is " << _realSampleDim << std::endl;
122 ooccoutI(
nullptr, Generation) <<
" Category sampling multiplier is " << _catSampleMult << std::endl ;
123 ooccoutI(
nullptr, Generation) <<
" Min sampling trials is " << _minTrials << std::endl;
125 if (!_catVars.empty()) {
126 ooccoutI(
nullptr, Generation) <<
" Will generate category vars "<< _catVars << std::endl ;
128 if (!_realVars.empty()) {
129 ooccoutI(
nullptr, Generation) <<
" Will generate real vars " << _realVars << std::endl ;
146const RooArgSet *RooAcceptReject::generateEvent(
UInt_t remaining,
double& resampleRatio)
158 while(_totalEvents < _minTrials) {
162 if (_cache->numEntries()>1000000) {
163 oocoutI(
nullptr, Generation) <<
"RooAcceptReject::generateEvent: resetting event cache" << std::endl;
170 double oldMax2(_maxFuncVal);
171 while(
nullptr ==
event) {
173 if (_maxFuncVal>oldMax2) {
174 oocxcoutD(
nullptr, Generation) <<
"RooAcceptReject::generateEvent maxFuncVal has changed, need to resample already accepted events by factor"
175 << oldMax2 <<
"/" << _maxFuncVal <<
"=" << oldMax2/_maxFuncVal << std::endl ;
176 resampleRatio=oldMax2/_maxFuncVal ;
178 event= nextAcceptedEvent();
186 if(_totalEvents*_maxFuncVal <= 0) {
187 oocoutE(
nullptr, Generation) <<
"RooAcceptReject::generateEvent: cannot estimate efficiency...giving up" << std::endl;
191 double eff= _funcSum/(_totalEvents*_maxFuncVal);
193 oocxcoutD(
nullptr, Generation) <<
"RooAcceptReject::generateEvent: adding " << extra <<
" events to the cache, eff = " << eff << std::endl;
194 double oldMax(_maxFuncVal);
197 if((_maxFuncVal > oldMax)) {
198 oocxcoutD(
nullptr, Generation) <<
"RooAcceptReject::generateEvent: estimated function maximum increased from "
199 << oldMax <<
" to " << _maxFuncVal << std::endl;
200 oldMax = _maxFuncVal ;
207 if (_eventsUsed>1000000) {
214 _maxFuncVal = _funcMaxVal->getVal() ;
218 while(
nullptr==
event) {
220 event = nextAcceptedEvent() ;
236const RooArgSet *RooAcceptReject::nextAcceptedEvent()
239 while((
event= _cache->get(_eventsUsed))) {
243 if(
r*_maxFuncVal > _funcValPtr->getVal()) {
249 if(_verbose && (_eventsUsed%1000==0)) {
250 std::cerr <<
"RooAcceptReject: accepted event (used " << _eventsUsed <<
" of "
251 << _cache->numEntries() <<
" so far)" << std::endl;
265void RooAcceptReject::addEventToCache()
274 double val= _funcClone->getVal();
275 _funcValPtr->setVal(val);
280 if(val > _maxFuncVal) _maxFuncVal= 1.05*val;
287 if (_verbose &&_totalEvents%10000==0) {
288 std::cerr <<
"RooAcceptReject: generated " << _totalEvents <<
" events so far." << std::endl ;
293double RooAcceptReject::getFuncMax()
300 while(_totalEvents < _minTrials) {
304 if (_cache->numEntries()>1000000) {
305 oocoutI(
nullptr, Generation) <<
"RooAcceptReject::getFuncMax: resetting event cache" << std::endl ;
314std::string
const& RooAcceptReject::generatorName()
const {
315 static const std::string
name =
"RooAcceptReject";
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int)
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
long long Long64_t
Portable signed long integer 8 bytes.
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
A space to attach TBranches.
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 objects that represent a real value and implements functionality common to al...
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Object to represent discrete states.
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.
static double uniform(TRandom *generator=randomGenerator())
Return a number uniformly distributed from (0,1)
Variable that can be changed from the outside.
const char * GetName() const override
Returns name of object.