Cuts in TMVAClassification macro

Dear ROOT forum,

Hello, I want to use as a cut the transverse momentum of a B meson and I have this modification of TMVAClassification.C

dataloader->AddVariable( "B_kaon_px", "B_kaon_px", "units", 'F' );
dataloader->AddVariable( "B_kaon_py", "B_kaon_py", "units", 'F' );
dataloader->AddVariable( "B_kaon_pz", "B_kaon_pz", "units", 'F' 

These variables are TLorentzVector in the tree of the source data, and I can get vector.Pt() and vector.Eta() in another macro, but how I can to use pT and eta as Tcuts?

BTW I tried with Spectactor variables (i.e. pT = [(B_kaon_px)^2 + …+B_kaon_pz)^2 ]^(1/2) but it didn’t work.

I ask this because of I don’t have the branches of pT and Eta, and I thought I create the branches, append in the original tree an used it. Also, I thought to call the first macro, but I don’t know if it is possible. Could you please help me to find another way?

Thanks for your attention,
Have a nice day :slight_smile:

Atte. Karen


You should be able to use either the approach you describe, but with AddVariable and not AddSpectator. E.g.

dataloader->AddVariable( "pT = pow(pow(B_kaon_px, 2), 0.5)", "units", 'F' );

As long as B_kaon_px exists as a branch in your tree.

You could also look into using RDataFrame and in particular the Define and Snapshot actions. With these you can easily save a new copy of your data with some added branches. E.g.

RDataFrame df{"path/to/orig/tree"};
df.Define("pt", "pow(pow(B_kaon_px, 2), 0.5)")

You can read more about RDataFrame here.