Hi,
I am wondering whether or not treeformula->EvalInstance() must be called after having filled the entire tree? I define a pointer of treeformula after creating new Tree, I would use EvalInstance() in the loop of filling the tree. If I didn’t re-define a pointer of treeformula before calling EvalInstance(), evalinstance will return 0. I am confused about that since when I define the first treeformula, I have set tree pointer to the treeformula, why must I re-define?
You must define the TTreeFormula after the creation of the tree branches, otherwise the Tree variables are unknown to the formula.
You do not have to call GetEntry (the Tree knows the addresses of your variables).
see code below
[code]void test_TTreeFormulaAfterFill() {
TTree * t_new = new TTree(“t_new”, “Create new tree”);
[quote]will give a value of last event, right? [/quote]Most likely not.
It will give the element that is stored at the entry number returned by t_new->GetReadEntry().
Before calling EvalInstance, you should always make a call to LoadEntry (t->LoadEntry(what_I_want); ) to tell the TTreeFormula object which entry you want to read.
If you intent is to get the last value you should do:t->LoadTree(t->GetEntries()-1);