Generate minute trends of the gamma calibration factors for the given
frequencies.

The default behavior is to read strides of 60s of data, compute the
gamma factors for every second, and make a trend of the average value,
for the real and imaginary part. If the state vector is not UP, then
just fill all with zeros.


To Do
-----

* Check why the last two points in the spectrum don't appear in the
  plot on the web, even though they do in the frame files.


How to use it in marble
-----------------------

The way I run the tests:

export LD_LIBRARY_PATH=/opt/lscsoft/framecpp/framecpp-1.14.0/lib/:$LD_LIBRARY_PATH
export DMTNAMESERVER=marble:23456
export DMTWEBSERVER=marble:9991
./callineMon  -ifo H1  \
    -freqs 1144.3,393.1,46.7  \
    -olg-re 3.2749237351091275e-02,-0.510396609305388,-2.06400782589301   \
    -olg-im 2.2395752008766873e-01,-0.227886482342667,1.71533989956955    \
    -whitener-re  0.0099845355,0.00986898153646618,0.000846105659780544   \
    -whitener-im -0.000556250271,-0.00162153463383678,-0.0151874466878841 \
    -spectrum -debug 3

And then I check the status here:
http://marble.ligo-wa.caltech.edu:9991/callineMon/objects.html


Call for H1 and L1
------------------

For H1:

callineMon \
  -ifo H1 \
  -freqs 1144.3,393.1,46.7 \
  -olg-re 3.2749237351091275e-02,-0.510396609305388,-2.06400782589301 \
  -olg-im 2.2395752008766873e-01,-0.227886482342667,1.71533989956955 \
  -whitener-re  0.0099845355,0.00986898153646618,0.000846105659780544 \
  -whitener-im -0.000556250271,-0.00162153463383678,-0.0151874466878841


For L1:

callineMon \
  -ifo L1 \
  -freqs 54.7,396.7,1151.5 \
  -olg-re -2.63664606032816,-0.463942657614613,0.121605171643382 \
  -olg-im  1.07949519489159,-0.00776460863107174,0.127206240269156 \
  -whitener-re 0.00330174581697695,0.00987134824667008,0.00998472832896893 \
  -whitener-im -0.0126054963175879,-0.0016067724865351,-0.000552770881673091


  ***** HOW TO GET ALL THOSE FACTORS *****

The calibration lines can be obtained here:
http://blue.ligo-wa.caltech.edu/scirun/S5/Results/CalibrationStability/index.html


To get the openloopgain I did:

In matlab:

freqdir = '/home/jordi/calibration/frequencydomain/runs/S6/H1/release/V2/';
cd([freqdir '../../../MatlabScripts/']);
path(path, pwd());     % to use twint.m, and who knows what else
path(path, '../H1/model/V2/');
IFOin = eval('H1DARMparams_942450950');
callinefreq = [1144.3 393.1 46.7]
[openloopgain, sensingSP, actuation, digfilter, response, k, ...
    etmxact, etmyact, sensingL, OLGresid] = DARMmodel(IFOin, callinefreq);
format long g
openloopgain

The last result I got:
         0.0327492373510913 +     0.223957520087669i
         -0.510396609305388 -     0.227886482342667i
          -2.06400782589301 +      1.71533989956955i


To get the antiwhitening factors:
(from ~/calibration/timedomain/runs/S5/DARMwhitener.m)

z=[-22.2144+i*22.2144;-22.2144-i*22.2144];
p=[-222.144+i*222.144;-222.144-i*222.144];
k=100;
s=zpk(z,p,k);
f=[1144.3 393.1 46.7];
hresp=squeeze(freqresp(s,2*pi*f));
format long g
1 ./ hresp

The last result I got:
         0.0099845355484356 -  0.000556250270852907i
        0.00986898154602597 -   0.00162153458826283i
       0.000846105854971885 -    0.0151874466737156i



How to choose alpha for the exponential average
-----------------------------------------------

Two kinds of spectrums are computed.

There is a instantaneous one which is just the modulus squared of the
FFT for the 60 seconds gamma factors timeseries:
<ifo>:DMT-CLIN_POWER_<freq>

There is also a exponential smoothing to better estimate the PSD, in
the channel:
<ifo>:DMT-CLIN_POWER_AVG_<freq>

The average (avg) is done this way:
  avg = alpha * current_spectrum + (1-alpha) * old_avg
where the value of alpha can be specified at runtime (with the option
-alpha).

For a mean that puts weight w in the last n samples:
  alpha = 1 - (1 - w)^(1/n)

For example, by default its value corresponds to 90% of the weight in
the last 10 minutes (which are the last 10 samples), so
  alpha = 1 - (1 - 0.9)^(1/10) = 0.20567...

Other interesting values:
  90% in the last 30 min: alpha = 0.07388...
  50% in the last 10 min: alpha = 0.06697...
