Skip to content

Instantly share code, notes, and snippets.

@mickypaganini
Created December 18, 2015 09:35
Show Gist options
  • Save mickypaganini/aa991054a91d7954425b to your computer and use it in GitHub Desktop.
Save mickypaganini/aa991054a91d7954425b to your computer and use it in GitHub Desktop.
function to compute the distance deltaR between two objects given their eta and phi coordinates
def deltaR(eta1, eta2, phi1, phi2):
import math
'''
Definition:
-----------
Function that calculates DR between two objects given their etas and phis
Args:
-----
eta1 = float, eta of first object
eta2 = float, eta of second object
phi1 = float, phi of first object
phi2 = float, phi of second object
Output:
-------
deltaR = float, distance between the two objects
'''
DEta = abs(eta1-eta2)
DPhi = math.acos(math.cos( abs( phi1-phi2 ) ) ) # hack to avoid |phi1-phi2| larger than 180 degrees
return math.sqrt( pow(DEta,2) + pow(DPhi,2) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment