Problem using TF1::DistancetoPrimitive

Hi,
I want to determine the distance minimum between a point and a function. I do this to in a view to test if the cinematic lines (E = f(Theta) ) I get experimentally match with the expected ones.
I don’t get why the simple code below doesn’t work.

  TCanvas *c1 = new TCanvas("c1","c1",100,100);
  TF1 *f1 = new TF1("f1","pol1",100,180);
  f1->SetParameter(0,1000);
  f1->SetParameter(1,-1);
  c1->cd();
  f1->Draw();
  c1->Update();
  Float_t MM_E = 880;
  Float_t angl = 110;
  Int_t pixelY = c1->YtoPixel(MM_E);
  Int_t pixelX = c1->XtoPixel(angl);
  cout<<endl<<angl<<"  "<<MM_E<<"  "<<f1->Eval(angl)<<"  #  "<<pixelX<<"  "<<pixelY<<"  "<<c1->YtoPixel(f1->Eval(angl))<<endl;
  cout<<f1->GetObjectInfo(pixelX,pixelY)<<endl;
  cout<<f1->DistancetoPrimitive(pixelX,pixelY)<<endl;

It breaks when I call the DistancetoPrimitive function.

thanks for your help,
jo

Hi,

I don’t exactly understand why, but it seems that if you call your code with f1->DistancetoPrimitive(-pixelX,pixelY)
it seems to work and give meaningful results. There is a statement in the documentation about the negative px argument and looking at the code a different function called when using negative px, but I am not sure I understand why this one works and the other doesn’t.

Hope this helps,

Erik

Thanks for your reply,
I thought that the second method would only consider vertical distance in pixel. I tried with a exponential function and it seems that the distance wth a -pixelX is meaningful and not only the vertical one.
Thanks again.