#include#include int main() { TFile *inputFile = TFile::Open("histograms.root"); TH1D *histogram = (TH1D*) inputFile->Get("myHistogram"); double rms = histogram->GetRMS(); // compute the RMS std::cout << "RMS of the histogram: " << rms << std::endl; inputFile->Close(); return 0; }
#includeIn this example, we create a new histogram using an array of values and compute its RMS only between bins 2 and 5 using the TH1D GetRMS method. We then print the result to the console. The package library used is ROOT (CERN).#include int main() { TFile *inputFile = TFile::Open("histograms.root"); // create a histogram using an array of values double values[] = {1, 2, 3, 4, 5, 6}; TH1D *histogram = new TH1D("myHistogram", "", 6, 0, 6); for (int i=0; i<6; i++) histogram->SetBinContent(i+1, values[i]); double rms = histogram->GetRMS(2,5); // compute the RMS between bins [2, 5] std::cout << "RMS of the histogram: " << rms << std::endl; inputFile->Close(); return 0; }