Acessing vector<TLorentzVector> with pyROOT

Hallo,

I have a Tree which has a vector of TLorentzVector (generated with a C++ program), but I cannot access it in pyROOT:

In [11]: mychain.Cut_Lepton_vec
Out[11]: <ROOT.vector<TLorentzVector> object at 0xa982930>

In [12]: mychain.Cut_Lepton_vec[0] 
Message: (file "_vector.h", line 85)  19: illegal instruction 0x3ec     1004
---------------------------------------------------------------------------
exceptions.TypeError                                 Traceback (most recent call last)

/afs/atlass01.physik.uni-bonn.de/user/duc/analyse/pysigmatop/<console> 

TypeError: none of the 2 overloaded methods succeeded. Full details:
  NULL result where temporary expected
  NULL result where temporary expected

In [13]: mychain.Cut_Lepton_vec[0]
---------------------------------------------------------------------------
exceptions.TypeError                                 Traceback (most recent call last)

/afs/atlass01.physik.uni-bonn.de/user/duc/analyse/pysigmatop/<console> 

TypeError: none of the 2 overloaded methods succeeded. Full details:
  NULL result where temporary expected
  NULL result where temporary expected

I haven’t tried to generate the vector/array of TLorentzVectors in pyROOT (which should work with array(…), as described in the manual) and then read in that vector/array.

Thanks Duc

Duc,

you’re missing a dictionary for the std::vector class. The easiest is probably to add it to a file and load it with: gROOT.LoadMacro( "TLorentzVectorDict.h+" )
where the file TLorentzVectorDict.h should look something like: [code]#include
#include “TLorentzVector.h”

#ifdef CINT
#pragma link C++ class std::vector< TLorentzVector >;
#endif

template class std::vector< TLorentzVector >;[/code]
Ii is possible to fully automate the above process, but am waiting for a proper API to ACLiC. :slight_smile:

Cheers,
Wim

Hi,

sorry to bother you again, but what should I do now to read a vector < vector < double > >?

tree.vector[a][b] does not work, I guess I am missing again a dictionary. Modifying your solution to


#ifdef __CINT__
#pragma link C++ class std::vector< std::vector <double> >;
#endif

template class std::vector< std::vector <double> >;

does not help (the original code works) and returns me:

In [11]: t.Tru_ParentIDs   
Out[11]: <ROOT.vector<vector<double> > object at 0x9494e50>

In [12]: t.Tru_ParentIDs[0][0]
---------------------------------------------------------------------------
exceptions.TypeError                                 Traceback (most recent call last)

/afs/atlass01.physik.uni-bonn.de/user/duc/analyse/pysigmatop/<console> 

TypeError: none of the 2 overloaded methods succeeded. Full details:
  NULL result where temporary expected
  NULL result where temporary expected

In [13]: t.Tru_ParentIDs[0]   
---------------------------------------------------------------------------
exceptions.TypeError                                 Traceback (most recent call last)

/afs/atlass01.physik.uni-bonn.de/user/duc/analyse/pysigmatop/<console> 

TypeError: none of the 2 overloaded methods succeeded. Full details:
  NULL result where temporary expected
  NULL result where temporary expected

In [14]: t.Tru_ParentIDs   
Out[14]: <ROOT.vector<vector<double> > object at 0x9494e50>

Thanks
Duc

Duc,

you don’t say which version you’re using, but the one that I have in front of me has pbs with the ‘std::’ bit in the template argument name. So, can you do this instead:

[code]
#ifdef CINT
#pragma link C++ class std::vector< vector >;
#endif

template class std::vector< vector >;[/code]
or drop all the ‘std::’ altogether. It then works for both w/ and w/o std:: in GetClass() lookups.

HTH,
Wim

Hi,

for completness: I am using root v5.14.00 together with IPython 2.4.1.
And it works now!

Thank you
Duc

Hello,

I followed the instruction to use vector::.

gROOT.LoadMacro( “TLorentzVectorDict.h+” )

After I type the above line, I got an error as follows.


$ python
Python 2.3.4 (#1, Mar 14 2006, 11:40:38)
[GCC 3.4.4 20050721 (Red Hat 3.4.4-2)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

from ROOT import *

gROOT.LoadMacro( “TLorentzVectorDict.h+” )
Info in TUnixSystem::ACLiC: creating shared library /home/heejong/dream06/python/./TLorentzVectorDict_h.so
In file included from /home/heejong/dream06/python/./fileOP3nrN.h:32,
from /home/heejong/dream06/python/./fileOP3nrN.cxx:16:
/home/heejong/dream06/python/./TLorentzVectorDict.h:8: error: expected unqualified-id before ‘;’ token
g++: /home/heejong/dream06/python/./fileOP3nrN.o: No such file or directory
Error in : Compilation failed!
0


TLorentzVectorDict.h containts only following lines.

#include
#include “TLorentzVector.h”

#ifdef CINT
#pragma link C++ class std::vector< TLorentzVector >;
#endif

template std::vector< TLorentzVector >;

I’m wondering if I missed something to make it work.
And I’m using Root version 5.14, python 2.3.4 and gcc 3.4.4.

Thanks,
Heejong

Heejong,

mea culpa. It’s supposed to read:template class std::vector< TLorentzVector >;
Note the “class” keyword. I’ve edited the messages above to reflect the correct code, in order to prevent further confusion.

HTH,
Wim