Logo ROOT   6.08/07
Reference Guide
mp102_readNtuplesFillHistosAndFit.C File Reference

Detailed Description

View in nbviewer Open in SWAN Read n-tuples in distinct workers, fill histograms, merge them and fit.

We express parallelism with multiprocessing as it is done with multithreading in mt102_readNtuplesFillHistosAndFit.

/// \date January 2016
Int_t mp102_readNtuplesFillHistosAndFit()
// No nuisance for batch execution
// Perform the operation sequentially
TChain inputChain("multiCore");
TH1F outHisto("outHisto", "Random Numbers", 128, -4, 4);
inputChain.Draw("r >> outHisto");
// We now go MP!
// TProcessExecutor offers an interface to directly process trees and chains without
// the need for the user to go through the low level implementation of a
// map-reduce.
// We adapt our parallelisation to the number of input files
const auto nFiles = inputChain.GetListOfFiles()->GetEntries();
// This is the function invoked during the processing of the trees.
auto workItem = [](TTreeReader & reader) {
auto partialHisto = new TH1F("outHistoMP", "Random Numbers", 128, -4, 4);
while (reader.Next()) {
return partialHisto;
// Create the pool of processes
ROOT::TProcessExecutor workers(nFiles);
// Process the TChain
auto sumHistogram = workers.ProcTree(inputChain, workItem, "multiCore");
sumHistogram->Fit("gaus", 0);
return 0;
Danilo Piparo

Definition in file mp102_readNtuplesFillHistosAndFit.C.