Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
NormalizationHelpers.cxx
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Jonas Rembser, CERN 2023
5 *
6 * Copyright (c) 2023, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
14
15#include <RooAbsArg.h>
16#include <RooArgList.h>
17#include <RooArgSet.h>
18
19#include <TNamed.h>
20
22
24
26{
27 _clonedArgsSet.emplace(arg.namePtr(), &arg);
28}
29
31{
32 auto existingServerClone = _clonedArgsSet.find(arg.namePtr());
33 if (existingServerClone != _clonedArgsSet.end()) {
34 return existingServerClone->second;
35 }
36 return nullptr;
37}
38
40{
41 for (RooAbsArg *server : arg.servers()) {
42 this->compile(*server, arg, normSet);
43 }
44 arg.redirectServers(_replacements);
45}
46
48{
49 this->compile(server, arg, normSet);
50 arg.redirectServers(_replacements);
51}
52
53/// Return a copy of `args` where each element is replaced by its compiled
54/// counterpart in this context, if there is one. Compiled objects that need to
55/// remember a normalization set must store the compiled args: the original
56/// args are not part of the compiled computation graph, so they are not
57/// affected by later transformations of that graph (for example the renaming
58/// of the channel observables in RooSimultaneous::compileForNormSet()).
60{
61 RooArgSet out;
62 for (RooAbsArg *arg : args) {
63 RooAbsArg *compiled = find(*arg);
64 out.add(compiled ? *compiled : *arg);
65 }
66 return out;
67}
68
70{
71 if (auto existingServerClone = this->find(arg)) {
73 }
74 if (arg.isFundamental() && !_topLevelNormSet.find(arg)) {
75 return nullptr;
76 }
77 if (isMarkedAsCompiled(arg)) {
78 return nullptr;
79 }
80
81 std::unique_ptr<RooAbsArg> newArg = arg.compileForNormSet(normSet, *this);
82 markAsCompiled(*newArg);
83 _replacements[&arg] = newArg.get();
84 this->add(*newArg);
85 RooAbsArg *out = newArg.get();
86 owner.addOwnedComponents(std::move(newArg));
87 return out;
88}
89
91{
92 arg.setAttribute("_COMPILED");
93}
94
95/// Mark `arg` and every branch node reachable through its server tree as
96/// already compiled. Use this after assembling or cloning a sub-graph
97/// yourself inside `compileForNormSet`: it prevents a follow-up
98/// `compileServers` call from re-cloning any of those internal nodes, while
99/// still letting the recursive descent reach the genuine leaves
100/// (fundamental observables and parameters) at the bottom of the tree.
102{
105 for (RooAbsArg *b : branches) {
106 markAsCompiled(*b);
107 }
108}
109
111{
112 return arg.getAttribute("_COMPILED");
113}
#define b(i)
Definition RSha256.hxx:100
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
const_iterator end() const
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:76
const TNamed * namePtr() const
De-duplicated pointer to this object's name.
Definition RooAbsArg.h:503
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
bool redirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool isRecursionStep=false)
Replace all direct servers of this object with the new servers in newServerList.
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.
Definition RooAbsArg.h:145
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
void branchNodeServerList(RooAbsCollection *list, const RooAbsArg *arg=nullptr, bool recurseNonDerived=false) const
Fill supplied list with all branch nodes of the arg tree starting with ourself as top node.
virtual bool isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
Definition RooAbsArg.h:175
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
void markAsCompiled(RooAbsArg &arg) const
RooArgSet mapToCompiled(RooArgSet const &args) const
Return a copy of args where each element is replaced by its compiled counterpart in this context,...
void compileServers(RooAbsArg &arg, RooArgSet const &normSet)
RooAbsArg * find(RooAbsArg &arg) const
RooAbsArg * compileImpl(RooAbsArg &arg, RooAbsArg &owner, RooArgSet const &normSet)
bool isMarkedAsCompiled(RooAbsArg const &arg) const
CompileContext(RooArgSet const &topLevelNormSet)
void compileServer(RooAbsArg &server, RooAbsArg &arg, RooArgSet const &normSet)
void markSubtreeAsCompiled(RooAbsArg &arg) const
Mark arg and every branch node reachable through its server tree as already compiled.