#include#include int main() { TFile* file = TFile::Open("data.root"); TH1D* hist = (TH1D*) file->Get("histogram"); double mean = hist->GetMean(); // do something with mean return 0; }
#includeIn this example, we create a new TH1D histogram and fill it with data. The data points also have weights, which are used to fill the histogram with the `Fill` function. We then call the GetMean function with an argument of `1` to indicate that we want to use the weights when calculating the mean value. This mean value is stored in the variable `mean`. Package library: ROOT library.int main() { TH1D* hist = new TH1D("histogram", "Histogram Title", 100, 0, 1); // fill histogram with data for (int i = 0; i < 1000; i++) { double x = some_function(); // get data point double weight = some_weight_function(x); // get weight for data point hist->Fill(x, weight); } double mean = hist->GetMean(1); // use weights when calculating mean // do something with mean return 0; }