# TMVA with std::vector as input variable

**URL:** <https://root-forum.cern.ch/t/tmva-with-std-vector-as-input-variable/20375>\
**Category:** TMVA\
**Created:** [December 23, 2015, 1:20pm UTC](https://root-forum.cern.ch/t/tmva-with-std-vector-as-input-variable/20375 "2015-12-23T13:20:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hcohen](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/58956e/32.png) [@hcohen](https://root-forum.cern.ch/u/hcohen)\
**Post date:** [December 23, 2015, 1:20pm UTC](https://root-forum.cern.ch/t/tmva-with-std-vector-as-input-variable/20375/1 "2015-12-23T13:20:59Z")

</div>

Hi,

I’ve got a classic classification in my analysis, and using BDT to train on the MC.  
My events has a large number of properties (jet1pt, angular distributions, el\_pt…)  
But, in my TTree i also got a std::vector named jet\_pt, this vector contains the p\_T of my jets in the event and for my analysis is larger than 5.

Accidentally I trained my BDT with this variable, the fact is the TMVA won’t yell at you since TTree::Draw(“jet\_pt”) yields an histogram so the training went on perfectly. The problem arose when I wanted to apply the BDT to my data and then i realized that no naive variable can describe the jet\_pt -\> TMVA requires float/int.

BUT, the interesting part is once this variable removed, my separation got allot worse, so i started investigating a bit. It appears that when i’m using this “jet\_pt” it multiplies my number of events (at least by 5 since this is my cut), both for signal & background. So my initial guess was that for every entry inside the vector it produces another event - so basically multiply the number of events. This multiplication is not straight forward, because if i simply multiply the number of events i’ve got (just duplicate the ntuples) i’m getting the same separation, just with lower errors. What is more interesting is that this variable is ranked the lowest after the BDT finished his training.

So my question is this: how come adding this std::vector to my training, improved my classification by a significant factor? Can this be actually used?

---

<div class="post-metadata">

**Author:** ![hcohen](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/58956e/32.png) [@hcohen](https://root-forum.cern.ch/u/hcohen)\
**Post date:** [December 23, 2015, 4:07pm UTC](https://root-forum.cern.ch/t/tmva-with-std-vector-as-input-variable/20375/2 "2015-12-23T16:07:41Z")

</div>

[overtrain\_BDT0\_inclusive\_H300\_SR64.eps](https://root-forum.cern.ch/uploads/default/original/2X/5/5ab23bd9509eee3137f82a5bc4f90091024b1f15.eps) (28.8 KB)  
[overtrain\_BDT8\_ttbb\_jp\_H300\_SR64.eps](https://root-forum.cern.ch/uploads/default/original/2X/e/e73702d1c90c55fb56d375038096edd2fe092422.eps) (21.4 KB)

---

<div class="post-metadata">

**Author:** ![iw273](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/bc8723/32.png) [@iw273](https://root-forum.cern.ch/u/iw273)\
**Post date:** [October 11, 2018, 11:05am UTC](https://root-forum.cern.ch/t/tmva-with-std-vector-as-input-variable/20375/3 "2018-10-11T11:05:07Z")

</div>

Hi, did you ever get an answer as to how exactly this works and why this gives an improvement?

---

<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 11, 2018, 2:47pm UTC](https://root-forum.cern.ch/t/tmva-with-std-vector-as-input-variable/20375/4 "2018-10-11T14:47:31Z")

</div>

Hi,

When adding a vector-type variable to TMVA it’s considered to be a collection of data within an event. E.g. the `jet_pt` in this case would represent each individual jet. To handle this in a generic way, TMVA adds a `TMVA::Event` for each entry in the vector(s) while keeping the non-vector data constant for that set of events.

E.g. a data point with variables `num_jets` and `jet_pt` with values `[1, 2]` and `[[30], [45, 10]]` would be added to TMVA as 3 TMVA::Events, namely:

```auto
1) [1, 30]
2) [2, 45]
3) [2, 10]

```

This can lead to problems if the weight normalisation is not done properly. E.g. if you replicate signal events more on average because of your selection than you do background events and do not normalise the class weights the final performance is skewed towards the signal class.

Even if you do per-class normalisation you can still have problems since TMVA currently does not automatically normalise the event weight for replicated events, it is assumed you also provide a vector variable for your weights or have already premultiplied your weights before entering them to TMVA. This can be done quite easily by e.g.

```auto
dataloader->SetSignalWeightExpression("weight/num_jets");

```

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![iw273](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/i/bc8723/32.png) [@iw273](https://root-forum.cern.ch/u/iw273)\
**Post date:** [October 12, 2018, 8:00am UTC](https://root-forum.cern.ch/t/tmva-with-std-vector-as-input-variable/20375/5 "2018-10-12T08:00:40Z")

</div>

Hi Kim,

Great, thanks for the explanation.

Ifan
