CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
utils.cc
Go to the documentation of this file.
1 #include "../interface/utils.h"
2 #include "../interface/RooSimultaneousOpt.h"
3 
4 #include <cstdio>
5 #include <iostream>
6 #include <sstream>
7 #include <cmath>
8 #include <vector>
9 #include <string>
10 #include <memory>
11 #include <typeinfo>
12 #include <stdexcept>
13 
14 #include <TIterator.h>
15 #include <TString.h>
16 
17 #include <RooAbsData.h>
18 #include <RooAbsPdf.h>
19 #include <RooArgSet.h>
20 #include <RooDataHist.h>
21 #include <RooDataSet.h>
22 #include <RooRealVar.h>
23 #include <RooProdPdf.h>
24 #include <RooProduct.h>
25 #include <RooSimultaneous.h>
26 #include <RooWorkspace.h>
27 #include <RooPlot.h>
28 #include <RooStats/ModelConfig.h>
29 
30 void utils::printRDH(RooAbsData *data) {
31  std::vector<std::string> varnames, catnames;
32  const RooArgSet *b0 = data->get();
33  TIterator *iter = b0->createIterator();
34  for (RooAbsArg *a = 0; (a = (RooAbsArg *)iter->Next()) != 0; ) {
35  if (a->InheritsFrom("RooRealVar")) {
36  varnames.push_back(a->GetName());
37  } else if (a->InheritsFrom("RooCategory")) {
38  catnames.push_back(a->GetName());
39  }
40  }
41  delete iter;
42  size_t nv = varnames.size(), nc = catnames.size();
43  printf(" bin ");
44  for (size_t j = 0; j < nv; ++j) { printf("%16.16s ", varnames[j].c_str()); }
45  for (size_t j = 0; j < nc; ++j) { printf("%16.16s ", catnames[j].c_str()); }
46  printf(" weight\n");
47  for (int i = 0, nb = data->numEntries(); i < nb; ++i) {
48  const RooArgSet *bin = data->get(i);
49  printf("%4d ",i);
50  for (size_t j = 0; j < nv; ++j) { printf("%16g ", bin->getRealValue(varnames[j].c_str())); }
51  for (size_t j = 0; j < nc; ++j) { printf("%16.16s ", bin->getCatLabel(catnames[j].c_str())); }
52  printf("%8.3f\n", data->weight());
53  }
54 }
55 
56 void utils::printRAD(const RooAbsData *d) {
57  if (d->InheritsFrom("RooDataHist") || d->numEntries() != 1) printRDH(const_cast<RooAbsData*>(d));
58  else d->get(0)->Print("V");
59 }
60 
61 void utils::printPdf(RooAbsPdf *pdf) {
62  std::cout << "Pdf " << pdf->GetName() << " parameters." << std::endl;
63  std::auto_ptr<RooArgSet> params(pdf->getVariables());
64  params->Print("V");
65 }
66 
67 
68 void utils::printPdf(RooStats::ModelConfig &mc) {
69  std::cout << "ModelConfig " << mc.GetName() << " (" << mc.GetTitle() << "): pdf parameters." << std::endl;
70  std::auto_ptr<RooArgSet> params(mc.GetPdf()->getVariables());
71  params->Print("V");
72 }
73 
74 void utils::printPdf(RooWorkspace *w, const char *pdfName) {
75  std::cout << "PDF " << pdfName << " parameters." << std::endl;
76  std::auto_ptr<RooArgSet> params(w->pdf(pdfName)->getVariables());
77  params->Print("V");
78 }
79 
80 RooAbsPdf *utils::factorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &constraints) {
81  assert(&pdf);
82  const std::type_info & id = typeid(pdf);
83  if (id == typeid(RooProdPdf)) {
84  //std::cout << " pdf is product pdf " << pdf.GetName() << std::endl;
85  RooProdPdf *prod = dynamic_cast<RooProdPdf *>(&pdf);
86  RooArgList newFactors; RooArgSet newOwned;
87  RooArgList list(prod->pdfList());
88  bool needNew = false;
89  for (int i = 0, n = list.getSize(); i < n; ++i) {
90  RooAbsPdf *pdfi = (RooAbsPdf *) list.at(i);
91  RooAbsPdf *newpdf = factorizePdf(observables, *pdfi, constraints);
92  //std::cout << " for " << pdfi->GetName() << " newpdf " << (newpdf == 0 ? "null" : (newpdf == pdfi ? "old" : "new")) << std::endl;
93  if (newpdf == 0) { needNew = true; continue; }
94  if (newpdf != pdfi) { needNew = true; newOwned.add(*newpdf); }
95  newFactors.add(*newpdf);
96  }
97  if (!needNew) { copyAttributes(pdf, *prod); return prod; }
98  else if (newFactors.getSize() == 0) return 0;
99  else if (newFactors.getSize() == 1) {
100  RooAbsPdf *ret = (RooAbsPdf *) newFactors.first()->Clone(TString::Format("%s_obsOnly", pdf.GetName()));
101  copyAttributes(pdf, *ret);
102  return ret;
103  }
104  RooProdPdf *ret = new RooProdPdf(TString::Format("%s_obsOnly", pdf.GetName()), "", newFactors);
105  ret->addOwnedComponents(newOwned);
106  copyAttributes(pdf, *ret);
107  return ret;
108  } else if (id == typeid(RooSimultaneous) || id == typeid(RooSimultaneousOpt)) {
109  RooSimultaneous *sim = dynamic_cast<RooSimultaneous *>(&pdf);
110  RooAbsCategoryLValue *cat = (RooAbsCategoryLValue *) sim->indexCat().Clone();
111  int nbins = cat->numBins((const char *)0);
112  TObjArray factorizedPdfs(nbins); RooArgSet newOwned;
113  bool needNew = false;
114  for (int ic = 0, nc = nbins; ic < nc; ++ic) {
115  cat->setBin(ic);
116  RooAbsPdf *pdfi = sim->getPdf(cat->getLabel());
117  RooAbsPdf *newpdf = factorizePdf(observables, *pdfi, constraints);
118  factorizedPdfs[ic] = newpdf;
119  if (newpdf == 0) { throw std::runtime_error(std::string("ERROR: channel ") + cat->getLabel() + " factorized to zero."); }
120  if (newpdf != pdfi) { needNew = true; newOwned.add(*newpdf); }
121  }
122  RooSimultaneous *ret = sim;
123  if (needNew) {
124  ret = new RooSimultaneous(TString::Format("%s_obsOnly", pdf.GetName()), "", (RooAbsCategoryLValue&) sim->indexCat());
125  for (int ic = 0, nc = nbins; ic < nc; ++ic) {
126  cat->setBin(ic);
127  RooAbsPdf *newpdf = (RooAbsPdf *) factorizedPdfs[ic];
128  if (newpdf) ret->addPdf(*newpdf, cat->getLabel());
129  }
130  ret->addOwnedComponents(newOwned);
131  }
132  delete cat;
133  if (id == typeid(RooSimultaneousOpt)) {
134  RooSimultaneousOpt *newret = new RooSimultaneousOpt(*ret);
135  newret->addOwnedComponents(RooArgSet(*ret));
136  ret = newret;
137  }
138  copyAttributes(pdf, *ret);
139  return ret;
140  } else if (pdf.dependsOn(observables)) {
141  return &pdf;
142  } else {
143  if (!constraints.contains(pdf)) constraints.add(pdf);
144  return 0;
145  }
146 
147 }
148 
149 void utils::factorizePdf(RooStats::ModelConfig &model, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints, bool debug) {
150  return factorizePdf(*model.GetObservables(), pdf, obsTerms, constraints, debug);
151 }
152 void utils::factorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &obsTerms, RooArgList &constraints, bool debug) {
153  assert(&pdf);
154  const std::type_info & id = typeid(pdf);
155  if (id == typeid(RooProdPdf)) {
156  RooProdPdf *prod = dynamic_cast<RooProdPdf *>(&pdf);
157  RooArgList list(prod->pdfList());
158  for (int i = 0, n = list.getSize(); i < n; ++i) {
159  RooAbsPdf *pdfi = (RooAbsPdf *) list.at(i);
160  factorizePdf(observables, *pdfi, obsTerms, constraints);
161  }
162  } else if (id == typeid(RooSimultaneous) || id == typeid(RooSimultaneousOpt)) {
163  RooSimultaneous *sim = dynamic_cast<RooSimultaneous *>(&pdf);
164  RooAbsCategoryLValue *cat = (RooAbsCategoryLValue *) sim->indexCat().Clone();
165  for (int ic = 0, nc = cat->numBins((const char *)0); ic < nc; ++ic) {
166  cat->setBin(ic);
167  RooAbsPdf *pdfi = sim->getPdf(cat->getLabel());
168  if (pdfi != 0) factorizePdf(observables, *pdfi, obsTerms, constraints);
169  }
170  delete cat;
171  } else if (pdf.dependsOn(observables)) {
172  if (!obsTerms.contains(pdf)) obsTerms.add(pdf);
173  } else {
174  if (!constraints.contains(pdf)) constraints.add(pdf);
175  }
176 }
177 void utils::factorizeFunc(const RooArgSet &observables, RooAbsReal &func, RooArgList &obsTerms, RooArgList &constraints, bool debug) {
178  RooAbsPdf *pdf = dynamic_cast<RooAbsPdf *>(&func);
179  if (pdf != 0) {
180  factorizePdf(observables, *pdf, obsTerms, constraints, debug);
181  return;
182  }
183  const std::type_info & id = typeid(func);
184  if (id == typeid(RooProduct)) {
185  RooProduct *prod = dynamic_cast<RooProduct *>(&func);
186  RooArgSet components(prod->components());
187  //std::cout << "Function " << func.GetName() << " is a RooProduct with " << components.getSize() << " components." << std::endl;
188  std::auto_ptr<TIterator> iter(components.createIterator());
189  for (RooAbsReal *funci = (RooAbsReal *) iter->Next(); funci != 0; funci = (RooAbsReal *) iter->Next()) {
190  //std::cout << " component " << funci->GetName() << " of type " << funci->ClassName() << std::endl;
191  factorizeFunc(observables, *funci, obsTerms, constraints);
192  }
193  } else if (func.dependsOn(observables)) {
194  if (!obsTerms.contains(func)) obsTerms.add(func);
195  } else {
196  if (!constraints.contains(func)) constraints.add(func);
197  }
198 }
199 
200 RooAbsPdf *utils::makeNuisancePdf(RooStats::ModelConfig &model, const char *name) {
201  return utils::makeNuisancePdf(*model.GetPdf(), *model.GetObservables(), name);
202 }
203 
204 RooAbsPdf *utils::makeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name) {
205  assert(&pdf);
206  RooArgList obsTerms, constraints;
207  factorizePdf(observables, pdf, obsTerms, constraints);
208  if (constraints.getSize() == 0) return 0;
209  return new RooProdPdf(name,"", constraints);
210 }
211 
212 RooAbsPdf *utils::makeObsOnlyPdf(RooStats::ModelConfig &model, const char *name) {
213  RooArgList obsTerms, constraints;
214  factorizePdf(model, *model.GetPdf(), obsTerms, constraints);
215  return new RooProdPdf(name,"", obsTerms);
216 }
217 
218 RooAbsPdf *utils::fullClonePdf(const RooAbsPdf *pdf, RooArgSet &holder, bool cloneLeafNodes) {
219  // Clone all FUNC compents by copying all branch nodes
220  RooArgSet tmp("RealBranchNodeList") ;
221  pdf->branchNodeServerList(&tmp);
222  tmp.snapshot(holder, cloneLeafNodes);
223  // Find the top level FUNC in the snapshot list
224  return (RooAbsPdf*) holder.find(pdf->GetName());
225 }
226 RooAbsReal *utils::fullCloneFunc(const RooAbsReal *pdf, RooArgSet &holder, bool cloneLeafNodes) {
227  // Clone all FUNC compents by copying all branch nodes
228  RooArgSet tmp("RealBranchNodeList") ;
229  pdf->branchNodeServerList(&tmp);
230  tmp.snapshot(holder, cloneLeafNodes);
231  // Find the top level FUNC in the snapshot list
232  return (RooAbsReal*) holder.find(pdf->GetName());
233 }
234 
235 
236 void utils::getClients(const RooAbsCollection &values, const RooAbsCollection &allObjects, RooAbsCollection &clients) {
237  std::auto_ptr<TIterator> iterAll(allObjects.createIterator());
238  std::auto_ptr<TIterator> iterVal(values.createIterator());
239  for (RooAbsArg *v = (RooAbsArg *) iterVal->Next(); v != 0; v = (RooAbsArg *) iterVal->Next()) {
240  if (typeid(*v) != typeid(RooRealVar)) continue;
241  std::auto_ptr<TIterator> clientIter(v->clientIterator());
242  for (RooAbsArg *a = (RooAbsArg *) clientIter->Next(); a != 0; a = (RooAbsArg *) clientIter->Next()) {
243  if (allObjects.containsInstance(*a) && !clients.containsInstance(*a)) clients.add(*a);
244  }
245  }
246 }
247 
248 bool utils::setAllConstant(const RooAbsCollection &coll, bool constant) {
249  bool changed = false;
250  std::auto_ptr<TIterator> iter(coll.createIterator());
251  for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
252  RooRealVar *v = dynamic_cast<RooRealVar *>(a);
253  if (v && (v->isConstant() != constant)) {
254  changed = true;
255  v->setConstant(constant);
256  }
257  }
258  return changed;
259 }
260 
261 bool utils::checkModel(const RooStats::ModelConfig &model, bool throwOnFail) {
262  bool ok = true; std::ostringstream errors;
263  std::auto_ptr<TIterator> iter;
264  RooAbsPdf *pdf = model.GetPdf(); if (pdf == 0) throw std::invalid_argument("Model without Pdf");
265  RooArgSet allowedToFloat;
266  if (model.GetObservables() == 0) {
267  ok = false; errors << "ERROR: model does not define observables.\n";
268  std::cout << errors.str() << std::endl;
269  if (throwOnFail) throw std::invalid_argument(errors.str()); else return false;
270  } else {
271  allowedToFloat.add(*model.GetObservables());
272  }
273  if (model.GetParametersOfInterest() == 0) {
274  ok = false; errors << "ERROR: model does not define parameters of interest.\n";
275  } else {
276  iter.reset(model.GetParametersOfInterest()->createIterator());
277  for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
278  RooRealVar *v = dynamic_cast<RooRealVar *>(a);
279  if (!v) { ok = false; errors << "ERROR: parameter of interest " << a->GetName() << " is a " << a->ClassName() << " and not a RooRealVar\n"; continue; }
280  if (v->isConstant()) { ok = false; errors << "ERROR: parameter of interest " << a->GetName() << " is constant\n"; continue; }
281  if (!pdf->dependsOn(*v)) { ok = false; errors << "ERROR: pdf does not depend on parameter of interest " << a->GetName() << "\n"; continue; }
282  allowedToFloat.add(*v);
283  }
284  }
285  if (model.GetNuisanceParameters() != 0) {
286  iter.reset(model.GetNuisanceParameters()->createIterator());
287  for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
288  RooRealVar *v = dynamic_cast<RooRealVar *>(a);
289  if (!v) { ok = false; errors << "ERROR: nuisance parameter " << a->GetName() << " is a " << a->ClassName() << " and not a RooRealVar\n"; continue; }
290  if (v->isConstant()) { ok = false; errors << "ERROR: nuisance parameter " << a->GetName() << " is constant\n"; continue; }
291  if (!pdf->dependsOn(*v)) { errors << "WARNING: pdf does not depend on nuisance parameter " << a->GetName() << "\n"; continue; }
292  allowedToFloat.add(*v);
293  }
294  }
295  if (model.GetGlobalObservables() != 0) {
296  iter.reset(model.GetGlobalObservables()->createIterator());
297  for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
298  RooRealVar *v = dynamic_cast<RooRealVar *>(a);
299  if (!v) { ok = false; errors << "ERROR: global observable " << a->GetName() << " is a " << a->ClassName() << " and not a RooRealVar\n"; continue; }
300  if (!v->isConstant()) { ok = false; errors << "ERROR: global observable " << a->GetName() << " is not constant\n"; continue; }
301  if (!pdf->dependsOn(*v)) { errors << "WARNING: pdf does not depend on global observable " << a->GetName() << "\n"; continue; }
302  }
303  }
304  std::auto_ptr<RooArgSet> params(pdf->getParameters(*model.GetObservables()));
305  iter.reset(params->createIterator());
306  for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) {
307  if (a->getAttribute("flatParam") && a->isConstant()) {
308  ok = false; errors << "ERROR: parameter " << a->GetName() << " is declared as flatParam but is constant.\n";
309  }
310  if (a->isConstant() || allowedToFloat.contains(*a)) continue;
311  if (a->getAttribute("flatParam")) {
312  RooRealVar *rrv = dynamic_cast<RooRealVar *>(a);
313  if (rrv->getVal() > rrv->getMax() || rrv->getVal() < rrv->getMin()) {
314  ok = false; errors << "ERROR: flatParam " << rrv->GetName() << " has a value " << rrv->getVal() <<
315  " outside of the defined range [" << rrv->getMin() << ", " << rrv->getMax() << "]\n";
316  }
317  } else {
318  errors << "WARNING: pdf parameter " << a->GetName() << " (type " << a->ClassName() << ") is not allowed to float (it's not nuisance, poi, observable or global observable\n";
319  }
320  }
321  iter.reset();
322  std::cout << errors.str() << std::endl;
323  if (!ok && throwOnFail) throw std::invalid_argument(errors.str());
324  return ok;
325 }
326 
327 RooSimultaneous * utils::rebuildSimPdf(const RooArgSet &observables, RooSimultaneous *sim) {
328  RooArgList constraints;
329  RooAbsCategoryLValue *cat = (RooAbsCategoryLValue *) sim->indexCat().Clone();
330  int nbins = cat->numBins((const char *)0);
331  TObjArray factorizedPdfs(nbins);
332  RooArgSet newOwned;
333  for (int ic = 0, nc = nbins; ic < nc; ++ic) {
334  cat->setBin(ic);
335  RooAbsPdf *pdfi = sim->getPdf(cat->getLabel());
336  if (pdfi == 0) { factorizedPdfs[ic] = 0; continue; }
337  RooAbsPdf *newpdf = factorizePdf(observables, *pdfi, constraints);
338  factorizedPdfs[ic] = newpdf;
339  if (newpdf == 0) { continue; }
340  if (newpdf != pdfi) { newOwned.add(*newpdf); }
341  }
342  RooSimultaneous *ret = new RooSimultaneous(TString::Format("%s_reloaded", sim->GetName()), "", (RooAbsCategoryLValue&) sim->indexCat());
343  for (int ic = 0, nc = nbins; ic < nc; ++ic) {
344  cat->setBin(ic);
345  RooAbsPdf *newpdf = (RooAbsPdf *) factorizedPdfs[ic];
346  if (newpdf) {
347  if (constraints.getSize() > 0) {
348  RooArgList allfactors(constraints); allfactors.add(*newpdf);
349  RooProdPdf *newerpdf = new RooProdPdf(TString::Format("%s_plus_constr", newpdf->GetName()), "", allfactors);
350  ret->addPdf(*newerpdf, cat->getLabel());
351  copyAttributes(*newpdf, *newerpdf);
352  newOwned.add(*newerpdf);
353  } else {
354  ret->addPdf(*newpdf, cat->getLabel());
355  }
356  }
357  }
358  ret->addOwnedComponents(newOwned);
359  copyAttributes(*sim, *ret);
360  delete cat;
361  return ret;
362 }
363 
364 void utils::copyAttributes(const RooAbsArg &from, RooAbsArg &to) {
365  if (&from == &to) return;
366  const std::set<std::string> attribs = from.attributes();
367  if (!attribs.empty()) {
368  for (std::set<std::string>::const_iterator it = attribs.begin(), ed = attribs.end(); it != ed; ++it) to.setAttribute(it->c_str());
369  }
370  const std::map<std::string, std::string> strattribs = from.stringAttributes();
371  if (!strattribs.empty()) {
372  for (std::map<std::string,std::string>::const_iterator it = strattribs.begin(), ed = strattribs.end(); it != ed; ++it) to.setStringAttribute(it->first.c_str(), it->second.c_str());
373  }
374 }
375 
376 void utils::guessChannelMode(RooSimultaneous &simPdf, RooAbsData &simData, bool verbose)
377 {
378  RooAbsCategoryLValue &cat = const_cast<RooAbsCategoryLValue &>(simPdf.indexCat());
379  TList *split = simData.split(cat, kTRUE);
380  for (int i = 0, n = cat.numBins((const char *)0); i < n; ++i) {
381  cat.setBin(i);
382  RooAbsPdf *pdf = simPdf.getPdf(cat.getLabel());
383  if (pdf->getAttribute("forceGenBinned") || pdf->getAttribute("forceGenUnbinned")) {
384  if (verbose) std::cout << " - " << cat.getLabel() << " has generation mode already set" << std::endl;
385  continue;
386  }
387  RooAbsData *spl = (RooAbsData *) split->FindObject(cat.getLabel());
388  if (spl == 0) {
389  if (verbose) std::cout << " - " << cat.getLabel() << " has no dataset, cannot guess" << std::endl;
390  continue;
391  }
392  if (spl->numEntries() != spl->sumEntries()) {
393  if (verbose) std::cout << " - " << cat.getLabel() << " has " << spl->numEntries() << " num entries of sum " << spl->sumEntries() << ", mark as binned" << std::endl;
394  pdf->setAttribute("forceGenBinned");
395  } else {
396  if (verbose) std::cout << " - " << cat.getLabel() << " has " << spl->numEntries() << " num entries of sum " << spl->sumEntries() << ", mark as unbinned" << std::endl;
397  pdf->setAttribute("forceGenUnbinned");
398  }
399  }
400 }
401 
402 std::vector<RooPlot *>
403 utils::makePlots(const RooAbsPdf &pdf, const RooAbsData &data, const char *signalSel, const char *backgroundSel, float rebinFactor) {
404  std::vector<RooPlot *> ret;
405  RooArgList constraints;
406  RooAbsPdf *facpdf = factorizePdf(*data.get(0), const_cast<RooAbsPdf &>(pdf), constraints);
407 
408  const std::type_info & id = typeid(*facpdf);
409  if (id == typeid(RooSimultaneous) || id == typeid(RooSimultaneousOpt)) {
410  const RooSimultaneous *sim = dynamic_cast<const RooSimultaneous *>(&pdf);
411  const RooAbsCategoryLValue &cat = (RooAbsCategoryLValue &) sim->indexCat();
412  TList *datasets = data.split(cat, true);
413  TIter next(datasets);
414  for (RooAbsData *ds = (RooAbsData *) next(); ds != 0; ds = (RooAbsData *) next()) {
415  RooAbsPdf *pdfi = sim->getPdf(ds->GetName());
416  std::auto_ptr<RooArgSet> obs(pdfi->getObservables(ds));
417  if (obs->getSize() == 0) break;
418  RooRealVar *x = dynamic_cast<RooRealVar *>(obs->first());
419  if (x == 0) continue;
420  int nbins = x->numBins(); if (nbins == 0) nbins = 100;
421  if (nbins/rebinFactor > 6) nbins = ceil(nbins/rebinFactor);
422  ret.push_back(x->frame(RooFit::Title(ds->GetName()), RooFit::Bins(nbins)));
423  ret.back()->SetName(ds->GetName());
424  ds->plotOn(ret.back());
425  if (signalSel && strlen(signalSel)) pdfi->plotOn(ret.back(), RooFit::LineColor(209), RooFit::Components(signalSel));
426  if (backgroundSel && strlen(backgroundSel)) pdfi->plotOn(ret.back(), RooFit::LineColor(206), RooFit::Components(backgroundSel));
427  pdfi->plotOn(ret.back());
428  delete ds;
429  }
430  delete datasets;
431  } else if (pdf.canBeExtended()) {
432  std::auto_ptr<RooArgSet> obs(pdf.getObservables(&data));
433  RooRealVar *x = dynamic_cast<RooRealVar *>(obs->first());
434  if (x != 0) {
435  ret.push_back(x->frame());
436  ret.back()->SetName("data");
437  data.plotOn(ret.back());
438  if (signalSel && strlen(signalSel)) pdf.plotOn(ret.back(), RooFit::LineColor(209), RooFit::Components(signalSel));
439  if (backgroundSel && strlen(backgroundSel)) pdf.plotOn(ret.back(), RooFit::LineColor(206), RooFit::Components(backgroundSel));
440  pdf.plotOn(ret.back());
441  }
442  }
443  if (facpdf != &pdf) { delete facpdf; }
444  return ret;
445 
446 }
447 
448 void utils::CheapValueSnapshot::readFrom(const RooAbsCollection &src) {
449  if (&src != src_) {
450  src_ = &src;
451  values_.resize(src.getSize());
452  }
453  RooLinkedListIter iter = src.iterator(); int i = 0;
454  for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) {
455  RooRealVar *rrv = dynamic_cast<RooRealVar *>(a);
456  if (rrv == 0) throw std::invalid_argument("Collection to read from contains a non-RooRealVar");
457  values_[i] = rrv->getVal();
458  }
459 }
460 
461 void utils::CheapValueSnapshot::writeTo(const RooAbsCollection &src) const {
462  if (&src == src_) {
463  RooLinkedListIter iter = src.iterator(); int i = 0;
464  for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) {
465  RooRealVar *rrv = dynamic_cast<RooRealVar *>(a);
466  rrv->setVal(values_[i]);
467  }
468  } else {
469  RooLinkedListIter iter = src_->iterator(); int i = 0;
470  for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) {
471  RooAbsArg *a2 = src.find(a->GetName()); if (a2 == 0) continue;
472  RooRealVar *rrv = dynamic_cast<RooRealVar *>(a2);
473  rrv->setVal(values_[i]);
474  }
475  }
476 }
477 
478 void utils::CheapValueSnapshot::Print(const char *fmt) const {
479  if (src_ == 0) { printf("<NIL>\n"); return; }
480  if (fmt[0] == 'V') {
481  RooLinkedListIter iter = src_->iterator(); int i = 0;
482  for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) {
483  printf(" %3d) %-30s = %9.6g\n", i, a->GetName(), values_[i]);
484  }
485  printf("\n");
486  } else {
487  src_->Print(fmt);
488  }
489 }
490 
const RooAbsCollection * src_
Definition: utils.h:83
int i
Definition: DBlmapReader.cc:9
std::vector< RooPlot * > makePlots(const RooAbsPdf &pdf, const RooAbsData &data, const char *signalSel=0, const char *backgroundSel=0, float rebinFactor=1.0)
make plots, if possible
Definition: utils.cc:403
bool setAllConstant(const RooAbsCollection &coll, bool constant=true)
set all RooRealVars to constants. return true if at least one changed status
Definition: utils.cc:248
void guessChannelMode(RooSimultaneous &simPdf, RooAbsData &simData, bool verbose=false)
Definition: utils.cc:376
void factorizeFunc(const RooArgSet &observables, RooAbsReal &pdf, RooArgList &obsTerms, RooArgList &otherTerms, bool debug=false)
factorize a RooAbsReal
Definition: utils.cc:177
std::vector< double > values_
Definition: utils.h:84
void getClients(const RooAbsCollection &values, const RooAbsCollection &allObjects, RooAbsCollection &clients)
add to &#39;clients&#39; all object within allObjects that directly depend on values
Definition: utils.cc:236
void writeTo(const RooAbsCollection &) const
Definition: utils.cc:461
RooAbsPdf * makeNuisancePdf(RooStats::ModelConfig &model, const char *name="nuisancePdf")
Definition: utils.cc:200
Definition: sim.h:19
const RooAbsCollection & src() const
Definition: utils.h:79
static const char * fmt
Definition: Version.cc:9
RooSimultaneous * rebuildSimPdf(const RooArgSet &observables, RooSimultaneous *pdf)
Definition: utils.cc:327
void printPdf(RooAbsPdf *pdf)
Definition: utils.cc:61
RooAbsPdf * fullClonePdf(const RooAbsPdf *pdf, RooArgSet &holder, bool cloneLeafNodes=false)
Definition: utils.cc:218
RooAbsPdf * factorizePdf(const RooArgSet &observables, RooAbsPdf &pdf, RooArgList &constraints)
Definition: utils.cc:80
int j
Definition: DBlmapReader.cc:9
void printRDH(RooAbsData *data)
Definition: utils.cc:30
RooAbsPdf * makeObsOnlyPdf(RooStats::ModelConfig &model, const char *name="obsPdf")
Note: doesn&#39;t recompose Simultaneous pdfs properly, for that use factorizePdf method.
Definition: utils.cc:212
RooAbsReal * fullCloneFunc(const RooAbsReal *pdf, RooArgSet &holder, bool cloneLeafNodes=false)
Definition: utils.cc:226
static std::string from(" from ")
bool checkModel(const RooStats::ModelConfig &model, bool throwOnFail=false)
Definition: utils.cc:261
void readFrom(const RooAbsCollection &)
Definition: utils.cc:448
JetCorrectorParametersCollection coll
Definition: classes.h:14
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
void printRAD(const RooAbsData *d)
Definition: utils.cc:56
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
double a
Definition: hdecay.h:121
void Print(const char *fmt) const
Definition: utils.cc:478
tuple cout
Definition: gather_cfg.py:121
x
Definition: VDTMath.h:216
#define debug
Definition: MEtoEDMFormat.h:34
double split
Definition: MVATrainer.cc:139
mathSSE::Vec4< T > v
void copyAttributes(const RooAbsArg &from, RooAbsArg &to)
Definition: utils.cc:364
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
T w() const