Fitting text and numbers into a statistics box properly

Hello,

I am drawing 8 histograms on one page of a ps file. In the stats box of each histogram I
have printed a title, the number of entries, the mean and the rms.

The problem is that there is a large amount of white space between the text and the
numbers leading to the problem of the numbers being outside the stats box.
No amount of font resizing and stat box size/position adjusting seems to
solve the problem. Is there any way to tell root to put the numbers
actually inside the stats box instead of half in and half out?

Thanks,

Mark

Can you send a little macro showing the problem ?

Thanks, Olivier

Hello,

My code does the following:

#includeSetUp.cc

void DrawNtrk(){

SetUp();

TFile data("");
TFile mc1("");//and so on up to filename 8

TPostScript ps1("");
TPostScript *PS1 = &ps1;

TLine * l;

TCanvas *can = new TCanvas();

can->Divide(2,4);//I experimented and things work fine with divide(2,1) but moving to two rows (2,2) introduces the problem I have

TH1D* dataNtrk = (TH1D*)data.Get(“ntrk;1”);

dataNtrk->SetTitle("Data");
dataNtrk->Draw();
gPad->Update();
TPaveText *title = (TPaveText*)gPad->GetPrimitive("title");
title->SetX1NDC(0.4);
title->SetX2NDC(0.<img src="/uploads/default/original/1X/fe5f42ae79e389360ae9d969db4dcc4bca03d384.gif" width="15" height="17" alt="8)" title="Cool"/>;

l = new TLine(4, 0, 4, (Int_t)dataNtrk->GetBinContent(5) ); l->SetLineColor(kRed);            
l->Draw();
l = new TLine(5, 0, 5, (Int_t)dataNtrk->GetBinContent(5) );  l->SetLineColor(kRed);    l
l->Draw();

can->cd(2);
TH1D* bbNtrk =(TH1D*)bb.Get(“ntrk;1”);
bbNtrk->SetTitle(“BB MC”);
bbNtrk->Draw();
l = new TLine(4, 0, 4, bbNtrk->GetBinContent(5)); l->SetLineColor(kRed); l->Draw();
l = new TLine(5, 0, 5, bbNtrk->GetBinContent(5)); l->SetLineColor(kRed); l->Draw();
//and the same for remainig 6 sub-canvases and remaing 6 files

ps1.Close();

}

SetUp contains:

#ifndef SetUp_h
#define SetUp_h
//
#include <TROOT.h>
#include <TStyle.h>
#include <iostream.h>
// Set up the root environment
void SetUp(){
cout << "SetUp Plain " << endl;
gROOT->SetBatch(kTRUE);
gROOT->SetStyle(“Plain”);
gStyle->SetStatW(0.6);
gStyle->SetStatH(1.0);
gStyle->SetStatY(0.975);
gStyle->SetStatStyle(0);
gStyle->SetStatTextColor(4);
gStyle->SetStatFontSize(0.04);
gStyle->SetTitleH(0.08);
gStyle->SetTitleX(0.1);
gStyle->SetTitleY(0.98);
gStyle->SetTitleStyle(0);
gStyle->SetLabelSize(0.05,“x”);
gStyle->SetTitleSize(0.07,“x”);
gStyle->SetLabelSize(0.05,“y”);
gStyle->SetTitleSize(0.07,“y”);
gStyle->SetLabelSize(0.05,“z”);
gStyle->SetTitleSize(0.07,“z”);
gStyle->SetNdivisions(510,“x”);
gStyle->SetNdivisions(505,“y”);
gStyle->SetOptFit();
}
#endif

It seems the problem is somehow caused when I use more than 2 sub-canvases in the canvas. With less than or 2 sub-canvases the stats inforrmation fits in the stats box. With more than 2 sub-canvases the stats information does not fit into the stats box anymore for every sub-canvas I draw on.

Thanks,

Mark

Thanks for your macro but I cannot execute it because data files are missing. Can you, either provide me the data files or a runable macro showing the problem.

Thanks in advance.

PS: when you post some code do it as “code” not as plain text otherwise some parts of your text are interpreted as “Emoticons”. You can also click “Disable Smilies in this post” or even better put the code as an attachement.

Hi,

I have put a demo file at:

hep.man.ac.uk/u/markhod/test.root
hep.man.ac.uk/u/markhod/test.ps

the ps file shows the output and the problem, which doesnt seem to be solvd by resizing the stats box or moving it etc.

I have attached a demo macro that illustrates the problem. (just download the above root file and change the relevant line to in the macro to read it) and the macro will reproduce the ps file.

I am using the root 3.10/01 (for gcc 2.95.3) version.

Thanks,

Mark

Hi,

Looks I forgot to add the attachment.

hmm. I added it but it doesnt appear. I guess I’ll have to put it in the message:

void Draw(){

TFile file("/afs/slac.stanford.edu/u/br/markhod/test.root");

TPostScript ps1("/afs/slac.stanford.edu/u/br/markhod/test.ps", 111);
TPostScript *PS1 = &ps1;

TLine * l;

TCanvas can = new TCanvas();
can->Divide(2,2);
can->cd(1);
TH1D
histo = (TH1D*)file.Get(“Hist;1”);
histo->Draw();
gPad->Update();
l = new TLine(4, 0, 4, (Int_t)histo->GetBinContent(5) ); l->SetLineColor(kRed); l->Draw();
l = new TLine(5, 0, 5, (Int_t)histo->GetBinContent(5) ); l->SetLineColor(kRed); l->Draw();
can->cd(2);
histo->Draw();
gPad->Update();
l = new TLine(4, 0, 4, (Int_t)histo->GetBinContent(5) ); l->SetLineColor(kRed); l->Draw();
l = new TLine(5, 0, 5, (Int_t)histo->GetBinContent(5) ); l->SetLineColor(kRed); l->Draw();
can->cd(3);
histo->Draw();
gPad->Update();
l = new TLine(4, 0, 4, (Int_t)histo->GetBinContent(5) ); l->SetLineColor(kRed); l->Draw();
l = new TLine(5, 0, 5, (Int_t)histo->GetBinContent(5) ); l->SetLineColor(kRed); l->Draw();
can->cd(4);
histo->Draw();
gPad->Update();
l = new TLine(4, 0, 4, (Int_t)histo->GetBinContent(5) ); l->SetLineColor(kRed); l->Draw();
l = new TLine(5, 0, 5, (Int_t)histo->GetBinContent(5) ); l->SetLineColor(kRed); l->Draw();

ps1.Close();

}

The attached macro is working
test.C (1.11 KB)

Hi,

Yes, this works great! Thank you very much.

I wondered why it is neccessary to open the ps file after the TCanvas is instantiated instead of before the instantiaiton of the TCanvas as I had written in the code originally?

Thanks,

Mark

To have the canvas size properlly set