CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
ToyMCSamplerOpt Class Reference

#include <ToyMCSamplerOpt.h>

Inheritance diagram for ToyMCSamplerOpt:

Public Member Functions

virtual RooAbsData * GenerateToyData (RooArgSet &, double &weight) const
 
void setGlobalObsPdf (RooAbsPdf *pdf)
 
virtual void SetPdf (RooAbsPdf &pdf)
 
 ToyMCSamplerOpt (RooStats::TestStatistic &ts, Int_t ntoys, RooAbsPdf *globalObsPdf=0, bool generateNuisances=false)
 
 ToyMCSamplerOpt (const RooStats::ToyMCSampler &base)
 
 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_
 

Detailed Description

Definition at line 53 of file ToyMCSamplerOpt.h.

Constructor & Destructor Documentation

ToyMCSamplerOpt::ToyMCSamplerOpt ( RooStats::TestStatistic &  ts,
Int_t  ntoys,
RooAbsPdf *  globalObsPdf = 0,
bool  generateNuisances = false 
)

Definition at line 17 of file ToyMCSamplerOpt.cc.

17  :
18  ToyMCSampler(ts, ntoys),
19  globalObsPdf_(globalObsPdf),
21  nuisValues_(0), nuisIndex_(-1),
22  weightVar_(0)
23 {
24  if (!generateNuisances) fPriorNuisance = 0; // set things straight from the beginning
25 }
RooDataSet * nuisValues_
RooDataSet * globalObsValues_
RooAbsPdf * globalObsPdf_
RooRealVar * weightVar_
ToyMCSamplerOpt::ToyMCSamplerOpt ( const RooStats::ToyMCSampler &  base)

Definition at line 28 of file ToyMCSamplerOpt.cc.

28  :
29  ToyMCSampler(base),
30  globalObsPdf_(0),
32  weightVar_(0)
33 {
34 }
tuple base
Main Program
Definition: newFWLiteAna.py:92
RooDataSet * globalObsValues_
RooAbsPdf * globalObsPdf_
RooRealVar * weightVar_
ToyMCSamplerOpt::ToyMCSamplerOpt ( const ToyMCSamplerOpt other)

Definition at line 36 of file ToyMCSamplerOpt.cc.

36  :
37  ToyMCSampler(other),
38  globalObsPdf_(0),
40  weightVar_(0)
41 {
42 }
RooDataSet * globalObsValues_
RooAbsPdf * globalObsPdf_
RooRealVar * weightVar_
ToyMCSamplerOpt::~ToyMCSamplerOpt ( )

Definition at line 44 of file ToyMCSamplerOpt.cc.

References genCache_, globalObsValues_, and weightVar_.

45 {
46  delete weightVar_;
47  for (std::map<RooAbsPdf *, toymcoptutils::SimPdfGenInfo *>::iterator it = genCache_.begin(), ed = genCache_.end(); it != ed; ++it) {
48  delete it->second;
49  }
50  genCache_.clear();
51  delete _allVars; _allVars = 0;
52  delete globalObsValues_;
53 }
RooDataSet * globalObsValues_
std::map< RooAbsPdf *, toymcoptutils::SimPdfGenInfo * > genCache_
RooRealVar * weightVar_

Member Function Documentation

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().

502 {
503  if(fProtoData) {
504  protoData = fProtoData;
505  forceEvents = protoData->numEntries();
506  }
507  int events = forceEvents;
508  if (events == 0) events = fNEvents;
509  if (events != 0) {
510  assert(events == 1);
511  assert(protoData == 0);
512  RooAbsData *ret = pdf.generate(observables, events);
513  return ret;
514  }
516  if (info == 0) {
517  info = new toymcoptutils::SimPdfGenInfo(pdf, observables, fGenerateBinned, protoData, forceEvents);
518  info->setCopyData(false);
519  if (!fPriorNuisance) info->setCacheTemplates(true);
520  }
521  return info->generate(weightVar_, protoData, forceEvents);
522 }
std::map< RooAbsPdf *, toymcoptutils::SimPdfGenInfo * > genCache_
void setCacheTemplates(bool cache)
RooAbsData * generate(RooRealVar *&weightVar, const RooDataSet *protoData=NULL, int forceEvents=0)
void setCopyData(bool copyData)
tuple events
Definition: patZpeak.py:19
RooRealVar * weightVar_
RooAbsData * ToyMCSamplerOpt::GenerateToyData ( RooArgSet &  ,
double &  weight 
) const
virtual

Definition at line 419 of file ToyMCSamplerOpt.cc.

References data, relval_generation_module::generate(), NULL, and makeHLTPrescaleTable::values.

419  {
420  weight = 1;
421  // This method generates a toy data set for the given parameter point taking
422  // global observables into account.
423 
424  if (fObservables == NULL) {
425  ooccoutE((TObject*)NULL,InputArguments) << "Observables not set." << endl;
426  return 0;
427  }
428 
429  // generate nuisances
430  RooArgSet saveNuis;
431  if(fPriorNuisance && fNuisancePars && fNuisancePars->getSize() > 0) {
432  if (nuisValues_ == 0 || nuisIndex_ == nuisValues_->numEntries()) {
433  delete nuisValues_;
434  nuisValues_ = fPriorNuisance->generate(*fNuisancePars, fNToys);
435  nuisIndex_ = 0;
436  }
437  fNuisancePars->snapshot(saveNuis);
438  const RooArgSet *values = nuisValues_->get(nuisIndex_++);
439  RooArgSet pars(*fNuisancePars); pars = *values;
440  }
441 
442  RooArgSet observables(*fObservables);
443  if(fGlobalObservables && fGlobalObservables->getSize()) {
444  observables.remove(*fGlobalObservables);
445 
446  // generate one set of global observables and assign it
447  assert(globalObsPdf_);
448  if (globalObsValues_ == 0 || globalObsIndex_ == globalObsValues_->numEntries()) {
449  delete globalObsValues_;
450  globalObsValues_ = (globalObsPdf_ ? globalObsPdf_ : fPdf)->generate(*fGlobalObservables, fNToys);
451  globalObsIndex_ = 0;
452  }
453  const RooArgSet *values = globalObsValues_->get(globalObsIndex_++);
454  if (!_allVars) _allVars = fPdf->getObservables(*fGlobalObservables);
455  *_allVars = *values;
456  }
457 
458  RooAbsData* data = NULL;
459 
460  if(!fImportanceDensity) {
461  // no Importance Sampling
462  data = Generate(*fPdf, observables);
463  }else{
464  throw std::runtime_error("No importance sampling yet");
465  // Importance Sampling
466  RooArgSet* allVars = fPdf->getVariables();
467  RooArgSet* allVars2 = fImportanceDensity->getVariables();
468  allVars->add(*allVars2);
469  const RooArgSet* saveVars = (const RooArgSet*)allVars->snapshot();
470 
471  // the number of events generated is either the given fNEvents or
472  // in case this is not given, the expected number of events of
473  // the pdf with a Poisson fluctuation
474  int forceEvents = 0;
475  if(fNEvents == 0) {
476  forceEvents = (int)fPdf->expectedEvents(observables);
477  forceEvents = RooRandom::randomGenerator()->Poisson(forceEvents);
478  }
479 
480  // need to be careful here not to overwrite the current state of the
481  // nuisance parameters, ie they must not be part of the snapshot
482  if(fImportanceSnapshot) *allVars = *fImportanceSnapshot;
483 
484  // generate with the parameters configured in this class
485  // NULL => no protoData
486  // overwriteEvents => replaces fNEvents it would usually take
487  data = Generate(*fImportanceDensity, observables, NULL, forceEvents);
488 
489  *allVars = *saveVars;
490  delete allVars;
491  delete allVars2;
492  delete saveVars;
493  }
494 
495  if (saveNuis.getSize()) { RooArgSet pars(*fNuisancePars); pars = saveNuis; }
496  return data;
497 }
RooDataSet * nuisValues_
RooAbsData * Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooDataSet *protoData=NULL, int forceEvents=0) const
#define NULL
Definition: scimark2.h:8
RooDataSet * globalObsValues_
RooAbsPdf * globalObsPdf_
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void ToyMCSamplerOpt::setGlobalObsPdf ( RooAbsPdf *  pdf)
inline

Definition at line 60 of file ToyMCSamplerOpt.h.

References globalObsPdf_.

60 { globalObsPdf_ = pdf; }
RooAbsPdf * globalObsPdf_
void ToyMCSamplerOpt::SetPdf ( RooAbsPdf &  pdf)
virtual

Definition at line 411 of file ToyMCSamplerOpt.cc.

412 {
413  ToyMCSampler::SetPdf(pdf);
414  delete _allVars; _allVars = 0;
416  delete nuisValues_; nuisValues_ = 0; nuisIndex_ = -1;
417 }
RooDataSet * nuisValues_
RooDataSet * globalObsValues_

Member Data Documentation

std::map<RooAbsPdf *, toymcoptutils::SimPdfGenInfo *> ToyMCSamplerOpt::genCache_
mutableprivate

Definition at line 73 of file ToyMCSamplerOpt.h.

Referenced by ~ToyMCSamplerOpt().

int ToyMCSamplerOpt::globalObsIndex_
mutableprivate

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_
mutableprivate

Definition at line 65 of file ToyMCSamplerOpt.h.

Referenced by ~ToyMCSamplerOpt().

int ToyMCSamplerOpt::nuisIndex_
mutableprivate

Definition at line 70 of file ToyMCSamplerOpt.h.

RooDataSet* ToyMCSamplerOpt::nuisValues_
mutableprivate

Definition at line 69 of file ToyMCSamplerOpt.h.

RooRealVar* ToyMCSamplerOpt::weightVar_
mutableprivate

Definition at line 72 of file ToyMCSamplerOpt.h.

Referenced by ~ToyMCSamplerOpt().