Get Quantiles using PyROOT

The main goal is that when I am trying to make use of the GetQuantiles method, I do not know how to pass the pointers needed by the method.

import matplotlib.pyplot as plt
import numpy as np
import sys, os
from scipy.interpolate import interp1d
import matplotlib.colors as colors
import matplotlib.cm as cmx  # Colormap
import seaborn as sns

from root_numpy import root2array, tree2array
import root_numpy as rnpy
import ROOT
import h5py

...


fname = 'ts_dist_log_l70_b100_ch0_mass' + str(m) + '.root'
fInp = ROOT.TFile(path + fname)
    
histBG = fInp.Get('hTS_0')
prob=0.5
y=0.
q=0.    
y=histBG.GetQuantiles(1,q,prob)

But I get this error.

TypeError                                 Traceback (most recent call last)
<ipython-input-34-b618e70e1565> in <module>()
     33     q=0.
     34 
---> 35     y=histBG.GetQuantiles(1,q,prob)
     36 
     37     print(histBG.Integral())

TypeError: int TH1::GetQuantiles(int nprobSum, double* q, const double* probSum = 0) =>
    could not convert argument 2

So… How I have to pass this arguments to that function?


_ROOT Version: 6.14/04
Platform: Linux MInt 19, Kernel 4.15.0-50
Compiler: 7.4.0
_Python Version: 2.7
___Preformatted text

Ok, I think I found the solution.
What I did was the following:

histBG = fInp.Get('hTS_0')
prob=np.array([0.5])
y=0.
q=np.array([0.])
y=histBG.GetQuantiles(1,q,prob)

And problem solved.

1 Like

Yes the solution is correct, a numpy array is an allowed conversion to double* (you could also do it with an array.array).

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.