The problem appears when I try to execute both sets of coded sequentially. Independently of which one comes first, I get to execute correctly the first set of instructions while things crash on the second.
Apart from this, I have another question regarding which method is more efficient. Inside the loop, should retrieve entries by calling the GetEntry(entry) or the LoadTree(entry) methods?
Inside the loop, you should call LoadTree (the TTreeFormula will do the GetEntry on the branch it needs), but you also need to call UpdateLeaves every time LoadTree change the value of GetTreeNumber.
Thanks for the answer. Still related to the TTreeFormula’s I would like to know if the following:
On a TTree branch which is a vector, e.g. vector<double> vjtPt. I would like to know if it is possible to define formulas from conditions on its elements, without using the GetNdata() to cycle over the vector, such as:
With the TTree’s I’m working, this is strangely working fine when I use “cut1”, but not “cut2”. Is this just a coincidence?
This kind of TCut’s can be applied to TTree::Draw() analysis method. And I’m trying to migrate an analysis code using the Draw() method, while trying to keep the selections cut definitions unchanged.
[quote]This kind of TCut’s can be applied to TTree::Draw() analysis method. [/quote]Anything that works with TTree::Draw should work with TTreeFormula.
TCut cut2 = "(vjtPt_pf[0]>30)&&(vjtPt_pf[1]>30)&&(vjtPt_pf[2]>30)"Note that this formula will return GetNdata()==0 for entries where vjtPt_pf.size() < 2.
Would this return a default value, e.g. 0, when the vector is smaller than the entry we are trying to get? Or would it always be necessary to check for GetNdata().
[quote]into a variable, by calling GetEntry, using something like:[/quote]No this is not possible (In part because this operation is undefined if the size of the vector is less than 2).
[quote]Would this return a default value, e.g. 0, when the vector is smaller than the entry we are trying to get? Or would it always be necessary to check for GetNdata().[/quote]I think it would return 0, however it is better and more efficient to check the value of GetNdata.
In term of performance the best is:std::vector<double> * vjtPt_pf = 0;
TBranch *branch = 0;
ttree->SetBranchAddress("vjtPt_pf",&vjtPt_pf1,&branch);
...
branch->GetEntry( entry );