Logo ROOT  
Reference Guide
No Matches
mt304_fillHistos.C File Reference

Detailed Description

View in nbviewer Open in SWAN Fill histograms in parallel with automatic binning.

Illustrates use of power-of-two autobin algorithm

// The number of workers
const UInt_t nWorkers = 8U;
// Reference boundaries
const Double_t xmiref = -1.;
const Double_t xmaref = 7.;
Int_t mt304_fillHistos(UInt_t nNumbers = 1001)
// The first, fundamental operation to be performed in order to make ROOT
// thread-aware.
// Histograms to be filled in parallel
ROOT::TThreadedObject<TH1D> h1d("h1d", "1D test histogram", 64, 0., -1.);
ROOT::TThreadedObject<TH1D> h1dr("h1dr", "1D test histogram w/ ref boundaries", 64, xmiref, xmaref);
// We define our work item
auto workItem = [&](UInt_t workerID) {
// One generator, file and ntuple per worker
TRandom3 workerRndm(workerID); // Change the seed
auto wh1d = h1d.Get();
auto wh1dr = h1dr.Get();
for (UInt_t i = 0; i < nNumbers; ++i) {
x = workerRndm.Gaus(3.);
// Create the collection which will hold the threads, our "pool"
std::vector<std::thread> workers;
// Fill the "pool" with workers
for (auto workerID : ROOT::TSeqI(nWorkers)) {
workers.emplace_back(workItem, workerID);
// Now join them
for (auto &&worker : workers)
// Merge
auto fh1d = h1d.Merge();
auto fh1dr = h1dr.Merge();
// Make the canvas
auto c = new TCanvas("c", "c", 800, 800);
c->Divide(1, 2);
return 0;
#define c(i)
Definition RSha256.hxx:101
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
double Double_t
Definition RtypesCore.h:59
R__EXTERN TStyle * gStyle
Definition TStyle.h:413
A wrapper to make object instances thread private, lazily.
The Canvas class.
Definition TCanvas.h:23
@ kAutoBinPTwo
Use Power(2)-based algorithm for autobinning.
Definition TH1.h:173
Random number generator class based on M.
Definition TRandom3.h:27
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Definition TStyle.cxx:1589
Double_t x[n]
Definition legend1.C:17
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
void EnableThreadSafety()
Enables the global mutex to make ROOT thread safe/aware.
Definition TROOT.cxx:493
TSeq< int > TSeqI
Definition TSeq.hxx:201
November 2017
Gerardo Ganis

Definition in file mt304_fillHistos.C.