Hello,
I am trying to export a RooAbsPdf
constructed via BindPdf()
function, which creates a pdf from a custom-defined template IBaseFunctionMultiDimTempl
. But it seems the internal compiler did not manage to interoperate the pdf with compilation error and segfault when I try to dump the workspace. Is there any documentation how I can achieve this goal?
Here is a mini example to reproduce the problem:
#include "SumFunction.h"
#include "RooWorkspace.h"
#include "RooRealVar.h"
#include "TMath.h"
#include "Math/DistFunc.h"
#include "RooTFnBinding.h"
#include "RooFunctorBinding.h"
using namespace RooFit;
int main(int argc, char *argv[]) {
RooRealVar a("a", "a", 0, -10, 10);
RooRealVar b("b", "b", 0, -10, 10);
RooArgList vars(a, b);
// SumFunction is just a simple template with take the summation of two varialbes
SumFunction* test = new SumFunction();
// creating the pdf
RooAbsPdf *testpdf = bindPdf("test", *test, vars);
// creating worksapce
RooWorkspace *ws = new RooWorkspace("w");
ws->import(vars);
ws->import(*testpdf);
ws->writeToFile("workspace.root", kTRUE);
}
I also adde the SumFunction.cpp and SumFunction.h here.
#include "SumFunction.h"
ROOT::Math::IBaseFunctionMultiDimTempl<double>* SumFunction::Clone() const {
return new SumFunction(*this);
}
unsigned int SumFunction::NDim() const {
return 2;
}
double SumFunction::DoEval(const double *x) const {
return x[0] + x[1];
}
#include <Math/IFunction.h>
class SumFunction : public ROOT::Math::IBaseFunctionMultiDimTempl<double> {
public:
SumFunction() = default;
bool HasGradient() const override{
return false;
}
// Clone method for copying functions
virtual ROOT::Math:: IBaseFunctionMultiDimTempl<double>* Clone() const override;
virtual unsigned int NDim() const override;
// Destructor
~SumFunction() = default;
private:
virtual double DoEval(const double *x) const override;
};
Many thanks,
Huacheng
PS: when I run this code I got warnings like:
Warning in <TBufferFile::WriteObjectAny>: An object of type 11SumFunction (from type_info) passed through a ROOT::Math::IBaseFunctionMultiDimTempl<double> pointer was truncated (due a missing dictionary)!!!
Warning in <TStreamerInfo::WriteBuffer>: The actual class of RooFunctorPdfBinding::func is not available. Only the "ROOT::Math::IBaseFunctionMultiDimTempl<double>" part will be written
_ROOT Version: 6.30.02
Platform: linuxx8664gcc
Compiler: GCC 13.1.0