TGraphAsymmErrors in PyROOT

I am trying to do a TGraphAsymmErrors and I am experiencing difficulties. In C++ you can pass arrays into the arguments but python does not seem to like that. What do I do?

   minustwosigma = []
   plustwosigma = []
   median = []
   minusonesigma = []
   plusonesigma = []

are the arrays that I am filling later on. Then after filling them I am writing:

expectedband = TGraphAsymmErrors(len(median),massarray, median, 0,0 minusonesigmaar ,plustwosigmaar)

I read on Stackoverflow if you put np,array in your argument of TGraphAsymmErrors it fixes it, but it does not.

here is my error:

 File "getLimits.py", line 152, in BrazilFlagPlot
    expectedband = r.TGraphAsymmErrors(len(medianar),np.array(massarray),np.array(medianar),np.array(0),np.array(0),np.array(minusonesigmaar),np.array(plustwosigmaar))
TypeError: none of the 9 overloaded methods succeeded. Full details:
  TGraphAsymmErrors::TGraphAsymmErrors() =>
    takes at most 0 arguments (7 given)
  TGraphAsymmErrors::TGraphAsymmErrors(int n) =>
    takes at most 1 arguments (7 given)
  TGraphAsymmErrors::TGraphAsymmErrors(const TVectorT<float>& vx, const TVectorT<float>& vy, const TVectorT<float>& vexl, const TVectorT<float>& vexh, const TVectorT<float>& veyl, const TVectorT<float>& veyh) =>
    takes at most 6 arguments (7 given)
  TGraphAsymmErrors::TGraphAsymmErrors(const TVectorT<double>& vx, const TVectorT<double>& vy, const TVectorT<double>& vexl, const TVectorT<double>& vexh, const TVectorT<double>& veyl, const TVectorT<double>& veyh) =>
    takes at most 6 arguments (7 given)
  TGraphAsymmErrors::TGraphAsymmErrors(const TGraphAsymmErrors& gr) =>
    takes at most 1 arguments (7 given)
  TGraphAsymmErrors::TGraphAsymmErrors(const TH1* h) =>
    takes at most 1 arguments (7 given)
  TGraphAsymmErrors::TGraphAsymmErrors(const TH1* pass, const TH1* total, const char* option = "") =>
    takes at most 3 arguments (7 given)
  TGraphAsymmErrors::TGraphAsymmErrors(int n, const float* x, const float* y, const float* exl = 0, const float* exh = 0, const float* eyl = 0, const float* eyh = 0) =>
    could not convert argument 2 ('numpy.ndarray' object has no attribute 'typecode' and given element size (8) do not match needed (4))
  TGraphAsymmErrors::TGraphAsymmErrors(int n, const double* x, const double* y, const double* exl = 0, const double* exh = 0, const double* eyl = 0, const double* eyh = 0) =>
    could not convert argument 3 ('numpy.ndarray' object has no attribute 'typecode' and given element size (14) do not match needed (8))

if I try to change it according to: https://root.cern/doc/master/gerrors_8py_source.html

I get:
minustwosigma = array.array(ā€˜dā€™, minustwosigmaar)
TypeError: a float is required

Hi,

I guess you want to call this overload?

  TGraphAsymmErrors::TGraphAsymmErrors(int n, const double* x, const double* y, const double* exl = 0, const double* exh = 0, const double* eyl = 0, const double* eyh = 0) =>

Then every const double* parameter needs to be either a numpy array or an array.array of doubles. The conversion of Python list to double* is not allowed.

For example, you can create a numpy array of doubles like this:

import numpy as np
a = np.array([1.,2.], dtype='double')

If you create your minustwosigma and other parameters like this, the call should succeed.

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