I want to access the values of a variable in events that pass a particular cut selection. That means that I want to access the actual numbers in a list.
Selection cuts can be applied using the Draw function of a TTree. For a histogram of the values of the variable el_pt in events that contain the flag variable e_jets (indicating that the event has passed some prior selection) the procedure could be something like the following:
from ROOT import *
ROOTFile1Name = "output_13TeV.root"
variablesTreeName = "nominal"
variable = "el_pt"
selection = "e_jets"
ROOTFile1 = TFile(ROOTFile1Name)
variablesTree1 = ROOTFile1.Get(variablesTreeName)
histogram1 = TH1F(
"histogram1",
"histogram1",
100,
0,
300000
)
variablesTree1.Project("histogram1", variable, selection)
histogram1.Draw()
Rather than drawing a histogram of the values of the variable, I want to access the values themselves, likely as a simple list of numbers. This could be used in a function that recommends a certain histogram binning, for example. What I have so far is the following:
from ROOT import *
ROOTFile1Name = "output_13TeV.root"
variablesTreeName = "nominal"
variable = "el_pt"
selection = "e_jets"
ROOTFile1 = TFile(ROOTFile1Name)
variablesTree1 = ROOTFile1.Get(variablesTreeName)
# Make a list of all of the event numbers that pass the selection.
variablesTree1.Draw(">>eventNumberList1", variable, selection)
# Convert the list of event numbers to a list of events.
eventList1 = variablesTree1.SetEventList(eventNumberList1)
How could I proceed now with a view to creating a list that contains the values of the variable el_pt?