Some 'how-to' questions on Histograms

Please read tips for efficient and successful posting and posting code

_ROOT Version: 6.14/04
_Platform: linuxx8664 (Ubuntu 16.04.12)
_Compiler: gcc 5.4.0

I am trying to plot histograms from two different ROOT files into the same canvas/pad for several variables, you know as with one signal and background(s). My code is attached herewith. The plots are coming. But, I have some queries:

  1. In my plots, the stats are for only the signal (or, in the code for nfile=0). But I want to see the stats of the background(s) also. How can I see that? I tried a few things like putting the command “histPhotonPT[nfile]->SetStats(1);” outside the loop with specific values for ‘nfile’ and inside. But with no success.
  2. How can I set the gridlines to be only from the main tick-marks and NOT also from the sub-ticks? In Logscales it’s looking ugly.
  3. How can I put the ‘Header’ of the ‘Legend’ inside a box as in the stats-box?
  4. The last query is regarding a warning I am getting while running the macro in the terminal.

Warning in TROOT::Append: Replacing existing TH1: photon_pt (Potential memory leak).
Warning in TROOT::Append: Replacing existing TH1: photon_energy (Potential memory leak).
What does that mean and how to resolve it?

SampleMacro.C (2.6 KB)


… 1. …
move stats box
move TPaveStats

… 4. …

   histPhotonPT[nfile] = new TH1F(TString::Format("photon_pt_%d", nfile), "P_{T}(#gamma)", 100, 0.0, 500.0);
   histPhotonE[nfile]= new TH1F(TString::Format("photon_energy_%d", nfile), "E(#gamma)", 100, 0.0, 500.0);

Thanks a lot Coyote…
So, the query-4 is now resolved and I understand the issue.
But for query-1, I modified the macro a bit using ’ TPaveStats’. But for ‘background’ (or, ‘nfile’=0), I am getting a ‘null pointer’. I’ve attached the modified macro herewith.

SampleMacro_mod.C (3.8 KB)


“FindObject” is not “GetPrimitive”

I tried both actually. Initially, I had put “GetPrimitive”, later tried with “FindObject”. But neither worked.

Attach your ROOT files.

Here’s a link to my dropbox folder. The file sizes are more than 3mb.
Dropbox link to the files

FYI, I can see the stat-boxes in TBrowser as well as in the plots but cannot re-position them.

And, if you don’t mind, may I ask about the second query?


SampleMacro.cxx (4.1 KB)

Thank you so much, Wile, for the help. It is absolutely fine now…
Thank you a lot for the time you paid in it…


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