Jpp  debug
the software that should make you happy
SN_timecalib.sh
Go to the documentation of this file.
1 #!/bin/zsh
2 script=${0##*/}
3 
4 if [ -z $JPP_DIR ]; then
5  echo "Variable JPP_DIR undefined."
6  exit
7 fi
8 
9 source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
10 
11 if do_usage $*; then
12  usage "$script <input detector file> <output detector file> <first run> <last run> <name suffix> <output directory> <data directory>"
13 fi
14 
15 DETECTOR_IN=$1
16 DETECTOR_OUT=$2
17 RUNFIRST=$3
18 RUNSECOND=$4
19 EXT=$5
20 OUTDIR=$6
21 DATADIR=$7
22 
23 eval `JPrintDetector -a $DETECTOR_IN -O IDENTIFIER`
24 
25 #--- copy detector
26 
27 JConvertDetectorFormat -a $DETECTOR_IN -o $DETECTOR_OUT
28 
29 #--- remove the base modules
30 
31 eval `JPrintDetector -a $DETECTOR_OUT -O SUMMARY`
32 
33 
34 for STRING in $STRINGS; do
35 
36  JEditDetector -a $DETECTOR_OUT -o $DETECTOR_OUT -D "$STRING 0"
37 
38 done
39 
40 #--- sort modules 1-18
41 JEditDetector -a $DETECTOR_OUT -o $DETECTOR_OUT -O 2
42 
43 #--- remove here malfunctioning strings if present in the detector file
44 
45 #JEditDetector -a $DETECTOR_OUT -o $DETECTOR_OUT -r 18
46 #JEditDetector -a $DETECTOR_OUT -o $DETECTOR_OUT -r 19
47 
48 #--- loop over data files
49 
50 rm $OUTDIR/${EXT}.root
51 
52 for RUN_IN in `seq $RUNFIRST $RUNSECOND`; do
53 
54 RUN=$(printf %08d $RUN_IN)
55 INFILE=$DATADIR/KM3NeT_000000${DETECTOR_ID}_${RUN}.root
56 
57 #---- process JMonitorL1dt
58 
59 $JPP_DIR/examples/JCalibrate/JMonitorL1dt -a $DETECTOR_OUT -C JDAQTimesliceSN -f $INFILE -o $OUTDIR/temp_$RUN_IN.root
60 
61 if [ -f "$OUTDIR/${EXT}.root" ]
62 then
63 echo "JMonitorL1dt output added to previous results"
64  hadd $OUTDIR/sum.root $OUTDIR/temp_$RUN_IN.root $OUTDIR/${EXT}.root
65  mv $OUTDIR/sum.root $OUTDIR/${EXT}.root
66 else
67  echo "No previous output from JMonitorL1dt found, new output file created"
68  cp $OUTDIR/temp_$RUN_IN.root $OUTDIR/${EXT}.root
69 fi
70 
71 
72 done
73 
74 #--- determine time offsets between DU pairs (for 1-8 neighboured levels)
75 
76 rm -i $OUTDIR/${EXT}_*.txt
77 for nei in 2 3 4 5 6 7 8; do
78 $JPP_DIR/examples/JCalibrate/JOffset_extract -a $DETECTOR_OUT -f $OUTDIR/${EXT}.root -m 0 -n $nei > $OUTDIR/${EXT}_$nei.txt
79 done
80 cat $OUTDIR/${EXT}_*.txt > $OUTDIR/${EXT}.txt
81 #--- evaluate best inter-DU offsets
82 #
83 # The argument "-m 5.5" needs to be tuned to the amount of data used, for 30 hours of ARCA a value of 5.5 was found reasonable,
84 # for 6 hours of ORCA a value of 20 is suggested
85 # Some tuning will be required, it should be a high enough value to remove 'noise' correlations and a low enough to keep enough correlations
86 # Possibly some further cuts on the quality of the correlations need to be applied
87 file=$OUTDIR/offsets_${EXT}.txt
88 $JPP_DIR/examples/JCalibrate/JMatrix_sol -a $DETECTOR_OUT -f $OUTDIR/${EXT}.txt -m 5.5 -r 0 > $file
89 
90 #--- adapt detector file
91 
92 while read line; do
93  read -r a b <<< $line
94  if [ $a -gt 0 ]
95  then
96  JEditDetector -a $DETECTOR_OUT -S "$a add $b" -o $DETECTOR_OUT --!
97  fi
98 done < $file