Mtbb 0 0 1_Fill Histos

Fill histograms in parallel and write them on file. This example expresses the parallelism of the mt001_fillHistos.C tutorial with multiprocessing techniques.

Author: Danilo Piparo
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, February 24, 2021 at 09:35 AM.

Total amount of numbers

In [1]:
const UInt_t nNumbers = 20000000U;

The number of workers

In [2]:
const UInt_t nThreads = 4U;

We define our work item

In [3]:
auto workItem = [](UInt_t workerID) {
   // One generator, file and ntuple per worker
   TRandom3 workerRndm(workerID); // Change the seed
   TFile f(Form("myFile_mtbb001_%u.root", workerID), "RECREATE");
   TH1F h(Form("myHisto_%u", workerID), "The Histogram", 64, -4, 4);
   for (UInt_t i = 0; i < nNumbers; ++i) {
   return 0;

Create the pool of threads

In [4]:
ROOT::TThreadExecutor pool(nThreads);

Fill the pool with work

In [5]:
pool.Map(workItem, ROOT::TSeqI(nThreads));
return 0;

Draw all canvases

In [6]: