How to combine Tree.Project with weights read from an external .root


While calling the Tree.Project method, is there a way to also call/read external .root files that would read for instance scale factors “dynamically” that can be then applied on a per-event case on the values filled histo called by the Tree.Project ?

For instance, I have the tree, that I want to apply a series of cuts, but also apply weights at the same time from an external source.

I hope my question is clear.


I am not sure I fully understand. Are this “scale factors” in an other tree ? Is there one scale factor per event in the main tree ?

Right, let me describe it better.

I call the

mytree.Project(varName, cuts)

and the cuts has all the info/applied selection acting on the mytree of course. But then, for each of the events that is “projected” I would need for instance to know the exact value like the pT/eta (that are branches in the myTree) of the events that are selected/projected, and then use those as input to another fuction that would open another .root histo to extract the corresponding scale factor from a histo.

So the sequence should be like

.- project using a predifined set of cuts from the mytree
.- for each projected event, extract info from a TBranch and use it as input to another function
.- apply also the result of the previous function per event on the projection

I know I can loop go through all the events in the tree sequentially, and then extracting whatever variable that is the input to another function is trivial, but this is way too slow vs projecting.

Thanks for the explanations.
I guess @pcanal will have some idea about your problem.

Something like this pseudo code could work:

create someHistogram;
for (factors_file in all_files_with_factors) {
  open factors_file;
  retrieve histo_with_factors;
  set pt_eta_specific_factor;
  current_cuts = "pt_eta_specific_factor * (pt/Eta in range_valid_for_current_factors_file && cuts)";
  mytree.Project("someHitogram+", varName, current_cuts); // note the "+"
  close factors_file;

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