#! /usr/bin/env python
#
# 2014.Feb.28
# this is a script to estimate the power recycling gain for 9 MHz sideband using POPAIR_B_RF18

from scipy.special import jn


# soem parameters
gamma9 = 0.17 # in rad for 9 MHz alog 9979 (11/Feb/2014)
Pin = 8.8 * 0.8 # incident on PRM assuming Timc = 0.8
J1 = jn(1, gamma9) # bessel 1st kind 
Tpr2 = 229e-6 # according to Nebula https://galaxy.ligo.caltech.edu/optics/
Rbs1 = 0.9 # BS which separates in-air and in-vac. M12 in D1000313-v10
Tbs2 = 0.5 # BS which separates the light to A and B diodes on ISCT1



# calibration of POPAIR_B_RF18
calib = 7803.0 / (5.13e-3 * 0.93 * 0.1) # in counts/W at 18 MHz (alog 9845)
print "POPAIR_RF18 calib = %e counts/W at 18 MHz"%(calib)

### actual estimation starts here
measuredCoutns = 18000 # measured Feb.28 with ring heater completely off
wfg = 10**(45.0/20.0) # whitening gain for RF18 was set to be 45 dB
Pam = measuredCoutns / wfg / calib# AM component in W at POPAIR_B
print "Pam = %f uW"%(Pam*1e6)

# estimation
Gpr = Pam / (2 * Pin * J1**2 * Tpr2 * Rbs1 * Tbs2)
print "PR gain for 9 MHz is %f"%Gpr

