#include "MantidAPI/MatrixWorkspace.h" // Create a new MatrixWorkspace object MatrixWorkspace_sptr matrixWorkspace = MatrixWorkspace_sptr::create(); // Fill the workspace with data // Get the number of histograms in the workspace int numHistograms = matrixWorkspace->getNumberHistograms(); // Print the number of histograms in the workspace std::cout << "Number of histograms: " << numHistograms << std::endl;
#include "ROOT/TH1.h" #include "ROOT/TFile.h" int main() { // Open a ROOT file containing a histogram TFile* file = TFile::Open("histogram.root", "READ"); // Retrieve a histogram from the file TH1* histogram = (TH1*)file->Get("myHistogram"); // Print the number of bins in the histogram std::cout << "Number of bins: " << histogram->GetNbinsX() << std::endl; // Close the file file->Close(); return 0; }In this example, a ROOT file containing a histogram is opened and the `GetNbinsX()` function is used to retrieve the number of bins in the histogram. Package/library: ROOT