Skip to content

Commit a0d930c

Browse files
committed
[RF] Format code of RooAbsPdf::syncNormalization()
This is done to fix clang-format failures in the CI. (cherry picked from commit 202843a)
1 parent 55474bb commit a0d930c

File tree

1 file changed

+92
-88
lines changed

1 file changed

+92
-88
lines changed

roofit/roofitcore/src/RooAbsPdf.cxx

Lines changed: 92 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -487,103 +487,107 @@ const RooAbsReal* RooAbsPdf::getNormObj(const RooArgSet* nset, const RooArgSet*
487487
/// For functions that declare to be self-normalized by overloading the
488488
/// selfNormalized() function, a unit normalization is always constructed.
489489

490-
bool RooAbsPdf::syncNormalization(const RooArgSet* nset, bool adjustProxies) const
491-
{
492-
setActiveNormSet(nset);
493-
494-
// Check if data sets are identical
495-
CacheElem* cache = static_cast<CacheElem*>(_normMgr.getObj(nset)) ;
496-
if (cache) {
497-
498-
bool nintChanged = (_norm!=cache->_norm.get()) ;
499-
_norm = cache->_norm.get();
500-
501-
// In the past, this condition read `if (nintChanged && adjustProxies)`.
502-
// However, the cache checks if the nset was already cached **by content**,
503-
// and not by RooArgSet instance! So it can happen that the normalization
504-
// set object is different, but the integral object is the same, in which
505-
// case it would be wrong to not adjust the proxies. They always have to be
506-
// adjusted when the nset changed, which is always the case when
507-
// `syncNormalization()` is called.
508-
if (adjustProxies) {
509-
// Update dataset pointers of proxies
510-
const_cast<RooAbsPdf*>(this)->setProxyNormSet(nset) ;
511-
}
490+
bool RooAbsPdf::syncNormalization(const RooArgSet *nset, bool adjustProxies) const
491+
{
492+
setActiveNormSet(nset);
493+
494+
// Check if data sets are identical
495+
CacheElem *cache = static_cast<CacheElem *>(_normMgr.getObj(nset));
496+
if (cache) {
497+
498+
bool nintChanged = (_norm != cache->_norm.get());
499+
_norm = cache->_norm.get();
500+
501+
// In the past, this condition read `if (nintChanged && adjustProxies)`.
502+
// However, the cache checks if the nset was already cached **by content**,
503+
// and not by RooArgSet instance! So it can happen that the normalization
504+
// set object is different, but the integral object is the same, in which
505+
// case it would be wrong to not adjust the proxies. They always have to be
506+
// adjusted when the nset changed, which is always the case when
507+
// `syncNormalization()` is called.
508+
if (adjustProxies) {
509+
// Update dataset pointers of proxies
510+
const_cast<RooAbsPdf *>(this)->setProxyNormSet(nset);
511+
}
512512

513-
return nintChanged ;
514-
}
513+
return nintChanged;
514+
}
515515

516-
// Update dataset pointers of proxies
517-
if (adjustProxies) {
518-
const_cast<RooAbsPdf*>(this)->setProxyNormSet(nset) ;
519-
}
516+
// Update dataset pointers of proxies
517+
if (adjustProxies) {
518+
const_cast<RooAbsPdf *>(this)->setProxyNormSet(nset);
519+
}
520520

521-
RooArgSet depList;
522-
getObservables(nset, depList);
521+
RooArgSet depList;
522+
getObservables(nset, depList);
523523

524-
if (_verboseEval>0) {
525-
if (!selfNormalized()) {
526-
cxcoutD(Tracing) << ClassName() << "::syncNormalization(" << GetName()
527-
<< ") recreating normalization integral " << std::endl ;
528-
depList.printStream(ccoutD(Tracing),kName|kValue|kArgs,kSingleLine) ;
529-
} else {
530-
cxcoutD(Tracing) << ClassName() << "::syncNormalization(" << GetName() << ") selfNormalized, creating unit norm" << std::endl;
531-
}
532-
}
533-
534-
// Destroy old normalization & create new
535-
if (selfNormalized() || depList.empty()) {
536-
auto ntitle = std::string(GetTitle()) + " Unit Normalization";
537-
auto nname = std::string(GetName()) + "_UnitNorm";
538-
_norm = new RooRealVar(nname.c_str(),ntitle.c_str(),1) ;
539-
} else {
540-
const char* nr = (_normRangeOverride.Length()>0 ? _normRangeOverride.Data() : (_normRange.Length()>0 ? _normRange.Data() : nullptr)) ;
541-
542-
// std::cout << "RooAbsPdf::syncNormalization(" << GetName() << ") rangeName for normalization is " << (nr?nr:"<null>") << std::endl ;
543-
RooAbsReal* normInt;
544-
{
545-
// Normalization is always over all pdf components. Overriding the global
546-
// component selection temporarily makes all RooRealIntegrals created during
547-
// that time always include all components.
548-
GlobalSelectComponentRAII selCompRAII(true);
549-
normInt = std::unique_ptr<RooAbsReal>{createIntegral(depList,*getIntegratorConfig(),nr)}.release();
550-
}
551-
static_cast<RooRealIntegral*>(normInt)->setAllowComponentSelection(false);
552-
normInt->getVal() ;
553-
// std::cout << "resulting normInt = " << normInt->GetName() << std::endl ;
554-
555-
const char* cacheParamsStr = getStringAttribute("CACHEPARAMINT") ;
556-
if (cacheParamsStr && strlen(cacheParamsStr)) {
557-
558-
std::unique_ptr<RooArgSet> intParams{normInt->getVariables()} ;
559-
560-
RooArgSet cacheParams = RooHelpers::selectFromArgSet(*intParams, cacheParamsStr);
561-
562-
if (!cacheParams.empty()) {
563-
cxcoutD(Caching) << "RooAbsReal::createIntObj(" << GetName() << ") INFO: constructing " << cacheParams.size()
564-
<< "-dim value cache for integral over " << depList << " as a function of " << cacheParams << " in range " << (nr?nr:"<default>") << std::endl ;
565-
std::string name = normInt->GetName() + ("_CACHE_[" + cacheParams.contentsString()) + "]";
566-
RooCachedReal* cachedIntegral = new RooCachedReal(name.c_str(),name.c_str(),*normInt,cacheParams) ;
567-
cachedIntegral->setInterpolationOrder(2) ;
568-
cachedIntegral->addOwnedComponents(*normInt) ;
569-
cachedIntegral->setCacheSource(true) ;
570-
if (normInt->operMode()==ADirty) {
571-
cachedIntegral->setOperMode(ADirty) ;
572-
}
573-
normInt= cachedIntegral ;
524+
if (_verboseEval > 0) {
525+
if (!selfNormalized()) {
526+
cxcoutD(Tracing) << ClassName() << "::syncNormalization(" << GetName()
527+
<< ") recreating normalization integral " << std::endl;
528+
depList.printStream(ccoutD(Tracing), kName | kValue | kArgs, kSingleLine);
529+
} else {
530+
cxcoutD(Tracing) << ClassName() << "::syncNormalization(" << GetName()
531+
<< ") selfNormalized, creating unit norm" << std::endl;
574532
}
533+
}
575534

576-
}
577-
_norm = normInt ;
578-
}
535+
// Destroy old normalization & create new
536+
if (selfNormalized() || depList.empty()) {
537+
auto ntitle = std::string(GetTitle()) + " Unit Normalization";
538+
auto nname = std::string(GetName()) + "_UnitNorm";
539+
_norm = new RooRealVar(nname.c_str(), ntitle.c_str(), 1);
540+
} else {
541+
const char *nr = (_normRangeOverride.Length() > 0 ? _normRangeOverride.Data()
542+
: (_normRange.Length() > 0 ? _normRange.Data() : nullptr));
543+
544+
// std::cout << "RooAbsPdf::syncNormalization(" << GetName() << ") rangeName for normalization is " <<
545+
// (nr?nr:"<null>") << std::endl ;
546+
RooAbsReal *normInt;
547+
{
548+
// Normalization is always over all pdf components. Overriding the global
549+
// component selection temporarily makes all RooRealIntegrals created during
550+
// that time always include all components.
551+
GlobalSelectComponentRAII selCompRAII(true);
552+
normInt = std::unique_ptr<RooAbsReal>{createIntegral(depList, *getIntegratorConfig(), nr)}.release();
553+
}
554+
static_cast<RooRealIntegral *>(normInt)->setAllowComponentSelection(false);
555+
normInt->getVal();
556+
// std::cout << "resulting normInt = " << normInt->GetName() << std::endl ;
557+
558+
const char *cacheParamsStr = getStringAttribute("CACHEPARAMINT");
559+
if (cacheParamsStr && strlen(cacheParamsStr)) {
560+
561+
std::unique_ptr<RooArgSet> intParams{normInt->getVariables()};
562+
563+
RooArgSet cacheParams = RooHelpers::selectFromArgSet(*intParams, cacheParamsStr);
564+
565+
if (!cacheParams.empty()) {
566+
cxcoutD(Caching) << "RooAbsReal::createIntObj(" << GetName() << ") INFO: constructing "
567+
<< cacheParams.size() << "-dim value cache for integral over " << depList
568+
<< " as a function of " << cacheParams << " in range " << (nr ? nr : "<default>")
569+
<< std::endl;
570+
std::string name = normInt->GetName() + ("_CACHE_[" + cacheParams.contentsString()) + "]";
571+
RooCachedReal *cachedIntegral = new RooCachedReal(name.c_str(), name.c_str(), *normInt, cacheParams);
572+
cachedIntegral->setInterpolationOrder(2);
573+
cachedIntegral->addOwnedComponents(*normInt);
574+
cachedIntegral->setCacheSource(true);
575+
if (normInt->operMode() == ADirty) {
576+
cachedIntegral->setOperMode(ADirty);
577+
}
578+
normInt = cachedIntegral;
579+
}
580+
}
581+
_norm = normInt;
582+
}
579583

580-
// Register new normalization with manager (takes ownership)
581-
cache = new CacheElem(*_norm) ;
582-
_normMgr.setObj(nset,cache) ;
584+
// Register new normalization with manager (takes ownership)
585+
cache = new CacheElem(*_norm);
586+
_normMgr.setObj(nset, cache);
583587

584-
// std::cout << "making new object " << _norm->GetName() << std::endl ;
588+
// std::cout << "making new object " << _norm->GetName() << std::endl ;
585589

586-
return true ;
590+
return true;
587591
}
588592

589593

0 commit comments

Comments
 (0)