Reading data from a leaf of a TClonesArray created by MadGraph

Hi, all.

I was trying to read the data from a decay process that I ran in MadGraph. The result of that simulation in Madgraph gave me a TClonesArray with the name “LHEF” and several branches: Event, Rwgt, and Particle. Now I am interested in reading the information from the branch Particle, the leaf Particle.E to be exact. I have tried the following so far:

#include "TFile.h"
#include "TH1F.h"
#include "TTreeReader.h"
#include "TTreeReaderValue.h"

void electron_positron_gamma()

{
//Upload the file with the data
TFile *f = new TFile("unweighted_events.root");

//Upload the tree with the event data
TTree *LHEF = (TTree*)f->Get("LHEF");

//Calling the particle branch
TClonesArray *branchParticle = treeReader->UseBranch("Particle");
}

This gave me the following error:
Error: cannot open file “TTreeReader.h” electron_positron_gamma.cxx:4:
*** Interpreter error recovered ***

I have also tried this:

void electron_positron_gamma()

{
//Upload the file with the data
TFile *f = new TFile("unweighted_events.root");

//Upload the tree with the event data
TTree *LHEF = (TTree*)f->Get("LHEF");

//Create a variable to store all the particle energies
TClonesArray *ParticleEnergy = new TClonesArray("ParticleEnergy");
}

In this case I get the following error:

Error in TClonesArray::SetClass: called with a null pointer

I have looked around and found similar issues (especially concerning my second error), but was unable to find a solution. Therefore any help will be kindly appreciated.

With kind regards,
Ramin

_ROOT Version: 5.34/38
_Platform: Windows 10
_Compiler: 4.9.3

Hi @Ramin,

As per the information that you attached, you are running ROOT 5.34. TTreeReader is only available as per ROOT6. ROOT 5.34 is not supported anymore, so I would strongly encourage you to upgrade to the latest release.

Other than that, after reading the post, the structure of your input file is not quite clear. Could you post either the file or the output of the following?

$ root your_input_file.root
root [] gFile->ls();
// We need the output of this
root [] TTree *LHEF = (TTree*)f->Get("LHEF");
root [] LHEF->Print();
// And of this

Cheers,
J.

Hi.

Thank you very much for the quick response!

I am working on the upgrade.
I have uploaded my root file and provide the necessary output below:

root [1] gFile->ls();
TFile**         unweighted_events.root
 TFile*         unweighted_events.root
  KEY: TTree    LHEF;1  Analysis tree
root [2] TFile *f = new TFile("unweighted_events.root");
root [3] TTree *LHEF = (TTree*)f->Get("LHEF");
root [4] LHEF->Print();
******************************************************************************
*Tree    :LHEF      : Analysis tree                                          *
*Entries :      198 : Total =          162685 bytes  File  Size =      55741 *
*        :          : Tree compression factor =   2.70                       *
******************************************************************************
*Br    0 :Event     : Int_t Event_                                           *
*Entries :      198 : Total  Size=       7879 bytes  File Size  =        411 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   4.05     *
*............................................................................*
*Br    1 :Event.fUniqueID : UInt_t fUniqueID[Event_]                         *
*Entries :      198 : Total  Size=       2268 bytes  File Size  =        419 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   4.00     *
*............................................................................*
*Br    2 :Event.fBits : UInt_t fBits[Event_]                                 *
*Entries :      198 : Total  Size=       2248 bytes  File Size  =        416 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   4.01     *
*............................................................................*
*Br    3 :Event.Number : Long64_t Number[Event_]                             *
*Entries :      198 : Total  Size=       3045 bytes  File Size  =        807 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   3.05     *
*............................................................................*
*Br    4 :Event.Nparticles : Int_t Nparticles[Event_]                        *
*Entries :      198 : Total  Size=       2273 bytes  File Size  =        423 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   3.96     *
*............................................................................*
*Br    5 :Event.ProcessID : Int_t ProcessID[Event_]                          *
*Entries :      198 : Total  Size=       2268 bytes  File Size  =        420 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   3.99     *
*............................................................................*
*Br    6 :Event.Weight : Double_t Weight[Event_]                             *
*Entries :      198 : Total  Size=       3045 bytes  File Size  =        400 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   6.16     *
*............................................................................*
*Br    7 :Event.ScalePDF : Double_t ScalePDF[Event_]                         *
*Entries :      198 : Total  Size=       3055 bytes  File Size  =        401 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   6.15     *
*............................................................................*
*Br    8 :Event.CouplingQED : Double_t CouplingQED[Event_]                   *
*Entries :      198 : Total  Size=       3070 bytes  File Size  =        406 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   6.08     *
*............................................................................*
*Br    9 :Event.CouplingQCD : Double_t CouplingQCD[Event_]                   *
*Entries :      198 : Total  Size=       3070 bytes  File Size  =        406 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   6.08     *
*............................................................................*
*Br   10 :Event_size : Event_size/I                                          *
*Entries :      198 : Total  Size=       1363 bytes  File Size  =        108 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   8.05     *
*............................................................................*
*Br   11 :Rwgt      : Int_t Rwgt_                                            *
*Entries :      198 : Total  Size=       4313 bytes  File Size  =        405 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   4.11     *
*............................................................................*
*Br   12 :Rwgt.fUniqueID : UInt_t fUniqueID[Rwgt_]                           *
*Entries :      198 : Total  Size=       1469 bytes  File Size  =        116 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   7.59     *
*............................................................................*
*Br   13 :Rwgt.fBits : UInt_t fBits[Rwgt_]                                   *
*Entries :      198 : Total  Size=       1449 bytes  File Size  =        112 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   7.83     *
*............................................................................*
*Br   14 :Rwgt.Weight : Double_t Weight[Rwgt_]                               *
*Entries :      198 : Total  Size=       1454 bytes  File Size  =        113 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   7.77     *
*............................................................................*
*Br   15 :Rwgt_size : Rwgt_size/I                                            *
*Entries :      198 : Total  Size=       1358 bytes  File Size  =        104 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   8.35     *
*............................................................................*
*Br   16 :Particle  : Int_t Particle_                                        *
*Entries :      198 : Total  Size=      13831 bytes  File Size  =        415 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   4.02     *
*............................................................................*
*Br   17 :Particle.fUniqueID : UInt_t fUniqueID[Particle_]                   *
*Entries :      198 : Total  Size=       4665 bytes  File Size  =        384 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=  10.55     *
*............................................................................*
*Br   18 :Particle.fBits : UInt_t fBits[Particle_]                           *
*Entries :      198 : Total  Size=       4645 bytes  File Size  =        384 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=  10.54     *
*............................................................................*
*Br   19 :Particle.PID : Int_t PID[Particle_]                                *
*Entries :      198 : Total  Size=       4635 bytes  File Size  =        403 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=  10.04     *
*............................................................................*
*Br   20 :Particle.Status : Int_t Status[Particle_]                          *
*Entries :      198 : Total  Size=       4650 bytes  File Size  =        409 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   9.90     *
*............................................................................*
*Br   21 :Particle.Mother1 : Int_t Mother1[Particle_]                        *
*Entries :      198 : Total  Size=       4655 bytes  File Size  =        406 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   9.98     *
*............................................................................*
*Br   22 :Particle.Mother2 : Int_t Mother2[Particle_]                        *
*Entries :      198 : Total  Size=       4655 bytes  File Size  =        383 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=  10.58     *
*............................................................................*
*Br   23 :Particle.ColorLine1 : Int_t ColorLine1[Particle_]                  *
*Entries :      198 : Total  Size=       4670 bytes  File Size  =        385 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=  10.53     *
*............................................................................*
*Br   24 :Particle.ColorLine2 : Int_t ColorLine2[Particle_]                  *
*Entries :      198 : Total  Size=       4670 bytes  File Size  =        385 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=  10.53     *
*............................................................................*
*Br   25 :Particle.Px : Double_t Px[Particle_]                               *
*Entries :      198 : Total  Size=       7798 bytes  File Size  =       5302 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   1.36     *
*............................................................................*
*Br   26 :Particle.Py : Double_t Py[Particle_]                               *
*Entries :      198 : Total  Size=       7798 bytes  File Size  =       5315 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   1.36     *
*............................................................................*
*Br   27 :Particle.Pz : Double_t Pz[Particle_]                               *
*Entries :      198 : Total  Size=       7798 bytes  File Size  =       5325 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   1.35     *
*............................................................................*
*Br   28 :Particle.E : Double_t E[Particle_]                                 *
*Entries :      198 : Total  Size=       7793 bytes  File Size  =       4583 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   1.57     *
*............................................................................*
*Br   29 :Particle.M : Double_t M[Particle_]                                 *
*Entries :      198 : Total  Size=       7793 bytes  File Size  =        471 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=  15.31     *
*............................................................................*
*Br   30 :Particle.PT : Double_t PT[Particle_]                               *
*Entries :      198 : Total  Size=       7798 bytes  File Size  =       5185 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   1.39     *
*............................................................................*
*Br   31 :Particle.Eta : Double_t Eta[Particle_]                             *
*Entries :      198 : Total  Size=       7803 bytes  File Size  =       5237 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   1.38     *
*............................................................................*
*Br   32 :Particle.Phi : Double_t Phi[Particle_]                             *
*Entries :      198 : Total  Size=       7803 bytes  File Size  =       5471 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   1.32     *
*............................................................................*
*Br   33 :Particle.Rapidity : Double_t Rapidity[Particle_]                   *
*Entries :      198 : Total  Size=       7828 bytes  File Size  =       5230 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   1.38     *
*............................................................................*
*Br   34 :Particle.LifeTime : Double_t LifeTime[Particle_]                   *
*Entries :      198 : Total  Size=       7828 bytes  File Size  =        393 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=  18.37     *
*............................................................................*
*Br   35 :Particle.Spin : Double_t Spin[Particle_]                           *
*Entries :      198 : Total  Size=       7808 bytes  File Size  =        584 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=  12.36     *
*............................................................................*
*Br   36 :Particle_size : Particle_size/I                                    *
*Entries :      198 : Total  Size=       1378 bytes  File Size  =        111 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   7.86     *
*............................................................................*

I just managed to update my version of root. However, I now get the following error:

input_line_13:2:3: error: use of undeclared identifier 'treeReader'
 (treeReader->UseBranch("Particle"))

I tried to solve this by this line of code:

TTreeReader treeReader("LHEF","unweighted_events.root");

, but this only worsened the situation.

With kind regards,
Ramin

unweighted_events.root (61.2 KB)

It seems there are several classes involved (e.g., “TRootLHEFEvent”, “TRootWeight”, “TRootLHEFParticle”, “TSortableObject”). In order to use them, you need to load dictionaries for these classes (e.g., some shared library).

BTW. You need something like this:

TFile *f = TFile::Open("unweighted_events.root");
TTreeReader treeReader("LHEF", f);

Perhaps, additionally you might want to take a look at the TTree section in the manual: Trees - ROOT.

Cheers,
J.

Hi, Wile_E_Coyote.

Thank you very much for your quick reply. I assumed that the warning about the libraries were okay (as mentioned Warning in <TClass::TClass>). Do you mean that I should do gSystem->Load() in root with the library that I would like to load within brackets?

I tried this little piece of code and still get an error if I leave

TClonesArray *ParticleEnergy = new TClonesArray("ParticleEnergy");

in place. Is that my mistake then?

Thank you very much for your quick reply, jalopezg.
I will take a look.

With kind regards,
Ramin

Hi, all.

I have another question. Is the branch Particle.E an array of name E of type double?

With kind regards,
Ramin

I guess you need to talk to your colleagues and / or your supervisor about how to deal with your data.

Hi, Wile_E_Coyote.

Thank you very much for reply. The thing is that I have created several trees and read data from them. This is however, the first time I encounter such a tree (it were usually trees containing branches of doubles, floats and integers). Hence my question.

With kind regards,
Ramin

You maybe need a package called “ExRootAnalysis” (or “ExRoot”?), which possibly provides the “libExRootAnalysis.so” shared library (which you need to load) and the corresponding documentation for all classes and trees.

Hi, Wile_E_Coyote.

Thanks for your reply. I have this package installed in MadGraph. All this does though, is simply storing all the data in a root file (which I posted here).

With kind regards,
Ramin

Hi Ramin,

The package might/should also contains as part of the share library the (ROOT) dictionary representing the class that is helpful when reading (i.e. loading that library might solve your problem).

Cheers,
Philippe.

Hi pcanal,

I did indeed have to load the library before actually being able to read from the tree. Thanks a lot.

With kind regards,
Ramin