# Delphes-root file or root for TMVA

**URL:** <https://root-forum.cern.ch/t/delphes-root-file-or-root-for-tmva/36034>\
**Category:** TMVA\
**Tags:** tree, root\
**Created:** [September 14, 2019, 9:29pm UTC](https://root-forum.cern.ch/t/delphes-root-file-or-root-for-tmva/36034 "2019-09-14T21:29:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hhamdell](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/ecccb3/32.png) [@hhamdell](https://root-forum.cern.ch/u/hhamdell)\
**Post date:** [September 14, 2019, 9:29pm UTC](https://root-forum.cern.ch/t/delphes-root-file-or-root-for-tmva/36034/1 "2019-09-14T21:29:30Z")

</div>

Hi,

I am new here regarding using TMVA and root as well. I have many background processes and a specific signal, generated using madgraph(with pythia for showering/hadronization and delphes for detector simulation), My data files are .root files (the tree name is “Delphes”). could i use just delphes-root file especially when you need many variables inside a macro in order to use TMVA Or i need to produce another root file?if yes how?  
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:** [September 16, 2019, 8:54am UTC](https://root-forum.cern.ch/t/delphes-root-file-or-root-for-tmva/36034/2 "2019-09-16T08:54:42Z")

</div>

Hi and welcome to the ROOT forum!

TMVA natively understands `.root` files and `TTree`s contained within. You can check out the `TMVAClassification.C` example (in your `$ROOTSYS/tutorials/tmva` directory and [here](https://root.cern/doc/master/TMVAClassification_8C.html))

You can add the branches of your Delphes tree to the dataloader and TMVA will read the data. You can even define combinations such as `"myvar := branch1 + branch2"`.

Condensed:

```auto
   TFile * file = TFile::Open("/path/to/file.root");
   TTree * tree = static_cast<TTree*>(input->Get("Delphes"));
   TMVA::Factory * factory = new TMVA::Factory("TestSetup", "<options>" );
   TMVA::DataLoader * dataloader = new TMVA::DataLoader("dataset");
   dataloader->AddVariable("branch/in/tree");
   dataloader->AddSignalTree(tree);
   dataloader->AddBackgroundTree(tree);

   // Here <sigcut> and <bkgcut> is a string convertible to a TCut, e.g. `"branch1 > 0.5 && branch2 != 0"`.
   dataloader->PrepareTrainingAndTestTree("<sigcut>", "<bkgcut>");

   // ... Do training here...

```

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![hhamdell](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/ecccb3/32.png) [@hhamdell](https://root-forum.cern.ch/u/hhamdell)\
**Post date:** [September 16, 2019, 10:37am UTC](https://root-forum.cern.ch/t/delphes-root-file-or-root-for-tmva/36034/3 "2019-09-16T10:37:23Z")

</div>

Hi Kim,  
Thank you very much for your reply.  
What i do not able to do is how i define a combination variables for example the invariant mass of the two leading b-jet from the branch. also i want to put some cuts on the defined variables. i followed your suggest and i tried to write a macro. as it’s uploaded.  
Best regards  
Hilal [tmvatest.C](https://root-forum.cern.ch/uploads/short-url/1YT4mrPjZCTgQbDDbHBjqNAyQOP.C) (9.0 KB)

---

<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:** [September 19, 2019, 2:06pm UTC](https://root-forum.cern.ch/t/delphes-root-file-or-root-for-tmva/36034/4 "2019-09-19T14:06:54Z")

</div>

Hi,

To define a combination variable you can do like this (non-sensical example but the principle is valid):

```auto
dataloader->AddVariable("Combined := Jet.PT + MissingET", "Combined", 'F');

```

What kinds of cuts do you want to put? For global cuts on signal and background you can use:

```auto
dataloader->PrepareTrainingAndTestTree("<sigcut>", "<bkgcut>");

```

where `"<sigcut>"` is a string such as `"Jet.PT < 2"`.

More complex cuts are better handled outside TMVA.

Finally I see that the call to `dataloader->PrepareTrainingAndTestTree` is missing from your macro. This is probably a mistake, this is where you control the creation of data that is fed to your ML algorithm! See [here](https://root.cern.ch/download/doc/tmva/TMVAUsersGuide.pdf) under “_3.1.4 Preparing the training and test data_” for more info.

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![hhamdell](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/ecccb3/32.png) [@hhamdell](https://root-forum.cern.ch/u/hhamdell)\
**Post date:** [September 19, 2019, 2:47pm UTC](https://root-forum.cern.ch/t/delphes-root-file-or-root-for-tmva/36034/5 "2019-09-19T14:47:17Z")

</div>

Hi Kim,  
thanks a lot, i will let you know when i do the requirement corrections.

---

<div class="post-metadata">

**Author:** ![hhamdell](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/ecccb3/32.png) [@hhamdell](https://root-forum.cern.ch/u/hhamdell)\
**Post date:** [October 1, 2019, 4:14pm UTC](https://root-forum.cern.ch/t/delphes-root-file-or-root-for-tmva/36034/6 "2019-10-01T16:14:33Z")

</div>

Hi Kim,  
Sorry for this late.  
I added `dataloader->PrepareTrainingAndTestTree` to my macro and it is working[tmvatest.C](https://root-forum.cern.ch/uploads/short-url/lxP0hqSBc4levjIrhDNy77MMtBw.C) (9.0 KB) .  
But as i said before i want know how i can write one combined variable at least, like the invariant mass of the two leading b-jet because in delphes-root file there is just Jets.

Thanks in advance,  
Hilal

---

<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:** [October 2, 2019, 11:40am UTC](https://root-forum.cern.ch/t/delphes-root-file-or-root-for-tmva/36034/7 "2019-10-02T11:40:57Z")

</div>

Hi Hilal,

Could you explain in more detail how the proposed solution (i.e. `AddVariable("combinded := part1 + part2")`) fails you?

If there is information lacking in the delphes tree you need to either: look at the program that produced it and modify that accordingly; or talk to those who produced it and ask them to include the necessary information.

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![hhamdell](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/ecccb3/32.png) [@hhamdell](https://root-forum.cern.ch/u/hhamdell)\
**Post date:** [October 2, 2019, 12:58pm UTC](https://root-forum.cern.ch/t/delphes-root-file-or-root-for-tmva/36034/8 "2019-10-02T12:58:30Z")

</div>

Hi Kim,  
I mean that i am interested in b-jet not in all jets in order to do my combination (i.e. `AddVariable("Eb1b2 := Eb1 + Eb2")` ).  
Indeed as you said i found that i have to produce another root file (from the original one) where i include all needed tree.  
Thank you very much.  
Hilal
