Logo ROOT   6.14/05
Reference Guide
RooAbsPdf.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * @(#)root/roofitcore:$Id$
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 
17 //////////////////////////////////////////////////////////////////////////////
18 /** \class RooAbsPdf
19  \ingroup Roofitcore
20 
21 RooAbsPdf is the abstract interface for all probability density
22 functions The class provides hybrid analytical/numerical
23 normalization for its implementations, error tracing and a MC
24 generator interface.
25 
26 A minimal implementation of a PDF class derived from RooAbsPdf
27 should overload the evaluate() function. This functions should
28 return PDFs value.
29 
30 
31 ### Normalization/Integration
32 
33 Although the normalization of a PDF is an integral part of a
34 probability density function, normalization is treated separately
35 in RooAbsPdf. The reason is that a RooAbsPdf object is more than a
36 PDF: it can be a building block for a more complex, composite PDF
37 if any of its variables are functions instead of variables. In
38 such cases the normalization of the composite may not be simply the
39 integral over the dependents of the top level PDF as these are
40 functions with potentially non-trivial Jacobian terms themselves.
41 Therefore
42 
43 **--> No explicit attempt should be made to normalize
44  the functions output in evaluate().**
45 
46 In addition, RooAbsPdf objects do not have a static concept of what
47 variables are parameters and what variables are dependents (which
48 need to be integrated over for a correct PDF normalization).
49 Instead the choice of normalization is always specified each time a
50 normalized values is requested from the PDF via the getVal()
51 method.
52 
53 RooAbsPdf manages the entire normalization logic of each PDF with
54 help of a RooRealIntegral object, which coordinates the integration
55 of a given choice of normalization. By default, RooRealIntegral will
56 perform a fully numeric integration of all dependents. However,
57 PDFs can advertise one or more (partial) analytical integrals of
58 their function, and these will be used by RooRealIntegral, if it
59 determines that this is safe (i.e. no hidden Jacobian terms,
60 multiplication with other PDFs that have one or more dependents in
61 commen etc)
62 
63 To implement analytical integrals, two functions must be implemented. First,
64 
65 ``Int_t getAnalyticalIntegral(const RooArgSet& integSet, RooArgSet& anaIntSet)``
66 
67 advertises the analytical integrals that are supported. 'integSet'
68 is the set of dependents for which integration is requested. The
69 function should copy the subset of dependents it can analytically
70 integrate to anaIntSet and return a unique identification code for
71 this integration configuration. If no integration can be
72 performed, zero should be returned. Second,
73 
74 ``Double_t analyticalIntegral(Int_t code)``
75 
76 Implements the actual analytical integral(s) advertised by
77 getAnalyticalIntegral. This functions will only be called with
78 codes returned by getAnalyticalIntegral, except code zero.
79 
80 The integration range for real each dependent to be integrated can
81 be obtained from the dependents' proxy functions min() and
82 max(). Never call these proxy functions for any proxy not known to
83 be a dependent via the integration code. Doing so may be
84 ill-defined, e.g. in case the proxy holds a function, and will
85 trigger an assert. Integrated category dependents should always be
86 summed over all of their states.
87 
88 
89 
90 ### Direct generation of observables
91 
92 Any PDF dependent can be generated with the accept/reject method,
93 but for certain PDFs more efficient methods may be implemented. To
94 implement direct generation of one or more observables, two
95 functions need to be implemented, similar to those for analytical
96 integrals:
97 
98 ``Int_t getGenerator(const RooArgSet& generateVars, RooArgSet& directVars)`` and
99 ``void generateEvent(Int_t code)``
100 
101 The first function advertises observables that can be generated,
102 similar to the way analytical integrals are advertised. The second
103 function implements the generator for the advertised observables
104 
105 The generated dependent values should be store in the proxy
106 objects. For this the assignment operator can be used (i.e. xProxy
107 = 3.0 ). Never call assign to any proxy not known to be a dependent
108 via the generation code. Doing so may be ill-defined, e.g. in case
109 the proxy holds a function, and will trigger an assert
110 
111 
112 */
113 
114 #include "RooFit.h"
115 #include "RooMsgService.h"
116 
117 #include "TClass.h"
118 #include "Riostream.h"
119 #include "TMath.h"
120 #include "TObjString.h"
121 #include "TPaveText.h"
122 #include "TList.h"
123 #include "TH1.h"
124 #include "TH2.h"
125 #include "TMatrixD.h"
126 #include "TMatrixDSym.h"
127 #include "RooAbsPdf.h"
128 #include "RooDataSet.h"
129 #include "RooArgSet.h"
130 #include "RooArgProxy.h"
131 #include "RooRealProxy.h"
132 #include "RooRealVar.h"
133 #include "RooGenContext.h"
134 #include "RooBinnedGenContext.h"
135 #include "RooPlot.h"
136 #include "RooCurve.h"
137 #include "RooNLLVar.h"
138 #include "RooMinuit.h"
139 #include "RooCategory.h"
140 #include "RooNameReg.h"
141 #include "RooCmdConfig.h"
142 #include "RooGlobalFunc.h"
143 #include "RooAddition.h"
144 #include "RooRandom.h"
145 #include "RooNumIntConfig.h"
146 #include "RooProjectedPdf.h"
147 #include "RooInt.h"
148 #include "RooCustomizer.h"
149 #include "RooConstraintSum.h"
150 #include "RooParamBinning.h"
151 #include "RooNumCdf.h"
152 #include "RooFitResult.h"
153 #include "RooNumGenConfig.h"
154 #include "RooCachedReal.h"
155 #include "RooXYChi2Var.h"
156 #include "RooChi2Var.h"
157 #include "RooMinimizer.h"
158 #include "RooRealIntegral.h"
159 #include "RooWorkspace.h"
160 #include "Math/CholeskyDecomp.h"
161 #include <string>
162 
163 using namespace std;
164 
166 ;
168 ;
169 
173 
174 ////////////////////////////////////////////////////////////////////////////////
175 /// Default constructor
176 
177 RooAbsPdf::RooAbsPdf() : _norm(0), _normSet(0), _specGeneratorConfig(0)
178 {
179  _errorCount = 0 ;
180  _negCount = 0 ;
181  _rawValue = 0 ;
182  _selectComp = kFALSE ;
183  _traceCount = 0 ;
184 }
185 
186 
187 
188 ////////////////////////////////////////////////////////////////////////////////
189 /// Constructor with name and title only
190 
191 RooAbsPdf::RooAbsPdf(const char *name, const char *title) :
192  RooAbsReal(name,title), _norm(0), _normSet(0), _normMgr(this,10), _selectComp(kTRUE), _specGeneratorConfig(0)
193 {
195  setTraceCounter(0) ;
196 }
197 
198 
199 
200 ////////////////////////////////////////////////////////////////////////////////
201 /// Constructor with name, title, and plot range
202 
203 RooAbsPdf::RooAbsPdf(const char *name, const char *title,
204  Double_t plotMin, Double_t plotMax) :
205  RooAbsReal(name,title,plotMin,plotMax), _norm(0), _normSet(0), _normMgr(this,10), _selectComp(kTRUE), _specGeneratorConfig(0)
206 {
208  setTraceCounter(0) ;
209 }
210 
211 
212 
213 ////////////////////////////////////////////////////////////////////////////////
214 /// Copy constructor
215 
216 RooAbsPdf::RooAbsPdf(const RooAbsPdf& other, const char* name) :
217  RooAbsReal(other,name), _norm(0), _normSet(0),
218  _normMgr(other._normMgr,this), _selectComp(other._selectComp), _normRange(other._normRange)
219 {
222 
223  if (other._specGeneratorConfig) {
225  } else {
227  }
228 }
229 
230 
231 
232 ////////////////////////////////////////////////////////////////////////////////
233 /// Destructor
234 
236 {
238 }
239 
240 
241 
242 ////////////////////////////////////////////////////////////////////////////////
243 /// Return current value, normalizated by integrating over
244 /// the observables in 'nset'. If 'nset' is 0, the unnormalized value.
245 /// is returned. All elements of 'nset' must be lvalues
246 ///
247 /// Unnormalized values are not cached
248 /// Doing so would be complicated as _norm->getVal() could
249 /// spoil the cache and interfere with returning the cached
250 /// return value. Since unnormalized calls are typically
251 /// done in integration calls, there is no performance hit.
252 
254 {
255  // Fast-track processing of clean-cache objects
256  // if (_operMode==AClean) {
257  // cout << "RooAbsPdf::getValV(" << this << "," << GetName() << ") CLEAN value = " << _value << endl ;
258  // return _value ;
259  // }
260 
261  // Special handling of case without normalization set (used in numeric integration of pdfs)
262  if (!nset) {
263  RooArgSet* tmp = _normSet ;
264  _normSet = 0 ;
265  Double_t val = evaluate() ;
266  _normSet = tmp ;
267  Bool_t error = traceEvalPdf(val) ;
268 
269  if (error) {
270 // raiseEvalError() ;
271  return 0 ;
272  }
273  return val ;
274  }
275 
276 
277  // Process change in last data set used
278  Bool_t nsetChanged(kFALSE) ;
279  if (nset!=_normSet || _norm==0) {
280  nsetChanged = syncNormalization(nset) ;
281  }
282 
283  // Return value of object. Calculated if dirty, otherwise cached value is returned.
284  if (isValueDirty() || nsetChanged || _norm->isValueDirty()) {
285 
286  // Evaluate numerator
287  Double_t rawVal = evaluate() ;
288  Bool_t error = traceEvalPdf(rawVal) ; // Error checking and printing
289 
290  // Evaluate denominator
291  Double_t normVal(_norm->getVal()) ;
292 
293  if (normVal<=0.) {
294  error=kTRUE ;
295  logEvalError("p.d.f normalization integral is zero or negative") ;
296  }
297 
298  // Raise global error flag if problems occur
299  if (error) {
300 // raiseEvalError() ;
301  _value = 0 ;
302  } else {
303  _value = rawVal / normVal ;
304 // cout << "RooAbsPdf::getValV(" << GetName() << ") writing _value = " << rawVal << "/" << normVal << " = " << _value << endl ;
305  }
306 
307  clearValueAndShapeDirty() ; //setValueDirty(kFALSE) ;
308  }
309 
310  return _value ;
311 }
312 
313 
314 
315 ////////////////////////////////////////////////////////////////////////////////
316 /// Analytical integral with normalization (see RooAbsReal::analyticalIntegralWN() for further information)
317 ///
318 /// This function applies the normalization specified by 'normSet' to the integral returned
319 /// by RooAbsReal::analyticalIntegral(). The passthrough scenario (code=0) is also changed
320 /// to return a normalized answer
321 
322 Double_t RooAbsPdf::analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName) const
323 {
324  cxcoutD(Eval) << "RooAbsPdf::analyticalIntegralWN(" << GetName() << ") code = " << code << " normset = " << (normSet?*normSet:RooArgSet()) << endl ;
325 
326 
327  if (code==0) return getVal(normSet) ;
328  if (normSet) {
329  return analyticalIntegral(code,rangeName) / getNorm(normSet) ;
330  } else {
331  return analyticalIntegral(code,rangeName) ;
332  }
333 }
334 
335 
336 
337 ////////////////////////////////////////////////////////////////////////////////
338 /// Check that passed value is positive and not 'not-a-number'. If
339 /// not, print an error, until the error counter reaches its set
340 /// maximum.
341 
343 {
344  // check for a math error or negative value
345  Bool_t error(kFALSE) ;
346  if (TMath::IsNaN(value)) {
347  logEvalError(Form("p.d.f value is Not-a-Number (%f), forcing value to zero",value)) ;
348  error=kTRUE ;
349  }
350  if (value<0) {
351  logEvalError(Form("p.d.f value is less than zero (%f), forcing value to zero",value)) ;
352  error=kTRUE ;
353  }
354 
355  // do nothing if we are no longer tracing evaluations and there was no error
356  if(!error) return error ;
357 
358  // otherwise, print out this evaluations input values and result
359  if(++_errorCount <= 10) {
360  cxcoutD(Tracing) << "*** Evaluation Error " << _errorCount << " ";
361  if(_errorCount == 10) cxcoutD(Tracing) << "(no more will be printed) ";
362  }
363  else {
364  return error ;
365  }
366 
367  Print() ;
368  return error ;
369 }
370 
371 
372 
373 
374 ////////////////////////////////////////////////////////////////////////////////
375 /// Return the integral of this PDF over all observables listed in 'nset'.
376 
378 {
379  if (!nset) return 1 ;
380 
381  syncNormalization(nset,kTRUE) ;
382  if (_verboseEval>1) cxcoutD(Tracing) << IsA()->GetName() << "::getNorm(" << GetName() << "): norm(" << _norm << ") = " << _norm->getVal() << endl ;
383 
384  Double_t ret = _norm->getVal() ;
385  if (ret==0.) {
386  if(++_errorCount <= 10) {
387  coutW(Eval) << "RooAbsPdf::getNorm(" << GetName() << ":: WARNING normalization is zero, nset = " ; nset->Print("1") ;
388  if(_errorCount == 10) coutW(Eval) << "RooAbsPdf::getNorm(" << GetName() << ") INFO: no more messages will be printed " << endl ;
389  }
390  }
391 
392  return ret ;
393 }
394 
395 
396 
397 ////////////////////////////////////////////////////////////////////////////////
398 /// Return pointer to RooAbsReal object that implements calculation of integral over observables iset in range
399 /// rangeName, optionally taking the integrand normalized over observables nset
400 
401 const RooAbsReal* RooAbsPdf::getNormObj(const RooArgSet* nset, const RooArgSet* iset, const TNamed* rangeName) const
402 {
403 
404  // Check normalization is already stored
405  CacheElem* cache = (CacheElem*) _normMgr.getObj(nset,iset,0,rangeName) ;
406  if (cache) {
407  return cache->_norm ;
408  }
409 
410  // If not create it now
411  RooArgSet* depList = getObservables(iset) ;
412  RooAbsReal* norm = createIntegral(*depList,*nset, *getIntegratorConfig(), RooNameReg::str(rangeName)) ;
413  delete depList ;
414 
415  // Store it in the cache
416  cache = new CacheElem(*norm) ;
417  _normMgr.setObj(nset,iset,cache,rangeName) ;
418 
419  // And return the newly created integral
420  return norm ;
421 }
422 
423 
424 
425 ////////////////////////////////////////////////////////////////////////////////
426 /// Verify that the normalization integral cached with this PDF
427 /// is valid for given set of normalization observables
428 ///
429 /// If not, the cached normalization integral (if any) is deleted
430 /// and a new integral is constructed for use with 'nset'
431 /// Elements in 'nset' can be discrete and real, but must be lvalues
432 ///
433 /// For functions that declare to be self-normalized by overloading the
434 /// selfNormalized() function, a unit normalization is always constructed
435 
436 Bool_t RooAbsPdf::syncNormalization(const RooArgSet* nset, Bool_t adjustProxies) const
437 {
438 
439 // cout << IsA()->GetName() << "::syncNormalization(" << GetName() << ") nset = " << nset << " = " << (nset?*nset:RooArgSet()) << endl ;
440 
441  _normSet = (RooArgSet*) nset ;
442 
443  // Check if data sets are identical
444  CacheElem* cache = (CacheElem*) _normMgr.getObj(nset) ;
445  if (cache) {
446 
447  Bool_t nsetChanged = (_norm!=cache->_norm) ;
448  _norm = cache->_norm ;
449 
450 
451 // cout << "returning existing object " << _norm->GetName() << endl ;
452 
453  if (nsetChanged && adjustProxies) {
454  // Update dataset pointers of proxies
455  ((RooAbsPdf*) this)->setProxyNormSet(nset) ;
456  }
457 
458  return nsetChanged ;
459  }
460 
461  // Update dataset pointers of proxies
462  if (adjustProxies) {
463  ((RooAbsPdf*) this)->setProxyNormSet(nset) ;
464  }
465 
466  RooArgSet* depList = getObservables(nset) ;
467 
468  if (_verboseEval>0) {
469  if (!selfNormalized()) {
470  cxcoutD(Tracing) << IsA()->GetName() << "::syncNormalization(" << GetName()
471  << ") recreating normalization integral " << endl ;
472  if (depList) depList->printStream(ccoutD(Tracing),kName|kValue|kArgs,kSingleLine) ; else ccoutD(Tracing) << "<none>" << endl ;
473  } else {
474  cxcoutD(Tracing) << IsA()->GetName() << "::syncNormalization(" << GetName() << ") selfNormalized, creating unit norm" << endl;
475  }
476  }
477 
478  // Destroy old normalization & create new
479  if (selfNormalized() || !dependsOn(*depList)) {
480  TString ntitle(GetTitle()) ; ntitle.Append(" Unit Normalization") ;
481  TString nname(GetName()) ; nname.Append("_UnitNorm") ;
482  _norm = new RooRealVar(nname.Data(),ntitle.Data(),1) ;
483  } else {
484  const char* nr = (_normRangeOverride.Length()>0 ? _normRangeOverride.Data() : (_normRange.Length()>0 ? _normRange.Data() : 0)) ;
485 
486 // cout << "RooAbsPdf::syncNormalization(" << GetName() << ") rangeName for normalization is " << (nr?nr:"<null>") << endl ;
487  RooAbsReal* normInt = createIntegral(*depList,*getIntegratorConfig(),nr) ;
488  normInt->getVal() ;
489 // cout << "resulting normInt = " << normInt->GetName() << endl ;
490 
491  const char* cacheParamsStr = getStringAttribute("CACHEPARAMINT") ;
492  if (cacheParamsStr && strlen(cacheParamsStr)) {
493 
494  RooArgSet* intParams = normInt->getVariables() ;
495 
496  RooNameSet cacheParamNames ;
497  cacheParamNames.setNameList(cacheParamsStr) ;
498  RooArgSet* cacheParams = cacheParamNames.select(*intParams) ;
499 
500  if (cacheParams->getSize()>0) {
501  cxcoutD(Caching) << "RooAbsReal::createIntObj(" << GetName() << ") INFO: constructing " << cacheParams->getSize()
502  << "-dim value cache for integral over " << *depList << " as a function of " << *cacheParams << " in range " << (nr?nr:"<default>") << endl ;
503  string name = Form("%s_CACHE_[%s]",normInt->GetName(),cacheParams->contentsString().c_str()) ;
504  RooCachedReal* cachedIntegral = new RooCachedReal(name.c_str(),name.c_str(),*normInt,*cacheParams) ;
505  cachedIntegral->setInterpolationOrder(2) ;
506  cachedIntegral->addOwnedComponents(*normInt) ;
507  cachedIntegral->setCacheSource(kTRUE) ;
508  if (normInt->operMode()==ADirty) {
509  cachedIntegral->setOperMode(ADirty) ;
510  }
511  normInt= cachedIntegral ;
512  }
513 
514  delete cacheParams ;
515  delete intParams ;
516  }
517  _norm = normInt ;
518  }
519 
520  // Register new normalization with manager (takes ownership)
521  cache = new CacheElem(*_norm) ;
522  _normMgr.setObj(nset,cache) ;
523 
524 // cout << "making new object " << _norm->GetName() << endl ;
525 
526  delete depList ;
527  return kTRUE ;
528 }
529 
530 
531 
532 ////////////////////////////////////////////////////////////////////////////////
533 /// WVE 08/21/01 Probably obsolete now.
534 
536 {
537  // Floating point error checking and tracing for given float value
538 
539  // check for a math error or negative value
540  Bool_t error= TMath::IsNaN(value) || (value < 0);
541 
542  // do nothing if we are no longer tracing evaluations and there was no error
543  if(!error && _traceCount <= 0) return error ;
544 
545  // otherwise, print out this evaluations input values and result
546  if(error && ++_errorCount <= 10) {
547  cxcoutD(Tracing) << "*** Evaluation Error " << _errorCount << " ";
548  if(_errorCount == 10) ccoutD(Tracing) << "(no more will be printed) ";
549  }
550  else if(_traceCount > 0) {
551  ccoutD(Tracing) << '[' << _traceCount-- << "] ";
552  }
553  else {
554  return error ;
555  }
556 
557  Print() ;
558 
559  return error ;
560 }
561 
562 
563 
564 
565 ////////////////////////////////////////////////////////////////////////////////
566 /// Reset error counter to given value, limiting the number
567 /// of future error messages for this pdf to 'resetValue'
568 
570 {
571  _errorCount = resetValue ;
572  _negCount = resetValue ;
573 }
574 
575 
576 
577 ////////////////////////////////////////////////////////////////////////////////
578 /// Reset trace counter to given value, limiting the
579 /// number of future trace messages for this pdf to 'value'
580 
582 {
583  if (!allNodes) {
584  _traceCount = value ;
585  return ;
586  } else {
587  RooArgList branchList ;
588  branchNodeServerList(&branchList) ;
589  TIterator* iter = branchList.createIterator() ;
590  RooAbsArg* arg ;
591  while((arg=(RooAbsArg*)iter->Next())) {
592  RooAbsPdf* pdf = dynamic_cast<RooAbsPdf*>(arg) ;
593  if (pdf) pdf->setTraceCounter(value,kFALSE) ;
594  }
595  delete iter ;
596  }
597 
598 }
599 
600 
601 
602 
603 ////////////////////////////////////////////////////////////////////////////////
604 /// Return the log of the current value with given normalization
605 /// An error message is printed if the argument of the log is negative.
606 
608 {
609  Double_t prob = getVal(nset) ;
610 
611  if (fabs(prob)>1e6) {
612  coutW(Eval) << "RooAbsPdf::getLogVal(" << GetName() << ") WARNING: large likelihood value: " << prob << endl ;
613  }
614 
615  if(prob < 0) {
616 
617  logEvalError("getLogVal() top-level p.d.f evaluates to a negative number") ;
618 
619  return 0;
620  }
621  if(prob == 0) {
622 
623  logEvalError("getLogVal() top-level p.d.f evaluates to zero") ;
624 
625  return log((double)0);
626  }
627 
628  if (TMath::IsNaN(prob)) {
629  logEvalError("getLogVal() top-level p.d.f evaluates to NaN") ;
630 
631  return log((double)0);
632 
633  }
634  return log(prob);
635 }
636 
637 
638 
639 ////////////////////////////////////////////////////////////////////////////////
640 /// Returned the extended likelihood term (Nexpect - Nobserved*log(NExpected)
641 /// of this PDF for the given number of observed events
642 ///
643 /// For successfull operation the PDF implementation must indicate
644 /// it is extendable by overloading canBeExtended() and must
645 /// implemented the expectedEvents() function.
646 
647 Double_t RooAbsPdf::extendedTerm(Double_t observed, const RooArgSet* nset) const
648 {
649  // check if this PDF supports extended maximum likelihood fits
650  if(!canBeExtended()) {
651  coutE(InputArguments) << fName << ": this PDF does not support extended maximum likelihood"
652  << endl;
653  return 0;
654  }
655 
656  Double_t expected= expectedEvents(nset);
657  if(expected < 0) {
658  coutE(InputArguments) << fName << ": calculated negative expected events: " << expected
659  << endl;
660  return 0;
661  }
662 
663 
664  // Explicitly handle case Nobs=Nexp=0
665  if (fabs(expected)<1e-10 && fabs(observed)<1e-10) {
666  return 0 ;
667  }
668 
669  // Check for errors in Nexpected
670  if (expected<0 || TMath::IsNaN(expected)) {
671  logEvalError("extendedTerm #expected events is <0 or NaN") ;
672  return 0 ;
673  }
674 
675  // calculate and return the negative log-likelihood of the Poisson
676  // factor for this dataset, dropping the constant log(observed!)
677  // Double_t extra=0;
678  // if(observed<1000000) {
679  // Double_t Delta1 = (expected-observed);
680  // Double_t Delta2 = observed*(log(expected)-log(observed+1));
681  // Double_t Const3 = 0.5*log(observed+1);
682  // extra= Delta1 - Delta2 + Const3;
683 
684  // cout << " extra obs = " << observed << " exp = " << expected << endl ;
685  // cout << " extra orig = " << expected - observed*log(expected) << endl ;
686  // cout << " extra orig fix = " << expected - observed*log(expected) + log(TMath::Gamma(observed+1)) << endl ;
687  // cout << " extra new = " << extra << endl ;
688 
689  // } else {
690  // Double_t sigma_square=expected;
691  // Double_t diff=observed-expected;
692  // extra=-log(sigma_square)/2 + (diff*diff)/(2*sigma_square);
693  // }
694 
695  Double_t extra= expected - observed*log(expected);
696 
697 // cout << "RooAbsPdf::extendedTerm(" << GetName() << ") observed = " << observed << " expected = " << expected << endl ;
698 
699  Bool_t trace(kFALSE) ;
700  if(trace) {
701  cxcoutD(Tracing) << fName << "::extendedTerm: expected " << expected << " events, got "
702  << observed << " events. extendedTerm = " << extra << endl;
703  }
704 
705 // cout << "RooAbsPdf::extendedTerm(" << GetName() << ") nExp = " << expected << " nObs = " << observed << endl ;
706  return extra;
707 }
708 
709 
710 
711 ////////////////////////////////////////////////////////////////////////////////
712 /// Construct representation of -log(L) of PDFwith given dataset. If dataset is unbinned, an unbinned likelihood is constructed. If the dataset
713 /// is binned, a binned likelihood is constructed.
714 ///
715 /// The following named arguments are supported
716 ///
717 /// ConditionalObservables(const RooArgSet& set) -- Do not normalize PDF over listed observables
718 /// Extended(Bool_t flag) -- Add extended likelihood term, off by default
719 /// Range(const char* name) -- Fit only data inside range with given name
720 /// Range(Double_t lo, Double_t hi) -- Fit only data inside given range. A range named "fit" is created on the fly on all observables.
721 /// Multiple comma separated range names can be specified.
722 /// SumCoefRange(const char* name) -- Set the range in which to interpret the coefficients of RooAddPdf components
723 /// NumCPU(int num, int strat) -- Parallelize NLL calculation on num CPUs
724 ///
725 /// Strategy 0 = RooFit::BulkPartition (Default) --> Divide events in N equal chunks
726 /// Strategy 1 = RooFit::Interleave --> Process event i%N in process N. Recommended for binned data with
727 /// a substantial number of zero-bins, which will be distributed across processes more equitably in this strategy
728 /// Strategy 2 = RooFit::SimComponents --> Process each component likelihood of a RooSimultaneous fully in a single process
729 /// and distribute components over processes. This approach can be benificial if normalization calculation time
730 /// dominates the total computation time of a component (since the normalization calculation must be performed
731 /// in each process in strategies 0 and 1. However beware that if the RooSimultaneous components do not share many
732 /// parameters this strategy is inefficient: as most minuit-induced likelihood calculations involve changing
733 /// a single parameter, only 1 of the N processes will be active most of the time if RooSimultaneous components
734 /// do not share many parameters
735 /// Strategy 3 = RooFit::Hybrid --> Follow strategy 0 for all RooSimultaneous components, except those with less than
736 /// 30 dataset entries, for which strategy 2 is followed.
737 ///
738 /// Optimize(Bool_t flag) -- Activate constant term optimization (on by default)
739 /// SplitRange(Bool_t flag) -- Use separate fit ranges in a simultaneous fit. Actual range name for each
740 /// subsample is assumed to by rangeName_{indexState} where indexState
741 /// is the state of the master index category of the simultaneous fit
742 /// Constrain(const RooArgSet&pars) -- For p.d.f.s that contain internal parameter constraint terms, only apply constraints to given subset of parameters
743 /// ExternalConstraints(const RooArgSet& ) -- Include given external constraints to likelihood
744 /// GlobalObservables(const RooArgSet&) -- Define the set of normalization observables to be used for the constraint terms.
745 /// If none are specified the constrained parameters are used
746 /// GlobalObservablesTag(const char* tagName) -- Define the set of normalization observables to be used for the constraint terms by a string attribute
747 /// associated with pdf observables that match the given tagName
748 /// Verbose(Bool_t flag) -- Constrols RooFit informational messages in likelihood construction
749 /// CloneData(Bool flag) -- Use clone of dataset in NLL (default is true)
750 /// Offset(Bool_t) -- Offset likelihood by initial value (so that starting value of FCN in minuit is zero). This
751 /// can improve numeric stability in simultaneously fits with components with large likelihood values
752 ///
753 ///
754 
755 RooAbsReal* RooAbsPdf::createNLL(RooAbsData& data, const RooCmdArg& arg1, const RooCmdArg& arg2, const RooCmdArg& arg3, const RooCmdArg& arg4,
756  const RooCmdArg& arg5, const RooCmdArg& arg6, const RooCmdArg& arg7, const RooCmdArg& arg8)
757 {
758  RooLinkedList l ;
759  l.Add((TObject*)&arg1) ; l.Add((TObject*)&arg2) ;
760  l.Add((TObject*)&arg3) ; l.Add((TObject*)&arg4) ;
761  l.Add((TObject*)&arg5) ; l.Add((TObject*)&arg6) ;
762  l.Add((TObject*)&arg7) ; l.Add((TObject*)&arg8) ;
763  return createNLL(data,l) ;
764 }
765 
766 
767 
768 
769 ////////////////////////////////////////////////////////////////////////////////
770 /// Construct representation of -log(L) of PDFwith given dataset. If dataset is unbinned, an unbinned likelihood is constructed. If the dataset
771 /// is binned, a binned likelihood is constructed.
772 ///
773 /// See RooAbsPdf::createNLL(RooAbsData& data, RooCmdArg arg1, RooCmdArg arg2, RooCmdArg arg3, RooCmdArg arg4,
774 /// RooCmdArg arg5, RooCmdArg arg6, RooCmdArg arg7, RooCmdArg arg8)
775 ///
776 /// for documentation of options
777 
779 {
780 
781  // Select the pdf-specific commands
782  RooCmdConfig pc(Form("RooAbsPdf::createNLL(%s)",GetName())) ;
783 
784  pc.defineString("rangeName","RangeWithName",0,"",kTRUE) ;
785  pc.defineString("addCoefRange","SumCoefRange",0,"") ;
786  pc.defineString("globstag","GlobalObservablesTag",0,"") ;
787  pc.defineDouble("rangeLo","Range",0,-999.) ;
788  pc.defineDouble("rangeHi","Range",1,-999.) ;
789  pc.defineInt("splitRange","SplitRange",0,0) ;
790  pc.defineInt("ext","Extended",0,2) ;
791  pc.defineInt("numcpu","NumCPU",0,1) ;
792  pc.defineInt("interleave","NumCPU",1,0) ;
793  pc.defineInt("verbose","Verbose",0,0) ;
794  pc.defineInt("optConst","Optimize",0,0) ;
795  pc.defineInt("cloneData","CloneData",2,0) ;
796  pc.defineSet("projDepSet","ProjectedObservables",0,0) ;
797  pc.defineSet("cPars","Constrain",0,0) ;
798  pc.defineSet("glObs","GlobalObservables",0,0) ;
799  pc.defineInt("constrAll","Constrained",0,0) ;
800  pc.defineInt("doOffset","OffsetLikelihood",0,0) ;
801  pc.defineSet("extCons","ExternalConstraints",0,0) ;
802  pc.defineMutex("Range","RangeWithName") ;
803  pc.defineMutex("Constrain","Constrained") ;
804  pc.defineMutex("GlobalObservables","GlobalObservablesTag") ;
805 
806  // Process and check varargs
807  pc.process(cmdList) ;
808  if (!pc.ok(kTRUE)) {
809  return 0 ;
810  }
811 
812  // Decode command line arguments
813  const char* rangeName = pc.getString("rangeName",0,kTRUE) ;
814  const char* addCoefRangeName = pc.getString("addCoefRange",0,kTRUE) ;
815  const char* globsTag = pc.getString("globstag",0,kTRUE) ;
816  Int_t ext = pc.getInt("ext") ;
817  Int_t numcpu = pc.getInt("numcpu") ;
818  RooFit::MPSplit interl = (RooFit::MPSplit) pc.getInt("interleave") ;
819 
820  Int_t splitr = pc.getInt("splitRange") ;
821  Bool_t verbose = pc.getInt("verbose") ;
822  Int_t optConst = pc.getInt("optConst") ;
823  Int_t cloneData = pc.getInt("cloneData") ;
824  Int_t doOffset = pc.getInt("doOffset") ;
825 
826  // If no explicit cloneData command is specified, cloneData is set to true if optimization is activated
827  if (cloneData==2) {
828  cloneData = optConst ;
829  }
830 
831 
832  RooArgSet* cPars = pc.getSet("cPars") ;
833  RooArgSet* glObs = pc.getSet("glObs") ;
834  if (pc.hasProcessed("GlobalObservablesTag")) {
835  if (glObs) delete glObs ;
836  RooArgSet* allVars = getVariables() ;
837  glObs = (RooArgSet*) allVars->selectByAttrib(globsTag,kTRUE) ;
838  coutI(Minimization) << "User-defined specification of global observables definition with tag named '" << globsTag << "'" << endl ;
839  delete allVars ;
840  } else if (!pc.hasProcessed("GlobalObservables")) {
841 
842  // Neither GlobalObservables nor GlobalObservablesTag has been processed - try if a default tag is defined in the head node
843  // Check if head not specifies default global observable tag
844  const char* defGlobObsTag = getStringAttribute("DefaultGlobalObservablesTag") ;
845  if (defGlobObsTag) {
846  coutI(Minimization) << "p.d.f. provides built-in specification of global observables definition with tag named '" << defGlobObsTag << "'" << endl ;
847  if (glObs) delete glObs ;
848  RooArgSet* allVars = getVariables() ;
849  glObs = (RooArgSet*) allVars->selectByAttrib(defGlobObsTag,kTRUE) ;
850  }
851  }
852 
853 
854  Bool_t doStripDisconnected=kFALSE ;
855 
856  // If no explicit list of parameters to be constrained is specified apply default algorithm
857  // All terms of RooProdPdfs that do not contain observables and share a parameters with one or more
858  // terms that do contain observables are added as constraints.
859  if (!cPars) {
860  cPars = getParameters(data,kFALSE) ;
861  doStripDisconnected=kTRUE ;
862  }
863  const RooArgSet* extCons = pc.getSet("extCons") ;
864 
865  // Process automatic extended option
866  if (ext==2) {
867  ext = ((extendMode()==CanBeExtended || extendMode()==MustBeExtended)) ? 1 : 0 ;
868  if (ext) {
869  coutI(Minimization) << "p.d.f. provides expected number of events, including extended term in likelihood." << endl ;
870  }
871  }
872 
873  if (pc.hasProcessed("Range")) {
874  Double_t rangeLo = pc.getDouble("rangeLo") ;
875  Double_t rangeHi = pc.getDouble("rangeHi") ;
876 
877  // Create range with name 'fit' with above limits on all observables
878  RooArgSet* obs = getObservables(&data) ;
879  TIterator* iter = obs->createIterator() ;
880  RooAbsArg* arg ;
881  while((arg=(RooAbsArg*)iter->Next())) {
882  RooRealVar* rrv = dynamic_cast<RooRealVar*>(arg) ;
883  if (rrv) rrv->setRange("fit",rangeLo,rangeHi) ;
884  }
885  // Set range name to be fitted to "fit"
886  rangeName = "fit" ;
887  }
888 
889  RooArgSet projDeps ;
890  RooArgSet* tmp = pc.getSet("projDepSet") ;
891  if (tmp) {
892  projDeps.add(*tmp) ;
893  }
894 
895  // Construct NLL
897  RooAbsReal* nll ;
898  string baseName = Form("nll_%s_%s",GetName(),data.GetName()) ;
899  if (!rangeName || strchr(rangeName,',')==0) {
900  // Simple case: default range, or single restricted range
901  //cout<<"FK: Data test 1: "<<data.sumEntries()<<endl;
902 
903  nll = new RooNLLVar(baseName.c_str(),"-log(likelihood)",*this,data,projDeps,ext,rangeName,addCoefRangeName,numcpu,interl,verbose,splitr,cloneData) ;
904 
905  } else {
906  // Composite case: multiple ranges
907  RooArgList nllList ;
908  const size_t bufSize = strlen(rangeName)+1;
909  char* buf = new char[bufSize] ;
910  strlcpy(buf,rangeName,bufSize) ;
911  char* token = strtok(buf,",") ;
912  while(token) {
913  RooAbsReal* nllComp = new RooNLLVar(Form("%s_%s",baseName.c_str(),token),"-log(likelihood)",*this,data,projDeps,ext,token,addCoefRangeName,numcpu,interl,verbose,splitr,cloneData) ;
914  nllList.add(*nllComp) ;
915  token = strtok(0,",") ;
916  }
917  delete[] buf ;
918  nll = new RooAddition(baseName.c_str(),"-log(likelihood)",nllList,kTRUE) ;
919  }
921 
922  // Collect internal and external constraint specifications
923  RooArgSet allConstraints ;
924 
925  if (_myws && _myws->set(Form("CACHE_CONSTR_OF_PDF_%s_FOR_OBS_%s", GetName(), RooNameSet(*data.get()).content()))) {
926 
927  // retrieve from cache
928  const RooArgSet *constr =
929  _myws->set(Form("CACHE_CONSTR_OF_PDF_%s_FOR_OBS_%s", GetName(), RooNameSet(*data.get()).content()));
930  coutI(Minimization) << "createNLL picked up cached consraints from workspace with " << constr->getSize()
931  << " entries" << endl;
932  allConstraints.add(*constr);
933 
934  } else {
935 
936  if (cPars && cPars->getSize() > 0) {
937  RooArgSet *constraints = getAllConstraints(*data.get(), *cPars, doStripDisconnected);
938  allConstraints.add(*constraints);
939  delete constraints;
940  }
941  if (extCons) {
942  allConstraints.add(*extCons);
943  }
944 
945  // write to cache
946  if (_myws) {
947  // cout << "createNLL: creating cache for allconstraints=" << allConstraints << endl ;
948  coutI(Minimization) << "createNLL: caching constraint set under name "
949  << Form("CONSTR_OF_PDF_%s_FOR_OBS_%s", GetName(), RooNameSet(*data.get()).content())
950  << " with " << allConstraints.getSize() << " entries" << endl;
952  Form("CACHE_CONSTR_OF_PDF_%s_FOR_OBS_%s", GetName(), RooNameSet(*data.get()).content()), allConstraints);
953  }
954  }
955 
956  // Include constraints, if any, in likelihood
957  RooAbsReal* nllCons(0) ;
958  if (allConstraints.getSize()>0 && cPars) {
959 
960  coutI(Minimization) << " Including the following contraint terms in minimization: " << allConstraints << endl ;
961  if (glObs) {
962  coutI(Minimization) << "The following global observables have been defined: " << *glObs << endl ;
963  }
964  nllCons = new RooConstraintSum(Form("%s_constr",baseName.c_str()),"nllCons",allConstraints,glObs ? *glObs : *cPars) ;
965  nllCons->setOperMode(ADirty) ;
966  RooAbsReal* orignll = nll ;
967 
968  nll = new RooAddition(Form("%s_with_constr",baseName.c_str()),"nllWithCons",RooArgSet(*nll,*nllCons)) ;
969  nll->addOwnedComponents(RooArgSet(*orignll,*nllCons)) ;
970  }
971 
972 
973  if (optConst) {
975  }
976 
977  if (doStripDisconnected) {
978  delete cPars ;
979  }
980 
981  if (doOffset) {
982  nll->enableOffsetting(kTRUE) ;
983  }
984 
985  return nll ;
986 }
987 
988 
989 
990 
991 
992 
993 ////////////////////////////////////////////////////////////////////////////////
994 /// Fit PDF to given dataset. If dataset is unbinned, an unbinned maximum likelihood is performed. If the dataset
995 /// is binned, a binned maximum likelihood is performed. By default the fit is executed through the MINUIT
996 /// commands MIGRAD, HESSE in succession.
997 ///
998 /// The following named arguments are supported
999 ///
1000 /// Options to control construction of -log(L)
1001 /// ------------------------------------------
1002 /// ConditionalObservables(const RooArgSet& set) -- Do not normalize PDF over listed observables
1003 /// Extended(Bool_t flag) -- Add extended likelihood term, off by default
1004 /// Range(const char* name) -- Fit only data inside range with given name
1005 /// Range(Double_t lo, Double_t hi) -- Fit only data inside given range. A range named "fit" is created on the fly on all observables.
1006 /// Multiple comma separated range names can be specified.
1007 /// SumCoefRange(const char* name) -- Set the range in which to interpret the coefficients of RooAddPdf components
1008 /// NumCPU(int num, int strat) -- Parallelize NLL calculation on num CPUs
1009 ///
1010 /// Strategy 0 = RooFit::BulkPartition (Default) --> Divide events in N equal chunks
1011 /// Strategy 1 = RooFit::Interleave --> Process event i%N in process N. Recommended for binned data with
1012 /// a substantial number of zero-bins, which will be distributed across processes more equitably in this strategy
1013 /// Strategy 2 = RooFit::SimComponents --> Process each component likelihood of a RooSimultaneous fully in a single process
1014 /// and distribute components over processes. This approach can be benificial if normalization calculation time
1015 /// dominates the total computation time of a component (since the normalization calculation must be performed
1016 /// in each process in strategies 0 and 1. However beware that if the RooSimultaneous components do not share many
1017 /// parameters this strategy is inefficient: as most minuit-induced likelihood calculations involve changing
1018 /// a single parameter, only 1 of the N processes will be active most of the time if RooSimultaneous components
1019 /// do not share many parameters
1020 /// Strategy 3 = RooFit::Hybrid --> Follow strategy 0 for all RooSimultaneous components, except those with less than
1021 /// 30 dataset entries, for which strategy 2 is followed.
1022 ///
1023 /// SplitRange(Bool_t flag) -- Use separate fit ranges in a simultaneous fit. Actual range name for each
1024 /// subsample is assumed to by rangeName_{indexState} where indexState
1025 /// is the state of the master index category of the simultaneous fit
1026 /// Constrained() -- Apply all constrained contained in the p.d.f. in the likelihood
1027 /// Contrain(const RooArgSet&pars) -- Apply constraints to listed parameters in likelihood using internal constrains in p.d.f
1028 /// GlobalObservables(const RooArgSet&) -- Define the set of normalization observables to be used for the constraint terms.
1029 /// If none are specified the constrained parameters are used
1030 /// ExternalConstraints(const RooArgSet& ) -- Include given external constraints to likelihood
1031 /// Offset(Bool_t) -- Offset likelihood by initial value (so that starting value of FCN in minuit is zero). This
1032 /// can improve numeric stability in simultaneously fits with components with large likelihood values
1033 ///
1034 /// Options to control flow of fit procedure
1035 /// ----------------------------------------
1036 ///
1037 /// Minimizer(type,algo) -- Choose minimization package and algorithm to use. Default is MINUIT/MIGRAD through the RooMinimizer
1038 /// interface, but others can be specified (through RooMinimizer interface). Select OldMinuit to use
1039 /// MINUIT through the old RooMinuit interface
1040 ///
1041 /// Type Algorithm
1042 /// ------ ---------
1043 /// OldMinuit migrad, simplex, minimize (=migrad+simplex), migradimproved (=migrad+improve)
1044 /// Minuit migrad, simplex, minimize (=migrad+simplex), migradimproved (=migrad+improve)
1045 /// Minuit2 migrad, simplex, minimize, scan
1046 /// GSLMultiMin conjugatefr, conjugatepr, bfgs, bfgs2, steepestdescent
1047 /// GSLSimAn -
1048 ///
1049 ///
1050 /// InitialHesse(Bool_t flag) -- Flag controls if HESSE before MIGRAD as well, off by default
1051 /// Optimize(Bool_t flag) -- Activate constant term optimization of test statistic during minimization (on by default)
1052 /// Hesse(Bool_t flag) -- Flag controls if HESSE is run after MIGRAD, on by default
1053 /// Minos(Bool_t flag) -- Flag controls if MINOS is run after HESSE, off by default
1054 /// Minos(const RooArgSet& set) -- Only run MINOS on given subset of arguments
1055 /// Save(Bool_t flag) -- Flac controls if RooFitResult object is produced and returned, off by default
1056 /// Strategy(Int_t flag) -- Set Minuit strategy (0 through 2, default is 1)
1057 /// FitOptions(const char* optStr) -- Steer fit with classic options string (for backward compatibility). Use of this option
1058 /// excludes use of any of the new style steering options.
1059 ///
1060 /// SumW2Error(Bool_t flag) -- Apply correaction to errors and covariance matrix using sum-of-weights covariance matrix
1061 /// to obtain correct error for weighted likelihood fits. If this option is activated the
1062 /// corrected covariance matrix is calculated as Vcorr = V C-1 V, where V is the original
1063 /// covariance matrix and C is the inverse of the covariance matrix calculated using the
1064 /// weights squared
1065 ///
1066 /// Options to control informational output
1067 /// ---------------------------------------
1068 /// Verbose(Bool_t flag) -- Flag controls if verbose output is printed (NLL, parameter changes during fit
1069 /// Timer(Bool_t flag) -- Time CPU and wall clock consumption of fit steps, off by default
1070 /// PrintLevel(Int_t level) -- Set Minuit print level (-1 through 3, default is 1). At -1 all RooFit informational
1071 /// messages are suppressed as well
1072 /// Warnings(Bool_t flag) -- Enable or disable MINUIT warnings (enabled by default)
1073 /// PrintEvalErrors(Int_t numErr) -- Control number of p.d.f evaluation errors printed per likelihood evaluation. A negative
1074 /// value suppress output completely, a zero value will only print the error count per p.d.f component,
1075 /// a positive value is will print details of each error up to numErr messages per p.d.f component.
1076 ///
1077 ///
1078 
1079 RooFitResult* RooAbsPdf::fitTo(RooAbsData& data, const RooCmdArg& arg1, const RooCmdArg& arg2, const RooCmdArg& arg3, const RooCmdArg& arg4,
1080  const RooCmdArg& arg5, const RooCmdArg& arg6, const RooCmdArg& arg7, const RooCmdArg& arg8)
1081 {
1082  RooLinkedList l ;
1083  l.Add((TObject*)&arg1) ; l.Add((TObject*)&arg2) ;
1084  l.Add((TObject*)&arg3) ; l.Add((TObject*)&arg4) ;
1085  l.Add((TObject*)&arg5) ; l.Add((TObject*)&arg6) ;
1086  l.Add((TObject*)&arg7) ; l.Add((TObject*)&arg8) ;
1087  return fitTo(data,l) ;
1088 }
1089 
1090 
1091 
1092 ////////////////////////////////////////////////////////////////////////////////
1093 /// Fit PDF to given dataset. If dataset is unbinned, an unbinned maximum likelihood is performed. If the dataset
1094 /// is binned, a binned maximum likelihood is performed. By default the fit is executed through the MINUIT
1095 /// commands MIGRAD, HESSE and MINOS in succession.
1096 ///
1097 /// See RooAbsPdf::fitTo(RooAbsData& data, RooCmdArg arg1, RooCmdArg arg2, RooCmdArg arg3, RooCmdArg arg4,
1098 /// RooCmdArg arg5, RooCmdArg arg6, RooCmdArg arg7, RooCmdArg arg8)
1099 ///
1100 /// for documentation of options
1101 
1103 {
1104 
1105  // Select the pdf-specific commands
1106  RooCmdConfig pc(Form("RooAbsPdf::fitTo(%s)",GetName())) ;
1107 
1108  RooLinkedList fitCmdList(cmdList) ;
1109  RooLinkedList nllCmdList = pc.filterCmdList(fitCmdList,"ProjectedObservables,Extended,Range,RangeWithName,SumCoefRange,NumCPU,SplitRange,Constrained,Constrain,ExternalConstraints,CloneData,GlobalObservables,GlobalObservablesTag,OffsetLikelihood") ;
1110 
1111  pc.defineString("fitOpt","FitOptions",0,"") ;
1112  pc.defineInt("optConst","Optimize",0,2) ;
1113  pc.defineInt("verbose","Verbose",0,0) ;
1114  pc.defineInt("doSave","Save",0,0) ;
1115  pc.defineInt("doTimer","Timer",0,0) ;
1116  pc.defineInt("plevel","PrintLevel",0,1) ;
1117  pc.defineInt("strat","Strategy",0,1) ;
1118  pc.defineInt("initHesse","InitialHesse",0,0) ;
1119  pc.defineInt("hesse","Hesse",0,1) ;
1120  pc.defineInt("minos","Minos",0,0) ;
1121  pc.defineInt("ext","Extended",0,2) ;
1122  pc.defineInt("numcpu","NumCPU",0,1) ;
1123  pc.defineInt("numee","PrintEvalErrors",0,10) ;
1124  pc.defineInt("doEEWall","EvalErrorWall",0,1) ;
1125  pc.defineInt("doWarn","Warnings",0,1) ;
1126  pc.defineInt("doSumW2","SumW2Error",0,-1) ;
1127  pc.defineInt("doOffset","OffsetLikelihood",0,0) ;
1128  pc.defineString("mintype","Minimizer",0,"Minuit") ;
1129  pc.defineString("minalg","Minimizer",1,"minuit") ;
1130  pc.defineObject("minosSet","Minos",0,0) ;
1131  pc.defineSet("cPars","Constrain",0,0) ;
1132  pc.defineSet("extCons","ExternalConstraints",0,0) ;
1133  pc.defineMutex("FitOptions","Verbose") ;
1134  pc.defineMutex("FitOptions","Save") ;
1135  pc.defineMutex("FitOptions","Timer") ;
1136  pc.defineMutex("FitOptions","Strategy") ;
1137  pc.defineMutex("FitOptions","InitialHesse") ;
1138  pc.defineMutex("FitOptions","Hesse") ;
1139  pc.defineMutex("FitOptions","Minos") ;
1140  pc.defineMutex("Range","RangeWithName") ;
1141  pc.defineMutex("InitialHesse","Minimizer") ;
1142 
1143  // Process and check varargs
1144  pc.process(fitCmdList) ;
1145  if (!pc.ok(kTRUE)) {
1146  return 0 ;
1147  }
1148 
1149  // Decode command line arguments
1150  const char* fitOpt = pc.getString("fitOpt",0,kTRUE) ;
1151  Int_t optConst = pc.getInt("optConst") ;
1152  Int_t verbose = pc.getInt("verbose") ;
1153  Int_t doSave = pc.getInt("doSave") ;
1154  Int_t doTimer = pc.getInt("doTimer") ;
1155  Int_t plevel = pc.getInt("plevel") ;
1156  Int_t strat = pc.getInt("strat") ;
1157  Int_t initHesse= pc.getInt("initHesse") ;
1158  Int_t hesse = pc.getInt("hesse") ;
1159  Int_t minos = pc.getInt("minos") ;
1160  Int_t numee = pc.getInt("numee") ;
1161  Int_t doEEWall = pc.getInt("doEEWall") ;
1162  Int_t doWarn = pc.getInt("doWarn") ;
1163  Int_t doSumW2 = pc.getInt("doSumW2") ;
1164  const RooArgSet* minosSet = static_cast<RooArgSet*>(pc.getObject("minosSet")) ;
1165 #ifdef __ROOFIT_NOROOMINIMIZER
1166  const char* minType =0 ;
1167 #else
1168  const char* minType = pc.getString("mintype","Minuit") ;
1169  const char* minAlg = pc.getString("minalg","minuit") ;
1170 #endif
1171 
1172  // Determine if the dataset has weights
1173  Bool_t weightedData = data.isNonPoissonWeighted() ;
1174 
1175  // Warn user that a SumW2Error() argument should be provided if weighted data is offered
1176  if (weightedData && doSumW2==-1) {
1177  coutW(InputArguments) << "RooAbsPdf::fitTo(" << GetName() << ") WARNING: a likelihood fit is request of what appears to be weighted data. " << endl
1178  << " While the estimated values of the parameters will always be calculated taking the weights into account, " << endl
1179  << " there are multiple ways to estimate the errors on these parameter values. You are advised to make an " << endl
1180  << " explicit choice on the error calculation: " << endl
1181  << " - Either provide SumW2Error(kTRUE), to calculate a sum-of-weights corrected HESSE error matrix " << endl
1182  << " (error will be proportional to the number of events)" << endl
1183  << " - Or provide SumW2Error(kFALSE), to return errors from original HESSE error matrix" << endl
1184  << " (which will be proportional to the sum of the weights)" << endl
1185  << " If you want the errors to reflect the information contained in the provided dataset, choose kTRUE. " << endl
1186  << " If you want the errors to reflect the precision you would be able to obtain with an unweighted dataset " << endl
1187  << " with 'sum-of-weights' events, choose kFALSE." << endl ;
1188  }
1189 
1190 
1191  // Warn user that sum-of-weights correction does not apply to MINOS errrors
1192  if (doSumW2==1 && minos) {
1193  coutW(InputArguments) << "RooAbsPdf::fitTo(" << GetName() << ") WARNING: sum-of-weights correction does not apply to MINOS errors" << endl ;
1194  }
1195 
1196  RooAbsReal* nll = createNLL(data,nllCmdList) ;
1197  RooFitResult *ret = 0 ;
1198 
1199  // Instantiate MINUIT
1200 
1201  if (string(minType)!="OldMinuit") {
1202 
1203 #ifndef __ROOFIT_NOROOMINIMIZER
1204  RooMinimizer m(*nll) ;
1205 
1206  m.setMinimizerType(minType) ;
1207 
1208  m.setEvalErrorWall(doEEWall) ;
1209  if (doWarn==0) {
1210  // m.setNoWarn() ; WVE FIX THIS
1211  }
1212 
1213  m.setPrintEvalErrors(numee) ;
1214  if (plevel!=1) {
1215  m.setPrintLevel(plevel) ;
1216  }
1217 
1218  if (optConst) {
1219  // Activate constant term optimization
1220  m.optimizeConst(optConst) ;
1221  }
1222 
1223  if (fitOpt) {
1224 
1225  // Play fit options as historically defined
1226  ret = m.fit(fitOpt) ;
1227 
1228  } else {
1229 
1230  if (verbose) {
1231  // Activate verbose options
1232  m.setVerbose(1) ;
1233  }
1234  if (doTimer) {
1235  // Activate timer options
1236  m.setProfile(1) ;
1237  }
1238 
1239  if (strat!=1) {
1240  // Modify fit strategy
1241  m.setStrategy(strat) ;
1242  }
1243 
1244  if (initHesse) {
1245  // Initialize errors with hesse
1246  m.hesse() ;
1247  }
1248 
1249  // Minimize using chosen algorithm
1250  m.minimize(minType,minAlg) ;
1251 
1252  if (hesse) {
1253  // Evaluate errors with Hesse
1254  m.hesse() ;
1255  }
1256 
1257  if (doSumW2==1 && m.getNPar()>0) {
1258  // Make list of RooNLLVar components of FCN
1259  RooArgSet* comps = nll->getComponents();
1260  vector<RooNLLVar*> nllComponents;
1261  nllComponents.reserve(comps->getSize());
1262  TIterator* citer = comps->createIterator();
1263  RooAbsArg* arg;
1264  while ((arg=(RooAbsArg*)citer->Next())) {
1265  RooNLLVar* nllComp = dynamic_cast<RooNLLVar*>(arg);
1266  if (!nllComp) continue;
1267  nllComponents.push_back(nllComp);
1268  }
1269  delete citer;
1270  delete comps;
1271 
1272  // Calculated corrected errors for weighted likelihood fits
1273  RooFitResult* rw = m.save();
1274  for (vector<RooNLLVar*>::iterator it = nllComponents.begin(); nllComponents.end() != it; ++it) {
1275  (*it)->applyWeightSquared(kTRUE);
1276  }
1277  coutI(Fitting) << "RooAbsPdf::fitTo(" << GetName() << ") Calculating sum-of-weights-squared correction matrix for covariance matrix" << endl ;
1278  m.hesse();
1279  RooFitResult* rw2 = m.save();
1280  for (vector<RooNLLVar*>::iterator it = nllComponents.begin(); nllComponents.end() != it; ++it) {
1281  (*it)->applyWeightSquared(kFALSE);
1282  }
1283 
1284  // Apply correction matrix
1285  const TMatrixDSym& matV = rw->covarianceMatrix();
1286  TMatrixDSym matC = rw2->covarianceMatrix();
1288  CholeskyDecompGenDim<Double_t> decomp(matC.GetNrows(), matC);
1289  if (!decomp) {
1290  coutE(Fitting) << "RooAbsPdf::fitTo(" << GetName()
1291  << ") ERROR: Cannot apply sum-of-weights correction to covariance matrix: correction matrix calculated with weight-squared is singular" <<endl ;
1292  } else {
1293  // replace C by its inverse
1294  decomp.Invert(matC);
1295  // the class lies about the matrix being symmetric, so fill in the
1296  // part above the diagonal
1297  for (int i = 0; i < matC.GetNrows(); ++i)
1298  for (int j = 0; j < i; ++j) matC(j, i) = matC(i, j);
1299  matC.Similarity(matV);
1300  // C now contiains V C^-1 V
1301  // Propagate corrected errors to parameters objects
1302  m.applyCovarianceMatrix(matC);
1303  }
1304 
1305  delete rw;
1306  delete rw2;
1307  }
1308 
1309  if (minos) {
1310  // Evaluate errs with Minos
1311  if (minosSet) {
1312  m.minos(*minosSet) ;
1313  } else {
1314  m.minos() ;
1315  }
1316  }
1317 
1318  // Optionally return fit result
1319  if (doSave) {
1320  string name = Form("fitresult_%s_%s",GetName(),data.GetName()) ;
1321  string title = Form("Result of fit of p.d.f. %s to dataset %s",GetName(),data.GetName()) ;
1322  ret = m.save(name.c_str(),title.c_str()) ;
1323  }
1324 
1325  }
1326  if (optConst) {
1327  m.optimizeConst(0) ;
1328  }
1329 
1330 #endif
1331 
1332  } else {
1333 
1334  RooMinuit m(*nll) ;
1335 
1336  m.setEvalErrorWall(doEEWall) ;
1337  if (doWarn==0) {
1338  m.setNoWarn() ;
1339  }
1340 
1341  m.setPrintEvalErrors(numee) ;
1342  if (plevel!=1) {
1343  m.setPrintLevel(plevel) ;
1344  }
1345 
1346  if (optConst) {
1347  // Activate constant term optimization
1348  m.optimizeConst(optConst) ;
1349  }
1350 
1351  if (fitOpt) {
1352 
1353  // Play fit options as historically defined
1354  ret = m.fit(fitOpt) ;
1355 
1356  } else {
1357 
1358  if (verbose) {
1359  // Activate verbose options
1360  m.setVerbose(1) ;
1361  }
1362  if (doTimer) {
1363  // Activate timer options
1364  m.setProfile(1) ;
1365  }
1366 
1367  if (strat!=1) {
1368  // Modify fit strategy
1369  m.setStrategy(strat) ;
1370  }
1371 
1372  if (initHesse) {
1373  // Initialize errors with hesse
1374  m.hesse() ;
1375  }
1376 
1377  // Minimize using migrad
1378  m.migrad() ;
1379 
1380  if (hesse) {
1381  // Evaluate errors with Hesse
1382  m.hesse() ;
1383  }
1384 
1385  if (doSumW2==1 && m.getNPar()>0) {
1386 
1387  // Make list of RooNLLVar components of FCN
1388  list<RooNLLVar*> nllComponents ;
1389  RooArgSet* comps = nll->getComponents() ;
1390  RooAbsArg* arg ;
1391  TIterator* citer = comps->createIterator() ;
1392  while((arg=(RooAbsArg*)citer->Next())) {
1393  RooNLLVar* nllComp = dynamic_cast<RooNLLVar*>(arg) ;
1394  if (nllComp) {
1395  nllComponents.push_back(nllComp) ;
1396  }
1397  }
1398  delete citer ;
1399  delete comps ;
1400 
1401  // Calculated corrected errors for weighted likelihood fits
1402  RooFitResult* rw = m.save() ;
1403  for (list<RooNLLVar*>::iterator iter1=nllComponents.begin() ; iter1!=nllComponents.end() ; ++iter1) {
1404  (*iter1)->applyWeightSquared(kTRUE) ;
1405  }
1406  coutI(Fitting) << "RooAbsPdf::fitTo(" << GetName() << ") Calculating sum-of-weights-squared correction matrix for covariance matrix" << endl ;
1407  m.hesse() ;
1408  RooFitResult* rw2 = m.save() ;
1409  for (list<RooNLLVar*>::iterator iter2=nllComponents.begin() ; iter2!=nllComponents.end() ; ++iter2) {
1410  (*iter2)->applyWeightSquared(kFALSE) ;
1411  }
1412 
1413  // Apply correction matrix
1414  const TMatrixDSym& matV = rw->covarianceMatrix();
1415  TMatrixDSym matC = rw2->covarianceMatrix();
1417  CholeskyDecompGenDim<Double_t> decomp(matC.GetNrows(), matC);
1418  if (!decomp) {
1419  coutE(Fitting) << "RooAbsPdf::fitTo(" << GetName()
1420  << ") ERROR: Cannot apply sum-of-weights correction to covariance matrix: correction matrix calculated with weight-squared is singular" <<endl ;
1421  } else {
1422  // replace C by its inverse
1423  decomp.Invert(matC);
1424  // the class lies about the matrix being symmetric, so fill in the
1425  // part above the diagonal
1426  for (int i = 0; i < matC.GetNrows(); ++i)
1427  for (int j = 0; j < i; ++j) matC(j, i) = matC(i, j);
1428  matC.Similarity(matV);
1429  // C now contiains V C^-1 V
1430  // Propagate corrected errors to parameters objects
1431  m.applyCovarianceMatrix(matC);
1432  }
1433 
1434  delete rw ;
1435  delete rw2 ;
1436  }
1437 
1438  if (minos) {
1439  // Evaluate errs with Minos
1440  if (minosSet) {
1441  m.minos(*minosSet) ;
1442  } else {
1443  m.minos() ;
1444  }
1445  }
1446 
1447  // Optionally return fit result
1448  if (doSave) {
1449  string name = Form("fitresult_%s_%s",GetName(),data.GetName()) ;
1450  string title = Form("Result of fit of p.d.f. %s to dataset %s",GetName(),data.GetName()) ;
1451  ret = m.save(name.c_str(),title.c_str()) ;
1452  }
1453 
1454  }
1455 
1456  if (optConst) {
1457  m.optimizeConst(0) ;
1458  }
1459 
1460  }
1461 
1462 
1463 
1464  // Cleanup
1465  delete nll ;
1466  return ret ;
1467 }
1468 
1469 
1470 
1471 ////////////////////////////////////////////////////////////////////////////////
1472 /// Internal back-end function to steer chi2 fits
1473 
1475 {
1476  // Select the pdf-specific commands
1477  RooCmdConfig pc(Form("RooAbsPdf::chi2FitTo(%s)",GetName())) ;
1478 
1479  // Pull arguments to be passed to chi2 construction from list
1480  RooLinkedList fitCmdList(cmdList) ;
1481  RooLinkedList chi2CmdList = pc.filterCmdList(fitCmdList,"Range,RangeWithName,NumCPU,Optimize,ProjectedObservables,AddCoefRange,SplitRange,DataError,Extended") ;
1482 
1483  RooAbsReal* chi2 = createChi2(data,chi2CmdList) ;
1484  RooFitResult* ret = chi2FitDriver(*chi2,fitCmdList) ;
1485 
1486  // Cleanup
1487  delete chi2 ;
1488  return ret ;
1489 }
1490 
1491 
1492 
1493 
1494 ////////////////////////////////////////////////////////////////////////////////
1495 /// Create a chi-2 from a histogram and this function.
1496 ///
1497 /// The following named arguments are supported
1498 ///
1499 /// Options to control construction of the chi^2
1500 /// ------------------------------------------
1501 /// Extended() -- Use expected number of events of an extended p.d.f as normalization
1502 /// DataError() -- Choose between Expected error [RooAbsData::Expected] , or Observed error (e.g. Sum-of-weights [RooAbsData:SumW2] or Poisson interval [RooAbsData::Poisson] )
1503 /// Default is AUTO : Expected error for unweighted data, Sum-of-weights for weighted data
1504 /// NumCPU() -- Activate parallel processing feature
1505 /// Range() -- Fit only selected region
1506 /// SumCoefRange() -- Set the range in which to interpret the coefficients of RooAddPdf components
1507 /// SplitRange() -- Fit range is split by index catory of simultaneous PDF
1508 /// ConditionalObservables() -- Define projected observables
1509 
1511  const RooCmdArg& arg3, const RooCmdArg& arg4, const RooCmdArg& arg5,
1512  const RooCmdArg& arg6, const RooCmdArg& arg7, const RooCmdArg& arg8)
1513 {
1514  RooLinkedList cmdList ;
1515  cmdList.Add((TObject*)&arg1) ; cmdList.Add((TObject*)&arg2) ;
1516  cmdList.Add((TObject*)&arg3) ; cmdList.Add((TObject*)&arg4) ;
1517  cmdList.Add((TObject*)&arg5) ; cmdList.Add((TObject*)&arg6) ;
1518  cmdList.Add((TObject*)&arg7) ; cmdList.Add((TObject*)&arg8) ;
1519 
1520  RooCmdConfig pc(Form("RooAbsPdf::createChi2(%s)",GetName())) ;
1521  pc.defineString("rangeName","RangeWithName",0,"",kTRUE) ;
1522  pc.allowUndefined(kTRUE) ;
1523  pc.process(cmdList) ;
1524  if (!pc.ok(kTRUE)) {
1525  return 0 ;
1526  }
1527  const char* rangeName = pc.getString("rangeName",0,kTRUE) ;
1528 
1529  // Construct Chi2
1531  RooAbsReal* chi2 ;
1532  string baseName = Form("chi2_%s_%s",GetName(),data.GetName()) ;
1533 
1534  if (!rangeName || strchr(rangeName,',')==0) {
1535  // Simple case: default range, or single restricted range
1536 
1537  chi2 = new RooChi2Var(baseName.c_str(),baseName.c_str(),*this,data,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8) ;
1538 
1539  } else {
1540 
1541  // Find which argument is RangeWithName
1542  const RooCmdArg* rarg(0) ;
1543  string rcmd = "RangeWithName" ;
1544  if (arg1.GetName()==rcmd) rarg = &arg1 ;
1545  if (arg2.GetName()==rcmd) rarg = &arg2 ;
1546  if (arg3.GetName()==rcmd) rarg = &arg3 ;
1547  if (arg4.GetName()==rcmd) rarg = &arg4 ;
1548  if (arg5.GetName()==rcmd) rarg = &arg5 ;
1549  if (arg6.GetName()==rcmd) rarg = &arg6 ;
1550  if (arg7.GetName()==rcmd) rarg = &arg7 ;
1551  if (arg8.GetName()==rcmd) rarg = &arg8 ;
1552 
1553  // Composite case: multiple ranges
1554  RooArgList chi2List ;
1555  const size_t bufSize = strlen(rangeName)+1;
1556  char* buf = new char[bufSize] ;
1557  strlcpy(buf,rangeName,bufSize) ;
1558  char* token = strtok(buf,",") ;
1559  while(token) {
1560  RooCmdArg subRangeCmd = RooFit::Range(token) ;
1561  // Construct chi2 while substituting original RangeWithName argument with subrange argument created above
1562  RooAbsReal* chi2Comp = new RooChi2Var(Form("%s_%s",baseName.c_str(),token),"chi^2",*this,data,
1563  &arg1==rarg?subRangeCmd:arg1,&arg2==rarg?subRangeCmd:arg2,
1564  &arg3==rarg?subRangeCmd:arg3,&arg4==rarg?subRangeCmd:arg4,
1565  &arg5==rarg?subRangeCmd:arg5,&arg6==rarg?subRangeCmd:arg6,
1566  &arg7==rarg?subRangeCmd:arg7,&arg8==rarg?subRangeCmd:arg8) ;
1567  chi2List.add(*chi2Comp) ;
1568  token = strtok(0,",") ;
1569  }
1570  delete[] buf ;
1571  chi2 = new RooAddition(baseName.c_str(),"chi^2",chi2List,kTRUE) ;
1572  }
1574 
1575 
1576  return chi2 ;
1577 }
1578 
1579 
1580 
1581 
1582 ////////////////////////////////////////////////////////////////////////////////
1583 /// Internal back-end function to create a chi^2 from a p.d.f. and a dataset
1584 
1586 {
1587  // Select the pdf-specific commands
1588  RooCmdConfig pc(Form("RooAbsPdf::fitTo(%s)",GetName())) ;
1589 
1590  pc.defineInt("integrate","Integrate",0,0) ;
1591  pc.defineObject("yvar","YVar",0,0) ;
1592 
1593  // Process and check varargs
1594  pc.process(cmdList) ;
1595  if (!pc.ok(kTRUE)) {
1596  return 0 ;
1597  }
1598 
1599  // Decode command line arguments
1600  Bool_t integrate = pc.getInt("integrate") ;
1601  RooRealVar* yvar = (RooRealVar*) pc.getObject("yvar") ;
1602 
1603  string name = Form("chi2_%s_%s",GetName(),data.GetName()) ;
1604 
1605  if (yvar) {
1606  return new RooXYChi2Var(name.c_str(),name.c_str(),*this,data,*yvar,integrate) ;
1607  } else {
1608  return new RooXYChi2Var(name.c_str(),name.c_str(),*this,data,integrate) ;
1609  }
1610 }
1611 
1612 
1613 
1614 
1615 ////////////////////////////////////////////////////////////////////////////////
1616 /// Print value of p.d.f, also print normalization integral that was last used, if any
1617 
1618 void RooAbsPdf::printValue(ostream& os) const
1619 {
1620  getVal() ;
1621 
1622  if (_norm) {
1623  os << evaluate() << "/" << _norm->getVal() ;
1624  } else {
1625  os << evaluate() ;
1626  }
1627 }
1628 
1629 
1630 
1631 ////////////////////////////////////////////////////////////////////////////////
1632 /// Print multi line detailed information of this RooAbsPdf
1633 
1634 void RooAbsPdf::printMultiline(ostream& os, Int_t contents, Bool_t verbose, TString indent) const
1635 {
1636  RooAbsReal::printMultiline(os,contents,verbose,indent);
1637  os << indent << "--- RooAbsPdf ---" << endl;
1638  os << indent << "Cached value = " << _value << endl ;
1639  if (_norm) {
1640  os << indent << " Normalization integral: " << endl ;
1641  TString moreIndent(indent) ; moreIndent.Append(" ") ;
1642  _norm->printStream(os,kName|kAddress|kTitle|kValue|kArgs,kSingleLine,moreIndent.Data()) ;
1643  }
1644 }
1645 
1646 
1647 
1648 ////////////////////////////////////////////////////////////////////////////////
1649 /// Return a binned generator context
1650 
1652 {
1653  return new RooBinnedGenContext(*this,vars,0,0,verbose) ;
1654 }
1655 
1656 
1657 ////////////////////////////////////////////////////////////////////////////////
1658 /// Interface function to create a generator context from a p.d.f. This default
1659 /// implementation returns a 'standard' context that works for any p.d.f
1660 
1662  const RooArgSet* auxProto, Bool_t verbose) const
1663 {
1664  return new RooGenContext(*this,vars,prototype,auxProto,verbose) ;
1665 }
1666 
1667 
1668 ////////////////////////////////////////////////////////////////////////////////
1669 
1670 RooAbsGenContext* RooAbsPdf::autoGenContext(const RooArgSet &vars, const RooDataSet* prototype, const RooArgSet* auxProto,
1671  Bool_t verbose, Bool_t autoBinned, const char* binnedTag) const
1672 {
1673  if (prototype || (auxProto && auxProto->getSize()>0)) {
1674  return genContext(vars,prototype,auxProto,verbose);
1675  }
1676 
1677  RooAbsGenContext *context(0) ;
1678  if ( (autoBinned & isBinnedDistribution(vars)) || ( binnedTag && strlen(binnedTag) && (getAttribute(binnedTag)||string(binnedTag)=="*"))) {
1679  context = binnedGenContext(vars,verbose) ;
1680  } else {
1681  context= genContext(vars,0,0,verbose);
1682  }
1683  return context ;
1684 }
1685 
1686 
1687 
1688 ////////////////////////////////////////////////////////////////////////////////
1689 /// Generate a new dataset containing the specified variables with events sampled from our distribution.
1690 /// Generate the specified number of events or expectedEvents() if not specified.
1691 ///
1692 /// Any variables of this PDF that are not in whatVars will use their
1693 /// current values and be treated as fixed parameters. Returns zero
1694 /// in case of an error. The caller takes ownership of the returned
1695 /// dataset.
1696 ///
1697 /// The following named arguments are supported
1698 ///
1699 /// Name(const char* name) -- Name of the output dataset
1700 /// Verbose(Bool_t flag) -- Print informational messages during event generation
1701 /// Extended() -- The actual number of events generated will be sampled from a Poisson distribution
1702 /// with mu=nevt. For use with extended maximum likelihood fits
1703 /// AutoBinned(Bool_t flag) -- Automatically deploy binned generation for binned distributions (e.g. RooHistPdf, sums and products of RooHistPdfs etc)
1704 /// NB: Datasets that are generated in binned mode are returned as weighted unbinned datasets
1705 ///
1706 /// GenBinned(const char* tag) -- Use binned generation for all component pdfs that have 'setAttribute(tag)' set
1707 /// AllBinned() -- As above, but for all components.
1708 ///
1709 /// Note that the notion of components is only meaningful for simultaneous pdf
1710 /// as binned generation is always executed at the top-level node for a regular
1711 /// pdf, so for those it only mattes that the top-level node is tagged.
1712 ///
1713 /// ProtoData(const RooDataSet& data, -- Use specified dataset as prototype dataset. If randOrder is set to true
1714 /// Bool_t randOrder) the order of the events in the dataset will be read in a random order
1715 /// if the requested number of events to be generated does not match the
1716 /// number of events in the prototype dataset
1717 ///
1718 /// If ProtoData() is used, the specified existing dataset as a prototype: the new dataset will contain
1719 /// the same number of events as the prototype (unless otherwise specified), and any prototype variables not in
1720 /// whatVars will be copied into the new dataset for each generated event and also used to set our PDF parameters.
1721 /// The user can specify a number of events to generate that will override the default. The result is a
1722 /// copy of the prototype dataset with only variables in whatVars randomized. Variables in whatVars that
1723 /// are not in the prototype will be added as new columns to the generated dataset.
1724 
1725 RooDataSet *RooAbsPdf::generate(const RooArgSet& whatVars, Int_t nEvents, const RooCmdArg& arg1,
1726  const RooCmdArg& arg2, const RooCmdArg& arg3,const RooCmdArg& arg4, const RooCmdArg& arg5)
1727 {
1728  return generate(whatVars,RooFit::NumEvents(nEvents),arg1,arg2,arg3,arg4,arg5) ;
1729 }
1730 
1731 
1732 
1733 ////////////////////////////////////////////////////////////////////////////////
1734 /// Generate a new dataset containing the specified variables with events sampled from our distribution.
1735 /// Generate the specified number of events or expectedEvents() if not specified.
1736 ///
1737 /// Any variables of this PDF that are not in whatVars will use their
1738 /// current values and be treated as fixed parameters. Returns zero
1739 /// in case of an error. The caller takes ownership of the returned
1740 /// dataset.
1741 ///
1742 /// The following named arguments are supported
1743 ///
1744 /// Name(const char* name) -- Name of the output dataset
1745 /// Verbose(Bool_t flag) -- Print informational messages during event generation
1746 /// NumEvent(int nevt) -- Generate specified number of events
1747 ///
1748 /// AutoBinned(Bool_t flag) -- Automatically deploy binned generation for binned distributions (e.g. RooHistPdf, sums and products of RooHistPdfs etc)
1749 /// NB: Datasets that are generated in binned mode are returned as weighted unbinned datasets
1750 ///
1751 /// GenBinned(const char* tag) -- Use binned generation for all component pdfs that have 'setAttribute(tag)' set
1752 /// AllBinned() -- As above, but for all components.
1753 ///
1754 /// Note that the notion of components is only meaningful for simultaneous pdf
1755 /// as binned generation is always executed at the top-level node for a regular
1756 /// pdf, so for those it only mattes that the top-level node is tagged.
1757 ///
1758 /// Binned generation cannot be used when prototype data is supplied
1759 /// Extended() -- The actual number of events generated will be sampled from a Poisson distribution
1760 /// with mu=nevt. For use with extended maximum likelihood fits
1761 /// ProtoData(const RooDataSet& data, -- Use specified dataset as prototype dataset. If randOrder is set to true
1762 /// Bool_t randOrder, the order of the events in the dataset will be read in a random order
1763 /// Bool_t resample) if the requested number of events to be generated does not match the
1764 /// number of events in the prototype dataset. If resample is also set to
1765 /// true, the prototype dataset will be resampled rather than be strictly
1766 /// reshuffled. In this mode events of the protodata may be used more than
1767 /// once.
1768 ///
1769 /// If ProtoData() is used, the specified existing dataset as a prototype: the new dataset will contain
1770 /// the same number of events as the prototype (unless otherwise specified), and any prototype variables not in
1771 /// whatVars will be copied into the new dataset for each generated event and also used to set our PDF parameters.
1772 /// The user can specify a number of events to generate that will override the default. The result is a
1773 /// copy of the prototype dataset with only variables in whatVars randomized. Variables in whatVars that
1774 /// are not in the prototype will be added as new columns to the generated dataset.
1775 
1776 RooDataSet *RooAbsPdf::generate(const RooArgSet& whatVars, const RooCmdArg& arg1,const RooCmdArg& arg2,
1777  const RooCmdArg& arg3,const RooCmdArg& arg4, const RooCmdArg& arg5,const RooCmdArg& arg6)
1778 {
1779  // Select the pdf-specific commands
1780  RooCmdConfig pc(Form("RooAbsPdf::generate(%s)",GetName())) ;
1781  pc.defineObject("proto","PrototypeData",0,0) ;
1782  pc.defineString("dsetName","Name",0,"") ;
1783  pc.defineInt("randProto","PrototypeData",0,0) ;
1784  pc.defineInt("resampleProto","PrototypeData",1,0) ;
1785  pc.defineInt("verbose","Verbose",0,0) ;
1786  pc.defineInt("extended","Extended",0,0) ;
1787  pc.defineInt("nEvents","NumEvents",0,0) ;
1788  pc.defineInt("autoBinned","AutoBinned",0,1) ;
1789  pc.defineInt("expectedData","ExpectedData",0,0) ;
1790  pc.defineDouble("nEventsD","NumEventsD",0,-1.) ;
1791  pc.defineString("binnedTag","GenBinned",0,"") ;
1792  pc.defineMutex("GenBinned","ProtoData") ;
1793 
1794  // Process and check varargs
1795  pc.process(arg1,arg2,arg3,arg4,arg5,arg6) ;
1796  if (!pc.ok(kTRUE)) {
1797  return 0 ;
1798  }
1799 
1800  // Decode command line arguments
1801  RooDataSet* protoData = static_cast<RooDataSet*>(pc.getObject("proto",0)) ;
1802  const char* dsetName = pc.getString("dsetName") ;
1803  Bool_t verbose = pc.getInt("verbose") ;
1804  Bool_t randProto = pc.getInt("randProto") ;
1805  Bool_t resampleProto = pc.getInt("resampleProto") ;
1806  Bool_t extended = pc.getInt("extended") ;
1807  Bool_t autoBinned = pc.getInt("autoBinned") ;
1808  const char* binnedTag = pc.getString("binnedTag") ;
1809  Int_t nEventsI = pc.getInt("nEvents") ;
1810  Double_t nEventsD = pc.getInt("nEventsD") ;
1811  //Bool_t verbose = pc.getInt("verbose") ;
1812  Bool_t expectedData = pc.getInt("expectedData") ;
1813 
1814  Double_t nEvents = (nEventsD>0) ? nEventsD : Double_t(nEventsI);
1815 
1816  // Force binned mode for expected data mode
1817  if (expectedData) {
1818  binnedTag="*" ;
1819  }
1820 
1821  if (extended) {
1822  if (nEvents == 0) nEvents = expectedEvents(&whatVars);
1823  // nEvents = RooRandom::randomGenerator()->Poisson(nEvents==0 ? expectedEvents(&whatVars) : nEvents ) ;
1824  // // If Poisson fluctuation results in zero events, stop here
1825  // if (nEvents==0) {
1826  // return new RooDataSet("emptyData","emptyData",whatVars) ;
1827  // }
1828  } else if (nEvents==0) {
1829  cxcoutI(Generation) << "No number of events specified , number of events generated is "
1830  << GetName() << "::expectedEvents() = " << expectedEvents(&whatVars)<< endl ;
1831  }
1832 
1833  if (extended && protoData && !randProto) {
1834  cxcoutI(Generation) << "WARNING Using generator option Extended() (Poisson distribution of #events) together "
1835  << "with a prototype dataset implies incomplete sampling or oversampling of proto data. "
1836  << "Set randomize flag in ProtoData() option to randomize prototype dataset order and thus "
1837  << "to randomize the set of over/undersampled prototype events for each generation cycle." << endl ;
1838  }
1839 
1840 
1841  // Forward to appropriate implementation
1842  RooDataSet* data ;
1843  if (protoData) {
1844  data = generate(whatVars,*protoData,Int_t(nEvents),verbose,randProto,resampleProto) ;
1845  } else {
1846  data = generate(whatVars,nEvents,verbose,autoBinned,binnedTag,expectedData, extended) ;
1847  }
1848 
1849  // Rename dataset to given name if supplied
1850  if (dsetName && strlen(dsetName)>0) {
1851  data->SetName(dsetName) ;
1852  }
1853 
1854  return data ;
1855 }
1856 
1857 
1858 
1859 
1860 
1861 ////////////////////////////////////////////////////////////////////////////////
1862 /// Prepare GenSpec configuration object for efficient generation of multiple datasets from idetical specification
1863 /// This method does not perform any generation. To generate according to generations specification call RooAbsPdf::generate(RooAbsPdf::GenSpec&)
1864 ///
1865 /// Generate the specified number of events or expectedEvents() if not specified.
1866 ///
1867 /// Any variables of this PDF that are not in whatVars will use their
1868 /// current values and be treated as fixed parameters. Returns zero
1869 /// in case of an error. The caller takes ownership of the returned
1870 /// dataset.
1871 ///
1872 /// The following named arguments are supported
1873 ///
1874 /// Name(const char* name) -- Name of the output dataset
1875 /// Verbose(Bool_t flag) -- Print informational messages during event generation
1876 /// NumEvent(int nevt) -- Generate specified number of events
1877 
1879  const RooCmdArg& arg1,const RooCmdArg& arg2,
1880  const RooCmdArg& arg3,const RooCmdArg& arg4,
1881  const RooCmdArg& arg5,const RooCmdArg& arg6)
1882 {
1883  // AutoBinned(Bool_t flag) -- Automatically deploy binned generation for binned distributions (e.g. RooHistPdf, sums and products of RooHistPdfs etc)
1884  // NB: Datasets that are generated in binned mode are returned as weighted unbinned datasets
1885  //
1886  //
1887  // GenBinned(const char* tag) -- Use binned generation for all component pdfs that have 'setAttribute(tag)' set
1888  // AllBinned() -- As above, but for all components.
1889  //
1890  // Note that the notion of components is only meaningful for simultaneous pdf
1891  // as binned generation is always executed at the top-level node for a regular
1892  // pdf, so for those it only mattes that the top-level node is tagged.
1893  //
1894  // Extended() -- The actual number of events generated will be sampled from a Poisson distribution
1895  // with mu=nevt. For use with extended maximum likelihood fits
1896  // ProtoData(const RooDataSet& data, -- Use specified dataset as prototype dataset. If randOrder is set to true
1897  // Bool_t randOrder, the order of the events in the dataset will be read in a random order
1898  // Bool_t resample) if the requested number of events to be generated does not match the
1899  // number of events in the prototype dataset. If resample is also set to
1900  // true, the prototype dataset will be resampled rather than be strictly
1901  // reshuffled. In this mode events of the protodata may be used more than
1902  // once.
1903  //
1904  // If ProtoData() is used, the specified existing dataset as a prototype: the new dataset will contain
1905  // the same number of events as the prototype (unless otherwise specified), and any prototype variables not in
1906  // whatVars will be copied into the new dataset for each generated event and also used to set our PDF parameters.
1907  // The user can specify a number of events to generate that will override the default. The result is a
1908  // copy of the prototype dataset with only variables in whatVars randomized. Variables in whatVars that
1909  // are not in the prototype will be added as new columns to the generated dataset.
1910 
1911  // Select the pdf-specific commands
1912  RooCmdConfig pc(Form("RooAbsPdf::generate(%s)",GetName())) ;
1913  pc.defineObject("proto","PrototypeData",0,0) ;
1914  pc.defineString("dsetName","Name",0,"") ;
1915  pc.defineInt("randProto","PrototypeData",0,0) ;
1916  pc.defineInt("resampleProto","PrototypeData",1,0) ;
1917  pc.defineInt("verbose","Verbose",0,0) ;
1918  pc.defineInt("extended","Extended",0,0) ;
1919  pc.defineInt("nEvents","NumEvents",0,0) ;
1920  pc.defineInt("autoBinned","AutoBinned",0,1) ;
1921  pc.defineString("binnedTag","GenBinned",0,"") ;
1922  pc.defineMutex("GenBinned","ProtoData") ;
1923 
1924 
1925  // Process and check varargs
1926  pc.process(arg1,arg2,arg3,arg4,arg5,arg6) ;
1927  if (!pc.ok(kTRUE)) {
1928  return 0 ;
1929  }
1930 
1931  // Decode command line arguments
1932  RooDataSet* protoData = static_cast<RooDataSet*>(pc.getObject("proto",0)) ;
1933  const char* dsetName = pc.getString("dsetName") ;
1934  Int_t nEvents = pc.getInt("nEvents") ;
1935  Bool_t verbose = pc.getInt("verbose") ;
1936  Bool_t randProto = pc.getInt("randProto") ;
1937  Bool_t resampleProto = pc.getInt("resampleProto") ;
1938  Bool_t extended = pc.getInt("extended") ;
1939  Bool_t autoBinned = pc.getInt("autoBinned") ;
1940  const char* binnedTag = pc.getString("binnedTag") ;
1941 
1942  RooAbsGenContext* cx = autoGenContext(whatVars,protoData,0,verbose,autoBinned,binnedTag) ;
1943 
1944  return new GenSpec(cx,whatVars,protoData,nEvents,extended,randProto,resampleProto,dsetName) ;
1945 }
1946 
1947 
1948 ////////////////////////////////////////////////////////////////////////////////
1949 /// Generate data according to a pre-configured specification created by
1950 /// RooAbsPdf::prepareMultiGen(). If many identical generation requests
1951 /// are needed, e.g. in toy MC studies, it is more efficient to use the prepareMultiGen()/generate()
1952 /// combination than calling the standard generate() multiple times as
1953 /// initialization overhead is only incurred once.
1954 
1956 {
1957  //Int_t nEvt = spec._extended ? RooRandom::randomGenerator()->Poisson(spec._nGen) : spec._nGen ;
1958  //Int_t nEvt = spec._extended ? RooRandom::randomGenerator()->Poisson(spec._nGen==0?expectedEvents(spec._whatVars):spec._nGen) : spec._nGen ;
1959  //Int_t nEvt = spec._nGen == 0 ? RooRandom::randomGenerator()->Poisson(expectedEvents(spec._whatVars)) : spec._nGen;
1960 
1961  Double_t nEvt = spec._nGen == 0 ? expectedEvents(spec._whatVars) : spec._nGen;
1962 
1963  RooDataSet* ret = generate(*spec._genContext,spec._whatVars,spec._protoData, nEvt,kFALSE,spec._randProto,spec._resampleProto,
1964  spec._init,spec._extended) ;
1965  spec._init = kTRUE ;
1966  return ret ;
1967 }
1968 
1969 
1970 
1971 
1972 
1973 ////////////////////////////////////////////////////////////////////////////////
1974 /// Generate a new dataset containing the specified variables with
1975 /// events sampled from our distribution. Generate the specified
1976 /// number of events or else try to use expectedEvents() if nEvents <= 0.
1977 /// Any variables of this PDF that are not in whatVars will use their
1978 /// current values and be treated as fixed parameters. Returns zero
1979 /// in case of an error. The caller takes ownership of the returned
1980 /// dataset.
1981 
1982 RooDataSet *RooAbsPdf::generate(const RooArgSet &whatVars, Double_t nEvents, Bool_t verbose, Bool_t autoBinned, const char* binnedTag, Bool_t expectedData, Bool_t extended) const
1983 {
1984  if (nEvents==0 && extendMode()==CanNotBeExtended) {
1985  return new RooDataSet("emptyData","emptyData",whatVars) ;
1986  }
1987 
1988  // Request for binned generation
1989  RooAbsGenContext *context = autoGenContext(whatVars,0,0,verbose,autoBinned,binnedTag) ;
1990  if (expectedData) {
1991  context->setExpectedData(kTRUE) ;
1992  }
1993 
1994  RooDataSet *generated = 0;
1995  if(0 != context && context->isValid()) {
1996  generated= context->generate(nEvents, kFALSE, extended);
1997  }
1998  else {
1999  coutE(Generation) << "RooAbsPdf::generate(" << GetName() << ") cannot create a valid context" << endl;
2000  }
2001  if(0 != context) delete context;
2002  return generated;
2003 }
2004 
2005 
2006 
2007 
2008 ////////////////////////////////////////////////////////////////////////////////
2009 /// Internal method
2010 
2011 RooDataSet *RooAbsPdf::generate(RooAbsGenContext& context, const RooArgSet &whatVars, const RooDataSet *prototype,
2012  Double_t nEvents, Bool_t /*verbose*/, Bool_t randProtoOrder, Bool_t resampleProto,
2013  Bool_t skipInit, Bool_t extended) const
2014 {
2015  if (nEvents==0 && (prototype==0 || prototype->numEntries()==0)) {
2016  return new RooDataSet("emptyData","emptyData",whatVars) ;
2017  }
2018 
2019  RooDataSet *generated = 0;
2020 
2021  // Resampling implies reshuffling in the implementation
2022  if (resampleProto) {
2023  randProtoOrder=kTRUE ;
2024  }
2025 
2026  if (randProtoOrder && prototype && prototype->numEntries()!=nEvents) {
2027  coutI(Generation) << "RooAbsPdf::generate (Re)randomizing event order in prototype dataset (Nevt=" << nEvents << ")" << endl ;
2028  Int_t* newOrder = randomizeProtoOrder(prototype->numEntries(),Int_t(nEvents),resampleProto) ;
2029  context.setProtoDataOrder(newOrder) ;
2030  delete[] newOrder ;
2031  }
2032 
2033  if(context.isValid()) {
2034  generated= context.generate(nEvents,skipInit,extended);
2035  }
2036  else {
2037  coutE(Generation) << "RooAbsPdf::generate(" << GetName() << ") do not have a valid generator context" << endl;
2038  }
2039  return generated;
2040 }
2041 
2042 
2043 
2044 
2045 ////////////////////////////////////////////////////////////////////////////////
2046 /// Generate a new dataset with values of the whatVars variables
2047 /// sampled from our distribution. Use the specified existing dataset
2048 /// as a prototype: the new dataset will contain the same number of
2049 /// events as the prototype (by default), and any prototype variables not in
2050 /// whatVars will be copied into the new dataset for each generated
2051 /// event and also used to set our PDF parameters. The user can specify a
2052 /// number of events to generate that will override the default. The result is a
2053 /// copy of the prototype dataset with only variables in whatVars
2054 /// randomized. Variables in whatVars that are not in the prototype
2055 /// will be added as new columns to the generated dataset. Returns
2056 /// zero in case of an error. The caller takes ownership of the
2057 /// returned dataset.
2058 
2059 RooDataSet *RooAbsPdf::generate(const RooArgSet &whatVars, const RooDataSet& prototype,
2060  Int_t nEvents, Bool_t verbose, Bool_t randProtoOrder, Bool_t resampleProto) const
2061 {
2062  RooAbsGenContext *context= genContext(whatVars,&prototype,0,verbose);
2063  if (context) {
2064  RooDataSet* data = generate(*context,whatVars,&prototype,nEvents,verbose,randProtoOrder,resampleProto) ;
2065  delete context ;
2066  return data ;
2067  } else {
2068  coutE(Generation) << "RooAbsPdf::generate(" << GetName() << ") ERROR creating generator context" << endl ;
2069  return 0 ;
2070  }
2071 }
2072 
2073 
2074 
2075 ////////////////////////////////////////////////////////////////////////////////
2076 /// Return lookup table with randomized access order for prototype events,
2077 /// given nProto prototype data events and nGen events that will actually
2078 /// be accessed
2079 
2081 {
2082  // Make unsorted linked list of indeces
2083  RooLinkedList l ;
2084  Int_t i ;
2085  for (i=0 ; i<nProto ; i++) {
2086  l.Add(new RooInt(i)) ;
2087  }
2088 
2089  // Make output list
2090  Int_t* lut = new Int_t[nProto] ;
2091 
2092  // Randomly samply input list into output list
2093  if (!resampleProto) {
2094  // In this mode, randomization is a strict reshuffle of the order
2095  for (i=0 ; i<nProto ; i++) {
2096  Int_t iran = RooRandom::integer(nProto-i) ;
2097  RooInt* sample = (RooInt*) l.At(iran) ;
2098  lut[i] = *sample ;
2099  l.Remove(sample) ;
2100  delete sample ;
2101  }
2102  } else {
2103  // In this mode, we resample, i.e. events can be used more than once
2104  for (i=0 ; i<nProto ; i++) {
2105  lut[i] = RooRandom::integer(nProto);
2106  }
2107  }
2108 
2109 
2110  return lut ;
2111 }
2112 
2113 
2114 
2115 ////////////////////////////////////////////////////////////////////////////////
2116 /// Load generatedVars with the subset of directVars that we can generate events for,
2117 /// and return a code that specifies the generator algorithm we will use. A code of
2118 /// zero indicates that we cannot generate any of the directVars (in this case, nothing
2119 /// should be added to generatedVars). Any non-zero codes will be passed to our generateEvent()
2120 /// implementation, but otherwise its value is arbitrary. The default implemetation of
2121 /// this method returns zero. Subclasses will usually implement this method using the
2122 /// matchArgs() methods to advertise the algorithms they provide.
2123 
2124 Int_t RooAbsPdf::getGenerator(const RooArgSet &/*directVars*/, RooArgSet &/*generatedVars*/, Bool_t /*staticInitOK*/) const
2125 {
2126  return 0 ;
2127 }
2128 
2129 
2130 
2131 ////////////////////////////////////////////////////////////////////////////////
2132 /// Interface for one-time initialization to setup the generator for the specified code.
2133 
2135 {
2136 }
2137 
2138 
2139 
2140 ////////////////////////////////////////////////////////////////////////////////
2141 /// Interface for generation of anan event using the algorithm
2142 /// corresponding to the specified code. The meaning of each code is
2143 /// defined by the getGenerator() implementation. The default
2144 /// implementation does nothing.
2145 
2147 {
2148 }
2149 
2150 
2151 
2152 ////////////////////////////////////////////////////////////////////////////////
2153 /// Check if given observable can be safely generated using the
2154 /// pdfs internal generator mechanism (if that existsP). Observables
2155 /// on which a PDF depends via more than route are not safe
2156 /// for use with internal generators because they introduce
2157 /// correlations not known to the internal generator
2158 
2160 {
2161  // Arg must be direct server of self
2162  if (!findServer(arg.GetName())) return kFALSE ;
2163 
2164  // There must be no other dependency routes
2165  TIterator* sIter = serverIterator() ;
2166  const RooAbsArg *server = 0;
2167  while((server=(const RooAbsArg*)sIter->Next())) {
2168  if(server == &arg) continue;
2169  if(server->dependsOn(arg)) {
2170  delete sIter ;
2171  return kFALSE ;
2172  }
2173  }
2174  delete sIter ;
2175  return kTRUE ;
2176 }
2177 
2178 
2179 
2180 
2181 ////////////////////////////////////////////////////////////////////////////////
2182 /// Generate a new dataset containing the specified variables with events sampled from our distribution.
2183 /// Generate the specified number of events or expectedEvents() if not specified.
2184 ///
2185 /// Any variables of this PDF that are not in whatVars will use their
2186 /// current values and be treated as fixed parameters. Returns zero
2187 /// in case of an error. The caller takes ownership of the returned
2188 /// dataset.
2189 ///
2190 /// The following named arguments are supported
2191 ///
2192 /// Name(const char* name) -- Name of the output dataset
2193 /// Verbose(Bool_t flag) -- Print informational messages during event generation
2194 /// Extended() -- The actual number of events generated will be sampled from a Poisson distribution
2195 /// with mu=nevt. For use with extended maximum likelihood fits
2196 /// ExpectedData() -- Return a binned dataset _without_ statistical fluctuations (also aliased as Asimov())
2197 
2198 RooDataHist *RooAbsPdf::generateBinned(const RooArgSet& whatVars, Double_t nEvents, const RooCmdArg& arg1,
2199  const RooCmdArg& arg2, const RooCmdArg& arg3,const RooCmdArg& arg4, const RooCmdArg& arg5)
2200 {
2201  return generateBinned(whatVars,RooFit::NumEvents(nEvents),arg1,arg2,arg3,arg4,arg5) ;
2202 }
2203 
2204 
2205 
2206 ////////////////////////////////////////////////////////////////////////////////
2207 /// Generate a new dataset containing the specified variables with events sampled from our distribution.
2208 /// Generate the specified number of events or expectedEvents() if not specified.
2209 ///
2210 /// Any variables of this PDF that are not in whatVars will use their
2211 /// current values and be treated as fixed parameters. Returns zero
2212 /// in case of an error. The caller takes ownership of the returned
2213 /// dataset.
2214 ///
2215 /// The following named arguments are supported
2216 ///
2217 /// Name(const char* name) -- Name of the output dataset
2218 /// Verbose(Bool_t flag) -- Print informational messages during event generation
2219 /// NumEvent(int nevt) -- Generate specified number of events
2220 /// Extended() -- The actual number of events generated will be sampled from a Poisson distribution
2221 /// with mu=nevt. For use with extended maximum likelihood fits
2222 /// ExpectedData() -- Return a binned dataset _without_ statistical fluctuations (also aliased as Asimov())
2223 
2224 RooDataHist *RooAbsPdf::generateBinned(const RooArgSet& whatVars, const RooCmdArg& arg1,const RooCmdArg& arg2,
2225  const RooCmdArg& arg3,const RooCmdArg& arg4, const RooCmdArg& arg5,const RooCmdArg& arg6)
2226 {
2227 
2228  // Select the pdf-specific commands
2229  RooCmdConfig pc(Form("RooAbsPdf::generate(%s)",GetName())) ;
2230  pc.defineString("dsetName","Name",0,"") ;
2231  pc.defineInt("verbose","Verbose",0,0) ;
2232  pc.defineInt("extended","Extended",0,0) ;
2233  pc.defineInt("nEvents","NumEvents",0,0) ;
2234  pc.defineDouble("nEventsD","NumEventsD",0,-1.) ;
2235  pc.defineInt("expectedData","ExpectedData",0,0) ;
2236 
2237  // Process and check varargs
2238  pc.process(arg1,arg2,arg3,arg4,arg5,arg6) ;
2239  if (!pc.ok(kTRUE)) {
2240  return 0 ;
2241  }
2242 
2243  // Decode command line arguments
2244  Double_t nEvents = pc.getDouble("nEventsD") ;
2245  if (nEvents<0) {
2246  nEvents = pc.getInt("nEvents") ;
2247  }
2248  //Bool_t verbose = pc.getInt("verbose") ;
2249  Bool_t extended = pc.getInt("extended") ;
2250  Bool_t expectedData = pc.getInt("expectedData") ;
2251  const char* dsetName = pc.getString("dsetName") ;
2252 
2253  if (extended) {
2254  //nEvents = (nEvents==0?Int_t(expectedEvents(&whatVars)+0.5):nEvents) ;
2255  nEvents = (nEvents==0 ? expectedEvents(&whatVars) :nEvents) ;
2256  cxcoutI(Generation) << " Extended mode active, number of events generated (" << nEvents << ") is Poisson fluctuation on "
2257  << GetName() << "::expectedEvents() = " << nEvents << endl ;
2258  // If Poisson fluctuation results in zero events, stop here
2259  if (nEvents==0) {
2260  return 0 ;
2261  }
2262  } else if (nEvents==0) {
2263  cxcoutI(Generation) << "No number of events specified , number of events generated is "
2264  << GetName() << "::expectedEvents() = " << expectedEvents(&whatVars)<< endl ;
2265  }
2266 
2267  // Forward to appropriate implementation
2268  RooDataHist* data = generateBinned(whatVars,nEvents,expectedData,extended) ;
2269 
2270  // Rename dataset to given name if supplied
2271  if (dsetName && strlen(dsetName)>0) {
2272  data->SetName(dsetName) ;
2273  }
2274 
2275  return data ;
2276 }
2277 
2278 
2279 
2280 
2281 ////////////////////////////////////////////////////////////////////////////////
2282 /// Generate a new dataset containing the specified variables with
2283 /// events sampled from our distribution. Generate the specified
2284 /// number of events or else try to use expectedEvents() if nEvents <= 0.
2285 ///
2286 /// If expectedData is kTRUE (it is kFALSE by default), the returned histogram returns the 'expected'
2287 /// data sample, i.e. no statistical fluctuations are present.
2288 ///
2289 /// Any variables of this PDF that are not in whatVars will use their
2290 /// current values and be treated as fixed parameters. Returns zero
2291 /// in case of an error. The caller takes ownership of the returned
2292 /// dataset.
2293 
2294 RooDataHist *RooAbsPdf::generateBinned(const RooArgSet &whatVars, Double_t nEvents, Bool_t expectedData, Bool_t extended) const
2295 {
2296  // Create empty RooDataHist
2297  RooDataHist* hist = new RooDataHist("genData","genData",whatVars) ;
2298 
2299  // Scale to number of events and introduce Poisson fluctuations
2300  if (nEvents<=0) {
2301  if (!canBeExtended()) {
2302  coutE(InputArguments) << "RooAbsPdf::generateBinned(" << GetName() << ") ERROR: No event count provided and p.d.f does not provide expected number of events" << endl ;
2303  delete hist ;
2304  return 0 ;
2305  } else {
2306 
2307  // Don't round in expectedData or extended mode
2308  if (expectedData || extended) {
2309  nEvents = expectedEvents(&whatVars) ;
2310  } else {
2311  nEvents = Int_t(expectedEvents(&whatVars)+0.5) ;
2312  }
2313  }
2314  }
2315 
2316  // Sample p.d.f. distribution
2317  fillDataHist(hist,&whatVars,1,kTRUE) ;
2318 
2319  vector<int> histOut(hist->numEntries()) ;
2320  Double_t histMax(-1) ;
2321  Int_t histOutSum(0) ;
2322  for (int i=0 ; i<hist->numEntries() ; i++) {
2323  hist->get(i) ;
2324  if (expectedData) {
2325 
2326  // Expected data, multiply p.d.f by nEvents
2327  Double_t w=hist->weight()*nEvents ;
2328  hist->set(w,sqrt(w)) ;
2329 
2330  } else if (extended) {
2331 
2332  // Extended mode, set contents to Poisson(pdf*nEvents)
2333  Double_t w = RooRandom::randomGenerator()->Poisson(hist->weight()*nEvents) ;
2334  hist->set(w,sqrt(w)) ;
2335 
2336  } else {
2337 
2338  // Regular mode, fill array of weights with Poisson(pdf*nEvents), but to not fill
2339  // histogram yet.
2340  if (hist->weight()>histMax) {
2341  histMax = hist->weight() ;
2342  }
2343  histOut[i] = RooRandom::randomGenerator()->Poisson(hist->weight()*nEvents) ;
2344  histOutSum += histOut[i] ;
2345  }
2346  }
2347 
2348 
2349  if (!expectedData && !extended) {
2350 
2351  // Second pass for regular mode - Trim/Extend dataset to exact number of entries
2352 
2353  // Calculate difference between what is generated so far and what is requested
2354  Int_t nEvtExtra = abs(Int_t(nEvents)-histOutSum) ;
2355  Int_t wgt = (histOutSum>nEvents) ? -1 : 1 ;
2356 
2357  // Perform simple binned accept/reject procedure to get to exact event count
2358  while(nEvtExtra>0) {
2359 
2360  Int_t ibinRand = RooRandom::randomGenerator()->Integer(hist->numEntries()) ;
2361  hist->get(ibinRand) ;
2362  Double_t ranY = RooRandom::randomGenerator()->Uniform(histMax) ;
2363 
2364  if (ranY<hist->weight()) {
2365  if (wgt==1) {
2366  histOut[ibinRand]++ ;
2367  } else {
2368  // If weight is negative, prior bin content must be at least 1
2369  if (histOut[ibinRand]>0) {
2370  histOut[ibinRand]-- ;
2371  } else {
2372  continue ;
2373  }
2374  }
2375  nEvtExtra-- ;
2376  }
2377  }
2378 
2379  // Transfer working array to histogram
2380  for (int i=0 ; i<hist->numEntries() ; i++) {
2381  hist->get(i) ;
2382  hist->set(histOut[i],sqrt(1.0*histOut[i])) ;
2383  }
2384 
2385  } else if (expectedData) {
2386 
2387  // Second pass for expectedData mode -- Normalize to exact number of requested events
2388  // Minor difference may be present in first round due to difference between
2389  // bin average and bin integral in sampling bins
2390  Double_t corr = nEvents/hist->sumEntries() ;
2391  for (int i=0 ; i<hist->numEntries() ; i++) {
2392  hist->get(i) ;
2393  hist->set(hist->weight()*corr,sqrt(hist->weight()*corr)) ;
2394  }
2395 
2396  }
2397 
2398  return hist;
2399 }
2400 
2401 
2402 
2403 ////////////////////////////////////////////////////////////////////////////////
2404 /// Special generator interface for generation of 'global observables' -- for RooStats tools
2405 
2407 {
2408  return generate(whatVars,nEvents) ;
2409 }
2410 
2411 
2412 
2413 ////////////////////////////////////////////////////////////////////////////////
2414 /// Plot (project) PDF on specified frame. If a PDF is plotted in an empty frame, it
2415 /// will show a unit normalized curve in the frame variable, taken at the present value
2416 /// of other observables defined for this PDF
2417 ///
2418 /// If a PDF is plotted in a frame in which a dataset has already been plotted, it will
2419 /// show a projected curve integrated over all variables that were present in the shown
2420 /// dataset except for the one on the x-axis. The normalization of the curve will also
2421 /// be adjusted to the event count of the plotted dataset. An informational message
2422 /// will be printed for each projection step that is performed
2423 ///
2424 /// This function takes the following named arguments
2425 ///
2426 /// Projection control
2427 /// ------------------
2428 /// Slice(const RooArgSet& set) -- Override default projection behaviour by omittting observables listed
2429 /// in set from the projection, resulting a 'slice' plot. Slicing is usually
2430 /// only sensible in discrete observables
2431 /// Project(const RooArgSet& set) -- Override default projection behaviour by projecting over observables
2432 /// given in set and complete ignoring the default projection behavior. Advanced use only.
2433 /// ProjWData(const RooAbsData& d) -- Override default projection _technique_ (integration). For observables present in given dataset
2434 /// projection of PDF is achieved by constructing an average over all observable values in given set.
2435 /// Consult RooFit plotting tutorial for further explanation of meaning & use of this technique
2436 /// ProjWData(const RooArgSet& s, -- As above but only consider subset 's' of observables in dataset 'd' for projection through data averaging
2437 /// const RooAbsData& d)
2438 /// ProjectionRange(const char* rn) -- Override default range of projection integrals to a different range speficied by given range name.
2439 /// This technique allows you to project a finite width slice in a real-valued observable
2440 /// NormRange(const char* name) -- Calculate curve normalization w.r.t. only in specified ranges. NB: A Range() by default implies a NormRange()
2441 /// on the same range, but this option allows to override the default, or specify a normalization ranges
2442 /// when the full curve is to be drawn
2443 ///
2444 /// Misc content control
2445 /// --------------------
2446 /// Normalization(Double_t scale, -- Adjust normalization by given scale factor. Interpretation of number depends on code: Relative:
2447 /// ScaleType code) relative adjustment factor, NumEvent: scale to match given number of events.
2448 /// Name(const chat* name) -- Give curve specified name in frame. Useful if curve is to be referenced later
2449 /// Asymmetry(const RooCategory& c) -- Show the asymmetry of the PDF in given two-state category [F(+)-F(-)] / [F(+)+F(-)] rather than
2450 /// the PDF projection. Category must have two states with indices -1 and +1 or three states with
2451 /// indeces -1,0 and +1.
2452 /// ShiftToZero(Bool_t flag) -- Shift entire curve such that lowest visible point is at exactly zero. Mostly useful when
2453 /// plotting -log(L) or chi^2 distributions
2454 /// AddTo(const char* name, -- Add constructed projection to already existing curve with given name and relative weight factors
2455 /// double_t wgtSelf, double_t wgtOther)
2456 ///
2457 /// Plotting control
2458 /// ----------------
2459 /// LineStyle(Int_t style) -- Select line style by ROOT line style code, default is solid
2460 /// LineColor(Int_t color) -- Select line color by ROOT color code, default is blue
2461 /// LineWidth(Int_t width) -- Select line with in pixels, default is 3
2462 /// FillStyle(Int_t style) -- Select fill style, default is not filled. If a filled style is selected, also use VLines()
2463 /// to add vertical downward lines at end of curve to ensure proper closure
2464 /// FillColor(Int_t color) -- Select fill color by ROOT color code
2465 /// Range(const char* name) -- Only draw curve in range defined by given name
2466 /// Range(double lo, double hi) -- Only draw curve in specified range
2467 /// VLines() -- Add vertical lines to y=0 at end points of curve
2468 /// Precision(Double_t eps) -- Control precision of drawn curve w.r.t to scale of plot, default is 1e-3. Higher precision
2469 /// will result in more and more densely spaced curve points
2470 /// A negative precision value will disable adaptive point spacing and restrict sampling to
2471 /// the grid point of points defined by the binning of the plotted observabled (recommended for
2472 /// expensive functions such as profile likelihoods)
2473 /// Invisble(Bool_t flag) -- Add curve to frame, but do not display. Useful in combination AddTo()
2474 
2476 {
2477 
2478  // Pre-processing if p.d.f. contains a fit range and there is no command specifying one,
2479  // add a fit range as default range
2480  RooCmdArg* plotRange(0) ;
2481  RooCmdArg* normRange2(0) ;
2482  if (getStringAttribute("fitrange") && !cmdList.FindObject("Range") &&
2483  !cmdList.FindObject("RangeWithName")) {
2484  plotRange = (RooCmdArg*) RooFit::Range(getStringAttribute("fitrange")).Clone() ;
2485  cmdList.Add(plotRange) ;
2486  }
2487 
2488  if (getStringAttribute("fitrange") && !cmdList.FindObject("NormRange")) {
2489  normRange2 = (RooCmdArg*) RooFit::NormRange(getStringAttribute("fitrange")).Clone() ;
2490  cmdList.Add(normRange2) ;
2491  }
2492 
2493  if (plotRange || normRange2) {
2494  coutI(Plotting) << "RooAbsPdf::plotOn(" << GetName() << ") p.d.f was fitted in range and no explicit "
2495  << (plotRange?"plot":"") << ((plotRange&&normRange2)?",":"")
2496  << (normRange2?"norm":"") << " range was specified, using fit range as default" << endl ;
2497  }
2498 
2499  // Sanity checks
2500  if (plotSanityChecks(frame)) return frame ;
2501 
2502  // Select the pdf-specific commands
2503  RooCmdConfig pc(Form("RooAbsPdf::plotOn(%s)",GetName())) ;
2504  pc.defineDouble("scaleFactor","Normalization",0,1.0) ;
2505  pc.defineInt("scaleType","Normalization",0,Relative) ;
2506  pc.defineObject("compSet","SelectCompSet",0) ;
2507  pc.defineString("compSpec","SelectCompSpec",0) ;
2508  pc.defineObject("asymCat","Asymmetry",0) ;
2509  pc.defineDouble("rangeLo","Range",0,-999.) ;
2510  pc.defineDouble("rangeHi","Range",1,-999.) ;
2511  pc.defineString("rangeName","RangeWithName",0,"") ;
2512  pc.defineString("normRangeName","NormRange",0,"") ;
2513  pc.defineInt("rangeAdjustNorm","Range",0,0) ;
2514  pc.defineInt("rangeWNAdjustNorm","RangeWithName",0,0) ;
2515  pc.defineMutex("SelectCompSet","SelectCompSpec") ;
2516  pc.defineMutex("Range","RangeWithName") ;
2517  pc.allowUndefined() ; // unknowns may be handled by RooAbsReal
2518 
2519  // Process and check varargs
2520  pc.process(cmdList) ;
2521  if (!pc.ok(kTRUE)) {
2522  return frame ;
2523  }
2524 
2525  // Decode command line arguments
2526  ScaleType stype = (ScaleType) pc.getInt("scaleType") ;
2527  Double_t scaleFactor = pc.getDouble("scaleFactor") ;
2528  const RooAbsCategoryLValue* asymCat = (const RooAbsCategoryLValue*) pc.getObject("asymCat") ;
2529  const char* compSpec = pc.getString("compSpec") ;
2530  const RooArgSet* compSet = (const RooArgSet*) pc.getObject("compSet") ;
2531  Bool_t haveCompSel = ( (compSpec && strlen(compSpec)>0) || compSet) ;
2532 
2533  // Suffix for curve name
2534  TString nameSuffix ;
2535  if (compSpec && strlen(compSpec)>0) {
2536  nameSuffix.Append("_Comp[") ;
2537  nameSuffix.Append(compSpec) ;
2538  nameSuffix.Append("]") ;
2539  } else if (compSet) {
2540  nameSuffix.Append("_Comp[") ;
2541  nameSuffix.Append(compSet->contentsString().c_str()) ;
2542  nameSuffix.Append("]") ;
2543  }
2544 
2545  // Remove PDF-only commands from command list
2546  pc.stripCmdList(cmdList,"SelectCompSet,SelectCompSpec") ;
2547 
2548  // Adjust normalization, if so requested
2549  if (asymCat) {
2550  RooCmdArg cnsuffix("CurveNameSuffix",0,0,0,0,nameSuffix.Data(),0,0,0) ;
2551  cmdList.Add(&cnsuffix);
2552  return RooAbsReal::plotOn(frame,cmdList) ;
2553  }
2554 
2555  // More sanity checks
2556  Double_t nExpected(1) ;
2557  if (stype==RelativeExpected) {
2558  if (!canBeExtended()) {
2559  coutE(Plotting) << "RooAbsPdf::plotOn(" << GetName()
2560  << "): ERROR the 'Expected' scale option can only be used on extendable PDFs" << endl ;
2561  return frame ;
2562  }
2563  nExpected = expectedEvents(frame->getNormVars()) ;
2564  }
2565 
2566  if (stype != Raw) {
2567 
2568  if (frame->getFitRangeNEvt() && stype==Relative) {
2569 
2570  Bool_t hasCustomRange(kFALSE), adjustNorm(kFALSE) ;
2571 
2572  list<pair<Double_t,Double_t> > rangeLim ;
2573 
2574  // Retrieve plot range to be able to adjust normalization to data
2575  if (pc.hasProcessed("Range")) {
2576 
2577  Double_t rangeLo = pc.getDouble("rangeLo") ;
2578  Double_t rangeHi = pc.getDouble("rangeHi") ;
2579  rangeLim.push_back(make_pair(rangeLo,rangeHi)) ;
2580  adjustNorm = pc.getInt("rangeAdjustNorm") ;
2581  hasCustomRange = kTRUE ;
2582 
2583  coutI(Plotting) << "RooAbsPdf::plotOn(" << GetName() << ") only plotting range ["
2584  << rangeLo << "," << rangeHi << "]" ;
2585  if (!pc.hasProcessed("NormRange")) {
2586  ccoutI(Plotting) << ", curve is normalized to data in " << (adjustNorm?"given":"full") << " given range" << endl ;
2587  } else {
2588  ccoutI(Plotting) << endl ;
2589  }
2590 
2591  nameSuffix.Append(Form("_Range[%f_%f]",rangeLo,rangeHi)) ;
2592 
2593  } else if (pc.hasProcessed("RangeWithName")) {
2594 
2595  char tmp[1024] ;
2596  strlcpy(tmp,pc.getString("rangeName",0,kTRUE),1024) ;
2597  char* rangeNameToken = strtok(tmp,",") ;
2598  while(rangeNameToken) {
2599  Double_t rangeLo = frame->getPlotVar()->getMin(rangeNameToken) ;
2600  Double_t rangeHi = frame->getPlotVar()->getMax(rangeNameToken) ;
2601  rangeLim.push_back(make_pair(rangeLo,rangeHi)) ;
2602  rangeNameToken = strtok(0,",") ;
2603  }
2604  adjustNorm = pc.getInt("rangeWNAdjustNorm") ;
2605  hasCustomRange = kTRUE ;
2606 
2607  coutI(Plotting) << "RooAbsPdf::plotOn(" << GetName() << ") only plotting range '" << pc.getString("rangeName",0,kTRUE) << "'" ;
2608  if (!pc.hasProcessed("NormRange")) {
2609  ccoutI(Plotting) << ", curve is normalized to data in " << (adjustNorm?"given":"full") << " given range" << endl ;
2610  } else {
2611  ccoutI(Plotting) << endl ;
2612  }
2613 
2614  nameSuffix.Append(Form("_Range[%s]",pc.getString("rangeName"))) ;
2615  }
2616  // Specification of a normalization range override those in a regular ranage
2617  if (pc.hasProcessed("NormRange")) {
2618  char tmp[1024] ;
2619  strlcpy(tmp,pc.getString("normRangeName",0,kTRUE),1024) ;
2620  char* rangeNameToken = strtok(tmp,",") ;
2621  rangeLim.clear() ;
2622  while(rangeNameToken) {
2623  Double_t rangeLo = frame->getPlotVar()->getMin(rangeNameToken) ;
2624  Double_t rangeHi = frame->getPlotVar()->getMax(rangeNameToken) ;
2625  rangeLim.push_back(make_pair(rangeLo,rangeHi)) ;
2626  rangeNameToken = strtok(0,",") ;
2627  }
2628  adjustNorm = kTRUE ;
2629  hasCustomRange = kTRUE ;
2630  coutI(Plotting) << "RooAbsPdf::plotOn(" << GetName() << ") p.d.f. curve is normalized using explicit choice of ranges '" << pc.getString("normRangeName",0,kTRUE) << "'" << endl ;
2631 
2632  nameSuffix.Append(Form("_NormRange[%s]",pc.getString("rangeName"))) ;
2633 
2634  }
2635 
2636  if (hasCustomRange && adjustNorm) {
2637 
2638  Double_t rangeNevt(0) ;
2639  list<pair<Double_t,Double_t> >::iterator riter = rangeLim.begin() ;
2640  for (;riter!=rangeLim.end() ; ++riter) {
2641  Double_t nevt= frame->getFitRangeNEvt(riter->first,riter->second) ;
2642  rangeNevt += nevt ;
2643  }
2644  scaleFactor *= rangeNevt/nExpected ;
2645 
2646  } else {
2647  scaleFactor *= frame->getFitRangeNEvt()/nExpected ;
2648  }
2649  } else if (stype==RelativeExpected) {
2650  scaleFactor *= nExpected ;
2651  } else if (stype==NumEvent) {
2652  scaleFactor /= nExpected ;
2653  }
2654  scaleFactor *= frame->getFitRangeBinW() ;
2655  }
2656  frame->updateNormVars(*frame->getPlotVar()) ;
2657 
2658  // Append overriding scale factor command at end of original command list
2659  RooCmdArg tmp = RooFit::Normalization(scaleFactor,Raw) ;
2660  tmp.setInt(1,1) ; // Flag this normalization command as created for internal use (so that VisualizeError can strip it)
2661  cmdList.Add(&tmp) ;
2662 
2663  // Was a component selected requested
2664  if (haveCompSel) {
2665 
2666  // Get complete set of tree branch nodes
2667  RooArgSet branchNodeSet ;
2668  branchNodeServerList(&branchNodeSet) ;
2669 
2670  // Discard any non-RooAbsReal nodes
2671  TIterator* iter = branchNodeSet.createIterator() ;
2672  RooAbsArg* arg ;
2673  while((arg=(RooAbsArg*)iter->Next())) {
2674  if (!dynamic_cast<RooAbsReal*>(arg)) {
2675  branchNodeSet.remove(*arg) ;
2676  }
2677  }
2678  delete iter ;
2679 
2680  // Obtain direct selection
2681  RooArgSet* dirSelNodes ;
2682  if (compSet) {
2683  dirSelNodes = (RooArgSet*) branchNodeSet.selectCommon(*compSet) ;
2684  } else {
2685  dirSelNodes = (RooArgSet*) branchNodeSet.selectByName(compSpec) ;
2686  }
2687  if (dirSelNodes->getSize()>0) {
2688  coutI(Plotting) << "RooAbsPdf::plotOn(" << GetName() << ") directly selected PDF components: " << *dirSelNodes << endl ;
2689 
2690  // Do indirect selection and activate both
2691  plotOnCompSelect(dirSelNodes) ;
2692  } else {
2693  if (compSet) {
2694  coutE(Plotting) << "RooAbsPdf::plotOn(" << GetName() << ") ERROR: component selection set " << *compSet << " does not match any components of p.d.f." << endl ;
2695  } else {
2696  coutE(Plotting) << "RooAbsPdf::plotOn(" << GetName() << ") ERROR: component selection expression '" << compSpec << "' does not select any components of p.d.f." << endl ;
2697  }
2698  return 0 ;
2699  }
2700 
2701  delete dirSelNodes ;
2702  }
2703 
2704 
2705  RooCmdArg cnsuffix("CurveNameSuffix",0,0,0,0,nameSuffix.Data(),0,0,0) ;
2706  cmdList.Add(&cnsuffix);
2707 
2708  RooPlot* ret = RooAbsReal::plotOn(frame,cmdList) ;
2709 
2710  // Restore selection status ;
2711  if (haveCompSel) plotOnCompSelect(0) ;
2712 
2713  if (plotRange) {
2714  delete plotRange ;
2715  }
2716  if (normRange2) {
2717  delete normRange2 ;
2718  }
2719 
2720  return ret ;
2721 }
2722 
2723 
2724 
2725 
2726 //_____________________________________________________________________________
2727 // coverity[PASS_BY_VALUE]
2729 {
2730  // Plot oneself on 'frame'. In addition to features detailed in RooAbsReal::plotOn(),
2731  // the scale factor for a PDF can be interpreted in three different ways. The interpretation
2732  // is controlled by ScaleType
2733  //
2734  // Relative - Scale factor is applied on top of PDF normalization scale factor
2735  // NumEvent - Scale factor is interpreted as a number of events. The surface area
2736  // under the PDF curve will match that of a histogram containing the specified
2737  // number of event
2738  // Raw - Scale factor is applied to the raw (projected) probability density.
2739  // Not too useful, option provided for completeness.
2740 
2741  // Sanity checks
2742  if (plotSanityChecks(frame)) return frame ;
2743 
2744  // More sanity checks
2745  Double_t nExpected(1) ;
2746  if (o.stype==RelativeExpected) {
2747  if (!canBeExtended()) {
2748  coutE(Plotting) << "RooAbsPdf::plotOn(" << GetName()
2749  << "): ERROR the 'Expected' scale option can only be used on extendable PDFs" << endl ;
2750  return frame ;
2751  }
2752  nExpected = expectedEvents(frame->getNormVars()) ;
2753  }
2754 
2755  // Adjust normalization, if so requested
2756  if (o.stype != Raw) {
2757 
2758  if (frame->getFitRangeNEvt() && o.stype==Relative) {
2759  // If non-default plotting range is specified, adjust number of events in fit range
2760  o.scaleFactor *= frame->getFitRangeNEvt()/nExpected ;
2761  } else if (o.stype==RelativeExpected) {
2762  o.scaleFactor *= nExpected ;
2763  } else if (o.stype==NumEvent) {
2764  o.scaleFactor /= nExpected ;
2765  }
2766  o.scaleFactor *= frame->getFitRangeBinW() ;
2767  }
2768  frame->updateNormVars(*frame->getPlotVar()) ;
2769 
2770  return RooAbsReal::plotOn(frame,o) ;
2771 }
2772 
2773 
2774 
2775 
2776 ////////////////////////////////////////////////////////////////////////////////
2777 /// Add a box with parameter values (and errors) to the specified frame
2778 ///
2779 /// The following named arguments are supported
2780 ///
2781 /// Parameters(const RooArgSet& param) -- Only the specified subset of parameters will be shown.
2782 /// By default all non-contant parameters are shown
2783 /// ShowConstants(Bool_t flag) -- Also display constant parameters
2784 /// Format(const char* optStr) -- Classing [arameter formatting options, provided for backward compatibility
2785 /// Format(const char* what,...) -- Parameter formatting options, details given below
2786 /// Label(const chat* label) -- Add header label to parameter box
2787 /// Layout(Double_t xmin, -- Specify relative position of left,right side of box and top of box. Position of
2788 /// Double_t xmax, Double_t ymax) bottom of box is calculated automatically from number lines in box
2789 ///
2790 ///
2791 /// The Format(const char* what,...) has the following structure
2792 ///
2793 /// const char* what -- Controls what is shown. "N" adds name, "E" adds error,
2794 /// "A" shows asymmetric error, "U" shows unit, "H" hides the value
2795 /// FixedPrecision(int n) -- Controls precision, set fixed number of digits
2796 /// AutoPrecision(int n) -- Controls precision. Number of shown digits is calculated from error
2797 /// + n specified additional digits (1 is sensible default)
2798 ///
2799 /// Example use: pdf.paramOn(frame, Label("fit result"), Format("NEU",AutoPrecision(1)) ) ;
2800 ///
2801 
2802 RooPlot* RooAbsPdf::paramOn(RooPlot* frame, const RooCmdArg& arg1, const RooCmdArg& arg2,
2803  const RooCmdArg& arg3, const RooCmdArg& arg4, const RooCmdArg& arg5,
2804  const RooCmdArg& arg6, const RooCmdArg& arg7, const RooCmdArg& arg8)
2805 {
2806  // Stuff all arguments in a list
2807  RooLinkedList cmdList;
2808  cmdList.Add(const_cast<RooCmdArg*>(&arg1)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg2)) ;
2809  cmdList.Add(const_cast<RooCmdArg*>(&arg3)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg4)) ;
2810  cmdList.Add(const_cast<RooCmdArg*>(&arg5)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg6)) ;
2811  cmdList.Add(const_cast<RooCmdArg*>(&arg7)) ; cmdList.Add(const_cast<RooCmdArg*>(&arg8)) ;
2812 
2813  // Select the pdf-specific commands
2814  RooCmdConfig pc(Form("RooAbsPdf::paramOn(%s)",GetName())) ;
2815  pc.defineString("label","Label",0,"") ;
2816  pc.defineDouble("xmin","Layout",0,0.50) ;
2817  pc.defineDouble("xmax","Layout",1,0.99) ;
2818  pc.defineInt("ymaxi","Layout",0,Int_t(0.95*10000)) ;
2819  pc.defineInt("showc","ShowConstants",0,0) ;
2820  pc.defineObject("params","Parameters",0,0) ;
2821  pc.defineString("formatStr","Format",0,"NELU") ;
2822  pc.defineInt("sigDigit","Format",0,2) ;
2823  pc.defineInt("dummy","FormatArgs",0,0) ;
2824  pc.defineMutex("Format","FormatArgs") ;
2825 
2826  // Process and check varargs
2827  pc.process(cmdList) ;
2828  if (!pc.ok(kTRUE)) {
2829  return frame ;
2830  }
2831 
2832  const char* label = pc.getString("label") ;
2833  Double_t xmin = pc.getDouble("xmin") ;
2834  Double_t xmax = pc.getDouble("xmax") ;
2835  Double_t ymax = pc.getInt("ymaxi") / 10000. ;
2836  Int_t showc = pc.getInt("showc") ;
2837 
2838 
2839  const char* formatStr = pc.getString("formatStr") ;
2840  Int_t sigDigit = pc.getInt("sigDigit") ;
2841 
2842  // Decode command line arguments
2843  RooArgSet* params = static_cast<RooArgSet*>(pc.getObject("params")) ;
2844  if (!params) {
2845  params = getParameters(frame->getNormVars()) ;
2846  if (pc.hasProcessed("FormatArgs")) {
2847  const RooCmdArg* formatCmd = static_cast<RooCmdArg*>(cmdList.FindObject("FormatArgs")) ;
2848  paramOn(frame,*params,showc,label,0,0,xmin,xmax,ymax,formatCmd) ;
2849  } else {
2850  paramOn(frame,*params,showc,label,sigDigit,formatStr,xmin,xmax,ymax) ;
2851  }
2852  delete params ;
2853  } else {
2854  RooArgSet* pdfParams = getParameters(frame->getNormVars()) ;
2855  RooArgSet* selParams = static_cast<RooArgSet*>(pdfParams->selectCommon(*params)) ;
2856  if (pc.hasProcessed("FormatArgs")) {
2857  const RooCmdArg* formatCmd = static_cast<RooCmdArg*>(cmdList.FindObject("FormatArgs")) ;
2858  paramOn(frame,*selParams,showc,label,0,0,xmin,xmax,ymax,formatCmd) ;
2859  } else {
2860  paramOn(frame,*selParams,showc,label,sigDigit,formatStr,xmin,xmax,ymax) ;
2861  }
2862  delete selParams ;
2863  delete pdfParams ;
2864  }
2865 
2866  return frame ;
2867 }
2868 
2869 
2870 
2871 
2872 ////////////////////////////////////////////////////////////////////////////////
2873 /// OBSOLETE FUNCTION PROVIDED FOR BACKWARD COMPATIBILITY
2874 
2875 RooPlot* RooAbsPdf::paramOn(RooPlot* frame, const RooAbsData* data, const char *label,
2876  Int_t sigDigits, Option_t *options, Double_t xmin,
2878 {
2879  RooArgSet* params = getParameters(data) ;
2880  TString opts(options) ;
2881  paramOn(frame,*params,opts.Contains("c"),label,sigDigits,options,xmin,xmax,ymax) ;
2882  delete params ;
2883  return frame ;
2884 }
2885 
2886 
2887 
2888 ////////////////////////////////////////////////////////////////////////////////
2889 /// Add a text box with the current parameter values and their errors to the frame.
2890 /// Observables of this PDF appearing in the 'data' dataset will be omitted.
2891 ///
2892 /// Optional label will be inserted as first line of the text box. Use 'sigDigits'
2893 /// to modify the default number of significant digits printed. The 'xmin,xmax,ymax'
2894 /// values specify the inital relative position of the text box in the plot frame
2895 
2896 RooPlot* RooAbsPdf::paramOn(RooPlot* frame, const RooArgSet& params, Bool_t showConstants, const char *label,
2897  Int_t sigDigits, Option_t *options, Double_t xmin,
2898  Double_t xmax ,Double_t ymax, const RooCmdArg* formatCmd)
2899 {
2900 
2901  // parse the options
2902  TString opts = options;
2903  opts.ToLower();
2904  Bool_t showLabel= (label != 0 && strlen(label) > 0);
2905 
2906  // calculate the box's size, adjusting for constant parameters
2907  TIterator* pIter = params.createIterator() ;
2908 
2909  Double_t ymin(ymax), dy(0.06);
2910  RooRealVar *var = 0;
2911  while((var=(RooRealVar*)pIter->Next())) {
2912  if(showConstants || !var->isConstant()) ymin-= dy;
2913  }
2914 
2915  if(showLabel) ymin-= dy;
2916 
2917  // create the box and set its options
2918  TPaveText *box= new TPaveText(xmin,ymax,xmax,ymin,"BRNDC");
2919  if(!box) return 0;
2920  box->SetName(Form("%s_paramBox",GetName())) ;
2921  box->SetFillColor(0);
2922  box->SetBorderSize(1);
2923  box->SetTextAlign(12);
2924  box->SetTextSize(0.04F);
2925  box->SetFillStyle(1001);
2926  box->SetFillColor(0);
2927  //char buffer[512];
2928  pIter->Reset() ;
2929  while((var=(RooRealVar*)pIter->Next())) {
2930  if(var->isConstant() && !showConstants) continue;
2931 
2932  TString *formatted= options ? var->format(sigDigits, options) : var->format(*formatCmd) ;
2933  box->AddText(formatted->Data());
2934  delete formatted;
2935  }
2936  // add the optional label if specified
2937  if(showLabel) box->AddText(label);
2938 
2939  // Add box to frame
2940  frame->addObject(box) ;
2941 
2942  delete pIter ;
2943  return frame ;
2944 }
2945 
2946 
2947 
2948 
2949 ////////////////////////////////////////////////////////////////////////////////
2950 /// Return expected number of events from this p.d.f for use in extended
2951 /// likelihood calculations. This default implementation returns zero
2952 
2954 {
2955  return 0 ;
2956 }
2957 
2958 
2959 
2960 ////////////////////////////////////////////////////////////////////////////////
2961 /// Change global level of verbosity for p.d.f. evaluations
2962 
2964 {
2965  _verboseEval = stat ;
2966 }
2967 
2968 
2969 
2970 ////////////////////////////////////////////////////////////////////////////////
2971 /// Return global level of verbosity for p.d.f. evaluations
2972 
2974 {
2975  return _verboseEval ;
2976 }
2977 
2978 
2979 
2980 ////////////////////////////////////////////////////////////////////////////////
2981 /// Dummy implementation
2982 
2984 {
2985 }
2986 
2987 
2988 
2989 ////////////////////////////////////////////////////////////////////////////////
2990 /// Destructor of normalization cache element. If this element
2991 /// provides the 'current' normalization stored in RooAbsPdf::_norm
2992 /// zero _norm pointer here before object pointed to is deleted here
2993 
2995 {
2996  // Zero _norm pointer in RooAbsPdf if it is points to our cache payload
2997  if (_owner) {
2998  RooAbsPdf* pdfOwner = static_cast<RooAbsPdf*>(_owner) ;
2999  if (pdfOwner->_norm == _norm) {
3000  pdfOwner->_norm = 0 ;
3001  }
3002  }
3003 
3004  delete _norm ;
3005 }
3006 
3007 
3008 
3009 ////////////////////////////////////////////////////////////////////////////////
3010 /// Return a p.d.f that represent a projection of this p.d.f integrated over given observables
3011 
3013 {
3014  // Construct name for new object
3015  TString name(GetName()) ;
3016  name.Append("_Proj[") ;
3017  if (iset.getSize()>0) {
3018  TIterator* iter = iset.createIterator() ;
3019  RooAbsArg* arg ;
3020  Bool_t first(kTRUE) ;
3021  while((arg=(RooAbsArg*)iter->Next())) {
3022  if (first) {
3023  first=kFALSE ;
3024  } else {
3025  name.Append(",") ;
3026  }
3027  name.Append(arg->GetName()) ;
3028  }
3029  delete iter ;
3030  }
3031  name.Append("]") ;
3032 
3033  // Return projected p.d.f.
3034  return new RooProjectedPdf(name.Data(),name.Data(),*this,iset) ;
3035 }
3036 
3037 
3038 
3039 ////////////////////////////////////////////////////////////////////////////////
3040 /// Create a cumulative distribution function of this p.d.f in terms
3041 /// of the observables listed in iset. If no nset argument is given
3042 /// the c.d.f normalization is constructed over the integrated
3043 /// observables, so that its maximum value is precisely 1. It is also
3044 /// possible to choose a different normalization for
3045 /// multi-dimensional p.d.f.s: eg. for a pdf f(x,y,z) one can
3046 /// construct a partial cdf c(x,y) that only when integrated itself
3047 /// over z results in a maximum value of 1. To construct such a cdf pass
3048 /// z as argument to the optional nset argument
3049 
3051 {
3052  return createCdf(iset,RooFit::SupNormSet(nset)) ;
3053 }
3054 
3055 
3056 
3057 ////////////////////////////////////////////////////////////////////////////////
3058 /// Create an object that represents the integral of the function over one or more observables listed in iset
3059 /// The actual integration calculation is only performed when the return object is evaluated. The name
3060 /// of the integral object is automatically constructed from the name of the input function, the variables
3061 /// it integrates and the range integrates over
3062 ///
3063 /// The following named arguments are accepted
3064 ///
3065 /// SupNormSet(const RooArgSet&) -- Observables over which should be normalized _in_addition_ to the
3066 /// integration observables
3067 /// ScanNumCdf() -- Apply scanning technique if cdf integral involves numeric integration [ default ]
3068 /// ScanAllCdf() -- Always apply scanning technique
3069 /// ScanNoCdf() -- Never apply scanning technique
3070 /// ScanParameters(Int_t nbins, -- Parameters for scanning technique of making CDF: number
3071 /// Int_t intOrder) of sampled bins and order of interpolation applied on numeric cdf
3072 
3073 RooAbsReal* RooAbsPdf::createCdf(const RooArgSet& iset, const RooCmdArg& arg1, const RooCmdArg& arg2,
3074  const RooCmdArg& arg3, const RooCmdArg& arg4, const RooCmdArg& arg5,
3075  const RooCmdArg& arg6, const RooCmdArg& arg7, const RooCmdArg& arg8)
3076 {
3077  // Define configuration for this method
3078  RooCmdConfig pc(Form("RooAbsReal::createCdf(%s)",GetName())) ;
3079  pc.defineObject("supNormSet","SupNormSet",0,0) ;
3080  pc.defineInt("numScanBins","ScanParameters",0,1000) ;
3081  pc.defineInt("intOrder","ScanParameters",1,2) ;
3082  pc.defineInt("doScanNum","ScanNumCdf",0,1) ;
3083  pc.defineInt("doScanAll","ScanAllCdf",0,0) ;
3084  pc.defineInt("doScanNon","ScanNoCdf",0,0) ;
3085  pc.defineMutex("ScanNumCdf","ScanAllCdf","ScanNoCdf") ;
3086 
3087  // Process & check varargs
3088  pc.process(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8) ;
3089  if (!pc.ok(kTRUE)) {
3090  return 0 ;
3091  }
3092 
3093  // Extract values from named arguments
3094  const RooArgSet* snset = static_cast<const RooArgSet*>(pc.getObject("supNormSet",0)) ;
3095  RooArgSet nset ;
3096  if (snset) {
3097  nset.add(*snset) ;
3098  }
3099  Int_t numScanBins = pc.getInt("numScanBins") ;
3100  Int_t intOrder = pc.getInt("intOrder") ;
3101  Int_t doScanNum = pc.getInt("doScanNum") ;
3102  Int_t doScanAll = pc.getInt("doScanAll") ;
3103  Int_t doScanNon = pc.getInt("doScanNon") ;
3104 
3105  // If scanning technique is not requested make integral-based cdf and return
3106  if (doScanNon) {
3107  return createIntRI(iset,nset) ;
3108  }
3109  if (doScanAll) {
3110  return createScanCdf(iset,nset,numScanBins,intOrder) ;
3111  }
3112  if (doScanNum) {
3114  Int_t isNum= (tmp->numIntRealVars().getSize()>0) ;
3115  delete tmp ;
3116 
3117  if (isNum) {
3118  coutI(NumIntegration) << "RooAbsPdf::createCdf(" << GetName() << ") integration over observable(s) " << iset << " involves numeric integration," << endl
3119  << " constructing cdf though numeric integration of sampled pdf in " << numScanBins << " bins and applying order "
3120  << intOrder << " interpolation on integrated histogram." << endl
3121  << " To override this choice of technique use argument ScanNone(), to change scan parameters use ScanParameters(nbins,order) argument" << endl ;
3122  }
3123 
3124  return isNum ? createScanCdf(iset,nset,numScanBins,intOrder) : createIntRI(iset,nset) ;
3125  }
3126  return 0 ;
3127 }
3128 
3129 RooAbsReal* RooAbsPdf::createScanCdf(const RooArgSet& iset, const RooArgSet& nset, Int_t numScanBins, Int_t intOrder)
3130 {
3131  string name = string(GetName()) + "_NUMCDF_" + integralNameSuffix(iset,&nset).Data() ;
3132  RooRealVar* ivar = (RooRealVar*) iset.first() ;
3133  ivar->setBins(numScanBins,"numcdf") ;
3134  RooNumCdf* ret = new RooNumCdf(name.c_str(),name.c_str(),*this,*ivar,"numcdf") ;
3135  ret->setInterpolationOrder(intOrder) ;
3136  return ret ;
3137 }
3138 
3139 
3140 
3141 
3142 ////////////////////////////////////////////////////////////////////////////////
3143 /// This helper function finds and collects all constraints terms of all coponent p.d.f.s
3144 /// and returns a RooArgSet with all those terms
3145 
3146 RooArgSet* RooAbsPdf::getAllConstraints(const RooArgSet& observables, RooArgSet& constrainedParams, Bool_t stripDisconnected) const
3147 {
3148  RooArgSet* ret = new RooArgSet("AllConstraints") ;
3149 
3150  RooArgSet* comps = getComponents() ;
3151  TIterator* iter = comps->createIterator() ;
3152  RooAbsArg *arg ;
3153  while((arg=(RooAbsArg*)iter->Next())) {
3154  RooAbsPdf* pdf = dynamic_cast<RooAbsPdf*>(arg) ;
3155  if (pdf && !ret->find(pdf->GetName())) {
3156  RooArgSet* compRet = pdf->getConstraints(observables,constrainedParams,stripDisconnected) ;
3157  if (compRet) {
3158  ret->add(*compRet,kFALSE) ;
3159  delete compRet ;
3160  }
3161  }
3162  }
3163  delete iter ;
3164  delete comps ;
3165 
3166  return ret ;
3167 }
3168 
3169 
3170 ////////////////////////////////////////////////////////////////////////////////
3171 /// Clear the evaluation error flag
3172 
3174 {
3175  _evalError = kFALSE ;
3176 }
3177 
3178 
3179 
3180 ////////////////////////////////////////////////////////////////////////////////
3181 /// Return the evaluation error flag
3182 
3184 {
3185  return _evalError ;
3186 }
3187 
3188 
3189 
3190 ////////////////////////////////////////////////////////////////////////////////
3191 /// Raise the evaluation error flag
3192 
3194 {
3195  _evalError = kTRUE ;
3196 }
3197 
3198 
3199 
3200 ////////////////////////////////////////////////////////////////////////////////
3201 /// Returns the default numeric MC generator configuration for all RooAbsReals
3202 
3204 {
3205  return &RooNumGenConfig::defaultConfig() ;
3206 }
3207 
3208 
3209 ////////////////////////////////////////////////////////////////////////////////
3210 /// Returns the specialized integrator configuration for _this_ RooAbsReal.
3211 /// If this object has no specialized configuration, a null pointer is returned
3212 
3214 {
3215  return _specGeneratorConfig ;
3216 }
3217 
3218 
3219 
3220 ////////////////////////////////////////////////////////////////////////////////
3221 /// Returns the specialized integrator configuration for _this_ RooAbsReal.
3222 /// If this object has no specialized configuration, a null pointer is returned,
3223 /// unless createOnTheFly is kTRUE in which case a clone of the default integrator
3224 /// configuration is created, installed as specialized configuration, and returned
3225 
3227 {
3228  if (!_specGeneratorConfig && createOnTheFly) {
3230  }
3231  return _specGeneratorConfig ;
3232 }
3233 
3234 
3235 
3236 ////////////////////////////////////////////////////////////////////////////////
3237 /// Return the numeric MC generator configuration used for this object. If
3238 /// a specialized configuration was associated with this object, that configuration
3239 /// is returned, otherwise the default configuration for all RooAbsReals is returned
3240 
3242 {
3243  const RooNumGenConfig* config = specialGeneratorConfig() ;
3244  if (config) return config ;
3245  return defaultGeneratorConfig() ;
3246 }
3247 
3248 
3249 
3250 ////////////////////////////////////////////////////////////////////////////////
3251 /// Set the given configuration as default numeric MC generator
3252 /// configuration for this object
3253 
3255 {
3256  if (_specGeneratorConfig) {
3257  delete _specGeneratorConfig ;
3258  }
3259  _specGeneratorConfig = new RooNumGenConfig(config) ;
3260 }
3261 
3262 
3263 
3264 ////////////////////////////////////////////////////////////////////////////////
3265 /// Remove the specialized numeric MC generator configuration associated
3266 /// with this object
3267 
3269 {
3270  if (_specGeneratorConfig) {
3271  delete _specGeneratorConfig ;
3272  }
3273  _specGeneratorConfig = 0 ;
3274 }
3275 
3276 
3277 
3278 ////////////////////////////////////////////////////////////////////////////////
3279 
3281 {
3282  delete _genContext ;
3283 }
3284 
3285 
3286 ////////////////////////////////////////////////////////////////////////////////
3287 
3288 RooAbsPdf::GenSpec::GenSpec(RooAbsGenContext* context, const RooArgSet& whatVars, RooDataSet* protoData, Int_t nGen,
3289  Bool_t extended, Bool_t randProto, Bool_t resampleProto, TString dsetName, Bool_t init) :
3290  _genContext(context), _whatVars(whatVars), _protoData(protoData), _nGen(nGen), _extended(extended),
3291  _randProto(randProto), _resampleProto(resampleProto), _dsetName(dsetName), _init(init)
3292 {
3293 }
3294 
3295 
3296 
3297 ////////////////////////////////////////////////////////////////////////////////
3298 
3299 void RooAbsPdf::setNormRange(const char* rangeName)
3300 {
3301  if (rangeName) {
3302  _normRange = rangeName ;
3303  } else {
3304  _normRange.Clear() ;
3305  }
3306 
3307  if (_norm) {
3308  _normMgr.sterilize() ;
3309  _norm = 0 ;
3310  }
3311 }
3312 
3313 
3314 ////////////////////////////////////////////////////////////////////////////////
3315 
3316 void RooAbsPdf::setNormRangeOverride(const char* rangeName)
3317 {
3318  if (rangeName) {
3319  _normRangeOverride = rangeName ;
3320  } else {
3321  _normRangeOverride.Clear() ;
3322  }
3323 
3324  if (_norm) {
3325  _normMgr.sterilize() ;
3326  _norm = 0 ;
3327  }
3328 }
virtual RooAbsReal * createNLL(RooAbsData &data, const RooLinkedList &cmdList)
Construct representation of -log(L) of PDFwith given dataset.
Definition: RooAbsPdf.cxx:778
virtual Double_t getMin(const char *name=0) const
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
Definition: RooAbsArg.cxx:2073
void operModeHook(RooAbsArg::OperMode)
Dummy implementation.
Definition: RooAbsPdf.cxx:2983
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
void setInterpolationOrder(Int_t order)
Set interpolation order of RooHistFunct representing cache histogram.
TIterator * createIterator(Bool_t dir=kIterForward) const
#define coutE(a)
Definition: RooMsgService.h:34
virtual void printStream(std::ostream &os, Int_t contents, StyleOption style, TString indent="") const
Print description of object on ostream, printing contents set by contents integer, which is interpreted as an OR of &#39;enum ContentsOptions&#39; values and in the style given by &#39;enum StyleOption&#39;.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Bool_t _selectComp
Definition: RooAbsPdf.h:331
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg(), const RooCmdArg &arg10=RooCmdArg()) const
Plot (project) PDF on specified frame.
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
float xmin
Definition: THbookFile.cxx:93
void SetName(const char *name)
Change the name of this dataset into the given name.
virtual RooFitResult * chi2FitTo(RooDataHist &data, const RooLinkedList &cmdList)
Internal back-end function to steer chi2 fits.
Definition: RooAbsPdf.cxx:1474
virtual void SetName(const char *name="")
Definition: TPave.h:72
void setPrintEvalErrors(Int_t numEvalErrors)
Definition: RooMinuit.h:72
virtual Double_t getMax(const char *name=0) const
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:86
virtual const RooArgSet * get() const
Definition: RooDataHist.h:77
void setVerbose(Bool_t flag=kTRUE)
Definition: RooMinuit.h:73
auto * m
Definition: textangle.C:8
void optimizeConst(Int_t flag)
If flag is true, perform constant term optimization on function being minimized.
Bool_t dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=0, Bool_t valueOnly=kFALSE) const
Test whether we depend on (ie, are served by) any object in the specified collection.
Definition: RooAbsArg.cxx:735
void setTraceCounter(Int_t value, Bool_t allNodes=kFALSE)
Reset trace counter to given value, limiting the number of future trace messages for this pdf to &#39;val...
Definition: RooAbsPdf.cxx:581
#define cxcoutI(a)
Definition: RooMsgService.h:83
virtual void Reset()=0
void plotOnCompSelect(RooArgSet *selNodes) const
Helper function for plotting of composite p.d.fs.
void applyCovarianceMatrix(TMatrixDSym &V)
Apply results of given external covariance matrix.
virtual RooAbsReal * createChi2(RooDataHist &data, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Create a chi-2 from a histogram and this function.
Definition: RooAbsPdf.cxx:1510
Bool_t defineDouble(const char *name, const char *argName, Int_t doubleNum, Double_t defValue=0.)
Define Double_t property name &#39;name&#39; mapped to Double_t in slot &#39;doubleNum&#39; in RooCmdArg with name ar...
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Definition: RooAbsArg.h:194
Double_t scaleFactor
Definition: RooAbsReal.h:420
virtual const RooArgSet * get() const
Definition: RooAbsData.h:79
virtual Bool_t Remove(TObject *arg)
Remove object from collection.
virtual RooDataHist * generateBinned(const RooArgSet &whatVars, Double_t nEvents, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none())
Generate a new dataset containing the specified variables with events sampled from our distribution...
Definition: RooAbsPdf.cxx:2198
virtual Double_t evaluate() const =0
const char Option_t
Definition: RtypesCore.h:62
RooAbsCollection * selectCommon(const RooAbsCollection &refColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
void addObject(TObject *obj, Option_t *drawOptions="", Bool_t invisible=kFALSE)
Add a generic object to this plot.
Definition: RooPlot.cxx:391
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Print multi line detailed information of this RooAbsPdf.
Definition: RooAbsPdf.cxx:1634
#define coutI(a)
Definition: RooMsgService.h:31
float ymin
Definition: THbookFile.cxx:93
Int_t hesse()
Execute HESSE.
Definition: RooMinuit.cxx:343
const char * getString(const char *name, const char *defaultValue="", Bool_t convEmptyToNull=kFALSE)
Return string property registered with name &#39;name&#39;.
Class RooNumCdf is an implementation of RooNumRunningInt specialized to calculate cumulative distribu...
Definition: RooNumCdf.h:17
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
#define cxcoutD(a)
Definition: RooMsgService.h:79
virtual ~RooAbsPdf()
Destructor.
Definition: RooAbsPdf.cxx:235
virtual Bool_t selfNormalized() const
Definition: RooAbsPdf.h:202
void setGeneratorConfig()
Remove the specialized numeric MC generator configuration associated with this object.
Definition: RooAbsPdf.cxx:3268
const TMatrixDSym & covarianceMatrix() const
Return covariance matrix.
static const char * str(const TNamed *ptr)
Return C++ string corresponding to given TNamed pointer.
Definition: RooNameReg.cxx:135
Int_t _errorCount
Definition: RooAbsPdf.h:324
TString _normRange
MC generator configuration specific for this object.
Definition: RooAbsPdf.h:339
Normalization set with for above integral.
Definition: RooAbsPdf.h:304
void set(Double_t weight, Double_t wgtErr=-1)
Increment the weight of the bin enclosing the coordinates given by &#39;row&#39; by the specified amount...
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
Definition: TPaveText.cxx:182
Bool_t isValid() const
Int_t minos()
Execute MINOS.
Definition: RooMinuit.cxx:376
Bool_t defineSet(const char *name, const char *argName, Int_t setNum, const RooArgSet *set=0)
Define TObject property name &#39;name&#39; mapped to object in slot &#39;setNum&#39; in RooCmdArg with name argName ...
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Structure printing.
Definition: RooAbsReal.cxx:422
void setNormRange(const char *rangeName)
Definition: RooAbsPdf.cxx:3299
void setNameList(const char *givenList)
Definition: RooNameSet.cxx:144
RooCmdArg NumEvents(Int_t numEvents)
void updateNormVars(const RooArgSet &vars)
Install the given set of observables are reference normalization variables for this frame...
Definition: RooPlot.cxx:349
static UInt_t integer(UInt_t max, TRandom *generator=randomGenerator())
Return an integer uniformly distributed from [0,n-1].
Definition: RooRandom.cxx:102
static Bool_t _evalError
Definition: RooAbsPdf.h:335
Int_t * randomizeProtoOrder(Int_t nProto, Int_t nGen, Bool_t resample=kFALSE) const
Return lookup table with randomized access order for prototype events, given nProto prototype data ev...
Definition: RooAbsPdf.cxx:2080
virtual Double_t getLogVal(const RooArgSet *set=0) const
Return the log of the current value with given normalization An error message is printed if the argum...
Definition: RooAbsPdf.cxx:607
RooInt is a minimal implementation of a TObject holding a Int_t value.
Definition: RooInt.h:22
RooNumGenConfig * _specGeneratorConfig
Definition: RooAbsPdf.h:337
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
friend class RooProjectedPdf
Definition: RooAbsArg.h:427
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
Definition: RooAbsArg.h:75
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition: TAttFill.h:39
GenSpec * prepareMultiGen(const RooArgSet &whatVars, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none())
Prepare GenSpec configuration object for efficient generation of multiple datasets from idetical spec...
Definition: RooAbsPdf.cxx:1878
Bool_t IsNaN(Double_t x)
Definition: TMath.h:891
void allowUndefined(Bool_t flag=kTRUE)
Definition: RooCmdConfig.h:39
void setProxyNormSet(const RooArgSet *nset)
Forward a change in the cached normalization argset to all the registered proxies.
Definition: RooAbsArg.cxx:1269
Bool_t addOwnedComponents(const RooArgSet &comps)
Take ownership of the contents of &#39;comps&#39;.
Definition: RooAbsArg.cxx:2273
STL namespace.
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none(), const RooCmdArg &arg9=RooCmdArg::none(), const RooCmdArg &arg10=RooCmdArg::none()) const
Plot (project) PDF on specified frame.
Definition: RooAbsPdf.h:105
Int_t migrad()
Execute MIGRAD.
Definition: RooMinuit.cxx:309
void setStrategy(Int_t strat)
Change MINUIT strategy to istrat.
Definition: RooMinuit.cxx:221
#define coutW(a)
Definition: RooMsgService.h:33
TObject * getObject(const char *name, TObject *obj=0)
Return TObject property registered with name &#39;name&#39;.
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
RooCmdArg SupNormSet(const RooArgSet &nset)
static TString _normRangeOverride
Definition: RooAbsPdf.h:340
static int verboseEval()
Return global level of verbosity for p.d.f. evaluations.
Definition: RooAbsPdf.cxx:2973
#define ccoutI(a)
Definition: RooMsgService.h:38
Iterator abstract base class.
Definition: TIterator.h:30
header file containing the templated implementation of matrix inversion routines for use with ROOT&#39;s ...
void setMinimizerType(const char *type)
Choose the minimzer algorithm.
Double_t analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=0) const
Analytical integral with normalization (see RooAbsReal::analyticalIntegralWN() for further informatio...
Definition: RooAbsPdf.cxx:322
Double_t getFitRangeBinW() const
Definition: RooPlot.h:135
void setStrategy(Int_t strat)
Change MINUIT strategy to istrat.
RooDataSet * _protoData
Definition: RooAbsPdf.h:77
void setEvalErrorWall(Bool_t flag)
Definition: RooMinuit.h:51
RooAbsArg * findServer(const char *name) const
Definition: RooAbsArg.h:122
RooAbsGenContext * _genContext
Definition: RooAbsPdf.h:75
RooAbsReal * createCdf(const RooArgSet &iset, const RooArgSet &nset=RooArgSet())
Create a cumulative distribution function of this p.d.f in terms of the observables listed in iset...
Definition: RooAbsPdf.cxx:3050
RooAbsReal * createScanCdf(const RooArgSet &iset, const RooArgSet &nset, Int_t numScanBins, Int_t intOrder)
Definition: RooAbsPdf.cxx:3129
RooDataHist * fillDataHist(RooDataHist *hist, const RooArgSet *nset, Double_t scaleFactor, Bool_t correctForBinVolume=kFALSE, Bool_t showProgress=kFALSE) const
Fill a RooDataHist with values sampled from this function at the bin centers.
Bool_t process(const RooCmdArg &arg)
Process given RooCmdArg.
RooAbsReal * createIntRI(const RooArgSet &iset, const RooArgSet &nset=RooArgSet())
Utility function for createRunningIntegral that construct an object implementing the standard (analyt...
double sqrt(double)
RooCmdArg Range(const char *rangeName, Bool_t adjustNorm=kTRUE)
void setVerbose(Bool_t flag=kTRUE)
Definition: RooMinimizer.h:74
Bool_t traceEvalPdf(Double_t value) const
Check that passed value is positive and not &#39;not-a-number&#39;.
Definition: RooAbsPdf.cxx:342
static void setEvalErrorLoggingMode(ErrorLoggingMode m)
Set evaluation error logging mode.
void clearValueAndShapeDirty() const
Definition: RooAbsArg.h:444
RooDataSet is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:40
friend class CacheElem
Definition: RooAbsPdf.h:314
RooRealIntegral performs hybrid numerical/analytical integrals of RooAbsReal objects The class perfor...
void applyCovarianceMatrix(TMatrixDSym &V)
Apply results of given external covariance matrix.
Definition: RooMinuit.cxx:1182
RooAbsPdf()
Default constructor.
Definition: RooAbsPdf.cxx:177
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
RooNumGenConfig * specialGeneratorConfig() const
Returns the specialized integrator configuration for this RooAbsReal.
Definition: RooAbsPdf.cxx:3213
T * getObj(const RooArgSet *nset, Int_t *sterileIndex=0, const TNamed *isetRangeName=0)
RooConstraintSum calculates the sum of the -(log) likelihoods of a set of RooAbsPfs that represent co...
Int_t setPrintLevel(Int_t newLevel)
Change the MINUIT internal printing level.
Definition: RooMinuit.cxx:569
virtual RooArgSet * getConstraints(const RooArgSet &, RooArgSet &, Bool_t) const
Definition: RooAbsPdf.h:168
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition: RooAbsArg.h:227
virtual UInt_t Integer(UInt_t imax)
Returns a random integer on [ 0, imax-1 ].
Definition: TRandom.cxx:341
RooAbsCollection * selectByAttrib(const char *name, Bool_t value) const
Create a subset of the current collection, consisting only of those elements with the specified attri...
Bool_t defineString(const char *name, const char *argName, Int_t stringNum, const char *defValue="", Bool_t appendMode=kFALSE)
Define Double_t property name &#39;name&#39; mapped to Double_t in slot &#39;stringNum&#39; in RooCmdArg with name ar...
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition: RooRandom.cxx:54
virtual Double_t weight() const
Definition: RooDataHist.h:96
friend class RooArgSet
Definition: RooAbsArg.h:471
const RooArgSet * getNormVars() const
Definition: RooPlot.h:139
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
void setBins(Int_t nBins, const char *name=0)
Definition: RooRealVar.h:77
virtual RooAbsPdf * createProjection(const RooArgSet &iset)
Return a p.d.f that represent a projection of this p.d.f integrated over given observables.
Definition: RooAbsPdf.cxx:3012
RooAbsGenContext is the abstract base class for generator contexts of RooAbsPdf objects.
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
virtual Double_t expectedEvents(const RooArgSet *nset) const
Return expected number of events from this p.d.f for use in extended likelihood calculations.
Definition: RooAbsPdf.cxx:2953
virtual RooAbsGenContext * binnedGenContext(const RooArgSet &vars, Bool_t verbose=kFALSE) const
Return a binned generator context.
Definition: RooAbsPdf.cxx:1651
static void clearEvalError()
Clear the evaluation error flag.
Definition: RooAbsPdf.cxx:3173
virtual Bool_t syncNormalization(const RooArgSet *dset, Bool_t adjustProxies=kTRUE) const
Verify that the normalization integral cached with this PDF is valid for given set of normalization o...
Definition: RooAbsPdf.cxx:436
Bool_t defineInt(const char *name, const char *argName, Int_t intNum, Int_t defValue=0)
Define integer property name &#39;name&#39; mapped to integer in slot &#39;intNum&#39; in RooCmdArg with name argName...
virtual void enableOffsetting(Bool_t)
Definition: RooAbsReal.h:307
void stripCmdList(RooLinkedList &cmdList, const char *cmdsToPurge)
Utility function that strips command names listed (comma separated) in cmdsToPurge from cmdList...
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition: TAttText.h:41
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
const RooArgSet & numIntRealVars() const
void SetName(const char *name)
Change the name of the RooDataHist.
virtual Double_t getValV(const RooArgSet *set=0) const
Return current value, normalizated by integrating over the observables in &#39;nset&#39;. ...
Definition: RooAbsPdf.cxx:253
Bool_t getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
Definition: RooAbsArg.cxx:263
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:62
#define F(x, y, z)
RooNameSet is a utility class that stores the names the objects in a RooArget.
Definition: RooNameSet.h:24
RooAbsReal * _norm
Definition: RooAbsPdf.h:301
Int_t getSize() const
RooAbsReal * createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Create an object that represents the integral of the function over one or more observables listed in ...
Definition: RooAbsReal.cxx:501
float ymax
Definition: THbookFile.cxx:93
RooAbsReal * _norm
Definition: RooAbsPdf.h:310
Class RooNLLVar implements a a -log(likelihood) calculation from a dataset and a PDF.
Definition: RooNLLVar.h:26
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
virtual void setExpectedData(Bool_t)
void defineMutex(const char *argName1, const char *argName2)
Define arguments named argName1 and argName2 mutually exclusive.
Int_t getInt(const char *name, Int_t defaultValue=0)
Return integer property registered with name &#39;name&#39;.
static RooNumGenConfig & defaultConfig()
Return reference to instance of default numeric integrator configuration object.
std::string contentsString() const
Return comma separated list of contained object names as STL string.
static Int_t _verboseEval
Definition: RooAbsPdf.h:295
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
RooAbsArg * first() const
void logEvalError(const char *message, const char *serverValueString=0) const
Log evaluation error message.
RooFitResult * save(const char *name=0, const char *title=0)
Save and return a RooFitResult snaphot of current minimizer status.
virtual Bool_t isNonPoissonWeighted() const
Definition: RooAbsData.h:98
TObject * At(Int_t index) const
Return object stored in sequential position given by index.
void setNormRangeOverride(const char *rangeName)
Definition: RooAbsPdf.cxx:3316
virtual void generateEvent(Int_t code)
Interface for generation of anan event using the algorithm corresponding to the specified code...
Definition: RooAbsPdf.cxx:2146
RooObjCacheManager _normMgr
Definition: RooAbsPdf.h:312
void setProfile(Bool_t flag=kTRUE)
Definition: RooMinuit.h:74
Bool_t ok(Bool_t verbose) const
Return true of parsing was successful.
RooArgSet * getComponents() const
Definition: RooAbsArg.cxx:679
void branchNodeServerList(RooAbsCollection *list, const RooAbsArg *arg=0, Bool_t recurseNonDerived=kFALSE) const
Fill supplied list with all branch nodes of the arg tree starting with ourself as top node...
Definition: RooAbsArg.cxx:476
static void raiseEvalError()
Raise the evaluation error flag.
Definition: RooAbsPdf.cxx:3193
RooWorkspace * _myws
Prevent &#39;AlwaysDirty&#39; mode for this node.
Definition: RooAbsArg.h:593
const Text_t * getStringAttribute(const Text_t *key) const
Get string attribute mapped under key &#39;key&#39;.
Definition: RooAbsArg.cxx:285
char * Form(const char *fmt,...)
Int_t _negCount
Definition: RooAbsPdf.h:329
RooCachedReal is an implementation of RooAbsCachedReal that can cache any external RooAbsReal input f...
Definition: RooCachedReal.h:20
Double_t getNorm(const RooArgSet &nset) const
Definition: RooAbsPdf.h:190
TString * format(const RooCmdArg &formatArg) const
Format contents of RooRealVar for pretty printing on RooPlot parameter boxes.
Definition: RooRealVar.cxx:779
Int_t _traceCount
Definition: RooAbsPdf.h:328
OperMode operMode() const
Definition: RooAbsArg.h:399
Class RooCmdConfig is a configurable parser for RooCmdArg named arguments.
Definition: RooCmdConfig.h:27
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
float xmax
Definition: THbookFile.cxx:93
void setPrintEvalErrors(Int_t numEvalErrors)
Definition: RooMinimizer.h:73
virtual void resetErrorCounters(Int_t resetValue=10)
Reset error counter to given value, limiting the number of future error messages for this pdf to &#39;res...
Definition: RooAbsPdf.cxx:569
Int_t getNPar() const
Definition: RooMinuit.h:96
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
TString fName
Definition: TNamed.h:32
virtual RooAbsGenContext * autoGenContext(const RooArgSet &vars, const RooDataSet *prototype=0, const RooArgSet *auxProto=0, Bool_t verbose=kFALSE, Bool_t autoBinned=kTRUE, const char *binnedTag="") const
Definition: RooAbsPdf.cxx:1670
Bool_t canBeExtended() const
Definition: RooAbsPdf.h:216
TIterator * serverIterator() const
Definition: RooAbsArg.h:112
class to compute the Cholesky decomposition of a matrix
Class RooGenContext implement a universal generator context for all RooAbsPdf classes that do not hav...
Definition: RooGenContext.h:30
virtual const RooAbsReal * getNormObj(const RooArgSet *set, const RooArgSet *iset, const TNamed *rangeName=0) const
Return pointer to RooAbsReal object that implements calculation of integral over observables iset in ...
Definition: RooAbsPdf.cxx:401
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
virtual Bool_t isDirectGenSafe(const RooAbsArg &arg) const
Check if given observable can be safely generated using the pdfs internal generator mechanism (if tha...
Definition: RooAbsPdf.cxx:2159
Int_t GetNrows() const
Definition: TMatrixTBase.h:122
const Bool_t kFALSE
Definition: RtypesCore.h:88
const RooNumGenConfig * getGeneratorConfig() const
Return the numeric MC generator configuration used for this object.
Definition: RooAbsPdf.cxx:3241
virtual ExtendMode extendMode() const
Definition: RooAbsPdf.h:210
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:35
virtual Bool_t isBinnedDistribution(const RooArgSet &) const
Definition: RooAbsReal.h:277
RooArgSet * getSet(const char *name, RooArgSet *set=0)
Return RooArgSet property registered with name &#39;name&#39;.
virtual Double_t sumEntries() const
void setInt(Int_t idx, Int_t value)
Definition: RooCmdArg.h:66
Bool_t defineSetInternal(const char *name, const RooArgSet &aset)
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:21
TString integralNameSuffix(const RooArgSet &iset, const RooArgSet *nset=0, const char *rangeName=0, Bool_t omitEmpty=kFALSE) const
Construct string with unique suffix name to give to integral object that encodes integrated observabl...
Definition: RooAbsReal.cxx:755
#define ClassImp(name)
Definition: Rtypes.h:359
void setEvalErrorWall(Bool_t flag)
Definition: RooMinimizer.h:50
static Int_t init()
RooAbsArg * find(const char *name) const
Find object with given name in list.
virtual Int_t numEntries() const
Return the number of bins.
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
virtual Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, Bool_t staticInitOK=kTRUE) const
Load generatedVars with the subset of directVars that we can generate events for, and return a code t...
Definition: RooAbsPdf.cxx:2124
friend class RooDataSet
Definition: RooAbsArg.h:539
RooFitResult * save(const char *name=0, const char *title=0)
Save and return a RooFitResult snaphot of current minimizer status.
Definition: RooMinuit.cxx:877
Int_t minos()
Execute MINOS.
RooArgSet * getParameters(const RooAbsData *data, Bool_t stripDisconnected=kTRUE) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don&#39;t match any of...
Definition: RooAbsArg.cxx:532
virtual RooAbsGenContext * genContext(const RooArgSet &vars, const RooDataSet *prototype=0, const RooArgSet *auxProto=0, Bool_t verbose=kFALSE) const
Interface function to create a generator context from a p.d.f.
Definition: RooAbsPdf.cxx:1661
RooArgSet _whatVars
Definition: RooAbsPdf.h:76
Double_t getDouble(const char *name, Double_t defaultValue=0)
Return Double_t property registered with name &#39;name&#39;.
static RooNumGenConfig * defaultGeneratorConfig()
Returns the default numeric MC generator configuration for all RooAbsReals.
Definition: RooAbsPdf.cxx:3203
virtual Bool_t traceEvalHook(Double_t value) const
WVE 08/21/01 Probably obsolete now.
Definition: RooAbsPdf.cxx:535
RooCmdArg Normalization(Double_t scaleFactor)
virtual void setProtoDataOrder(Int_t *lut)
Set the traversal order of prototype data to that in the lookup tables passed as argument.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
TMatrixTSym< Element > & Similarity(const TMatrixT< Element > &n)
Calculate B * (*this) * B^T , final matrix will be (nrowsb x nrowsb) This is a similarity transform w...
RooCmdArg NormRange(const char *rangeNameList)
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:627
RooArgSet * select(const RooArgSet &list) const
Construct a RooArgSet of objects in input &#39;list&#39; whose names match to those in the internal name list...
Definition: RooNameSet.cxx:187
Int_t minimize(const char *type, const char *alg=0)
virtual RooDataSet * generate(Double_t nEvents=0, Bool_t skipInit=kFALSE, Bool_t extendedMode=kFALSE)
Generate the specified number of events with nEvents>0 and and return a dataset containing the genera...
Bool_t isValueDirty() const
Definition: RooAbsArg.h:336
Double_t _value
Definition: RooAbsReal.h:389
void setRange(const char *name, Double_t min, Double_t max)
Set range named &#39;name to [min,max].
Definition: RooRealVar.cxx:448
Mother of all ROOT objects.
Definition: TObject.h:37
Int_t setPrintLevel(Int_t newLevel)
Change the MINUIT internal printing level.
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
Int_t hesse()
Execute HESSE.
Bool_t hasProcessed(const char *cmdName) const
Return true if RooCmdArg with name &#39;cmdName&#39; has been processed.
virtual RooPlot * paramOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Add a box with parameter values (and errors) to the specified frame.
Definition: RooAbsPdf.cxx:2802
RooFitResult * fit(const char *options)
Parse traditional RooAbsPdf::fitTo driver options.
Definition: RooMinuit.cxx:273
void setProfile(Bool_t flag=kTRUE)
Definition: RooMinimizer.h:75
virtual void printValue(std::ostream &os) const
Print value of p.d.f, also print normalization integral that was last used, if any.
Definition: RooAbsPdf.cxx:1618
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
virtual Double_t analyticalIntegral(Int_t code, const char *rangeName=0) const
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral. ...
Definition: RooAbsReal.cxx:361
RooFitResult * chi2FitDriver(RooAbsReal &fcn, RooLinkedList &cmdList)
Internal driver function for chi2 fits.
auto * l
Definition: textangle.C:4
RooAbsRealLValue * getPlotVar() const
Definition: RooPlot.h:132
const RooNumIntConfig * getIntegratorConfig() const
Return the numeric integration configuration used for this object.
RooMinimizer is a wrapper class around ROOT::Fit:Fitter that provides a seamless interface between th...
Definition: RooMinimizer.h:38
virtual void constOptimizeTestStatistic(ConstOpCode opcode, Bool_t doAlsoTrackingOpt=kTRUE)
Interface function signaling a request to perform constant term optimization.
Definition: RooAbsArg.cxx:1730
RooDataSet * generate(const RooArgSet &whatVars, Int_t nEvents, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none())
Generate a new dataset containing the specified variables with events sampled from our distribution...
Definition: RooAbsPdf.cxx:1725
static Bool_t evalError()
Return the evaluation error flag.
Definition: RooAbsPdf.cxx:3183
virtual void initGenerator(Int_t code)
Interface for one-time initialization to setup the generator for the specified code.
Definition: RooAbsPdf.cxx:2134
virtual TObject * Next()=0
virtual RooArgSet * getAllConstraints(const RooArgSet &observables, RooArgSet &constrainedParams, Bool_t stripDisconnected=kTRUE) const
This helper function finds and collects all constraints terms of all coponent p.d.f.s and returns a RooArgSet with all those terms.
Definition: RooAbsPdf.cxx:3146
const RooArgSet * set(const char *name)
Return pointer to previously defined named set with given nmame If no such set is found a null pointe...
void setOperMode(OperMode mode, Bool_t recurseADirty=kTRUE)
Change cache operation mode to given mode.
Definition: RooAbsArg.cxx:1745
Double_t getFitRangeNEvt() const
Definition: RooPlot.h:133
virtual RooFitResult * fitTo(RooAbsData &data, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Fit PDF to given dataset.
Definition: RooAbsPdf.cxx:1079
static constexpr double pc
RooNumGenConfig holds the configuration parameters of the various numeric integrators used by RooReal...
Bool_t defineObject(const char *name, const char *argName, Int_t setNum, const TObject *obj=0, Bool_t isArray=kFALSE)
Define TObject property name &#39;name&#39; mapped to object in slot &#39;setNum&#39; in RooCmdArg with name argName ...
RooAbsCollection * selectByName(const char *nameList, Bool_t verbose=kFALSE) const
Create a subset of the current collection, consisting only of those elements with names matching the ...
void setNoWarn()
Instruct MINUIT to suppress warnings.
Definition: RooMinuit.cxx:583
RooArgSet * _normSet
Normalization integral (owned by _normMgr)
Definition: RooAbsPdf.h:302
Bool_t _resampleProto
Definition: RooAbsPdf.h:81
Int_t setObj(const RooArgSet *nset, T *obj, const TNamed *isetRangeName=0)
RooAddition calculates the sum of a set of RooAbsReal terms, or when constructed with two sets...
Definition: RooAddition.h:26
Definition: first.py:1
virtual Int_t Poisson(Double_t mean)
Generates a random integer N according to a Poisson law.
Definition: TRandom.cxx:383
Double_t _rawValue
Definition: RooAbsPdf.h:300
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition: TAttText.h:46
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:357
#define ccoutD(a)
Definition: RooMsgService.h:37
virtual ~CacheElem()
Destructor of normalization cache element.
Definition: RooAbsPdf.cxx:2994
Int_t getNPar() const
Definition: RooMinimizer.h:99
RooFitResult * fit(const char *options)
Parse traditional RooAbsPdf::fitTo driver options.
virtual RooDataSet * generateSimGlobal(const RooArgSet &whatVars, Int_t nEvents)
Special generator interface for generation of &#39;global observables&#39; – for RooStats tools...
Definition: RooAbsPdf.cxx:2406
RooLinkedList filterCmdList(RooLinkedList &cmdInList, const char *cmdNameList, Bool_t removeFromInList=kTRUE)
Utility function to filter commands listed in cmdNameList from cmdInList.
const Bool_t kTRUE
Definition: RtypesCore.h:87
Bool_t plotSanityChecks(RooPlot *frame) const
Utility function for plotOn(), perform general sanity check on frame to ensure safe plotting operatio...
virtual Double_t extendedTerm(Double_t observedEvents, const RooArgSet *nset=0) const
Returned the extended likelihood term (Nexpect - Nobserved*log(NExpected) of this PDF for the given n...
Definition: RooAbsPdf.cxx:647
char name[80]
Definition: TGX11.cxx:109
double log(double)
Bool_t isConstant() const
Definition: RooAbsArg.h:266
virtual void SetBorderSize(Int_t bordersize=4)
Definition: TPave.h:70
virtual Int_t numEntries() const
Definition: RooAbsData.cxx:285
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
RooMinuit is a wrapper class around TFitter/TMinuit that provides a seamless interface between the MI...
Definition: RooMinuit.h:39
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:27
void optimizeConst(Int_t flag)
If flag is true, perform constant term optimization on function being minimized.
Definition: RooMinuit.cxx:845
RooBinnedGenContext is an efficient implementation of the generator context specific for binned pdfs...