47using std::endl, std::string, std::ostream;
65 _updateFMaxPerEvent(0)
67 cxcoutI(Generation) <<
"RooGenContext::ctor() setting up event generator context for p.d.f. " << model.
GetName()
68 <<
" for generation of observable(s) " << vars ;
79 coutE(Generation) <<
"RooGenContext::RooGenContext(" <<
GetName() <<
") Couldn't deep-clone PDF, abort," << std::endl ;
101 if(!
tmp->isFundamental()) {
102 coutE(Generation) <<
"RooGenContext::ctor(): cannot generate values for derived \"" <<
tmp->GetName() <<
"\"" << std::endl;
109 coutI(Generation) <<
"RooGenContext::ctor() WARNING model does not depend on \"" <<
tmp->GetName()
110 <<
"\" which will have uniform distribution" << std::endl;
120 cxcoutD(Generation) <<
"RooGenContext::ctor() observable " << arg->
GetName() <<
" has been determined to be unsafe for internal generation" << std::endl;
136 coutE(Generation) <<
"RooGenContext::ctor() constructor failed with errors" << std::endl;
143 cxcoutD(Generation) <<
"RooGenContext::ctor() observables " <<
_directVars <<
" are safe for internal generator (if supported by p.d.f)" << std::endl ;
146 cxcoutD(Generation) <<
"RooGenContext::ctor() observables " <<
_otherVars <<
" are NOT safe for internal generator (if supported by p.d.f)" << std::endl ;
153 cxcoutD(Generation) <<
"RooGenContext::ctor() Model depends on supplied protodata observables, static initialization of internal generator will not be allowed" << std::endl ;
161 cxcoutD(Generation) <<
"RooGenContext::ctor() Model indicates that it can internally generate observables "
175 cxcoutI(Generation) <<
"RooGenContext::ctor() Context will" ;
188 nname.Append(
"_AccRej") ;
190 ntitle.Append(
" (Accept/Reject)") ;
207 coutI(Generation) <<
"RooGenContext::ctor() no prototype data provided, all observables are generated with numerically and "
208 <<
"model supports analytical maximum findin:, can provide analytical pdf maximum to numeric generator" << std::endl ;
210 _maxVar = std::make_unique<RooRealVar>(
"funcMax",
"function maximum",maxVal) ;
211 cxcoutD(Generation) <<
"RooGenContext::ctor() maximum value returned by RooAbsPdf::maxVal() is " << maxVal << std::endl ;
218 cxcoutI(Generation) <<
"RooGenContext::ctor() accept/reject sampling function is " <<
_acceptRejectFunc->GetName() << std::endl ;
228 cxcoutI(Generation) <<
"RooGenContext::ctor() accept/reject sampling function is " <<
_acceptRejectFunc->GetName() << std::endl ;
236 coutI(Generation) <<
"RooGenContext::ctor() prototype data provided, and "
237 <<
"model supports analytical maximum finding in the full phase space: "
238 <<
"can provide analytical pdf maximum to numeric generator" << std::endl ;
240 _maxVar = std::make_unique<RooRealVar>(
"funcMax",
"function maximum", maxVal);
245 coutI(Generation) <<
"RooGenContext::ctor() prototype data provided, and "
246 <<
"model supports analytical maximum finding in the variables which are not"
247 <<
" internally generated. Can provide analytical pdf maximum to numeric "
248 <<
"generator" << std::endl;
249 cxcoutD(Generation) <<
"RooGenContext::ctor() maximum value must be reevaluated for each "
250 <<
"event with configuration code " <<
maxFindCode << std::endl ;
251 _maxVar = std::make_unique<RooRealVar>(
"funcMax",
"function maximum",1) ;
264 cxcoutD(Generation) <<
"RooGenContext::ctor() prototype data provided, observables are generated numerically no "
265 <<
"analytical estimate of maximum function value provided by model, must determine maximum value through initial sampling space "
266 <<
"of accept/reject observables plus prototype observables: " <<
otherAndProto << std::endl ;
273 _maxVar = std::make_unique<RooRealVar>(
"funcMax",
"function maximum",max) ;
276 oocoutE(
nullptr, Generation) <<
"RooGenContext::ctor(" << model.
GetName()
277 <<
") ERROR: generating conditional p.d.f. which requires prior knowledge of function maximum, "
278 <<
"but chosen numeric generator (" <<
maxFinder->generatorName() <<
") does not support maximum finding" << std::endl ;
279 throw string(
"RooGenContext::ctor()") ;
282 cxcoutD(Generation) <<
"RooGenContext::ctor() maximum function value found through initial sampling is " << max << std::endl ;
290 cxcoutD(Generation) <<
"RooGenContext::ctor() creating MC sampling generator " <<
_generator->generatorName() <<
" from function for observables " <<
_otherVars << std::endl ;
336 cxcoutD(Generation) <<
"RooGenContext::initGenerator() initializing internal generator of model with code " <<
_code << std::endl ;
353 cxcoutD(Generation) <<
"RooGenContext::initGenerator() reevaluation of maximum function value is required for each event, new value is " << max << std::endl ;
361 coutI(Generation) <<
"RooGenContext::generateEvent INFO: accept/reject generator requests resampling of previously produced events by factor "
362 <<
resampleRatio <<
" due to increased maximum weight" << std::endl ;
366 coutE(Generation) <<
"RooGenContext::generateEvent ERROR accept/reject generator failed" << std::endl ;
385 coutE(Generation) <<
"RooGenContext::generateEvent(" <<
GetName() <<
") ERROR: uniform variable " <<
uniVar->GetName() <<
" is not an lvalue" << std::endl ;
401 os <<
indent <<
" --- RooGenContext --- " << std::endl ;
402 os <<
indent <<
"Using PDF ";
static void indent(ostringstream &buf, int indent_level)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Common abstract base class for objects that represent a value and a "shape" in RooFit.
bool dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr, bool valueOnly=false) const
Test whether we depend on (ie, are served by) any object in the specified collection.
bool recursiveRedirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool recurseInNewSet=true)
Recursively replace all servers with the new servers in newSet.
void setOperMode(OperMode mode, bool recurseADirty=true)
Set the operation mode of this node.
RooFit::OwningPtr< RooArgSet > getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract base class for generator contexts of RooAbsPdf objects.
RooArgSet _theEvent
Pointer to observable event being generated.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Interface for multi-line printing.
RooArgSet _protoVars
Prototype observables.
bool _verbose
Verbose messaging?
bool _isValid
Is context in valid state?
void resampleData(double &ratio)
Rescale existing output buffer with given ratio.
Abstract base class for objects that are lvalues, i.e.
Abstract interface for all probability density functions.
double getNorm(const RooArgSet &nset) const
Get normalisation term needed to normalise the raw values returned by getVal().
virtual void generateEvent(Int_t code)
Interface for generation of an event using the algorithm corresponding to the specified code.
virtual void resetErrorCounters(Int_t resetValue=10)
Reset error counter to given value, limiting the number of future error messages for this pdf to 'res...
virtual bool isDirectGenSafe(const RooAbsArg &arg) const
Check if given observable can be safely generated using the pdfs internal generator mechanism (if tha...
const RooNumGenConfig * getGeneratorConfig() const
Return the numeric MC generator configuration used for this object.
virtual void initGenerator(Int_t code)
Interface for one-time initialization to setup the generator for the specified code.
virtual Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, bool staticInitOK=true) const
Load generatedVars with the subset of directVars that we can generate events for, and return a code t...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
virtual void fixAddCoefNormalization(const RooArgSet &addNormSet=RooArgSet(), bool force=true)
Fix the interpretation of the coefficient of any RooAddPdf component in the expression tree headed by...
virtual double maxVal(Int_t code) const
Return maximum value for set of observables identified by code assigned in getMaxVal.
RooFit::OwningPtr< RooAbsReal > createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}) const
Create an object that represents the integral of the function over one or more observables listed in ...
virtual Int_t getMaxVal(const RooArgSet &vars) const
Advertise capability to determine maximum value of function for given set of observables.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Container class to hold unbinned data.
static void softAbort()
Soft abort function that interrupts macro execution but doesn't kill ROOT.
void printMultiline(std::ostream &os, Int_t content, bool verbose=false, TString indent="") const override
Printing interface.
void generateEvent(RooArgSet &theEvent, Int_t remaining) override
Generate one event.
RooArgSet _otherVars
List of observables generated internally, randomly, and by accept/reject sampling.
Int_t _code
Internal generation code.
void initGenerator(const RooArgSet &theEvent) override
Perform one-time initialization of the generator context.
~RooGenContext() override
std::unique_ptr< RooAbsNumGenerator > _generator
MC sampling generation engine.
RooAbsPdf * _pdfClone
Clone of input p.d.f.
RooArgSet _cloneSet
Clone of all nodes of input p.d.f.
Int_t _updateFMaxPerEvent
If true, maximum p.d.f value needs to be recalculated for each event.
std::unique_ptr< RooRealVar > _maxVar
Variable holding maximum value of p.d.f.
std::unique_ptr< RooAbsReal > _acceptRejectFunc
Projection function to be passed to accept/reject sampler.
void attach(const RooArgSet ¶ms) override
Attach the cloned model to the event buffer we will be filling.
RooGenContext(const RooAbsPdf &model, const RooArgSet &vars, const RooDataSet *prototype=nullptr, const RooArgSet *auxProto=nullptr, bool verbose=false, const RooArgSet *forceDirect=nullptr)
Initialize a new context for generating events with the specified variables, using the specified PDF ...
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,...
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.