6 #        | | |  \| |   __ _   _ __     ___   | |_) |   ___    __ _    ___    ___    _ __    
 
    7 #    _   | | | . ` |  / _` | | '_ \   / _ \  |  _ <   / _ \  / _` |  / __|  / _ \  | '_ \  
 
    8 #   | |__| | | |\  | | (_| | | | | | | (_) | | |_) | |  __/ | (_| | | (__  | (_) | | | | | 
 
    9 #    \____/  |_| \_|  \__,_| |_| |_|  \___/  |____/   \___|  \__,_|  \___|  \___/  |_| |_| 
 
   14 #This script should be launched everytime a new DU is deployed in the sea, and a set of runs with the nanobeacons tuned at different voltages has been taken. It launches several programs. 
 
   17 #First, it copies the run files from irods to a temporary directory and launches JPulseFinder to analyze each of them. JPulseFinder searches for the NB pulses detected by the different PMTs in the neighbor DOMs. Once JPulseFinder has finished, its output is stored and the run files removed from the temporary directory.
 
   24 source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
 
   26 if ( do_usage $* ); then
 
   27     usage "$script [edit the different options within]"
 
   30 # ------------------------------------------------------------------------------------------
 
   32 #          Script to find the optimal voltage of the nanobeacons in a DU
 
   34 # ------------------------------------------------------------------------------------------
 
   44     print -u2 "$script \n\t Choose the adequate options and run it!"
 
   50 #------------------------------------
 
   51 # Input-Output definitions
 
   52 #------------------------------------
 
   55 #   / __ \  / _ \ / ___/  / _ |
 
   56 #  / /_/ / / , _// /__   / __ |
 
   57 #  \____/ /_/|_| \___/  /_/ |_|
 
   59 #####################################################################################################################
 
   65 # irods_path="/in2p3/km3net/data/raw/sea/KM3NeT_00000029/${string}/"
 
   67 # filename="KM3NeT_00000029_0000"
 
   69 # runs=(2660 2661 2662 2663 2664 2665 2666 2667 2668) 
 
   71 # runs=(2745 2746 2747 2748 2749 2750 2751 2752 2753)
 
   73 # voltages=(5.5 6 6.5 7 7.5 8 8.5 10 15)
 
   75 # in_detx="/afs/in2p3.fr/home/r/rgracia/sps/KM3NeT/ORCA/Calibration/data/det/ORCA/KM3NeT_00000029_20170920.detx"
 
   77 #####################################################################################################################
 
   82 #    / _ |  / _ \ / ___/  / _ |
 
   83 #   / __ | / , _// /__   / __ |
 
   84 #  /_/ |_|/_/|_| \___/  /_/ |_|
 
   86 #####################################################################################################################
 
   94 #irods_path="/in2p3/km3net/data/raw/darkroom/KM3NeT_00000038/0/"
 
   96 #filename="KM3NeT_00000038_00000"
 
   98 #runs=(207 208 209 211)
 
  100 #voltages=(15 15 8 8)
 
  102 #in_detx="/afs/in2p3.fr/home/r/rgracia/sps/Soft/src/Jpp_trunk/examples/JMonitor/JNanoBeacon/JPulseFinder/temp/KM3NeT_00000038_intrainterDOM_final_pmt7_v1.detx"
 
  108 irods_path="/in2p3/km3net/data/raw/sea/KM3NeT_00000014/5/"
 
  110 filename="KM3NeT_00000014_0000"
 
  114 in_detx="/afs/in2p3.fr/home/r/rgracia/sps/KM3NeT/ORCA/Calibration/data/det/ARCA/KM3NeT_00000014_20170327.detx"
 
  124 #####################################################################################################################
 
  129 ###################################################################################################################
 
  130 #GET RUN FILES FROM IRODS AND STORE THEM IN A TEMPORARY DIRECTORY
 
  131 ###################################################################################################################
 
  134 tmpdir="${WORKDIR}/tmp"
 
  136 if [ ! -d ${tmpdir} ] 
 
  144 source /usr/local/shared/bin/irods_env.sh >& /dev/null
 
  149 ################################################################################################################
 
  150 #LAUNCH JPULSEFINDER FOR EACH OF THE RUN FILES GRABBED FROM IRODS. STORE THE OUTPUT, AND REMOVE THE RUN FILES.
 
  151 ################################################################################################################
 
  154 outdir_pulse="${WORKDIR}/out/$detector/JPulseFinder"
 
  156 if [ ! -d ${outdir_pulse} ] 
 
  160     mkdir -p ${outdir_pulse} 
 
  164 #cd ./../JPulseFinder
 
  166 pulse_period=6250 #in units of 16 ns
 
  168 stagger_period=220 #in units of 16 ns
 
  170 for i in {1..$((${#runs[@]}))}
 
  174   infile=$tmpdir/${filename}${runs[i]}.root  
 
  176   outfile_pulse=$outdir_pulse/JPF_${runs[i]}.root
 
  178   if [ ! -f $outfile_pulse ]; then
 
  180       if [ ! -f $infile ]; then
 
  182      echo "\nGetting file ${filename}${runs[i]}.root from ${irods_path}. Please wait..."
 
  184      iget -f ${irods_path}${filename}${${runs[i]}}.root $tmpdir/
 
  188      echo "\n\nThe file \n${filename}${${runs[i]}}.root \nalready exists in \n$tmpdir.\nContinue..."
 
  197      -stagger $stagger_period          \
 
  206       echo "\nThe pulses for run $runs[i] already exist in file\n$outfile\nContinue..."
 
  210   outdir_calibrator="${WORKDIR}/out/$detector/JInterDomCal"
 
  212   if [ ! -d ${outdir_calibrator} ] 
 
  216       mkdir -p ${outdir_calibrator} 
 
  220   outfile_txt="$outdir_calibrator/JNBCal_${runs[i]}.txt"
 
  222   outfile_checks="$outdir_calibrator/JNBCal_${runs[i]}.root"
 
  224   outfile_detx="$outdir_calibrator/JNBCal_${runs[i]}.detx"
 
  238   report_name="$outdir_calibrator/calibration_report_${runs[i]}.pdf"
 
  241   echo "Writing calibration report in file:" 
 
  243   echo "------------------------------------\n"
 
  245   python plot_report_calibration.py -ir $outfile_checks -it $outfile_txt -o $report_name
 
  247   echo "Done... Hasta pronto!"