Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RF] RooTruthModel analytical integrals for general integration ranges #14021

Merged
merged 1 commit into from Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion roofit/roofitcore/inc/RooTruthModel.h
Expand Up @@ -39,7 +39,6 @@ class RooTruthModel : public RooResolutionModel {
RooTruthModel(const char *name, const char *title, RooAbsRealLValue& x) ;
RooTruthModel(const RooTruthModel& other, const char* name=nullptr);
TObject* clone(const char* newname) const override { return new RooTruthModel(*this,newname) ; }
~RooTruthModel() override;

Int_t basisCode(const char* name) const override ;

Expand Down
97 changes: 44 additions & 53 deletions roofit/roofitcore/src/RooAbsAnaConvPdf.cxx
Expand Up @@ -467,66 +467,57 @@ Int_t RooAbsAnaConvPdf::getAnalyticalIntegralWN(RooArgSet& allVars,
/// Set \f$ x \f$ must be contained in \f$ v \f$ and set \f$ y \f$ must be contained in \f$ w \f$.
///

double RooAbsAnaConvPdf::analyticalIntegralWN(Int_t code, const RooArgSet* normSet, const char* rangeName) const
double RooAbsAnaConvPdf::analyticalIntegralWN(Int_t code, const RooArgSet *normSet, const char *rangeName) const
{
// WVE needs adaptation to handle new rangeName feature

// Handle trivial passthrough scenario
if (code==0) return getVal(normSet) ;

// Unpack master code
RooArgSet *intCoefSet, *intConvSet, *normCoefSet, *normConvSet ;
_codeReg.retrieve(code-1,intCoefSet,intConvSet,normCoefSet,normConvSet) ;

Int_t index(0) ;
double answer(0) ;

if (normCoefSet==nullptr&&normConvSet==nullptr) {

// Integral over unnormalized function
double integral(0) ;
const TNamed *_rangeName = RooNameReg::ptr(rangeName);
for (auto convArg : _convSet) {
auto conv = static_cast<RooAbsPdf*>(convArg);
double coef = getCoefNorm(index++,intCoefSet,_rangeName) ;
//cout << "coefInt[" << index << "] = " << coef << " " ; intCoefSet->Print("1") ;
if (coef!=0) {
integral += coef* conv->getNormObj(nullptr,intConvSet,_rangeName)->getVal();
cxcoutD(Eval) << "RooAbsAnaConv::aiWN(" << GetName() << ") [" << index-1 << "] integral += " << conv->getNorm(intConvSet) << endl ;
// WVE needs adaptation to handle new rangeName feature

// Handle trivial passthrough scenario
if (code == 0)
return getVal(normSet);

// Unpack master code
RooArgSet *intCoefSet, *intConvSet, *normCoefSet, *normConvSet;
_codeReg.retrieve(code - 1, intCoefSet, intConvSet, normCoefSet, normConvSet);

Int_t index(0);

if (normCoefSet == nullptr && normConvSet == nullptr) {
// Integral over unnormalized function
double integral(0);
const TNamed *rangeNamePtr = RooNameReg::ptr(rangeName);
for (auto *conv : static_range_cast<RooAbsPdf *>(_convSet)) {
double coef = getCoefNorm(index++, intCoefSet, rangeNamePtr);
if (coef != 0) {
const double term = coef * conv->getNormObj(nullptr, intConvSet, rangeNamePtr)->getVal();
integral += term;
cxcoutD(Eval) << "RooAbsAnaConv::aiWN(" << GetName() << ") [" << index - 1 << "] integral += " << term
<< std::endl;
}
}
return integral;
}

}
answer = integral ;

} else {

// Integral over normalized function
double integral(0) ;
double norm(0) ;
const TNamed *_rangeName = RooNameReg::ptr(rangeName);
for (auto convArg : _convSet) {
auto conv = static_cast<RooAbsPdf*>(convArg);

double coefInt = getCoefNorm(index,intCoefSet,_rangeName) ;
//cout << "coefInt[" << index << "] = " << coefInt << "*" << term << " " << (intCoefSet?*intCoefSet:RooArgSet()) << endl ;
if (coefInt!=0) {
double term = conv->getNormObj(nullptr,intConvSet,_rangeName)->getVal();
integral += coefInt*term ;
}
// Integral over normalized function
double integral(0);
double norm(0);
const TNamed *rangeNamePtr = RooNameReg::ptr(rangeName);
for (auto *conv : static_range_cast<RooAbsPdf *>(_convSet)) {

double coefNorm = getCoefNorm(index,normCoefSet) ;
//cout << "coefNorm[" << index << "] = " << coefNorm << "*" << term << " " << (normCoefSet?*normCoefSet:RooArgSet()) << endl ;
if (coefNorm!=0) {
double term = conv->getNormObj(nullptr,normConvSet)->getVal();
norm += coefNorm*term ;
double coefInt = getCoefNorm(index, intCoefSet, rangeNamePtr);
if (coefInt != 0) {
double term = conv->getNormObj(nullptr, intConvSet, rangeNamePtr)->getVal();
integral += coefInt * term;
}

index++ ;
}
answer = integral/norm ;
}
double coefNorm = getCoefNorm(index, normCoefSet);
if (coefNorm != 0) {
double term = conv->getNormObj(nullptr, normConvSet)->getVal();
norm += coefNorm * term;
}

return answer ;
index++;
}
return integral / norm;
}


Expand Down