You are here

10. Go Parallel!

Why you care

Number crunching takes time. If you look at top (open a terminal, type top) in Linux or your activity monitor on MacOS you will see that one core is really really busy with root. But only one core - and you have two or four or if you're lucky even more. What about getting much more data crunched in the same time, or reducing the arrival time of your analysis results by factors? TSelector

ROOT offers Proof lite - multiple ROOT processes "hacking away" on the same analysis. For that to work your analysis must be written using the TSelector interface: it must publicly derive from it and implement SlaveBegin() where you create the histograms, Process(Long64_t entry) to process the data, and Terminate() to do fits etc. You can find an example for using a TTreeReader within a TSelector here; try to adapt to to our tree and our efficiency determination. TChain

Proof lite will run the TSelector on several input files in parallel - actually, it chunks the input (even of one file) and sends these chunks to worker processes. You can combine TTrees from multiple files (if they have the same name and structure) using a TChain:

TChain* chain = new TChain("MyTree");
chain->AddFile("http://root.cern.ch/root/files/tutorials/mockupx.root");
chain->AddFile("http://root.cern.ch/root/files/tutorials/mockupx_1.root");
chain->AddFile("http://root.cern.ch/root/files/tutorials/mockupx_2.root");
chain->AddFile("http://root.cern.ch/root/files/tutorials/mockupx_3.root");
chain->Process("MySelector.C+"); // if you have put your selector from above into MySelector.C

The last line will run the selector on the whole chain. O - but that takes ages! We need to: Enable Proof Lite There are two parts to using Proof lite: you need to create an instance and you need to tell the chain to use that instance:

// Create a Proof-lite instance:
TProof::Open("");
// tell the chain that we want to use PROOF
chain->SetProof();
// And this will now use all your cores!
chain->Process("MySelector.C+");

Spoiler: here is the solution!