Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTreeFormula behaves badly with <= operator and multiple conditions #7986

Open
1 task done
Timothy-Anders0n opened this issue Apr 23, 2021 · 0 comments
Open
1 task done

Comments

@Timothy-Anders0n
Copy link

Timothy-Anders0n commented Apr 23, 2021

  • Checked for duplicates

Describe the bug

Using pyRoot, preparing a selection string to use in TTree.GetEntries(const string * selection), it seems that a string of the type: _value1_ <= _variable_ <= _value2_"

should be working but insteads it returns an error: TTreeFormula bad expression "=_value2_"

when other operators work just fine (no error), e.g.:

  • _value1_ < _variable_ < _value2_"
  • _value1_ <= _variable_ < _value2_"
  • etc.

I have tried with and without parentheses around the conditions. The only working solution (for now) to write: _value1_ <= _variable_ && _variable_ <= _value2_"

but this sensibly slows the code.

Expected behavior

Using _value1_ <= _variable_ <= _value2_" should not return an error when trying to limit a variable to a closed interval, in the same way it works when limiting a variable to an open interval.

To Reproduce

Steps to reproduce the behavior:

  1. The code that can reproduce the issue is the following:
    import itertools
    import numpy as np
    import ROOT as rt
    paramList = { 'Variable_1' : np.linspace(0,1,4),
                          'Variable_2' : np.linspace(0,3,5) }

    boundaries = list(itertools.product(*[itertools.combinations(val,2) for val in paramList.values()]))
    for val in boundaries:
        string = 'dmID_signal == <whatever ID for final particle>'
        for bounds, key in enumerate(paramList.keys()):
            string += " && ({} <= {} <= {})".format(val[bounds][0], key, key, val[bounds][1])
        signal = sigData.GetEntries(string)
  1. I cannot really join a .root file here, but it is just a matter of changing Variable_1 and Variable_2 of paramList for 2 variables of a TTree. Also, I start the selection string with a selection of dmID but that can be removed, you just need to modify the string so that it doesn't start with &&.

  2. To run the code, write it in a python file or jupyter notebook and run it using Python 3.

Setup

  1. JupyROOT 6.22/08
  2. Linux Mint 19.3 Cinnamon
  3. Installed Root using conda

Additional context

Using PyRoot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants