Home | News | Documentation | Download

Module 'ROOT' has no attribute 'TF1'

Hello! I am new at ROOT
I have a problem with PyRoot
I am trying to f1 = ROOT.TF1("f2","[0]*sin([1]*x)x",0.,10.) but I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'ROOT' has no attribute 'TF1'

do you know why and what is the solution?

by the way import ROOT is successfully working

At least:
f1 = ROOT.TF1("f2", "[0]*sin([1]*x)*x", 0., 10.)

Interesting. I seem to be having the same problem

Here’s what I get if I run that:

In [1]: import ROOT

In [2]:  f1 = ROOT.TF1("f2","[0]*sin([1]*x)x",0.,10.)
input_line_34:2:104: error: expected ';' after return statement
Double_t TFormula____id11643295355092022388(Double_t *x,Double_t *p){ return p[0]*TMath::Sin(p[1]*x[0])x[0] ; }
                                                                                                       ^
                                                                                                       ;
input_line_35:2:104: error: expected ';' after return statement
Double_t TFormula____id11643295355092022388(Double_t *x,Double_t *p){ return p[0]*TMath::Sin(p[1]*x[0])x[0] ; }
                                                                                                       ^
                                                                                                       ;
Error in <prepareMethod>: Can't compile function TFormula____id11643295355092022388 prototype with arguments Double_t*,Double_t*
Error in <TFormula::InputFormulaIntoCling>: Error compiling formula expression in Cling
Error in <TFormula::ProcessFormula>: Formula "[p0]*sin([p1]*x)x" is invalid !

I.e. the expression is invalid, as I think @Wile_E_Coyote meant to point out.

Cheers,
Enrico

Ah sorry, I ran f = ROOT.TF1("f1", "sin(x)/x", 0., 10.), it’s from the Example in Interactive graphics for PyROOT and the invalid expression in this post, still got the same error.
So it seems to be something more than just the invalid expression.

Thank you anways.
Cheers

It works if you change "[0]*sin([1]*x)x" to "[0]*sin([1]*x)*x".

The formula from the above did work for me…

What version of ROOT and python do you use? f = ROOT.TF1("f1", "sin(x)/x", 0., 10.) worked for me with ROOT 6.18/04 and python 2.7.16…
You can check with root --version and python --version in terminal

ROOT Version: 6.22/08
Python 3.7.8

That works:

~ root-config --version                                                            (cern-root)
6.22/08
~ python                                                                           (cern-root)
Python 3.9.2 | packaged by conda-forge | (default, Feb 21 2021, 05:02:46)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT; f = ROOT.TF1("f1", "sin(x)/x", 0., 10.)
>>>

There might be something wrong with your environment/installation.

This does not (from ROOT import * rather than import ROOT):

>>> from ROOT import *
>>> ROOT.TF1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: <namespace cppyy.gbl.ROOT at 0x55a259620340> has no attribute 'TF1'. Full details:
  type object 'ROOT' has no attribute 'TF1'
  'ROOT::TF1' is not a known C++ class
  'TF1' is not a known C++ template
  'TF1' is not a known C++ enum
>>>

Figured as much. Probably the environment since the installation was done with the .exe file.

Cheers.

See https://root.cern/install for supported installation methods. Feel free to open a bug report with ROOT or the relevant package manager (conda, homebrew…) in case you believe your installation should just work.

Cheers,
Enrico

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