Hi, here’s what I was trying to do:
[ol]
[li] Loop over the names of many root files, all of similar format .root, and extract and for each.[/li]
[li] Open each file, and extract the number of entries in a tree.[/li]
[li] Make a TH2 plot with and on the axes, and the corresponding number of entries as bin content.[/li][/ol]
I’ve managed to do that, and here’s a simplified core version of the code I have:
id_dict = {}
#some code fills id_dict, such that id_dict[<file_identifier>]=[<id1>,<id2>]
selection = "(eT_miss > 500)" #Some cut on a variable
histo = ROOT.TH2D("histo","My Histogram",10,400,900,12,0,300)
for file in id_dict: #Loop over the files
rootfile = ROOT.TFile(file, "read") #Open the file
tree = rootfile.Get("MyTree") #Open the tree
id_dict[file].append(int(MyTree.GetEntries(selection)))#Store the number of entries
for i in range(0, id_dict[file][2]): #Loop length = number of entries
histo.Fill(id_dict[file][0], id_dict[file][1]) #Fill the histogram
histo->Draw() #ta-da!
What I want to do is add weights. As far as I know, I can’t just pass weights as an argument in “MyTree.GetEntries()”, like I would do with “Draw()”. The weights I want to add exists as branches in MyTree - let’s call them “Weight1” and “Weight2”.
Ideally, I’d like to fill my histogram with the number of events, for each file, that pass the selection “selection”, and weighted by “Weight1*Weight2”. Is there a tree-level way of doing this, without having to loop over all the events in the tree?
Thanks!