// RooEffGenContext is a specialized generator context for p.d.fs represented
// by class RooEffProd, which are p.d.fs multiplied with an efficiency function.
// This generator context generates events from such products by first
// generating events from a dedicated generator context of the input p.d.f.
// and applying an extra rejection step based on the efficiency function.
// END_HTML
#include "RooFit.h"
#include "RooEffGenContext.h"
#include "RooAbsPdf.h"
#include "RooRandom.h"
using namespace std;
ClassImp(RooEffGenContext)
;
RooEffGenContext::RooEffGenContext(const RooAbsPdf &model,
const RooAbsPdf& pdf, const RooAbsReal& eff,
const RooArgSet &vars,
const RooDataSet *prototype, const RooArgSet* auxProto,
Bool_t verbose, const RooArgSet* ) :
RooAbsGenContext(model,vars,prototype,auxProto,verbose)
{
RooArgSet x(eff,eff.GetName());
_cloneSet = (RooArgSet*) x.snapshot(kTRUE);
_eff = dynamic_cast<RooAbsReal*>(_cloneSet->find(eff.GetName()));
_generator=pdf.genContext(vars,prototype,auxProto,verbose);
}
RooEffGenContext::~RooEffGenContext()
{
delete _generator ;
delete _cloneSet ;
}
void RooEffGenContext::initGenerator(const RooArgSet &theEvent)
{
_eff->recursiveRedirectServers(theEvent);
_generator->initGenerator(theEvent);
}
void RooEffGenContext::generateEvent(RooArgSet &theEvent, Int_t remaining)
{
Double_t maxEff=1;
do {
_generator->generateEvent(theEvent,remaining);
} while (_eff->getVal() < RooRandom::uniform()*maxEff);
}