Divide a histogram with a number

I am trying to create a histogram that contains the mean pulse of various pulses. I am easily able to create the total pulses and add them all in a histogram. When I come to divide the histogram, that contains the total pulses, with the number of pulses using

TH1F hmean = 8*htotal; hmean->Draw();
I get an error

Then I tried using

TH1F hmean = 8*(*htotal); hmean->Draw();
and I got

and an empty canvas so, I tried

TH1F hmean = 8*htotal; hmean.Draw();
and I got

and an empty canvas.

Note that I am running root on lxplus. Is there a way around it?

1 Like

The TH1F class does not have the “operator*” method defined at all.
There exist various Add, Divide, Multiply and Scale methods: see the TH1 class description.

I tried to use Divide but I don’t know how. I first, created a function that has only the value 1 and then I will try to divide it like this

TF1 *constant = new TF1("constant","1",0,channels); TH1F hmean = htotal->Divide("constant",1.); hmean->Draw();

but i get an error that something must be wrong with TF1 or TH1F, with the arguments of Divide() that is. Any idea on that?

And which one of the three available TH1::Divide methods returns a histogram?
(A small hint: as far as I can see they all return a Bool_t.)

That is true!
But how am I going to create the histogram?

A really very tough question, indeed. :-k
:bulb: Maybe you could find some magic Clone method? :mrgreen:
And maybe this magic Clone method would allow you to change the name of the histogram, too? :-k
And then maybe you could simply Scale this newly created histogram by 8? <img src="/uploads/default/original/2X/8/84c2fe9464a4066c00e1bd5978e913e7869cbb07.gif" width=“22” height=“16” alt=":-"" title=“Whistle”/>
I really don’t know what the best approach in your case is. O:)

Thank you very much for your help!
It really worked!
Kind regards!
Cheers!!!

I have also tried in macro…but it showing error