Hi there,
I have an possible issue with projecting vector branches out of a pair of TTrees. I assign a TTreeIndex to both TTrees and “friend them”:
# Assign common TTree Index
truth_index = TTreeIndex(truth_tree, "eventNumber", "0")
reco_index = TTreeIndex(reco_tree, "eventNumber", "0")
reco_tree.SetTreeIndex(reco_index)
truth_tree.SetTreeIndex(truth_index)
# "Combine TTress" by using Add Friend
truth_tree.AddFriend(reco_tree,reco_tree.GetName())
I have been using the Project function to generate TH2D histogram but notice that the behaviour is odd when projecting out a vector branch (perhaps this is expected?). For example, consider a branch of a TTree which is of varying length for each individual event in the TTree. I do:
hist2 = TH2D("hist2d","",len(bins)-1,bins)
truth_tree.Project(hist2.GetName(), truth_tree.GetName()+".<branch1>:" + reco_tree.GetName() + ".<branch1>")
For some - but not all - branches, this wrongly fills the TH2D, placing events in cells which should be empty. Specifically, if this branch corresponds to el_pt
to which the cut “>25 GeV” has been previously applied to both truth and reco TTrees, then all cells below 25 GeV in the TH2D should be empty. This is not the case, as the bottom row is filled?
Example code below for pre-loaded TTrees:
# Assign common TTree Index
truth_index = TTreeIndex(truth_tree, "eventNumber", "0")
reco_index = TTreeIndex(reco_tree, "eventNumber", "0")
reco_tree.SetTreeIndex(reco_index)
truth_tree.SetTreeIndex(truth_index)
# "Combine TTress" by using Add Friend
truth_tree.AddFriend(reco_tree,reco_tree.GetName())
import numpy as np
binX = np.linspace(0,100e3,21)
binY = binX
hist2d=TH2D("_unnormalised","",len(binX)-1,binX,len(binY)-1,binY)
varexp = truth_tree.GetName()+".el_pt:"+reco_tree.GetName()+".el_pt"
truth_tree.Project(hist2d.GetName(),varexp )#,selection,"",num_events_used,first_event)
hy=hist2d.ProjectionY()
h1d =TH1D("h1d","",len(binX)-1,binX)
reco_tree.Project(h1d.GetName(),"el_pt")
print(h1d.GetBinContent(1))
print(hy.GetBinContent(1))
returns:
0.0
9.0
i.e. different values. The first is expected…
Tested on ROOT versions 6.08.06 locally, and on 6.22.08 on lxplus
Thanks,
Ethan