# Segmentation fault with TMVA in ROOT 6.13

**URL:** <https://root-forum.cern.ch/t/segmentation-fault-with-tmva-in-root-6-13/31835>\
**Category:** TMVA\
**Created:** [November 30, 2018, 4:53pm UTC](https://root-forum.cern.ch/t/segmentation-fault-with-tmva-in-root-6-13/31835 "2018-11-30T16:53:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![tisol](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@tisol](https://root-forum.cern.ch/u/tisol)\
**Post date:** [November 30, 2018, 4:53pm UTC](https://root-forum.cern.ch/t/segmentation-fault-with-tmva-in-root-6-13/31835/1 "2018-11-30T16:53:27Z")

</div>

Hello,

I have a segmentation fault problem when running a multivariate classification in 6.13. The algorithm training works without problems, but when it comes to using the trained algorithms to classify new data the program crashes every time.

I upload two files: the first is the ROOT macro I use for the classification; I checked it thoroughly, and all paths seem to lead to existing files. The second file is the stack trace of the crash, including the terminal output before the crash.

I would really appreciate any hint to a solution, as I am pretty clueless as to how I could solve this.

[Classification1\_1.C](https://root-forum.cern.ch/uploads/default/original/3X/a/e/aeaa4d430d1a02a2c518a6e31074d7348354a18b.C) (4.8 KB)  
[stack-trace.txt](https://root-forum.cern.ch/uploads/default/original/3X/d/3/d33fe8dbd73e0235be1f43d33f6b19cbfa7c2ddb.txt) (3.0 KB)

---

<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:** [November 30, 2018, 5:16pm UTC](https://root-forum.cern.ch/t/segmentation-fault-with-tmva-in-root-6-13/31835/2 "2018-11-30T17:16:23Z")

</div>

Hi,

Try using this as your event loop:

```auto
for (Long64_t iEvent=0; iEvent < theTree->GetEntries(); ++iEvent) {
    if (iEvent%1000 == 0) {
        std::cout << "--- ... Processing event: " << iEvent << std::endl;
    }

    theTree->GetEntry(iEvent);
      
    Pp_px = dPp_px; Pp_py = dPp_py; Pp_pz = dPp_pz; Pp_e=dPp_e; Pm_px=dPm_px;
    Pm_py = dPm_py; Pm_pz = dPm_pz; Pm_e = dPm_e;
    gamma_px = dgamma_px; gamma_py=dgamma_py; gamma_pz = dgamma_pz;
    gamma_e = dgamma_e;

    histBDT->Fill(reader->EvaluateMVA("BDT2"));
}

```

Basically, the way you set up your script is that data is read from the TTree into the variables `d*` (`dPp_px` etc). TMVA itself is setup to read data from the variables lacking the d prefix (`Pp_px` etc). However, data was never transferred between the two sets of variables.

This _should_ explain why TMVA choked on the input. Please try it out and get back to us!

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![tisol](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@tisol](https://root-forum.cern.ch/u/tisol)\
**Post date:** [November 30, 2018, 5:19pm UTC](https://root-forum.cern.ch/t/segmentation-fault-with-tmva-in-root-6-13/31835/3 "2018-11-30T17:19:54Z")

</div>

Thank you for your quick reply. That is indeed something I did’t think of; unfortunately, it doesn’t seem to change much: the program still crashes at the same point.

---

<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:** [November 30, 2018, 5:24pm UTC](https://root-forum.cern.ch/t/segmentation-fault-with-tmva-in-root-6-13/31835/4 "2018-11-30T17:24:05Z")

</div>

Can you run the TMVAClassificationApplication.C example successfully? Use:

```auto
root -l -b -q "$ROOTSYS/tutorials/tmva/TMVAClassificationApplication.C(\"BDTG\")"

```

(You might have to run `root -l -b -q $ROOTSYS/tutorials/tmva/TMVAClassification.C(\"BDTG\")"`) first to ensure all required files are generated.)

---

<div class="post-metadata">

**Author:** ![tisol](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@tisol](https://root-forum.cern.ch/u/tisol)\
**Post date:** [November 30, 2018, 5:25pm UTC](https://root-forum.cern.ch/t/segmentation-fault-with-tmva-in-root-6-13/31835/5 "2018-11-30T17:25:07Z")

</div>

Yes, no problems with that! In fact I used it as a guideline to create my macro.

---

<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:** [November 30, 2018, 5:30pm UTC](https://root-forum.cern.ch/t/segmentation-fault-with-tmva-in-root-6-13/31835/6 "2018-11-30T17:30:13Z")

</div>

I think the next step is to figure out where exactly things go wrong in your script. You can use something like this.

```auto
for (Long64_t iEvent=0; iEvent < theTree->GetEntries(); ++iEvent) {
    std::cout << "Checkpoint 1" << std::endl;
    theTree->GetEntry(iEvent);

    std::cout << "Checkpoint 2" << std::endl;
    Pp_px = dPp_px; Pp_py = dPp_py; Pp_pz = dPp_pz; Pp_e=dPp_e; Pm_px=dPm_px;
    Pm_py = dPm_py; Pm_pz = dPm_pz; Pm_e = dPm_e;
    gamma_px = dgamma_px; gamma_py=dgamma_py; gamma_pz = dgamma_pz;
    gamma_e = dgamma_e;

    std::cout << "Checkpoint 3" << std::endl;
    auto mva_output = reader->EvaluateMVA("BDT2");

    std::cout << "Checkpoint 4" << std::endl;
    histBDT->Fill(mva_output);
}

```

If checkpoints 1-4 are printed, the problem is external to TMVA. If any are not printed we need to dig deeper.

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![tisol](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@tisol](https://root-forum.cern.ch/u/tisol)\
**Post date:** [November 30, 2018, 5:36pm UTC](https://root-forum.cern.ch/t/segmentation-fault-with-tmva-in-root-6-13/31835/7 "2018-11-30T17:36:53Z")

</div>

All checkpoints are printed multiple times. I guess as you said the problem is external to TMVA.

---

<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:** [November 30, 2018, 5:47pm UTC](https://root-forum.cern.ch/t/segmentation-fault-with-tmva-in-root-6-13/31835/8 "2018-11-30T17:47:26Z")

</div>

What about the last iteration just before the crash; Are all checkpoints printed then as well?

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![tisol](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@tisol](https://root-forum.cern.ch/u/tisol)\
**Post date:** [December 4, 2018, 8:44am UTC](https://root-forum.cern.ch/t/segmentation-fault-with-tmva-in-root-6-13/31835/9 "2018-12-04T08:44:23Z")

</div>

They are all printed, yes! After printing the last “Checkpoint 4” string the program halts for a moment and then crashes.

---

<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:** [December 4, 2018, 9:34am UTC](https://root-forum.cern.ch/t/segmentation-fault-with-tmva-in-root-6-13/31835/10 "2018-12-04T09:34:43Z")

</div>

Then I suggest you take a look at you histogram. What number is it trying to fill it with when it crashes?

---

<div class="post-metadata">

**Author:** ![tisol](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@tisol](https://root-forum.cern.ch/u/tisol)\
**Post date:** [December 5, 2018, 12:22pm UTC](https://root-forum.cern.ch/t/segmentation-fault-with-tmva-in-root-6-13/31835/11 "2018-12-05T12:22:52Z")

</div>

I post here the full output up until right before the crash. Apparently the last number which is filled in is -0.807566, which does not appear to me to have any special significance. Both lower and higher numbers were filled in before.  
[Terminal output.txt](https://root-forum.cern.ch/uploads/default/original/3X/f/0/f0edafca1e580aa9d6bb7ad744ceac5dcbb79021.txt) (22.4 KB)
