42 typedef RooProduct::ProdMap::iterator RPPMIter ;
43 std::pair<RPPMIter,RPPMIter> findOverlap2nd(RPPMIter i, RPPMIter end) ;
44 void dump_map(std::ostream& os, RPPMIter i, RPPMIter end) ;
72 _compRSet(
"!compRSet",
"Set of real product components",this),
73 _compCSet(
"!compCSet",
"Set of category product components",this),
76 for (
auto comp : prodSet) {
108 coutE(InputArguments) <<
"RooProduct::addTerm(" <<
GetName() <<
") ERROR: component " << term->
GetName()
109 <<
" is not of type RooAbsReal or RooAbsCategory" << std::endl ;
110 throw std::invalid_argument(
"RooProduct can only handle terms deriving from RooAbsReal or RooAbsCategory.");
126 depends = rcomp->dependsOn(dep);
145 if( !rcomp->dependsOn(allVars) ) indep->
add(*rcomp);
147 if (!indep->
empty()) {
148 map->push_back( std::make_pair(
new RooArgSet(),indep) );
159 if( rcomp2->dependsOn(*var) ) comps->
add(*rcomp2);
161 map->push_back( std::make_pair(vars,comps) );
167 std::pair<ProdMap::iterator,ProdMap::iterator> i = findOverlap2nd(
map->begin(),
map->end());
168 overlap = (i.first!=i.second);
170 i.first->first->add(*i.second->first);
173 for (
auto const* targ : *(i.second->second)) {
174 if (!i.first->second->find(*targ)) {
175 i.first->second->add(*targ) ;
180 delete i.second->first;
181 delete i.second->second;
182 map->erase(i.second);
191 for (ProdMap::iterator i =
map->begin();i!=
map->end();++i) {
192 nVar+=i->first->size();
193 nFunc+=i->second->size();
195 assert(nVar==allVars.
size());
212 Int_t sterileIndex(-1);
214 if (cache!=
nullptr) {
221 cxcoutD(Integration) <<
"RooProduct::getPartIntList(" <<
GetName() <<
") groupProductTerms returned map" ;
222 if (
dologD(Integration)) {
224 ccoutD(Integration) << std::endl;
230 for (ProdMap::iterator iter =
map->begin() ; iter !=
map->end() ; ++iter) {
232 delete iter->second ;
239 for (ProdMap::const_iterator i =
map->begin();i!=
map->end();++i) {
241 if (i->second->size()>1) {
243 auto ownedTerm = std::make_unique<RooProduct>(
name,
name,*i->second);
244 term = ownedTerm.get();
246 cxcoutD(Integration) <<
"RooProduct::getPartIntList(" <<
GetName() <<
") created subexpression " << term->
GetName() << std::endl;
248 assert(i->second->size()==1);
249 term =
static_cast<RooAbsReal*
>(i->second->at(0));
251 assert(term!=
nullptr);
252 if (i->first->empty()) {
254 cxcoutD(Integration) <<
"RooProduct::getPartIntList(" <<
GetName() <<
") adding simple factor " << term->
GetName() << std::endl;
256 std::unique_ptr<RooAbsReal> integral{term->
createIntegral(*i->first,isetRange)};
258 cxcoutD(Integration) <<
"RooProduct::getPartIntList(" <<
GetName() <<
") adding integral for " << term->
GetName() <<
" : " << integral->GetName() << std::endl;
265 cxcoutD(Integration) <<
"RooProduct::getPartIntList(" <<
GetName() <<
") created list " << cache->
_prodList <<
" with code " << code+1 << std::endl
266 <<
" for iset=" << *iset <<
" @" << iset <<
" range: " << (isetRange?isetRange:
"<none>") << std::endl ;
268 for (ProdMap::iterator iter =
map->begin() ; iter !=
map->end() ; ++iter) {
270 delete iter->second ;
281 const char* rangeName)
const
288 assert(analVars.
empty());
289 analVars.
add(allVars) ;
302 if (cache==
nullptr) {
310 assert(cache!=
nullptr);
322 for (
const auto arg : partIntList) {
323 const auto term =
static_cast<const RooAbsReal*
>(arg);
324 double x = term->getVal();
339 for (
auto const* arg : terms) {
340 if (first) { first=
false;}
342 pname.
Append(arg->GetName());
358 auto rcomp =
static_cast<const RooAbsReal*
>(item);
360 prod *= rcomp->getVal(nset) ;
366 prod *= ccomp->getCurrentIndex() ;
375 std::span<double> output = ctx.
output();
376 std::size_t nEvents = output.size();
378 for (
unsigned int i = 0; i < nEvents; ++i) {
383 auto rcomp =
static_cast<const RooAbsReal*
>(item);
384 auto componentValues = ctx.
at(rcomp);
386 for (
unsigned int i = 0; i < nEvents; ++i) {
387 output[i] *= componentValues.size() == 1 ? componentValues[0] : componentValues[i];
395 for (
unsigned int i = 0; i < nEvents; ++i) {
396 output[i] *= catIndex;
408 auto func =
static_cast<const RooAbsReal*
>(item);
410 if (std::list<double>* binb = func->binBoundaries(obs,xlo,xhi)) {
425 auto func =
static_cast<const RooAbsReal*
>(item);
427 if (func->dependsOn(obs) && !func->isBinnedDistribution(obs)) {
443 auto func =
static_cast<const RooAbsReal*
>(item);
445 if (std::list<double>* hint = func->plotSamplingHint(obs,xlo,xhi)) {
481 for (
const auto parg : comp) {
482 if (parg->isDerived()) {
483 if (parg->canNodeBeCached()==
Always) {
484 trackNodes.
add(*parg) ;
499 if (!first) { os <<
" * " ; }
else { first = false ; }
500 os << rcomp->GetName() ;
506 if (!first) { os <<
" * " ; }
else { first = false ; }
507 os << ccomp->GetName() ;
518 throw std::runtime_error(
"RooProduct::ioStreamerPass2(): the number of proxies in the proxy list should be at least 2!");
538 auto expectProxyIs = [
this](std::size_t idx,
RooAbsProxy * proxyInArg,
RooListProxy * ourProxy,
const char* memberName) {
539 if(proxyInArg != ourProxy) {
547 std::stringstream ss;
548 ss <<
"Problem when reading RooProduct instance \"" <<
GetName() <<
"\"!\n"
549 <<
" _proxyList[" << idx <<
"] was expected to be equal to " << memberName <<
", but it's not.\n"
550 <<
" - proxyList[" << idx <<
"] : ";
551 proxyInArg->print(ss,
true);
552 ss <<
"\n - " << memberName <<
" : " ;
553 ourProxy->print(ss,
true);
554 ss <<
"\n RooFit will resolve this inconsistency by making _proxyList[" << idx <<
"] point to " << memberName
556 coutW(LinkStateMgmt) << ss.str() << std::endl;
560 expectProxyIs(0, p0, &
_compRSet,
"_compRSet");
561 expectProxyIs(1, p1, &
_compCSet,
"_compCSet");
567std::pair<RPPMIter,RPPMIter> findOverlap2nd(RPPMIter i, RPPMIter end)
570 for (; i != end; ++i) {
571 for (RPPMIter j(i + 1); j != end; ++j) {
572 if (i->second->overlaps(*j->second)) {
573 return std::make_pair(i, j);
577 return std::make_pair(end,end);
581void dump_map(std::ostream& os, RPPMIter i, RPPMIter end)
587 if (first) { first=
false; }
588 else { os <<
" , " ; }
589 os << *(i->first) <<
" -> " << *(i->second) ;
RooCollectionProxy< RooArgList > RooListProxy
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
int Int_t
Signed integer 4 bytes (int).
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.
RooAbsArg()
Default constructor.
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
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
Abstract interface for proxy classes.
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
RooAbsReal()
coverity[UNINIT_CTOR] Default constructor
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.
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.
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.
void setCacheAndTrackHints(RooArgSet &) override
Label OK'ed components of a RooProduct with cache-and-track.
~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.
const char * Data() const
TString & Append(const char *cs)