# Using TMVA for the .root files converted from madgraph generated .lhe file

**URL:** <https://root-forum.cern.ch/t/using-tmva-for-the-root-files-converted-from-madgraph-generated-lhe-file/32999>\
**Category:** TMVA\
**Tags:** tree, hist\
**Created:** [March 3, 2019, 7:21pm UTC](https://root-forum.cern.ch/t/using-tmva-for-the-root-files-converted-from-madgraph-generated-lhe-file/32999 "2019-03-03T19:21:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![atanu54598568](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/atanu54598568/32/18114_2.png) [@atanu54598568](https://root-forum.cern.ch/u/atanu54598568)\
**Post date:** [March 3, 2019, 7:21pm UTC](https://root-forum.cern.ch/t/using-tmva-for-the-root-files-converted-from-madgraph-generated-lhe-file/32999/1 "2019-03-03T19:21:02Z")

</div>

Hi,

I am new here regarding using TMVA and root as well. I have specific background process and a signal, generated using madgraph. I converted the .lhe files as .root files. Also I am able to generate the desired histograms using root. To start with, I am not able to understand how to use the .root files (say, background.root and signal.root) in TMVA platform; I mean how can I import then to make it usable by TMVAClassification.C or TMVARegression.C ?

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [March 4, 2019, 12:33pm UTC](https://root-forum.cern.ch/t/using-tmva-for-the-root-files-converted-from-madgraph-generated-lhe-file/32999/2 "2019-03-04T12:33:59Z")

</div>

Hi,

What does your files contain? If they contain a TTree with your variables integrating it should be straightforward. In essence it should be a matter of chaning the path to the loaded files and changing the names of the loaded variables.

You could also have a look at TMVAMinimalClassification for a less overwhelming template.

If you have any specific questions arising from looking at these two files, I’m happy to answer them.

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![atanu54598568](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/atanu54598568/32/18114_2.png) [@atanu54598568](https://root-forum.cern.ch/u/atanu54598568)\
**Post date:** [March 5, 2019, 12:25pm UTC](https://root-forum.cern.ch/t/using-tmva-for-the-root-files-converted-from-madgraph-generated-lhe-file/32999/3 "2019-03-05T12:25:35Z")

</div>

Hi,

Thank you very much for your reply. Yeah I guess the files contain TTree as I am able to plot the histos by TH1. By I am confused about TMVAMinimalClassification.C or TMVAClassification.C; which statement stands for importing my file.root…!!!

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [March 5, 2019, 1:37pm UTC](https://root-forum.cern.ch/t/using-tmva-for-the-root-files-converted-from-madgraph-generated-lhe-file/32999/4 "2019-03-05T13:37:29Z")

</div>

This example should maybe make things a bit more clear. Then you can combine this with MinimalClassification to build a fully working setup for your case.

```auto
// Get the input file
TFile * input = TFile::Open("/path/to/your/file.root");
if (not input) {
   std::cout << "ERROR: Could not open input file!" << std::endl;
   exit(1);
}

// Get the trees from the input file
TTree * sigTree = static_cast<TTree *>(input->Get("TreeS"));
TTree * bkgTree = static_cast<TTree *>(input->Get("TreeB"));

// Add the trees to the dataset
auto * dataloader = new TMVA::DataLoader("dataset");
dataloader->AddVariable("YourVariable1");
dataloader->AddVariable("YourVariable2");
dataloader->AddSignalTree(sigTree);
dataloader->AddSignalTree(bkgTree);

```

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![atanu54598568](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/atanu54598568/32/18114_2.png) [@atanu54598568](https://root-forum.cern.ch/u/atanu54598568)\
**Post date:** [March 5, 2019, 4:30pm UTC](https://root-forum.cern.ch/t/using-tmva-for-the-root-files-converted-from-madgraph-generated-lhe-file/32999/5 "2019-03-05T16:30:11Z")

</div>

Thank you very much Kim for your time and effort. That solves my problem and makes it easier to understand for me. Thank you once again.

---

<div class="post-metadata">

**Author:** ![atanu54598568](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/atanu54598568/32/18114_2.png) [@atanu54598568](https://root-forum.cern.ch/u/atanu54598568)\
**Post date:** [March 6, 2019, 8:14pm UTC](https://root-forum.cern.ch/t/using-tmva-for-the-root-files-converted-from-madgraph-generated-lhe-file/32999/6 "2019-03-06T20:14:46Z")

</div>

For this particular file I am getting this error…

##########################################################  
 : Tree does not exist (empty pointer).  
\*\*\*\> abort program execution  
terminate called after throwing an instance of ‘std::runtime\_error’  
what(): FATAL error  
##########################################################  
[bg.root](https://root-forum.cern.ch/uploads/default/original/3X/f/a/faccfeea231365cff6a27f83fab9ae2ac0dedec1.root) (2.5 MB)

Please find the attached file; I’m not sure what is wrong here. It’s a .root file converted from a .lhe file using ExRootLHEFConverter.

Thank you. Regards.

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [March 6, 2019, 8:43pm UTC](https://root-forum.cern.ch/t/using-tmva-for-the-root-files-converted-from-madgraph-generated-lhe-file/32999/7 "2019-03-06T20:43:35Z")

</div>

It seems that the tree that you are trying to access does not exist. You can inspect the contents of the root file using `rootbrowse /path/to/file` or `rootls -t /path/to/file`.

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![atanu54598568](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/atanu54598568/32/18114_2.png) [@atanu54598568](https://root-forum.cern.ch/u/atanu54598568)\
**Post date:** [March 6, 2019, 10:13pm UTC](https://root-forum.cern.ch/t/using-tmva-for-the-root-files-converted-from-madgraph-generated-lhe-file/32999/8 "2019-03-06T22:13:09Z")

</div>

Well. Yeah… this command " rootls -t /path/to/file ." is working fine… It shows the following messages…  
#############################################################  
TTree Feb 24 19:50 2019 LHEF “Analysis tree”  
Event “Event\_” 80160  
Event.fUniqueID “fUniqueID[Event\_]” 80180  
Event.fBits “fBits[Event\_]” 80172  
Event.Number “Number[Event\_]” 120261  
Event.Nparticles “Nparticles[Event\_]” 80182  
Event.ProcessID “ProcessID[Event\_]” 80180  
Event.Weight “Weight[Event\_]” 120261  
Event.ScalePDF “ScalePDF[Event\_]” 120267  
Event.CouplingQED “CouplingQED[Event\_]” 120276  
Event.CouplingQCD “CouplingQCD[Event\_]” 120276  
Event\_size “Event\_size/I” 40154  
Rwgt “Rwgt\_” 80158  
Rwgt.fUniqueID “fUniqueID[Rwgt\_]” 40178  
Rwgt.fBits “fBits[Rwgt\_]” 40170  
Rwgt.Weight “Weight[Rwgt\_]” 40172  
Rwgt\_size “Rwgt\_size/I” 40152  
Particle “Particle\_” 80166  
Particle.fUniqueID “fUniqueID[Particle\_]” 240861  
Particle.fBits “fBits[Particle\_]” 240841  
Particle.PID “PID[Particle\_]” 240831  
Particle.Status “Status[Particle\_]” 240846  
Particle.Mother1 “Mother1[Particle\_]” 240851  
Particle.Mother2 “Mother2[Particle\_]” 240851  
Particle.ColorLine1 “ColorLine1[Particle\_]” 240866  
Particle.ColorLine2 “ColorLine2[Particle\_]” 240866  
Particle.Px “Px[Particle\_]” 441480  
Particle.Py “Py[Particle\_]” 441480  
Particle.Pz “Pz[Particle\_]” 441480  
Particle.E “E[Particle\_]” 441472  
Particle.M “M[Particle\_]” 441472  
Particle.PT “PT[Particle\_]” 441480  
Particle.Eta “Eta[Particle\_]” 441488  
Particle.Phi “Phi[Particle\_]” 441488  
Particle.Rapidity “Rapidity[Particle\_]” 441528  
Particle.LifeTime “LifeTime[Particle\_]” 441528  
Particle.Spin “Spin[Particle\_]” 441496  
Particle\_size “Particle\_size/I” 40160  
#####################################################  
How can I identify the name of the tree(s)?

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [March 7, 2019, 2:37pm UTC](https://root-forum.cern.ch/t/using-tmva-for-the-root-files-converted-from-madgraph-generated-lhe-file/32999/9 "2019-03-07T14:37:36Z")

</div>

Should be this, no?

> [@atanu54598568](#):
>
> TTree Feb 24 19:50 2019 LHEF “Analysis tree”

EDIT: As @Pepe_Le_Pew was kind enough to highlight, it is not so obvious to see the actual name of the tree. The tree name is “LHEF” and then there is the tree title “Analysis Tree”.

Should you be able to use rootbrowse (e.g. if you are running locally or through an ssh session with X forwarding) this should be better indicated.

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![atanu54598568](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/atanu54598568/32/18114_2.png) [@atanu54598568](https://root-forum.cern.ch/u/atanu54598568)\
**Post date:** [March 7, 2019, 7:44pm UTC](https://root-forum.cern.ch/t/using-tmva-for-the-root-files-converted-from-madgraph-generated-lhe-file/32999/10 "2019-03-07T19:44:32Z")

</div>

Thanks… The TTree has been loaded now without any error.

Cheers…

Atanu

---

<div class="post-metadata">

**Author:** ![atanu54598568](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/atanu54598568/32/18114_2.png) [@atanu54598568](https://root-forum.cern.ch/u/atanu54598568)\
**Post date:** [March 8, 2019, 8:43pm UTC](https://root-forum.cern.ch/t/using-tmva-for-the-root-files-converted-from-madgraph-generated-lhe-file/32999/11 "2019-03-08T20:43:28Z")

</div>

In my above mentioned file, can I use condition to work on a particular branch like “Particle” and set a condition to take out the events only for Particle.PID == 22 , I mean in general for any particular particle?
