Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
RooMultiReal.cxx
Go to the documentation of this file.
1#include "RooMultiReal.h"
2#include "RooConstVar.h"
3
4// Constructor
5RooMultiReal::RooMultiReal(const char *name, const char *title, RooCategory &indexCat, const RooArgList &models)
6 : RooAbsReal(name, title),
7 _models("_models", "List of RooAbsReal models", this), // name, title, owner
8 _index("_index", "Index category", this, indexCat) // name, title, owner, reference to RooCategory
9
10{
11 _models.add(models);
12
13 RooCategory &cat = dynamic_cast<RooCategory &>(const_cast<RooAbsCategory &>(_index.arg()));
14
15 for (int i = 0; i < _models.getSize(); ++i) {
16 cat.defineType(("model" + std::to_string(i)).c_str(), i);
17 }
18}
19
20// Copy constructor
22 : RooAbsReal(other, name),
23 _models("_models", this, other._models), // name, owner, other list proxy
24 _index("_index", this, other._index) // name, owner, other category proxy
25
26{
27}
28
29// Evaluate: returns the value of the currently selected RooAbsReal model
31{
32 int currentIndex = static_cast<int>(_index);
33 if (currentIndex < 0 || currentIndex >= _models.getSize()) {
34 // Defensive fallback: invalid index
35 return 0.0;
36 }
37
38 Double_t val = static_cast<RooAbsReal *>(_models.at(currentIndex))->getVal(_models.nset());
39
40 return val;
41}
42
43// Propagate parameter fetching to the current model
44void RooMultiReal::getParametersHook(const RooArgSet *nset, RooArgSet *list, bool stripDisconnected) const
45{
46 if (!stripDisconnected)
47 return;
48
49 list->removeAll();
50
51 RooAbsReal *absReal = static_cast<RooAbsReal *>(_models.at(static_cast<int>(_index)));
52
53 if (absReal->isFundamental()) {
54 if (!nset || !absReal->dependsOn(*nset)) {
55 list->add(*absReal);
56 }
57 return;
58 }
59
60 absReal->getParameters(nset, *list, stripDisconnected);
61 list->add(*_index);
62}
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
char name[80]
Definition TGX11.cxx:148
bool dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr, bool valueOnly=false) const
Test whether we depend on (ie, are served by) any object in the specified collection.
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...
virtual bool isFundamental() const
Is this object a fundamental type that can be added to a dataset?
Definition RooAbsArg.h:175
A space to attach TBranches.
RooAbsReal()
coverity[UNINIT_CTOR] Default constructor
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Object to represent discrete states.
Definition RooCategory.h:28
bool defineType(const std::string &label)
Define a state with given name.
RooCategoryProxy _index
RooMultiReal()=default
void getParametersHook(const RooArgSet *nset, RooArgSet *list, bool stripDisconnected) const override
RooListProxy _models
Double_t evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.