TH1D* hist = new TH1D("hist","Example Histogram",100,0,10); // Set the error of bin 5 to 0.2 hist->SetBinError(5, 0.2);
TH1D* hist = new TH1D("hist","Example Histogram",100,0,10); // Loop over all bins and set the error values randomly for(int i=1; i<=hist->GetNbinsX(); i++) { hist->SetBinError(i, rand() % 10 / 10.0); }In this example, the SetBinError function is used in a loop to set the error values of all bins randomly between 0 and 1. The package library for TH1D is included in the ROOT Data Analysis Framework.