47 ClassImp(RooAddition);
53 RooAddition::RooAddition()
66 RooAddition::RooAddition(
const char* name,
const char* title,
const RooArgList& sumSet, Bool_t takeOwnership)
67 : RooAbsReal(name, title)
68 , _set(
"!set",
"set of components",this)
71 for (
const auto comp : sumSet) {
72 if (!dynamic_cast<RooAbsReal*>(comp)) {
73 coutE(InputArguments) <<
"RooAddition::ctor(" << GetName() <<
") ERROR: component " << comp->GetName()
74 <<
" is not of type RooAbsReal" << endl ;
75 RooErrorHandler::softAbort() ;
78 if (takeOwnership) _ownedList.addOwned(*comp) ;
99 RooAddition::RooAddition(
const char* name,
const char* title,
const RooArgList& sumSet1,
const RooArgList& sumSet2, Bool_t takeOwnership)
100 : RooAbsReal(name, title)
101 , _set(
"!set",
"set of components",this)
104 if (sumSet1.getSize() != sumSet2.getSize()) {
105 coutE(InputArguments) <<
"RooAddition::ctor(" << GetName() <<
") ERROR: input lists should be of equal length" << endl ;
106 RooErrorHandler::softAbort() ;
109 for (
unsigned int i = 0; i < sumSet1.size(); ++i) {
110 const auto comp1 = &sumSet1[i];
111 const auto comp2 = &sumSet2[i];
113 if (!dynamic_cast<RooAbsReal*>(comp1)) {
114 coutE(InputArguments) <<
"RooAddition::ctor(" << GetName() <<
") ERROR: component " << comp1->GetName()
115 <<
" in first list is not of type RooAbsReal" << endl ;
116 RooErrorHandler::softAbort() ;
119 if (!dynamic_cast<RooAbsReal*>(comp2)) {
120 coutE(InputArguments) <<
"RooAddition::ctor(" << GetName() <<
") ERROR: component " << comp2->GetName()
121 <<
" in first list is not of type RooAbsReal" << endl ;
122 RooErrorHandler::softAbort() ;
127 _name.Append(comp1->GetName());
128 _name.Append(
"_x_");
129 _name.Append(comp2->GetName());
131 RooProduct *prod =
new RooProduct( _name, _name , RooArgSet(*comp1, *comp2) ) ;
133 _ownedList.addOwned(*prod) ;
135 _ownedList.addOwned(*comp1) ;
136 _ownedList.addOwned(*comp2) ;
146 RooAddition::RooAddition(
const RooAddition& other,
const char* name)
147 : RooAbsReal(other, name)
148 , _set(
"!set",this,other._set)
149 , _cacheMgr(other._cacheMgr,this)
157 RooAddition::~RooAddition()
165 Double_t RooAddition::evaluate()
const
168 const RooArgSet* nset = _set.nset() ;
172 for (
const auto arg : _set) {
173 const auto comp =
static_cast<RooAbsReal*
>(arg);
174 const Double_t tmp = comp->getVal(nset);
192 Double_t RooAddition::defaultErrorLevel()
const
194 RooAbsReal* nllArg(0) ;
195 RooAbsReal* chi2Arg(0) ;
199 RooArgSet* comps = getComponents() ;
200 TIterator* iter = comps->createIterator() ;
201 while((arg=(RooAbsArg*)iter->Next())) {
202 if (dynamic_cast<RooNLLVar*>(arg)) {
203 nllArg = (RooAbsReal*)arg ;
205 if (dynamic_cast<RooChi2Var*>(arg)) {
206 chi2Arg = (RooAbsReal*)arg ;
212 if (nllArg && !chi2Arg) {
213 coutI(Fitting) <<
"RooAddition::defaultErrorLevel(" << GetName()
214 <<
") Summation contains a RooNLLVar, using its error level" << endl ;
215 return nllArg->defaultErrorLevel() ;
216 }
else if (chi2Arg && !nllArg) {
217 coutI(Fitting) <<
"RooAddition::defaultErrorLevel(" << GetName()
218 <<
") Summation contains a RooChi2Var, using its error level" << endl ;
219 return chi2Arg->defaultErrorLevel() ;
220 }
else if (!nllArg && !chi2Arg) {
221 coutI(Fitting) <<
"RooAddition::defaultErrorLevel(" << GetName() <<
") WARNING: "
222 <<
"Summation contains neither RooNLLVar nor RooChi2Var server, using default level of 1.0" << endl ;
224 coutI(Fitting) <<
"RooAddition::defaultErrorLevel(" << GetName() <<
") WARNING: "
225 <<
"Summation contains BOTH RooNLLVar and RooChi2Var server, using default level of 1.0" << endl ;
234 void RooAddition::enableOffsetting(Bool_t flag)
236 for (
auto arg : _set) {
237 static_cast<RooAbsReal*
>(arg)->enableOffsetting(flag) ;
245 Bool_t RooAddition::setData(RooAbsData& data, Bool_t cloneData)
247 for (
const auto arg : _set) {
248 static_cast<RooAbsReal*
>(arg)->setData(data,cloneData) ;
257 void RooAddition::printMetaArgs(ostream& os)
const
259 Bool_t first(kTRUE) ;
260 for (
const auto arg : _set) {
266 os << arg->GetName() ;
273 Int_t RooAddition::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars,
const char* rangeName)
const
276 analVars.add(allVars);
279 Int_t sterileIndex(-1);
280 CacheElem* cache = (CacheElem*) _cacheMgr.getObj(&analVars,&analVars,&sterileIndex,RooNameReg::ptr(rangeName));
282 Int_t code = _cacheMgr.lastIndex();
287 cache =
new CacheElem;
288 for (
const auto arg : _set) {
289 RooAbsReal *I =
static_cast<const RooAbsReal*
>(arg)->createIntegral(analVars,rangeName);
290 cache->_I.addOwned(*I);
293 Int_t code = _cacheMgr.setObj(&analVars,&analVars,(RooAbsCacheElement*)cache,RooNameReg::ptr(rangeName));
300 Double_t RooAddition::analyticalIntegral(Int_t code,
const char* rangeName)
const
303 CacheElem *cache = (CacheElem*) _cacheMgr.getObjByIndex(code-1);
306 std::unique_ptr<RooArgSet> vars( getParameters(RooArgSet()) );
307 std::unique_ptr<RooArgSet> iset( _cacheMgr.nameSet2ByIndex(code-1)->select(*vars) );
309 Int_t code2 = getAnalyticalIntegral(*iset,dummy,rangeName);
311 return analyticalIntegral(code2,rangeName);
317 for (
auto I : cache->_I) {
318 result +=
static_cast<const RooAbsReal*
>(I)->getVal();
328 std::list<Double_t>* RooAddition::binBoundaries(RooAbsRealLValue& obs, Double_t xlo, Double_t xhi)
const
330 std::list<Double_t>* sumBinB = 0 ;
331 Bool_t needClean(kFALSE) ;
333 RooFIter iter = _set.fwdIterator() ;
336 while((func=(RooAbsReal*)iter.next())) {
338 std::list<Double_t>* funcBinB = func->binBoundaries(obs,xlo,xhi) ;
347 std::list<Double_t>* newSumBinB =
new std::list<Double_t>(sumBinB->size()+funcBinB->size()) ;
350 merge(funcBinB->begin(),funcBinB->end(),sumBinB->begin(),sumBinB->end(),newSumBinB->begin()) ;
355 sumBinB = newSumBinB ;
363 std::list<Double_t>::iterator new_end = unique(sumBinB->begin(),sumBinB->end()) ;
364 sumBinB->erase(new_end,sumBinB->end()) ;
372 Bool_t RooAddition::isBinnedDistribution(
const RooArgSet& obs)
const
376 RooFIter iter = _set.fwdIterator() ;
378 while((func=(RooAbsReal*)iter.next())) {
379 if (func->dependsOn(obs) && !func->isBinnedDistribution(obs)) {
392 std::list<Double_t>* RooAddition::plotSamplingHint(RooAbsRealLValue& obs, Double_t xlo, Double_t xhi)
const
394 std::list<Double_t>* sumHint = 0 ;
395 Bool_t needClean(kFALSE) ;
397 RooFIter iter = _set.fwdIterator() ;
400 while((func=(RooAbsReal*)iter.next())) {
402 std::list<Double_t>* funcHint = func->plotSamplingHint(obs,xlo,xhi) ;
413 std::list<Double_t>* newSumHint =
new std::list<Double_t>(sumHint->size()+funcHint->size()) ;
416 merge(funcHint->begin(),funcHint->end(),sumHint->begin(),sumHint->end(),newSumHint->begin()) ;
420 sumHint = newSumHint ;
428 std::list<Double_t>::iterator new_end = unique(sumHint->begin(),sumHint->end()) ;
429 sumHint->erase(new_end,sumHint->end()) ;
440 RooArgList RooAddition::CacheElem::containedArgs(Action)
446 RooAddition::CacheElem::~CacheElem()