I tried to store multiple TLorentzVector objects in a list, let’s say mass_bjet.
dRel = ROOT.TLorentzVector ()
mass_bjet = []
for k in range(10):
lepton0 = ROOT.TLorentzVector ()
mass_bjet.append(lepton0)
mass_lep_close_data.Fill((mass_bjet[k]+dRel).M())
However, the error said
TypeError: TLorentzVector TLorentzVector::operator+(const TLorentzVector&) =>
TypeError: could not convert argument 1
The error is gone when I used (lepton0+dRel) instead, so I guess List is not compatible with TLorentzVector. What is the approach to store TLorentzVector objects in a list/array in python? Thank you so much!
Dear @Enki ,
Thanks for reaching out! Please, refrain from using TLorentzVector in your code. It is a legacy class, as stated in the docs. The suggested alternative is ROOT::Math::LorentzVector or one of its specialisations. They can naturally be used in Python lists, for example:
l = []
l.append(ROOT.Math.XYZTVector())
(l[0] + ROOT.Math.XYZTVector()).M() # prints 0.0
However the attribute ‘SetPtEtaPhiE’ is not found. I also tried ‘SetCoordinates’ but it only accepts one parameter. How to set coordinate values for the 4-vector? Thank you!