const UInt_t nNumbers = 20000000U; const UInt_t nWorkers = 4U; auto workItem = [](UInt_t workerID) { // One generator, file and ntuple per worker TRandom3 workerRndm(workerID); // Change the seed TFile f(Form("myFile_mp001_%u.root", workerID), "RECREATE"); TH1F h(Form("myHisto_%u", workerID), "The Histogram", 64, -4, 4); for (UInt_t i = 0; i < nNumbers; ++i) { h.Fill(workerRndm.Gaus()); } h.Write(); return 0; }; ROOT::TProcessExecutor workers(nWorkers); workers.Map(workItem, ROOT::TSeqI(nWorkers)); return 0;