Stitching TH1s together to make a TH2

Hi experts,

I have a possibly basic ROOT question. We can get the TH1s that make up a TH2 using the Projection method through the bins. Now what I want is something of a reverse operation: supposing I have a bunch of TH1s, how can I stitch these together to make a TH2?

I’m aware that this comes with many potential issues, which might explain why I don’t find anything obvious on this in the documentation. However now I’m finding myself wanting it in order to apply some non-uniform 2D rebinning on a TH2. The sketch I have in mind would make the resulting TH2 not projectable in X or Y or both, but these exceptions can be handled accordingly if the core operation is available.

In some sense it’s similar to applying multirow and multicol here and there in the TH2… if this analogy helps clarify what I want to achieve. Any pointers on how to go about this is greatly appreciated.

Cheers,
Afiq

Hi Afiq,

indeed what you have in mind is not absolutely “main stream”. Why not looping on all 1D histos and then on all of the bins of each histo and set the content and error of the bins of the 2D histo?

Cheers,
D

Hi dplparo,

Thanks for your reply. I’m not sure if that will work though… please look at the picture below. This is an example of what I want to achieve, which is consistent in X. The problem I see with what you described is that I would need to already have the binning in the TH2 defined, but I don’t know how to define this for the TH2 in the picture for example. Based on what I understood of the current TH2 class, while non-uniform bin size is supported, each bin x,y must have a distinct set of 4-bin neighbors: x±1, y±1. As you can see in the picture this is not true, 1,1 is the y-1 neighbor for 1,3, 1,4 and 1,5.

Cheers,
Afiq

Hi,

if the binning is not compatible, the problem gets hairy. I think your best call would be to find a binning for the TH2 which corresponds to all of your TH1s (exact multiple) and then fill the bins…

D

Hi,

if the binning is not compatible, the problem gets hairy. I think your best call would be to find a binning for the TH2 which corresponds to all of your TH1s (exact multiple) and then fill the bins…

D

Hi,

Well, the problem being hairy is exactly what prompted this question. :smiley:

This binning is still compatible if the TH1s are stitched together only in the x-direction, but indeed it does not obey the “each bin having a distinct set of 4-bin neighbors” property.

For statistical analysis I would be using the 1D unrolled histogram corresponding to this, so having this true only in x or y is sufficient, no need for both, but I wanted also to put this into TH2 so to get the color maps for easier visualization (and if possible, the general case where it’s not consistent in both x and y).

Am I to take it that this is not possible with the TH2 class as it is?

Cheers,
Afiq

TH2Poly

1 Like

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