This is a bit of a speculative question, so apologies in advance if this is not clear.

I have a TTree with a number of branches. At the moment, this is processed using a TSelector, going entry by entry and making graphs etc.

I would like to calculate a numerical differential between two of the branches e.g. suppose my branches were 1D displacement of a particle, x, and the time, t, then I want to calculate something like

dx/dt ~ ( x[n+1] - x[n] )/( t[n+1] - t[n] ) for all n

where n is just the entry number (or something similar - choose your favourite method here)

However, my TSelector only accesses one entry at a time (as far as I know), so I canâ€™t take a difference between branches easily. While this could be sidestepped by remembering the previous value or so, I have more than two branches, so that its not trivial to just remember the last value â€“ e.g. like also having y, z, temperature, size of particle, etc. which vary as well. I canâ€™t calculate dx/dt with fixed temperature if the next entry has a different temperatureâ€¦

Is there any way to calculate sums like this one with a TSelector?

What about storing older values in some data members? So at every event you have the current event loaded by the TSelector and the values you need from the previous event saved in some variables. You calculate the difference and then store the current event in the â€śprevious eventâ€ť variables.

Thatâ€™s the best solution that I was able to come up with as well. I was just wondering if there was an easier way to access the previous data members, because this solution is only convenient for a small number of branches. If you have any more than ten, it starts to become quite cumbersome. It may be that the answer is no, in which case this is the best solution .