The convention in the ROOT code is that symbol starting with a lower case letter ‘f’ to be the data member. Hence fFormulaList is a data member of TTreePlayer (the class you copied the code from).
I’ve cleaned up the code and now it’s running without segmentation violation. However the results are not what one would expect… I’m doing the same simple cout as before (when I called TTree::CopyTree), but now the resulting root file is twice as big as the one generated by CopyTree. When I try to open the root file the following error message appears:
Attaching file zee60_130_subsample.root…
Error in TFile::Init: file zee60_130_subsample.root is truncated at 209715200 bytes: should be 385278941, trying to recover
Warning in TFile::Init: no keys recovered, file has been made a Zombie
I guess I made a mistake in my code, but I can’t figure out where…
I’ve played around with my macro for a while, but there are still some things which I don’t understand. I’m referring to the source code which is the last attachement above.
select-GetNdata() has quite often the value ‘1’, but also sometimes ‘0’. When I change select to “LETM_Nelectron>1 && LETM_pT[0]>30.” I don’t notice any change in GetNdata(). Isn’t it suppossed to be ‘2’??
The change I’ve just made to the TTreeFormula select puzzles me. How can root be sure that (as it is in this case) the number of electrons has to be bigger than one before one can require the (first or second) electron to be above a given threshold?
I know that I don’t understand the following logic yet:
for(Int_t current = 0; current<ndata && !keep; current++) {
keep |= (select->EvalInstance(current) != 0);
}
What exactly means |= ? It looks to me that the first instance of select is evaluated (which would be LETM_Nelectron>1, and then???
My output root file contains the trees tsm;2 and tsm;3. Why are there two and not one tree? And why doesn’t the first one start with 1?
I’ve just chained two root files together, but my event loop stops after having processed only the first root file…
“select->GetNdata()” returns the number of values for your formula in this entry. In your case, LETM_Nelectron is a counter which is either present or not (respectively value 1 or 0).
For “LETM_Nelectron>1 && LETM_pT[0]>30” there are NO change in the cardinality of this expression (per event). It either 0 (no LETM at all) or 0 (LETM exsist but LETM_pt[0] does not) or 1 (LETM exist And LETM_pt[0]).
If you are looking for the Value of LETM_Nelectron, you have to use
select = new TTreeFormula("Selection","LETM_Nelectron>1",fTree);
if (select) {
Int_t ndata = select->GetNdata();
if (ndata) LETM_Nelectron = select->EvalInstance();
else continue;
}
a |= b;
is equivalent in C++ to
a = a | b;
See the ROOT User’s Guide. The lower number are older copies of the tree meta data.
Well that’s exactly what you asked by doing:
Int_t nentries= (Int_t) ch->GetTree()->GetEntriesFast();//fTree->GetEntries();it should be: Int_t nentries= (Int_t) fTree->GetEntries();
or Int_t nentries= (Int_t) ch->GetEntries();
thanks for the detailed explanation! However I still have trouble accessing the value of my TTreeFormula.
From your example (especially the following line) I’ve concluded that in
LETM_Nelectron contains the actual value of this variable for this event. However I get the same answer (‘0’ or ‘1’) as for ‘ndata’.
In a further step I’ve tried to acces the electron pT (LETM_pT[0]), and here I definately get only an integer value of ‘0’ or ‘1’ back.
If you used:select = new TTreeFormula("Selection","LETM_Nelectron",fTree);
...
if (ndata) LETM_Nelectron = select->EvalInstance();
then the variable LETM_Nelectron should vary in the same way as its counterpart inside the origianl tree (chain). If you already use the code similar to the code snippet above (not the __absence of ‘>1’), please send me the code you are currently using.
one last time, then I should have understand everything.
The code I’ve attached stops with the following error message:
[quote]root [2] .X make_subsample3.C
37685
hallo
0
37685
firstentry/nentries/entry: 0/37685/0
ndata: 1
Warning: Automatic variable LETM_Nelectron is allocated FILE:make_subsample3.C LINE:85
nr: 2
Warning: Automatic variable LETM_pT[0] is allocated FILE:make_subsample3.C LINE:93
em1: 55.9228
Error: Array index out of range LETM_pT[1] -> [1] valid upto LETM_pT FILE:make_subsample3.C LINE:100
Error: Incorrect assignment to newtree, wrong type ‘Double_t’ FILE:make_subsample3.C LINE:18
*** Interpreter error recovered ***[/quote]
I don’t understand why the array index is out of range. I’ve explicitly checked before that LETM_Nelectron is equal or bigger than two. LETM_Nelectron tells me how many entries are in the array LETM_pT[i]; it’s used to fill all variables and to read them back. So why doesn’t it work?
The ‘LETM_pT[0]’ is refering to a C++ identifier. In your code you never defined LETM_pT thus the error messages. You need to define a C++ variable in your script to store the information retrieved from your Tree.