# JupyROOT: SetInputTrees fails

**URL:** <https://root-forum.cern.ch/t/jupyroot-setinputtrees-fails/52426>\
**Category:** TMVA\
**Tags:** python, root, jupyter\
**Created:** [November 18, 2022, 11:35am UTC](https://root-forum.cern.ch/t/jupyroot-setinputtrees-fails/52426 "2022-11-18T11:35:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![petrakou](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/d78d45/32.png) [@petrakou](https://root-forum.cern.ch/u/petrakou)\
**Post date:** [November 18, 2022, 11:35am UTC](https://root-forum.cern.ch/t/jupyroot-setinputtrees-fails/52426/1 "2022-11-18T11:35:57Z")

</div>

Hello,  
What the title says. I’m trying to get signal and background events from the same tree.  
But when I run:

```auto
thetree = inputFile.Get("myTree")
sigCut = ROOT.TCut("Class>1")
bgCut = ROOT.TCut("Class<1")
dataloader.SetInputTrees(thetree, sigCut, bgCut)

```

I get this:

```auto
Error in callback <bound method StreamCapture.post_execute of <JupyROOT.helpers.utils.StreamCapture object at 0x000001F21C9AAB38>> (for post_execute):

---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
C:\rootinstall\bin\JupyROOT\helpers\utils.py in post_execute(self)
    389 # Print for the notebook
    390 out = self.ioHandler.GetStdout()
--> 391 err = self.ioHandler.GetStderr()
    392 if not transformers:
    393 sys.stdout.write(out)

C:\rootinstall\bin\JupyROOT\helpers\handlers.py in GetStderr(self)
     66 
     67 def GetStderr(self):
---> 68 return _lib.JupyROOTExecutorHandler_GetStderr()
     69 
     70 def GetStreamsDicts(self):

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x86 in position 60001: invalid start byte

```

**Edit:** What I write below about double loading isn’t correct, so I’m using the solution below. (See also my reply.)

Let me note that the following code, which loads signal and background separately, runs succesfully. But of course it loads all events twice.

```auto
dataloader.AddSignalTree(thetree)
dataloader.AddBackgroundTree(thetree)
dataloader.PrepareTrainingAndTestTree(sigCut, bgCut, etc.

```

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [November 18, 2022, 11:38am UTC](https://root-forum.cern.ch/t/jupyroot-setinputtrees-fails/52426/2 "2022-11-18T11:38:56Z")

</div>

Maybe @moneta can help

---

<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:** [November 22, 2022, 3:41pm UTC](https://root-forum.cern.ch/t/jupyroot-setinputtrees-fails/52426/3 "2022-11-22T15:41:30Z")

</div>

Hi,  
Sorry for the late reply. Your code seems correct, can you please post your code and the input file so I can try to reproduce the problem ?

Cheers

Lorenzo

---

<div class="post-metadata">

**Author:** ![petrakou](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/d78d45/32.png) [@petrakou](https://root-forum.cern.ch/u/petrakou)\
**Post date:** [December 1, 2022, 6:27pm UTC](https://root-forum.cern.ch/t/jupyroot-setinputtrees-fails/52426/4 "2022-12-01T18:27:40Z")

</div>

I wrote that the last snippet in my question loads all events twice.  
Actually, it doesn’t; it does so only at BookMethod, but the training uses the dataset only once. So I am using that solution, ie. separate loading.
