= Fscan =

<<TableOfContents(3)>>

== Installation ==

=== Installation of LALSuite ===

{{{
apt-get install lscsoft-lalsuite
}}}

[[https://lscsoft.docs.ligo.org/lalsuite/|LALSuite]]

=== Installation of Fscan ===

 1. Download Fscan code from [[https://github.com/lscsoft/lalsuite/tree/master/lalapps/src/pulsar/Fscan|GitHub]]
 1. Copy to /home/controls/public_html

== How to use ==

 * Move to Fscan directory({{{/home/controls/opt/Fscan}}})
 * Before using Fscan, we must set the environmental variables by
 {{{
source /users/DET/tools/Fscan/etc/environment.sh
 }}}
 * Fscan job is submitted to Condor when the following command line is executed
 {{{
./testmultiFscanGenerator.tcl testKagraDailyFscanGenerator.rsc /home/controls/opt/Fscan/test_segments.txt -R
 }}}
 Results are exported to the "{{{~/public_html/fscan/daily}}}" directory

=== Channels ===
|| Channel || Frequency || Description ||
|| K1:CAL-CS_PROC_MICH_DISPLACEMENT_DQ || 0-5000 || difference of MICH ||
|| K1:CAL-CS_PROC_DARM_DISPLACEMENT_DQ || 0-5000 || difference of DARM ||
|| K1:CAL-CS_PROC_IMC_FREQUENCY_DQ || 0-5000 || IMC length at laser frequency ||
|| K1:CAL-CS_PROC_C00_STRAIN_DBL_DQ || 0-5000 || ||


==== Old Channels ====
|| Channel || Frequency || Description ||
|| K1:PSL-TTFSS_MIXER_MON_OUT_DQ || 0-4000 || error signal of TTFSS(Table Top Frequency Stabilization Servo) ||
|| K1:PSL-TTFSS_EOM_MON_OUT_DQ || 0-4000 || signal of EOM(electro optic modulator) ||
|| K1:PSL-REFCAV_REFL_OUT_DQ || 0-4000 || beat signal of REFCAV ||
|| K1:PSL-REFCAV_TRANS_OUT_DQ || 0-4000 || transmitted light of REFCAV ||
|| K1:PSL-PMC_MIXER_MON_OUT_DQ || 0-4000 || error signal of PMC ||
|| K1:IMC-MCL_SERVO_OUT_DQ || 0-2000 || feedback signal to IMC ||
|| K1:IMC-SERVO_MIXER_DAQ_OUT_DQ || 0-5000 || error signal of IMC ||
|| K1:CAL-CS_PROC_XARM_FREQUENCY_DQ || 0-5000 || Xarm length at laser frequency ||

== Setting ==

== Code Modification for KAGRA ==
 * multiFscanGenerator.tcl
 {{{
--- multiFscanGenerator.tcl       2019-03-27 14:58:01.287737201 +0900
+++ multiFscanGenerator_kagra.tcl 2019-03-27 16:54:47.367739644 +0900
@@ -292,7 +292,8 @@ set moveSFTsFromSuffix "";
 
 set crab 0; #if crab stuff is to be run then rsc file sets crab to 1, default is not to run.X
 
-set submitLogFileDir "/usr1/pulsar"; # directory location for log files given in the condor submit files, for use with fscanDriver.py -o option.
+set submitLogFileDir "/home/controls/opt/Fscan/logs"; # directory location for log files given in the condor submit files, for use with fscanDriver.py -o option.
 
 
 ##### MAIN CODE STARTS HERE #####
 }}} 
 * fscanDriver.py
 {{{
--- fscanDriver.py       2019-03-27 14:58:01.287737201 +0900
+++ fscanDriver_kagra.py 2019-03-29 14:15:32.386858803 +0900
@@ -602,7 +602,11 @@ if (createSFTs):
      sft_freqBand = 2
   else:
      sft_freqBand = freqBand + 1;
-  makeDAGCommand = 'MakeSFTDAG -f %s -G %s -d %s -x %d -k %d -T %d -F %d -B %d -p %s -N %s -m 1 -o %s -X %s -Z -g %s -v %d -w %d' % (sftDAGFile,tagString,inputDataType,extraDatafindTime,filterKneeFreq,timeBaseline,startFreq,sft_freqBand,pathToSFTs,channelName,subLogPath,miscDesc,segmentFile,sftVersion,windowType)
+  if ifo == 'K1':
+    makeDAGCommand = os.environ['KAGRA_FSCANBIN_PATH']+'/lalapps_MakeSFTDAG_kagra -f %s -G %s -d %s -x %d -k %d -T %d -F %d -B %d -p %s -N %s -m 1 -o %s -X %s -Z -g %s -v %d -w %d' % (sftDAGFile,tagString,inputDataType,extraDatafindTime,filterKneeFreq,timeBaseline,startFreq,sft_freqBand,pathToSFTs,channelName,subLogPath,miscDesc,segmentFile,sftVersion,windowType)
+  else:
+    makeDAGCommand = 'MakeSFTDAG -f %s -G %s -d %s -x %d -k %d -T %d -F %d -B %d -p %s -N %s -m 1 -o %s -X %s -Z -g %s -v %d -w %d' % (sftDAGFile,tagString,inputDataType,extraDatafindTime,filterKneeFreq,timeBaseline,startFreq,sft_freqBand,pathToSFTs,channelName,subLogPath,miscDesc,segmentFile,sftVersion,windowType)
+
   if (useHoT):
      makeDAGCommand = makeDAGCommand + ' -H'
   if (makeSFTIFO != None):
@@ -1009,7 +1013,8 @@ if (htmlFilename != None):
     htmlFID.write('    Spectrogram data: <a href="' + thisSeg + '">' + thisSeg + '</a><br>')
     htmlFID.write('    Freq. vs Power: <a href="' + thisSeg + '.txt">' + thisSeg + '.txt</a><br>')
     htmlFID.write('    Freq. vs Power (Sorted): <a href="' + thisSeg + '_sorted.txt">' + thisSeg + '_sorted.txt</a><br>')
-    htmlFID.write('    List of found combs : <a href="%s_combs.txt">%s_combs.txt</a><br>\n' % (inputFileName,inputFileName))
+    htmlFID.write('    List of found combs : <a href="' + thisSeg + '_combs.txt">' + thisSeg + '_combs.txt</a><br>')
+    #htmlFID.write('    List of found combs : <a href="%s_combs.txt">%s_combs.txt</a><br>\n' % (inputFileName,inputFileName))
     #htmlFID.write('    Kurtosis test output: <a href="' + thisSeg + '_kurtosis">' + thisSeg + '_kurtosis</a><br>')
     htmlFID.write('  </td>\n')
     htmlFID.write('</tr>\n')
 }}}
 * makeSFTDAG
 {{{
--- /home/controls/opt/summary-2.7/bin/lalapps_MakeSFTDAG       2018-10-15 10:53:42.042880005 +0900
+++ /users/DET/tools/Fscan/Script/lalapps_MakeSFTDAG_kagra      2019-03-29 14:01:07.868739651 +0900
@@ -1,4 +1,4 @@
-#!/home/controls/opt/summary-2.7/bin/python
+#!/usr/bin/python2.7
 """
 
 MakeSFTDAG.py - Creates DAGs to run jobs that generates SFTs; can act as a dag generator for use with onasys.
@@ -527,12 +527,19 @@ nodeCount         = 0L
 datafindFID = file('datafind.sub','w')
 datafindLogFile = subLogPath + '/' + 'datafind_' + dagFileName + '.log'
 datafindFID.write('universe = scheduler\n')
-datafindFID.write('executable = $ENV(LSC_DATAFIND_PATH)/gw_data_find\n')
 if not datafindMatch:
    dataFindMatchString = ''
 else:
    dataFindMatchString = '--match ' + datafindMatch
-datafindFID.write('arguments = -r $ENV(LIGO_DATAFIND_SERVER) --observatory $(observatory) --url-type file --gps-start-time $(gpsstarttime) --gps-end-time $(gpsendtime) --lal-cache --type $(inputdatatype) %s\n' % dataFindMatchString)
+
+if site == 'K':
+    datafindFID.write('executable = $ENV(KAGRA_FSCANBIN_PATH)/mkcache.py\n')
+    #datafindFID.write('arguments =  --cache-path {0} --ifo {1} --gps-start-time {2} --gps-end-time {3}\n'.format(cachePath,'K1',startTimeDatafind,endTimeDatafind))
+    datafindFID.write('arguments =  --cache-path %s --ifo %s --gps-start-time $(gpsstarttime) --gps-end-time $(gpsendtime)\n' % (cachePath,'K1'))
+else:
+    datafindFID.write('executable = $ENV(LSC_DATAFIND_PATH)/gw_data_find\n')
+    datafindFID.write('arguments = -r $ENV(LIGO_DATAFIND_SERVER) --observatory $(observatory) --url-type file --gps-start-time $(gpsstarttime) --gps-end-time $(gpsendtime) --lal-cache --type $(inputdatatype) %s\n' % dataFindMatchString)
+
 datafindFID.write('getenv = True\n')
 if (accountingGroup != None):
    datafindFID.write('accounting_group = %s\n' % accountingGroup)
 }}}