# The usage of comparison and condition operators in the formula in TF1

Hi to all,

I have seen the comparison operators can be used in the equation part of TF1. Example:
TF1 * f1= new TF1(“f1”, “((x < [0]) * [1] * (x - [0])) + [2]”, 0, 100 );
I wonder if we can also use the condition operators in the equation part? Example:

If it’s not possible, can “the way around it” be the inline expressions using a user defined Cling function by name as stated in TF1 link here? I also attach sample down below.

I also checked the TFormula, but I came to conclusion after reading some comments that we cannot REPLACE the equation part of TF1 with TFormula. Plus, there is not much example about the usage of TFormula. Please, refer me some simple TFormula application if there is any somewhere. On the TFormula link, there is an example which I suspect the equation is missing " " quotation mark. Can you confirm that! I put the part down below.

Cheers.

Are you trying to say ternary operators work fine in TF1? I see it does, I doubt one second after not seeing any example.

Is this statement correct?

TF1*total = total = new TF1(“total”, "gausn(0) + gausn(3) + ( (x< [6]) ? ([8] * (x - [6])) + [7] : ([9] * (x - [6])) + [7] ) ", 400 , 534);

Cheers.

``````{
TF1 *total = new TF1("total", "gausn(0) + gausn(3) + ((x < [6]) ? [8] : [9]) * (x - [6]) + [7]", 400., 534.);
total->SetParameters(1000., 430., 2., 2000., 500., 4., 460., 100., -4., -1.);
total->SetNpx(1000);
total->Draw();
gPad->SetGrid(1, 1);
}
``````

Oh, yeah, even shorter. Thanks for the confirmation.

BTW, what do you think about the sin(x*(x<0.5 || x > 1)) example on ROOT website I stated above in the story?

@moneta I’m not sure who is responsible for fixing HTML rendering bugs on “class reference” pages.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.