Add histograms automatically from two files

Hi,

I have a quick, and sort of naive question, but I have surprisingly not found an example yet.

I have two root files, each one with a bunch of histograms, but with the exact number of them (both say, with 20). Is there a quick and dirty way to do the following:

  • produce a root file where each of the histograms are added in the same canvas but with different colors?

Note that I’m not talking about simply “hadd” or rather, something like “hadd merge.root file1.root (in red) file2.root (in blue)”

I also don’t want something that needs to necessarily know the name of each histogram in these files. It should be completely general, that is, assuming file1.root and file2.root have the same number of histograms and with the same name. For example, file1.root and file2.root have both 3 or both 30 histograms and each time these histograms have completely different names (as long as the names are the same between both). How to do this in a automatized way and without having to each time check the histograms names?

Hi,

I don’t understand exactly what would you like to do. To merge the histogram or to plot them.
For merging the histogram we have hadd.
Please clarify exactly what would you like to do

Thank you

Lorenzo

Hi Lorenzo,

Sorry, I probably shouldn’t have used hadd in the example. What I’m asking is pretty simple. Is there a Root tool to automatically draw histograms side by side using a command line (like hadd does with merging)?

I know one can do this with a simple macro using THStack and putting both histograms in the same canvas, etc. I’m just asking if there is a quick and dirty command to do this, without the need of writing any macro, or not.

Typically that sort of tool is just a few lines of code. But each user has its own taste and it is difficult to make a general one. Such small tools are typically part of the “library of macros” each user makes for its own usage.