{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/roberto.derenzi/git/mujpy\n",
      "******************* SUITE *********************\n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2241.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 30.000K \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2242.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 1.500K  \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2243.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 3.000K  \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2244.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 6.000K  \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2245.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 8.000K  \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2246.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 9.000K  \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2247.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 10.000K \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2248.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 11.000K \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2249.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 12.000K \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2250.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 13.000K \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2251.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 14.000K \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2252.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 15.000K \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2253.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 16.000K \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2254.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 18.000K \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2255.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 20.000K \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2256.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 22.000K \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2257.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 23.000K \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2258.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 24.000K \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2259.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 25.000K \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2260.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 26.000K \n",
      "Run /afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_2261.bin loaded\n",
      " MnBi2Te4 pellet   7000.000 28.000K \n",
      "Succesfully completed prompt Minuit fit, check nt0, dt0 \n",
      "****************END OF SUITE*****************\n"
     ]
    }
   ],
   "source": [
    "%cd /home/roberto.derenzi/git/mujpy/\n",
    "from mujpy.musuite import suite\n",
    "from mujpy.aux.aux import get_title\n",
    "import json\n",
    "logpath = '/home/roberto.derenzi/git/mujpy/log/'\n",
    "datafile = '/afs/psi.ch/project/bulkmusr/data/gps/d2021/tdc/deltat_tdc_gps_0822.bin'\n",
    "runlist = '2241:2261' # first run first\n",
    "inputsuitefile = 'input.suite'\n",
    "grp_calib = [{'forward':'2,3', 'backward':'1,4', 'alpha':1.13}]\n",
    "groupcalibfile = '2_3-1_4.calib'\n",
    "input_suite = {'console':'print',\n",
    "                   'datafile':datafile,\n",
    "                   'logpath':logpath,\n",
    "                   'runlist':runlist,\n",
    "                   'groups calibration':groupcalibfile,\n",
    "                   'offset':20\n",
    "                  }  # 'console':logging, for output in Log Console, 'console':print, for output in notebook\n",
    "with open(logpath+inputsuitefile,\"w\") as f:\n",
    "    json.dump(input_suite,f)\n",
    "\n",
    "with open(logpath+groupcalibfile,\"w\") as f:\n",
    "    json.dump(grp_calib,f)\n",
    "    \n",
    "the_suite = suite(logpath+inputsuitefile,mplot=False) # the_suite implements the class suite according to input.suite"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2241: MnBi2Te4 pellet   7000.000 30.000K   from 24-JUN-21 15:52:27 to  24-JUN-21 16:40:28 Tot 37632846 Mev\n",
      "2242: MnBi2Te4 pellet   7000.000 1.500K    from 24-JUN-21 16:47:01 to  24-JUN-21 18:34:28 Tot 82295976 Mev\n",
      "2243: MnBi2Te4 pellet   7000.000 3.000K    from 24-JUN-21 18:37:41 to  24-JUN-21 19:44:07 Tot 49464640 Mev\n",
      "2244: MnBi2Te4 pellet   7000.000 6.000K    from 24-JUN-21 19:47:12 to  24-JUN-21 20:51:27 Tot 49228606 Mev\n",
      "2245: MnBi2Te4 pellet   7000.000 8.000K    from 24-JUN-21 20:53:51 to  24-JUN-21 21:57:06 Tot 49091711 Mev\n",
      "2246: MnBi2Te4 pellet   7000.000 9.000K    from 24-JUN-21 21:59:25 to  24-JUN-21 23:03:19 Tot 49258336 Mev\n",
      "2247: MnBi2Te4 pellet   7000.000 10.000K   from 24-JUN-21 23:05:39 to  25-JUN-21 00:08:53 Tot 49128797 Mev\n",
      "2248: MnBi2Te4 pellet   7000.000 11.000K   from 25-JUN-21 00:11:11 to  25-JUN-21 01:14:25 Tot 49189792 Mev\n",
      "2249: MnBi2Te4 pellet   7000.000 12.000K   from 25-JUN-21 01:16:45 to  25-JUN-21 02:20:00 Tot 49212535 Mev\n",
      "2250: MnBi2Te4 pellet   7000.000 13.000K   from 25-JUN-21 02:22:27 to  25-JUN-21 03:26:12 Tot 49405631 Mev\n",
      "2251: MnBi2Te4 pellet   7000.000 14.000K   from 25-JUN-21 03:28:40 to  25-JUN-21 04:31:54 Tot 49226867 Mev\n",
      "2252: MnBi2Te4 pellet   7000.000 15.000K   from 25-JUN-21 04:34:14 to  25-JUN-21 05:38:08 Tot 49036236 Mev\n",
      "2253: MnBi2Te4 pellet   7000.000 16.000K   from 25-JUN-21 05:40:38 to  25-JUN-21 06:44:23 Tot 49160705 Mev\n",
      "2254: MnBi2Te4 pellet   7000.000 18.000K   from 25-JUN-21 06:50:34 to  25-JUN-21 07:53:48 Tot 49155105 Mev\n",
      "2255: MnBi2Te4 pellet   7000.000 20.000K   from 25-JUN-21 08:00:00 to  25-JUN-21 09:33:18 Tot 49264990 Mev\n",
      "2256: MnBi2Te4 pellet   7000.000 22.000K   from 25-JUN-21 09:35:55 to  25-JUN-21 10:41:39 Tot 49268143 Mev\n",
      "2257: MnBi2Te4 pellet   7000.000 23.000K   from 25-JUN-21 10:44:03 to  25-JUN-21 11:48:58 Tot 49431676 Mev\n",
      "2258: MnBi2Te4 pellet   7000.000 24.000K   from 25-JUN-21 11:51:21 to  25-JUN-21 12:38:48 Tot 36144161 Mev\n",
      "2259: MnBi2Te4 pellet   7000.000 25.000K   from 25-JUN-21 12:41:15 to  25-JUN-21 13:27:46 Tot 34020259 Mev\n",
      "2260: MnBi2Te4 pellet   7000.000 26.000K   from 25-JUN-21 13:30:10 to  25-JUN-21 14:17:43 Tot 36129557 Mev\n",
      "2261: MnBi2Te4 pellet   7000.000 28.000K   from 25-JUN-21 14:20:20 to  25-JUN-21 15:11:16 Tot 38639214 Mev\n"
     ]
    }
   ],
   "source": [
    "for runs in the_suite._the_runs_:\n",
    "    run = runs[0]\n",
    "    print('{}: {}  from {} to  {} Tot {} Mev'.format(run.get_runNumber_int(),get_title(run),run.get_timeStart_vector(),run.get_timeStop_vector(),sum(run.get_eventsHisto_vector())))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
