Save a histogram


ROOT Version: 5.34/36
Platform: lxplus
Compiler: Not Provided


I want to do histogram division in PyRoot but couldn’t do it. Then I tried to save them as Root files, and everything works basically well, except that I still couldn’t do the division in Root, regardless of treating them as histograms or pointers.

Histograms’division can be performed thanks to the Divide method. Is it the technique you were trying to use ?

Yes, and it shows

Error: Symbol Dec is not defined in current scope  (tmpfile):1:
Error: Symbol Dec is not defined in current scope  (tmpfile):1:
(const int)0
*** Interpreter error recovered ***

And I’ve also tried using “/” directly and it doesn’t work as well

It seems you are trying to access some undefined object (Dec).
Can you provide a small script reproducing your problem ?

root [0] TFile f("Histograms.ROOT")
root [1] Dec->Draw()
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [2] ->Divide(Dec,Dec)
Error: Symbol Dec is not defined in current scope  (tmpfile):1:
Error: Symbol Dec is not defined in current scope  (tmpfile):1:
(const int)0
*** Interpreter error recovered ***

I just draw Dec to make sure it really exists and is a histogram. “Histograms.ROOT” is a file I created in PyRoot to store my histograms.

Your Divide line is wrong. You need to do:

result_histogram->Divide(Dec,Dec);

See the help…:

Replace contents of this histogram by the division of h1 by h2.

this = c1h1/(c2h2)

By the way Dec divided by Dec should give a predictable result equal to 1.

root [3] result_histogram->Divide(Dec,Dec)
Error: Symbol result_histogram is not defined in current scope  (tmpfile):1:
Error: Failed to evaluate result_histogram->Divide(Dec,Dec)
*** Interpreter error recovered ***

That’s what I’ve got…Do I need to define result_histogram first?

Yes you need to create an histogram in order to call the Divide method on it.

Great, seems it works. Thank you!

Yes it must work :slight_smile:

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