Adding multiple 1D histograms

When I run the macro attached here like 3 or 4 times, I start getting the same histogram plot every single time. I thought the use of TRandom3 meant I should be getting different plots since the data points generated are pseudo-random. I have attached the gif file here. Does anyone know why that is the case?

Also, root keeps on giving me following warnings:

Warning in TROOT::Append: Replacing existing TH1: sig_h (Potential memory leak).
Warning in TROOT::Append: Replacing existing TH1: gaus_h1 (Potential memory leak).
Warning in TROOT::Append: Replacing existing TH1: gaus_h2 (Potential memory leak).
Warning in TROOT::Append: Replacing existing TH1: exp_h (Potential memory leak).
Warning in TROOT::Append: Replacing existing TH1: exp_h (Potential memory leak).

How do I get rid of such warnings?
histexample3.cpp (1.2 KB)

P.S. The macro is based on an example in ROOT 5 primer. I was playing with the code.

ROOT Version: 5.34/18
Platform: Ubuntu 18.04
Compiler: Not Provided


TRandom3 rndgen(0);

Not sure if it is helping. On the very first run, I am getting a plot like this:

If I run the macro again, I get a different kind of plot, but the histograms indicated by red and blue color are still being plotted as in the first run.

But after the third run and further, the histogram indicated by red just flattens out (as shown in the main question body), and no matter how many times I run the macro, it stays that way. I cannot even see the blue one.

Your macro has a problem:

Processing histexample3.cpp...
In file included from input_line_11:1:
/Users/couet/Downloads/histexample3.cpp:18:7: error: use of undeclared identifier 'exp_h'
      exp_h->Fill(rndgen.Exp(4));

For me, it does not show that error. Furthermore, based on some other questions posted in the forum, I have modified the code a bit by including few lines from line 13-18 in my new code attached here. This does not give any memory leak warnings.
histexample3.cpp (2.2 KB)

Look at your code … exp_h is not defined … I guess you mean bkg_h instead

1 Like

I completely did not see it, but I am not lying when I say that my code is running fine just the way it is right now. But now, I have changed bkg_h to exp_h everywhere.

So I get these two canvases. What is wrong ?

In my original code in the question (where the second canvas is not a part of the code), I am only trying to plot Exponential+Gaussian plot. Let’s say, I run it in root, it works fine. I get something similar to what you have on the left side. Let’s say, I close the canvas window and run the macro again, I get something similar. But when I do it the third time and more, I keep on getting something like this:

No matter how many times, I run the macro, the histogram indicated by red color just flattens out totally, and I don’t even see blue one anymore. That was my original question.

I just ran it several time in the same root session (closing the canvases in between the runs) I always get similar plots.

1 Like

Ok, interesting, I am not sure what is going on at my end, then.

I guess the ROOT version… I am using 6.20
5.34 is very old… can you try a more recent version ?