
# SLICS: 
#model='SLICS' # for noise free V1 sims
#for LOS in {74..99}; do

# cosmo-SLICS:
model='fid_f'
#dz='dz10'
A_IA='_AIA1.0'   #1.0
#A_IA='_AIA1.5'    #1.5
#A_IA='_AIA2.0'   #2.0

for LOS in {1..5}; do

for tomobin in {1..5}; do
let tomobin2_min=$tomobin
#tomobin2=$tomobin2_min # auto
#tomobin2=2
for tomobin2 in $(seq $tomobin2_min 5); do # cross
#----------
# IA mocks: 
#dir_in='/home/jharno/Projects/cosmoSLICS/'$model'/IA_mocks_smooth5Mpcoverh/'
#dir_in='/home/jharno/Projects/cosmoSLICS/'$model'/IA_mocks_smooth1Mpcoverh/'
#dir_in='/home/jharno/Projects/cosmoSLICS/'$model'/IA_mocks_smooth05Mpcoverh/'
#dir_in='/home/jharno/Projects/cosmoSLICS/'$model'/IA_mocks_smooth025Mpcoverh/'
dir_in='/home/jharno/Projects/cosmoSLICS/'$model'/IA_mocks_smooth01Mpcoverh/'
#dir_in='/home/jharno/Projects/cosmoSLICS/'$model'/IA_mocks_nosmooth/'
#dir_in='/home/jharno/Projects/cosmoSLICS/'$model'/IA_mocks/'
dir_in2=$dir_in

dir_out=$dir_in'/xipm_revised/'
mkdir -p $dir_out

filename_sources_in='GalCatalog_Euclid_IA_TATT_bin'$tomobin'_AIA1._A21..dat_LOS'$LOS
filename_sources_in2='GalCatalog_Euclid_IA_TATT_bin'$tomobin2'_AIA1._A21..dat_LOS'$LOS
#---------


# specify name for cross
#treecorr_out_name='IA_bin'$tomobin'_bin'$tomobin2'_'$LOS'_'$model$A_IA'.dat'
treecorr_out_name='Euclid_IA_TATT_bin'$tomobin'_bin'$tomobin2'_'$LOS'_'$model'.dat'

echo 'Launching TreeCorr on redshift bin' $tomobin ' and ' $tomobin2' , LOS' $LOS ' model' $model', for file' $filename_sources_in 'and ' $filename_sources_in2

#---
# interactive:
# create link to input file

rm GalCat_sources.dat ;  ln -s $dir_in$filename_sources_in GalCat_sources.dat ;
rm GalCat_sources2.dat ;  ln -s $dir_in2$filename_sources_in2 GalCat_sources2.dat ;

# noise free, no IA:
corr2 IA_JHD_config_noisefree.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_noisefree'_cone$LOS

# noisy, no IA
corr2 IA_JHD_config_noisy_noIA.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_noisy_noIA'_cone$LOS

#noise-free, NLA:
corr2 IA_JHD_config_noisefree_IA_model1.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_NLA'_cone$LOS
corr2 IA_JHD_config_noisefree_II_model1.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_NLA_II'_cone$LOS
corr2 IA_JHD_config_noisefree_GI_model1.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_NLA_gI'_cone$LOS

#noise-free, delta-NLA:
#Make the delta-NLA model with Garance's code:
rm GalCat_sources_deltaNLA.dat GalCat_sources2_deltaNLA.dat
python3.7 CombineEllipticities.py 1.0 0.0 GalCat_sources.dat GalCat_sources_deltaNLA.dat
python3.7 CombineEllipticities.py 1.0 0.0 GalCat_sources2.dat GalCat_sources2_deltaNLA.dat
corr2 IA_JHD_config_noisefree_IA_model2.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_deltaNLA'_cone$LOS
corr2 IA_JHD_config_noisefree_II_model2.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_deltaNLA_II'_cone$LOS
corr2 IA_JHD_config_noisefree_GI_model2.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_deltaNLA_gI'_cone$LOS

#noise-free, TATT:
#Make the TATT model with Garance's code:
rm GalCat_sources_TATT.dat GalCat_sources2_TATT.dat
python3.7 CombineEllipticities.py 1.0 1.0 GalCat_sources.dat GalCat_sources_TATT.dat
python3.7 CombineEllipticities.py 1.0 1.0 GalCat_sources2.dat GalCat_sources2_TATT.dat
corr2 IA_JHD_config_noisefree_IA_model3.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_TATT'_cone$LOS
corr2 IA_JHD_config_noisefree_II_model3.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_TATT_II'_cone$LOS
corr2 IA_JHD_config_noisefree_GI_model3.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_TATT_gI'_cone$LOS

#  -- OR --

#---
# to workers:
# Create unique config file:

#-------
# for SLICS/cosmo-SLICS
#cp config_SLICS_xipm_V1_DES_noisefree_sbatch.yaml config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat.yaml'
#sed 's/XXXX/'"$filename_sources_in"'/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat.yaml' > config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_1.yaml'
#sed 's/YYYY/xipm\/xipm_'"$filename_sources_in"'/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_1.yaml'  > config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_2.yaml'
#my_config=config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_2.yaml' 
#-------

#--------
# for peaks catalogue
# noise free
#cp config_SLICS_xipm_peaks_DES_noisefree_sbatch.yaml config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'.yaml'
#sed 's/XXXX/'"$filename_sources_in"'/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'.yaml' > config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_1.yaml'
#sed 's/YYYY/xipm\/xipm_'"$filename_sources_in"'_e2flip_noisefree/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_1.yaml'  > config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_2.yaml'
#my_config=config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_2.yaml' 
#----

#---
# noise free + mbias
#cp config_SLICS_xipm_peaks_DES_noisefree_mbias_sbatch.yaml config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'.yaml'
#sed 's/XXXX/'"$filename_sources_in"'/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'.yaml' > config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_1.yaml'
#sed 's/YYYY/xipm\/xipm_'"$filename_sources_in"'_e2flip_noisefree_mbias/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_1.yaml'  > config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_2.yaml'
#my_config=config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_2.yaml' 
#---

#-----
# shape noise
#cp config_SLICS_xipm_peaks_DES_sbatch.yaml config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'.yaml'
#sed 's/XXXX/'"$filename_sources_in"'/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'.yaml' > config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_1.yaml'
#sed 's/YYYY/xipm\/xipm_'"$filename_sources_in"'_mbias_fixed/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_1.yaml'  > config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_2.yaml'
#my_config=config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_2.yaml' 
#---
#-----
# shape noise + cross-correlation
#cp config_SLICS_xipm_peaks_DES_sbatch_cross.yaml config_SLICS_xipm_peaks_DES_sbatch_$tomobin$tomobin2'_R'$Field'_LOS'$LOS'.dat_it'$it'.yaml'
#sed 's/XXXX/'"$filename_sources_in"'/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin$tomobin2'_R'$Field'_LOS'$LOS'.dat_it'$it'.yaml' > config_SLICS_xipm_peaks_DES_sbatch_$tomobin$tomobin2'_R'$Field'_LOS'$LOS'.dat_it'$it'_1.yaml'
#sed 's/YYYY/xipm_'"$treecorr_out_name"'_mbias_fixed/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin$tomobin2'_R'$Field'_LOS'$LOS'.dat_it'$it'_1.yaml'  > config_SLICS_xipm_peaks_DES_sbatch_$tomobin$tomobin2'_R'$Field'_LOS'$LOS'.dat_it'$it'_2.yaml'
#sed 's/ZZZZ/'"$filename_sources_in2"'/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin$tomobin2'_R'$Field'_LOS'$LOS'.dat_it'$it'_2.yaml' > config_SLICS_xipm_peaks_DES_sbatch_$tomobin$tomobin2'_R'$Field'_LOS'$LOS'.dat_it'$it'_3.yaml'
#my_config=config_SLICS_xipm_peaks_DES_sbatch_$tomobin$tomobin2'_R'$Field'_LOS'$LOS'.dat_it'$it'_3.yaml' 
#---


#sbatch batch_treecorr.sh  ${dir_in} ${filename_sources_in} ${my_config} ;
#sbatch batch_treecorr_cross.sh  ${dir_in} ${dir_in2} ${filename_sources_in} ${filename_sources_in2} ${my_config} ;

#done
done
done
done
