Perhaps this is something obvious, but I am a little bit lost after a long time of trying to figure it out.
I have a TTree with fields like frame, star_id, mag, etc. The order of filling is that I start with frame=1, fill all star_id and other values with frame=1, than change to frame=2 and fill, and so on. So naturally, when I loop over the tree, the entries order is such that first I get all star_id’s from frame=1, than all star_id’s from frame=2 etc.
Now, I’d like to change the order of analysis - for example analyse all frames for star_id=1 than switch to star_id=2, analyse all frames and so on. Is there any easy way to do this with TTree?
I can build my own unique list of star_id’s looping over a separate branch containing star_id’s, than build an index, and try to loop over the list of star_id’s and use GetEntryWithIndex. However, that is many lines of code to build the list, sort, unique, etc. Additionally, I am not sure if I can apply any cuts based on other variable, to the branch based on star_id. Using the whole TTree (and thus having a possibility to apply cuts in process of creating a unique list of star_id’s) is… another iteration of analysing whole TTree. I think this is generally not a good approach.
the problem is that you try to “change the order of analysis”. Ideally your analysis is immune to that order: you would create e.g. a 2D histogram: whatever you would count in a 1D histogram in x, and say star_id in y. Like that you don’t need to re-run through the TTree for each star_id.
Does that make sense?
If I understand correctly, this approach is too easy for my case. For each “frame” for given “star_id” I’ve got a matrix of points, to which I want to fit a 2D function. Thus I cannot create a 2D histogram with star_id on one axis and matrix_for_each_frame on the second axis. I agree that I need that kind of ordering, but TH2 would not work here… I think
well, next dimension then: either you create a vector of TH2* where one dimension is the star_id, or you use a TH3 to begin with. Which approach you pick mostly depends on the sparsity of the star_id: if it nicely maps to a histogram’s axis then use a TH3, of it doesn’t use a vector of TH2*.
If I understand correctly, I would need some kind of generalized TH2/3 class, that on one axis would have star_id, and on the other the matrix to which I want to fit, or, more preferably in more general case, all other entries for given star_id.
However, I am not sure if I understand correctly. Assuming I want to use TH3, I have 3 fields: star_id, frame and 2d_matrix (of values to which I want to fit). As far as I know there is no TH3 that allows me to have a matrix as one of the data points…