Unstable results when enabling MT and filling a THnD histogram using Take

Hi @Javier_Galan,

I’ve been testing your reproducer and I do see the same problem, but for now I don’t have a direct solution for your exact method with Take and manual Fill. Is there a reason why you want to use Take and manual Fill?

However, I have also tested what @eguiraud suggested and the histogram filling looks stable and consistent, I tested both with bin contents and plotting the 3D histogram, see attached.

Int_t testMT( Bool_t mt )
{
    TCanvas cv;

    if( mt ) ROOT::EnableImplicitMT();
    ROOT::RDataFrame df("AnalysisTree", "AnalysisTree10M.root");

    Int_t* bins = new Int_t[3];
    Double_t* xmin = new Double_t[3];
    Double_t* xmax = new Double_t[3];

    for (size_t n = 0; n < 2; n++) {
        bins[n] = 80;
        xmin[n] = -20;
        xmax[n] = 20;
    }
    bins[2] = 100;
    xmin[2] = 0;
    xmax[2] = 10;

    auto myhisto = df.Histo3D({"sparse", "sparse", 80, -20, 20, 80, -20, 20, 100, 0, 10}, "final_posX", "final_posY", "final_energy");

    std::cout << "Bin contents: " << myhisto->GetBinContent(40 , 40, 50) << std::endl;
    auto c_mc = new TCanvas("c_mc", " ", 600, 600);
    myhisto->Draw();
    c_mc->SaveAs("test3dhisto_true1.png");

    return 0;
}

Cheers,
Marta