46 typedef RooProduct::ProdMap::iterator RPPMIter ;
47 std::pair<RPPMIter,RPPMIter> findOverlap2nd(RPPMIter i, RPPMIter end) ;
48 void dump_map(ostream& os, RPPMIter i, RPPMIter end) ;
78 _compRSet(
"!compRSet",
"Set of real product components",this),
79 _compCSet(
"!compCSet",
"Set of category product components",this),
82 for (
auto comp : prodSet) {
98 _compRSet(
"!compRSet",this,other._compRSet),
99 _compCSet(
"!compCSet",this,other._compCSet),
100 _cacheMgr(other._cacheMgr,this)
114 coutE(InputArguments) <<
"RooProduct::addTerm(" <<
GetName() <<
") ERROR: component " << term->
GetName()
115 <<
" is not of type RooAbsReal or RooAbsCategory" << endl ;
116 throw std::invalid_argument(
"RooProduct can only handle terms deriving from RooAbsReal or RooAbsCategory.");
130 for (
auto const* rcomp : static_range_cast<RooAbsReal*>(
_compRSet)) {
132 depends = rcomp->dependsOn(dep);
150 for (
auto const* rcomp : static_range_cast<RooAbsReal*>(
_compRSet)) {
151 if( !rcomp->dependsOn(allVars) ) indep->
add(*rcomp);
154 map->push_back( std::make_pair(
new RooArgSet(),indep) );
160 for (
auto const* var : static_range_cast<RooAbsReal*>(allVars)) {
164 for (
auto const* rcomp2 : static_range_cast<RooAbsReal*>(
_compRSet)) {
165 if( rcomp2->dependsOn(*var) ) comps->
add(*rcomp2);
167 map->push_back( std::make_pair(vars,comps) );
173 std::pair<ProdMap::iterator,ProdMap::iterator> i = findOverlap2nd(map->begin(),map->end());
174 overlap = (i.first!=i.second);
176 i.first->first->add(*i.second->first);
179 for (
auto const* targ : *(i.second->second)) {
180 if (!i.first->second->find(*targ)) {
181 i.first->second->add(*targ) ;
186 delete i.second->first;
187 delete i.second->second;
188 map->erase(i.second);
195 int nVar=0;
int nFunc=0;
196 for (ProdMap::iterator i = map->begin();i!=map->end();++i) {
197 nVar+=i->first->getSize();
198 nFunc+=i->second->getSize();
200 assert(nVar==allVars.
getSize());
217 Int_t sterileIndex(-1);
226 cxcoutD(Integration) <<
"RooProduct::getPartIntList(" <<
GetName() <<
") groupProductTerms returned map" ;
227 if (
dologD(Integration)) {
228 dump_map(
ccoutD(Integration),map->begin(),map->end());
229 ccoutD(Integration) << endl;
235 for (ProdMap::iterator iter = map->begin() ; iter != map->end() ; ++iter) {
237 delete iter->second ;
244 for (ProdMap::const_iterator i = map->begin();i!=map->end();++i) {
246 if (i->second->getSize()>1) {
248 auto ownedTerm = std::make_unique<RooProduct>(
name,
name,*i->second);
249 term = ownedTerm.get();
251 cxcoutD(Integration) <<
"RooProduct::getPartIntList(" <<
GetName() <<
") created subexpression " << term->
GetName() << endl;
253 assert(i->second->getSize()==1);
254 term =
static_cast<RooAbsReal*
>(i->second->at(0));
257 if (i->first->empty()) {
259 cxcoutD(Integration) <<
"RooProduct::getPartIntList(" <<
GetName() <<
") adding simple factor " << term->
GetName() << endl;
261 std::unique_ptr<RooAbsReal> integral{term->
createIntegral(*i->first,isetRange)};
263 cxcoutD(Integration) <<
"RooProduct::getPartIntList(" <<
GetName() <<
") adding integral for " << term->
GetName() <<
" : " << integral->GetName() << endl;
270 cxcoutD(Integration) <<
"RooProduct::getPartIntList(" <<
GetName() <<
") created list " << cache->
_prodList <<
" with code " << code+1 << endl
271 <<
" for iset=" << *iset <<
" @" << iset <<
" range: " << (isetRange?isetRange:
"<none>") << endl ;
273 for (ProdMap::iterator iter = map->begin() ; iter != map->end() ; ++iter) {
275 delete iter->second ;
286 const char* rangeName)
const
293 assert(analVars.
empty());
294 analVars.
add(allVars) ;
327 for (
const auto arg : partIntList) {
328 const auto term =
static_cast<const RooAbsReal*
>(arg);
329 double x = term->getVal();
344 for (
auto const* arg : terms) {
347 pname.
Append(arg->GetName());
363 auto rcomp =
static_cast<const RooAbsReal*
>(item);
365 prod *= rcomp->getVal(nset) ;
371 prod *= ccomp->getCurrentIndex() ;
380 for (
unsigned int i = 0; i < nEvents; ++i) {
385 auto rcomp =
static_cast<const RooAbsReal*
>(item);
386 auto componentValues = dataMap.
at(rcomp);
388 for (
unsigned int i = 0; i < nEvents; ++i) {
389 output[i] *= componentValues.size() == 1 ? componentValues[0] : componentValues[i];
397 for (
unsigned int i = 0; i < nEvents; ++i) {
410 auto func =
static_cast<const RooAbsReal*
>(item);
428 auto func =
static_cast<const RooAbsReal*
>(item);
430 if (func->dependsOn(obs) && !func->isBinnedDistribution(obs)) {
446 auto func =
static_cast<const RooAbsReal*
>(item);
485 for (
const auto parg : comp) {
486 if (parg->isDerived()) {
487 if (parg->canNodeBeCached()==
Always) {
488 trackNodes.
add(*parg) ;
508 if (!
first) { os <<
" * " ; }
else {
first = false ; }
509 os << rcomp->GetName() ;
515 if (!
first) { os <<
" * " ; }
else {
first = false ; }
516 os << ccomp->GetName() ;
527 throw std::runtime_error(
"RooProduct::ioStreamerPass2(): the number of proxies in the proxy list should be at leat 2!");
547 auto expectProxyIs = [
this](std::size_t idx,
RooAbsProxy * proxyInArg,
RooListProxy * ourProxy,
const char* memberName) {
548 if(proxyInArg != ourProxy) {
556 std::stringstream ss;
557 ss <<
"Problem when reading RooProduct instance \"" <<
GetName() <<
"\"!\n"
558 <<
" _proxyList[" << idx <<
"] was expected to be equal to " << memberName <<
", but it's not.\n"
559 <<
" - proxyList[" << idx <<
"] : ";
560 proxyInArg->print(ss,
true);
561 ss <<
"\n - " << memberName <<
" : " ;
562 ourProxy->print(ss,
true);
563 ss <<
"\n RooFit will resolve this inconsistency by making _proxyList[" << idx <<
"] point to " << memberName
565 coutW(LinkStateMgmt) << ss.str() << std::endl;
569 expectProxyIs(0, p0, &
_compRSet,
"_compRSet");
570 expectProxyIs(1, p1, &
_compCSet,
"_compCSet");
576std::pair<RPPMIter,RPPMIter> findOverlap2nd(RPPMIter i, RPPMIter end)
579 for (; i!=end; ++i)
for ( RPPMIter j(i+1); j!=end; ++j) {
580 if (i->second->overlaps(*j->second)) {
581 return std::make_pair(i,j);
584 return std::make_pair(end,end);
588void dump_map(ostream& os, RPPMIter i, RPPMIter end)
595 else { os <<
" , " ; }
596 os << *(i->first) <<
" -> " << *(i->second) ;
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
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.
RooAbsCacheElement is the abstract base class for objects to be stored in RooAbsCache cache manager o...
A space to attach TBranches.
virtual value_type getCurrentIndex() const
Return index number of current state.
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.
RooAbsArg * first() const
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
RooAbsProxy is the abstact interface for proxy classes.
const RooArgSet * nset() const
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
virtual std::list< double > * binBoundaries(RooAbsRealLValue &obs, double xlo, double xhi) const
Retrieve bin boundaries if this distribution is binned in obs.
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...
bool _forceNumInt
Force numerical integration if flag set.
virtual std::list< double > * plotSamplingHint(RooAbsRealLValue &obs, double xlo, double xhi) const
Interface for returning an optional hint for initial sampling points when constructing a curve projec...
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 contatining the objects that are both in the cached set 2.
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...
RooSpan< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
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.
A RooProduct 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.
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
The cache manager.
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
void computeBatch(cudaStream_t *, double *output, size_t nEvents, RooFit::Detail::DataMap const &) const override
Base function for computing multiple values of a RooAbsReal.
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)