#! /usr/bin/env python
#
# A simple script to estimate the MICH optical gain
from pylab import *
from scipy.special import jn


####### parameters
c = 299792458.0
lamda = 1064e-9

W2C = 3.37e6 # counts/watts at 980 nm (alog 9630)
eta980 = 0.67 # PD responsibity at 980 nm (C30642G InGaAs) 
eta1064 = 0.76 # PD responsibity at 1064 nm (C30642G InGaAs)
W2C_1064 = W2C /eta980 * eta1064 # counts/watts at 1064 nm

gamma45 = 0.07 # alog 9395
J0 = jn(0, gamma45) # J0 component
J1 = jn(1, gamma45) # J1 component

print "- - "
print "J0 = %e"%J0
print "J1 = %e"%J1
print "- - "

Titm = 0.014 # ITM tranmissivity (assumed both ITMX and ITMY)
Ritm = 1.0 - 0.014 # ITM
fm = 9099471.0 * 5 # modulation frequency when measurement was performed (alog 9695)
lsch = 0.082 # Schnupp asymmetry (alog 9776)
measured_response = 6.79e9 # counts/meters (alog 9698)

wfg = 10**(45.0/20) # whitening filter gain set at 45 dB
Peff = 45e-6 # according to Paul, ITMX single reflection was 15 uW at REFLAIR. So the effective incident Power on BS should be 4 times bigger


# estimation of the optical gain
sig = 2 *J0 * J1 * Ritm * 4 * pi / lamda * sin(2*pi*fm/c * lsch) * W2C * wfg * Peff
p2p = 2 *J0 * J1 * Ritm * sin(2*pi*fm/c * lsch) * W2C * wfg * Peff # peak-to-peak counts in ADC

print ""
print "- - -"
print "sig = %e"%sig
#print "estimated peak to peak = %f"%(2*p2p)
print "measured value = %e"%(measured_response)
print "measurement/sig = %f"%(measured_response/sig)
print "- - -"


