From 36f133e5697a3714f98a1a571b9d543f92e31c6f Mon Sep 17 00:00:00 2001
From: Lee McCuller <Lee.McCuller@gmail.com>
Date: Thu, 8 Oct 2020 10:31:18 -0400
Subject: [PATCH] coverted QuantumVacuum to use PWR struct precomp

---
 gwinc/ifo/noises.py    | 16 +++++++++++++---
 gwinc/nb.py            |  2 +-
 gwinc/noise/quantum.py | 12 ++++++------
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/gwinc/ifo/noises.py b/gwinc/ifo/noises.py
index 7fa1ad63..351c5df6 100644
--- a/gwinc/ifo/noises.py
+++ b/gwinc/ifo/noises.py
@@ -154,6 +154,16 @@ def precomp_power(f, ifo):
     ifo.gwinc.prfactor = prfactor
 
 
+def precomp_power2(f, ifo):
+    PC = Struct()
+    pbs, parm, finesse, prfactor, Tpr = ifo_power(ifo)
+    PC.pbs = pbs
+    PC.parm = parm
+    PC.finesse = finesse
+    PC.gPhase = finesse * 2/np.pi
+    PC.prfactor = prfactor
+    return PC
+
 def precomp_cavity(f, ifo):
     if 'gwinc' not in ifo:
         ifo.gwinc = Struct()
@@ -181,9 +191,9 @@ class QuantumVacuum(nb.Noise):
     )
 
     @nb.precomp(precomp_mirror)
-    @nb.precomp(precomp_power)
-    def calc(self):
-        return noise.quantum.shotrad(self.freq, self.ifo)
+    @nb.precomp(PWR = precomp_power2)
+    def calc(self, PWR):
+        return noise.quantum.shotrad(self.freq, self.ifo, PWR = PWR)
 
 
 class StandardQuantumLimit(nb.Noise):
diff --git a/gwinc/nb.py b/gwinc/nb.py
index 4cca254d..aeb529ad 100644
--- a/gwinc/nb.py
+++ b/gwinc/nb.py
@@ -303,7 +303,7 @@ class Noise(BudgetItem):
                     kwargs['ifo'] = self.ifo
             self._ifo_hash = ifo_hash
         if kwargs:
-            self.update(_precomp = precomp, **kwargs)
+            self.update(_precomp = _precomp, **kwargs)
 
         return self.calc_trace(_precomp = _precomp)
 
diff --git a/gwinc/noise/quantum.py b/gwinc/noise/quantum.py
index 87378ad8..28c22665 100644
--- a/gwinc/noise/quantum.py
+++ b/gwinc/noise/quantum.py
@@ -17,7 +17,7 @@ def sqzOptimalSqueezeAngle(Mifo, eta):
     return alpha
 
 
-def shotrad(f, ifo):
+def shotrad(f, ifo, PWR):
     """Quantum noise noise strain spectrum
 
     :f: frequency array in Hz
@@ -47,7 +47,7 @@ def shotrad(f, ifo):
     else:
         namespace = globals()
         fname = namespace['shotrad' + ifo.Optics.Type]
-    coeff, Mifo, Msig, Mn = fname(f, ifo)
+    coeff, Mifo, Msig, Mn = fname(f, ifo, PWR = PWR)
 
     # check for consistent dimensions
     Nfield = Msig.shape[0]
@@ -290,7 +290,7 @@ def compile_SEC_RES_TF():
     print('RES', '=', str(SEC_RES_expr[0]).replace('Matrix', 'np.array'))
 
 
-def shotradSignalRecycled(f, ifo):
+def shotradSignalRecycled(f, ifo, PWR):
     """Quantum noise model for signal recycled IFO (see shotrad for more info)
 
     New version July 2016 by JH based on transfer function formalism
@@ -333,7 +333,7 @@ def shotradSignalRecycled(f, ifo):
 
     R = 1 - T - ifo.Optics.Loss                  # ITM Reflectivity [Power]
 
-    P = ifo.gwinc.parm                           # use precomputed value
+    P = PWR.parm                           # use precomputed value
 
     # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
@@ -460,7 +460,7 @@ def shotradSignalRecycled(f, ifo):
     return coeff, Mifo, Msig, Mnoise
 
 
-def shotradSignalRecycledBnC(f, ifo):
+def shotradSignalRecycledBnC(f, ifo, PWR):
     """Quantum noise model for signal recycled IFO
 
     See shotrad for more info.
@@ -514,7 +514,7 @@ def shotradSignalRecycledBnC(f, ifo):
     gamma_ac = T*c/(4*L)                         # [KLMTV-PRD2001] Arm cavity half bandwidth [1/s]
     epsilon = lambda_arm/(2*gamma_ac*L/c)        # [BnC, after 5.2] Loss coefficent for arm cavity
 
-    I_0 = ifo.gwinc.pbs                          # [BnC, Table 1] Power at BS (Power*prfactor) [W]
+    I_0 = PWR.pbs                          # [BnC, Table 1] Power at BS (Power*prfactor) [W]
     I_SQL = (m*L**2*gamma_ac**4)/(4*omega_0)     # [BnC, 2.14] Power to reach free mass SQL
     Kappa = 2*((I_0/I_SQL)*gamma_ac**4)/ \
               (Omega**2*(gamma_ac**2+Omega**2))  # [BnC 2.13] Effective Radiation Pressure Coupling
-- 
GitLab