41 typedef RooProduct::ProdMap::iterator RPPMIter ;
42 std::pair<RPPMIter,RPPMIter> findOverlap2nd(RPPMIter i, RPPMIter end) ;
43 void dump_map(std::ostream& os, RPPMIter i, RPPMIter end) ;
69 _compRSet(
"!compRSet",
"Set of real product components",this),
70 _compCSet(
"!compCSet",
"Set of category product components",this),
73 for (
auto comp : prodSet) {
88 _compRSet(
"!compRSet",this,other._compRSet),
89 _compCSet(
"!compCSet",this,other._compCSet),
90 _cacheMgr(other._cacheMgr,this)
103 coutE(InputArguments) <<
"RooProduct::addTerm(" <<
GetName() <<
") ERROR: component " << term->
GetName()
104 <<
" is not of type RooAbsReal or RooAbsCategory" << std::endl ;
105 throw std::invalid_argument(
"RooProduct can only handle terms deriving from RooAbsReal or RooAbsCategory.");
119 for (
auto const* rcomp : static_range_cast<RooAbsReal*>(
_compRSet)) {
121 depends = rcomp->dependsOn(dep);
139 for (
auto const* rcomp : static_range_cast<RooAbsReal*>(
_compRSet)) {
140 if( !rcomp->dependsOn(allVars) ) indep->
add(*rcomp);
142 if (!indep->
empty()) {
143 map->push_back( std::make_pair(
new RooArgSet(),indep) );
149 for (
auto const* var : static_range_cast<RooAbsReal*>(allVars)) {
153 for (
auto const* rcomp2 : static_range_cast<RooAbsReal*>(
_compRSet)) {
154 if( rcomp2->dependsOn(*var) ) comps->
add(*rcomp2);
156 map->push_back( std::make_pair(vars,comps) );
162 std::pair<ProdMap::iterator,ProdMap::iterator> i = findOverlap2nd(map->begin(),map->end());
163 overlap = (i.first!=i.second);
165 i.first->first->add(*i.second->first);
168 for (
auto const* targ : *(i.second->second)) {
169 if (!i.first->second->find(*targ)) {
170 i.first->second->add(*targ) ;
175 delete i.second->first;
176 delete i.second->second;
177 map->erase(i.second);
186 for (ProdMap::iterator i = map->begin();i!=map->end();++i) {
187 nVar+=i->first->size();
188 nFunc+=i->second->size();
190 assert(nVar==allVars.
size());
207 Int_t sterileIndex(-1);
209 if (cache!=
nullptr) {
216 cxcoutD(Integration) <<
"RooProduct::getPartIntList(" <<
GetName() <<
") groupProductTerms returned map" ;
217 if (
dologD(Integration)) {
218 dump_map(
ccoutD(Integration),map->begin(),map->end());
219 ccoutD(Integration) << std::endl;
225 for (ProdMap::iterator iter = map->begin() ; iter != map->end() ; ++iter) {
227 delete iter->second ;
234 for (ProdMap::const_iterator i = map->begin();i!=map->end();++i) {
236 if (i->second->size()>1) {
238 auto ownedTerm = std::make_unique<RooProduct>(
name,
name,*i->second);
239 term = ownedTerm.get();
241 cxcoutD(Integration) <<
"RooProduct::getPartIntList(" <<
GetName() <<
") created subexpression " << term->
GetName() << std::endl;
243 assert(i->second->size()==1);
244 term =
static_cast<RooAbsReal*
>(i->second->at(0));
246 assert(term!=
nullptr);
247 if (i->first->empty()) {
249 cxcoutD(Integration) <<
"RooProduct::getPartIntList(" <<
GetName() <<
") adding simple factor " << term->
GetName() << std::endl;
251 std::unique_ptr<RooAbsReal> integral{term->
createIntegral(*i->first,isetRange)};
253 cxcoutD(Integration) <<
"RooProduct::getPartIntList(" <<
GetName() <<
") adding integral for " << term->
GetName() <<
" : " << integral->GetName() << std::endl;
260 cxcoutD(Integration) <<
"RooProduct::getPartIntList(" <<
GetName() <<
") created list " << cache->
_prodList <<
" with code " << code+1 << std::endl
261 <<
" for iset=" << *iset <<
" @" << iset <<
" range: " << (isetRange?isetRange:
"<none>") << std::endl ;
263 for (ProdMap::iterator iter = map->begin() ; iter != map->end() ; ++iter) {
265 delete iter->second ;
276 const char* rangeName)
const
283 assert(analVars.
empty());
284 analVars.
add(allVars) ;
297 if (cache==
nullptr) {
305 assert(cache!=
nullptr);
317 for (
const auto arg : partIntList) {
318 const auto term =
static_cast<const RooAbsReal*
>(arg);
319 double x = term->getVal();
334 for (
auto const* arg : terms) {
335 if (first) { first=
false;}
337 pname.
Append(arg->GetName());
353 auto rcomp =
static_cast<const RooAbsReal*
>(item);
355 prod *= rcomp->getVal(nset) ;
361 prod *= ccomp->getCurrentIndex() ;
370 std::span<double> output = ctx.
output();
371 std::size_t nEvents = output.size();
373 for (
unsigned int i = 0; i < nEvents; ++i) {
378 auto rcomp =
static_cast<const RooAbsReal*
>(item);
379 auto componentValues = ctx.
at(rcomp);
381 for (
unsigned int i = 0; i < nEvents; ++i) {
382 output[i] *= componentValues.size() == 1 ? componentValues[0] : componentValues[i];
390 for (
unsigned int i = 0; i < nEvents; ++i) {
391 output[i] *= catIndex;
403 auto func =
static_cast<const RooAbsReal*
>(item);
405 if (std::list<double>* binb = func->binBoundaries(obs,xlo,xhi)) {
420 auto func =
static_cast<const RooAbsReal*
>(item);
422 if (func->dependsOn(obs) && !func->isBinnedDistribution(obs)) {
438 auto func =
static_cast<const RooAbsReal*
>(item);
440 if (std::list<double>* hint = func->plotSamplingHint(obs,xlo,xhi)) {
479 if (!first) { os <<
" * " ; }
else { first = false ; }
480 os << rcomp->GetName() ;
486 if (!first) { os <<
" * " ; }
else { first = false ; }
487 os << ccomp->GetName() ;
498 throw std::runtime_error(
"RooProduct::ioStreamerPass2(): the number of proxies in the proxy list should be at least 2!");
518 auto expectProxyIs = [
this](std::size_t idx,
RooAbsProxy * proxyInArg,
RooListProxy * ourProxy,
const char* memberName) {
519 if(proxyInArg != ourProxy) {
527 std::stringstream ss;
528 ss <<
"Problem when reading RooProduct instance \"" <<
GetName() <<
"\"!\n"
529 <<
" _proxyList[" << idx <<
"] was expected to be equal to " << memberName <<
", but it's not.\n"
530 <<
" - proxyList[" << idx <<
"] : ";
531 proxyInArg->print(ss,
true);
532 ss <<
"\n - " << memberName <<
" : " ;
533 ourProxy->print(ss,
true);
534 ss <<
"\n RooFit will resolve this inconsistency by making _proxyList[" << idx <<
"] point to " << memberName
536 coutW(LinkStateMgmt) << ss.str() << std::endl;
540 expectProxyIs(0, p0, &
_compRSet,
"_compRSet");
541 expectProxyIs(1, p1, &
_compCSet,
"_compCSet");
547std::pair<RPPMIter,RPPMIter> findOverlap2nd(RPPMIter i, RPPMIter end)
550 for (; i != end; ++i) {
551 for (RPPMIter j(i + 1); j != end; ++j) {
552 if (i->second->overlaps(*j->second)) {
553 return std::make_pair(i, j);
557 return std::make_pair(end,end);
561void dump_map(std::ostream& os, RPPMIter i, RPPMIter end)
567 if (first) { first=
false; }
568 else { os <<
" , " ; }
569 os << *(i->first) <<
" -> " << *(i->second) ;
Common abstract base class for objects that represent a value and a "shape" in RooFit.
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 void ioStreamerPass2()
Method called by workspace container to finalize schema evolution issues that cannot be handled in a ...
Int_t numProxies() const
Return the number of registered proxies.
RooAbsProxy * getProxy(Int_t index) const
Return the nth proxy from the proxy list.
Abstract base class for objects to be stored in RooAbsCache cache manager objects.
A space to attach TBranches.
virtual value_type getCurrentIndex() const
Return index number of current state.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
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.
Abstract interface for proxy classes.
const RooArgSet * nset() const
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...
bool _forceNumInt
Force numerical integration if flag set.
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 ...
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Int_t setObj(const RooArgSet *nset, T *obj, const TNamed *isetRangeName=nullptr)
Setter function without integration set.
T * getObjByIndex(Int_t index) const
Retrieve payload object by slot index.
RooArgSet selectFromSet2(RooArgSet const &argSet, int index) const
Create RooArgSet containing the objects that are both in the cached set 2 with a given index and an i...
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.
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...
std::span< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
std::span< double > output()
static const TNamed * ptr(const char *stringPtr)
Return a unique TNamed pointer for given C++ string.
RooArgList containedArgs(Action) override
Return list of all RooAbsArgs in cache element.
~CacheElem() override
Destructor.
Represents the product of a given set of RooAbsReal objects.
std::list< double > * binBoundaries(RooAbsRealLValue &, double, double) const override
Forward the plot sampling hint from the p.d.f. that defines the observable obs.
void doEval(RooFit::EvalContext &) const override
Base function for computing multiple values of a RooAbsReal.
double evaluate() const override
Evaluate product of input functions.
double analyticalIntegral(Int_t code, const char *rangeName=nullptr) const override
Calculate integral internally from appropriate partial integral cache.
void addTerm(RooAbsArg *term)
Add a term to this product.
std::list< double > * plotSamplingHint(RooAbsRealLValue &, double, double) const override
Forward the plot sampling hint from the p.d.f. that defines the observable obs.
ProdMap * groupProductTerms(const RooArgSet &) const
Group observables into subsets in which the product factorizes and that can thus be integrated separa...
double calculate(const RooArgList &partIntList) const
Calculate and return product of partial terms in partIntList.
bool forceAnalyticalInt(const RooAbsArg &dep) const override
Force internal handling of integration of given observable if any of the product terms depend on it.
~RooProduct() override
Destructor.
bool isBinnedDistribution(const RooArgSet &obs) const override
Tests if the distribution is binned. Unless overridden by derived classes, this always returns false.
void ioStreamerPass2() override
Method called by workspace container to finalize schema evolution issues that cannot be handled in a ...
Int_t getPartIntList(const RooArgSet *iset, const char *rangeName=nullptr) const
Return list of (partial) integrals whose product defines the integral of this RooProduct over the obs...
Int_t getAnalyticalIntegralWN(RooArgSet &allVars, RooArgSet &analVars, const RooArgSet *normSet, const char *rangeName=nullptr) const override
Declare that we handle all integrations internally.
void printMetaArgs(std::ostream &os) const override
Customized printing of arguments of a RooProduct to more intuitively reflect the contents of the prod...
const char * makeFPName(const char *pfx, const RooArgSet &terms) const
Construct automatic name for internal product terms.
RooProduct()
Default constructor.
RooObjCacheManager _cacheMgr
! The cache manager
const char * GetName() const override
Returns name of object.
void AddAt(TObject *obj, Int_t idx) override
Add object at position ids.
TObject * RemoveAt(Int_t idx) override
Remove object at index idx.
const char * Data() const
TString & Append(const char *cs)