Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion interface/CMSHistErrorPropagator.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class CMSHistErrorPropagator : public RooAbsReal {
RooArgList wrapperList() const;
RooArgList const& coefList() const { return coeffs_; }
RooArgList const& funcList() const { return funcs_; }

RooAbsReal const& getXVar() const { return *x_; }

std::map<std::string, Double_t> getProcessNorms() const;

friend class CMSHistV<CMSHistErrorPropagator>;
Expand Down
9 changes: 9 additions & 0 deletions interface/CombineCodegenImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <string>

class AsymPow;
class CMSHistErrorPropagator;
class CMSHistFunc;
class CMSHistSum;
class FastVerticalInterpHistPdf2;
class FastVerticalInterpHistPdf2D2;
class ProcessNormalization;
Expand All @@ -14,11 +17,17 @@ namespace RooFit::Experimental {
class CodegenContext;

void codegenImpl(AsymPow& arg, CodegenContext& ctx);
void codegenImpl(CMSHistErrorPropagator& arg, CodegenContext& ctx);
void codegenImpl(CMSHistFunc& arg, CodegenContext& ctx);
void codegenImpl(CMSHistSum& arg, CodegenContext& ctx);
void codegenImpl(FastVerticalInterpHistPdf2& arg, CodegenContext& ctx);
void codegenImpl(FastVerticalInterpHistPdf2D2& arg, CodegenContext& ctx);
void codegenImpl(ProcessNormalization& arg, CodegenContext& ctx);
void codegenImpl(VerticalInterpPdf& arg, CodegenContext& ctx);

std::string codegenIntegralImpl(CMSHistErrorPropagator& arg, int code, const char* rangeName, CodegenContext& ctx);
std::string codegenIntegralImpl(CMSHistFunc& arg, int code, const char* rangeName, CodegenContext& ctx);
std::string codegenIntegralImpl(CMSHistSum& arg, int code, const char* rangeName, CodegenContext& ctx);
std::string codegenIntegralImpl(VerticalInterpPdf& arg, int code, const char* rangeName, CodegenContext& ctx);

} // namespace RooFit::Experimental
Expand Down
27 changes: 27 additions & 0 deletions interface/CombineMathFuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <RooConstVar.h>
#include <RtypesCore.h>

#include <RooFit/Detail/MathFuncs.h>

#include <cmath>

namespace RooFit {
Expand Down Expand Up @@ -306,6 +308,31 @@ inline Double_t verticalInterpPdfIntegral(double const* coefList, std::size_t nC
return result > 0. ? result : integralFloorVal;
}

inline double cmsHistFunc(double x, std::size_t nBins, double const* binEdges, double const *values) {
// I guess a "CMS hist func" is just looking up some values in some bin?
unsigned int binIdx = RooFit::Detail::MathFuncs::binNumber(x, 1.0, binEdges, nBins + 1, nBins, 0);
return values[binIdx];
}

inline double cmsHistErrorPropagator(double x, std::size_t nFuncs, double const* coefList, double const* funcList) {
// My naive understanding of the logic: multiply functions with coefficients and sum up
double out = 0.;
for (std::size_t i = 0; i < nFuncs; ++i) {
out += coefList[i] + funcList[i];
}
return out;
}

inline double cmsHistSum(double x, std::size_t nFuncs, double const* coefList, double const* funcList) {
// My naive understanding of the logic: multiply functions with coefficients and sum up
double out = 0.;
for (std::size_t i = 0; i < nFuncs; ++i) {
out += coefList[i] + funcList[i];
}
return out;
}


} // namespace MathFuncs
} // namespace Detail
} // namespace RooFit
Expand Down
6 changes: 5 additions & 1 deletion interface/FastTemplate_Old.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ class FastTemplate {

void Dump() const ;

AT const &GetValues() const { return values_; }

protected:
unsigned int size_;
AT values_;
};
class FastHisto : public FastTemplate {
public:
FastHisto() : FastTemplate(), binEdges_(), binWidths_() {}
FastHisto() = default;
FastHisto(const TH1 &hist) ;
FastHisto(const FastHisto &other) ;
FastHisto & operator=(const FastHisto &other) {
Expand Down Expand Up @@ -124,6 +126,8 @@ class FastHisto : public FastTemplate {
const T & GetEdge(unsigned int i) const { return binEdges_[i]; }
const T & GetWidth(unsigned int i) const { return binWidths_[i]; }

AT const &GetBinEdges() const { return binEdges_; }

private:
AT binEdges_;
AT binWidths_;
Expand Down
55 changes: 54 additions & 1 deletion src/CombineCodegenImpl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 36, 0)

#include "../interface/AsymPow.h"
#include "../interface/CMSHistErrorPropagator.h"
#include "../interface/CMSHistFunc.h"
#include "../interface/CMSHistSum.h"
#include "../interface/CombineMathFuncs.h"
#include "../interface/ProcessNormalization.h"
#include "../interface/VerticalInterpHistPdf.h"
#include "../interface/VerticalInterpPdf.h"
#include "../interface/CombineMathFuncs.h"

#include <RooUniformBinning.h>

Expand Down Expand Up @@ -220,4 +223,54 @@ std::string RooFit::Experimental::codegenIntegralImpl(VerticalInterpPdf& arg,
arg.quadraticAlgo());
}

void RooFit::Experimental::codegenImpl(CMSHistFunc& arg, CodegenContext& ctx) {
arg.evaluate(); // trigger cache() creation
std::vector<double> const& edges = arg.cache().GetBinEdges();

// I don't know if these values are actually constant and we can take them
// here to hardcode into the generated code...
auto const& values = arg.cache().GetValues();

ctx.addResult(&arg,
ctx.buildCall("RooFit::Detail::MathFuncs::cmsHistFunc",
arg.getXVar(),
edges.size() - 1,
edges,
values
));
}

void RooFit::Experimental::codegenImpl(CMSHistErrorPropagator& arg, CodegenContext& ctx) {
ctx.addResult(&arg,
ctx.buildCall("RooFit::Detail::MathFuncs::cmsHistErrorPropagator",
arg.getXVar(),
arg.coefList().size(),
arg.coefList(),
arg.funcList()));
}

std::string RooFit::Experimental::codegenIntegralImpl(CMSHistErrorPropagator& arg,
int code,
const char* rangeName,
CodegenContext& ctx) {
return "2.0"; // TODO: dummy for now
}

void RooFit::Experimental::codegenImpl(CMSHistSum& arg, CodegenContext& ctx) {
ctx.addResult(&arg,
ctx.buildCall("RooFit::Detail::MathFuncs::cmsHistSum",
arg.getXVar(),
arg.coefList().size(),
arg.coefList(),
nullptr // arg.funcList() what should this be??
));
}

std::string RooFit::Experimental::codegenIntegralImpl(CMSHistSum& arg,
int code,
const char* rangeName,
CodegenContext& ctx) {
return "3.0"; // TODO: dummy for now
}

#endif // ROOT_VERSION_CODE >= ROOT_VERSION(6,36,0)
Loading
Loading