#!/bin/bash
# pedestals
#==========
# make limitfile - gains
shaper=0
polarity=1
cat <<EOF1 >plotchipped.txt
# one line per gain:  ped_min_mean ped_max_mean ped_max_rms
80.00 133.00 1.6
45.00 110.00 2.1
65.00 122.00 1.8
18.00 95.00 2.6
EOF1
cp plotchipped.txt plotchipped-gains-s${shaper}-p${polarity}.txt
# make limitfile - shapers
gain=3
cat <<EOF1 >plotchipped.txt
# one line per shaper:
# ped_min_mean ped_max_mean ped_max_rms
18.00 95.00 2.6
15.00 95.00 2.8
15.00 95.00 3.5
15.00 96.00 4.5
EOF1
cp plotchipped.txt plotchipped-shapers-g${gain}-p${polarity}.txt
#
# Pulser pedsub
#===============
shaper=0
for gain in {0..3}
do
    if [ ${gain} == 0 ]; then
        cat <<EOF1 >plotchippedsub.txt
# peaktypes type min_mean max_mean max_rms
0.0 50.0 5.0
475 540 4.0
450 520 4.0
# pedestals min_mean max_mean max_rms
80.00 130.00 2.0
83.00 135.00 7.0
83.00 135.00 7.0
EOF1
    elif [ ${gain} == 1 ]; then
        cat <<EOF2 >plotchippedsub.txt
# peaktypes type min_mean max_mean max_rms
0.0 50.0 5.0
440.0 510.0 3.0
420.0 500.0 3.0
# pedestals min_mean max_mean max_rms
50.0 110.00 2.0
50.0 110.0 6.0
50.0 110.0 6.0
EOF2
    elif [ ${gain} == 2 ]; then
        cat <<EOF3 >plotchippedsub.txt
# peaktypes type min_mean max_mean max_rms
0.0 50.0 5.0
585.0 660.0 7.0
555.0 640.0 7.0
# pedestals min_mean max_mean max_rms
70.0 125.0 2.0
70.0 125.0 8.0
70.0 125.0 8.0
EOF3
    elif [ ${gain} == 3 ]; then
        cat <<EOF4 >plotchippedsub.txt
# peaktypes type min_mean max_mean max_rms
0.0 50.0 5.0
640.0 720.0 4.0
610.0 710.0 4.0
# pedestals min_mean max_mean max_rms
18.00 95.00 2.0
18.00 95.00 5.0
19.00 95.00 5.0
EOF4
    fi
    cp plotchippedsub.txt plotchippedsub-g${gain}-s${shaper}-p${polarity}.txt
done
#
gain=3
for shaper in 0 1 3 7
do
    if [ ${shaper} == 0 ]; then
        cat <<EOF1 >plotchippedsub.txt
# peaktypes type min_mean max_mean max_rms
0.0 50.0 5.0
640.0 740.0 4.0
610.0 710.0 4.0
# pedestals min_mean max_mean max_rms
18.00 95.00 2.0
18.00 95.00 5.0
18.00 95.00 5.0
# cluster_thresh,cluster length min_mean max_mean max_rms 
40 85.0 120.0 5.0
EOF1
    elif [ ${shaper} == 1 ]; then
        cat <<EOF1 >plotchippedsub.txt
# peaktypes type min_mean max_mean max_rms
0.0 50 5.0
640.0 740.0 6.0
590.0 700.0 6.0
# pedestals min_mean max_mean max_rms
18.00 95.00 2.0
18.00 95.00 5.0
18.00 95.00 5.0
# cluster_thresh,cluster length min_mean max_mean max_rms min_clusters max_clusters
40 50.0 90.0 5.0
EOF1
    elif [ ${shaper} == 3 ]; then
        cat <<EOF1 >plotchippedsub.txt
# peaktypes type min_mean max_mean max_rms
0.0 50 5.0
630.0 730.0 5.0
450.0 550.0 7.0
# pedestals min_mean max_mean max_rms
18.00 95.00 2.0
18.00 95.00 5.0
18.00 95.00 5.0
# cluster_thresh,cluster length min_mean max_mean max_rms min_clusters max_clusters
40 45.0 55.0 3.0
EOF1
    elif [ ${shaper} == 7 ]; then
       cat <<EOF1 >plotchippedsub.txt
# peaktypes type min_mean max_mean max_rms
0.0 50 20.0
550.0 650.0 6.0
350.0 450.0 8.0
# pedestals min_mean max_mean max_rms
18.00 95.00 2.0
18.00 95.00 5.0
18.00 95.00 5.0
# cluster_thresh cluster length min_mean max_mean max_rms min_clusters max_clusters
40 20.0 30.0 2.0 
EOF1
    fi
    cp plotchippedsub.txt plotchippedsubsh-g${gain}-s${shaper}-p${polarity}.txt
done
#
# Polarity 0
polarity=0
gain=0
shaper=0
    cat <<EOF1 >plotchippedsub.txt
# peaktypes min_mean max_mean max_rms
0.0 50.0 5.0
445.0 580.0 3.0
420.0 560.0 3.0
# pedestals min_mean max_mean max_rms
770.0 840.0 5.0
770.0 840.0 5.0
770.0 940.0 5.0
EOF1
cp plotchippedsub.txt plotchippedsub-shapers-g${gain}-p${polarity}.txt
#
#Zerosup
polarity=1
shaper=0
events=500
declare -i clusters_min=events*12-10
declare -i clusters_max=events*12+10
for gain in {0..3}
do
    if [ ${gain} == 0 ]; then
        cat <<EOF1 >plotchipzsuppeaks.txt
# peaktypes type min_mean max_mean max_rms
0.0 50.0 5.0
500.0 600.0 5.0
470.0 570.0 5.0
# cluster length min_mean max_mean max_rms min_clusters max_clusters
10.0 40.0 10.0 $clusters_min $clusters_max
EOF1
    elif [ ${gain} == 1 ]; then
        cat <<EOF1 >plotchipzsuppeaks.txt
# peaktypes type min_mean max_mean max_rms
0.0 50.0 5.0
500.0 600.0 5.0
470.0 570.0 5.0
# cluster length min_mean max_mean max_rms min_clusters max_clusters
10.0 40.0 10.0 $clusters_min $clusters_max
EOF1
    elif [ ${gain} == 2 ]; then
        cat <<EOF1 >plotchipzsuppeaks.txt
# peaktypes type min_mean max_mean max_rms
0.0 50.0 5.0
650.0 750.0 5.0
620.0 720.0 5.0
# cluster length min_mean max_mean max_rms min_clusters max_clusters
10.0 40.0 10.0 $clusters_min $clusters_max
EOF1
    elif [ ${gain} == 3 ]; then
        cat <<EOF1 >plotchipzsuppeaks.txt
# peaktypes type min_mean max_mean max_rms
0.0 50.0 5.0
720.0 820.0 8.0
690.0 790.0 8.0
# cluster length min_mean max_mean max_rms min_clusters max_clusters
10.0 40.0 10.0 $clusters_min $clusters_max
EOF1
    fi
 cp plotchipzsuppeaks.txt plotchipzsuppeaks-g${gain}-s${shaper}-p${polarity}.txt
done
# zerosup shapers
declare -i clusters_min=events*12-15
declare -i clusters_max=events*12+15
for shaper in 0 1 3 7
do
   if [ ${shaper} == 0 ]; then                 
        cat <<EOF1 >plotchipzsuppeaks.txt
# peaktypes type min_mean max_mean max_rms
0.0 50.0 5.0
650.0 800.0 6.0
600.0 750.0 6.0
# cluster length min_mean max_mean max_rms min_clusters max_clusters
16.0 20.0 1.0 $clusters_min $clusters_max
EOF1
    elif [ ${shaper} == 1 ]; then
        cat <<EOF1 >plotchipzsuppeaks.txt
# peaktypes type min_mean max_mean max_rms
0.0 50.0 5.0
600.0 750.0 6.0
550.0 700.0 6.0
# cluster length min_mean max_mean max_rms min_clusters max_clusters
15.0 18.0 1.0 $clusters_min $clusters_max
EOF1
   elif [ ${shaper} == 3 ]; then
        cat <<EOF1 >plotchipzsuppeaks.txt
# peaktypes type min_mean max_mean max_rms
# peaktypes type min_mean max_mean max_rms
0.0 50.0 5.0
630.0 750.0 5.0
450.0 550.0 7.0
# cluster length min_mean max_mean max_rms min_clusters max_clusters
13.0 15.0 1.0 $clusters_min $clusters_max
EOF1
   elif [ ${shaper} == 7 ]; then
        cat <<EOF1 >plotchipzsuppeaks.txt
# peaktypes type min_mean max_mean max_rms
0.0 50.0 20.0
550.0 650.0 6.0
350.0 450.0 8.0
# cluster length min_mean max_mean max_rms min_clusters max_clusters
10.0 13.0 1.0 $clusters_min $clusters_max
EOF1
   fi
   cp plotchipzsuppeaks.txt plotchipzsuppeaksh-g${gain}-s${shaper}-p${polarity}.txt
done
#
# bits
polarity=1
shaper=0
gain=3
cat <<EOF1 >plotchipbits.txt
# peaktypetype min_mean max_mean max_rms
# bit mean min max
0 50.0 40.0 60.0
1 50.0 46.0 54.0
2 50.0 46.0 54.0
3 50.0 46.0 54.0
4 50.0 46.0 54.0
5 50.0 46.0 54.0
6 51.0 47.0 55.0
7 53.0 49.0 57.0
8 54.0 50.0 59.0
9 57.0 51.0 63.0
EOF1
cp plotchipbits.txt  plotchipbits-g${gain}-s${shaper}-p${polarity}.txt
