TH2D* h2d = new TH2D("h2d", "2D Histogram", 10, 0, 10, 20, 0, 20); Int_t numBinsY = h2d->GetNbinsY(); cout << "Number of bins in Y direction: " << numBinsY << endl;
TFile* file = new TFile("hist.root", "READ"); TH2D* h2d = (TH2D*) file->Get("h2d"); Int_t numBinsY = h2d->GetNbinsY(); cout << "Number of bins in Y direction: " << numBinsY << endl;Description: In this example, a TH2D object is retrieved from a ROOT file using the Get function. GetNbinsY function is used to get the number of bins in the y-axis direction, which is then printed on the console. Package library: ROOT, a data analysis framework.