Normalized a histogram with line but without error bar

_Hey All,
I am trying to normalize a histogram using:

Double_t norm = h->GetEntries();
h->Scale(1/norm);

It perfectly normalized histogram but when I write this normalized histogram in a root file using
h->Write();
then histogram draws with error bar and without line but I want to draw histogram without error bar and with a line. Can you suggest how can I do that?[qinv_test.pdf|attachment]

(upload://vTuPpCexEhvz84jOh9wxeY0IKfk.pdf) (16.6 KB) __
Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hi Haradhan,

to draw your histogram without error bars, just do

h->Draw("hist")

instead of simple

h->Draw()

Hey Yus,
Thank you so much. I tried it, it is working but if I want to write this histogram in a root file then it doesn’t work their. Alternatively I can do like later I can read this root file and h->Draw(""HIST); which is working but I tried to write this in the root file with line and without error bar.

You can’t write a histogram in a file with any particular plotting style. The plotting style is something you choose whenever you want to draw the histogram, not write it.

Okay Thanks

When i try these commands to normalize histogram error occured
root [1] Double_t norm = h1->GetEntries();
root [2] h->Scale(1/norm);
ROOT_prompt_2:1:12: error: reference to ‘norm’ is ambiguous
h->Scale(1/norm);
^
ROOT_prompt_1:1:10: note: candidate found by name lookup is ‘norm’
Double_t norm = h1->GetEntries();
^
/usr/include/c++/9/complex:1860:5: note: candidate found by name lookup is ‘std::norm’
norm(_Tp __x)
^
/usr/include/c++/9/complex:686:5: note: candidate found by name lookup is ‘std::norm’
norm(const complex<_Tp>& __z)

hello dear yus, i wann merge an error free histogram for this when i typed
h1->Draw(“hist”, “SAME”);
error is
ROOT_prompt_10:1:17: error: too many arguments to function call, expected at most single argument ‘option’,
have 2 arguments
h1->Draw(“hist”,“SAME”);

https://root.cern/doc/master/classTHistPainter.html#HP01

you can try h1->Draw(“HIST same”);

1 Like

Thanks it works. Do you have any idea of how to normalize histogram to unity?

I use this to normalize histogram

I already try with it but the error is
root [1] Double_t norm = h1->GetEntries();
root [2] h->Scale(1/norm);
ROOT_prompt_2:1:12: error: reference to ‘norm’ is ambiguous
h->Scale(1/norm);
^
ROOT_prompt_1:1:10: note: candidate found by name lookup is ‘norm’
Double_t norm = h1->GetEntries();
^
/usr/include/c++/9/complex:1860:5: note: candidate found by name lookup is ‘std::norm’
norm(_Tp __x)
^
/usr/include/c++/9/complex:686:5: note: candidate found by name lookup is ‘std::norm’
norm(const complex<_Tp>& __z)

try h1->Scale(1/norm);

Still error

What error you get?

Hi Muhammad,

Is your histogram called h or h1? In the first line you refer to h1, and in the second one it’s just h.

root [2] h1->Draw(“hist”);
root [3] Double_t norm = h1->GetEntries();
root [4] h1->Scale(1/norm);
ROOT_prompt_4:1:13: error: reference to ‘norm’ is ambiguous
h1->Scale(1/norm);
^
ROOT_prompt_3:1:10: note: candidate found by name lookup is ‘norm’
Double_t norm = h1->GetEntries();
^
/usr/include/c++/9/complex:1860:5: note: candidate found by name lookup is ‘std::norm’
norm(_Tp __x)
^
/usr/include/c++/9/complex:686:5: note: candidate found by name lookup is ‘std::norm’
norm(const complex<_Tp>& __z)

Sorry i wrote h1->Scale(1/norm); in the second command but still same error

Avoid naming your variable norm. Just call it e.g. norm_factor instead.

error: use of undeclared identifier ‘norm_h1’