Force TTreeFormula to use updated input values

ROOT Version (e.g. 6.12/06):
Platform, compiler (e.g. CentOS 7.4.1708, gcc6.2):

Is there some way of forcing TTreeFormula to pick up updated versions of its inputs?
My question is probably best illustrated in the short example below, which prints “45 45”.
I would like TTreeFormula to pick up the modification, of x and, therefore, print “45 90”.

(run by saving this snippet as foo.cpp, then running root foo.cpp+)

#include <TTree.h>
#include <TTreeFormula.h>
#include <iostream>

void foo()
  Float_t xin, sum_yin{0.0};
  TTree tree( "tree", "" );
  tree.Branch( "x", &xin );
  for ( auto i = 0; i < 10; ++i ) {
    xin = i;
    sum_yin += xin;

  Float_t x, sum_y{0.0};
  tree.SetBranchAddress( "x", &x );
  TTreeFormula form( "form", "x", &tree );
  for ( auto i = 0; i < tree.GetEntries(); ++i ) {
    tree.GetEntry( i );
    x *= 2.0;
    sum_y += form.EvalInstance();

  std::cout << sum_yin << " " << sum_y << std::endl;

You can simply use:

form.SetQuickLoad( true );

If the entry is already the last read entry, the TTreeFormula will not read it again [However if the cursor moves (LoadTree(other_entry)), it will read the value again]


Hi Philippe,

Thanks for the prompt reply and the simple solution!
I will have to double-check it works in my real-world case, but this looks very promising.

Cheers, Olli

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