60 ServerToAdd(
RooAbsArg *theArg,
bool isShape) : arg{theArg}, isShapeServer{isShape} {}
62 bool isShapeServer =
false;
65void addObservableToServers(
RooAbsReal const &function,
RooAbsArg &leaf, std::vector<ServerToAdd> &serversToAdd,
66 const char *rangeName)
69 if (leaflv && leaflv->getBinning(rangeName).isParameterized()) {
72 <<
" has parameterized binning, add value dependence of boundary objects rather than shape of leaf"
74 if (leaflv->getBinning(rangeName).lowBoundFunc()) {
75 serversToAdd.emplace_back(leaflv->getBinning(rangeName).lowBoundFunc(),
false);
77 if (leaflv->getBinning(rangeName).highBoundFunc()) {
78 serversToAdd.emplace_back(leaflv->getBinning(rangeName).highBoundFunc(),
false);
82 <<
" as shape dependent" << std::endl;
83 serversToAdd.emplace_back(&leaf,
true);
87void addParameterToServers(
RooAbsReal const &function,
RooAbsArg &leaf, std::vector<ServerToAdd> &serversToAdd,
92 <<
" as value dependent" << std::endl;
95 <<
" as shape dependent" << std::endl;
97 serversToAdd.emplace_back(&leaf, isShapeServer);
100enum class MarkedState { Dependent, Independent, AlreadyAdded };
103void unmarkDepValueClients(
RooAbsArg const &dep,
RooArgSet const &args, std::vector<MarkedState> &marked)
105 assert(args.
size() == marked.size());
108 marked[
index] = MarkedState::Dependent;
109 for (
RooAbsArg *client : dep.valueClients()) {
110 unmarkDepValueClients(*client, args, marked);
115std::vector<ServerToAdd>
116getValueAndShapeServers(
RooAbsReal const &function,
RooArgSet const &depList,
const char *rangeName)
118 std::vector<ServerToAdd> serversToAdd;
122 function.treeNodeServerList(&allArgsList,
nullptr,
true,
true,
false,
false);
128 function.treeNodeServerList(&allValueArgsList,
nullptr,
true,
true,
true,
false);
129 RooArgSet allValueArgs{allValueArgsList};
132 std::vector<MarkedState> marked(allArgs.size(), MarkedState::Independent);
133 marked.back() = MarkedState::Dependent;
141 unmarkDepValueClients(*depInArgs, allArgs, marked);
142 addObservableToServers(function, *depInArgs, serversToAdd, rangeName);
148 for (std::size_t i = 0; i < allArgs.size(); ++i) {
149 if(marked[i] == MarkedState::Dependent) {
150 for(
RooAbsArg* server : allArgs[i]->servers()) {
151 int index = allArgs.index(server->GetName());
152 if(
index >= 0 && marked[
index] == MarkedState::Independent) {
153 addParameterToServers(function, *server, serversToAdd, !allValueArgs.find(*server));
154 marked[
index] = MarkedState::AlreadyAdded;
165 for (
const auto arg :
function.servers()) {
168 if (!arg->dependsOnValue(intDepList)) {
170 }
else if (!arg->isValueServer(function) && !arg->isShapeServer(function)) {
178 if (arg->isDerived()) {
188 bool overlapOK =
true;
189 for (
const auto otherArg :
function.servers()) {
195 if (arg->overlaps(*otherArg,
true)) {
209 anIntOKDepList.
add(*arg,
true);
210 oocxcoutI(&function, Integration) <<
function.GetName() <<
": Observable " << arg->GetName()
211 <<
" is suitable for analytical integration (if supported by p.d.f)"
247 const char* rangeName) :
250 _sumList(
"!sumList",
"Categories to be summed numerically",this,false,false),
251 _intList(
"!intList",
"Variables to be integrated numerically",this,false,false),
252 _anaList(
"!anaList",
"Variables to be integrated analytically",this,false,false),
253 _jacList(
"!jacList",
"Jacobian product term",this,false,false),
254 _facList(
"!facList",
"Variables independent of function",this,false,true),
255 _function(
"!func",
"Function to be integrated",this,false,false),
257 _sumCat(
"!sumCat",
"SuperCategory for summation",this,false,false),
281 oocxcoutI(&function,Integration) <<
"RooRealIntegral::ctor(" <<
GetName() <<
") Constructing integral of function "
282 << function.GetName() <<
" over observables" << depList <<
" with normalization "
284 << (rangeName?rangeName:
"<none>") << std::endl ;
298 if (function.dependsOn(*nArg)) {
314 for (
auto arg : intDepList) {
315 if(!arg->isLValue()) {
320 if (!function.dependsOn(*arg)) {
321 std::unique_ptr<RooAbsArg> argClone{
static_cast<RooAbsArg*
>(arg->Clone())};
329 oocxcoutI(&function,Integration) << function.GetName() <<
": Factorizing obserables are " <<
_facList << std::endl ;
340 RooArgSet exclLVBranches(
"exclLVBranches") ;
342 function.branchNodeServerList(&branchList) ;
344 for (
auto branch: branchList) {
347 if ((realArgLV && (realArgLV->
isJacobianOK(intDepList)!=0)) || catArgLV) {
348 exclLVBranches.
add(*branch) ;
353 branchListVD.
add(*branch) ;
358 exclLVBranches.
remove(depList,
true,
true) ;
362 RooArgSet exclLVServers(
"exclLVServers") ;
363 function.getObservables(&intDepList, exclLVServers);
366 bool converged(
false) ;
371 std::vector<RooAbsArg*> toBeRemoved;
372 for (
auto server : exclLVServers) {
374 toBeRemoved.push_back(server);
378 exclLVServers.
remove(toBeRemoved.begin(), toBeRemoved.end());
382 for (std::size_t i=0; i < exclLVBranches.
size(); ++i) {
383 const RooAbsArg* branch = exclLVBranches[i];
387 bsList.
remove(exclLVServers,
true,
true) ;
388 if (!bsList.
empty()) {
389 exclLVBranches.
remove(*branch,
true,
true) ;
398 for (std::size_t i=0; i < exclLVBranches.
size(); ++i) {
399 const RooAbsArg* branch = exclLVBranches[i];
401 exclLVBranches.
remove(*branch,
true,
true) ;
408 if (!exclLVServers.
empty() && !function.isBinnedDistribution(exclLVBranches)) {
410 intDepList.
remove(exclLVServers) ;
411 intDepList.
add(exclLVBranches) ;
425 for (
auto arg : intDepList) {
426 if (function.forceAnalyticalInt(*arg)) {
427 anIntOKDepList.
add(*arg) ;
431 if (!anIntOKDepList.
empty()) {
432 oocxcoutI(&function,Integration) << function.GetName() <<
": Observables that function forcibly requires to be integrated internally " << anIntOKDepList << std::endl ;
441 auto serversToAdd = getValueAndShapeServers(function, depList, rangeName);
442 fillAnIntOKDepList(function, intDepList, anIntOKDepList);
459 oocxcoutI(&function,Integration) << function.GetName() <<
": Function integrated observables " <<
_anaList <<
" internally with code " <<
_mode << std::endl ;
488 auto argDepList = std::unique_ptr<RooArgSet>(arg->getObservables(&intDepList));
489 for (
const auto argDep : *argDepList) {
491 numIntDepList.
add(*argDep,
true) ;
500 if (!exclLVServers.
empty()) {
502 intDepList.
remove(exclLVBranches) ;
503 intDepList.
add(exclLVServers) ;
509 for (
const auto arg : function.servers()) {
518 numIntDepList.
add(*arg,
true) ;
523 auto argDeps = std::unique_ptr<RooArgSet>(arg->getObservables(&intDepList));
525 if (!argDeps->empty()) {
529 for (
const auto dep : *argDeps) {
531 numIntDepList.
add(*dep,
true) ;
544 for (
const auto arg : numIntDepList) {
553 oocxcoutI(&function,Integration) << function.GetName() <<
": Observables " <<
_anaList <<
" are analytically integrated with code " <<
_mode << std::endl ;
556 oocxcoutI(&function,Integration) << function.GetName() <<
": Observables " <<
_intList <<
" are numerically integrated" << std::endl ;
559 oocxcoutI(&function,Integration) << function.GetName() <<
": Observables " <<
_sumList <<
" are numerically summed" << std::endl ;
564 if (!numIntDepList.
empty()) {
594 for(
auto const& toAdd : serversToAdd) {
595 addServer(*toAdd.arg, !toAdd.isShapeServer, toAdd.isShapeServer);
612 if (server->isValueServer(*
this)) {
614 server->leafNodeServerList(&leafSet) ;
615 for (
const auto leaf : leafSet) {
640 if (exclLVBranches.
empty())
return false ;
653 if (!(exclLVBranches.
find(client->GetName())==client)) {
654 if (allBranches.
find(client->GetName())==client) {
666 return (numLVServ==1) ;
698 coutE(Integration) <<
ClassName() <<
"::" <<
GetName() <<
": failed to create valid integrand." << std::endl;
707 coutE(Integration) <<
ClassName() <<
"::" <<
GetName() <<
": failed to create valid integrator." << std::endl;
711 cxcoutI(NumIntegration) <<
"RooRealIntegral::init(" <<
GetName() <<
") using numeric integrator "
715 cxcoutI(NumIntegration) <<
"RooRealIntegral::init(" <<
GetName() <<
") evaluation requires " <<
_intList.
size() <<
"-D numeric integration step. Evaluation may be slow, sufficient numeric precision for fitting & minimization is not guaranteed" << std::endl ;
729 _valid(other._valid),
730 _respectCompSelect(other._respectCompSelect),
731 _sumList(
"!sumList",this,other._sumList),
732 _intList(
"!intList",this,other._intList),
733 _anaList(
"!anaList",this,other._anaList),
734 _jacList(
"!jacList",this,other._jacList),
735 _facList(
"!facList",
"Variables independent of function",this,false,true),
736 _function(
"!func",this,other._function),
737 _iconfig(other._iconfig),
738 _sumCat(
"!sumCat",this,other._sumCat),
740 _intOperMode(other._intOperMode),
741 _restartNumIntEngine(false),
742 _rangeName(other._rangeName),
747 for (
const auto arg : other.
_facList) {
748 std::unique_ptr<RooAbsArg> argClone{
static_cast<RooAbsArg*
>(arg->Clone())};
786 std::unique_ptr<RooArgSet> tmp;
792 tmp = std::make_unique<RooArgSet>();
795 newNormSet = tmp.
get();
862 <<
":evaluate: cannot initialize numerical integrator" << std::endl;
894 cxcoutD(Tracing) <<
"RooRealIntegral::evaluate_analytic(" <<
GetName()
945 ccxcoutD(Tracing) <<
"raw*fact = " << retVal << std::endl ;
965 jacProd *= arg->jacobian() ;
970 return std::abs(jacProd) ;
985 for (
const auto& nameIdx : *sumCat) {
1021 bool mustReplaceAll,
bool nameChange,
bool isRecursive)
1046 _params = std::make_unique<RooArgSet>(
"params") ;
1050 if (server->isValueServer(*
this))
_params->
add(*server) ;
1099 os <<
"d[Ana]" << tmp <<
" ";
1105 if (!tmp2.
empty()) {
1106 os <<
" d[Num]" << tmp2 <<
" ";
1118 os <<
indent <<
"--- RooRealIntegral ---" << std::endl;
1119 os <<
indent <<
" Integrates ";
1123 os <<
indent <<
" operating mode is "
1125 os <<
indent <<
" Summed discrete args are " <<
_sumList << std::endl ;
1126 os <<
indent <<
" Numerically integrated args are " <<
_intList << std::endl;
1127 os <<
indent <<
" Analytically integrated args using mode " <<
_mode <<
" are " <<
_anaList << std::endl ;
1128 os <<
indent <<
" Arguments included in Jacobian are " <<
_jacList << std::endl ;
1129 os <<
indent <<
" Factorized arguments are " <<
_facList << std::endl ;
1130 os <<
indent <<
" Function normalization set " ;
1158std::unique_ptr<RooAbsArg>
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
static void indent(ostringstream &buf, int indent_level)
static unsigned int total
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
RooExpensiveObjectCache & expensiveObjectCache() const
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.
void setOperMode(OperMode mode, bool recurseADirty=true)
Set the operation mode of this node.
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.
const RefCountList_t & valueClients() const
List of all value clients of this object. Value clients receive value updates.
virtual void setExpensiveObjectCache(RooExpensiveObjectCache &cache)
static void setDirtyInhibit(bool flag)
Control global dirty inhibit mode.
virtual std::unique_ptr< RooAbsArg > compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const
const RefCountList_t & servers() const
List of all servers of this object.
bool dependsOnValue(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr) const
Check whether this object depends on values from an element in the serverList.
void addServer(RooAbsArg &server, bool valueProp=true, bool shapeProp=false, std::size_t refCount=1)
Register another RooAbsArg as a server to us, ie, declare that we depend on it.
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
bool isValueOrShapeDirtyAndClear() const
bool inhibitDirty() const
Delete watch flag.
RefCountList_t _clientList
RefCountList_t _serverList
bool isValueServer(const RooAbsArg &arg) const
Check if this is serving values to arg.
OperMode operMode() const
Query the operation mode of this node.
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
Int_t numTypes(const char *=nullptr) const
Return number of types defined (in range named rangeName if rangeName!=nullptr)
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
Storage_t const & get() const
Const access to the underlying stl container.
void sortTopologically()
Sort collection topologically: the servers of any RooAbsArg will be before that RooAbsArg in the coll...
bool contains(const RooAbsArg &var) const
Check if collection contains an argument with the same name as var.
Int_t getSize() const
Return the number of elements in the collection.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in the collection.
void assign(const RooAbsCollection &other) const
Sets the value, cache and constant attribute of any argument in our set that also appears in the othe...
Storage_t::size_type size() const
RooAbsArg * first() const
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
RooAbsArg * find(const char *name) const
Find object with given name in list.
void Print(Option_t *options=nullptr) const override
This method must be overridden when a class wants to print itself.
Abstract base class for objects that are lvalues, i.e.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual bool isJacobianOK(const RooArgSet &depList) const
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
RooFit::OwningPtr< 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 std::liste...
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Structure printing.
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursiveStep) override
A buffer for reading values from trees.
double _value
Cache for current value of object.
double traceEval(const RooArgSet *set) const
Calculate current value of object, with error tracing wrapper.
virtual double analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName=nullptr) const
Implements the actual analytical integral(s) advertised by getAnalyticalIntegral.
virtual bool isBinnedDistribution(const RooArgSet &) const
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
static bool _globalSelectComp
Component selection flag for RooAbsPdf::plotCompOn.
RooArgList is a container object that can hold multiple RooAbsArg objects.
bool _valueServer
If true contents is value server of owner.
bool isValueServer() const
Returns true of contents is value server of owner.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
void removeAll() override
Remove all argument inset using remove(const RooAbsArg&).
bool addOwned(RooAbsArg &var, bool silent=false) override
Overloaded RooCollection_t::addOwned() method insert object into owning set and registers object as s...
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...
RooDouble is a minimal implementation of a TObject holding a double value.
bool registerObject(const char *ownerName, const char *objectName, TObject &cacheObject, const RooArgSet ¶ms)
Register object associated with given name and given associated parameters with given values in cache...
const TObject * retrieveObject(const char *name, TClass *tclass, const RooArgSet ¶ms)
Retrieve object from cache that was registered under given name with given parameters,...
RooNameReg is a registry for const char* names.
static const char * str(const TNamed *ptr)
Return C++ string corresponding to given TNamed pointer.
RooNumIntConfig holds the configuration parameters of the various numeric integrators used by RooReal...
static RooNumIntFactory & instance()
Static method returning reference to singleton instance of factory.
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,...
RooRealIntegral performs hybrid numerical/analytical integrals of RooAbsReal objects.
RooNumIntConfig * _iconfig
bool initNumIntegrator() const
(Re)Initialize numerical integration engine if necessary.
RooArgSet const * funcNormSet() const
RooFit::OwningPtr< RooAbsReal > createIntegral(const RooArgSet &iset, const RooArgSet *nset=nullptr, const RooNumIntConfig *cfg=nullptr, const char *rangeName=nullptr) const override
Create an object that represents the integral of the function over one or more observables std::liste...
void setAllowComponentSelection(bool allow)
Set component selection to be allowed/forbidden.
RooRealProxy _function
Function being integration.
RooArgSet intVars() const
RooSetProxy _intList
Set of continuous observables over which is integrated numerically.
virtual double sum() const
Perform summation of list of category dependents to be integrated.
RooSetProxy _facList
Set of observables on which function does not depends, which are integrated nevertheless.
std::unique_ptr< RooArgSet > _params
! cache for set of parameters
static void setCacheAllNumeric(Int_t ndim)
Global switch to cache all integral values that integrate at least ndim dimensions numerically.
IntOperMode _intOperMode
integration operation mode
bool _cacheNum
Cache integral if numeric.
double evaluate() const override
Perform the integration and return the result.
const RooArgSet & parameters() const
std::unique_ptr< RooAbsFunc > _numIntegrand
! do not persist
RooSetProxy _jacList
Set of lvalue observables over which is analytically integration that have a non-unit Jacobian.
bool isValidReal(double value, bool printError=false) const override
Check if current value is valid.
RooArgSet _saveInt
! do not persist
double getValV(const RooArgSet *set=nullptr) const override
Return value of object.
RooSetProxy _anaList
Set of observables over which is integrated/summed analytically.
bool _restartNumIntEngine
! do not persist
bool servesExclusively(const RooAbsArg *server, const RooArgSet &exclLVBranches, const RooArgSet &allBranches) const
Utility function that returns true if 'object server' is a server to exactly one of the RooAbsArgs in...
bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursive) override
Intercept server redirects and reconfigure internal object accordingly.
RooSetProxy _sumList
Set of discrete observable over which is summed numerically.
~RooRealIntegral() override
void printMetaArgs(std::ostream &os) const override
Customized printing of arguments of a RooRealIntegral to more intuitively reflect the contents of the...
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Print the state of this object to the specified output stream.
std::unique_ptr< RooAbsIntegrator > _numIntEngine
! do not persist
virtual double integrate() const
Perform hybrid numerical/analytical integration over all real-valued dependents.
RooListProxy _sumCat
! do not persist
virtual double jacobianProduct() const
Return product of jacobian terms originating from analytical integration.
static Int_t getCacheAllNumeric()
Return minimum dimensions of numeric integration for which values are cached.
RooArgSet _saveSum
! do not persist
static Int_t _cacheAllNDim
! Cache all integrals with given numeric dimension
std::unique_ptr< RooArgSet > _funcNormSet
Optional normalization set passed to function.
std::unique_ptr< RooAbsArg > compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const override
void autoSelectDirtyMode()
Set appropriate cache operation mode for integral depending on cache operation mode of server objects...
RooArgSet _facListOwned
Owned components in _facList.
const char * intRange() const
bool getAllowComponentSelection() const
Check if component selection is allowed.
bool empty() const
Check if empty.
The RooSuperCategory can join several RooAbsCategoryLValue objects into a single category.
bool setIndex(value_type index, bool printError=true) override
Set the value of the super category to the specified index.
bool inRange(const char *rangeName) const override
Check that all input category states are in the given range.
bool setArg(T &newRef)
Change object held in proxy into newRef.
The TNamed class is the base class for all named ROOT classes.
const char * GetName() const override
Returns name of object.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
TString & Append(const char *cs)
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
T * OwningPtr
An alias for raw pointers for indicating that the return type of a RooFit function is an owning point...