Cannot rewrite to an existing histogram


I have two histograms named h0 and h1, which were created like this:


I also wrote this method to plot them:

void PlotHists(TH1F* h1, TH1F* h2, TString title, TString name1 = "Uncut", TString name2 = "Cut")
	h1->SetName(name1); h2->SetName(name2);
	h1->SetNormFactor(1); h2->SetNormFactor(1); 
    h1->SetLineColor(kRed); h2->SetLineColor(kBlue); 
    h1->SetTitle(title); h1->Draw(); gPad->Update();
	TPaveStats* s = (TPaveStats*)h1->GetListOfFunctions()->FindObject("stats"); 
    s->SetY1NDC(0.65); s->SetY2NDC(0.40); s->SetX1NDC(0.98); s->SetX2NDC(0.65); 
	s->SetLineColor(kRed); s->SetTextSize(.05); 
	h2->Draw("sames"); gPad->Update(); 
    TPaveStats* s = (TPaveStats*)h2->GetListOfFunctions()->FindObject("stats"); 
    s->SetY1NDC(0.92); s->SetY2NDC(0.67); s->SetX1NDC(0.98); s->SetX2NDC(0.65);
	s->SetLineColor(kBlue); s->SetTextSize(.05);

This method works great.
However, when I now try to rewrite these histograms


and plot them using the same module, I notice that the plots does not change.

Thank you!

Add parentheses:


Otherwise you keep the old binning.

Edit: also, I find it strange that you rename the histograms in a plot function. Why would you do that? So I don’t know if my advice of using parens is what you really want or if renaming is your problem.

Thank you! it worked!
I’m changing the name so that statbox’s name would also change.

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