# How to specify different input files for training and testing events?

**URL:** <https://root-forum.cern.ch/t/how-to-specify-different-input-files-for-training-and-testing-events/33549>\
**Category:** TMVA\
**Created:** [April 11, 2019, 1:27pm UTC](https://root-forum.cern.ch/t/how-to-specify-different-input-files-for-training-and-testing-events/33549 "2019-04-11T13:27:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Einsiedler](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/51bf81/32.png) [@Einsiedler](https://root-forum.cern.ch/u/Einsiedler)\
**Post date:** [April 11, 2019, 1:27pm UTC](https://root-forum.cern.ch/t/how-to-specify-different-input-files-for-training-and-testing-events/33549/1 "2019-04-11T13:27:09Z")

</div>

Dear TMVA users,

I was wondering if there was any simple way to specify two different files in TMVAClassification.C for both training and testing samples rather than having the algorithm pick them randomly from one single file.

The thing is that I would like to have the file containing the testing sample so I can run an independent analysis that is not connected to TMVA. Maybe there is already another easier way to do that?

Cheers,  
Kévin

---

<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:** [April 12, 2019, 9:20am UTC](https://root-forum.cern.ch/t/how-to-specify-different-input-files-for-training-and-testing-events/33549/2 "2019-04-12T09:20:30Z")

</div>

Hi,

You can add any number of trees to the data loading process. Either add it as a generic data source, so that TMVA will to the splitting internally:

```auto
TFile * file1 = TFile::Open(...);
TFile * file2 = TFile::Open(...);

dataloader->AddTree(file1->Get<TTree>("tree1"));
dataloader->AddTree(file2->Get<TTree>("tree2"));

```

Or add them specifically to the training/test set

```auto
TFile * file1 = TFile::Open(...);
TFile * file2 = TFile::Open(...);

dataloader->AddTree(file1->Get<TTree>("tree1"), "Signal", 1.0, "signal cut", TMVA::Types::kTraining);
dataloader->AddTree(file1->Get<TTree>("tree1"), "Background", 1.0, "bkg cut", TMVA::Types::kTraining);
dataloader->AddTree(file1->Get<TTree>("tree2"), "Signal", 1.0, "signal cut", TMVA::Types::kTesting);
dataloader->AddTree(file1->Get<TTree>("tree2"), "Background", 1.0, "bkg cut", TMVA::Types::kTesting);

```

Do note that the all variables added to the data loader must be present in all trees.

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![Einsiedler](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/51bf81/32.png) [@Einsiedler](https://root-forum.cern.ch/u/Einsiedler)\
**Post date:** [April 12, 2019, 5:14pm UTC](https://root-forum.cern.ch/t/how-to-specify-different-input-files-for-training-and-testing-events/33549/3 "2019-04-12T17:14:04Z")

</div>

Thank you very much Kim, it worked like a charm 🙂
