In TF2 how to get x and y value corresponding to the maximimum value of the function or any value of the function

Hello Experts
I have defined a simple TF2 function(say f2) and I get the maximum value of the function using GetMaximum(). But I couldn’t find the x and y values corresponding to that maximum
value of the function or any value of function. So please point me if there is any inbuilt function in root for TF2 to get x and y value corresponding to the function value.

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

It looks like TF2 has a method TF2::GetMaximumXY which does what you need.

Hi, I am trying to get x and y value corresponding to the maximum value of the function. The method you suggested TF2::GetMaximumXY, gives the value of the function for the given x and y. Here is the function bellow

void test1()
TF2 *f2= new TF2("f2","(-(8.83+x*0.2169+y*0.8139)+(10*log(8.83+x*0.2169+y*0.8139))-(10*log(10))+10-(6.342+x*0.05957+y*2.5286)+(6*log(6.342+x*0.05957+y*2.5286))-(6*log(6))+6)",-20,50,-2.,2.);


Double_t co=-0.1;
Double_t coh=2;
cout<<"GetMaximum=  "<<f2->GetMaximum()<<endl;
cout<<"GetMaximumXY=  "<<f2->GetMaximumXY(co,coh)<<endl;

Method defination of TF2::GetMaximumXY

Correct me if I am missing something.

Thanks in advance.

std::cout << "GetMaximumXY = " << f2->GetMaximumXY(co, coh) << " at ( " << co << " , " << coh << " )" << std::endl;

The arguments (co,coh) to the GetMaximumXY method are “return parameters”, an older way of returning multiple values from a function in C/C++. The actual function return value is indeed the maximum, but if you look at the values of co and coh after calling the function, you’ll see they have changed to the X & Y location of that maximum.

See the second section here:

1 Like

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