# TMVA-Wrong Number of Entries w.r.t Inputs

**URL:** <https://root-forum.cern.ch/t/tmva-wrong-number-of-entries-w-r-t-inputs/53732>\
**Category:** Newbie\
**Tags:** tree, tmva\
**Created:** [February 22, 2023, 1:25pm UTC](https://root-forum.cern.ch/t/tmva-wrong-number-of-entries-w-r-t-inputs/53732 "2023-02-22T13:25:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Threshic](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/threshic/32/29367_2.png) [@Threshic](https://root-forum.cern.ch/u/Threshic)\
**Post date:** [February 22, 2023, 1:25pm UTC](https://root-forum.cern.ch/t/tmva-wrong-number-of-entries-w-r-t-inputs/53732/1 "2023-02-22T13:25:25Z")

</div>

\_ROOT Version: 6.24.06  
\_Platform: centos7.6  
_Compiler:_ Not Provided

* * *

Hello everyone,  
I am currently using the tmva framework to build a BDT.  
I will explain in two parts : one version that works, another that does not.  
**Works** :  
To get my inputs for my BDT (signal and Background), i have a code that builds two trees =\> one for signal and one for Background.  
The good thing here is that I only need to fill my trees with branches that have the same number of entries.  
Therefore, I only needed to Fill my tree after the value of my variables were assigned to my branches  
To simplify:

```auto
for loop
{
myvariable1 = myvalue1;
myvariable2 = myvalue2;
etc..
if (condition){treeSignal->Fill();}
else{treeBkg->Fill();}
}

```

With this configuration, the number of entries for all my variables is good for all my variables when I look at the “Input Variables” from the TMVAGui.  
**Does not work** :  
I am still building two trees **however** the different branches are not filled at the same time.  
I know that this specific subject has already been covered and by doing this:

```auto
treeSignal->GetBranch("name_of_branch1")->Fill();
...//same with TreeBkg
treeSignal->GetBranch("name_of_branch2")->Fill();//with different number of entries
...
treeS->SetEntries(totalNumberofEntriesofAllBranches);

```

This actually works fine when i look at my trees, all the branches have the right amount of entries.  
Now, this issue comes when I give these trees as inputs to my BDT.  
TMVA takes “totalNumberofEntriesofAllBranches” as the number of entries for **all** variables while all htese varaibles don’t have the same number of entries. It gives this weird behavior where it fills the variable (having less number of entries) with a certain value until reaching the “totalNumberofEntriesofAllBranches” (see picture of the TMVAGui-\>Input Variables)  
 ![Screenshot from 2023-02-22 14-22-08](https://root-forum.cern.ch/uploads/default/original/3X/0/1/01b0028e04c8cadfe8ea011a42b7a818b6832ad2.png)  
The peaks being the weird behavior that does not show when I look at this distribution in my tree

Has anyone ever encountered that behavior or am I mis-using the SetEntries in the case that it does not work.  
Sorry for being this long, I hope I made it clear.  
Thanks to anyone that reads all of this!  
Paul

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [February 22, 2023, 3:51pm UTC](https://root-forum.cern.ch/t/tmva-wrong-number-of-entries-w-r-t-inputs/53732/2 "2023-02-22T15:51:56Z")

</div>

Hello @Threshic ,

a small, self-contained reproducer for the issue would really help us figure out what’s going wrong.

Other than that maybe @moneta has other suggestions.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [February 22, 2023, 4:14pm UTC](https://root-forum.cern.ch/t/tmva-wrong-number-of-entries-w-r-t-inputs/53732/3 "2023-02-22T16:14:30Z")

</div>

Hi,  
yes please post the example code and especially the file containing the signal and background trees that do not work. I have not understood how is the structure of this TTree.

Lorenzo

---

<div class="post-metadata">

**Author:** ![Threshic](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/threshic/32/29367_2.png) [@Threshic](https://root-forum.cern.ch/u/Threshic)\
**Post date:** [February 22, 2023, 6:52pm UTC](https://root-forum.cern.ch/t/tmva-wrong-number-of-entries-w-r-t-inputs/53732/4 "2023-02-22T18:52:37Z")

</div>

I tried to make it as simple as possible w.r.t what my code is .

Basically, I am looping over muons and filling the basic informations (mva\_muon\_pt, mva\_muon\_eta,…).  
Now I added two other informations that are not filled at the same time as the basic infos of the muons =\>  
mva\_Met && mva\_Mmumu. =\> I have less entries for these. You shouldn’t see any issue with this in the output50\_Neu\_Forum.root file. However, after training, these variables with less entries will be filled with a certain value (that i don’t know how it is defined) until reaching the max number of entries.  
Files containing the trees : output50\_Neu\_Forum.root (I am actually using one file for the SIgnal and another one for the background but the issue is independant of the input file).I compile using runscript.C  
[output50\_Neu\_Forum.root](https://root-forum.cern.ch/uploads/short-url/lsEuMpDiYTx0beHehuwzrPlGrQ8.root) (1.2 MB)

[TreeReader.h](https://root-forum.cern.ch/uploads/short-url/1YbWZ3rogCsHrcJdZWyx30UycCk.h) (87.7 KB)  
[TreeReader.C](https://root-forum.cern.ch/uploads/short-url/tngDYwNLgJT8GOdhJ5mrksrT8PK.C) (18.2 KB)

The output50 file is built using TreeReader.c and TreeReader.h and “heavy” Ntuple (\>100MB file). I actually need the headers (i tried to be fast, but if you really need something less “messy”, i can change my code. You can actually train a BDT using the output50\_Neu\_Forum file) : HistoManager.h and HistoManager.cc // Muon.h and Muon.cc // PrimaryVertex.cc && PrimaryVertex.h, etc  
[PrimaryVertex.h](https://root-forum.cern.ch/uploads/short-url/zln8YcOOqmaeBxx9KGqxpu1s4KT.h) (1.4 KB)  
[Track.h](https://root-forum.cern.ch/uploads/short-url/ixkLCacdOlTKHMetiHIBvnYaDal.h) (12.0 KB)  
[TreeFormat.h](https://root-forum.cern.ch/uploads/short-url/eCo5IZjK0jEY7BZaaK7yYi0IS1N.h) (30.2 KB)  
[PFJet.cc](https://root-forum.cern.ch/uploads/short-url/prkOpauHBjvU3F2oaW1a4bOBa8W.cc) (823 Bytes)  
[Track.cc](https://root-forum.cern.ch/uploads/short-url/8C4P0SjQuBjsjLj0C4mF4zcgSvC.cc) (11.5 KB)

[runscript.C](https://root-forum.cern.ch/uploads/short-url/8mFqnfdhnqSl6AaMUSqFqkWtbyv.C) (368 Bytes)  
[TreeReader.h](https://root-forum.cern.ch/uploads/short-url/1YbWZ3rogCsHrcJdZWyx30UycCk.h) (87.7 KB)  
[DeltaFunc.h](https://root-forum.cern.ch/uploads/short-url/wXhjwK6rKZ8WgAj9gLiQMBl2EOH.h) (507 Bytes)  
[HistoManager.h](https://root-forum.cern.ch/uploads/short-url/ui76OHP1x3ILDjGhl70ZRTMuWSH.h) (1.5 KB)  
[Muon.h](https://root-forum.cern.ch/uploads/short-url/dDhDR2zIS92BK2ji9qOnEJfxjRp.h) (1.9 KB)  
[PFJet.h](https://root-forum.cern.ch/uploads/short-url/tFEk8Byfrv33tVFoQm88DVjVyig.h) (1.7 KB)  
[runscript.C](https://root-forum.cern.ch/uploads/short-url/8mFqnfdhnqSl6AaMUSqFqkWtbyv.C) (368 Bytes)  
[TreeReader.C](https://root-forum.cern.ch/uploads/short-url/tngDYwNLgJT8GOdhJ5mrksrT8PK.C) (18.2 KB)  
[PrimaryVertex.cc](https://root-forum.cern.ch/uploads/short-url/qNWPNGS05IOswn0d8YJfn6I4YLH.cc) (719 Bytes)  
[Muon.cc](https://root-forum.cern.ch/uploads/short-url/xCYnPlZRy6x8Qs5eUJG54sQwHWC.cc) (1.1 KB)  
[HistoManager.cc](https://root-forum.cern.ch/uploads/short-url/z5QmjHKxJmvCt11EOoKpyy6Ica8.cc) (3.4 KB)

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [February 27, 2023, 4:31pm UTC](https://root-forum.cern.ch/t/tmva-wrong-number-of-entries-w-r-t-inputs/53732/5 "2023-02-27T16:31:52Z")

</div>

Thank you for posting all this information. Sorry for the delay, I’ll try to look at it

Lorenzo
