SetShowProjectionX in same canvas

Dear @couet, @Wile_E_Coyote,

Is there any way to draw SetShowProjectionX() in same canvas? It is always creating a default TCanvas with name C1_n2

No, see the doc:
https://root.cern/doc/master/classTH2.html#ac693fd7c4db869b2c0b8feafdce49a76

1 Like

Then any way to draw projection of a 2D fit on the same canvas?

ProjectionX returns a TH1D. Simply draw it.

You mean I can Draw ProjectionX of a TF2 fit, right? I mean ProjectionX works with TH2D. Does it work with TF2?

Which function do you intend to do the projection ? Do you have a piece of code ?

Suppose,

  TF2 *f = new TF2("f", "[0] * TMath::Gaus(x, [1], [2]) * TMath::Gaus(y, [3], [4])", -10., 10., -20., 20.);
  f->SetParameters(10., 2., 3., 4., 5.);
  f->Draw("Surf");
{
  TF2 *f = new TF2("f", "[0] * TMath::Gaus(x, [1], [2]) * TMath::Gaus(y, [3], [4])", -10., 10., -20., 20.);
  f->SetParameters(10., 2., 3., 4., 5.);
  auto h2 = (TH2D*)f->GetHistogram();
  auto h1 = h2->ProjectionX();
  h1->Draw();
}
1 Like

The counts the projection is having, are those true yield or it should be normalized by integral?

up to you …

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