GetDetectorData - function to return the locations and detector response
 	tensor of the detector described by detectorName.

	detectorName - Name of required GW IFO.  Can be 'H1', 'L1', 'V1', 'I1'
	or 'K1'.

	Returns detRespTensor - Detector response tensor of the IFO.
	    	detPosVector - Position vector of the IFO.

        Sarah Gossan 2012. Last updated 02/18/14.

def GetDetectorData(detectorName):
    """ GetDetectorData - function to return the locations and detector response
 	tensor of the detector described by detectorName.

	detectorName - Name of required GW IFO.  Can be 'H1', 'L1', 'V1', 'I1'
	or 'K1'.

	Returns detRespTensor - Detector response tensor of the IFO.
	    	detPosVector - Position vector of the IFO.

        Sarah Gossan 2012. Last updated 02/18/14. """

    # Allocate direction vectors and position of IFO given detectorName
    detPosVector = np.zeros(3)
    nx = np.zeros(3)
    ny = np.zeros(3)

    ################# aLIGO HANFORD #############
    if detectorName == 'H1':
	nx[0] = -0.22389266154
	nx[1] = 0.79983062746
	nx[2] = 0.55690487831

	ny[0] = -0.91397818574
	ny[1] = 0.02609403989
	ny[2] = -0.40492342125

	detPosVector[0] = -2.16141492636e6
	detPosVector[1] = -3.83469517889e6
	detPosVector[2] = 4.60035022664e6
    ################# aLIGO LIVINGSTON ##########
    elif detectorName == 'L1':
	nx[0] = -0.95457412153
	nx[1] = -0.14158077340
	nx[2] = -0.26218911324

	ny[0] = 0.29774156894
	ny[1] = -0.48791033647 
	ny[2] = -0.82054461286

	detPosVector[0] = -7.42760447238e4
	detPosVector[1] = -5.49628371971e6
	detPosVector[2] = 3.22425701744e6
    ################# AdvVIRGO ##################
    elif detectorName == 'V1':
	nx[0] = -0.70045821479
        nx[1] = 0.20848948619
        nx[2] = 0.68256166277

        ny[0] = -0.05379255368 
        ny[1] = -0.96908180549
        ny[2] = 0.24080451708

        detPosVector[0] = 4.54637409900e6
        detPosVector[1] = 8.42989697626e5
        detPosVector[2] = 4.37857696241e6
    ################# INDIGO ####################
    elif detectorName == 'I1':
	# Not cached LIGO detector - construct x, nx and ny from other
	# quantities
	vxLat = (14. + 14./60.)*(np.pi/180.) # Vertex latitude
	vxLon = (76. + 26./60.)*(np.pi/180.) # Vertex longitude
	vxElev = 0. # Vertex elevation
	xAlt = 0. # Altitude of x-arm
	yAlt = 0. # Altitude of y-arm
	xAz = np.pi/2. # Azimuth of x-arm
	yAz = 0. # Azimuth of y-arm

	cosLat = np.cos(vxLat)
        sinLat = np.sin(vxLat)
        cosLon = np.cos(vxLon)
        sinLon = np.sin(vxLon)

        ellDenom = np.sqrt(AWGS84*AWGS84*cosLat*cosLat + \
                           BWGS84*BWGS84*sinLat*sinLat)
        locRho = cosLat*(AWGS84*AWGS84/ellDenom + vxElev)
        
        # Position
        detPosVector[0] = locRho*cosLon
        detPosVector[1] = locRho*sinLon
        detPosVector[2] = sinLat*(BWGS84*BWGS84/ellDenom + vxElev)

        # x-Arm vector
        cosxAlt = np.cos(xAlt)
        sinxAlt = np.sin(xAlt)
        cosxAz = np.cos(xAz)
        sinxAz = np.sin(xAz)
        uxNorth = cosxAlt*cosxAz
        uxEast = cosxAlt*sinxAz
        uxRho = -sinLat*uxNorth + cosLat*sinxAlt

        nx[0] = cosLon*uxRho - sinLon*uxEast
        nx[1] = sinLon*uxRho + cosLon*uxEast
        nx[2] = cosLat*uxNorth + sinLat*sinxAlt

        # y-Arm vector
        cosyAlt = np.cos(yAlt)
        sinyAlt = np.sin(yAlt)
        cosyAz = np.cos(yAz)
        sinyAz = np.sin(yAz)
        uyNorth = cosyAlt*cosyAz
        uyEast = cosyAlt*sinyAz
        uyRho = -sinLat*uyNorth + cosLat*sinyAlt

        ny[0] = cosLon*uyRho - sinLon*uyEast
        ny[1] = sinLon*uyRho + cosLon*uyEast
        ny[2] = cosLat*uyNorth + sinLat*sinyAlt

    ################# KAGRA #####################
    elif detectorName == 'K1':
	# Not cached LIGO detector - construct x, nx and ny from other
        # quantities
        vxLat = (36.25)*(np.pi/180.) # Vertex latitude
        vxLon = (137.18)*(np.pi/180.) # Vertex longitude
        vxElev = 0. # Vertex elevation
        xAlt = 0. # Altitude of x-arm
        yAlt = 0. # Altitude of y-arm
        xMid = 1500. # Midpoint of x-arm
        yMid = 1500. # Midpoint of y-arm
        xAz = 19.*(np.pi/180.) + np.pi/2. # Azimuth of x-arm
        yAz = 19.*(np.pi/180.) # Azimuth of y-arm

        cosLat = np.cos(vxLat)
	sinLat = np.sin(vxLat)
	cosLon = np.cos(vxLon)
	sinLon = np.sin(vxLon)

	ellDenom = np.sqrt(AWGS84*AWGS84*cosLat*cosLat + \
		           BWGS84*BWGS84*sinLat*sinLat)
	locRho = cosLat*(AWGS84*AWGS84/ellDenom + vxElev)

	# Position
	detPosVector[0] = locRho*cosLon
	detPosVector[1] = locRho*sinLon
	detPosVector[2] = sinLat*(BWGS84*BWGS84/ellDenom + vxElev)

	# x-Arm vector
	cosxAlt = np.cos(xAlt)
	sinxAlt = np.sin(xAlt)
	cosxAz = np.cos(xAz)
	sinxAz = np.sin(xAz)       
	uxNorth = cosxAlt*cosxAz
	uxEast = cosxAlt*sinxAz
	uxRho = -sinLat*uxNorth + cosLat*sinxAlt

	nx[0] = cosLon*uxRho - sinLon*uxEast
	nx[1] = sinLon*uxRho + cosLon*uxEast
	nx[2] = cosLat*uxNorth + sinLat*sinxAlt

	# y-Arm vector
	cosyAlt = np.cos(yAlt)
        sinyAlt = np.sin(yAlt)
        cosyAz = np.cos(yAz)
        sinyAz = np.sin(yAz)
	uyNorth = cosyAlt*cosyAz
        uyEast = cosyAlt*sinyAz
        uyRho = -sinLat*uyNorth + cosLat*sinyAlt

        ny[0] = cosLon*uyRho - sinLon*uyEast
        ny[1] = sinLon*uyRho + cosLon*uyEast
        ny[2] = cosLat*uyNorth + sinLat*sinyAlt

    # Compute detRespTensor as 
    # detRespTensor = 0.5(nx \outerprod nx - ny \outerprod ny)
    detRespTensor = np.zeros((3,3),float)
    for i in range(0,3):
	for j in range(0,3):
	    detRespTensor[i,j] = (nx[i]*nx[j] - ny[i]*ny[j])*0.5

    return detRespTensor,detPosVector