Howdy, quick question here (I think) I’m getting confused by my VecOps
I’m reading in a tree and creating a collection from it:
df1 = rdf.Define("l0", "ROOT::Math::PtEtaPhiMVector(lepton_pt.at(0,-999),lepton_eta.at(0,0),lepton_phi.at(0,0),0)")
as suggested in this older post
First I’d like to be able to define a collection and push back multiple items into it, eg leptons containing l0, l1, l2 etc depending on the length of the RVec I’m reading from.
Now from these RVec objects I’d like to make a selection without filtering the events. Eg, say in an event I have,
l1(8,1,1,0)I’d like to plot the pt of the object with the highest pt in the event that also has a rapidity of
8in this case. Can I sort the vector collection?
Finally I’d like to extend the event data model, so rather than l0, and l1 being
ROOT::Math::LorentzVectorsthey are lepton objects with members like
l0.vector.Pt() = 0, l0.passesEtaSelection=Falseetc such that I can snapshot them.
I’m fairly sure each of these are possible but I’m trying to create a nice example and am struggling. I’ve written out a quick pseudo code in pyroot below.
import ROOT f = ROOT.TFile.Open('inputfile.root') for event in f.tree: pt_hist = ROOT.TH1F("","",10,0,10) highest_pt = 0 for lepton in event.leptons: if lepton.Eta()>0: if lepton.Pt()>highest_pt: highest_pt = lepton.Pt() pt_hist.Fill(highest_pt) c = ROOT.TCanvas() pt_hist.Draw() c.SaveAs("pt_eta_passing.png")
import ROOT rdf0 = ROOT.RDataFrame('tree', 'inputfile.root') rdf1 = rdf0.Define('my_leptons','fill_leptons(leptons)') #assuming 'fill_leptons' returns LorentzVectors rdf2 = rdf1.Define('my_etaleptons','my_leptons.Eta() > 0') #or with a custom flag rdf2 = rdf1.Define('my_etaleptons','my_leptons.passesEtaSelection' pt_hist = rdf2.Histo1D(("pt", "Lepton Collections", 16, 0, 4), "my_etaleptons.at(0).Pt()") c = ROOT.TCanvas() pt_hist.Draw() c.SaveAs("pt_eta_passing.png")
ROOT Version: 6.22/06