i’m using TTreeFormulas to do a preselection over a containers of particle (vectors) and i was wondering whether it is possible to put a condition in the formula. for instance if i have two branches
el_pt and el_type
i’d like to have something like
el_pt>10 if(el_type==1)
and then a second ttf that would be
el_pt>15 if(el_type==2)
so far i’ve tried this
(el_pt>10 && el_type==1) || (el_pt>15 && el_type==2)
but it never gave me the right number of element in vector when doing GetNdata()
[quote]but it never gave me the right number of element in vector when doing GetNdata()[/quote]By definition the number of element will be the number of elements in el_pt and/or el_type, no matter what is the ‘value’ of the expression.
One way to implement what I understood you want is:" (el_pt>10)*(el_type==1) + (el_pt>15)*(el_type==2) "which will be value at 0 if el_type is neither 1 nor 2.
thanks for the answer, unfortunatly it doesn’t seems to work as i thought it would. apart from the GetNdata thing, this way of requesting a condition on el-type is working only on the first element and not on the other.
i’ve made a dummy example that i’ve joined. I changed el_type to el_phi requesting phi>0 (easier for me to provide a test file). the only thing to do is root launch.C
do you understand why is it not working as i would like it to ? what can be wrong in the way i’ve defined things ?