# ROOT TMVA filling histogram error

**URL:** <https://root-forum.cern.ch/t/root-tmva-filling-histogram-error/63793>\
**Category:** TMVA\
**Tags:** root\
**Created:** [June 24, 2025, 1:27pm UTC](https://root-forum.cern.ch/t/root-tmva-filling-histogram-error/63793 "2025-06-24T13:27:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahuang](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@ahuang](https://root-forum.cern.ch/u/ahuang)\
**Post date:** [June 24, 2025, 1:27pm UTC](https://root-forum.cern.ch/t/root-tmva-filling-histogram-error/63793/1 "2025-06-24T13:27:02Z")

</div>

Hello experts,

I’ve been having issues getting my TMVA BDT to work. Currently, there is a final fatal error due to the number of entries somehow being \<=0. I’ve also been having issues where certain entries are having an input issue, which I’m not sure how to resolve. As far as I know, there should not be nan values for the BDT input variables, but other variables within the TTree may have nan values. How should these be resolved? I’ve attached a google docs link with access to the input root files and the terminal output I currently get as follows, as these files are too large to upload here.

> **[root – Google Drive](https://drive.google.com/drive/folders/1MJGCoONCqVWHv26Q2m6HoTTOSFwAkuV4?usp=sharing)**

* * *

_ROOT Version:_ 6.26/14  
_Platform:_ Red Hat Enterprise Linux 9 v9.6  
_Compiler:_ gcc (GCC) 14.1.0

* * *

[Bzptn\_e\_belle\_tmva.C](https://root-forum.cern.ch/uploads/short-url/eVPno2qwSc6NRQTwqX42gLiUt7Q.C) (4.8 KB)

 ![TMVA ROOT Error](https://root-forum.cern.ch/uploads/default/original/3X/d/f/dfe794dcd6a5a6b64c00f97a7a05db96134f7f63.png)  
 ![TMVA ROOT Write Error](https://root-forum.cern.ch/uploads/default/original/3X/c/0/c05f5fa21b2cdb85f33a8c002889cf799b56f97e.png)

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [June 24, 2025, 2:20pm UTC](https://root-forum.cern.ch/t/root-tmva-filling-histogram-error/63793/2 "2025-06-24T14:20:47Z")

</div>

Put the creation of the output file (where you want to write the new tree(s)) _after_ opening other (input) files; basically, TTrees (and other ROOT objects) belong to the _last_ TFile you have opened by the point where you create the TTree, etc.; you can change that but in this case you can simply move the lines as I mentioned:

```auto
//...
    // Activate TMVA
    TMVA::Tools::Instance();

    // Open input file
    TFile* inputFile_train = TFile::Open("SLptn_e_mix_sig_train_belle.root");
    TFile* inputFile_test = TFile::Open("SLptn_e_mix_sig_test_belle.root");

    // to get access to the GUI and all tmva macros
    //TString tmva_dir(TString(gRootDir) + "/tmva");
    //if(gSystem->Getenv("TMVASYS"))
    // tmva_dir = TString(gSystem->Getenv("TMVASYS"));
    //gROOT->SetMacroPath(tmva_dir + "/test/:" + gROOT->GetMacroPath() );
    //gROOT->ProcessLine(".L TMVAGui.C");

    // Output file for TMVA
    TString outfileName(filename);
    TFile* outputFile = TFile::Open( outfileName, "RECREATE" );
//...

```

---

<div class="post-metadata">

**Author:** ![ahuang](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@ahuang](https://root-forum.cern.ch/u/ahuang)\
**Post date:** [June 25, 2025, 12:24am UTC](https://root-forum.cern.ch/t/root-tmva-filling-histogram-error/63793/3 "2025-06-25T00:24:14Z")

</div>

Thanks, this has worked to solve the problem!
