Fitting Histograms in Parallel

Hello All,

I have a desktop with multiple CPU cores.
And I have created 32 histograms (may be more in future).
How do I fit these histograms in parallel?
for now, I am looping though these 32 histograms and fitting one by one.

Thanks.


ROOT 6.28/06
ubuntu 22.04


Hi,

this task is easily solved with ROOT.
I assume that your setup, including the function being fit, is thread-unsafe: correct me if I am too pessimistic!
The tool to use is TProcessExecutor.
A simple example to get you started follows(a lot of guessing done here). Don’t hesitate to come back with additional questions if any!

Cheers,
Danilo

    // Preparation of toy histos to fit
    std::vector<TH1F> myHistos;
    for (auto idx : ROOT::TSeqI(32)) {
        myHistos.emplace_back("","",64,-4,4).FillRandom("gaus");
    }

    // end preparation of toy histos
   
    const auto nWorkers = 4;
    ROOT::TProcessExecutor pool(nWorkers);
    
    auto fitFunc = [&] (int idx) { 
        auto& h = myHistos[idx];
        return *h.Fit("gaus","0NSQ").Get();
        };

    auto myFitResults = pool.Map(fitFunc, ROOT::TSeqI(32));

    // Print results
    for (auto idx : ROOT::TSeqI(32)) {
        std::cout << "\n\nResult of fit " << idx << std::endl;
        myFitResults[idx].Print();
    }

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.