#!/bin/bash
# Script to generate plotable table of AOM frequency, pairs, singles and normailized g2.
# Requires compiled g2.c
# output file column format
# Col1   - AOM frequency (aligned in double pass configuration) 
# Col2   - Total pairs in measurement time
# Col3&4 - Singles in measurement time
# Col5   - Normalized g2.


g2_prog="/home/qitlab/programs/g2/g2"

	for((i=600;i<=750;i+=5))
	do
		freq=$(echo "$i" | awk '{print $0/10}')
		
		# run g2 and put the number of sinles in "singles"
		singles=$($g2_prog -t 8 -m 1200 -i "776_"$freq"MHz.dat" -o out.dat 2>&1 | awk '{print $2,$4}')

		pairs=$(awk 'BEGIN{sum=0;} {if($1>=325 && $1<365) sum+=$2;} END{print sum}' out.dat)
		acc=$(awk 'BEGIN{sum=0;} {if($1>=600 && $1<1000) sum+=$2;} END{print sum/400}' out.dat)
		g2_peak=$(awk '{if($1==328) print $2;}' out.dat)
		norm_g2=$(echo "$g2_peak $acc" | awk '{print $1/$2}')
		
		echo -e "$freq \t $pairs \t $singles \t $norm_g2" >> plot_data.dat
	done
