# TFoam error?

**URL:** <https://root-forum.cern.ch/t/tfoam-error/64492>\
**Category:** Roofit and RooStats\
**Created:** [November 29, 2025, 2:01pm UTC](https://root-forum.cern.ch/t/tfoam-error/64492 "2025-11-29T14:01:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vikas\_Raj](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vikas_raj/32/34682_2.png) [@Vikas\_Raj](https://root-forum.cern.ch/u/Vikas_Raj)\
**Post date:** [November 29, 2025, 2:01pm UTC](https://root-forum.cern.ch/t/tfoam-error/64492/1 "2025-11-29T14:01:21Z")

</div>

Dear experts,

I am generating toys using **TFoam** inside a **multiprocessing** setup (running many toys in parallel). The job _finishes_ and the output ROOT files are created correctly, but during the run TFoam prints many errors such as:

```auto
Error in <TFoam::Carver>: Something wrong with kBest - kBest = -1 dim = 5
STOP in TFoam::PeekMax: not found iCell = -1
Error in <TFoam::Grow>: Wrong iCell

```

These messages appear repeatedly, even though the final toy ROOT file looks properly formed.

When I run the exact same code in single-process mode, I do not see any TFoam errors. The problem only shows up when using multiprocessing.

So I would like to ask:

```auto
Is TFoam thread-safe or multiprocessing-safe?

Does each worker need its own fully independent TFoam instance and RNG?

Can these “kBest = -1” messages be ignored if the output file is okay, or do they indicate a deeper consistency issue?

Is there a recommended way to use TFoam safely in parallel toy production?

```

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [December 1, 2025, 8:25am UTC](https://root-forum.cern.ch/t/tfoam-error/64492/2 "2025-12-01T08:25:52Z")

</div>

I guess @jonas can help you.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [December 15, 2025, 8:26am UTC](https://root-forum.cern.ch/t/tfoam-error/64492/3 "2025-12-15T08:26:03Z")

</div>

Closed on December 15, 2025, 8:26am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
