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

Issue with Parsing ROOT:TFormula #250

Open
attikis opened this issue Jul 16, 2024 · 2 comments
Open

Issue with Parsing ROOT:TFormula #250

attikis opened this issue Jul 16, 2024 · 2 comments

Comments

@attikis
Copy link

attikis commented Jul 16, 2024

Dear devs,

we are experiencing some trouble trying to implement a TFormula in correctionlib. Our understanding is that problem is related to the parsing of the "&&" logic operator in the TFormula.

cset = _core.CorrectionSet.from_file(fname)

RuntimeError: Failed to parse Formula expression at position 28:
((min(max(x,20.),140.)>20.0&&min(max(x,20.),140.)<=30.0))*0.8434999999999999
^
syntax error, unexpected '&', expecting , .

Can you please clarify if this indeed the case? If indeed the case do you think i'd be possible to rectify this?

In the meantime, is there a way to test a-priory a given TFormula or even parse it and then pass it to correctionlib?
Perhaps an example script or documentation?

Thank you in advance.

Best regards,
Alexandros

@nsmith-
Copy link
Collaborator

nsmith- commented Aug 2, 2024

You can test formulas by making a small correction object in code:

from correctionlib import schemav2 as schema

c = schema.Correction(
    name="test",
    version=2,
    inputs=[schema.Variable(name="x", type="real")],
    output=schema.Variable(name="a scale", type="real"),
    data=schema.Formula(
        nodetype="formula",
        expression="23.*log(x)",
        parser="TFormula",
        variables=["x"],
    ),
).to_evaluator()

assert c.evaluate(1.0) == 0.0

Looking at your formula, it appears to be a binning. You should use a Binning node to implement this correction and not a formula.

@nsmith-
Copy link
Collaborator

nsmith- commented Aug 19, 2024

Were you able to implement a binned formula?

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

No branches or pull requests

2 participants