CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ToyMCSamplerOpt.cc
Go to the documentation of this file.
1 #include "../interface/ToyMCSamplerOpt.h"
2 #include "../interface/utils.h"
3 #include <memory>
4 #include <stdexcept>
5 #include <TH1.h>
6 #include <TH2.h>
7 #include <TH3.h>
8 #include <RooSimultaneous.h>
9 #include <RooRealVar.h>
10 #include <RooProdPdf.h>
11 #include <RooPoisson.h>
12 #include <RooDataHist.h>
13 #include <RooDataSet.h>
14 #include <RooRandom.h>
15 #include <../interface/ProfilingTools.h>
16 
17 ToyMCSamplerOpt::ToyMCSamplerOpt(RooStats::TestStatistic& ts, Int_t ntoys, RooAbsPdf *globalObsPdf, bool generateNuisances) :
18  ToyMCSampler(ts, ntoys),
19  globalObsPdf_(globalObsPdf),
20  globalObsValues_(0), globalObsIndex_(-1),
21  nuisValues_(0), nuisIndex_(-1),
22  weightVar_(0)
23 {
24  if (!generateNuisances) fPriorNuisance = 0; // set things straight from the beginning
25 }
26 
27 
28 ToyMCSamplerOpt::ToyMCSamplerOpt(const RooStats::ToyMCSampler &base) :
29  ToyMCSampler(base),
30  globalObsPdf_(0),
31  globalObsValues_(0), globalObsIndex_(-1),
32  weightVar_(0)
33 {
34 }
35 
37  ToyMCSampler(other),
38  globalObsPdf_(0),
39  globalObsValues_(0), globalObsIndex_(-1),
40  weightVar_(0)
41 {
42 }
43 
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 }
54 
55 
56 toymcoptutils::SinglePdfGenInfo::SinglePdfGenInfo(RooAbsPdf &pdf, const RooArgSet& observables, bool preferBinned, const RooDataSet* protoData, int forceEvents) :
57  mode_(pdf.canBeExtended() ? (preferBinned ? Binned : Unbinned) : Counting),
58  pdf_(&pdf),
59  spec_(0),histoSpec_(0),keepHistoSpec_(0),weightVar_(0)
60 {
61  if (pdf.canBeExtended()) {
62  if (pdf.getAttribute("forceGenBinned")) mode_ = Binned;
63  else if (pdf.getAttribute("forceGenPoisson")) mode_ = Poisson;
64  else if (pdf.getAttribute("forceGenUnbinned")) mode_ = Unbinned;
65  }
66 
67  RooArgSet *obs = pdf.getObservables(observables);
68  observables_.add(*obs);
69  delete obs;
70  if (mode_ == Binned) {
71  if (runtimedef::get("TMCSO_GenBinned")) mode_ = BinnedNoWorkaround;
72  else if (runtimedef::get("TMCSO_GenBinnedWorkaround")) mode_ = Binned;
73  else mode_ = Poisson;
74  } else if (mode_ == Unbinned) {
75  //if (!runtimedef::get("TMCSO_NoPrepareMultiGen")) {
76  // spec_ = protoData ? pdf.prepareMultiGen(observables_, RooFit::Extended(), RooFit::ProtoData(*protoData, true, true))
77  // : pdf.prepareMultiGen(observables_, RooFit::Extended());
78  //}
79  }
80 }
81 
83 {
84  delete spec_;
85  delete weightVar_;
86  delete histoSpec_;
87 }
88 
89 
90 RooAbsData *
91 toymcoptutils::SinglePdfGenInfo::generate(const RooDataSet* protoData, int forceEvents)
92 {
93  assert(forceEvents == 0 && "SinglePdfGenInfo: forceEvents must be zero at least for now");
94  RooAbsData *ret = 0;
95  switch (mode_) {
96  case Unbinned:
97  if (spec_ == 0) spec_ = protoData ? pdf_->prepareMultiGen(observables_, RooFit::Extended(), RooFit::ProtoData(*protoData, true, true))
98  : pdf_->prepareMultiGen(observables_, RooFit::Extended());
99  if (spec_) ret = pdf_->generate(*spec_);
100  else ret = pdf_->generate(observables_, RooFit::Extended());
101  break;
102  case Binned:
103  { // aka generateBinnedWorkaround
104  RooDataSet *data = pdf_->generate(observables_, RooFit::Extended());
105  ret = new RooDataHist(data->GetName(), "", *data->get(), *data);
106  delete data;
107  }
108  break;
109  case BinnedNoWorkaround:
110  ret = protoData ? pdf_->generateBinned(observables_, RooFit::Extended(), RooFit::ProtoData(*protoData, true, true))
111  : pdf_->generateBinned(observables_, RooFit::Extended());
112  break;
113  case Poisson:
114  ret = generateWithHisto(weightVar_, false);
115  break;
116  case Counting:
117  ret = pdf_->generate(observables_, 1);
118  break;
119  default:
120  throw std::logic_error("Mode not foreseen in SinglePdfGenInfo::generate");
121  }
122  //std::cout << "Dataset generated from " << pdf_->GetName() << " (weighted? " << ret->isWeighted() << ")" << std::endl;
123  //utils::printRAD(ret);
124  return ret;
125 }
126 
127 RooDataSet *
129 {
130  static int nPA = runtimedef::get("TMCSO_PseudoAsimov");
131  if (nPA) return generatePseudoAsimov(weightVar, nPA);
132  return generateWithHisto(weightVar, true);
133 }
134 
135 RooDataSet *
136 toymcoptutils::SinglePdfGenInfo::generatePseudoAsimov(RooRealVar *&weightVar, int nPoints)
137 {
138  if (mode_ == Unbinned) {
139  double expEvents = pdf_->expectedEvents(observables_);
140  std::auto_ptr<RooDataSet> data(pdf_->generate(observables_, nPoints));
141  if (weightVar == 0) weightVar = new RooRealVar("_weight_","",1.0);
142  RooArgSet obsPlusW(observables_); obsPlusW.add(*weightVar);
143  RooDataSet *rds = new RooDataSet(data->GetName(), "", obsPlusW, weightVar->GetName());
144  for (int i = 0; i < nPoints; ++i) {
145  observables_ = *data->get(i);
146  rds->add(observables_, expEvents/nPoints);
147  }
148  return rds;
149  } else {
150  return generateWithHisto(weightVar, true);
151  }
152 }
153 
154 
155 RooDataSet *
156 toymcoptutils::SinglePdfGenInfo::generateWithHisto(RooRealVar *&weightVar, bool asimov)
157 {
158  if (mode_ == Counting) return generateCountingAsimov();
159  if (observables_.getSize() > 3) throw std::invalid_argument(std::string("ERROR in SinglePdfGenInfo::generateWithHisto for ") + pdf_->GetName() + ", more than 3 observable");
160  RooArgList obs(observables_);
161  RooRealVar *x = (RooRealVar*)obs.at(0);
162  RooRealVar *y = obs.getSize() > 1 ? (RooRealVar*)obs.at(1) : 0;
163  RooRealVar *z = obs.getSize() > 2 ? (RooRealVar*)obs.at(2) : 0;
164  if (weightVar == 0) weightVar = new RooRealVar("_weight_","",1.0);
165 
166  RooCmdArg ay = (y ? RooFit::YVar(*y) : RooCmdArg::none());
167  RooCmdArg az = (z ? RooFit::ZVar(*z) : RooCmdArg::none());
168 
169  if (histoSpec_ == 0) {
170  histoSpec_ = pdf_->createHistogram("htemp", *x, ay, az);
171  histoSpec_->SetDirectory(0);
172  }
173 
174  double expectedEvents = pdf_->expectedEvents(observables_);
175  histoSpec_->Scale(expectedEvents/ histoSpec_->Integral());
176  RooArgSet obsPlusW(obs); obsPlusW.add(*weightVar);
177  RooDataSet *data = new RooDataSet(TString::Format("%sData", pdf_->GetName()), "", obsPlusW, weightVar->GetName());
178  RooAbsArg::setDirtyInhibit(true); // don't propagate dirty flags while filling histograms
179  switch (obs.getSize()) {
180  case 1:
181  for (int i = 1, n = histoSpec_->GetNbinsX(); i <= n; ++i) {
182  x->setVal(histoSpec_->GetXaxis()->GetBinCenter(i));
183  data->add(observables_, asimov ? histoSpec_->GetBinContent(i) : RooRandom::randomGenerator()->Poisson(histoSpec_->GetBinContent(i)) );
184  }
185  break;
186  case 2:
187  {
188  TH2& h2 = dynamic_cast<TH2&>(*histoSpec_);
189  for (int ix = 1, nx = h2.GetNbinsX(); ix <= nx; ++ix) {
190  for (int iy = 1, ny = h2.GetNbinsY(); iy <= ny; ++iy) {
191  x->setVal(h2.GetXaxis()->GetBinCenter(ix));
192  y->setVal(h2.GetYaxis()->GetBinCenter(iy));
193  data->add(observables_, asimov ? h2.GetBinContent(ix,iy) : RooRandom::randomGenerator()->Poisson(h2.GetBinContent(ix,iy)) );
194  } }
195  }
196  break;
197  case 3:
198  {
199  TH3& h3 = dynamic_cast<TH3&>(*histoSpec_);
200  for (int ix = 1, nx = h3.GetNbinsX(); ix <= nx; ++ix) {
201  for (int iy = 1, ny = h3.GetNbinsY(); iy <= ny; ++iy) {
202  for (int iz = 1, nz = h3.GetNbinsZ(); iz <= nz; ++iz) {
203  x->setVal(h3.GetXaxis()->GetBinCenter(ix));
204  y->setVal(h3.GetYaxis()->GetBinCenter(iy));
205  z->setVal(h3.GetYaxis()->GetBinCenter(iz));
206  data->add(observables_, asimov ? h3.GetBinContent(ix,iy,iz) : RooRandom::randomGenerator()->Poisson(h3.GetBinContent(ix,iy,iz)) );
207  } } }
208  }
209  }
210  RooAbsArg::setDirtyInhibit(false); // restore proper propagation of dirty flags
211  if (!keepHistoSpec_) { delete histoSpec_; histoSpec_ = 0; }
212  //std::cout << "Asimov dataset generated from " << pdf_->GetName() << " (sumw? " << data->sumEntries() << ", expected events " << expectedEvents << ")" << std::endl;
213  //utils::printRDH(data);
214  return data;
215 }
216 
217 
218 RooDataSet *
220 {
221  RooArgSet obs(observables_);
222  RooProdPdf *prod = dynamic_cast<RooProdPdf *>(pdf_);
223  RooPoisson *pois = 0;
224  if (prod != 0) {
225  setToExpected(*prod, observables_);
226  } else if ((pois = dynamic_cast<RooPoisson *>(pdf_)) != 0) {
227  setToExpected(*pois, observables_);
228  } else throw std::logic_error("A counting model pdf must be either a RooProdPdf or a RooPoisson");
229  RooDataSet *ret = new RooDataSet(TString::Format("%sData", pdf_->GetName()), "", obs);
230  ret->add(obs);
231  return ret;
232 }
233 
234 void
236 {
237  std::auto_ptr<TIterator> iter(prod.pdfList().createIterator());
238  for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
239  if (!a->dependsOn(obs)) continue;
240  RooPoisson *pois = 0;
241  if ((pois = dynamic_cast<RooPoisson *>(a)) != 0) {
242  setToExpected(*pois, obs);
243  } else {
244  RooProdPdf *subprod = dynamic_cast<RooProdPdf *>(a);
245  if (subprod) setToExpected(*subprod, obs);
246  else throw std::logic_error("Illegal term in counting model: depends on observables, but not Poisson or Product");
247  }
248  }
249 }
250 
251 void
252 toymcoptutils::SinglePdfGenInfo::setToExpected(RooPoisson &pois, RooArgSet &obs)
253 {
254  RooRealVar *myobs = 0;
255  RooAbsReal *myexp = 0;
256  std::auto_ptr<TIterator> iter(pois.serverIterator());
257  for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
258  if (obs.contains(*a)) {
259  assert(myobs == 0 && "SinglePdfGenInfo::setToExpected(RooPoisson): Two observables??");
260  myobs = dynamic_cast<RooRealVar *>(a);
261  assert(myobs != 0 && "SinglePdfGenInfo::setToExpected(RooPoisson): Observables is not a RooRealVar??");
262  } else {
263  assert(myexp == 0 && "SinglePdfGenInfo::setToExpected(RooPoisson): Two expecteds??");
264  myexp = dynamic_cast<RooAbsReal *>(a);
265  assert(myexp != 0 && "SinglePdfGenInfo::setToExpected(RooPoisson): Expectedis not a RooAbsReal??");
266  }
267  }
268  assert(myobs != 0 && "SinglePdfGenInfo::setToExpected(RooPoisson): No observable?");
269  assert(myexp != 0 && "SinglePdfGenInfo::setToExpected(RooPoisson): No expected?");
270  myobs->setVal(myexp->getVal());
271 }
272 
273 toymcoptutils::SimPdfGenInfo::SimPdfGenInfo(RooAbsPdf &pdf, const RooArgSet& observables, bool preferBinned, const RooDataSet* protoData, int forceEvents) :
274  pdf_(&pdf),
275  cat_(0),
276  observables_(observables),
277  copyData_(true)
278 {
279  assert(forceEvents == 0 && "SimPdfGenInfo: forceEvents must be zero at least for now");
280  RooSimultaneous *simPdf = dynamic_cast<RooSimultaneous *>(&pdf);
281  if (simPdf) {
282  cat_ = const_cast<RooAbsCategoryLValue *>(&simPdf->indexCat());
283  int nbins = cat_->numBins((const char *)0);
284  pdfs_.resize(nbins, 0);
285  RooArgList dummy;
286  for (int ic = 0; ic < nbins; ++ic) {
287  cat_->setBin(ic);
288  RooAbsPdf *pdfi = simPdf->getPdf(cat_->getLabel());
289  if (pdfi == 0) throw std::logic_error(std::string("Unmapped category state: ") + cat_->getLabel());
290  RooAbsPdf *newpdf = utils::factorizePdf(observables, *pdfi, dummy);
291  pdfs_[ic] = new SinglePdfGenInfo(*newpdf, observables, preferBinned);
292  if (newpdf != 0 && newpdf != pdfi) {
293  ownedCrap_.addOwned(*newpdf);
294  }
295  }
296  } else {
297  pdfs_.push_back(new SinglePdfGenInfo(pdf, observables, preferBinned, protoData, forceEvents));
298  }
299 }
300 
302 {
303  for (std::vector<SinglePdfGenInfo *>::iterator it = pdfs_.begin(), ed = pdfs_.end(); it != ed; ++it) {
304  delete *it;
305  }
306  pdfs_.clear();
307  //for (std::map<std::string,RooDataSet*>::iterator it = datasetPieces_.begin(), ed = datasetPieces_.end(); it != ed; ++it) {
308  for (std::map<std::string,RooAbsData*>::iterator it = datasetPieces_.begin(), ed = datasetPieces_.end(); it != ed; ++it) {
309  delete it->second;
310  }
311  datasetPieces_.clear();
312 }
313 
314 
315 RooAbsData *
316 toymcoptutils::SimPdfGenInfo::generate(RooRealVar *&weightVar, const RooDataSet* protoData, int forceEvents)
317 {
318  RooAbsData *ret = 0;
319  TString retName = TString::Format("%sData", pdf_->GetName());
320  if (cat_ != 0) {
321  //bool needsWeights = false;
322  for (int i = 0, n = cat_->numBins((const char *)0); i < n; ++i) {
323  if (pdfs_[i] == 0) continue;
324  cat_->setBin(i);
325  RooAbsData *&data = datasetPieces_[cat_->getLabel()]; delete data;
326  assert(protoData == 0);
327  data = pdfs_[i]->generate(protoData); // I don't really know if protoData != 0 would make sense here
328  if (data->isWeighted()) {
329  if (weightVar == 0) weightVar = new RooRealVar("_weight_","",1.0);
330  RooArgSet obs(*data->get());
331  obs.add(*weightVar);
332  RooDataSet *wdata = new RooDataSet(data->GetName(), "", obs, "_weight_");
333  for (int i = 0, n = data->numEntries(); i < n; ++i) {
334  obs = *data->get(i);
335  if (data->weight()) wdata->add(obs, data->weight());
336  }
337  //std::cout << "DataHist was " << std::endl; utils::printRAD(data);
338  delete data;
339  data = wdata;
340  //std::cout << "DataSet is " << std::endl; utils::printRAD(data);
341  }
342  //if (data->isWeighted()) needsWeights = true;
343  }
344  if (copyData_) {
346  RooArgSet vars(observables_), varsPlusWeight(observables_);
347  if (weightVar) varsPlusWeight.add(*weightVar);
348  ret = new RooDataSet(retName, "", varsPlusWeight, (weightVar ? weightVar->GetName() : 0));
349  for (std::map<std::string,RooAbsData*>::iterator it = datasetPieces_.begin(), ed = datasetPieces_.end(); it != ed; ++it) {
350  cat_->setLabel(it->first.c_str());
351  for (unsigned int i = 0, n = it->second->numEntries(); i < n; ++i) {
352  vars = *it->second->get(i);
353  ret->add(vars, it->second->weight());
354  }
355  }
356  } else {
357  // not copyData is the "fast" mode used when generating toys as a ToyMCSampler.
358  // this doesn't copy the data, so the toys cannot outlive this class and each new
359  // toy over-writes the memory of the previous one.
360  ret = new RooDataSet(retName, "", observables_, RooFit::Index((RooCategory&)*cat_), RooFit::Link(datasetPieces_) /*, RooFit::OwnLinked()*/);
361  }
362  } else ret = pdfs_[0]->generate(protoData, forceEvents);
363  //std::cout << "Dataset generated from sim pdf (weighted? " << ret->isWeighted() << ")" << std::endl; utils::printRAD(ret);
364  return ret;
365 }
366 
367 RooAbsData *
369 {
370  RooAbsData *ret = 0;
371  TString retName = TString::Format("%sData", pdf_->GetName());
372  if (cat_ != 0) {
373  //bool needsWeights = false;
374  for (int i = 0, n = cat_->numBins((const char *)0); i < n; ++i) {
375  if (pdfs_[i] == 0) continue;
376  cat_->setBin(i);
377  RooAbsData *&data = datasetPieces_[cat_->getLabel()]; delete data;
378  data = pdfs_[i]->generateAsimov(weightVar);
379  }
380  if (copyData_) {
381  RooArgSet vars(observables_), varsPlusWeight(observables_); varsPlusWeight.add(*weightVar);
382  ret = new RooDataSet(retName, "", varsPlusWeight, (weightVar ? weightVar->GetName() : 0));
383  for (std::map<std::string,RooAbsData*>::iterator it = datasetPieces_.begin(), ed = datasetPieces_.end(); it != ed; ++it) {
384  cat_->setLabel(it->first.c_str());
385  for (unsigned int i = 0, n = it->second->numEntries(); i < n; ++i) {
386  vars = *it->second->get(i);
387  ret->add(vars, it->second->weight());
388  }
389  }
390  } else {
391  // not copyData is the "fast" mode used when generating toys as a ToyMCSampler.
392  // this doesn't copy the data, so the toys cannot outlive this class and each new
393  // toy over-writes the memory of the previous one.
394  ret = new RooDataSet(retName, "", observables_, RooFit::Index((RooCategory&)*cat_), RooFit::Link(datasetPieces_) /*, RooFit::OwnLinked()*/);
395  }
396  } else ret = pdfs_[0]->generateAsimov(weightVar);
397  //std::cout << "Asimov dataset generated from sim pdf " << pdf_->GetName() << " (sumw? " << ret->sumEntries() << ")" << std::endl;
398  //utils::printRAD(ret);
399  return ret;
400 }
401 
402 void
404 {
405  for (std::vector<SinglePdfGenInfo *>::const_iterator it = pdfs_.begin(), ed = pdfs_.end(); it != ed; ++it) {
406  if (*it) (*it)->setCacheTemplates(cache);
407  }
408 }
409 
410 void
411 ToyMCSamplerOpt::SetPdf(RooAbsPdf& pdf)
412 {
413  ToyMCSampler::SetPdf(pdf);
414  delete _allVars; _allVars = 0;
415  delete globalObsValues_; globalObsValues_ = 0; globalObsIndex_ = -1;
416  delete nuisValues_; nuisValues_ = 0; nuisIndex_ = -1;
417 }
418 
419 RooAbsData* ToyMCSamplerOpt::GenerateToyData(RooArgSet& /*nullPOI*/, double& weight) const {
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 }
498 
499 
500 RooAbsData *
501 ToyMCSamplerOpt::Generate(RooAbsPdf& pdf, RooArgSet& observables, const RooDataSet* protoData, int forceEvents) const
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  }
515  toymcoptutils::SimPdfGenInfo *& info = genCache_[&pdf];
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 }
tuple base
Main Program
Definition: newFWLiteAna.py:92
RooAbsCategoryLValue * cat_
int i
Definition: DBlmapReader.cc:9
ToyMCSamplerOpt(RooStats::TestStatistic &ts, Int_t ntoys, RooAbsPdf *globalObsPdf=0, bool generateNuisances=false)
RooAbsData * Generate(RooAbsPdf &pdf, RooArgSet &observables, const RooDataSet *protoData=NULL, int forceEvents=0) const
int get(const char *name)
RooAbsData * generateAsimov(RooRealVar *&weightVar)
RooAbsData * generate(const RooDataSet *protoData=NULL, int forceEvents=0)
#define NULL
Definition: scimark2.h:8
RooDataSet * globalObsValues_
double double double z
virtual RooAbsData * GenerateToyData(RooArgSet &, double &weight) const
RooDataSet * generatePseudoAsimov(RooRealVar *&weightVar, int nPoints)
void setToExpected(RooProdPdf &prod, RooArgSet &obs)
std::map< RooAbsPdf *, toymcoptutils::SimPdfGenInfo * > genCache_
RooAbsPdf * factorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &constraints)
Definition: utils.cc:80
void setCacheTemplates(bool cache)
RooAbsData * generate(RooRealVar *&weightVar, const RooDataSet *protoData=NULL, int forceEvents=0)
virtual void SetPdf(RooAbsPdf &pdf)
RooDataSet * generateWithHisto(RooRealVar *&weightVar, bool asimov)
void setCopyData(bool copyData)
RooDataSet * generateAsimov(RooRealVar *&weightVar)
std::vector< SinglePdfGenInfo * > pdfs_
SimPdfGenInfo(RooAbsPdf &pdf, const RooArgSet &observables, bool preferBinned, const RooDataSet *protoData=NULL, int forceEvents=0)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
tuple events
Definition: patZpeak.py:19
double a
Definition: hdecay.h:121
x
Definition: VDTMath.h:216
SinglePdfGenInfo(RooAbsPdf &pdf, const RooArgSet &observables, bool preferBinned, const RooDataSet *protoData=NULL, int forceEvents=0)
RooRealVar * weightVar_