Example code for creation of an weighted histogram from TTree files

Hi !
Assume that i have two files, one with histogram data and a another one with weight to that data. The issue is that i want to plot a weighted histogram using ROOT. To be more precise, here is my case

In the file home/Downloads/Ovning_Root/ovning1/Signal_1fb.root there is a TTree file with two leaves. One leaf is the data ( invariantMass ) and the other one is the weight (eventWeight).

I am a beginner to ROOT so there are some things that i dont know. I want to write a code (emacs) and execute it using ROOT. It would be nice to see an example code that:

  • Load in the TTree files
  • plot a weighted histogram

Thanks on beforehand ! :slight_smile:


ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


I would suggest to first read the ROOT Guide For Beginners, it might help

Hi,
in addition to @bellenot’s suggestion, using RDataFrame (available since ROOT v6.16) this is just:

auto histo = ROOT::RDataFrame("treeName", "Signal_1fb.root").Histo1D("invariantMass", "eventWeight");
histo->Draw(); // or DrawClone(), or whatever histogram method you need to call

Cheers,
Enrico

1 Like

Thanks Guys! I stick around there in that thread :smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.