Hi all,
I have a TTree with a few branches output by simulation code, with each entry representing one MC event. One of the branches is the weight W of the event, and another is the quadratic error WE of the event.
Plotting histograms with the right total weight is easy, for example:
tree->Draw("Energy >> hist(100,0,100)", "W" );
Or it could be done more manually with a loop over the TTree that calls hist->Fill(Energy, W)
. However, both of these approaches lose the information on the weight error, since it is assumed to be W^2 for every event, instead of WE. Is there a way to propagate this information to the histogram?
I guess I could do something like:
TH1D hist("hist", "hist", 100, 0, 100);
tree->Draw("Energy >> hist", "W" );
TH1D hist_we("hist_we", "hist_we", 100, 0, 100);
tree->Draw("Energy >> hist_we", "WE" );
vector<double> binned_errors (0);
for (size_t i = 0; i < hist_we->GetNbinsX(); i++)
binned_errors.push_back( sqrt(hist_we.GetBinContent(i+1)) );
hist.SetError( &binned_errors[0] );
But it’s very awkward.
I looked in the forums, but the only solutions I saw were for people that really just wanted to make TGraphErrors, but were doing it with histograms for whatever reason, e.g. here.