![]() |
![]() |
#include <ToyMCSamplerOpt.h>
Public Member Functions | |
virtual RooAbsData * | GenerateToyData (RooArgSet &, double &weight) const |
void | setGlobalObsPdf (RooAbsPdf *pdf) |
virtual void | SetPdf (RooAbsPdf &pdf) |
ToyMCSamplerOpt (const RooStats::ToyMCSampler &base) | |
ToyMCSamplerOpt (RooStats::TestStatistic &ts, Int_t ntoys, RooAbsPdf *globalObsPdf=0, bool generateNuisances=false) | |
ToyMCSamplerOpt (const ToyMCSamplerOpt &other) | |
~ToyMCSamplerOpt () | |
Private Member Functions | |
RooAbsData * | Generate (RooAbsPdf &pdf, RooArgSet &observables, const RooDataSet *protoData=NULL, int forceEvents=0) const |
Private Attributes | |
std::map< RooAbsPdf *, toymcoptutils::SimPdfGenInfo * > | genCache_ |
int | globalObsIndex_ |
RooAbsPdf * | globalObsPdf_ |
RooDataSet * | globalObsValues_ |
int | nuisIndex_ |
RooDataSet * | nuisValues_ |
RooRealVar * | weightVar_ |
Definition at line 53 of file ToyMCSamplerOpt.h.
ToyMCSamplerOpt::ToyMCSamplerOpt | ( | RooStats::TestStatistic & | ts, |
Int_t | ntoys, | ||
RooAbsPdf * | globalObsPdf = 0 , |
||
bool | generateNuisances = false |
||
) |
Definition at line 17 of file ToyMCSamplerOpt.cc.
: ToyMCSampler(ts, ntoys), globalObsPdf_(globalObsPdf), globalObsValues_(0), globalObsIndex_(-1), nuisValues_(0), nuisIndex_(-1), weightVar_(0) { if (!generateNuisances) fPriorNuisance = 0; // set things straight from the beginning }
ToyMCSamplerOpt::ToyMCSamplerOpt | ( | const RooStats::ToyMCSampler & | base | ) |
Definition at line 28 of file ToyMCSamplerOpt.cc.
: ToyMCSampler(base), globalObsPdf_(0), globalObsValues_(0), globalObsIndex_(-1), weightVar_(0) { }
ToyMCSamplerOpt::ToyMCSamplerOpt | ( | const ToyMCSamplerOpt & | other | ) |
Definition at line 36 of file ToyMCSamplerOpt.cc.
: ToyMCSampler(other), globalObsPdf_(0), globalObsValues_(0), globalObsIndex_(-1), weightVar_(0) { }
ToyMCSamplerOpt::~ToyMCSamplerOpt | ( | ) |
Definition at line 44 of file ToyMCSamplerOpt.cc.
References genCache_, globalObsValues_, and weightVar_.
{ delete weightVar_; for (std::map<RooAbsPdf *, toymcoptutils::SimPdfGenInfo *>::iterator it = genCache_.begin(), ed = genCache_.end(); it != ed; ++it) { delete it->second; } genCache_.clear(); delete _allVars; _allVars = 0; delete globalObsValues_; }
RooAbsData * ToyMCSamplerOpt::Generate | ( | RooAbsPdf & | pdf, |
RooArgSet & | observables, | ||
const RooDataSet * | protoData = NULL , |
||
int | forceEvents = 0 |
||
) | const [private] |
Definition at line 501 of file ToyMCSamplerOpt.cc.
References patZpeak::events, toymcoptutils::SimPdfGenInfo::generate(), info, run_regression::ret, toymcoptutils::SimPdfGenInfo::setCacheTemplates(), and toymcoptutils::SimPdfGenInfo::setCopyData().
{ if(fProtoData) { protoData = fProtoData; forceEvents = protoData->numEntries(); } int events = forceEvents; if (events == 0) events = fNEvents; if (events != 0) { assert(events == 1); assert(protoData == 0); RooAbsData *ret = pdf.generate(observables, events); return ret; } toymcoptutils::SimPdfGenInfo *& info = genCache_[&pdf]; if (info == 0) { info = new toymcoptutils::SimPdfGenInfo(pdf, observables, fGenerateBinned, protoData, forceEvents); info->setCopyData(false); if (!fPriorNuisance) info->setCacheTemplates(true); } return info->generate(weightVar_, protoData, forceEvents); }
RooAbsData * ToyMCSamplerOpt::GenerateToyData | ( | RooArgSet & | , |
double & | weight | ||
) | const [virtual] |
Definition at line 419 of file ToyMCSamplerOpt.cc.
References AlCaHLTBitMon_QueryRunRegistry::data, relval_generation_module::generate(), NULL, and makeHLTPrescaleTable::values.
{ weight = 1; // This method generates a toy data set for the given parameter point taking // global observables into account. if (fObservables == NULL) { ooccoutE((TObject*)NULL,InputArguments) << "Observables not set." << endl; return 0; } // generate nuisances RooArgSet saveNuis; if(fPriorNuisance && fNuisancePars && fNuisancePars->getSize() > 0) { if (nuisValues_ == 0 || nuisIndex_ == nuisValues_->numEntries()) { delete nuisValues_; nuisValues_ = fPriorNuisance->generate(*fNuisancePars, fNToys); nuisIndex_ = 0; } fNuisancePars->snapshot(saveNuis); const RooArgSet *values = nuisValues_->get(nuisIndex_++); RooArgSet pars(*fNuisancePars); pars = *values; } RooArgSet observables(*fObservables); if(fGlobalObservables && fGlobalObservables->getSize()) { observables.remove(*fGlobalObservables); // generate one set of global observables and assign it assert(globalObsPdf_); if (globalObsValues_ == 0 || globalObsIndex_ == globalObsValues_->numEntries()) { delete globalObsValues_; globalObsValues_ = (globalObsPdf_ ? globalObsPdf_ : fPdf)->generate(*fGlobalObservables, fNToys); globalObsIndex_ = 0; } const RooArgSet *values = globalObsValues_->get(globalObsIndex_++); if (!_allVars) _allVars = fPdf->getObservables(*fGlobalObservables); *_allVars = *values; } RooAbsData* data = NULL; if(!fImportanceDensity) { // no Importance Sampling data = Generate(*fPdf, observables); }else{ throw std::runtime_error("No importance sampling yet"); // Importance Sampling RooArgSet* allVars = fPdf->getVariables(); RooArgSet* allVars2 = fImportanceDensity->getVariables(); allVars->add(*allVars2); const RooArgSet* saveVars = (const RooArgSet*)allVars->snapshot(); // the number of events generated is either the given fNEvents or // in case this is not given, the expected number of events of // the pdf with a Poisson fluctuation int forceEvents = 0; if(fNEvents == 0) { forceEvents = (int)fPdf->expectedEvents(observables); forceEvents = RooRandom::randomGenerator()->Poisson(forceEvents); } // need to be careful here not to overwrite the current state of the // nuisance parameters, ie they must not be part of the snapshot if(fImportanceSnapshot) *allVars = *fImportanceSnapshot; // generate with the parameters configured in this class // NULL => no protoData // overwriteEvents => replaces fNEvents it would usually take data = Generate(*fImportanceDensity, observables, NULL, forceEvents); *allVars = *saveVars; delete allVars; delete allVars2; delete saveVars; } if (saveNuis.getSize()) { RooArgSet pars(*fNuisancePars); pars = saveNuis; } return data; }
void ToyMCSamplerOpt::setGlobalObsPdf | ( | RooAbsPdf * | ) | [inline] |
void ToyMCSamplerOpt::SetPdf | ( | RooAbsPdf & | ) | [virtual] |
Definition at line 411 of file ToyMCSamplerOpt.cc.
{ ToyMCSampler::SetPdf(pdf); delete _allVars; _allVars = 0; delete globalObsValues_; globalObsValues_ = 0; globalObsIndex_ = -1; delete nuisValues_; nuisValues_ = 0; nuisIndex_ = -1; }
std::map<RooAbsPdf *, toymcoptutils::SimPdfGenInfo *> ToyMCSamplerOpt::genCache_ [mutable, private] |
Definition at line 73 of file ToyMCSamplerOpt.h.
Referenced by ~ToyMCSamplerOpt().
int ToyMCSamplerOpt::globalObsIndex_ [mutable, private] |
Definition at line 66 of file ToyMCSamplerOpt.h.
RooAbsPdf* ToyMCSamplerOpt::globalObsPdf_ [private] |
Definition at line 64 of file ToyMCSamplerOpt.h.
Referenced by setGlobalObsPdf().
RooDataSet* ToyMCSamplerOpt::globalObsValues_ [mutable, private] |
Definition at line 65 of file ToyMCSamplerOpt.h.
Referenced by ~ToyMCSamplerOpt().
int ToyMCSamplerOpt::nuisIndex_ [mutable, private] |
Definition at line 70 of file ToyMCSamplerOpt.h.
RooDataSet* ToyMCSamplerOpt::nuisValues_ [mutable, private] |
Definition at line 69 of file ToyMCSamplerOpt.h.
RooRealVar* ToyMCSamplerOpt::weightVar_ [mutable, private] |
Definition at line 72 of file ToyMCSamplerOpt.h.
Referenced by ~ToyMCSamplerOpt().