Using TTree functions for corrolation histograms

Suppose I am given a list of events consisting of a list of numbers from 0 to 100.

For each n from 0 to 100, I want to make a histogram showing the frequency that each number from 0 to 100 is hit during the same event as n. In other words, I make 100 histograms h[100], loop through the events, get the list of numbers hit, then for each n,m in this list, h[n]->Fill(m).

This program works fine when I am given the list of events in this format, but now I am given the data in TTree format, i.e. there is a branch N of the tree of values from 0 to 100. I’m having trouble figuring out a good way to do the result I want with a TTree. Is there a better way to produce the histograms I want than iterating through each event as above (maybe using TCuts or something?)?