Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooAddModel.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 RooAddModel
19///
20/// RooAddModel is an efficient implementation of a sum of PDFs of the form
21/// \f[
22/// c_1 \cdot \mathrm{PDF}_1 + c_2 \cdot \mathrm{PDF}_2 + ... + c_n \cdot \mathrm{PDF}_n
23/// \f]
24/// or
25/// \f[
26/// 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
27/// \f]
28/// The first form is for extended likelihood fits, where the
29/// expected number of events is \f$ \sum_i c_i \f$. The coefficients \f$ c_i \f$
30/// can either be explicitly provided, or, if all components support
31/// extended likelihood fits, they can be calculated from the contribution
32/// of each PDF to the total number of expected events.
33///
34/// In the second form, the sum of the coefficients is enforced to be one,
35/// and the coefficient of the last PDF is calculated from that condition.
36///
37/// RooAddModel relies on each component PDF to be normalized, and will perform
38/// no normalization other than calculating the proper last coefficient \f$ c_n \f$, if requested.
39/// An (enforced) condition for this assumption is that each \f$ \mathrm{PDF}_i \f$ is independent
40/// of each coefficient \f$ i \f$.
41///
42///
43
44#include "RooAddModel.h"
45
46#include "RooAddHelpers.h"
47#include "RooMsgService.h"
48#include "RooDataSet.h"
49#include "RooRealProxy.h"
50#include "RooPlot.h"
51#include "RooRealVar.h"
52#include "RooAddGenContext.h"
53#include "RooNameReg.h"
54#include "RooBatchCompute.h"
55
56using namespace std;
57
59
60
61////////////////////////////////////////////////////////////////////////////////
62
64 _refCoefNorm("!refCoefNorm","Reference coefficient normalization set",this,false,false),
65 _projCacheMgr(this,10),
66 _intCacheMgr(this,10)
67{
69}
70
71
72
73////////////////////////////////////////////////////////////////////////////////
74/// Generic constructor from list of PDFs and list of coefficients.
75/// Each pdf list element (i) is paired with coefficient list element (i).
76/// The number of coefficients must be either equal to the number of PDFs,
77/// in which case extended MLL fitting is enabled, or be one less.
78///
79/// All PDFs must inherit from RooAbsPdf. All coefficients must inherit from RooAbsReal.
80
81RooAddModel::RooAddModel(const char *name, const char *title, const RooArgList& inPdfList, const RooArgList& inCoefList, bool ownPdfList) :
82 RooResolutionModel(name,title,(static_cast<RooResolutionModel*>(inPdfList.at(0)))->convVar()),
83 _refCoefNorm("!refCoefNorm","Reference coefficient normalization set",this,false,false),
84 _refCoefRangeName(0),
85 _projCacheMgr(this,10),
86 _intCacheMgr(this,10),
87 _codeReg(10),
88 _pdfList("!pdfs","List of PDFs",this),
89 _coefList("!coefficients","List of coefficients",this),
90 _haveLastCoef(false),
91 _allExtendable(false)
92{
93 const std::string ownName(GetName() ? GetName() : "");
94 if (inPdfList.size() > inCoefList.size() + 1 || inPdfList.size() < inCoefList.size()) {
95 std::stringstream msgSs;
96 msgSs << "RooAddModel::RooAddModel(" << ownName
97 << ") number of pdfs and coefficients inconsistent, must have Npdf=Ncoef or Npdf=Ncoef+1";
98 const std::string msgStr = msgSs.str();
99 coutE(InputArguments) << msgStr << "\n";
100 throw std::runtime_error(msgStr);
101 }
102
103 // Constructor with N PDFs and N or N-1 coefs
104 std::size_t i = 0;
105 for (auto const &coef : inCoefList) {
106 auto pdf = inPdfList.at(i);
107 if (!pdf) {
108 std::stringstream msgSs;
109 msgSs << "RooAddModel::RooAddModel(" << ownName
110 << ") number of pdfs and coefficients inconsistent, must have Npdf=Ncoef or Npdf=Ncoef+1";
111 const std::string msgStr = msgSs.str();
112 coutE(InputArguments) << msgStr << "\n";
113 throw std::runtime_error(msgStr);
114 }
115 if (!coef) {
116 coutE(InputArguments) << "RooAddModel::RooAddModel(" << ownName
117 << ") encountered and undefined coefficient, ignored\n";
118 continue;
119 }
120 if (!dynamic_cast<RooAbsReal *>(coef)) {
121 auto coefName = coef->GetName();
122 coutE(InputArguments) << "RooAddModel::RooAddModel(" << ownName << ") coefficient "
123 << (coefName != nullptr ? coefName : "") << " is not of type RooAbsReal, ignored\n";
124 continue;
125 }
126 if (!dynamic_cast<RooAbsPdf *>(pdf)) {
127 coutE(InputArguments) << "RooAddModel::RooAddModel(" << ownName << ") pdf "
128 << (pdf->GetName() ? pdf->GetName() : "") << " is not of type RooAbsPdf, ignored\n";
129 continue;
130 }
131 _pdfList.add(*pdf);
132 _coefList.add(*coef);
133 i++;
134 }
135
136 if (i < inPdfList.size()) {
137 auto pdf = inPdfList.at(i);
138 if (!dynamic_cast<RooAbsPdf *>(pdf)) {
139 std::stringstream msgSs;
140 msgSs << "RooAddModel::RooAddModel(" << ownName << ") last pdf " << (pdf->GetName() ? pdf->GetName() : "")
141 << " is not of type RooAbsPdf, fatal error";
142 const std::string msgStr = msgSs.str();
143 coutE(InputArguments) << msgStr << "\n";
144 throw std::runtime_error(msgStr);
145 }
146 _pdfList.add(*pdf);
147 } else {
148 _haveLastCoef = true;
149 }
150
152
153 if (ownPdfList) {
155 }
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// Copy constructor
160
161RooAddModel::RooAddModel(const RooAddModel& other, const char* name) :
163 _refCoefNorm("!refCoefNorm",this,other._refCoefNorm),
164 _refCoefRangeName((TNamed*)other._refCoefRangeName),
165 _projCacheMgr(other._projCacheMgr,this),
166 _intCacheMgr(other._intCacheMgr,this),
167 _codeReg(other._codeReg),
168 _pdfList("!pdfs",this,other._pdfList),
169 _coefList("!coefficients",this,other._coefList),
170 _haveLastCoef(other._haveLastCoef),
171 _allExtendable(other._allExtendable)
172{
174}
175
176
177
178////////////////////////////////////////////////////////////////////////////////
179/// By default the interpretation of the fraction coefficients is
180/// performed in the contextual choice of observables. This makes the
181/// shape of the p.d.f explicitly dependent on the choice of
182/// observables. This method instructs RooAddModel to freeze the
183/// interpretation of the coefficients to be done in the given set of
184/// observables. If frozen, fractions are automatically transformed
185/// from the reference normalization set to the contextual normalization
186/// set by ratios of integrals
187
189{
190 if (refCoefNorm.empty()) {
191 return ;
192 }
193
195 _refCoefNorm.add(refCoefNorm) ;
196
198}
199
200
201
202////////////////////////////////////////////////////////////////////////////////
203/// By default the interpretation of the fraction coefficients is
204/// performed in the default range. This make the shape of a RooAddModel
205/// explicitly dependent on the range of the observables. To allow
206/// a range independent definition of the fraction this function
207/// instructs RooAddModel to freeze its interpretation in the given
208/// named range. If the current normalization range is different
209/// from the reference range, the appropriate fraction coefficients
210/// are automically calculation from the reference fractions using
211/// ratios if integrals
212
213void RooAddModel::fixCoefRange(const char* rangeName)
214{
216}
217
218
219
220////////////////////////////////////////////////////////////////////////////////
221/// Instantiate a clone of this resolution model representing a convolution with given
222/// basis function. The owners object name is incorporated in the clones name
223/// to avoid multiple convolution objects with the same name in complex PDF structures.
224///
225/// RooAddModel will clone all the component models to create a composite convolution object
226
228{
229 // Check that primary variable of basis functions is our convolution variable
230 if (inBasis->getParameter(0) != x.absArg()) {
231 coutE(InputArguments) << "RooAddModel::convolution(" << GetName()
232 << ") convolution parameter of basis function and PDF don't match" << endl ;
233 ccoutE(InputArguments) << "basis->findServer(0) = " << inBasis->findServer(0) << " " << inBasis->findServer(0)->GetName() << endl ;
234 ccoutE(InputArguments) << "x.absArg() = " << x.absArg() << " " << x.absArg()->GetName() << endl ;
235 inBasis->Print("v") ;
236 return 0 ;
237 }
238
239 TString newName(GetName()) ;
240 newName.Append("_conv_") ;
241 newName.Append(inBasis->GetName()) ;
242 newName.Append("_[") ;
243 newName.Append(owner->GetName()) ;
244 newName.Append("]") ;
245
246 TString newTitle(GetTitle()) ;
247 newTitle.Append(" convoluted with basis function ") ;
248 newTitle.Append(inBasis->GetName()) ;
249
250 RooArgList modelList ;
251 for (auto obj : _pdfList) {
252 auto model = static_cast<RooResolutionModel*>(obj);
253 // Create component convolution
254 RooResolutionModel* conv = model->convolution(inBasis,owner) ;
255 modelList.add(*conv) ;
256 }
257
258 RooArgList theCoefList ;
259 for (auto coef : _coefList) {
260 theCoefList.add(*coef) ;
261 }
262
263 RooAddModel* convSum = new RooAddModel(newName,newTitle,modelList,theCoefList,true) ;
264 for (std::set<std::string>::const_iterator attrIt = _boolAttrib.begin();
265 attrIt != _boolAttrib.end(); ++attrIt) {
266 convSum->setAttribute((*attrIt).c_str()) ;
267 }
268 for (std::map<std::string,std::string>::const_iterator attrIt = _stringAttrib.begin();
269 attrIt != _stringAttrib.end(); ++attrIt) {
270 convSum->setStringAttribute((attrIt->first).c_str(), (attrIt->second).c_str()) ;
271 }
272 convSum->changeBasis(inBasis) ;
273 return convSum ;
274}
275
276
277
278////////////////////////////////////////////////////////////////////////////////
279/// Return code for basis function representing by 'name' string.
280/// The basis code of the first component model will be returned,
281/// if the basis is supported by all components. Otherwise 0
282/// is returned
283
285{
286 bool first(true), code(0) ;
287 for (auto obj : _pdfList) {
288 auto model = static_cast<RooResolutionModel*>(obj);
289 Int_t subCode = model->basisCode(name) ;
290 if (first) {
291 code = subCode ;
292 first = false ;
293 } else if (subCode==0) {
294 code = 0 ;
295 }
296 }
297
298 return code ;
299}
300
301
302
303////////////////////////////////////////////////////////////////////////////////
304/// Retrieve cache element with for calculation of p.d.f value with normalization set nset and integrated over iset
305/// in range 'rangeName'. If cache element does not exist, create and fill it on the fly. The cache contains
306/// suplemental normalization terms (in case not all added p.d.f.s have the same observables), projection
307/// integrals to calculated transformed fraction coefficients when a frozen reference frame is provided
308/// and projection integrals for similar transformations when a frozen reference range is provided.
309
311{
312 // Check if cache already exists
313 auto cache = static_cast<AddCacheElem*>(_projCacheMgr.getObj(nset,iset,0,normRange()));
314 if (cache) {
315 return cache ;
316 }
317
318 //Create new cache
319 cache = new AddCacheElem{*this, _pdfList, _coefList, nset, iset, _refCoefNorm,
322
323 _projCacheMgr.setObj(nset,iset,cache,RooNameReg::ptr(normRange())) ;
324
325 return cache;
326}
327
328
329////////////////////////////////////////////////////////////////////////////////
330/// Update the coefficient values in the given cache element: calculate new remainder
331/// fraction, normalize fractions obtained from extended ML terms to unity, and
332/// multiply the various range and dimensional corrections needed in the
333/// current use context.
334
336{
337 _coefCache.resize(_pdfList.getSize());
338 for(std::size_t i = 0; i < _coefList.size(); ++i) {
339 _coefCache[i] = static_cast<RooAbsReal const&>(_coefList[i]).getVal(nset);
340 }
343}
344
345
346////////////////////////////////////////////////////////////////////////////////
347/// Calculate the current value
348
350{
351 const RooArgSet* nset = _normSet ;
352 AddCacheElem* cache = getProjCache(nset) ;
353
354 updateCoefficients(*cache,nset) ;
355
356
357 // Do running sum of coef/pdf pairs, calculate lastCoef.
358 double snormVal ;
359 double value(0) ;
360 Int_t i(0) ;
361 for (auto obj : _pdfList) {
362 auto pdf = static_cast<RooAbsPdf*>(obj);
363
364 if (_coefCache[i]!=0.) {
365 snormVal = nset ? cache->suppNormVal(i) : 1.0 ;
366 double pdfVal = pdf->getVal(nset) ;
367 // double pdfNorm = pdf->getNorm(nset) ;
368 if (pdf->isSelectedComp()) {
369 value += pdfVal*_coefCache[i]/snormVal ;
370 cxcoutD(Eval) << "RooAddModel::evaluate(" << GetName() << ") value += ["
371 << pdf->GetName() << "] " << pdfVal << " * " << _coefCache[i] << " / " << snormVal << endl ;
372 }
373 }
374 i++ ;
375 }
376
377 return value ;
378}
379
380void RooAddModel::computeBatch(cudaStream_t *stream, double *output, size_t nEvents,
381 RooFit::Detail::DataMap const &dataMap) const
382{
383 // Like many other functions in this class, the implementation was copy-pasted from the RooAddPdf
384
385 _coefCache.resize(_pdfList.size());
386 for (std::size_t i = 0; i < _coefList.size(); ++i) {
387 auto coefVals = dataMap.at(&_coefList[i]);
388 // We don't support per-event coefficients in this function. If the CPU
389 // mode is used, we can just fall back to the RooAbsReal implementation.
390 // With CUDA, we can't do that because the inputs might be on the device.
391 // That's why we throw an exception then.
392 if (coefVals.size() > 1) {
393 if (stream) {
394 throw std::runtime_error("The RooAddPdf doesn't support per-event coefficients in CUDA mode yet!");
395 }
396 RooAbsReal::computeBatch(stream, output, nEvents, dataMap);
397 return;
398 }
399 _coefCache[i] = coefVals[0];
400 }
401
404 const RooArgSet *nset = nullptr;
405 AddCacheElem *cache = getProjCache(nullptr);
406 // We don't sync the coefficient values from the _coefList to the _coefCache
407 // because we have already done it using the dataMap.
408 updateCoefficients(*cache, nset);
409
410 for (unsigned int pdfNo = 0; pdfNo < _pdfList.size(); ++pdfNo) {
411 auto pdf = static_cast<RooAbsPdf *>(&_pdfList[pdfNo]);
412 if (pdf->isSelectedComp()) {
413 pdfs.push_back(dataMap.at(pdf));
414 coefs.push_back(_coefCache[pdfNo] / cache->suppNormVal(pdfNo));
415 }
416 }
418 dispatch->compute(stream, RooBatchCompute::AddPdf, output, nEvents, pdfs, coefs);
419}
420
421
422////////////////////////////////////////////////////////////////////////////////
423/// Reset error counter to given value, limiting the number
424/// of future error messages for this pdf to 'resetValue'
425
427{
429 _coefErrCount = resetValue ;
430}
431
432
433
434////////////////////////////////////////////////////////////////////////////////
435/// Check if PDF is valid for given normalization set.
436/// Coeffient and PDF must be non-overlapping, but pdf-coefficient
437/// pairs may overlap each other
438
440{
441 bool ret(false) ;
442
443 for (unsigned int i = 0; i < _coefList.size(); ++i) {
444 auto pdf = &_pdfList[i];
445 auto coef = &_coefList[i];
446
447 if (pdf->observableOverlaps(nset,*coef)) {
448 coutE(InputArguments) << "RooAddModel::checkObservables(" << GetName() << "): ERROR: coefficient " << coef->GetName()
449 << " and PDF " << pdf->GetName() << " have one or more dependents in common" << endl ;
450 ret = true ;
451 }
452 }
453
454 return ret ;
455}
456
457
458
459////////////////////////////////////////////////////////////////////////////////
460
462 const RooArgSet* normSet, const char* rangeName) const
463{
464 if (_forceNumInt) return 0 ;
465
466 // Declare that we can analytically integrate all requested observables
467 analVars.add(allVars) ;
468
469 // Retrieve (or create) the required component integral list
470 Int_t code ;
471 RooArgList *cilist ;
472 getCompIntList(normSet,&allVars,cilist,code,rangeName) ;
473
474 return code+1 ;
475
476}
477
478
479
480////////////////////////////////////////////////////////////////////////////////
481/// Check if this configuration was created before
482
483void RooAddModel::getCompIntList(const RooArgSet* nset, const RooArgSet* iset, pRooArgList& compIntList, Int_t& code, const char* isetRangeName) const
484{
485 Int_t sterileIdx(-1) ;
486
487 IntCacheElem* cache = (IntCacheElem*) _intCacheMgr.getObj(nset,iset,&sterileIdx,RooNameReg::ptr(isetRangeName)) ;
488 if (cache) {
489 code = _intCacheMgr.lastIndex() ;
490 compIntList = &cache->_intList ;
491
492 return ;
493 }
494
495 // Create containers for partial integral components to be generated
496 cache = new IntCacheElem ;
497
498 // Fill Cache
499 for (auto obj : _pdfList) {
500 auto model = static_cast<RooResolutionModel*>(obj);
501
502 cache->_intList.addOwned(std::unique_ptr<RooAbsReal>{model->createIntegral(*iset,nset,0,isetRangeName)});
503 }
504
505 // Store the partial integral list and return the assigned code ;
506 code = _intCacheMgr.setObj(nset,iset,(RooAbsCacheElement*)cache,RooNameReg::ptr(isetRangeName)) ;
507
508 // Fill references to be returned
509 compIntList = &cache->_intList ;
510}
511
512
513
514////////////////////////////////////////////////////////////////////////////////
515/// Return analytical integral defined by given scenario code
516
517double RooAddModel::analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName) const
518{
519 // No integration scenario
520 if (code==0) {
521 return getVal(normSet) ;
522 }
523
524 // Partial integration scenarios
526
527 RooArgList* compIntList ;
528
529 // If cache has been sterilized, revive this slot
530 if (cache==0) {
531 std::unique_ptr<RooArgSet> vars{getParameters(RooArgSet())} ;
532 RooArgSet nset = _intCacheMgr.selectFromSet1(*vars, code-1) ;
533 RooArgSet iset = _intCacheMgr.selectFromSet2(*vars, code-1) ;
534
535 int code2 = -1 ;
536 getCompIntList(&nset,&iset,compIntList,code2,rangeName) ;
537 } else {
538
539 compIntList = &cache->_intList ;
540
541 }
542
543 // Calculate the current value
544 const RooArgSet* nset = _normSet ;
545 AddCacheElem* pcache = getProjCache(nset) ;
546
547 updateCoefficients(*pcache,nset) ;
548
549 // Do running sum of coef/pdf pairs, calculate lastCoef.
550 double snormVal ;
551 double value(0) ;
552 Int_t i(0) ;
553 for (const auto obj : *compIntList) {
554 auto pdfInt = static_cast<const RooAbsReal*>(obj);
555 if (_coefCache[i]!=0.) {
556 snormVal = nset ? pcache->suppNormVal(i) : 1.0 ;
557 double intVal = pdfInt->getVal(nset) ;
558 value += intVal*_coefCache[i]/snormVal ;
559 cxcoutD(Eval) << "RooAddModel::evaluate(" << GetName() << ") value += ["
560 << pdfInt->GetName() << "] " << intVal << " * " << _coefCache[i] << " / " << snormVal << endl ;
561 }
562 i++ ;
563 }
564
565 return value ;
566
567}
568
569
570
571////////////////////////////////////////////////////////////////////////////////
572/// Return the number of expected events, which is either the sum of all coefficients
573/// or the sum of the components extended terms
574
575double RooAddModel::expectedEvents(const RooArgSet* nset) const
576{
577 double expectedTotal(0.0);
578
579 if (_allExtendable) {
580
581 // Sum of the extended terms
582 for (auto obj : _pdfList) {
583 auto pdf = static_cast<RooAbsPdf*>(obj);
584 expectedTotal += pdf->expectedEvents(nset) ;
585 }
586
587 } else {
588
589 // Sum the coefficients
590 for (const auto obj : _coefList) {
591 auto coef = static_cast<RooAbsReal*>(obj);
592 expectedTotal += coef->getVal() ;
593 }
594 }
595
596 return expectedTotal;
597}
598
599
600
601////////////////////////////////////////////////////////////////////////////////
602/// Interface function used by test statistics to freeze choice of observables
603/// for interpretation of fraction coefficients
604
605void RooAddModel::selectNormalization(const RooArgSet* depSet, bool force)
606{
607 if (!force && _refCoefNorm.getSize()!=0) {
608 return ;
609 }
610
611 if (!depSet) {
613 return ;
614 }
615
616 RooArgSet myDepSet;
617 getObservables(depSet, myDepSet);
618 fixCoefNormalization(myDepSet);
619}
620
621
622
623////////////////////////////////////////////////////////////////////////////////
624/// Interface function used by test statistics to freeze choice of range
625/// for interpretation of fraction coefficients
626
627void RooAddModel::selectNormalizationRange(const char* rangeName, bool force)
628{
629 if (!force && _refCoefRangeName) {
630 return ;
631 }
632
633 fixCoefRange(rangeName) ;
634}
635
636
637
638////////////////////////////////////////////////////////////////////////////////
639/// Return specialized context to efficiently generate toy events from RooAddModels.
640
642 const RooArgSet* auxProto, bool verbose) const
643{
644 return RooAddGenContext::create(*this,vars,prototype,auxProto,verbose).release();
645}
646
647
648
649////////////////////////////////////////////////////////////////////////////////
650/// Direct generation is safe if all components say so
651
653{
654 for (auto obj : _pdfList) {
655 auto pdf = static_cast<RooAbsPdf*>(obj);
656
657 if (!pdf->isDirectGenSafe(arg)) {
658 return false ;
659 }
660 }
661 return true ;
662}
663
664
665
666////////////////////////////////////////////////////////////////////////////////
667/// Return pseud-code that indicates if all components can do internal generation (1) or not (0)
668
669Int_t RooAddModel::getGenerator(const RooArgSet& directVars, RooArgSet &/*generateVars*/, bool /*staticInitOK*/) const
670{
671 for (auto obj : _pdfList) {
672 auto pdf = static_cast<RooAbsPdf*>(obj);
673
674 RooArgSet tmp ;
675 if (pdf->getGenerator(directVars,tmp)==0) {
676 return 0 ;
677 }
678 }
679 return 1 ;
680}
681
682
683
684
685////////////////////////////////////////////////////////////////////////////////
686/// This function should never be called as RooAddModel implements a custom generator context
687
689{
690 assert(0) ;
691}
692
693
694////////////////////////////////////////////////////////////////////////////////
695/// List all RooAbsArg derived contents in this cache element
696
698{
699 RooArgList allNodes(_intList) ;
700 return allNodes ;
701}
702
703
704////////////////////////////////////////////////////////////////////////////////
705/// Customized printing of arguments of a RooAddModel to more intuitively reflect the contents of the
706/// product operator construction
707
708void RooAddModel::printMetaArgs(ostream& os) const
709{
710 bool first(true) ;
711
712 os << "(" ;
713 for (unsigned int i=0; i < _coefList.size(); ++i) {
714 auto coef = &_coefList[i];
715 auto pdf = &_pdfList[i];
716 if (!first) {
717 os << " + " ;
718 } else {
719 first = false ;
720 }
721 os << coef->GetName() << " * " << pdf->GetName() ;
722 }
723 if (_pdfList.size() > _coefList.size()) {
724 os << " + [%] * " << _pdfList[_pdfList.size()-1].GetName() ;
725 }
726 os << ") " ;
727}
728
#define ccoutE(a)
#define cxcoutD(a)
#define coutE(a)
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition TGX11.cxx:110
double suppNormVal(std::size_t idx) const
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:74
void Print(Option_t *options=nullptr) const override
Print the object to the defaultPrintStream().
Definition RooAbsArg.h:318
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
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.
std::set< std::string > _boolAttrib
Definition RooAbsArg.h:654
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
std::map< std::string, std::string > _stringAttrib
Definition RooAbsArg.h:655
RooAbsArg * findServer(const char *name) const
Return server of this with name name. Returns nullptr if not found.
Definition RooAbsArg.h:208
RooAbsCacheElement is the abstract base class for objects to be stored in RooAbsCache cache manager o...
Int_t getSize() const
Return the number of elements in the collection.
const char * GetName() const override
Returns name of object.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
RooAbsGenContext is the abstract base class for generator contexts of RooAbsPdf objects.
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...
RooArgSet const * _normSet
Normalization integral (owned by _normMgr)
Definition RooAbsPdf.h:377
Int_t _errorCount
Number of errors remaining to print.
Definition RooAbsPdf.h:392
const char * normRange() const
Definition RooAbsPdf.h:310
static Int_t _verboseEval
Definition RooAbsPdf.h:371
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition RooAbsReal.h:62
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:91
bool _forceNumInt
Force numerical integration if flag set.
Definition RooAbsReal.h:512
virtual void computeBatch(cudaStream_t *, double *output, size_t size, RooFit::Detail::DataMap const &) 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...
static void updateCoefficients(RooAbsPdf const &addPdf, std::vector< double > &coefCache, RooArgList const &pdfList, bool haveLastCoef, AddCacheElem &cache, const RooArgSet *nset, RooArgSet const &refCoefNormSet, bool allExtendable, int &coefErrCount)
Update the RooAddPdf coefficients for a given normalization set and projection configuration.
RooArgList containedArgs(Action) override
List all RooAbsArg derived contents in this cache element.
RooArgList _intList
List of component integrals.
RooAddModel is an efficient implementation of a sum of PDFs of the form.
Definition RooAddModel.h:28
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 RooAddModels.
void printMetaArgs(std::ostream &os) const override
Customized printing of arguments of a RooAddModel to more intuitively reflect the contents of the pro...
RooObjCacheManager _projCacheMgr
! Manager of cache with coefficient projections and transformations
void getCompIntList(const RooArgSet *nset, const RooArgSet *iset, pRooArgList &compIntList, Int_t &code, const char *isetRangeName) const
Check if this configuration was created before.
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...
RooSetProxy _refCoefNorm
! Reference observable set for coefficient interpretation
Definition RooAddModel.h:97
bool _allExtendable
Flag indicating if all PDF components are extendable.
Int_t _coefErrCount
! Coefficient error counter
RooArgSet _ownedComps
! Owned components
void computeBatch(cudaStream_t *, double *output, size_t nEvents, RooFit::Detail::DataMap const &) const override
Base function for computing multiple values of a RooAbsReal.
RooListProxy _coefList
List of coefficients.
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 basisCode(const char *name) const override
Return code for basis function representing by 'name' string.
double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Return analytical integral defined by given scenario code.
RooResolutionModel * convolution(RooFormulaVar *basis, RooAbsArg *owner) const override
Instantiate a clone of this resolution model representing a convolution with given basis function.
bool checkObservables(const RooArgSet *nset) const override
Check if PDF is valid for given normalization set.
void generateEvent(Int_t code) override
This function should never be called as RooAddModel implements a custom generator context.
bool _haveLastCoef
Flag indicating if last PDFs coefficient was supplied in the ctor.
double expectedEvents(const RooArgSet *nset) const override
Return expected number of events for extended likelihood calculation, which is the sum of all coeffic...
RooListProxy _pdfList
List of component PDFs.
RooObjCacheManager _intCacheMgr
! Manager of cache with integrals
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...
void fixCoefNormalization(const RooArgSet &refCoefNorm)
By default the interpretation of the fraction coefficients is performed in the contextual choice of o...
void fixCoefRange(const char *rangeName)
By default the interpretation of the fraction coefficients is performed in the default range.
TNamed * _refCoefRangeName
! Reference range name for coefficient interpretation
Definition RooAddModel.h:98
std::vector< double > _coefCache
! Transiet cache with transformed values of coefficients
double evaluate() const override
Calculate the current value.
void updateCoefficients(AddCacheElem &cache, const RooArgSet *nset) const
Update the coefficient values in the given cache element: calculate new remainder fraction,...
bool isDirectGenSafe(const RooAbsArg &arg) const override
Direct generation is safe if all components say so.
Int_t getGenerator(const RooArgSet &directVars, RooArgSet &generateVars, bool staticInitOK=true) const override
Return pseud-code that indicates if all components can do internal generation (1) or not (0)
AddCacheElem * getProjCache(const RooArgSet *nset, const RooArgSet *iset=nullptr) const
Retrieve cache element with for calculation of p.d.f value with normalization set nset and integrated...
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &numVars, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Variant of getAnalyticalIntegral that is also passed the normalization set that should be applied to ...
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
RooAbsArg * absArg() const
Return pointer to contained argument.
Definition RooArgProxy.h:47
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
virtual void compute(cudaStream_t *, Computer, RestrictArr, size_t, const VarVector &, ArgVector &)=0
Int_t setObj(const RooArgSet *nset, T *obj, const TNamed *isetRangeName=nullptr)
Setter function without integration set.
RooArgSet selectFromSet1(RooArgSet const &argSet, int index) const
Create RooArgSet contatining the objects that are both in the cached set 1.
T * getObjByIndex(Int_t index) const
Retrieve payload object by slot index.
RooArgSet selectFromSet2(RooArgSet const &argSet, int index) const
Create RooArgSet contatining the objects that are both in the cached set 2.
void reset()
Clear the cache.
Int_t lastIndex() const
Return index of slot used in last get or set operation.
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...
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:57
RooSpan< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
Definition DataMap.cxx:21
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
RooAbsArg * getParameter(const char *name) const
Return pointer to parameter with given name.
static const char * str(const TNamed *ptr)
Return C++ string corresponding to given TNamed pointer.
Definition RooNameReg.h:37
static const TNamed * ptr(const char *stringPtr)
Return a unique TNamed pointer for given C++ string.
RooResolutionModel is the base class for PDFs that represent a resolution model that can be convolute...
virtual void changeBasis(RooFormulaVar *basis)
Change the basis function we convolute with.
virtual RooResolutionModel * convolution(RooFormulaVar *basis, RooAbsArg *owner) const
Instantiate a clone of this resolution model representing a convolution with given basis function.
RooTemplateProxy< RooAbsRealLValue > x
Dependent/convolution variable.
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:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
Basic string class.
Definition TString.h:139
TString & Append(const char *cs)
Definition TString.h:576
std::vector< RooSpan< const double > > VarVector
R__EXTERN RooBatchComputeInterface * dispatchCUDA
R__EXTERN RooBatchComputeInterface * dispatchCPU
This dispatch pointer points to an implementation of the compute library, provided one has been loade...
std::vector< double > ArgVector
Definition first.py:1
static void output()