Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooAddPdf.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 RooAddPdf
19 \ingroup Roofitcore
20
21Efficient implementation of a sum of PDFs of the form
22
23\f[
24 \sum_{i=1}^{n} c_i \cdot \mathrm{PDF}_i
25\f]
26
27or
28\f[
29 c_1\cdot\mathrm{PDF}_1 + c_2\cdot\mathrm{PDF}_2 \; + \; ... \; + \; \left( 1-\sum_{i=1}^{n-1}c_i \right) \cdot \mathrm{PDF}_n
30\f]
31
32The first form is for extended likelihood fits, where the
33expected number of events is \f$ \sum_i c_i \f$. The coefficients \f$ c_i \f$
34can either be explicitly provided, or, if all components support
35extended likelihood fits, they can be calculated from the contribution
36of each PDF to the total expected number of events.
37
38In the second form, the sum of the coefficients is required to be 1 or less,
39and the coefficient of the last PDF is calculated automatically from the condition
40that the sum of all coefficients has to be 1.
41
42### Recursive coefficients
43It is also possible to parameterise the coefficients recursively
44
45\f[
46 \sum_{i=1}^n c_i \prod_{j=1}^{i-1} \left[ (1-c_j) \right] \cdot \mathrm{PDF}_i \\
47 = c_1 \cdot \mathrm{PDF}_1 + (1-c_1)\, c_2 \cdot \mathrm{PDF}_2 + \ldots + (1-c_1)\ldots(1-c_{n-1}) \cdot 1 \cdot \mathrm{PDF}_n \\
48\f]
49
50In this form the sum of the coefficients is always less than 1.0
51for all possible values of the individual coefficients between 0 and 1.
52\note Don't pass the \f$ n^\mathrm{th} \f$ coefficient. It is always 1, since the normalisation condition removes one degree of freedom.
53
54RooAddPdf relies on each component PDF to be normalized and will perform
55no normalization other than calculating the proper last coefficient \f$ c_n \f$, if requested.
56An (enforced) condition for this assumption is that each \f$ \mathrm{PDF}_i \f$ is independent of each \f$ c_i \f$.
57
58## Difference between RooAddPdf / RooRealSumFunc / RooRealSumPdf
59- RooAddPdf is a PDF of PDFs, *i.e.* its components need to be normalised and non-negative.
60- RooRealSumPdf is a PDF of functions, *i.e.*, its components can be negative, but their sum cannot be. The normalisation
61 is computed automatically, unless the PDF is extended (see above).
62- RooRealSumFunc is a sum of functions. It is neither normalised, nor need it be positive.
63
64*/
65
66#include <RooAddPdf.h>
67
68#include <RooAddGenContext.h>
69#include <RooAddition.h>
70#include <RooBatchCompute.h>
71#include <RooDataSet.h>
72#include <RooGenericPdf.h>
73#include <RooGlobalFunc.h>
74#include <RooProdPdf.h>
75#include <RooProduct.h>
76#include <RooRatio.h>
77#include <RooRealConstant.h>
78#include <RooRealProxy.h>
79#include <RooRealSumFunc.h>
80#include <RooRealSumPdf.h>
81#include <RooRealVar.h>
83
84#include "RooAddHelpers.h"
85#include "RooFitImplHelpers.h"
86
87#include <ROOT/StringUtils.hxx>
88
89#include <algorithm>
90#include <memory>
91#include <set>
92#include <sstream>
93
94
95
96////////////////////////////////////////////////////////////////////////////////
97/// Dummy constructor
98
99RooAddPdf::RooAddPdf(const char *name, const char *title) :
100 RooAbsPdf(name,title),
101 _refCoefNorm("!refCoefNorm","Reference coefficient normalization set",this,false,false),
102 _projCacheMgr(this,10),
103 _pdfList("!pdfs","List of PDFs",this),
104 _coefList("!coefficients","List of coefficients",this),
105 _coefErrCount{_errorCount}
106{
107}
108
109
111
112 // Two pdfs with the same name are only allowed in the input list if they are
113 // actually the same object.
114 using PdfInfo = std::pair<std::string,RooAbsArg*>;
115 std::set<PdfInfo> seen;
116 for(auto const& pdf : _pdfList) {
117 PdfInfo elem{pdf->GetName(), pdf};
118 auto comp = [&](PdfInfo const& p){ return p.first == elem.first && p.second != elem.second; };
119 auto found = std::find_if(seen.begin(), seen.end(), comp);
120 if(found != seen.end()) {
121 std::stringstream errorMsg;
122 errorMsg << "RooAddPdf::RooAddPdf(" << GetName()
123 << ") pdf list contains pdfs with duplicate name \"" << pdf->GetName() << "\".";
124 coutE(InputArguments) << errorMsg.str() << std::endl;
125 throw std::invalid_argument(errorMsg.str().c_str());
126 }
127 seen.insert(elem);
128 }
129}
130
131
132////////////////////////////////////////////////////////////////////////////////
133/// Constructor with two PDFs and one coefficient
134
135RooAddPdf::RooAddPdf(const char *name, const char *title,
136 RooAbsPdf& pdf1, RooAbsPdf& pdf2, RooAbsReal& coef1) :
137 RooAddPdf(name, title)
138{
139 _pdfList.add(pdf1) ;
140 _pdfList.add(pdf2) ;
142
144}
145
146
147////////////////////////////////////////////////////////////////////////////////
148/// Generic constructor from list of PDFs and list of coefficients.
149/// Each pdf list element (i) is paired with coefficient list element (i).
150/// The number of coefficients must be either equal to the number of PDFs,
151/// in which case extended MLL fitting is enabled, or be one less.
152///
153/// All PDFs must inherit from RooAbsPdf. All coefficients must inherit from RooAbsReal
154///
155/// If the recursiveFraction flag is true, the coefficients are interpreted as recursive
156/// coefficients as explained in the class description.
157
158RooAddPdf::RooAddPdf(const char *name, const char *title, const RooArgList &inPdfList, const RooArgList &inCoefList,
160 : RooAddPdf(name, title)
161{
163
164 if (inPdfList.size()>inCoefList.size()+1 || inPdfList.size()<inCoefList.size()) {
165 std::stringstream errorMsg;
166 errorMsg << "RooAddPdf::RooAddPdf(" << GetName()
167 << ") number of pdfs and coefficients inconsistent, must have Npdf=Ncoef or Npdf=Ncoef+1.";
168 coutE(InputArguments) << errorMsg.str() << std::endl;
169 throw std::invalid_argument(errorMsg.str().c_str());
170 }
171
172 if (recursiveFractions && inPdfList.size()!=inCoefList.size()+1) {
173 std::stringstream errorMsg;
174 errorMsg << "RooAddPdf::RooAddPdf(" << GetName()
175 << "): Recursive fractions option can only be used if Npdf=Ncoef+1.";
176 coutE(InputArguments) << errorMsg.str() << std::endl;
177 throw std::invalid_argument(errorMsg.str());
178 }
179
180 // Constructor with N PDFs and N or N-1 coefs
182
183 auto addRecursiveCoef = [this,&partinCoefList](RooAbsPdf& pdf, RooAbsReal& coef) -> RooAbsReal & {
184 partinCoefList.add(coef) ;
185 if(partinCoefList.size() == 1) {
186 // The first fraction is the first plain fraction
187 return coef;
188 }
189 // The i-th recursive fraction = (1-f1)*(1-f2)*...(fi) and is calculated from the list (f1,...,fi) by RooRecursiveFraction)
190 std::stringstream rfracName;
191 rfracName << GetName() << "_recursive_fraction_" << pdf.GetName() << "_" << partinCoefList.size();
192 auto rfrac = std::make_unique<RooRecursiveFraction>(rfracName.str().c_str(),"Recursive Fraction",partinCoefList) ;
193 auto & rfracRef = *rfrac;
194 addOwnedComponents(std::move(rfrac)) ;
195 return rfracRef;
196 };
197
198 for (auto i = 0u; i < inCoefList.size(); ++i) {
199 auto coef = dynamic_cast<RooAbsReal*>(inCoefList.at(i));
200 auto pdf = dynamic_cast<RooAbsPdf*>(inPdfList.at(i));
201 if (inPdfList.at(i) == nullptr) {
202 std::stringstream errorMsg;
203 errorMsg << "RooAddPdf::RooAddPdf(" << GetName()
204 << ") number of pdfs and coefficients inconsistent, must have Npdf=Ncoef or Npdf=Ncoef+1";
205 coutE(InputArguments) << errorMsg.str() << std::endl;
206 throw std::invalid_argument(errorMsg.str());
207 }
208 if (!coef) {
209 std::stringstream errorMsg;
210 errorMsg << "RooAddPdf::RooAddPdf(" << GetName() << ") coefficient " << (coef ? coef->GetName() : "") << " is not of type RooAbsReal, ignored";
211 coutE(InputArguments) << errorMsg.str() << std::endl;
212 throw std::invalid_argument(errorMsg.str());
213 }
214 if (!pdf) {
215 std::stringstream errorMsg;
216 errorMsg << "RooAddPdf::RooAddPdf(" << GetName() << ") pdf " << (pdf ? pdf->GetName() : "") << " is not of type RooAbsPdf, ignored";
217 coutE(InputArguments) << errorMsg.str() << std::endl;
218 throw std::invalid_argument(errorMsg.str());
219 }
220 _pdfList.add(*pdf) ;
221
222 // Process recursive fraction mode separately
223 _coefList.add(recursiveFractions ? addRecursiveCoef(*pdf, *coef) : *coef);
224 }
225
226 if (inPdfList.size() == inCoefList.size() + 1) {
227 auto pdf = dynamic_cast<RooAbsPdf*>(inPdfList.at(inCoefList.size()));
228
229 if (!pdf) {
230 coutE(InputArguments) << "RooAddPdf::RooAddPdf(" << GetName() << ") last argument " << inPdfList.at(inCoefList.size())->GetName() << " is not of type RooAbsPdf." << std::endl;
231 throw std::invalid_argument("Last argument for RooAddPdf is not a PDF.");
232 }
233 _pdfList.add(*pdf) ;
234
235 // Process recursive fractions mode. Above, we verified that we don't have a last coefficient
236 if (recursiveFractions) {
238 // In recursive mode we always have Ncoef=Npdf, since we added it just above
240 }
241
242 } else {
244 }
245
247}
248
249
250////////////////////////////////////////////////////////////////////////////////
251/// Generic constructor from list of extended PDFs. There are no coefficients as the expected
252/// number of events from each components determine the relative weight of the PDFs.
253///
254/// All PDFs must inherit from RooAbsPdf.
255
256RooAddPdf::RooAddPdf(const char *name, const char *title, const RooArgList &inPdfList)
257 : RooAddPdf(name, title)
258{
259 _allExtendable = true;
260
261 // Constructor with N PDFs
262 for (const auto pdfArg : inPdfList) {
263 auto pdf = dynamic_cast<const RooAbsPdf*>(pdfArg);
264
265 if (!pdf) {
266 std::stringstream errorMsg;
267 errorMsg << "RooAddPdf::RooAddPdf(" << GetName() << ") pdf " << (pdf ? pdf->GetName() : "")
268 << " is not of type RooAbsPdf, RooAddPdf constructor call is invalid!";
269 coutE(InputArguments) << errorMsg.str() << std::endl;
270 throw std::invalid_argument(errorMsg.str().c_str());
271 }
272 if (!pdf->canBeExtended()) {
273 std::stringstream errorMsg;
274 errorMsg << "RooAddPdf::RooAddPdf(" << GetName() << ") pdf " << pdf->GetName()
275 << " is not extendable, RooAddPdf constructor call is invalid!";
276 coutE(InputArguments) << errorMsg.str() << std::endl;
277 throw std::invalid_argument(errorMsg.str().c_str());
278 }
279 _pdfList.add(*pdf) ;
280 }
281
283}
284
285
286////////////////////////////////////////////////////////////////////////////////
287/// Copy constructor
288
290 : RooAbsPdf(other, name),
291 _refCoefNorm("!refCoefNorm", this, other._refCoefNorm),
292 _refCoefRangeName((TNamed *)other._refCoefRangeName),
293 _projCacheMgr(other._projCacheMgr, this),
294 _codeReg(other._codeReg),
295 _pdfList("!pdfs", this, other._pdfList),
296 _coefList("!coefficients", this, other._coefList),
297 _haveLastCoef(other._haveLastCoef),
298 _allExtendable(other._allExtendable),
299 _recursive(other._recursive),
300 _coefErrCount(_errorCount)
301{
302
304}
305
306
307////////////////////////////////////////////////////////////////////////////////
308/// By default the interpretation of the fraction coefficients is
309/// performed in the contextual choice of observables. This makes the
310/// shape of the p.d.f explicitly dependent on the choice of
311/// observables. This method instructs RooAddPdf to freeze the
312/// interpretation of the coefficients to be done in the given set of
313/// observables. If frozen, fractions are automatically transformed
314/// from the reference normalization set to the contextual normalization
315/// set by ratios of integrals.
316
318{
319 if (refCoefNorm.empty()) {
320 return ;
321 }
322
323 // Also set an attribute with this information, which is the easiest way to
324 // preserve this in the JSON IO.
326
329
331}
332
338
339// For the JSON IO, we are not storing the _refCoefNorm directly. Instead, it
340// is stored by names in a string attribute. This function should be called
341// internally before _refCoefNorm is used to materialize it from the attribute
342// if necessary.
344{
345 // _refCoefNorm was already materialized
346 if (!_refCoefNorm.empty())
347 return;
348
349 std::vector<std::string> names;
350 if (auto attrib = getStringAttribute("ref_coef_norm")) {
351 names = ROOT::Split(attrib, ",", /*skipEmpty=*/true);
352 } else {
353 return;
354 }
355
357
360 for (std::string const &name : names) {
361 if (RooAbsArg *arg = serverSet.find(name.c_str())) {
362 refCoefNorm.add(*arg);
363 } else {
364 throw std::runtime_error("Internal logic error in RooAddPdf::materializeRefCoefNormFromAttribute()");
365 }
366 }
367
368 const_cast<RooAddPdf *>(this)->fixCoefNormalization(refCoefNorm);
369}
370
371
372////////////////////////////////////////////////////////////////////////////////
373/// By default, fraction coefficients are assumed to refer to the default
374/// fit range. This makes the shape of a RooAddPdf
375/// explicitly dependent on the range of the observables. Calling this function
376/// allows for a range-independent definition of the fractions, because it
377/// ties all coefficients to the given
378/// named range. If the normalisation range is different
379/// from this reference range, the appropriate fraction coefficients
380/// are automatically calculated from the reference fractions by
381/// integrating over the ranges, and comparing these integrals.
382
384{
385 auto* newNamePtr = const_cast<TNamed*>(RooNameReg::ptr(rangeName));
388 }
390}
391
392
393
394////////////////////////////////////////////////////////////////////////////////
395/// Retrieve cache element for the computation of the PDF normalisation.
396/// \param[in] nset Current normalisation set (integration over these variables yields 1).
397/// \param[in] iset Integration set. Variables to be integrated over (if integrations are performed).
398///
399/// If a cache element does not exist, create and fill it on the fly. The cache also contains
400/// - Supplemental normalization terms (in case not all added p.d.f.s have the same observables)
401/// - Projection integrals to calculate transformed fraction coefficients when a frozen reference frame is provided
402/// - Projection integrals for similar transformations when a frozen reference range is provided.
403
404AddCacheElem* RooAddPdf::getProjCache(const RooArgSet* nset, const RooArgSet* iset) const
405{
406 // Check if cache already exists
407 auto cache = static_cast<AddCacheElem*>(_projCacheMgr.getObj(nset,iset,nullptr,normRange()));
408 if (cache) {
409 return cache ;
410 }
411
412 // Make sure _refCoefNorm is defined
414
415 //Create new cache
416 cache = new AddCacheElem{*this, _pdfList, _coefList, nset, iset, _refCoefNorm,
419
421
422 return cache;
423}
424
425
426////////////////////////////////////////////////////////////////////////////////
427/// Update the coefficient values in the given cache element: calculate new remainder
428/// fraction, normalize fractions obtained from extended ML terms to unity, and
429/// multiply the various range and dimensional corrections needed in the
430/// current use context.
431///
432/// param[in] cache The cache element for the given normalization set that
433/// stores the supplementary normalization values and
434/// projection-related objects.
435/// param[in] nset The set of variables to normalize over.
436/// param[in] syncCoefValues If the initial values of the coefficients still
437/// need to be copied from the `_coefList` elements to
438/// the `_coefCache`. True by default.
439
440void RooAddPdf::updateCoefficients(AddCacheElem &cache, const RooArgSet *nset, bool syncCoefValues) const
441{
442 _coefCache.resize(_pdfList.size());
443 if (syncCoefValues) {
444 for (std::size_t i = 0; i < _coefList.size(); ++i) {
445 _coefCache[i] = static_cast<RooAbsReal const &>(_coefList[i]).getVal(nset);
446 }
447 }
448 if (_allExtendable) {
449 for (std::size_t i = 0; i < _pdfList.size(); ++i) {
450 auto &pdf = static_cast<RooAbsPdf &>(_pdfList[i]);
451 _coefCache[i] = pdf.expectedEvents(!_refCoefNorm.empty() ? &_refCoefNorm : nset);
452 }
453 }
454
455 RooAddHelpers::updateCoefficients(*this, _pdfList.size(), _coefCache, _haveLastCoef || _allExtendable, cache,
457}
458
459////////////////////////////////////////////////////////////////////////////////
460/// Look up projection cache and per-PDF norm sets. If a PDF doesn't have a special
461/// norm set, use the `defaultNorm`. If `defaultNorm == nullptr`, use the member
462/// _normSet.
463std::pair<const RooArgSet*, AddCacheElem*> RooAddPdf::getNormAndCache(const RooArgSet* nset) const {
464
465 // Treat empty normalization set and nullptr the same way.
466 if(nset && nset->empty()) nset = nullptr;
467
468 if (nset == nullptr) {
469 // Make sure _refCoefNorm is defined
471
472 if (!_refCoefNorm.empty()) {
473 nset = &_refCoefNorm ;
474 }
475 }
476
477 // A RooAddPdf needs to have a normalization set defined, otherwise its
478 // coefficient will not be uniquely defined. Its shape depends on the
479 // normalization provided. Un-normalized calls to RooAddPdf can happen in
480 // Roofit, when printing the pdf's or when computing integrals. In these case,
481 // if the pdf has a normalization set previously defined (i.e. stored as a
482 // datamember in _copyOfLastNormSet) it should use it by default when the pdf
483 // is evaluated without passing a normalizations set (in pdf->getVal(nullptr) )
484 // In the case of no pre-defined normalization set exists, a warning will be
485 // produced, since the obtained value will be arbitrary. Note that to avoid
486 // unnecessary warning messages, when calling RooAbsPdf::printValue or
487 // RooAbsPdf::graphVizTree, the printing of the warning messages for the
488 // RooFit::Eval topic is explicitly disabled.
489 {
490 // If nset is still nullptr, get the pointer to a copy of the last-used
491 // normalization set. It nset is not nullptr, check whether the copy of
492 // the last-used normalization set needs an update.
493 if(nset == nullptr) {
494 nset = _copyOfLastNormSet.get();
496 _copyOfLastNormSet = std::make_unique<const RooArgSet>(*nset);
498 }
499
500 // If nset is STILL nullptr, print a warning.
501 if (nset == nullptr) {
502 coutW(Eval) << "Evaluating RooAddPdf " << GetName() << " without a defined normalization set. This can lead to ambiguous "
503 "coefficients definition and incorrect results."
504 << " Use RooAddPdf::fixCoefNormalization(nset) to provide a normalization set for "
505 "defining uniquely RooAddPdf coefficients!"
506 << std::endl;
507 }
508 }
509
510
511 AddCacheElem* cache = getProjCache(nset) ;
512
513 return {nset, cache};
514}
515
516
517////////////////////////////////////////////////////////////////////////////////
518/// Calculate and return the current value
519
521{
523 const RooArgSet* nset = normAndCache.first;
524 AddCacheElem* cache = normAndCache.second;
525 updateCoefficients(*cache, nset);
526
527 // Process change in last data set used
528 bool nsetChanged(false) ;
529 if (!isActiveNormSet(nset) || _norm==nullptr) {
531 }
532
533 // Do running sum of coef/pdf pairs, calculate lastCoef.
534 if (isValueDirty() || nsetChanged) {
535 _value = 0.0;
536
537 for (unsigned int i=0; i < _pdfList.size(); ++i) {
538 auto& pdf = static_cast<RooAbsPdf&>(_pdfList[i]);
539 double snormVal = 1.;
540 snormVal = cache->suppNormVal(i);
541
542 double pdfVal = pdf.getVal(nset);
543 if (pdf.isSelectedComp()) {
545 }
546 }
548 }
549
550 return _value;
551}
552
553////////////////////////////////////////////////////////////////////////////////
554/// Compute addition of PDFs in batches.
556{
557 std::span<double> output = ctx.output();
558
559 RooBatchCompute::Config config = ctx.config(this);
560
561 _coefCache.resize(_pdfList.size());
562 for(std::size_t i = 0; i < _coefList.size(); ++i) {
563 auto coefVals = ctx.at(&_coefList[i]);
564 // We don't support per-event coefficients in this function. If the CPU
565 // mode is used, we can just fall back to the RooAbsReal implementation.
566 // With CUDA, we can't do that because the inputs might be on the device.
567 // That's why we throw an exception then.
568 if(coefVals.size() > 1) {
569 if (config.useCuda()) {
570 throw std::runtime_error("The RooAddPdf doesn't support per-event coefficients in CUDA mode yet!");
571 }
573 return;
574 }
575 _coefCache[i] = coefVals[0];
576 }
577
578 std::vector<std::span<const double>> pdfs;
579 std::vector<double> coefs;
580 AddCacheElem* cache = getProjCache(nullptr);
581 RooAddHelpers::updateCoefficients(*this, _pdfList.size(), _coefCache, _haveLastCoef || _allExtendable, *cache,
583
584 for (unsigned int pdfNo = 0; pdfNo < _pdfList.size(); ++pdfNo)
585 {
586 auto pdf = static_cast<RooAbsPdf*>(&_pdfList[pdfNo]);
587 if (pdf->isSelectedComp())
588 {
589 pdfs.push_back(ctx.at(pdf));
590 coefs.push_back(_coefCache[pdfNo] / cache->suppNormVal(pdfNo) );
591 }
592 }
594}
595
596
597////////////////////////////////////////////////////////////////////////////////
598/// Reset error counter to given value, limiting the number
599/// of future error messages for this pdf to 'resetValue'
600
606
607
608
609////////////////////////////////////////////////////////////////////////////////
610/// Check if PDF is valid for given normalization set.
611/// Coefficient and PDF must be non-overlapping, but pdf-coefficient
612/// pairs may overlap each other
613
615{
617}
618
619
620////////////////////////////////////////////////////////////////////////////////
621/// Determine which part (if any) of given integral can be performed analytically.
622/// If any analytical integration is possible, return integration scenario code
623///
624/// RooAddPdf queries each component PDF for its analytical integration capability of the requested
625/// set ('allVars'). It finds the largest common set of variables that can be integrated
626/// by all components. If such a set exists, it reconfirms that each component is capable of
627/// analytically integrating the common set, and combines the components individual integration
628/// codes into a single integration code valid for RooAddPdf.
629
631 const RooArgSet* normSet, const char* rangeName) const
632{
633 // Make sure _refCoefNorm is defined
635
636 RooArgSet allAnalVars(*std::unique_ptr<RooArgSet>{getObservables(allVars)}) ;
637
638 Int_t n(0) ;
639
640 // First iteration, determine what each component can integrate analytically
641 for (const auto pdfArg : _pdfList) {
642 auto pdf = static_cast<const RooAbsPdf *>(pdfArg);
644 pdf->getAnalyticalIntegralWN(allVars,subAnalVars,normSet,rangeName) ;
645
646 // Observables that cannot be integrated analytically by this component are dropped from the common list
647 for (const auto arg : allVars) {
648 if (!subAnalVars.find(arg->GetName()) && pdf->dependsOn(*arg)) {
649 allAnalVars.remove(*arg,true,true) ;
650 }
651 }
652 n++ ;
653 }
654
655 // If no observables can be integrated analytically, return code 0 here
656 if (allAnalVars.empty()) {
657 return 0 ;
658 }
659
660
661 // Now retrieve codes for integration over common set of analytically integrable observables for each component
662 n=0 ;
663 std::vector<Int_t> subCode(_pdfList.size());
664 bool allOK(true) ;
665 for (const auto arg : _pdfList) {
666 auto pdf = static_cast<const RooAbsPdf *>(arg);
668 auto allAnalVars2 = std::unique_ptr<RooArgSet>{pdf->getObservables(allAnalVars)} ;
669 subCode[n] = pdf->getAnalyticalIntegralWN(*allAnalVars2,subAnalVars,normSet,rangeName) ;
670 if (subCode[n]==0 && !allAnalVars2->empty()) {
671 coutE(InputArguments) << "RooAddPdf::getAnalyticalIntegral(" << GetName() << ") WARNING: component PDF " << pdf->GetName()
672 << " advertises inconsistent set of integrals (e.g. (X,Y) but not X or Y individually."
673 << " Distributed analytical integration disabled. Please fix PDF" << std::endl ;
674 allOK = false ;
675 }
676 n++ ;
677 }
678 if (!allOK) {
679 return 0 ;
680 }
681
682 // Mare all analytically integrated observables as such
683 analVars.add(allAnalVars) ;
684
685 // Store set of variables analytically integrated
688
689 return masterCode ;
690}
691
692
693
694////////////////////////////////////////////////////////////////////////////////
695/// Return analytical integral defined by given scenario code
696
697double RooAddPdf::analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName) const
698{
699 // WVE needs adaptation to handle new rangeName feature
700 if (code==0) {
701 return getVal(normSet) ;
702 }
703
704 // Retrieve analytical integration subCodes and set of observabels integrated over
705 RooArgSet* intSet = nullptr;
706 const std::vector<Int_t>& subCode = _codeReg.retrieve(code-1,intSet) ;
707 if (subCode.empty()) {
708 std::stringstream errorMsg;
709 errorMsg << "RooAddPdf::analyticalIntegral(" << GetName() << "): ERROR unrecognized integration code, " << code;
710 coutE(InputArguments) << errorMsg.str() << std::endl;
711 throw std::invalid_argument(errorMsg.str().c_str());
712 }
713
714 cxcoutD(Caching) << "RooAddPdf::aiWN(" << GetName() << ") calling getProjCache with nset = " << (normSet?*normSet:RooArgSet()) << std::endl ;
715
716 if ((normSet==nullptr || normSet->empty()) && !_refCoefNorm.empty()) {
717// std::cout << "WVE integration of RooAddPdf without normalization, but have reference set, using ref set for normalization" << std::endl ;
719 }
720
723
724 // Calculate the current value of this object
725 double value(0) ;
726
727 // Do running sum of coef/pdf pairs, calculate lastCoef.
728 double snormVal ;
729
730 //cout << "ROP::aIWN updateCoefCache with rangeName = " << (rangeName?rangeName:"<null>") << std::endl ;
731 for (std::size_t i = 0; i < _pdfList.size(); ++i ) {
732 auto pdf = static_cast<const RooAbsPdf*>(_pdfList.at(i));
733
734 if (_coefCache[i]) {
735 snormVal = cache->suppNormVal(i);
736
737 // WVE swap this?
738 double val = pdf->analyticalIntegralWN(subCode[i],normSet,rangeName) ;
739 if (pdf->isSelectedComp()) {
740 value += val*_coefCache[i]/snormVal ;
741 }
742 }
743 }
744
745 return value ;
746}
747
748
749
750////////////////////////////////////////////////////////////////////////////////
751/// Return the number of expected events, which is either the sum of all coefficients
752/// or the sum of the components extended terms, multiplied with the fraction that
753/// is in the current range w.r.t the reference range
754
755double RooAddPdf::expectedEvents(const RooArgSet* nset) const
756{
757 double expectedTotal{0.0};
758
759 cxcoutD(Caching) << "RooAddPdf::expectedEvents(" << GetName() << ") calling getProjCache with nset = " << (nset?*nset:RooArgSet()) << std::endl ;
760 AddCacheElem& cache = *getProjCache(nset) ;
761 updateCoefficients(cache, nset);
762
763 if (cache.doProjection()) {
764
765 for (std::size_t i = 0; i < _pdfList.size(); ++i) {
766 double ncomp = _allExtendable ? static_cast<RooAbsPdf&>(_pdfList[i]).expectedEvents(nset)
767 : static_cast<RooAbsReal&>(_coefList[i]).getVal(nset);
768 expectedTotal += cache.rangeProjScaleFactor(i) * ncomp ;
769
770 }
771
772 } else {
773
774 if (_allExtendable) {
775 for(auto *arg : static_range_cast<RooAbsPdf*>(_pdfList)) {
776 expectedTotal += arg->expectedEvents(nset) ;
777 }
778 } else {
779 for(auto *arg : static_range_cast<RooAbsReal*>(_coefList)) {
780 expectedTotal += arg->getVal(nset) ;
781 }
782 }
783
784 }
785 return expectedTotal ;
786}
787
788
789std::unique_ptr<RooAbsReal> RooAddPdf::createExpectedEventsFunc(const RooArgSet *nset) const
790{
791 std::unique_ptr<RooAbsReal> out;
792
793 auto name = std::string(GetName()) + "_expectedEvents";
794 if (_allExtendable) {
796 for (auto *pdf : static_range_cast<RooAbsPdf *>(_pdfList)) {
797 sumSet.addOwned(pdf->createExpectedEventsFunc(nset));
798 }
799 out = std::make_unique<RooAddition>(name.c_str(), name.c_str(), sumSet);
800 out->addOwnedComponents(std::move(sumSet));
801 } else {
802 out = std::make_unique<RooAddition>(name.c_str(), name.c_str(), _coefList);
803 }
804
806
807 // Make sure _refCoefNorm is defined
809
810 if (!_allExtendable) {
811 // If the _refCoefNorm is empty or it's equal to normSet anyway, this is not
812 // a conditional pdf and we don't need to do any transformation. See also
813 // RooAddPdf::compileForNormSet() for more explanations on a similar logic.
814 if (!_refCoefNorm.empty() && !nset->equals(_refCoefNorm)) {
815 prodList.addOwned(std::unique_ptr<RooAbsReal>{createIntegral(*nset, _refCoefNorm)});
816 }
817
818 // Optionally multiply with fractional normalization. I this case, we
819 // replace the original factor stored in "out".
820 if (!_normRange.IsNull()) {
821 std::unique_ptr<RooAbsReal> owner;
822 RooArgList terms;
823 // The integrals own each other in a chain. We do this because it's
824 // not possible to add two objects with the same name via
825 // addOwnedComponents(), and it happens in some user models that some
826 // component pdfs are the same. Hence, the integrals might share names
827 // too and we can't add them all in one go as owned objects of the
828 // final integral sum.
829 for (auto *pdf : static_range_cast<RooAbsPdf *>(_pdfList)) {
830 auto integrl = std::unique_ptr<RooAbsReal>{pdf->createIntegral(*nset, *nset)};
831 auto formulaName = std::string(pdf->GetName()) + "_formulaVar";
832 auto next = std::make_unique<RooFormulaVar>(formulaName.c_str(), "1./x[0]", RooArgList{*integrl});
833 next->addOwnedComponents(std::move(integrl));
834 terms.add(*next);
835 if (owner)
836 next->addOwnedComponents(std::move(owner));
837 owner = std::move(next);
838 }
839 auto fracIntegName = std::string(GetName()) + "_integSum";
840 auto fracInteg =
841 std::make_unique<RooRealSumFunc>(fracIntegName.c_str(), fracIntegName.c_str(), _coefList, terms);
842 fracInteg->addOwnedComponents(std::move(owner));
843
844 out = std::move(fracInteg);
845 }
846 }
847
848 std::string finalName = std::string(out->GetName()) + "_finalized";
849 if (prodList.empty()) {
850 // If there are no additional factors, just return the single factor we have
851 return out;
852 } else {
853 prodList.addOwned(std::move(out));
854 }
855 auto finalOut = std::make_unique<RooProduct>(finalName.c_str(), finalName.c_str(), prodList);
856 finalOut->addOwnedComponents(std::move(prodList));
857 return finalOut;
858}
859
860
861////////////////////////////////////////////////////////////////////////////////
862/// Interface function used by test statistics to freeze choice of observables
863/// for interpretation of fraction coefficients
864
866{
867 // Make sure _refCoefNorm is defined
869
870 if (!force && !_refCoefNorm.empty()) {
871 return ;
872 }
873
874 if (!depSet) {
876 return ;
877 }
878
879 fixCoefNormalization(*std::unique_ptr<RooArgSet>{getObservables(depSet)}) ;
880}
881
882
883
884////////////////////////////////////////////////////////////////////////////////
885/// Interface function used by test statistics to freeze choice of range
886/// for interpretation of fraction coefficients
887
889{
890 if (!force && _refCoefRangeName) {
891 return ;
892 }
893
895}
896
897
898
899////////////////////////////////////////////////////////////////////////////////
900/// Return specialized context to efficiently generate toy events from RooAddPdfs
901/// return RooAbsPdf::genContext(vars,prototype,auxProto,verbose) ; // WVE DEBUG
902
904 const RooArgSet* auxProto, bool verbose) const
905{
906 return RooAddGenContext::create(*this,vars,prototype,auxProto,verbose).release();
907}
908
909
910
911////////////////////////////////////////////////////////////////////////////////
912/// Loop over components for plot sampling hints and merge them if there are multiple
913
914std::list<double>* RooAddPdf::plotSamplingHint(RooAbsRealLValue& obs, double xlo, double xhi) const
915{
916 return RooRealSumPdf::plotSamplingHint(_pdfList, obs, xlo, xhi);
917}
918
919
920////////////////////////////////////////////////////////////////////////////////
921/// Loop over components for plot sampling hints and merge them if there are multiple
922
923std::list<double>* RooAddPdf::binBoundaries(RooAbsRealLValue& obs, double xlo, double xhi) const
924{
925 return RooRealSumPdf::binBoundaries(_pdfList, obs, xlo, xhi);
926}
927
928
929////////////////////////////////////////////////////////////////////////////////
930/// If all components that depend on obs are binned, so is their sum.
935
936
937////////////////////////////////////////////////////////////////////////////////
938/// Label OK'ed components of a RooAddPdf with cache-and-track
939
944
945
946
947////////////////////////////////////////////////////////////////////////////////
948/// Customized printing of arguments of a RooAddPdf to more intuitively reflect the contents of the
949/// product operator construction
950
951void RooAddPdf::printMetaArgs(std::ostream& os) const
952{
954}
955
956
958 bool nameChange, bool isRecursiveStep)
959{
960 // If a server is redirected, the cached normalization set might not point
961 // to the right observables anymore. We need to reset it.
962 _copyOfLastNormSet.reset();
964}
965
966
967std::unique_ptr<RooAbsArg>
969{
970 // Make sure _refCoefNorm is defined
972
973 // Instead of cloning this RooAddPdf directly, we have to massage it a bit.
974 // In the case of extended pdfs, the coefficients should be set to functions
975 // representing the expected number of events, so we don't have to fall back
976 // to legacy code paths that don't support evaluation with the
977 // RooFit::EvalContext, like RooAbsPdf::expectedEvents().
979 if (_allExtendable) {
980 for (auto *pdf : static_range_cast<RooAbsPdf *>(_pdfList)) {
981 coefListNew.addOwned(pdf->createExpectedEventsFunc(!_refCoefNorm.empty() ? &_refCoefNorm : &normSet));
982 }
983 } else {
984 coefListNew.add(coefList());
985 }
986 auto newArg = std::make_unique<RooAddPdf>(GetName(), GetTitle(), pdfList(), coefListNew);
987 // Copy some other info that the RooAddPdf copy constructor would otherwise take care of.
988 newArg->setNormRange(normRange());
989 newArg->_codeReg = _codeReg;
990 if (!_refCoefNorm.empty()) {
991 newArg->fixCoefNormalization(_refCoefNorm);
992 }
993 if (_refCoefRangeName) {
994 newArg->fixCoefRange(getCoefRange());
995 }
996
998
999 // If we set the normalization ranges of the component pdfs to the
1000 // normalization range of the RooAddPdf, the RooAddPdf doesn't need to
1001 // compute as many correction factor integrals internally.
1002 // Remember the previous normalizations ranges to reset later.
1003 class ResetNormRangesRAII {
1004 public:
1005 ResetNormRangesRAII(RooAbsCollection const &pdfs, std::string const &normRange)
1006 {
1007 _componentPdfs.reserve(pdfs.size());
1008 _oldNormRanges.reserve(pdfs.size());
1009
1010 bool isMultiRange = normRange.find(',') != std::string::npos;
1011
1013
1014 // The RooProdPdf is not able to deal with a multi-range _normRange
1015 // for now, so skip the changing the range in this case.
1016 bool changeRange = !(isMultiRange && dynamic_cast<RooProdPdf *>(componentPdf));
1017
1018 const char *old = componentPdf->normRange();
1019 const char *newVal = changeRange ? normRange.c_str() : old;
1020 componentPdf->setNormRange(newVal);
1021 _componentPdfs.emplace_back(componentPdf);
1022 _oldNormRanges.emplace_back(old ? old : "");
1023 }
1024 }
1026 {
1027 for (std::size_t i = 0; i < _componentPdfs.size(); ++i) {
1028 _componentPdfs[i]->setNormRange(_oldNormRanges[i].c_str());
1029 }
1030 }
1031
1032 private:
1033 std::vector<RooAbsPdf *> _componentPdfs;
1034 std::vector<std::string> _oldNormRanges;
1036
1037 // In case conditional observables, e.g. p(x|y), the _refCoefNorm is set to
1038 // all observables (x, y) and the normSet doesn't contain the conditional
1039 // observables (so it only contains x in this example).
1040
1041 // If the _refCoefNorm is empty or it's equal to normSet anyway, this is not
1042 // a conditional pdf and we don't need to do any transformation.
1043 if (_refCoefNorm.empty() || normSet.equals(_refCoefNorm)) {
1045 return newArg;
1046 }
1047
1048 // In the conditional case, things become more complicated. The original
1049 // getValV() method is covering this case with very complicated logic,
1050 // caching multiple new RooFit objects to scale the individual coefficients
1051 // of the RooAddPdf.
1052 //
1053 // However, it's not complicated what we need to do mathematically:
1054 //
1055 // Since:
1056 // 1. p(x, y) = p(x | y) * p(y)
1057 // 2. p(y) = Integral of p(x, y) over x
1058 //
1059 // We conclude:
1060 // p(x, y)
1061 // p(x | y) = --------------------------
1062 // Integral of p(x, y) over x
1063 //
1064 // What follows is the implementation of this formula in RooFit. By doing
1065 // this here in compileForNormSet(), we don't invoke the old RooAddPdf
1066 // projection caches (note that no conditional pdfs are on the right hand
1067 // side of the equation).
1068 std::string finalName = std::string(GetName()) + "_conditional";
1069 std::unique_ptr<RooAbsReal> denom{newArg->createIntegral(normSet, _refCoefNorm)};
1070 auto finalArg = std::make_unique<RooGenericPdf>(finalName.c_str(), "@0/@1", RooArgList{*newArg, *denom});
1072 ctx.markAsCompiled(*denom);
1075 finalArg->addOwnedComponents(std::move(newArg));
1076 finalArg->addOwnedComponents(std::move(denom));
1077 return finalArg;
1078}
#define cxcoutD(a)
#define coutW(a)
#define coutE(a)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition TGX11.cxx:148
const_iterator begin() const
const_iterator end() const
const std::vector< Int_t > & retrieve(Int_t masterCode) const
Retrieve the array of integer codes associated with the given master code.
Int_t store(const std::vector< Int_t > &codeList, RooArgSet *set1=nullptr, RooArgSet *set2=nullptr, RooArgSet *set3=nullptr, RooArgSet *set4=nullptr)
Store given arrays of integer codes, and up to four RooArgSets in the registry (each setX pointer may...
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:76
void clearValueAndShapeDirty() const
Definition RooAbsArg.h:536
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
RooFit::OwningPtr< RooArgSet > getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
const Text_t * getStringAttribute(const Text_t *key) const
Get string attribute mapped under key 'key'.
bool isValueDirty() const
Definition RooAbsArg.h:356
Abstract container object that can hold multiple RooAbsArg objects.
bool equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically-named contents.
RooFit::UniqueId< RooAbsCollection > const & uniqueId() const
Returns a unique ID that is different for every instantiated RooAbsCollection.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
Abstract base class for generator contexts of RooAbsPdf objects.
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:32
virtual bool syncNormalization(const RooArgSet *dset, bool adjustProxies=true) const
Verify that the normalization integral cached with this PDF is valid for given set of normalization o...
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...
bool isActiveNormSet(RooArgSet const *normSet) const
Checks if normSet is the currently active normalization set of this PDF, meaning is exactly the same ...
Definition RooAbsPdf.h:295
TString _normRange
Normalization range.
Definition RooAbsPdf.h:336
RooAbsReal * _norm
! Normalization integral (owned by _normMgr)
Definition RooAbsPdf.h:313
const char * normRange() const
Definition RooAbsPdf.h:246
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursiveStep) override
Hook function intercepting redirectServer calls.
static Int_t _verboseEval
Definition RooAbsPdf.h:308
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:107
friend class AddCacheElem
Definition RooAbsReal.h:407
double _value
Cache for current value of object.
Definition RooAbsReal.h:542
RooFit::OwningPtr< RooAbsReal > createIntegral(const RooArgSet &iset, const RooCmdArg &arg1, const RooCmdArg &arg2={}, const RooCmdArg &arg3={}, const RooCmdArg &arg4={}, const RooCmdArg &arg5={}, const RooCmdArg &arg6={}, const RooCmdArg &arg7={}, const RooCmdArg &arg8={}) const
Create an object that represents the integral of the function over one or more observables listed in ...
virtual void doEval(RooFit::EvalContext &) const
Base function for computing multiple values of a RooAbsReal.
static std::unique_ptr< RooAbsGenContext > create(const Pdf_t &pdf, const RooArgSet &vars, const RooDataSet *prototype, const RooArgSet *auxProto, bool verbose)
Returns a RooAddGenContext if possible, or, if the RooAddGenContext doesn't support this particular R...
Efficient implementation of a sum of PDFs of the form.
Definition RooAddPdf.h:32
RooListProxy _coefList
List of coefficients.
Definition RooAddPdf.h:129
bool _allExtendable
Flag indicating if all PDF components are extendable.
Definition RooAddPdf.h:133
void doEval(RooFit::EvalContext &) const override
Compute addition of PDFs in batches.
RooAICRegistry _codeReg
! Registry of component analytical integration codes
Definition RooAddPdf.h:126
RooFit::UniqueId< RooArgSet >::Value_t _idOfLastUsedNormSet
!
Definition RooAddPdf.h:142
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Return analytical integral defined by given scenario code.
const char * getCoefRange() const
Definition RooAddPdf.h:82
std::unique_ptr< const RooArgSet > _copyOfLastNormSet
!
Definition RooAddPdf.h:143
void updateCoefficients(AddCacheElem &cache, const RooArgSet *nset, bool syncCoefValues=true) const
Update the coefficient values in the given cache element: calculate new remainder fraction,...
Int_t _coefErrCount
! Coefficient error counter
Definition RooAddPdf.h:136
bool _haveLastCoef
Flag indicating if last PDFs coefficient was supplied in the constructor.
Definition RooAddPdf.h:132
void selectNormalization(const RooArgSet *depSet=nullptr, bool force=false) override
Interface function used by test statistics to freeze choice of observables for interpretation of frac...
void printMetaArgs(std::ostream &os) const override
Customized printing of arguments of a RooAddPdf to more intuitively reflect the contents of the produ...
void finalizeConstruction()
void setCacheAndTrackHints(RooArgSet &) override
Label OK'ed components of a RooAddPdf with cache-and-track.
const RooArgList & coefList() const
Definition RooAddPdf.h:73
bool _recursive
Flag indicating is fractions are treated recursively.
Definition RooAddPdf.h:134
RooObjCacheManager _projCacheMgr
! Manager of cache with coefficient projections and transformations
Definition RooAddPdf.h:107
void materializeRefCoefNormFromAttribute() const
RooAbsGenContext * genContext(const RooArgSet &vars, const RooDataSet *prototype=nullptr, const RooArgSet *auxProto=nullptr, bool verbose=false) const override
Return specialized context to efficiently generate toy events from RooAddPdfs return RooAbsPdf::genCo...
bool checkObservables(const RooArgSet *nset) const override
Check if PDF is valid for given normalization set.
void fixCoefNormalization(const RooArgSet &refCoefNorm)
By default the interpretation of the fraction coefficients is performed in the contextual choice of o...
std::pair< const RooArgSet *, AddCacheElem * > getNormAndCache(const RooArgSet *nset) const
Look up projection cache and per-PDF norm sets.
RooSetProxy _refCoefNorm
Reference observable set for coefficient interpretation.
Definition RooAddPdf.h:101
void selectNormalizationRange(const char *rangeName=nullptr, bool force=false) override
Interface function used by test statistics to freeze choice of range for interpretation of fraction c...
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &numVars, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Determine which part (if any) of given integral can be performed analytically.
void resetErrorCounters(Int_t resetValue=10) override
Reset error counter to given value, limiting the number of future error messages for this pdf to 'res...
double expectedEvents(const RooArgSet *nset) const override
Return expected number of events for extended likelihood calculation, which is the sum of all coeffic...
double getValV(const RooArgSet *set=nullptr) const override
Calculate and return the current value.
std::unique_ptr< RooAbsArg > compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const override
void fixCoefRange(const char *rangeName)
By default, fraction coefficients are assumed to refer to the default fit range.
AddCacheElem * getProjCache(const RooArgSet *nset, const RooArgSet *iset=nullptr) const
Retrieve cache element for the computation of the PDF normalisation.
std::list< double > * plotSamplingHint(RooAbsRealLValue &obs, double xlo, double xhi) const override
Loop over components for plot sampling hints and merge them if there are multiple.
RooListProxy _pdfList
List of component PDFs.
Definition RooAddPdf.h:128
TNamed * _refCoefRangeName
Reference range name for coefficient interpretation.
Definition RooAddPdf.h:102
const RooArgList & pdfList() const
Definition RooAddPdf.h:69
std::unique_ptr< RooAbsReal > createExpectedEventsFunc(const RooArgSet *nset) const override
Returns an object that represents the expected number of events for a given normalization set,...
bool isBinnedDistribution(const RooArgSet &obs) const override
If all components that depend on obs are binned, so is their sum.
bool redirectServersHook(const RooAbsCollection &, bool, bool, bool) override
Hook function intercepting redirectServer calls.
std::vector< double > _coefCache
! Transient cache with transformed values of coefficients
Definition RooAddPdf.h:104
const RooArgSet & getCoefNormalization() const
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
Loop over components for plot sampling hints and merge them if there are multiple.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
Definition RooArgList.h:110
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Minimal configuration struct to steer the evaluation of a single node with the RooBatchCompute librar...
Int_t setObj(const RooArgSet *nset, T *obj, const TNamed *isetRangeName=nullptr)
Setter function without integration set.
void reset()
Clear the cache.
T * getObj(const RooArgSet *nset, Int_t *sterileIndex=nullptr, const TNamed *isetRangeName=nullptr)
Getter function without integration set.
void removeAll() override
Remove all argument inset using remove(const RooAbsArg&).
bool add(const RooAbsArg &var, bool valueServer, bool shapeServer, bool silent)
Overloaded RooCollection_t::add() method insert object into set and registers object as server to own...
Container class to hold unbinned data.
Definition RooDataSet.h:32
void markAsCompiled(RooAbsArg &arg) const
void compileServers(RooAbsArg &arg, RooArgSet const &normSet)
std::span< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
std::span< double > output()
RooBatchCompute::Config config(RooAbsArg const *arg) const
static const char * str(const TNamed *ptr)
Return C++ string corresponding to given TNamed pointer.
Definition RooNameReg.h:39
static const TNamed * ptr(const char *stringPtr)
Return a unique TNamed pointer for given C++ string.
Efficient implementation of a product of PDFs of the form.
Definition RooProdPdf.h:36
void setCacheAndTrackHints(RooArgSet &) override
Label OK'ed components of a RooRealSumPdf with cache-and-track.
bool checkObservables(const RooArgSet *nset) const override
Check if FUNC is valid for given normalization set.
std::list< double > * plotSamplingHint(RooAbsRealLValue &, double, double) const override
Interface for returning an optional hint for initial sampling points when constructing a curve projec...
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
Retrieve bin boundaries if this distribution is binned in obs.
void printMetaArgs(std::ostream &os) const override
Customized printing of arguments of a RooRealSumPdf to more intuitively reflect the contents of the p...
bool isBinnedDistribution(const RooArgSet &obs) const override
Check if all components that depend on obs are binned.
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
const char * Data() const
Definition TString.h:386
Bool_t IsNull() const
Definition TString.h:424
RooConstVar & RooConst(double val)
const Int_t n
Definition legend1.C:16
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.
void compute(Config cfg, Computer comp, std::span< double > output, VarSpan vars, ArgSpan extraArgs={})
void getSortedComputationGraph(RooAbsArg const &func, RooArgSet &out)
std::string getColonSeparatedNameString(RooArgSet const &argSet, char delim=':')
unsigned long Value_t
Definition UniqueId.h:41