I am drawing a few histograms on the same canvas. By default, the title of the whole plot, is the name of the first histogram. What I want to do is change it to something different, for instance “Plot” instead of “Experimental” on the following image. I want to do that ONLY on the title and not on the legend.
I’ve thought of adding a TPaveText on top of the title but I can’t seem to be able to draw it. Is there to change the title of the plot without having to change the histogram’s name?
Thank’s in advance.
My code is
#include "Riostream.h"
void HistogramFromAscii(){//(char * file_c) {
gROOT->SetStyle("Plain");
gStyle->SetOptStat(0000);
gStyle->SetOptFit(1111);
TPaveText *t=new TPaveText(0.8,0.8,1,1,"brNDC");
TCanvas *c = new TCanvas("c", "c");
c->SetFillColor(5);
c->SetFrameFillColor(10);
TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
dir.ReplaceAll("HistogramFromAscii.C","");
dir.ReplaceAll("/./","/");
ifstream in;
in.open(Form("%sZnF2_2600_170_Jesus.dat",dir.Data()));
Float_t x,y,z,w,k,l;
Int_t nlines = 0;
//TFile *f = new TFile("HistogramFromAscii.root","RECREATE");
TH1F *h1 = new TH1F("h1","Experimental",1024,1,1024);
TH1F *h2 = new TH1F("h2","Total SImulated",1024,1,1024);
TH1F *h3 = new TH1F("h3","Fluorine, Jesus et al.",1024,1,1024);
TH1F *h4 = new TH1F("h4","Zn, Rutherford",1024,1,1024);
TH1F *h5 = new TH1F("h5","Au, Rutherford",1024,1,1024);
//TNtuple *ntuple = new TNtuple("ntuple","data from ascii file","x:y:z");
while (1) {
in >> x >> y >> z >> w >> k >> l;
if (!in.good()) break;
if (nlines < 5) printf("x=%8f, y=%8f\n",x,y);
h1->Fill(x,y);
h2->Fill(x,z);
h3->Fill(x,w);
h4->Fill(x,k);
h5->Fill(x,l);
//ntuple->Fill(x,y,z);
nlines++;
}
printf("Found %d points\n",nlines);
in.close();
h1->SetLineColor(kRed);
h1->SetLineWidth(4);
h1->GetXaxis()->SetRangeUser(0,750);
h1->Draw();
h2->SetLineColor(kBlue);
h2->SetLineWidth(2);
h2->Draw("same");
h3->SetLineColor(kMagenta+1);
h3->SetLineWidth(2);
h3->Draw("same");
h4->SetLineColor(kGreen+3);
h4->SetLineWidth(2);
h4->Draw("same");
h5->SetLineColor(kBlack);
h5->SetLineWidth(2);
h5->Draw("same");
t->AddText("hola");
t->Draw();
TLegend *leg = c->BuildLegend();
//return c;
//leg->SetFillStyle(0);
//c->SetLogy();
//c->SaveAs("alpha_in_Si.pdf");
}