Error in using Piecewise interpolation function RooFit

Hi,
I’m trying to implement the function PiecewiseInterpolation following the example “include shape systematics” I found in this forum but I get error. Here a snipped of the code

import ROOT
import numpy as np
import globalConstants as ctes
from copy import deepcopy as cp 




# Variables
minv_var = ROOT.RooRealVar("m2inv", "m^{2}_{inv}", -200, 500, "[MeV^{2}]")
minv_var.setBins(ctes.BINS_OBS_MASS)

ang_var = ROOT.RooRealVar("dphi", "#Delta#phi", -2.3, 2.3, "[rad]")
ang_var.setBins(ctes.BINS_OBS_ANG)

inter_sys_minv_Ek = []
inter_sys_minv_Ep = []
inter_sys_minv_Ang = []

pdf_minv = []
pdf_ang = []
pdf_ma = []

for i in range(3):

    name = ctes.NAMES[i]

    # Input file
    inputF = ROOT.TFile(f"{ctes.FILE_PATH}/Histo{name}Fit.root")

    # Histograms from input file
    histo_minv = cp(inputF.Get("himas"))
    histo_minv.Rebin(ctes.BINNING_HISTO_MASS)
    histo_minv.Scale(1./histo_minv.Integral())
        
    histo_ang = cp(inputF.Get("hdphi"))
    histo_ang.Rebin(ctes.BINNING_HISTO_ANG)
    histo_ang.Scale(1./histo_ang.Integral())
    
    histo_ma = cp(inputF.Get("hmass_ang"))
    histo_ma.Rebin2D(ctes.BINNING_HISTO_MASS, ctes.BINNING_HISTO_ANG)
    histo_ma.Scale(1./histo_ma.Integral())

    # RooHist to PDF
    roohist_minv = cp(ROOT.RooDataHist(f"histo_minv_{name}", f"histo_minv_{name}", ROOT.RooArgList(minv_var), histo_minv))
    pdf_minv_one = cp(ROOT.RooHistPdf(f"pdf_minv_{name}", f"pdf_minv_{name}", ROOT.RooArgSet(minv_var), roohist_minv))

    roohist_ang = cp(ROOT.RooDataHist(f"histo_ang_{name}", f"histo_ang_{name}", ROOT.RooArgList(ang_var), histo_ang))
    pdf_ang_one = cp(ROOT.RooHistPdf(f"pdf_ang_{name}", f"pdf_ang_{name}", ROOT.RooArgSet(ang_var), roohist_ang))

    roohist_ma = cp(ROOT.RooDataHist(f"histo_ma_{name}", f"histo_ma_{name}", ROOT.RooArgList(minv_var, ang_var), histo_ma))
    pdf_ma_one = cp(ROOT.RooHistPdf(f"pdf_ma_{name}", f"pdf_ma_{name}", ROOT.RooArgSet(minv_var, ang_var), roohist_ma))

    # Draw and save
    c_mass = ROOT.TCanvas(f"c_minv_{name}", f"c_minv_{name}")
    plot_minv = minv_var.frame()
    pdf_minv_one.plotOn(plot_minv)
    plot_minv.Draw()
    c_mass.SaveAs(f"{ctes.IMMAGINI_PATH}/c_minv_{name}.pdf")

    c_ang = ROOT.TCanvas(f"c_ang_{name}", f"c_ang_{name}")
    plot_ang = ang_var.frame()
    pdf_ang_one.plotOn(plot_ang)
    plot_ang.Draw()
    c_ang.SaveAs(f"{ctes.IMMAGINI_PATH}/c_ang_{name}.pdf")

    #for 2d create histo
    histo_ma_one = roohist_ma.createHistogram(minv_var, ang_var, ctes.BINS_OBS_MASS, ctes.BINS_OBS_ANG, "", f"histo_ma_one_{name}")
    c_ma = ROOT.TCanvas(f"c_ma_{name}", f"c_ma_{name}")
    histo_ma_one.Draw("lego")
    c_ma.SaveAs(f"{ctes.IMMAGINI_PATH}/c_ma_{name}.pdf")

    pdf_minv.append(pdf_minv_one)
    pdf_ang.append(pdf_ang_one)
    pdf_ma.append(pdf_ma_one)

    if ctes.do_sys:
        if i != 2: # only sys for bkg
            if ctes.do_sys_Ek:
                
                histo_minv_sys_Ek_up = cp(inputF.Get("himas_sys_Ek_up"))
                histo_minv_sys_Ek_up.Rebin(ctes.BINNING_HISTO_MASS)
                histo_minv_sys_Ek_up.Scale(1./histo_minv_sys_Ek_up.Integral())

                histo_minv_sys_Ek_low = cp(inputF.Get("himas_sys_Ek_low"))
                histo_minv_sys_Ek_low.Rebin(ctes.BINNING_HISTO_MASS)
                histo_minv_sys_Ek_low.Scale(1./histo_minv_sys_Ek_low.Integral())

                roohist_minv_sys_Ek_up = cp(ROOT.RooDataHist(f"histo_minv_{name}_sys_Ek_up", f"histo_minv_{name}_sys_Ek_up",
                                                            ROOT.RooArgList(minv_var), histo_minv_sys_Ek_up ))
                pdf_minv_sys_Ek_up = cp(ROOT.RooHistPdf(f"pdf_minv_{name}_sys_Ek_up", f"pdf_minv_{name}_sys_Ek_up",
                                                        ROOT.RooArgSet(minv_var), roohist_minv_sys_Ek_up))
                
                roohist_minv_sys_Ek_low = cp(ROOT.RooDataHist(f"histo_minv_{name}_sys_Ek_low", f"histo_minv_{name}_sys_Ek_low",
                                                                ROOT.RooArgList(minv_var), histo_minv_sys_Ek_low ))
                pdf_minv_sys_Ek_low = cp(ROOT.RooHistPdf(f"pdf_minv_{name}_sys_Ek_low", f"pdf_minv_{name}_sys_Ek_low",
                                                            ROOT.RooArgSet(minv_var), roohist_minv_sys_Ek_low))
                
                #c = ROOT.TCanvas()
                #plot = minv_var.frame()
                #pdf_minv_sys_Ek_up.plotOn(plot)
                #pdf_minv_sys_Ek_low.plotOn(plot)
                #plot.Draw()
                #c.SaveAs(f"{ctes.IMMAGINI_PATH}/c_minv_{name}_sys_Ek_up.pdf")
                
                #systematic parameter
                alpha_sys_Ek = ROOT.RooRealVar(f"alpha_{name}_sys_Ek", f"alpha_{name}_sys_Ek", 0, -5, 5)
                inter_sys_Ek = ROOT.PiecewiseInterpolation(f"inter_{name}_Ek", f"inter_{name}_Ek",
                                                            pdf_minv_one, 
                                                            ROOT.RooArgList(pdf_minv_sys_Ek_low),
                                                            ROOT.RooArgList(pdf_minv_sys_Ek_up), 
                                                            ROOT.RooArgList(alpha_sys_Ek))

The error is

Info in <TCanvas::Print>: pdf file immagini//c_minv_RMD.pdf has been created
Info in <TCanvas::Print>: pdf file immagini//c_ang_RMD.pdf has been created
Info in <TCanvas::Print>: pdf file immagini//c_ma_RMD.pdf has been created
cling::DynamicLibraryManager::loadLibrary(): libc4core.so.0.1.9: cannot open shared object file: No such file or directory
Error in <TInterpreter::TCling::AutoLoad>: failure loading library libHistFactory.so for PiecewiseInterpolation
cling::DynamicLibraryManager::loadLibrary(): libc4core.so.0.1.9: cannot open shared object file: No such file or directory
Error in <TInterpreter::TCling::AutoLoad>: failure loading library libHistFactory.so for PiecewiseInterpolation
cling::DynamicLibraryManager::loadLibrary(): libc4core.so.0.1.9: cannot open shared object file: No such file or directory
Error in <TInterpreter::TCling::AutoLoad>: failure loading library libHistFactory.so for PiecewiseInterpolation
cling::DynamicLibraryManager::loadLibrary(): libc4core.so.0.1.9: cannot open shared object file: No such file or directory
Error in <TInterpreter::TCling::AutoLoad>: failure loading library libHistFactory.so for PiecewiseInterpolation
cling::DynamicLibraryManager::loadLibrary(): libc4core.so.0.1.9: cannot open shared object file: No such file or directory
Error in <TInterpreter::TCling::AutoLoad>: failure loading library libHistFactory.so for PiecewiseInterpolation
cling::DynamicLibraryManager::loadLibrary(): libc4core.so.0.1.9: cannot open shared object file: No such file or directory
Error in <AutoloadLibraryMU>: Failed to load library /home/egrandoni/root/lib/libHistFactory.socling JIT session error: Failed to materialize symbols: { (main, { _ZN22PiecewiseInterpolationC1EPKcS1_RK10RooAbsRealRK10RooArgListS7_S7_b }) }
Traceback (most recent call last):
  File "/home/egrandoni/PhD/AnalisiROOFIT/genWS.py", line 120, in <module>
    inter_sys_Ek = ROOT.PiecewiseInterpolation(f"inter_{name}_Ek", f"inter_{name}_Ek",
TypeError: none of the 3 overloaded methods succeeded. Full details:
  PiecewiseInterpolation constructor failed
  PiecewiseInterpolation::PiecewiseInterpolation(const PiecewiseInterpolation& other, const char* name = nullptr) =>
    TypeError: takes at most 2 arguments (6 given)
  PiecewiseInterpolation::PiecewiseInterpolation() =>
    TypeError: takes at most 0 arguments (6 given)

I can’t understand if is a bug in my code or root fails to upload some needed libraries (libHistFactory.so)

Thanks,
Elia

Hi @Elia_Giulio_Grandoni,
thanks for reaching out!

What if you run run a script that only imports the modules, do you still observe this failure?

Cheers,
Monica

Hi @mdessole,
thanks for the fast reply!

I tried to run

import ROOT
from ROOT import PiecewiseInterpolation

and I still get

python libraries_check.py 
cling::DynamicLibraryManager::loadLibrary(): libc4core.so.0.1.9: cannot open shared object file: No such file or directory
Error in <TInterpreter::TCling::AutoLoad>: failure loading library libHistFactory.so for PiecewiseInterpolation
cling::DynamicLibraryManager::loadLibrary(): libc4core.so.0.1.9: cannot open shared object file: No such file or directory
Error in <TInterpreter::TCling::AutoLoad>: failure loading library libHistFactory.so for PiecewiseInterpolation
cling::DynamicLibraryManager::loadLibrary(): libc4core.so.0.1.9: cannot open shared object file: No such file or directory
Error in <TInterpreter::TCling::AutoLoad>: failure loading library libHistFactory.so for PiecewiseInterpolation

There must be a problem with the libraries. Any ideas on how to solve it?

Thanks,
Elia

P.S. I worked through the problem doing the linear interpolation by hand

      # systematic parameter
      alpha_sys_Ek = cp(ROOT.RooRealVar(f"alpha_{name}_sys_Ek", f"alpha_{name}_sys_Ek", 0, -1, 1))
      # Manually implement linear interpolation
      weight_up = cp(ROOT.RooFormulaVar(f"weight_up_{name}_Ek", "(1+@0)/2", ROOT.RooArgList(alpha_sys_Ek)))
      weight_low = cp(ROOT.RooFormulaVar(f"weight_low_{name}_Ek", "(1-@0)/2", ROOT.RooArgList(alpha_sys_Ek)))

      inter_sys_Ek = cp(ROOT.RooAddPdf(f"inter_{name}_Ek", f"inter_{name}_Ek", 
                                    ROOT.RooArgList(pdf_minv_sys_Ek_up, pdf_minv_sys_Ek_low), 
                                    ROOT.RooArgList(weight_up, weight_low)))

Anyway it would be nice to be able to use the PiecewiseInterpolation class…

It looks like you’re missing this library… How did you install ROOT?

I’m not completely sure, but I believe I followed the installation instructions for AlmaLinux system that I found in Root-Cern website . I can try uninstalling and reinstalling it to see if the problem persists. The ROOT version I have installed is the 6.30/02.

Yes, you can try to reinstall it and if the problem persists we can try to dig more into it!

Done and it works…thanks for the help!

Cheers,
Elia