# Cuts in TMVAClassification macro

**URL:** <https://root-forum.cern.ch/t/cuts-in-tmvaclassification-macro/29909>\
**Category:** TMVA\
**Created:** [July 23, 2018, 4:13am UTC](https://root-forum.cern.ch/t/cuts-in-tmvaclassification-macro/29909 "2018-07-23T04:13:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![KarenDmn](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/a9a28c/32.png) [@KarenDmn](https://root-forum.cern.ch/u/KarenDmn)\
**Post date:** [July 23, 2018, 4:13am UTC](https://root-forum.cern.ch/t/cuts-in-tmvaclassification-macro/29909/1 "2018-07-23T04:13:03Z")

</div>

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

```auto
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 🙂

Atte. Karen

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [July 23, 2018, 10:51am UTC](https://root-forum.cern.ch/t/cuts-in-tmvaclassification-macro/29909/2 "2018-07-23T10:51:29Z")

</div>

Hi,

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

```auto
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.

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

```

You can read more about `RDataFrame` [here](https://root.cern.ch/doc/master/classROOT_1_1RDataFrame.html).

Cheers,  
Kim
