TH1D is a class in the ROOT framework that represents a one-dimensional histogram with double precision bins. The GetNbinsX() function is a built-in method of the TH1D class that returns the number of bins in the x-axis of the histogram.
Example 1: This example creates a new TH1D histogram with 20 bins and uses the GetNbinsX() function to retrieve the number of bins in the x-axis. The output will be 20.
```c++ #include
void example1() { TH1D* h = new TH1D("h1", "Example Histogram", 20, 0, 100); int nbins_x = h->GetNbinsX(); std::cout << "Number of bins in the x-axis: " << nbins_x << std::endl; }
Example 2:
This example reads in an existing TH1D histogram from a ROOT file and uses the GetNbinsX() function to retrieve the number of bins in the x-axis. The output will be the number of bins in the x-axis of the histogram.
c++
#include
#include
void example2() {
TFile* infile = TFile::Open("example.root");
TH1D* h = (TH1D*)infile->Get("h1");
int nbins_x = h->GetNbinsX();
std::cout << "Number of bins in the x-axis: " << nbins_x << std::endl;
infile->Close();
}
```
The TH1D class is part of the ROOT package library.
C++ (Cpp) TH1D::GetNbinsX - 30 examples found. These are the top rated real world C++ (Cpp) examples of TH1D::GetNbinsX extracted from open source projects. You can rate examples to help us improve the quality of examples.