Skip to content

Commit

Permalink
[RF] Support for RooEfficiency in the RooFit code generation backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhigyan Acherjee authored and guitargeek committed Mar 17, 2024
1 parent 3c1fa5d commit 4b75e2a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
3 changes: 3 additions & 0 deletions roofit/roofitcore/inc/RooEfficiency.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class RooEfficiency : public RooAbsPdf {

Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=nullptr) const override ;
double analyticalIntegral(Int_t code, const char* rangeName=nullptr) const override ;
void translate(RooFit::Detail::CodeSquashContext &ctx) const override;
std::string
buildCallToAnalyticIntegral(Int_t code, const char *rangeName, RooFit::Detail::CodeSquashContext &ctx) const override;

protected:

Expand Down
11 changes: 11 additions & 0 deletions roofit/roofitcore/inc/RooFit/Detail/EvaluateFuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ inline double bifurGaussEvaluate(double x, double mean, double sigmaL, double si
return gaussianEvaluate(x, mean, sigmaR);
}

inline double efficiencyEvaluate(double effFuncVal, int catIndex, int sigCatIndex)
{
// Truncate efficiency function in range 0.0-1.0
effFuncVal = std::clamp(effFuncVal, 0.0, 1.0);

if (catIndex == sigCatIndex)
return effFuncVal; // Accept case
else
return 1 - effFuncVal; // Reject case
}

/// In pdfMode, a coefficient for the constant term of 1.0 is implied if lowestOrder > 0.
template <bool pdfMode = false>
inline double polynomialEvaluate(double const *coeffs, int nCoeffs, int lowestOrder, double x)
Expand Down
52 changes: 18 additions & 34 deletions roofit/roofitcore/src/RooEfficiency.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ F may have an arbitrary number of dependents and parameters
#include "RooStreamParser.h"
#include "RooArgList.h"

#include <RooFit/Detail/EvaluateFuncs.h>

#include "TError.h"

ClassImp(RooEfficiency);
Expand Down Expand Up @@ -71,46 +73,28 @@ RooEfficiency::RooEfficiency(const RooEfficiency& other, const char* name) :

double RooEfficiency::evaluate() const
{
double effFuncVal = _effFunc ;

// Truncate efficiency function in range 0.0-1.0
if (_effFunc>1) {
effFuncVal = 1.0 ;
} else if (_effFunc<0) {
effFuncVal = 0.0 ;
}

if (_cat.label() == _sigCatName) {
// Accept case
return effFuncVal ;
} else {
// Reject case
return 1 - effFuncVal ;
}
const int sigCatIndex = _cat->lookupIndex(_sigCatName.Data());
return RooFit::Detail::EvaluateFuncs::efficiencyEvaluate(_effFunc, _cat, sigCatIndex);
}



////////////////////////////////////////////////////////////////////////////////

Int_t RooEfficiency::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* /*rangeName*/) const
int RooEfficiency::getAnalyticalIntegral(RooArgSet &allVars, RooArgSet &analVars, const char * /*rangeName*/) const
{
if (matchArgs(allVars,analVars,_cat)) return 1 ;
return 0 ;
return matchArgs(allVars, analVars, _cat) ? 1 : 0;
}



////////////////////////////////////////////////////////////////////////////////

double RooEfficiency::analyticalIntegral(Int_t code, const char* /*rangeName*/) const
double RooEfficiency::analyticalIntegral(int /*code*/, const char * /*rangeName*/) const
{
R__ASSERT(code==1) ;
return 1.0 ;
return 1.0;
}

void RooEfficiency::translate(RooFit::Detail::CodeSquashContext &ctx) const
{
int sigCatIndex = _cat->lookupIndex(_sigCatName.Data());
ctx.addResult(this, ctx.buildCall("RooFit::Detail::EvaluateFuncs::efficiencyEvaluate", _effFunc, _cat, sigCatIndex));
}





std::string RooEfficiency::buildCallToAnalyticIntegral(int /*code*/, const char * /*rangeName*/,
RooFit::Detail::CodeSquashContext &) const
{
return "1.0";
}

0 comments on commit 4b75e2a

Please sign in to comment.