How to use a branch as weights on histogram?

I am trying to use weights on my histogram but all bins of the histogram returns to 0. Weights are stored in a friendtree branch. Each entry has a weight.


  myhistogram = ROOT.TH3F('myhistogram','name', X, axesbinsX.GetArray(), Y, YArray, Z, ZArray)
  cuts = "branchname1 < 10000"

  tree.Draw(f"strings:{particle}>>+myhistogram", f"({cuts}) * cloned_tree.friend_tree.weights")

If i use a number instead the cloned_tree.friend_tree.weights, it works.

I tried to print the entries of this friend_tree by:

  for entry in tree:
    weight = getattr(entry, "friend_tree.weights")

and this actually prints the weights. There are non-zero weights but the weights are negative sometimes. Temporarily, I tried to set the weights to 0 when it is negative:

tree.Draw(f"strings:{particle}>>+myhistogram", f"({cuts}) * (cloned_tree.friend_tree.weights> 0 ? cloned_tree.friend_tree.weights :0 )")
Which did not work as well.

Hi @greentree, Thanks for your question.

Adding @couet and @linev who might be able to help you.

Thanks,
Dev

@devajith

Question is not about graphics but TTree::Draw syntax.

Maybe @pcanal can help here.

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