Histogram ROOT MACRO

I am not able to change the title of histogram.I have drawn four histograms in same canvas.i am giving here the code too.

void ravu()
{
    gStyle->SetOptTitle(0);
    gStyle->SetOptTitle(3); // set hist title "Different PLots"
    
    
    
    b1->SetLineColor(1);
    b2->SetLineColor(2);
    b3->SetLineColor(3);
    b4->SetLineColor(4);
    
    b1->SetLineWidth(2);
    b2->SetLineWidth(3);
    b3->SetLineWidth(4);
    b4->SetLineWidth(5);
    
    b1->GetXaxis()->SetRangeUser(0,9000);
    b1->Draw("HIST");
    b2->Draw("same HIST");
    b3->Draw("same HIST");
    b4->Draw("same HIST");
    b1->GetXaxis()->SetTitle("Energy(KeV)");
    b1->GetYaxis()->SetTitle("P(E)");
    b1-> GetXaxis()-> SetTitleSize(0.050);
    b1-> GetYaxis()-> SetTitleSize(0.050);
    b1-> GetXaxis()-> SetTitleOffset(1.048); 
    b1-> GetYaxis()-> SetTitleOffset(1.048);
    auto legend = new TLegend(0.6,0.7,0.48,0.9);
    legend->AddEntry(b1,"b1","l");
    legend->AddEntry(b2,"b2","l");
    legend->AddEntry(b3,"b3","l");
    legend->AddEntry(b4,"b4","l");
    legend->Draw();
    
    
}

What are b1, b2, b3, and b4 (what type)?

These are different histograms ,my mentor has given me this file already created and want me to do this work ,like giving title,labelling axis etc.

b1->Draw("HIST");

Will define the title of your plot. What is the Title of b1 ?

root [0] b1->GetTitle()
1 Like

So it’s (for example) b1->SetTitle("My Title"). Take a look at the TH1F Documentation

its not working.U run this macro and then see what type of errors it is showing

x-special/nautilus-clipboard
copy
file:///home/ravu/Downloads/c1.pdf

x-special/nautilus-clipboard
copy
file:///home/ravu/Downloads/response_all.root
check this.from this file u can get b1,b2,b3…

What you did doesn’t work

May I suggest you to start with Get Started, the ROOT Primer, and the many tutorials?

1 Like

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