Use TTree::Draw() to a histogram with weights and weight errors coming from branches

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.

Hi,

In ROOT, 1-D histograms store information about the bin content and its error, in a statistically meaningful manner.
There could be ways in which the error on the weight could be represented in the final histogram, but I would not be sure about how to take this into account properly from the statistical point of view. One could think about histograms with more than 1 dimensions, which are available in ROOT, however there is no procedure which is ready to be used out of the box I fear.

I realise the answer might not be fully satisfactory, but I hope it can help nevertheless.

Cheers,
Danilo

Hi @Danilo

I had a feeling the answer would be along those lines, since I am somewhat torturing the concept of ROOT histograms. The idea here was to propagate MC-provided systematic uncertainties, while “turning off” the statistical ones form the histogram, as it were. I can always add the statistical uncertainties back in later when needed, but the systematics get lost if I don’t handle them at the source.

I will think about workarounds elsewhere in my code. Thank you for your help!