Hello All,
I am trying to plot 3 text files as 1-D histograms. I can open one text file and make a histogram but cannot figure out how to make an over plot. Can any one give me some hints about hot I can over plot with suitable legends in the plot.
Here is what I have for reading just one file. I have 3 files 18.txt, 20.txt and 22.txt and I want all of them on the same plot for comparison purposes.
[code]{
gROOT->Reset();
TH1F *AxialSensitivityDet = new TH1F(“AxialSensitivityDet”,“Axial sensitivity”,50,-100.,+100.);
Int_t runID;
Float_t z;
FILE *out;
out=fopen(“18.txt”,“r”);
while(!feof(out)){
fscanf(out,"%f",&z);
//printf("%f\n",z);
AxialSensitivityDet->Fill(z);
}
fclose(out);
AxialSensitivityDet->Draw();
}[/code]
UPDATE: I messed about and got it working:
{
gROOT->Reset();
TCanvas *c1 = new TCanvas("c1","Axial Sensitivity",200,10,600,400);
//TCanvas *c2 = new TCanvas("c2","Two Graphs",200,10,600,400);
TH1F *AS18 = new TH1F("AS18","Axial sensitivity",50,-100.,+100.);
TH1F *AS20 = new TH1F("AS20","Axial sensitivity",50,-100.,+100.);
TH1F *AS22 = new TH1F("AS22","Axial sensitivity",50,-100.,+100.);
Float_t z;
FILE *out;
out=fopen("18.txt","r"); while(!feof(out)) { fscanf(out,"%f",&z); AS18->Fill(z); } fclose(out);
out=fopen("20.txt","r"); while(!feof(out)) { fscanf(out,"%f",&z); AS20->Fill(z); } fclose(out);
out=fopen("22.txt","r"); while(!feof(out)) { fscanf(out,"%f",&z); AS22->Fill(z); } fclose(out);
AS22->GetXaxis()->SetTitle("Axial position (mm)");
AS22->GetYaxis()->SetTitle("Counts");
AS22->SetFillColor(1);AS22->SetMarkerStyle(23); AS22->SetMarkerColor(1);AS22->Draw();
AS20->SetFillColor(2);AS20->SetMarkerStyle(22); AS20->SetMarkerColor(2);AS20->Draw("same");
AS18->SetFillColor(3);AS18->SetMarkerStyle(21); AS18->SetMarkerColor(3);AS18->Draw("same");
TLegend *legend = new TLegend(.75,.80,.95,.95);
legend->AddEntry(AS18,"18 mm");
legend->AddEntry(AS20,"20 mm");
legend->AddEntry(AS22,"22 mm");
legend->Draw("same");
}
How do I remove the A22 legend (the one with the entries, Mean, RMS etc).
Thanks.