How to apply a specific Cut?

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.

Hello,

What would be the question exactly?

Best,
D

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.

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

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.

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

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.

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

Maybe you need this?

   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
   }

Hi,

I could also propose a RDataFrame based solution for skipping the events with at least a jet with pt > 30:

// ... 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

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

2 Likes