# TMVA: Separately passing Train and Test Tree for Signal and Background

**URL:** <https://root-forum.cern.ch/t/tmva-separately-passing-train-and-test-tree-for-signal-and-background/43447>\
**Category:** TMVA\
**Created:** [February 8, 2021, 5:23pm UTC](https://root-forum.cern.ch/t/tmva-separately-passing-train-and-test-tree-for-signal-and-background/43447 "2021-02-08T17:23:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kormoranos](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/f1d935/32.png) [@kormoranos](https://root-forum.cern.ch/u/kormoranos)\
**Post date:** [February 8, 2021, 5:23pm UTC](https://root-forum.cern.ch/t/tmva-separately-passing-train-and-test-tree-for-signal-and-background/43447/1 "2021-02-08T17:23:04Z")

</div>

Dear rooters,

I have an apparently silly question that is bothering me since two weeks.

I have an old code using TMVA where I add signal and background in the following way:

```auto
 fTMVAdataloader[iTMVA]->AddSignalTree(signalTree, signalWeight);
 fTMVAdataloader[iTMVA]->AddBackgroundTree(backgroundTree, backgroundWeight);

```

Now I would like to specifically separate Train and Test tree as:

```auto
 fTMVAdataloader[iTMVA]->AddSignalTree(signalTestTree, signalWeight, TMVA::Types::kTesting);
 fTMVAdataloader[iTMVA]->AddSignalTree(signalTrainTree, signalWeight, TMVA::Types::kTraining);
 fTMVAdataloader[iTMVA]->AddBackgroundTree(backgroundTestTree, backgroundWeight, TMVA::Types::kTesting);
 fTMVAdataloader[iTMVA]->AddBackgroundTree(backgroundTrainTree, backgroundWeight, TMVA::Types::kTraining);

```

In both cases, I am running them with the following options: “nTrain\_Signal=0:nTrain\_Background=0:SplitMode=Alternate:NormMode=NumEvents:!V”

In the first case, TMVA automatically uses even events for train and odd events for test.  
In the second case, I manually divided the original two files in four final files using the same criteria.

If I check the variables used as spectator or for BDT, the output histograms are exactly the same in the two cases, confirming that I have correctly split the files in the second case.

However, the distribution of the BDT variable is different and I noticed that it changes if, in the second case, I change the “SplitMode” between “Alternate”, “Random” or “Block”.

Originally, I thought this flag has no meaning in the second case, but I have now realized that it does mean, but I do not understand which is the correct configuration.

My question is: if I want implement TMVA as in the second case but obtain exactly the same training as in the first case, which options or commands are needed?

Thank you!

---

<div class="post-metadata">

**Author:** ![kormoranos](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/f1d935/32.png) [@kormoranos](https://root-forum.cern.ch/u/kormoranos)\
**Post date:** [February 10, 2021, 2:06pm UTC](https://root-forum.cern.ch/t/tmva-separately-passing-train-and-test-tree-for-signal-and-background/43447/2 "2021-02-10T14:06:49Z")

</div>

Maybe my question was too long, saying it in a simpler way:

- in general we separately pass signal and background files and specify to TMVA how to divide each sample in a training and a test subsamples
- instead, how can I change this approach, separately specifying four files, i.e. training-signal, test-signal, training-background and test-background?

---

<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 10, 2021, 3:29pm UTC](https://root-forum.cern.ch/t/tmva-separately-passing-train-and-test-tree-for-signal-and-background/43447/3 "2021-02-10T15:29:26Z")

</div>

Hi @kormoranos ,  
I think we need our TMVA expert @moneta , let’s ping him.

---

<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 10, 2021, 4:42pm UTC](https://root-forum.cern.ch/t/tmva-separately-passing-train-and-test-tree-for-signal-and-background/43447/4 "2021-02-10T16:42:07Z")

</div>

Hi,  
I would need to check your second approach. Can you please post your files and your code,  
Thanks

Lorenzo
