Prepare graph's visual beforehand


ROOT Version: 6.22.08 for linux
Platform: WSL Ubuntu 20
Compiler: g++


Hi all,
I would like to know if there is some ‘clear’ way to prepare visuals before I actually start my drawings.
What I am doing :
I am about to draw some histograms and TF1s on a single canvas in a loop (let’s say for example 6 TF1s and 6 histograms). For sure, I’d like to have all the stuff like fonts, offset, axes titles set, but afaik this stuff is set basing on my FIRST drawing. In my case, I believe this will lead to a code duplication, and I’d like to avoid it (let me know if it’s actually okay).

What I tried :
I tried to draw a dummy histogram (initialized with empty constructor) and apply all the settings I like to it. Apparently, none of things I did for that dummy histogram took effect (commenting its code changes nothing).

Please let me know if you know some working & nice solution to it.

Thanks in advance.

gStyle->Set...(...);

Hi,

yes, it is. Can you show an example of things not working as expected?

Hi,
Thank you for your suggestion. It seems that gStyle function signatures do not really match with those of TH1D. Some of them (for example gStyle->SetTitleX) I find really uncommon. Could you please show me how do I rewrite the following?

h[i]->SetLineWidth(2);
h[i]->GetYaxis()->SetLabelFont(43);
h[i]->GetYaxis()->SetLabelSize(26);
h[i]->GetYaxis()->SetTitleFont(43);
h[i]->GetYaxis()->SetTitleSize(33);
h[i]->GetYaxis()->SetTitleOffset(1.0);
h[i]->GetXaxis()->SetLabelFont(43);
h[i]->GetXaxis()->SetLabelSize(26);
h[i]->GetXaxis()->SetTitleFont(43);
h[i]->GetXaxis()->SetTitleSize(33);
h[i]->GetXaxis()->SetTitleOffset(0.9);
h[i]->GetXaxis()->SetTitle("E [GeV]");
h[i]->GetYaxis()->SetTitle("1/4#pipE dN/dE [GeV^{-3}]");
h[i]->GetXaxis()->SetRangeUser(low_bound, upp_bound);

Hi,
depends on what you call “not working as expected”. It will probably work if I just initialize a first histogram manually (out of a loop), but as I said I expect redundant code in that case.
Instead of doing

initialize_visuals_and_dostuff();
for(loop without 1st){
 dostuff();
}

I’d like to do this

initialize_visuals();
for(loop){
 dostuff();
}

Axes titles and ranges are specific to histograms.
Some settings are “common”, though:

// ... before creating any histograms ...
// gStyle->SetLineWidth(2);
gStyle->SetHistLineWidth(2);
gStyle->SetLabelFont(43, "XY");
gStyle->SetLabelSize(26, "XY");
gStyle->SetTitleFont(43, "XY");
gStyle->SetTitleSize(33, "XY");
gStyle->SetTitleOffset(0.9, "X");
gStyle->SetTitleOffset(1.0, "Y");
// ... you may also need ... after histograms are drawn ...
if (gPad) gPad->UseCurrentStyle();
// ... you may also need ... if you retrieve histograms from a file ...
gROOT->ForceStyle(kTRUE);

For those who were looking for an easy way :

I figured out it is actually not a problem at all to predefine visuals with some temporary histogram. For example, when I wrote

TH1D *dummy = new TH1D;//empty hist
dummy->Draw("AXIS");
dummy->SetLineWidth(2);
dummy->GetYaxis()->SetLabelFont(43);
dummy->GetYaxis()->SetLabelSize(26);
dummy->GetYaxis()->SetTitleFont(43);
dummy->GetYaxis()->SetTitleSize(33);
dummy->GetYaxis()->SetTitleOffset(1.0);
dummy->GetXaxis()->SetLabelFont(43);
dummy->GetXaxis()->SetLabelSize(26);
dummy->GetXaxis()->SetTitleFont(43);
dummy->GetXaxis()->SetTitleSize(33);
dummy->GetXaxis()->SetTitleOffset(0.9);
dummy->GetXaxis()->SetTitle("E [GeV]");
dummy->GetYaxis()->SetTitle("1/4#pipE dN/dE [GeV^{-3}]");
dummy->GetXaxis()->SetRangeUser(low_bound, upp_bound);

…and then I draw some TF1s with “C SAME”, it works exactly the way I’d like it to be.

It, however, have not been working until I changed Fit options (yes, I perform a fit) from “RM” to “RM0” (documentation says that with ‘0’ code won’t plot figure automatically when fit is called). I do not know exact magic behind this (only a few ideas), but it works.

Thank you,
that looks really appropriate.
I believe your answer will be useful not only for me.

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