A problem in ROOT 6 with PyRoot

Hi,

this is a general issue and not a PyROOT one: ROOT is unable to find the headers where TRootLHEFParticle is defined even though a dictionary for it has been loaded. ROOT6 needs these headers to be able to interactively call the symbols defined in the libExRootAnalysis.so library.
If you relocated the madgraph directory where these headers are present, you can make sure the ROOT_INCLUDE_PATH points to the right header location.

Cheers,
Danilo

[quote=“dpiparo”]Hi,

this is a general issue and not a PyROOT one: ROOT is unable to find the headers where TRootLHEFParticle is defined even though a dictionary for it has been loaded. ROOT6 needs these headers to be able to interactively call the symbols defined in the libExRootAnalysis.so library.
If you relocated the madgraph directory where these headers are present, you can make sure the ROOT_INCLUDE_PATH points to the right header location.

Cheers,
Danilo[/quote]

Hi Danilo,
Thanks for your explanation, in my code, I have used gSystem.Load(’…’) to include the .so file. So you mean that I need to tell the .h head file to ROOT 6 myself? To edit the ROOT_INCLUDE_PATH ? Or using AddIncludePath ? Like gSystem.AddIncludePath(“the path of the head file”) ? Because in ROOT 5 , it seems that I don’t need to tell ROOT the head file location.

Best,
Li

Hi Li,

indeed ROOT5 works very differently than ROOT6. In ROOT5 dictionaries include trampolines to call the symbols in the libraries while in ROOT6, thanks to the Cling interpreter, those can be called directly.
The requirement for this is that the interpreter “knows” about these symbols, i.e. parsed the necessary header files.
So I would say you have, among the others, two possibilities:

  1. If it’s juts one file you can include it directly
  2. You set the ROOT_INCLUDE_PATH to point to the location of the headers

Cheers,
Danilo

[quote=“dpiparo”]Hi Li,

indeed ROOT5 works very differently than ROOT6. In ROOT5 dictionaries include trampolines to call the symbols in the libraries while in ROOT6, thanks to the Cling interpreter, those can be called directly.
The requirement for this is that the interpreter “knows” about these symbols, i.e. parsed the necessary header files.
So I would say you have, among the others, two possibilities:

  1. If it’s juts one file you can include it directly
  2. You set the ROOT_INCLUDE_PATH to point to the location of the headers

Cheers,
Danilo[/quote]

Thanks for your patient. But I still confused:

  1. If I use a C++ code, so it’s easy for me to use #include"…" to include the file, but for a python code, I don’t know how to include a c++ head file. And I think sometimes, this head file may include other files, so include a single file seems unstable.

  2. I find “TRootLHEFParticle” in

In this file:

#include "TRef.h"
#include "TObject.h"
#include "TRefArray.h"

#include "TMath.h"

......

class TRootLHEFParticle: public TSortableObject
{
public:

  Int_t PID; // particle HEP ID number | hepup.IDUP[number]
  Int_t Status; // particle status code | hepup.ISTUP[number]
  Int_t Mother1; // index for the particle first mother | hepup.MOTHUP[number][0]
  Int_t Mother2; // index for the particle last mother | hepup.MOTHUP[number][1]
  Int_t ColorLine1; // index for the particle color-line | hepup.ICOLUP[number][0]
  Int_t ColorLine2; // index for the particle anti-color-line | hepup.ICOLUP[number][1]
  
  ....

So I think I can add the path like this:

[code]gSystem.AddIncludePath(’/Users/li/tools/packages/ExRootAnalysis/ExRootAnalysis’)

print ’ the path is : ', gSystem.GetIncludePath()
[/code]

I did so but it didn’t solve my problem,

lis-MacBook-Pro:analysis li$ python analysis_parton.py the path is : -I$ROOTSYS/include /Users/li/tools/packages/ExRootAnalysis/ExRootAnalysis -I"/Users/li/tools/root/etc" -I"/Users/li/tools/root/include" -I"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1" -I"/Users/li/tools/root/etc/cling" -I"/Users/li/tools/root" -I"/Users/li/tools/root/" There are 10000 events Error in <TClass::LoadClassInfo>: no interpreter information for class TRootLHEFParticle is available even though it has a TClass initialization routine. analysis_parton.py:25: RuntimeWarning: failed offset calculation between TObject and TRootLHEFParticle quarks=[particle for particle in event.Particle if (particle.Status==1 and abs(particle.PID)<6)] Traceback (most recent call last): File "analysis_parton.py", line 25, in <module> quarks=[particle for particle in event.Particle if (particle.Status==1 and abs(particle.PID)<6)] AttributeError: 'TObject' object has no attribute 'Status'

You may see that I have add the path of the head file but it seem I have something wrong.

Best,
Li

Hi Li,

you can explicitly inject the header in the interpreter with

ROOT.gInterpreter.Declare('#include "myheader"')

This is compulsory if you do not have rootmaps for your classes, i.e. a mechanism to trigger the automatic loading of the libraries where they reside. If you want the above syntax is the one which corresponds for the interfaces to “gSystem.Load” in your code.
How did you generate the dictionary for the TRootLHEFParticle class (command)?

Danilo

[quote=“dpiparo”]Hi Li,

you can explicitly inject the header in the interpreter with

ROOT.gInterpreter.Declare('#include "myheader"')

This is compulsory if you do not have rootmaps for your classes, i.e. a mechanism to trigger the automatic loading of the libraries where they reside. If you want the above syntax is the one which corresponds for the interfaces to “gSystem.Load” in your code.
How did you generate the dictionary for the TRootLHEFParticle class (command)?

Danilo[/quote]

Hi Danilo,
Thanks a lot, it really works.

But it seems a little troublesome, because now I need to find the necessary head file myself. And I don’t know why using AddIncludePath con not work.

In fact I don’t know “rootmap” or “generate the dictionary” , so I can not answer you. I just use MadGraph to generate a lhe file, and install a ExRootAnalysis, then there is a ExRootLHEConverter executable file to convert the lhe file to a root file. ( So it seems I am write a file base on ROOT Event class to convert lhe file to root file instead exRootAnalysis , so I don’t need to worry about the head file)

Finally, it seems if I want to write other code that related to external libraries, like PYTHIA8 , Delphes… I need to do in the same way. Am I right?

Hi,

Indeed, #including the header (w.g. through ROOT.gInterpreter.Declare(’#include “ThatHeader.h”’) is the preferred option for ROOT 6, as Danilo explains.

We know this is annoying and we will make this simpler in the future, but that will still take a bit (the keyword to look out for here is “modules” or “PCMs”).

Cheers, Axel.

[quote=“Axel”]Hi,

Indeed, #including the header (w.g. through ROOT.gInterpreter.Declare(’#include “ThatHeader.h”’) is the preferred option for ROOT 6, as Danilo explains.

We know this is annoying and we will make this simpler in the future, but that will still take a bit (the keyword to look out for here is “modules” or “PCMs”).

Cheers, Axel.[/quote]

Hi Axel,
Thanks a lot for your explanation!

Best,
Li

Hi,

I’m facing the same exact issue, but the solution proposed does not help. I did gInterpreter.Declare(’#include “/full/path/ExRootClasses.h”’)

But I still get the error:

Error in <TClass::LoadClassInfo>: no interpreter information for class TRootLHEFParticle is available even though it has a TClass initialization routine.
and then, later when I try to access a particle:

Any other suggestion to try?

I run ROOT 6.06/01 from afs on SLC6 at cern.

Thanks,
Andrey

[quote=“Andrey Pozdnyakov”]Hi,

I’m facing the same exact issue, but the solution proposed does not help. I did gInterpreter.Declare(’#include “/full/path/ExRootClasses.h”’)

But I still get the error:

Error in <TClass::LoadClassInfo>: no interpreter information for class TRootLHEFParticle is available even though it has a TClass initialization routine.
and then, later when I try to access a particle:

Any other suggestion to try?

I run ROOT 6.06/01 from afs on SLC6 at cern.

Thanks,
Andrey[/quote]

Hi,

Maybe you can solve this by using AddIncludePath (when your problem came from the miss of head files path), like: root.cern.ch/doc/master/classTInterpreter.html

Best,
Li

Hi,

I think Li is right. If the header includes other headers setting the ROOT_INCLUDE_PATH will be necessary.

Cheers,
Danilo

Setting IncludePath does not help either.

Here is how I do this:

libExRootPath = '/afs/cern.ch/user/a/andrey/work/MG5_aMC_v2_4_3/ExRootAnalysis/' gInterpreter.AddIncludePath(libExRootPath) gInterpreter.Declare('#include "'+libExRootPath+'ExRootAnalysis/ExRootClasses.h"') gSystem.Load(libExRootPath+"/libExRootAnalysis.so")

% which root
% /cvmfs/cms.cern.ch/slc6_amd64_gcc493/cms/cmssw/CMSSW_8_0_8/external/slc6_amd64_gcc493/bin/root

Andrey

Hi Andrey,

I am not sure I follow. Some questions:

  1. Do you get any warning/error upon inclusion of the header?
  2. Can you use interactively any of the symbols in the header? (without undefined symbols or other errors?)

Can you try 1) and 2) outside PyROOT, i.e. at the prompt? What happens?

Cheers,
Danilo

Hi Danilo,

The error I get is this:

[quote]Error in TClass::LoadClassInfo: no interpreter information for class TRootLHEFParticle is available even though it has a TClass initialization routine.
./LHEanalyzer.py:119: RuntimeWarning: failed offset calculation between TObject and TRootLHEFParticle[/quote]

I pushed the script I run to git [1], can you have a look. It gets stack at p.Px line [2].

[1] github.com/andreypz/nwu-dalitz- … zer.py#L50
[2] github.com/andreypz/nwu-dalitz- … er.py#L120

I’m not sure what do you mean by your second question…

Andrey

Hi Andrey,

the error message is informing you that you do have a dictionary loaded for the class TRootLHEFParticle but the interpreter did not parse the header where it is defined.
Is TRootLHEFParticle defined in the header you include github.com/andreypz/nwu-dalitz- … zer.py#L50 ?
Can you produce a 10 lines program I can run (even after producing some dictionries) that shows the issue?

Cheers,
D

Hi,
Just to want to update this thread.

After some investigation I concluded the the error I’m getting is not directly related to ROOT6, but rather pyRoot implementation.
What I found is: if I comment out this line or this lines the error is no more.

I think somehow the gROOT.ProcessLine() calls are interfering with gInterpreter.Declare method, in a strange way. Anyway, my code works now and I did not investigate further. But I think there could be a problem in pyRoot with mixing sys.path and paths in ROOT.

Andrey

Hi Andrey,

great that you could solve this!
I am not sure we can safely blame pyroot for the message you are seeing. If you have some time to come back with a minimal program which is able to reproduce the behaviour you describe, I’ll be glad to have a look.

Cheers,
D

Hi Danilo,

Below is a minimal code needed to reproduce the problem.

Before running it, one needs of course ExRootAnalysis tools from Madgraph, compiled using the same root version. I assume you have that. My root version is from cvmfs:

% which root
/cvmfs/cms.cern.ch/slc6_amd64_gcc493/cms/cmssw/CMSSW_8_0_8/external/slc6_amd64_gcc493/bin/root

Three files are needed to reproduce the problem. First is testLHEanalyzer.py:

#!/usr/bin/env python

from ROOT import *
gROOT.SetBatch()

# If this line is commented error no more:
import utils as u

print gROOT.GetVersion()

libExRootPath = '/afs/cern.ch/user/a/andrey/work/MG5_aMC_v2_4_3/ExRootAnalysis/'
gInterpreter.Declare('#include "'+libExRootPath+'ExRootAnalysis/ExRootClasses.h"')

gSystem.Load(libExRootPath+"/libExRootAnalysis.so")

myPath = '/afs/cern.ch/user/a/andrey/public/'

def FillAllHists():
  oneFile = TFile(myPath+'/ggH120_eeg.lhe.root','open')
  fTree = oneFile.Get("LHEF");

  for evt in fTree:
    for p in evt.Particle:
      pid = p.PID
      px = p.Px
      py = p.Py
      pz = p.Pz
      E  = p.E
      M  = p.M

      #print pid, M, px, py, pz, E

if __name__ == "__main__":
  # If this line is commented error no more
  gROOT.ProcessLine(".L ./tdrstyle.C")

  # If instead od using function, we write the code as a simple script, error is no more..
  FillAllHists()

  print 'The End'

Second is utils.py

#! /usr/bin/env python
from ROOT import *
gROOT.SetBatch()
gROOT.ProcessLine(".L ./tdrstyle.C")

if __name__ == "__main__":
  print "This is utils.py script"

Third is tdrstyle.C:

#include "TStyle.h"

Then, once you run ./testLHEanalyzer.py you should see the mentioned errors.
The input file is available on afs at myPath, you only need to change libExRootPath

Andrey

Please help me. I plan to plot the histogram from the available datas in Appearance.txt file. But I try to make the errors but I can’t fix the code perfectly.Histogram.C (749 Bytes) Appearance.txt.txt (1.5 KB) ![Appearance%20v%20mode|341x224]

@Lian Please describe your data. If you are talking about histogram with a data with bin and event number in each bin, you may try bar graph. https://root.cern.ch/root/html534/guides/users-guide/Graphs.html#bar-graphs-ab