#!/bin/bash

t1=245605417
t2=246210217

for x in {10..19}

do

# Energy bins 800-2000 MeV; EA
# Energy bins 2000-5000 MeV; EB
# Energy bins >5000 MeV; EC

gtselect \
  infile=@/data/ajm/new_fermi_data/events.txt \
  outfile=/data/ajm/SN/1/filtered_87A_EA_n$x.fits \
  ra=0 dec=0 rad=180.0 evclass=128 evtype=3 \
  tmin=$t1 \
  tmax=$t2 \
  emin=800 emax=2000 zmax=90

gtselect \
  infile=@/data/ajm/new_fermi_data/events.txt \
  outfile=/data/ajm/SN/1/filtered_87A_EB_n$x.fits \
  ra=0 dec=0 rad=180.0 evclass=128 evtype=3 \
  tmin=$t1 \
  tmax=$t2 \
  emin=2000 emax=5000 zmax=90

gtselect \
  infile=@/data/ajm/new_fermi_data/events.txt \
  outfile=/data/ajm/SN/1/filtered_87A_EC_n$x.fits \
  ra=0 dec=0 rad=180.0 evclass=128 evtype=3 \
  tmin=$t1 \
  tmax=$t2 \
  emin=5000 emax=500000 zmax=90


echo $x >> /data/ajm/SN/1/myfile.out

gtmktime \
  scfile=/data/ajm/new_fermi_data/L200305052624F357373F06_SC00.fits \
  filter="DATA_QUAL>0 && LAT_CONFIG==1" \
  roicut=no evfile=/data/ajm/SN/1/filtered_87A_EA_n$x.fits \
  outfile=/data/ajm/SN/1/gti_87A_EA_n$x.fits

gtmktime \
  scfile=/data/ajm/new_fermi_data/L200305052624F357373F06_SC00.fits \
  filter="DATA_QUAL>0 && LAT_CONFIG==1" \
  roicut=no evfile=/data/ajm/SN/1/filtered_87A_EB_n$x.fits \
  outfile=/data/ajm/SN/1/gti_87A_EB_n$x.fits

gtmktime \
  scfile=/data/ajm/new_fermi_data/L200305052624F357373F06_SC00.fits \
  filter="DATA_QUAL>0 && LAT_CONFIG==1" \
  roicut=no evfile=/data/ajm/SN/1/filtered_87A_EC_n$x.fits \
  outfile=/data/ajm/SN/1/gti_87A_EC_n$x.fits


gtbin \
  algorithm=HEALPIX \
  evfile=/data/ajm/SN/1/gti_87A_EA_n$x.fits \
  scfile=/data/ajm/new_fermi_data/L200305052624F357373F06_SC00.fits \
  outfile=/data/ajm/SN/1/hpmap_87A_EA_n$x.fits \
  hpx_ordering_scheme=RING hpx_order=9 coordsys=GAL hpx_ebin="NO" hpx_region=""

gtbin \
  algorithm=HEALPIX \
  evfile=/data/ajm/SN/1/gti_87A_EB_n$x.fits \
  scfile=/data/ajm/new_fermi_data/L200305052624F357373F06_SC00.fits \
  outfile=/data/ajm/SN/1/hpmap_87A_EB_n$x.fits \
  hpx_ordering_scheme=RING hpx_order=9 coordsys=GAL hpx_ebin="NO" hpx_region=""

gtbin \
  algorithm=HEALPIX \
  evfile=/data/ajm/SN/1/gti_87A_EC_n$x.fits \
  scfile=/data/ajm/new_fermi_data/L200305052624F357373F06_SC00.fits \
  outfile=/data/ajm/SN/1/hpmap_87A_EC_n$x.fits \
  hpx_ordering_scheme=RING hpx_order=9 coordsys=GAL hpx_ebin="NO" hpx_region=""


gtltcube \
  evfile=/data/ajm/SN/1/gti_87A_EA_n$x.fits \
  scfile=/data/ajm/new_fermi_data/L200305052624F357373F06_SC00.fits \
  outfile=/data/ajm/SN/1/cub_87A_EA_n$x.fits \
  zmax=90 dcostheta=0.025 binsz=1

gtltcube \
  evfile=/data/ajm/SN/1/gti_87A_EB_n$x.fits \
  scfile=/data/ajm/new_fermi_data/L200305052624F357373F06_SC00.fits \
  outfile=/data/ajm/SN/1/cub_87A_EB_n$x.fits \
  zmax=90 dcostheta=0.025 binsz=1

gtltcube \
  evfile=/data/ajm/SN/1/gti_87A_EC_n$x.fits \
  scfile=/data/ajm/new_fermi_data/L200305052624F357373F06_SC00.fits \
  outfile=/data/ajm/SN/1/cub_87A_EC_n$x.fits \
  zmax=90 dcostheta=0.025 binsz=1


gtexpcube2 \
  infile=/data/ajm/SN/1/cub_87A_EA_n$x.fits \
  cmap=/data/ajm/SN/1/hpmap_87A_EA_n$x.fits \
  outfile=/data/ajm/SN/1/ehp_87A_EA_n$x.fits \
  irfs=P8R3_SOURCE_V2

gtexpcube2 \
  infile=/data/ajm/SN/1/cub_87A_EB_n$x.fits \
  cmap=/data/ajm/SN/1/hpmap_87A_EB_n$x.fits \
  outfile=/data/ajm/SN/1/ehp_87A_EB_n$x.fits \
  irfs=P8R3_SOURCE_V2

gtexpcube2 \
  infile=/data/ajm/SN/1/cub_87A_EC_n$x.fits \
  cmap=/data/ajm/SN/1/hpmap_87A_EC_n$x.fits \
  outfile=/data/ajm/SN/1/ehp_87A_EC_n$x.fits \
  irfs=P8R3_SOURCE_V2


let t1=t1+604800
let t2=t2+604800

done
