Applying conditional weights while tree.Project


I want to tree.Project while stitching also W+jets inclusive with W+Njets exclusive samples.

The weight applied depends on the nLHE that is a Branch in the tree.

For example, I first create the dictionnairy storing the appropriate weight for each dataset

             for i in range(1,5) :
                  nn = 'W{0:d}JetsToLNu'.format(i)
                  if search(nickNames, nn) :
                      sampleWeight[nn] = (weights_['WJetsToLNu']/xsec_wjetsincl + WxGenweightsArr[i-1]/(xsec_[i-1]))

now, what I do not know how to do it, is basically how while tree.Project to perform the equivalent to that

    if tree.LHE_Njets > 0 : sWeight = sampleWeight['W{0:d}JetsToLNu'.format(tree.LHE_Njets)]
    elif tree.LHE_Njets == 0 : sWeight = sampleWeight['WJetsToLNu']

is there a way as part of the cut string to also pass the conditional weighting of the event?

Thanks in advance


Thanks for the question.
I think @pcanal could help here.

I take also the opportunity to ask a, perhaps naive, question (please ignore if it does not make sense for the work you are trying to accomplish!): would it be possible to express all the operations with RDataFrame? In case of doubts we would of course support you…


Thanks Danilo

While waiting for @pcanal to reply, regarding your question about RDataFrame, the answer is not at this point of the analysis, which is rather mature etc. But in the long term, yes, we would like to try to migrate our code to something like that.


Hello Alex,

Fair enough: this makes a lot of sense.
In case you need support for the next RDataFrame based version of your analysis, just don’t hesitate to come back to us.
(and yes, let’s wait for Philippe to clarify the original doubt)


if the data is part of the tree you can use something like:

   (LHE_Njets > 0) * ( expression using branch/leaf names) + (tree.LHE_Njets == 0) * (other expression using branch/leaf names)

if the data is not then you need to use a static function and call it from Project.

   some_static_function(LHE_Njets, ...)

If neither of those work in your cases (and since moving to RDataFrame is not an option), you can use a script fragment as the Project argument (see ROOT: TTreePlayer Class Reference for the detail on how to write that script fragment)

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