GetMaximum(), GetMaximumX(), etc. for TSpline

The TF1 class has nice functions like GetMaximum(), GetMaximumX(), and others. Is there an easy way to add these functions to the TSpline class? Or at least a way to convert a TSpline3 to a TF1?

What about:

spline->GetHistogram()->GetMaximum(); 

?

TSpline3::GetHistogram() is returning a null pointer, so TH1F::GetMaximum() is throwing an exception. This is what I’m doing:

  TGraph* g = new TGraph(count, &x[0], &y[0]);
  g->Draw("A*");
  g->SetMarkerStyle(20);

  TSpline3* spline = new TSpline3("spline", g);
  TH1F* tmp = spline->GetHistogram();
  spline->SetLineWidth(3);
  spline->Draw("SAME");

  Double_t bestY = tmp->GetMaximum();
  Double_t bestX = tmp->GetBinCenter(tmp->GetMaximumBin());

I know the TSpline3 is not null, because it’s plotting and looking reasonable. But spline->GetHistogram() returns null.

may be:

  TSpline3* spline = new TSpline3("spline", g);
  spline->SetLineWidth(3);
  spline->Draw("SAME");
  gPad->Update();
  TH1F* tmp = spline->GetHistogram();

That works, thank you very much.

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