# How to apply a specific Cut?

**URL:** <https://root-forum.cern.ch/t/how-to-apply-a-specific-cut/56553>\
**Category:** Newbie\
**Tags:** tree, hist, root\
**Created:** [September 30, 2023, 10:01pm UTC](https://root-forum.cern.ch/t/how-to-apply-a-specific-cut/56553 "2023-09-30T22:01:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![NMarichalar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/ea5d25/32.png) [@NMarichalar](https://root-forum.cern.ch/u/NMarichalar)\
**Post date:** [September 30, 2023, 10:01pm UTC](https://root-forum.cern.ch/t/how-to-apply-a-specific-cut/56553/1 "2023-09-30T22:01:10Z")

</div>

_ROOT Version:_ 6.18  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

Hello, I am fairly new to coding in C++ and using root. I was tasked with applying cuts to a set of data and combining it. I have no issues with everything but one cut in specific. The cut takes the form: Njet(pt\>30 GeV) = 0. What it translates to as i understand is for every element in one list of the tree (pt) if its energy is above this threshold then the an associated list in the tree (Njet) element must be zero.

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [October 1, 2023, 4:47am UTC](https://root-forum.cern.ch/t/how-to-apply-a-specific-cut/56553/2 "2023-10-01T04:47:39Z")

</div>

Hello,

What would be the question exactly?

Best,  
D

---

<div class="post-metadata">

**Author:** ![NMarichalar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/ea5d25/32.png) [@NMarichalar](https://root-forum.cern.ch/u/NMarichalar)\
**Post date:** [October 1, 2023, 6:59am UTC](https://root-forum.cern.ch/t/how-to-apply-a-specific-cut/56553/3 "2023-10-01T06:59:48Z")

</div>

How would I actually go about writing this specific cut. I have not had to create cuts that depend on two different lists in a tree and their values. I assume you could iterate through the lists and check but I dont know how to do so, especially while retaining the other values that dont need the cut applied to them.

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [October 1, 2023, 10:53am UTC](https://root-forum.cern.ch/t/how-to-apply-a-specific-cut/56553/4 "2023-10-01T10:53:40Z")

</div>

Hi,

What is the meaning of `Njet(pt>30 GeV) = 0` ? Perhaps “Select events with no jet which has a transverse momentum greater than 30 GeV”?

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![NMarichalar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/ea5d25/32.png) [@NMarichalar](https://root-forum.cern.ch/u/NMarichalar)\
**Post date:** [October 1, 2023, 11:18pm UTC](https://root-forum.cern.ch/t/how-to-apply-a-specific-cut/56553/5 "2023-10-01T23:18:17Z")

</div>

Thank you for sticking with me. It means that you the Number of jets that have a pt greater than 30 GeV must be zero.

---

<div class="post-metadata">

**Author:** ![NMarichalar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/ea5d25/32.png) [@NMarichalar](https://root-forum.cern.ch/u/NMarichalar)\
**Post date:** [October 1, 2023, 11:20pm UTC](https://root-forum.cern.ch/t/how-to-apply-a-specific-cut/56553/6 "2023-10-01T23:20:49Z")

</div>

or conversely that if we have some number of jets associated with a pt above 30 GeV we want to ignore those jets

---

<div class="post-metadata">

**Author:** ![mzks](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mzks/32/30392_2.png) [@mzks](https://root-forum.cern.ch/u/mzks)\
**Post date:** [October 2, 2023, 6:41am UTC](https://root-forum.cern.ch/t/how-to-apply-a-specific-cut/56553/7 "2023-10-02T06:41:45Z")

</div>

Hello,

It is hard to imagine your situation for me. Could you please explain a bit more?  
I think that people need your tree structure.

I guessed your situation like this.  
Njet and pt are branches saving different trees, and the trees shares the eventids.  
That is, i-th entry in the both trees means the same event.  
Is this correct?

In this case, you can load the branch variables with two `tree->GetEntry(i)` in the loop for both trees, then `if(<cut condition>) continue` is a way.

---

<div class="post-metadata">

**Author:** ![NMarichalar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/ea5d25/32.png) [@NMarichalar](https://root-forum.cern.ch/u/NMarichalar)\
**Post date:** [October 2, 2023, 6:44am UTC](https://root-forum.cern.ch/t/how-to-apply-a-specific-cut/56553/8 "2023-10-02T06:44:06Z")

</div>

yes, this is correct. pt and Njet are variables in the trees of the data I am working with. I need to apply this specific cut using both of these variables associated with one another in an event

---

<div class="post-metadata">

**Author:** ![mzks](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mzks/32/30392_2.png) [@mzks](https://root-forum.cern.ch/u/mzks)\
**Post date:** [October 2, 2023, 6:55am UTC](https://root-forum.cern.ch/t/how-to-apply-a-specific-cut/56553/9 "2023-10-02T06:55:42Z")

</div>

Maybe you need this?

```auto
   auto file1 = TFile::Open("your file 1");
   auto tree1 = dynamic_cast<TTree*>(file1->Get("tree"));
   auto file2 = TFile::Open("your file 2");
   auto tree2 = dynamic_cast<TTree*>(file2->Get("tree"));

   // Prepare
   Float_t pt;
   Int_t Njet;
   TBranch *b_pt;
   TBranch *b_Njet;
   tree->SetBranchAddress("pt", &pt, &b_pt);
   tree->SetBranchAddress("Njet", &Njet, &b_Njet);

   ULong64_t n_entries = tree1->GetEntries();
   for(ULong64_t i_entry=0; i_entry<n_entries; ++i_entry){
       tree1->GetEntry(i_entry);
       tree2->GetEntry(i_entry);

       if (pt > 30) continue;
       if (Njet == 0) continue;

       // to do something after cut
   }

```

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [October 2, 2023, 12:03pm UTC](https://root-forum.cern.ch/t/how-to-apply-a-specific-cut/56553/10 "2023-10-02T12:03:42Z")

</div>

Hi,

I could also propose a [RDataFrame](https://root.cern/manual/data_frame/) based solution for skipping the events with at least a jet with pt \> 30:

```auto
// ... here your DF is initialised...
df.Filter("ROOT::VecOps::Max(pt) < 30") // the event is skipped

```

if you want to deal only with the jets with pt smaller than 30, e.g. their `eta` (not sure is relevant since it’s not clear if this is part of your tree

```auto
df.Define("good_indices", "pt<30").Define("jetpt_less_30", "pt[good_indices]").Define("eta_less_30", "eta[good_indices]")

```

I hope this simplifies the formulation of the problem.

Cheers,  
D
