Modify TPaveStat

Hi !

I am trying to superpose two histogram that I extract from a TTree with a selection. I achieved to display the superposed histograms in the same Canvas, the problem is that the TPaveStats box display only one mean and one StdDev.
I would like to display the means both of the first histogram and the second (in the TPaveStats box). I tried to implement and run the ROOT website tutorial about TPaveStat modification but nothing change except the TPaveStats name…

TFile f("total.root");
    if (f.IsZombie()) {
        cout << "Error, no file total.root in /analyse" << endl;
        exit(-1);
    } else {
        TTree *T = (TTree*)f.Get("mytree");
TCanvas *c2 = new TCanvas("c2","Flux Analogue & Biaised vs energy");
            c2->cd();
            T->Draw("flux:energy","flag","prof CLP");
            T->GetHistogram()->SetTitle("Flux Biased");
            T->SetLineColor(kRed);
            T->GetHistogram()->GetYaxis()->SetTitle("#Phi");
            T->GetHistogram()->GetXaxis()->SetTitle("E(MeV)");
            gPad->Update();
            T->Draw("flux:energy","!flag && score==1","prof SAME CLP");
            T->GetHistogram()->SetTitle("Flux Analogue");
            T->SetLineColor(kBlue);
            T->GetHistogram()->GetYaxis()->SetTitle("#Phi");
            T->GetHistogram()->GetXaxis()->SetTitle("E(MeV)");
            gPad->BuildLegend(0.6,0.4,09,0.6,"","PL");
            
            // Retrieve the stat box
            TPaveStats *ps = (TPaveStats*)c2->GetPrimitive("stats");
            ps->SetName("mystats");
            TList *listOfLines = ps->GetListOfLines();
            
            // Add a new line in the stat box.
            TLatex *myt = new TLatex(0,0,"Test = 10");
            myt->SetTextFont(42);
            myt->SetTextSize(0.04);
            myt->SetTextColor(kRed);
            listOfLines->Add(myt);
            
            // the following line is needed to avoid that the automatic redrawing of stats
            T->GetHistogram()->SetStats(0);
            c2->Modified();
}

Could you tell me what I did wrong ?
Thanks greatly.


Post a small “standalone reproducer”, which one can run (i.e., including any ROOT files that are needed).

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