Try (sensitive to user’s changes to the current x-axis range):
std::cout << h->GetMean() * h->Integral() << "\n"; // mean * integral
and/or (valid only for the “entire” x-axis range):
std::cout << h->GetMean() * h->GetSumOfWeights() << "\n";
Another good idea would be (sensitive to user’s changes to the current x-axis range):
// change the x-axis range, if desired, and then ...
Double_t stats[(TH1::kNstat)]; // sums of w, w^2, w*x, w*x^2, ...
h->GetStats(stats);
std::cout << stats[2] << "\n"; // sum of w*x
Then the error could be (whatever you like more):
std::cout << " +- " << TMath::Sqrt(stats[3]) << "\n"; // sqrt(sum of w*x^2)
or (note: “stats[1] / stats[0]
” is the “average” weight):
std::cout << " +- " << TMath::Sqrt((stats[1] / stats[0]) * stats[3]) << "\n";
or:
std::cout << " +- " << TMath::Sqrt(TMath::Sq(mean_error * integral) + TMath::Sq(mean * integral_error)) << "\n";