Applying cuts to histogram without having a TTree branch

Hi

So I created 2 list of masses and i want to apply a cut to one variable to draw the histogram of the other but I am having trouble in adding branches to my existing root file. Is there a way to apply a cut to the histogram without using the tree Draw method. Thanks for the help

ROOT Version: 6.3.0 (PyROOT to be specific)


Hello,

Once the histogram is created, the data is reduced, and no cut can be applied on the entries any more.
If you want to easily create new columns of a dataset and represent their entries as histograms, perhaps applying selection cuts, I would recommend to look into RDataFrame.

Best,
Danilo

Hi Danilo,

Thanks for the reply, I guess I can use the Filter method of RDataFrame but that would still have me add a new branch to my dataset. When I use the TTree Branch method to add a list of masses to my root file it only adds one entry, so I was trying to look for a different solution. Would it be possible for you to show me the way I can I add a list as a branch to my dataset?

Hi,

Sure: you can do it through a Define: ROOT: ROOT::RDF::RInterface< Proxied, DataSource > Class Template Reference

Cheers,
Danilo

So the second parameter to the Define method is a producer as written in the docs. Would that be referring to a function that outputs the list of masses?

I tried the Define method and here is my code:

This return the following error:

Hi Amish,

I think I start to understand what you are trying to accomplish: if I am not too wrong, we can identify an easy solution.
Are the names J_psi_15_PX J_psi_15_PY J_psi_15_PZ J_psi_15_PE and phi_1020_PX… your branches?

Cheers,
D

Hi,

Yes and just a correction the branch names for Jpsi are J_psi_1S…

Hello,

I think this is what is needed for the calculation of the mass in your case

ROOT.gInterpreter.Declare("""
float InvMass(float px1, float py1, float pz1, float e1, float px2, float py2, float pz2, float e2)
{
    ROOT::Math::PxPyPzEVector v1(px1, py1, pz1, e1);
    ROOT::Math::PxPyPzEVector v2(px2, py2, pz2, e2);
    return (v1 + v2).M();
}
""")

myDF.Define("JpsiPhiMass", "InvMass(J_psi_15_PX, J_psi_15_PY, J_psi_15_PZ, J_psi_15_PE, phi_1020_PX, phi_1020_PY, phi_1020_PZ, phi_1020_PE)")

Cheers,
Danilo

I will try this solution and let you know. Thank you for all your help Danilo

Cheers,
AG

Hi,

So this code worked but I wanted to ask, does this code add a column to my dataframe or a branch to the tree in my root file? In order to use the tree Draw method I would need a need a new branch in my tree.

And also when I do mydf.Display(“JpsiPhiMass”) it gives me the error that regex “JpsiPhiMass” did not match any column.

Alright so the final solution is as follows:
I used the above code given by Danilo and then I execute the following command:
myDF.Snapshot(“nameofTree”, “path_to_root_file”)

This will create the new column and add it to the tree in the ROOT file. Thank you for all the help on this.

1 Like

That’s right, Snapshot allows you to dump on disk the enriched ROOT dataset. Thanks for the interesting use case!

D