Hi,
I’m tying to extract fitted histograms from HistFactory workspace, and save them as TH3. I’m doing this because I’m also building fitted histograms based on input templates and shape variations with some external script, and I’d like to check that I build it correctly.
I looked at this question, and it seems that there the suggestions is to use plotOn
, which is not what I’m looking for.
Naively I’d like to use createHistogram
method of, say, PiecewiseInterpolation
, and here’s the gist:
auto obs =
static_cast<RooArgSet *>(mModelHf->getObservables(*mData)->selectByName(
TString("*") + keyword + skim + "*"));
auto x = reinterpret_cast<RooAbsRealLValue *>(
obs->find("obs_x_" + prefix + skim));
auto y = reinterpret_cast<RooCmdArg *>(obs->find("obs_y_" + prefix + skim));
auto z = reinterpret_cast<RooCmdArg *>(obs->find("obs_z_" + prefix + skim));
if (pdf == nullptr) {
auto pdfHist = static_cast<RooHistFunc *>(
mWorkspace->function(pdfName + "_nominal"));
if (pdfHist == nullptr) {
cout << pdfName << " does not exist, continuing" << endl;
continue;
}
histo = reinterpret_cast<TH3F *>(pdfHist->createHistogram(
outputName.c_str(), *x, IntrinsicBinning(), *y, IntrinsicBinning(),
*z, IntrinsicBinning()));
} else {
histo = reinterpret_cast<TH3F *>(
pdf->createHistogram(outputName.c_str(), *x, IntrinsicBinning(), *y,
}
But I get segmentation faults:
*** Break *** segmentation violation
Generating stack trace...
0x00007f7b2730585b in RooArgList::RooArgList(RooAbsArg const&, char const*) + 0x3b from /nix/store/z7xj2hix4nfzagwz2fp4gg3rv6kgbc61-root-6.16.00/lib/libRooFitCore.so
0x00007f7b272d926e in RooAbsReal::createHistogram(char const*, RooAbsRealLValue const&, RooLinkedList&) const + 0x21e from /nix/store/z7xj2hix4nfzagwz2fp4gg3rv6kgbc61-root-6.16.00/lib/libRooFitCore.so
0x00007f7b272da62e in RooAbsReal::createHistogram(char const*, RooAbsRealLValue const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&, RooCmdArg const&) const + 0x11e from /nix/store/z7xj2hix4nfzagwz2fp4gg3rv6kgbc61-root-6.16.00/lib/libRooFitCore.so
0x0000000000421bb1 in ParamExtract::getHistos(TString const&, std::vector<RooStats::HistFactory::Sample, std::allocator<RooStats::HistFactory::Sample> >&, TString const&) + 0xd91 from ./bin/extract_fit_params.exe
0x00000000004223ee in ParamExtract::writeHistos(std::vector<TString, std::allocator<TString> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) + 0x30e from ./bin/extract_fit_params.exe
0x000000000041bd7e in main + 0x11ae from ./bin/extract_fit_params.exe
0x00007f7b26428ded in __libc_start_main + 0xed from /nix/store/adxc893j47gxx3xjw403zdf0liiddvw2-glibc-2.32-48/lib/libc.so.6
0x000000000041c18a in _start at /build/glibc-2.32/csu/../sysdeps/x86_64/start.S:122 from ./bin/extract_fit_params.exe
The full source code is available at here