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