# Multi-threaded output of TH\* histograms via TBufferMerger

**URL:** <https://root-forum.cern.ch/t/multi-threaded-output-of-th-histograms-via-tbuffermerger/64089>\
**Category:** ROOT\
**Tags:** hist\
**Created:** [August 28, 2025, 9:59pm UTC](https://root-forum.cern.ch/t/multi-threaded-output-of-th-histograms-via-tbuffermerger/64089 "2025-08-28T21:59:44Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![crafter312](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crafter312/32/36890_2.png) [@crafter312](https://root-forum.cern.ch/u/crafter312)\
**Post date:** [August 28, 2025, 9:59pm UTC](https://root-forum.cern.ch/t/multi-threaded-output-of-th-histograms-via-tbuffermerger/64089/1 "2025-08-28T21:59:46Z")

</div>

_ROOT Version:_ 6.30/08  
_Platform:_ AlmaLinux 8.10  
_Compiler:_ GNU 8.5.0 via CMake 3.26.5

* * *

I am writing a program which uses `TTreeProcessorMT` for multi-threaded processing of an input tree and `TBufferMerger` for output in this multi-threaded context. I can easily create a `TTree` and fill it from multiple threads. This works, and I have done this a few different times already.

However, when I try to create and fill a `TH1I` histogram alongside the tree, **it fails to appear in the output file**. As far as I’m aware, I should just be able to create and fill the histogram in the same way as I do for the tree, at least this is what I would do for a normal `TFile`:

```cpp
auto f = merger.GetFile();
TTree t(“t”, “t”);
t.Branch(“whatever”, &whatever);

TH1I h(“h”, “h”, 100, -1., 1.);

```

I would think it should be simple for a TBufferMerger to merge histograms from different threads by just adding them, so I am confused as to why this doesn’t work. Additionally, I found a [sort of related thread](https://root-forum.cern.ch/t/thread-safe-fill-of-same-tree-and-histograms-from-different-synchronized-threads/55258/3) which implies that this should be possible. Is there some detail that I’m missing here, or some other solution/workaround?

I created a little macro to replicate this issue, and tried to keep the general framework of how my larger program works. It requires a ROOT file as input, the file path for which is specified in the program, but it doesn’t matter what file is used.

[tbuffermerger\_hist.C](https://root-forum.cern.ch/uploads/short-url/monYZUajFv44FKsDETp2KbBc0lx.C) (1.3 KB)

---

_[View the full topic](https://root-forum.cern.ch/t/multi-threaded-output-of-th-histograms-via-tbuffermerger/64089)._
