TTree Differential

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?

ROOT Version: 6.18/04
Platform: Linux

Hi @PTMac73 ,
sorry for the high latency!

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.

Cheers,
Enrico

Hi @eguiraud,

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 :man_shrugging:.

Cheers,
@PTMac73

You can probably make things prettier by defining a struct such as

struct PreviousEvent {
  float x1, x2, x3, x4;
  void SetAll(float _x1, float _x2, float _x3, float _x4) { x1 = _x1; x2 = _x2; ... }
};

and use that as data member.

Cheers,
Enrico

That’s a good idea! Thanks @eguiraud!

1 Like

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