Apply a Cut and a weight on the histogram

Hi all,

I have several runs (root files), and I need to plot some variable (for each run) and apply a cut and a weight at the same time. Each run has a different weighting factor. So I have:

TTree *t[n]; //n : number of runs
TCut icut = “a>0”;
Double_t weights[ ] = {w1, w2, …,wn};

when I try:

t[i] ->Draw(“h”,(icut)*“weights[i]”,""); // i = 0,…,n

it does not work. However, when I replace it with a number say:

t[i] ->Draw(“h”,(icut)*“0.8”,"");

it works.

Is there away to be able to read the weights from an array and apply it in each run?



Hi Sharey,

The variable you are using, weights[i], is a double, but you are using it inside of a string, and so it is being interpreted literally as “weights[i]”. The best way I’ve found to use a variable inside a cut is to use the Form() function, explained in the documentation here.

So for your example you could do the following:


Or to keep it all in one string, you could do


Or, if your cut is constant across all your files, you could even do


Hope this helps!

hi hyperbolee,

it works now! Great thanks. :slight_smile:


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