How to create a 2D histogram from TTree data without knowing range of that data in advance

Suppose I have a TTree that contains two branches b1 and b2. Then I want to create a 2D histo from data which is b1:b2. How to do this if I know range of neither b1 nor b2 in advance.

Thanks in advance.

{
  gStyle->SetOptStat("nemruo"); // "uo" for "underflows" and "overflows"
  TFile *f = TFile::Open("hsimple.root");
  if ((!f) || f->IsZombie()) { delete f; return; } // just a precaution
  TTree *t; f->GetObject("ntuple", t);
  if (!t) { delete f; return; } // just a precaution
#if 0 /* 0 or 1 */
  TH2D *h = new TH2D("h", "H;X;Y;Z", 20, 0., 0., 20, 0., 0.);
#else /* 0 or 1 */
  TH2D *h = new TH2D("h", "H;X;Y;Z",
                     20, t->GetMinimum("px"), t->GetMaximum("px"),
                     20, t->GetMinimum("py"), t->GetMaximum("py"));
#endif /* 0 or 1 */
  t->Project("h", "py:px");
  h->Draw("SURF1");
}

Thank you. Pretty natural solution.

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