From fea2fb1fb2ea4d4205d08ca2e49d4679d797dc1b Mon Sep 17 00:00:00 2001
From: hallc-online <hallc-online@jlab.org>
Date: Thu, 20 Apr 2017 11:39:34 -0400
Subject: [PATCH] Scaler replay and online GUI

Added files
------------
DBASE/db_HSScalerevt.dat : scaler database for HMS
DBASE/db_PSScalerevt.dat : scaler database for SHMS
DBASE/make_scaler_db.py  : Python script to make HMS and SHMS
                           database files from xscaler scaler.map
SCRIPTS/HMS/replay_hms_scalers.C : script to replay HMS scalers only
SCRIPTS/SHMS/replay_shms_scalers.C : script to replay SHMS scalers only
DEF-files/HMS/EPICS/epics_short.def : List of EPICS variables to include in Tree
                                      used in scaler scripts as an example
onlineGUI/Config/hms_scaler.cfg  : configuration file to plot HMS scalers
onlineGUI/Macros/plot_hms_scaler.C  : Macro used by hms_scaler.cfg

onlineGUI/Config/shms_scaler.cfg  : configuration file to plot SHMS scalers
onlineGUI/Macros/plot_shms_scaler.C  : Macro used by shms_scaler.cfg
---
 DBASE/db_HSScalevt.dat               | 309 +++++++++++++++++++++++++++
 DBASE/db_PSScalevt.dat               | 278 ++++++++++++++++++++++++
 DBASE/make_scaler_db.py              |  83 +++++++
 DEF-files/HMS/EPICS/epics_short.def  |  14 ++
 SCRIPTS/HMS/replay_hms_scalers.C     |  97 +++++++++
 SCRIPTS/SHMS/replay_shms_scalers.C   |  96 +++++++++
 onlineGUI/Config/hms_scaler.cfg      |  89 ++++++++
 onlineGUI/Config/shms_scaler.cfg     |  74 +++++++
 onlineGUI/Macros/plot_hms_scalers.C  | 289 +++++++++++++++++++++++++
 onlineGUI/Macros/plot_shms_scalers.C | 288 +++++++++++++++++++++++++
 10 files changed, 1617 insertions(+)
 create mode 100755 DBASE/db_HSScalevt.dat
 create mode 100755 DBASE/db_PSScalevt.dat
 create mode 100755 DBASE/make_scaler_db.py
 create mode 100644 DEF-files/HMS/EPICS/epics_short.def
 create mode 100644 SCRIPTS/HMS/replay_hms_scalers.C
 create mode 100644 SCRIPTS/SHMS/replay_shms_scalers.C
 create mode 100644 onlineGUI/Config/hms_scaler.cfg
 create mode 100644 onlineGUI/Config/shms_scaler.cfg
 create mode 100644 onlineGUI/Macros/plot_hms_scalers.C
 create mode 100644 onlineGUI/Macros/plot_shms_scalers.C

diff --git a/DBASE/db_HSScalevt.dat b/DBASE/db_HSScalevt.dat
new file mode 100755
index 00000000..7d088867
--- /dev/null
+++ b/DBASE/db_HSScalevt.dat
@@ -0,0 +1,309 @@
+map 3801 5 6 00000620 ffffffff 12
+map 3801 5 7 00200720 ffffffff 12
+map 3801 5 8 00400820 ffffffff 12
+map 3801 5 9 00600920 ffffffff 12
+map 3801 5 10 00800a20 ffffffff 12
+map 3801 5 11 00a00b20 ffffffff 12
+map 3801 5 12 00c00c20 ffffffff 12 31 1000000
+variable 3 3 1 hhod2y7P HMS 2Y+ paddle 7
+variable 3 3 2 hhod2y7Pr HMS 2Y+ paddle 7
+variable 0 8 1 hhod1x9P HMS 1X+ paddle 9
+variable 0 8 2 hhod1x9Pr HMS 1X+ paddle 9
+variable 0 24 1 hhod1x9M HMS 1X- paddle 9
+variable 0 24 2 hhod1x9Mr HMS 1X- paddle 9
+variable 3 19 1 hhod2y7M HMS 2Y- paddle 7
+variable 3 19 2 hhod2y7Mr HMS 2Y- paddle 7
+variable 6 4 1 h1Xh1y h1T
+variable 6 4 2 h1Xh1yr h1T
+variable 2 22 1 hhod2x6M HMS 2X- paddle 6
+variable 2 22 2 hhod2x6Mr HMS 2X- paddle 6
+variable 6 5 1 h2Xh2Y h2T
+variable 6 5 2 h2Xh2Yr h2T
+variable 2 6 1 hhod2x6P HMS 2X+ paddle 6
+variable 2 6 2 hhod2x6Pr HMS 2X+ paddle 6
+variable 2 27 1 hhod2x15M HMS 2X- paddle 15
+variable 2 27 2 hhod2x15Mr HMS 2X- paddle 15
+variable 3 26 1 Empty_20 Empty
+variable 3 26 2 Empty_20r Empty
+variable 1 2 1 hhod1y5P HMS 1Y+ paddle 5
+variable 1 2 2 hhod1y5Pr HMS 1Y+ paddle 5
+variable 3 29 1 Empty_22 Empty
+variable 3 29 2 Empty_22r Empty
+variable 1 18 1 hhod1y5M HMS 1Y- paddle 5
+variable 1 18 2 hhod1y5Mr HMS 1Y- paddle 5
+variable 3 31 1 Empty_24 Empty
+variable 3 31 2 Empty_24r Empty
+variable 2 11 1 hhod2x15P HMS 2X+ paddle 15
+variable 2 11 2 hhod2x15Pr HMS 2X+ paddle 15
+variable 6 13 1 hSHWR hSHWR
+variable 6 13 2 hSHWRr hSHWR
+variable 1 20 1 hhod1y2M HMS 1Y- paddle 2
+variable 1 20 2 hhod1y2Mr HMS 1Y- paddle 2
+variable 1 4 1 hhod1y2P HMS 1Y+ paddle 2
+variable 1 4 2 hhod1y2Pr HMS 1Y+ paddle 2
+variable 0 13 1 hhod1x12P HMS 1X+ paddle 12
+variable 0 13 2 hhod1x12Pr HMS 1X+ paddle 12
+variable 0 29 1 hhod1x12M HMS 1X- paddle 12
+variable 0 29 2 hhod1x12Mr HMS 1X- paddle 12
+variable 2 0 1 hhod2x1P HMS 2X+ paddle 1
+variable 2 0 2 hhod2x1Pr HMS 2X+ paddle 1
+variable 2 16 1 hhod2x1M HMS 2X- paddle 1
+variable 2 16 2 hhod2x1Mr HMS 2X- paddle 1
+variable 3 21 1 hhod2y4M HMS 2Y- paddle 4
+variable 3 21 2 hhod2y4Mr HMS 2Y- paddle 4
+variable 3 5 1 hhod2y4P HMS 2Y+ paddle 4
+variable 3 5 2 hhod2y4Pr HMS 2Y+ paddle 4
+variable 6 30 1 Unser Unser
+variable 6 30 2 Unserr Unser
+variable 1 5 1 hhod1y4P HMS 1Y+ paddle 4
+variable 1 5 2 hhod1y4Pr HMS 1Y+ paddle 4
+variable 2 8 1 hhod2x9P HMS 2X+ paddle 9
+variable 2 8 2 hhod2x9Pr HMS 2X+ paddle 9
+variable 2 24 1 hhod2x9M HMS 2X- paddle 9
+variable 2 24 2 hhod2x9Mr HMS 2X- paddle 9
+variable 1 21 1 hhod1y4M HMS 1Y- paddle 4
+variable 1 21 2 hhod1y4Mr HMS 1Y- paddle 4
+variable 0 0 1 hhod1x1P HMS 1X+ paddle 1
+variable 0 0 2 hhod1x1Pr HMS 1X+ paddle 1
+variable 0 16 1 hhod1x1M HMS 1X- paddle 1
+variable 0 16 2 hhod1x1Mr HMS 1X- paddle 1
+variable 0 18 1 hhod1x5M HMS 1X- paddle 5
+variable 0 18 2 hhod1x5Mr HMS 1X- paddle 5
+variable 0 27 1 hhod1x15M HMS 1X- paddle 15
+variable 0 27 2 hhod1x15Mr HMS 1X- paddle 15
+variable 0 11 1 hhod1x15P HMS 1X+ paddle 15
+variable 0 11 2 hhod1x15Pr HMS 1X+ paddle 15
+variable 3 27 1 Empty_21 Empty
+variable 3 27 2 Empty_21r Empty
+variable 3 2 1 hhod2y5P HMS 2Y+ paddle 5
+variable 3 2 2 hhod2y5Pr HMS 2Y+ paddle 5
+variable 3 18 1 hhod2y5M HMS 2Y- paddle 5
+variable 3 18 2 hhod2y5Mr HMS 2Y- paddle 5
+variable 2 7 1 hhod2x8P HMS 2X+ paddle 8
+variable 2 7 2 hhod2x8Pr HMS 2X+ paddle 8
+variable 1 19 1 hhod1y7M HMS 1Y- paddle 7
+variable 1 19 2 hhod1y7Mr HMS 1Y- paddle 7
+variable 0 2 1 hhod1x5P HMS 1X+ paddle 5
+variable 0 2 2 hhod1x5Pr HMS 1X+ paddle 5
+variable 1 3 1 hhod1y7P HMS 1Y+ paddle 7
+variable 1 3 2 hhod1y7Pr HMS 1Y+ paddle 7
+variable 3 30 1 Empty_23 Empty
+variable 3 30 2 Empty_23r Empty
+variable 2 23 1 hhod2x8M HMS 2X- paddle 8
+variable 2 23 2 hhod2x8Mr HMS 2X- paddle 8
+variable 0 22 1 hhod1x6M HMS 1X- paddle 6
+variable 0 22 2 hhod1x6Mr HMS 1X- paddle 6
+variable 2 15 1 hhod2x16P HMS 2X+ paddle 16
+variable 2 15 2 hhod2x16Pr HMS 2X+ paddle 16
+variable 6 11 1 hPSHWRLO hPSHWRLO
+variable 6 11 2 hPSHWRLOr hPSHWRLO
+variable 2 31 1 hhod2x16M HMS 2X- paddle 16
+variable 2 31 2 hhod2x16Mr HMS 2X- paddle 16
+variable 0 6 1 hhod1x6P HMS 1X+ paddle 6
+variable 0 6 2 hhod1x6Pr HMS 1X+ paddle 6
+variable 0 30 1 hhod1x14M HMS 1X- paddle 14
+variable 0 30 2 hhod1x14Mr HMS 1X- paddle 14
+variable 6 2 1 h2X h2X
+variable 6 2 2 h2Xr h2X
+variable 6 3 1 h2Y h2Y
+variable 6 3 2 h2Yr h2Y
+variable 6 27 1 BCM1 bcm1
+variable 6 27 2 BCM1r bcm1
+variable 0 14 1 hhod1x14P HMS 1X+ paddle 14
+variable 0 14 2 hhod1x14Pr HMS 1X+ paddle 14
+variable 2 17 1 hhod2x3M HMS 2X- paddle 3
+variable 2 17 2 hhod2x3Mr HMS 2X- paddle 3
+variable 2 1 1 hhod2x3P HMS 2X+ paddle 3
+variable 2 1 2 hhod2x3Pr HMS 2X+ paddle 3
+variable 1 29 1 Empty_10 Empty
+variable 1 29 2 Empty_10r Empty
+variable 1 30 1 Empty_11 Empty
+variable 1 30 2 Empty_11r Empty
+variable 1 31 1 Empty_12 Empty
+variable 1 31 2 Empty_12r Empty
+variable 3 9 1 Empty_13 Empty
+variable 3 9 2 Empty_13r Empty
+variable 3 10 1 Empty_14 Empty
+variable 3 10 2 Empty_14r Empty
+variable 3 11 1 Empty_15 Empty
+variable 3 11 2 Empty_15r Empty
+variable 3 4 1 hhod2y2P HMS 2Y+ paddle 2
+variable 3 4 2 hhod2y2Pr HMS 2Y+ paddle 2
+variable 2 28 1 hhod2x10M HMS 2X- paddle 10
+variable 2 28 2 hhod2x10Mr HMS 2X- paddle 10
+variable 3 15 1 Empty_18 Empty
+variable 3 15 2 Empty_18r Empty
+variable 3 25 1 Empty_19 Empty
+variable 3 25 2 Empty_19r Empty
+variable 6 8 1 hBSUM hBSUM
+variable 6 8 2 hBSUMr hBSUM
+variable 3 20 1 hhod2y2M HMS 2Y- paddle 2
+variable 3 20 2 hhod2y2Mr HMS 2Y- paddle 2
+variable 0 19 1 hhod1x7M HMS 1X- paddle 7
+variable 0 19 2 hhod1x7Mr HMS 1X- paddle 7
+variable 0 3 1 hhod1x7P HMS 1X+ paddle 7
+variable 0 3 2 hhod1x7Pr HMS 1X+ paddle 7
+variable 2 12 1 hhod2x10P HMS 2X+ paddle 10
+variable 2 12 2 hhod2x10Pr HMS 2X+ paddle 10
+variable 6 7 1 hASUM hASUM
+variable 6 7 2 hASUMr hASUM
+variable 6 1 1 h1Y h1Y
+variable 6 1 2 h1Yr h1Y
+variable 6 0 1 h1X h1X
+variable 6 0 2 h1Xr h1X
+variable 6 25 1 BCM4A bcm4a
+variable 6 25 2 BCM4Ar bcm4a
+variable 0 31 1 hhod1x16M HMS 1X- paddle 16
+variable 0 31 2 hhod1x16Mr HMS 1X- paddle 16
+variable 0 15 1 hhod1x16P HMS 1X+ paddle 16
+variable 0 15 2 hhod1x16Pr HMS 1X+ paddle 16
+variable 3 13 1 Empty_16 Empty
+variable 3 13 2 Empty_16r Empty
+variable 1 24 1 hhod1y9M HMS 1Y- paddle 9
+variable 1 24 2 hhod1y9Mr HMS 1Y- paddle 9
+variable 2 4 1 hhod2x2P HMS 2X+ paddle 2
+variable 2 4 2 hhod2x2Pr HMS 2X+ paddle 2
+variable 2 20 1 hhod2x2M HMS 2X- paddle 2
+variable 2 20 2 hhod2x2Mr HMS 2X- paddle 2
+variable 1 8 1 hhod1y9P HMS 1Y+ paddle 9
+variable 1 8 2 hhod1y9Pr HMS 1Y+ paddle 9
+variable 2 9 1 hhod2x11P HMS 2X+ paddle 11
+variable 2 9 2 hhod2x11Pr HMS 2X+ paddle 11
+variable 3 17 1 hhod2y3M HMS 2Y- paddle 3
+variable 3 17 2 hhod2y3Mr HMS 2Y- paddle 3
+variable 2 25 1 hhod2x11M HMS 2X- paddle 11
+variable 2 25 2 hhod2x11Mr HMS 2X- paddle 11
+variable 3 1 1 hhod2y3P HMS 2Y+ paddle 3
+variable 3 1 2 hhod2y3Pr HMS 2Y+ paddle 3
+variable 6 29 1 BCM17 bcm17
+variable 6 29 2 BCM17r bcm17
+variable 3 14 1 Empty_17 Empty
+variable 3 14 2 Empty_17r Empty
+variable 1 6 1 hhod1y6P HMS 1Y+ paddle 6
+variable 1 6 2 hhod1y6Pr HMS 1Y+ paddle 6
+variable 1 22 1 hhod1y6M HMS 1Y- paddle 6
+variable 1 22 2 hhod1y6Mr HMS 1Y- paddle 6
+variable 6 15 1 hCERSUM hCERSUM
+variable 6 15 2 hCERSUMr hCERSUM
+variable 0 5 1 hhod1x4P HMS 1X+ paddle 4
+variable 0 5 2 hhod1x4Pr HMS 1X+ paddle 4
+variable 0 21 1 hhod1x4M HMS 1X- paddle 4
+variable 0 21 2 hhod1x4Mr HMS 1X- paddle 4
+variable 6 12 1 hPSHWRHI hPSHWRHI
+variable 6 12 2 hPSHWRHIr hPSHWRHI
+variable 3 7 1 hhod2y8P HMS 2Y+ paddle 8
+variable 3 7 2 hhod2y8Pr HMS 2Y+ paddle 8
+variable 3 23 1 hhod2y8M HMS 2Y- paddle 8
+variable 3 23 2 hhod2y8Mr HMS 2Y- paddle 8
+variable 2 18 1 hhod2x5M HMS 2X- paddle 5
+variable 2 18 2 hhod2x5Mr HMS 2X- paddle 5
+variable 1 23 1 hhod1y8M HMS 1Y- paddle 8
+variable 1 23 2 hhod1y8Mr HMS 1Y- paddle 8
+variable 1 7 1 hhod1y8P HMS 1Y+ paddle 8
+variable 1 7 2 hhod1y8Pr HMS 1Y+ paddle 8
+variable 2 2 1 hhod2x5P HMS 2X+ paddle 5
+variable 2 2 2 hhod2x5Pr HMS 2X+ paddle 5
+variable 2 29 1 hhod2x12M HMS 2X- paddle 12
+variable 2 29 2 hhod2x12Mr HMS 2X- paddle 12
+variable 2 13 1 hhod2x12P HMS 2X+ paddle 12
+variable 2 13 2 hhod2x12Pr HMS 2X+ paddle 12
+variable 6 6 1 hTrig hT1
+variable 6 6 2 hTrigr hT1
+variable 0 4 1 hhod1x2P HMS 1X+ paddle 2
+variable 0 4 2 hhod1x2Pr HMS 1X+ paddle 2
+variable 0 20 1 hhod1x2M HMS 1X- paddle 2
+variable 0 20 2 hhod1x2Mr HMS 1X- paddle 2
+variable 1 16 1 hhod1y1M HMS 1Y- paddle 1
+variable 1 16 2 hhod1y1Mr HMS 1Y- paddle 1
+variable 1 26 1 Empty_8 Empty
+variable 1 26 2 Empty_8r Empty
+variable 1 27 1 Empty_9 Empty
+variable 1 27 2 Empty_9r Empty
+variable 1 0 1 hhod1y1P HMS 1Y+ paddle 1
+variable 1 0 2 hhod1y1Pr HMS 1Y+ paddle 1
+variable 1 10 1 Empty_2 Empty
+variable 1 10 2 Empty_2r Empty
+variable 1 11 1 Empty_3 Empty
+variable 1 11 2 Empty_3r Empty
+variable 1 15 1 Empty_6 Empty
+variable 1 15 2 Empty_6r Empty
+variable 1 25 1 Empty_7 Empty
+variable 1 25 2 Empty_7r Empty
+variable 1 13 1 Empty_4 Empty
+variable 1 13 2 Empty_4r Empty
+variable 1 14 1 Empty_5 Empty
+variable 1 14 2 Empty_5r Empty
+variable 0 9 1 hhod1x11P HMS 1X+ paddle 11
+variable 0 9 2 hhod1x11Pr HMS 1X+ paddle 11
+variable 1 9 1 Empty Empty
+variable 1 9 2 Emptyr Empty
+variable 0 25 1 hhod1x11M HMS 1X- paddle 11
+variable 0 25 2 hhod1x11Mr HMS 1X- paddle 11
+variable 1 28 1 hhod1y10M HMS 1Y- paddle 10
+variable 1 28 2 hhod1y10Mr HMS 1Y- paddle 10
+variable 1 12 1 hhod1y10P HMS 1Y+ paddle 10
+variable 1 12 2 hhod1y10Pr HMS 1Y+ paddle 10
+variable 3 24 1 hhod2y9M HMS 2Y- paddle 9
+variable 3 24 2 hhod2y9Mr HMS 2Y- paddle 9
+variable 6 10 1 hDSUM hDSUM
+variable 6 10 2 hDSUMr hDSUM
+variable 3 8 1 hhod2y9P HMS 2Y+ paddle 9
+variable 3 8 2 hhod2y9Pr HMS 2Y+ paddle 9
+variable 2 21 1 hhod2x4M HMS 2X- paddle 4
+variable 2 21 2 hhod2x4Mr HMS 2X- paddle 4
+variable 2 5 1 hhod2x4P HMS 2X+ paddle 4
+variable 2 5 2 hhod2x4Pr HMS 2X+ paddle 4
+variable 3 16 1 hhod2y1M HMS 2Y- paddle 1
+variable 3 16 2 hhod2y1Mr HMS 2Y- paddle 1
+variable 2 10 1 hhod2x13P HMS 2X+ paddle 13
+variable 2 10 2 hhod2x13Pr HMS 2X+ paddle 13
+variable 0 1 1 hhod1x3P HMS 1X+ paddle 3
+variable 0 1 2 hhod1x3Pr HMS 1X+ paddle 3
+variable 6 26 1 BCM4B bcm4b
+variable 6 26 2 BCM4Br bcm4b
+variable 2 26 1 hhod2x13M HMS 2X- paddle 13
+variable 2 26 2 hhod2x13Mr HMS 2X- paddle 13
+variable 0 17 1 hhod1x3M HMS 1X- paddle 3
+variable 0 17 2 hhod1x3Mr HMS 1X- paddle 3
+variable 6 31 1 1Mhz 1MHz
+variable 6 31 2 1Mhzr 1MHz
+variable 0 12 1 hhod1x10P HMS 1X+ paddle 10
+variable 0 12 2 hhod1x10Pr HMS 1X+ paddle 10
+variable 0 28 1 hhod1x10M HMS 1X- paddle 10
+variable 0 28 2 hhod1x10Mr HMS 1X- paddle 10
+variable 3 0 1 hhod2y1P HMS 2Y+ paddle 1
+variable 3 0 2 hhod2y1Pr HMS 2Y+ paddle 1
+variable 6 9 1 hCSUM hCSUM
+variable 6 9 2 hCSUMr hCSUM
+variable 3 28 1 hhod2y10M HMS 2Y- paddle 10
+variable 3 28 2 hhod2y10Mr HMS 2Y- paddle 10
+variable 0 23 1 hhod1x8M HMS 1X- paddle 8
+variable 0 23 2 hhod1x8Mr HMS 1X- paddle 8
+variable 0 7 1 hhod1x8P HMS 1X+ paddle 8
+variable 0 7 2 hhod1x8Pr HMS 1X+ paddle 8
+variable 3 12 1 hhod2y10P HMS 2Y+ paddle 10
+variable 3 12 2 hhod2y10Pr HMS 2Y+ paddle 10
+variable 6 28 1 BCM2 bcm2
+variable 6 28 2 BCM2r bcm2
+variable 3 6 1 hhod2y6P HMS 2Y+ paddle 6
+variable 3 6 2 hhod2y6Pr HMS 2Y+ paddle 6
+variable 3 22 1 hhod2y6M HMS 2Y- paddle 6
+variable 3 22 2 hhod2y6Mr HMS 2Y- paddle 6
+variable 2 3 1 hhod2x7P HMS 2X+ paddle 7
+variable 2 3 2 hhod2x7Pr HMS 2X+ paddle 7
+variable 6 14 1 hAERSUM hAERSUM
+variable 6 14 2 hAERSUMr hAERSUM
+variable 2 19 1 hhod2x7M HMS 2X- paddle 7
+variable 2 19 2 hhod2x7Mr HMS 2X- paddle 7
+variable 2 30 1 hhod2x14M HMS 2X- paddle 14
+variable 2 30 2 hhod2x14Mr HMS 2X- paddle 14
+variable 2 14 1 hhod2x14P HMS 2X+ paddle 14
+variable 2 14 2 hhod2x14Pr HMS 2X+ paddle 14
+variable 1 1 1 hhod1y3P HMS 1Y+ paddle 3
+variable 1 1 2 hhod1y3Pr HMS 1Y+ paddle 3
+variable 1 17 1 hhod1y3M HMS 1Y- paddle 3
+variable 1 17 2 hhod1y3Mr HMS 1Y- paddle 3
+variable 0 26 1 hhod1x13M HMS 1X- paddle 13
+variable 0 26 2 hhod1x13Mr HMS 1X- paddle 13
+variable 0 10 1 hhod1x13P HMS 1X+ paddle 13
+variable 0 10 2 hhod1x13Pr HMS 1X+ paddle 13
diff --git a/DBASE/db_PSScalevt.dat b/DBASE/db_PSScalevt.dat
new file mode 100755
index 00000000..cb66f3cf
--- /dev/null
+++ b/DBASE/db_PSScalevt.dat
@@ -0,0 +1,278 @@
+map 3801 8 6 02800620 ffffffff 13
+map 3801 8 7 02a00720 ffffffff 13
+map 3801 8 8 02c00820 ffffffff 13
+map 3801 8 9 02e00920 ffffffff 13
+map 3801 8 10 03000a20 ffffffff 13
+map 3801 8 11 03200b20 ffffffff 13
+map 3801 8 12 03400c20 ffffffff 13
+map 3801 8 13 03600d20 ffffffff 13 31 1000000
+variable 7 31 1 1Mhz 1MHz
+variable 7 31 2 1Mhzr 1MHz
+variable 7 28 1 BCM2 bcm2
+variable 7 28 2 BCM2r bcm2
+variable 7 27 1 BCM1 bcm1
+variable 7 27 2 BCM1r bcm1
+variable 0 16 1 shod1x1M SHMS 1X- paddle 1
+variable 0 16 2 shod1x1Mr SHMS 1X- paddle 1
+variable 0 20 1 shod1x2M SHMS 1X- paddle 2
+variable 0 20 2 shod1x2Mr SHMS 1X- paddle 2
+variable 0 17 1 shod1x3M SHMS 1X- paddle 3
+variable 0 17 2 shod1x3Mr SHMS 1X- paddle 3
+variable 0 21 1 shod1x4M SHMS 1X- paddle 4
+variable 0 21 2 shod1x4Mr SHMS 1X- paddle 4
+variable 0 18 1 shod1x5M SHMS 1X- paddle 5
+variable 0 18 2 shod1x5Mr SHMS 1X- paddle 5
+variable 0 22 1 shod1x6M SHMS 1X- paddle 6
+variable 0 22 2 shod1x6Mr SHMS 1X- paddle 6
+variable 0 19 1 shod1x7M SHMS 1X- paddle 7
+variable 0 19 2 shod1x7Mr SHMS 1X- paddle 7
+variable 0 23 1 shod1x8M SHMS 1X- paddle 8
+variable 0 23 2 shod1x8Mr SHMS 1X- paddle 8
+variable 0 24 1 shod1x9M SHMS 1X- paddle 9
+variable 0 24 2 shod1x9Mr SHMS 1X- paddle 9
+variable 0 28 1 shod1x10M SHMS 1X- paddle 10
+variable 0 28 2 shod1x10Mr SHMS 1X- paddle 10
+variable 0 25 1 shod1x11M SHMS 1X- paddle 11
+variable 0 25 2 shod1x11Mr SHMS 1X- paddle 11
+variable 0 30 1 shod1x12M SHMS 1X- paddle 12
+variable 0 30 2 shod1x12Mr SHMS 1X- paddle 12
+variable 0 26 1 shod1x13M SHMS 1X- paddle 13
+variable 0 26 2 shod1x13Mr SHMS 1X- paddle 13
+variable 0 0 1 shod1x1P SHMS 1X+ paddle 1
+variable 0 0 2 shod1x1Pr SHMS 1X+ paddle 1
+variable 0 4 1 shod1x2P SHMS 1X+ paddle 2
+variable 0 4 2 shod1x2Pr SHMS 1X+ paddle 2
+variable 0 1 1 shod1x3P SHMS 1X+ paddle 3
+variable 0 1 2 shod1x3Pr SHMS 1X+ paddle 3
+variable 0 5 1 shod1x4P SHMS 1X+ paddle 4
+variable 0 5 2 shod1x4Pr SHMS 1X+ paddle 4
+variable 0 2 1 shod1x5P SHMS 1X+ paddle 5
+variable 0 2 2 shod1x5Pr SHMS 1X+ paddle 5
+variable 0 6 1 shod1x6P SHMS 1X+ paddle 6
+variable 0 6 2 shod1x6Pr SHMS 1X+ paddle 6
+variable 0 3 1 shod1x7P SHMS 1X+ paddle 7
+variable 0 3 2 shod1x7Pr SHMS 1X+ paddle 7
+variable 0 7 1 shod1x8P SHMS 1X+ paddle 8
+variable 0 7 2 shod1x8Pr SHMS 1X+ paddle 8
+variable 0 8 1 shod1x9P SHMS 1X+ paddle 9
+variable 0 8 2 shod1x9Pr SHMS 1X+ paddle 9
+variable 0 12 1 shod1x10P SHMS 1X+ paddle 10
+variable 0 12 2 shod1x10Pr SHMS 1X+ paddle 10
+variable 0 9 1 shod1x11P SHMS 1X+ paddle 11
+variable 0 9 2 shod1x11Pr SHMS 1X+ paddle 11
+variable 0 13 1 shod1x12P SHMS 1X+ paddle 12
+variable 0 13 2 shod1x12Pr SHMS 1X+ paddle 12
+variable 0 10 1 shod1x13P SHMS 1X+ paddle 13
+variable 0 10 2 shod1x13Pr SHMS 1X+ paddle 13
+variable 1 0 1 shod1y1M SHMS 1Y- paddle 1
+variable 1 0 2 shod1y1Mr SHMS 1Y- paddle 1
+variable 1 4 1 shod1y2M SHMS 1Y- paddle 2
+variable 1 4 2 shod1y2Mr SHMS 1Y- paddle 2
+variable 1 1 1 shod1y3M SHMS 1Y- paddle 3
+variable 1 1 2 shod1y3Mr SHMS 1Y- paddle 3
+variable 1 5 1 shod1y4M SHMS 1Y- paddle 4
+variable 1 5 2 shod1y4Mr SHMS 1Y- paddle 4
+variable 1 2 1 shod1y5M SHMS 1Y- paddle 5
+variable 1 2 2 shod1y5Mr SHMS 1Y- paddle 5
+variable 1 3 1 shod1y7M SHMS 1Y- paddle 7
+variable 1 3 2 shod1y7Mr SHMS 1Y- paddle 7
+variable 1 7 1 shod1y8M SHMS 1Y- paddle 8
+variable 1 7 2 shod1y8Mr SHMS 1Y- paddle 8
+variable 1 8 1 shod1y9M SHMS 1Y- paddle 9
+variable 1 8 2 shod1y9Mr SHMS 1Y- paddle 9
+variable 1 12 1 shod1y10M SHMS 1Y- paddle 10
+variable 1 12 2 shod1y10Mr SHMS 1Y- paddle 10
+variable 1 9 1 shod1y11M SHMS 1Y- paddle 11
+variable 1 9 2 shod1y11Mr SHMS 1Y- paddle 11
+variable 1 13 1 shod1y12M SHMS 1Y- paddle 12
+variable 1 13 2 shod1y12Mr SHMS 1Y- paddle 12
+variable 1 10 1 shod1y13M SHMS 1Y- paddle 13
+variable 1 10 2 shod1y13Mr SHMS 1Y- paddle 13
+variable 1 16 1 shod1y1P SHMS 1Y+ paddle 1
+variable 1 16 2 shod1y1Pr SHMS 1Y+ paddle 1
+variable 1 20 1 shod1y2P SHMS 1Y+ paddle 2
+variable 1 20 2 shod1y2Pr SHMS 1Y+ paddle 2
+variable 1 17 1 shod1y3P SHMS 1Y+ paddle 3
+variable 1 17 2 shod1y3Pr SHMS 1Y+ paddle 3
+variable 1 21 1 shod1y4P SHMS 1Y+ paddle 4
+variable 1 21 2 shod1y4Pr SHMS 1Y+ paddle 4
+variable 1 18 1 shod1y5P SHMS 1Y+ paddle 5
+variable 1 18 2 shod1y5Pr SHMS 1Y+ paddle 5
+variable 1 22 1 shod1y6P SHMS 1Y+ paddle 6
+variable 1 22 2 shod1y6Pr SHMS 1Y+ paddle 6
+variable 1 19 1 shod1y7P SHMS 1Y+ paddle 7
+variable 1 19 2 shod1y7Pr SHMS 1Y+ paddle 7
+variable 1 23 1 shod1y8P SHMS 1Y+ paddle 8
+variable 1 23 2 shod1y8Pr SHMS 1Y+ paddle 8
+variable 1 24 1 shod1y9P SHMS 1Y+ paddle 9
+variable 1 24 2 shod1y9Pr SHMS 1Y+ paddle 9
+variable 1 28 1 shod1y10P SHMS 1Y+ paddle 10
+variable 1 28 2 shod1y10Pr SHMS 1Y+ paddle 10
+variable 1 25 1 shod1y11P SHMS 1Y+ paddle 11
+variable 1 25 2 shod1y11Pr SHMS 1Y+ paddle 11
+variable 1 29 1 shod1y12P SHMS 1Y+ paddle 12
+variable 1 29 2 shod1y12Pr SHMS 1Y+ paddle 12
+variable 1 26 1 shod1y13P SHMS 1Y+ paddle 13
+variable 1 26 2 shod1y13Pr SHMS 1Y+ paddle 13
+variable 2 9 1 shod2x11P SHMS 2X+ paddle 11
+variable 2 9 2 shod2x11Pr SHMS 2X+ paddle 11
+variable 7 1 1 s1Y s1Y
+variable 7 1 2 s1Yr s1Y
+variable 7 30 1 Unser Unser
+variable 7 30 2 Unserr Unser
+variable 2 30 1 shod2x14M SHMS 2X- paddle 14
+variable 2 30 2 shod2x14Mr SHMS 2X- paddle 14
+variable 7 14 1 sAERSUM sAERSUM
+variable 7 14 2 sAERSUMr sAERSUM
+variable 3 19 1 shod2y7M SHMS 2y- paddle 7
+variable 3 19 2 shod2y7Mr SHMS 2y- paddle 7
+variable 3 3 1 shod2y7P SHMS 2y+ paddle 7
+variable 3 3 2 shod2y7Pr SHMS 2y+ paddle 7
+variable 2 19 1 shod2x7M SHMS 2X- paddle 7
+variable 2 19 2 shod2x7Mr SHMS 2X- paddle 7
+variable 2 3 1 shod2x7P SHMS 2X+ paddle 7
+variable 2 3 2 shod2x7Pr SHMS 2X+ paddle 7
+variable 3 31 1 shod2y16M SHMS 2y- paddle 16
+variable 3 31 2 shod2y16Mr SHMS 2y- paddle 16
+variable 3 15 1 shod2y16P SHMS 2y+ paddle 16
+variable 3 15 2 shod2y16Pr SHMS 2y+ paddle 16
+variable 3 24 1 shod2y9M SHMS 2y- paddle 9
+variable 3 24 2 shod2y9Mr SHMS 2y- paddle 9
+variable 7 15 1 sCERSUM sCERSUM
+variable 7 15 2 sCERSUMr sCERSUM
+variable 3 14 1 shod2y14P SHMS 2y+ paddle 14
+variable 3 14 2 shod2y14Pr SHMS 2y+ paddle 14
+variable 2 5 1 shod2x4P SHMS 2X+ paddle 4
+variable 2 5 2 shod2x4Pr SHMS 2X+ paddle 4
+variable 2 21 1 shod2x4M SHMS 2X- paddle 4
+variable 2 21 2 shod2x4Mr SHMS 2X- paddle 4
+variable 7 3 1 s2Y s2Y
+variable 7 3 2 s2Yr s2Y
+variable 7 2 1 s2X s2X
+variable 7 2 2 s2Xr s2X
+variable 2 13 1 shod2x12P SHMS 2X+ paddle 12
+variable 2 13 2 shod2x12Pr SHMS 2X+ paddle 12
+variable 2 2 1 shod2x5P SHMS 2X+ paddle 5
+variable 2 2 2 shod2x5Pr SHMS 2X+ paddle 5
+variable 3 8 1 shod2y9P SHMS 2y+ paddle 9
+variable 3 8 2 shod2y9Pr SHMS 2y+ paddle 9
+variable 3 16 1 shod2y1M SHMS 2y- paddle 1
+variable 3 16 2 shod2y1Mr SHMS 2y- paddle 1
+variable 3 0 1 shod2y1P SHMS 2y+ paddle 1
+variable 3 0 2 shod2y1Pr SHMS 2y+ paddle 1
+variable 7 7 1 sASUM sASUM
+variable 7 7 2 sASUMr sASUM
+variable 2 25 1 shod2x11M SHMS 2X- paddle 11
+variable 2 25 2 shod2x11Mr SHMS 2X- paddle 11
+variable 3 28 1 shod2y10M SHMS 2y- paddle 10
+variable 3 28 2 shod2y10Mr SHMS 2y- paddle 10
+variable 3 12 1 shod2y10P SHMS 2y+ paddle 10
+variable 3 12 2 shod2y10Pr SHMS 2y+ paddle 10
+variable 7 9 1 sCSUM sCSUM
+variable 7 9 2 sCSUMr sCSUM
+variable 3 5 1 shod2y4P SHMS 2y+ paddle 4
+variable 3 5 2 shod2y4Pr SHMS 2y+ paddle 4
+variable 3 10 1 shod2y13P SHMS 2y+ paddle 13
+variable 3 10 2 shod2y13Pr SHMS 2y+ paddle 13
+variable 7 4 1 s1Xs1y s1T
+variable 7 4 2 s1Xs1yr s1T
+variable 2 4 1 shod2x2P SHMS 2X+ paddle 2
+variable 2 4 2 shod2x2Pr SHMS 2X+ paddle 2
+variable 2 20 1 shod2x2M SHMS 2X- paddle 2
+variable 2 20 2 shod2x2Mr SHMS 2X- paddle 2
+variable 3 22 1 shod2y6M SHMS 2y- paddle 6
+variable 3 22 2 shod2y6Mr SHMS 2y- paddle 6
+variable 2 12 1 shod2x10P SHMS 2X+ paddle 10
+variable 2 12 2 shod2x10Pr SHMS 2X+ paddle 10
+variable 2 28 1 shod2x10M SHMS 2X- paddle 10
+variable 2 28 2 shod2x10Mr SHMS 2X- paddle 10
+variable 3 25 1 shod2y11M SHMS 2y- paddle 11
+variable 3 25 2 shod2y11Mr SHMS 2y- paddle 11
+variable 2 10 1 shod2x13P SHMS 2X+ paddle 13
+variable 2 10 2 shod2x13Pr SHMS 2X+ paddle 13
+variable 3 6 1 shod2y6P SHMS 2y+ paddle 6
+variable 3 6 2 shod2y6Pr SHMS 2y+ paddle 6
+variable 2 22 1 shod2x6M SHMS 2X- paddle 6
+variable 2 22 2 shod2x6Mr SHMS 2X- paddle 6
+variable 3 23 1 shod2y8M SHMS 2y- paddle 8
+variable 3 23 2 shod2y8Mr SHMS 2y- paddle 8
+variable 3 7 1 shod2y8P SHMS 2y+ paddle 8
+variable 3 7 2 shod2y8Pr SHMS 2y+ paddle 8
+variable 2 1 1 shod2x3P SHMS 2X+ paddle 3
+variable 2 1 2 shod2x3Pr SHMS 2X+ paddle 3
+variable 2 17 1 shod2x3M SHMS 2X- paddle 3
+variable 2 17 2 shod2x3Mr SHMS 2X- paddle 3
+variable 3 9 1 shod2y11P SHMS 2y+ paddle 11
+variable 3 9 2 shod2y11Pr SHMS 2y+ paddle 11
+variable 3 1 1 shod2y3P SHMS 2y+ paddle 3
+variable 3 1 2 shod2y3Pr SHMS 2y+ paddle 3
+variable 2 24 1 shod2x9M SHMS 2X- paddle 9
+variable 2 24 2 shod2x9Mr SHMS 2X- paddle 9
+variable 3 17 1 shod2y3M SHMS 2y- paddle 3
+variable 3 17 2 shod2y3Mr SHMS 2y- paddle 3
+variable 2 26 1 shod2x13M SHMS 2X- paddle 13
+variable 2 26 2 shod2x13Mr SHMS 2X- paddle 13
+variable 2 8 1 shod2x9P SHMS 2X+ paddle 9
+variable 2 8 2 shod2x9Pr SHMS 2X+ paddle 9
+variable 3 13 1 shod2y12P SHMS 2y+ paddle 12
+variable 3 13 2 shod2y12Pr SHMS 2y+ paddle 12
+variable 7 0 1 s1X s1X
+variable 7 0 2 s1Xr s1X
+variable 3 29 1 shod2y12M SHMS 2y- paddle 12
+variable 3 29 2 shod2y12Mr SHMS 2y- paddle 12
+variable 7 8 1 sBSUM sBSUM
+variable 7 8 2 sBSUMr sBSUM
+variable 7 29 1 BCM17 bcm17
+variable 7 29 2 BCM17r bcm17
+variable 3 20 1 shod2y2M SHMS 2y- paddle 2
+variable 3 20 2 shod2y2Mr SHMS 2y- paddle 2
+variable 7 13 1 sSHWR sSHWR
+variable 7 13 2 sSHWRr sSHWR
+variable 3 4 1 shod2y2P SHMS 2y+ paddle 2
+variable 3 4 2 shod2y2Pr SHMS 2y+ paddle 2
+variable 2 23 1 shod2x8M SHMS 2X- paddle 8
+variable 2 23 2 shod2x8Mr SHMS 2X- paddle 8
+variable 7 6 1 sTrig sT1
+variable 7 6 2 sTrigr sT1
+variable 2 7 1 shod2x8P SHMS 2X+ paddle 8
+variable 2 7 2 shod2x8Pr SHMS 2X+ paddle 8
+variable 7 10 1 sDSUM sDSUM
+variable 7 10 2 sDSUMr sDSUM
+variable 2 16 1 shod2x1M SHMS 2X- paddle 1
+variable 2 16 2 shod2x1Mr SHMS 2X- paddle 1
+variable 3 2 1 shod2y5P SHMS 2y+ paddle 5
+variable 3 2 2 shod2y5Pr SHMS 2y+ paddle 5
+variable 3 18 1 shod2y5M SHMS 2y- paddle 5
+variable 3 18 2 shod2y5Mr SHMS 2y- paddle 5
+variable 2 0 1 shod2x1P SHMS 2X+ paddle 1
+variable 2 0 2 shod2x1Pr SHMS 2X+ paddle 1
+variable 2 14 1 shod2x14P SHMS 2X+ paddle 14
+variable 2 14 2 shod2x14Pr SHMS 2X+ paddle 14
+variable 7 11 1 sPSHWRLO sPSHWRLO
+variable 7 11 2 sPSHWRLOr sPSHWRLO
+variable 7 5 1 s2Xs2Y s2T
+variable 7 5 2 s2Xs2Yr s2T
+variable 3 30 1 shod2y14M SHMS 2y- paddle 14
+variable 3 30 2 shod2y14Mr SHMS 2y- paddle 14
+variable 2 6 1 shod2x6P SHMS 2X+ paddle 6
+variable 2 6 2 shod2x6Pr SHMS 2X+ paddle 6
+variable 7 26 1 BCM4B bcm4b
+variable 7 26 2 BCM4Br bcm4b
+variable 3 21 1 shod2y4M SHMS 2y- paddle 4
+variable 3 21 2 shod2y4Mr SHMS 2y- paddle 4
+variable 3 26 1 shod2y13M SHMS 2y- paddle 13
+variable 3 26 2 shod2y13Mr SHMS 2y- paddle 13
+variable 7 25 1 BCM4A bcm4a
+variable 7 25 2 BCM4Ar bcm4a
+variable 3 11 1 shod2y15P SHMS 2y+ paddle 15
+variable 3 11 2 shod2y15Pr SHMS 2y+ paddle 15
+variable 3 27 1 shod2y15M SHMS 2y- paddle 15
+variable 3 27 2 shod2y15Mr SHMS 2y- paddle 15
+variable 7 12 1 sPSHWRHI sPSHWRHI
+variable 7 12 2 sPSHWRHIr sPSHWRHI
+variable 2 29 1 shod2x12M SHMS 2X- paddle 12
+variable 2 29 2 shod2x12Mr SHMS 2X- paddle 12
+variable 1 6 1 shod1y6M SHMS 1Y- paddle 6
+variable 1 6 2 shod1y6Mr SHMS 1Y- paddle 6
+variable 2 18 1 shod2x5M SHMS 2X- paddle 5
+variable 2 18 2 shod2x5Mr SHMS 2X- paddle 5
diff --git a/DBASE/make_scaler_db.py b/DBASE/make_scaler_db.py
new file mode 100755
index 00000000..93b29c32
--- /dev/null
+++ b/DBASE/make_scaler_db.py
@@ -0,0 +1,83 @@
+#!/usr/bin/python
+
+# Deal with args
+
+xscalerMapName = 'scaler.map'
+
+cratemap = {
+    "4":{"spec":"H", "firstslot":6, "nslots":7, "roc":5, "offset":0},
+    "5":{"spec":"P", "firstslot":6, "nslots":8, "roc":8, "offset":640}
+    }
+chandict = {}
+nperslot = 32
+clockrate = 1000000
+
+class Channel:
+    def __init__(self, spec, slot, chan, comment=''):
+        self.spec = spec
+        self.slot = slot
+        self.chan = chan
+        self.comment = comment
+    def __str__(self):
+        string = self.spec+"."+str(self.slot)+"."+str(self.chan)+"."+self.comment
+        return string
+
+with open(xscalerMapName, 'r') as fi:
+    for line in fi:
+        # Skip empty lines
+        if line.isspace():
+            continue
+
+        line = line.strip()
+
+        # Check if comment line
+        if line.startswith('#'):
+            continue
+        if line.startswith('DATE') or line.startswith('xscaler-'):
+            continue
+
+        splitline = line.split(None,6)
+        helicity = splitline[1]
+        spec = cratemap[splitline[2]]["spec"]
+        name = spec+splitline[0]
+        slot = int(splitline[3])+cratemap[splitline[2]]["firstslot"]
+        start = int(splitline[4])
+        nchan = splitline[5] # This better be 1
+        comment = splitline[6]
+        uniquename = name
+        count = 2
+        while chandict.has_key(uniquename):
+            uniquename = name+"_"+str(count)
+            count += 1
+        chandict[uniquename] = Channel(cratemap[splitline[2]]["spec"],slot,start,comment)
+
+    for spec in cratemap:
+        firstslot = cratemap[spec]["firstslot"]
+        nslots = cratemap[spec]["nslots"]
+        roc = cratemap[spec]["roc"]
+        lastslot = firstslot + nslots - 1
+        offset = cratemap[spec]["offset"]
+        specprefix = cratemap[spec]["spec"]
+        hcanaMapName = 'db_'+specprefix+'SScalevt.dat'
+        with open(hcanaMapName, 'w') as fo:
+            for slot in range(firstslot,firstslot+nslots):
+                if slot == lastslot:
+                    rateinfo=' {0} {1}'.format(nperslot-1,clockrate)
+                else:
+                    rateinfo=''
+                print >>fo, 'map 3801 {0} {1} {2:04x}{1:02x}{3:02x} ffffffff {4}'.\
+                format(roc, slot, offset+(slot-firstslot)*nperslot,nperslot,lastslot)\
+                +rateinfo
+
+            for name in chandict:
+                channel = chandict[name]
+                slot = channel.slot-firstslot
+                printname = name[1:] # Drop prefix
+                printname = printname.replace("+","P")
+                printname = printname.replace("-","M")
+                if specprefix == channel.spec and slot<nslots:
+                    chan = channel.chan
+                    slot = channel.slot-firstslot
+                    comment = channel.comment
+                    print >>fo, 'variable', slot, chan, 1, printname, comment
+                    print >>fo, 'variable', slot, chan, 2, printname+'r', comment
diff --git a/DEF-files/HMS/EPICS/epics_short.def b/DEF-files/HMS/EPICS/epics_short.def
new file mode 100644
index 00000000..b1e773c1
--- /dev/null
+++ b/DEF-files/HMS/EPICS/epics_short.def
@@ -0,0 +1,14 @@
+# See $ANALYZER/examples/output_example.def for examples
+
+
+begin epics
+IBC3H00CRCUR4
+hac_bcm_average
+ibcm1
+ibcm2
+iunser
+itov3out
+itov4out
+end epics
+
+
diff --git a/SCRIPTS/HMS/replay_hms_scalers.C b/SCRIPTS/HMS/replay_hms_scalers.C
new file mode 100644
index 00000000..971560b1
--- /dev/null
+++ b/SCRIPTS/HMS/replay_hms_scalers.C
@@ -0,0 +1,97 @@
+void replay_hms_scalers(Int_t RunNumber=0, Int_t MaxEvent=0) {
+
+  // Get RunNumber and MaxEvent if not provided.
+  if(RunNumber == 0) {
+    cout << "Enter a Run Number (-1 to exit): ";
+    cin >> RunNumber;
+    if( RunNumber<=0 ) return;
+  }
+  if(MaxEvent == 0) {
+    cout << "\nNumber of Events to analyze: ";
+    cin >> MaxEvent;
+    if(MaxEvent == 0) {
+      cerr << "...Invalid entry\n";
+      exit;
+    }
+  }
+
+  // Create file name patterns.
+  const char* RunFileNamePattern = "raw/hms_all_%05d.dat";
+  const char* ROOTFileNamePattern = "ROOTfiles/hms_replay_scalers_%d.root";
+  // Add variables to global list.
+  gHcParms->Define("gen_run_number", "Run Number", RunNumber);
+  gHcParms->AddString("g_ctp_database_filename", "DBASE/standard.database");
+
+  // Load varibles from files to global list.
+  gHcParms->Load(gHcParms->GetString("g_ctp_database_filename"), RunNumber);
+
+  // g_ctp_parm_filename and g_decode_map_filename should now be defined.
+  gHcParms->Load(gHcParms->GetString("g_ctp_kinematics_filename"), RunNumber);
+  gHcParms->Load(gHcParms->GetString("g_ctp_parm_filename"));
+
+  // Load params for HMS trigger configuration
+  gHcParms->Load("PARAM/TRIG/thms.param");
+  // Load params for HODO tof calibration. 
+  // gHcParms->Load("PARAM/HMS/HODO/htofcal.param");
+
+  // Load the Hall C style detector map
+  gHcDetectorMap = new THcDetectorMap();
+  if ( RunNumber > 243) {
+  gHcDetectorMap->Load("MAPS/HMS/DETEC/hms_stack.map");
+  } else {
+  gHcDetectorMap->Load("MAPS/HMS/DETEC/hms_stack_spring17_run_00001_00243.map");
+  }
+
+  gHaEvtHandlers->Add (new THaEpicsEvtHandler("epics","HC EPICS event type 180"));
+  THcScalerEvtHandler *hscaler = new THcScalerEvtHandler("HS","Hall C scaler event type 1");
+  hscaler->AddEventType(1);
+  hscaler->SetUseFirstEvent(kTRUE);
+  // hscaler->SetDebugFile("REPORT_OUTPUT/hms_scaler_debug.txt");
+  gHaEvtHandlers->Add(hscaler);
+  // Set up the analyzer - we use the standard one,
+  // but this could be an experiment-specific one as well.
+  // The Analyzer controls the reading of the data, executes
+  // tests/cuts, loops over Acpparatus's and PhysicsModules,
+  // and executes the output routines.
+  THcAnalyzer* analyzer = new THcAnalyzer;
+
+  // A simple event class to be output to the resulting tree.
+  // Creating your own descendant of THaEvent is one way of
+  // defining and controlling the output.
+  THaEvent* event = new THaEvent;
+
+  // Define the run(s) that we want to analyze.
+  // We just set up one, but this could be many.
+  char RunFileName[100];
+  sprintf(RunFileName, RunFileNamePattern, RunNumber);
+  THaRun* run = new THaRun(RunFileName);
+
+  // Eventually need to learn to skip over, or properly analyze
+  // the pedestal events
+  run->SetEventRange(1, MaxEvent);    // Physics Event number, does not
+                                      // include scaler or control events.
+  run->SetNscan(1);
+  run->SetDataRequired(0x7);
+  run->Print();
+
+  // Define the analysis parameters
+  TString ROOTFileName = Form(ROOTFileNamePattern, RunNumber);
+  analyzer->SetCountMode(2);    // 0 = counter is # of physics triggers
+                                // 1 = counter is # of all decode reads
+                                // 2 = counter is event number
+ analyzer->SetEvent(event);
+  analyzer->SetEpicsEvtType(180);
+ analyzer->SetCrateMapFileName("MAPS/db_cratemap.dat");
+ analyzer->SetOutFile(ROOTFileName.Data());
+  analyzer->SetOdefFile("DEF-files/HMS/EPICS/epics_short.def");  // Call EPICS variables  K.Park
+  // analyzer->SetOdefFile("DEF-files/HMS/GEN/hstackana_report.def");
+  //analyzer->SetCutFile("DEF-files/HMS/GEN/hstackana_report_cuts.def");    // optional
+
+ // File to record cuts accounting information
+  analyzer->SetSummaryFile(Form("REPORT_OUTPUT/HMS/summary_%05d.report", RunNumber));    // optional
+
+  // Start the actual analysis.
+  analyzer->Process(run);
+  // Create report file from template.
+  // analyzer->PrintReport("TEMPLATES/hstackana.template",Form("REPORT_OUTPUT/HMS/replay_hms_%05d.report", RunNumber));
+}
diff --git a/SCRIPTS/SHMS/replay_shms_scalers.C b/SCRIPTS/SHMS/replay_shms_scalers.C
new file mode 100644
index 00000000..9d83a715
--- /dev/null
+++ b/SCRIPTS/SHMS/replay_shms_scalers.C
@@ -0,0 +1,96 @@
+void replay_shms_scalers(Int_t RunNumber=0, Int_t MaxEvent=0) {
+
+  // Get RunNumber and MaxEvent if not provided.
+  if(RunNumber == 0) {
+    cout << "Enter a Run Number (-1 to exit): ";
+    cin >> RunNumber;
+    if( RunNumber<=0 ) return;
+  }
+  if(MaxEvent == 0) {
+    cout << "\nNumber of Events to analyze: ";
+    cin >> MaxEvent;
+    if(MaxEvent == 0) {
+      cerr << "...Invalid entry\n";
+      exit;
+    }
+  }
+
+  // Create file name patterns.
+  const char* RunFileNamePattern = "raw/shms_all_%05d.dat";
+  const char* ROOTFileNamePattern = "ROOTfiles/shms_replay_scalers_%d.root";
+  // Add variables to global list.
+  gHcParms->Define("gen_run_number", "Run Number", RunNumber);
+  gHcParms->AddString("g_ctp_database_filename", "DBASE/standard.database");
+
+  // Load varibles from files to global list.
+  gHcParms->Load(gHcParms->GetString("g_ctp_database_filename"), RunNumber);
+
+  // g_ctp_parm_filename and g_decode_map_filename should now be defined.
+  gHcParms->Load(gHcParms->GetString("g_ctp_kinematics_filename"), RunNumber);
+  gHcParms->Load(gHcParms->GetString("g_ctp_parm_filename"));
+
+  // Load the Hall C style detector map
+  gHcDetectorMap = new THcDetectorMap();
+  gHcDetectorMap->Load("MAPS/SHMS/DETEC/shms_stack.map");
+
+  gHaEvtHandlers->Add (new THaEpicsEvtHandler("epics","HC EPICS event type 180"));
+  // Add EPICS variables
+  //  THaEpics* epics = new THaEpics("T", "Epics");
+  //  gHaApps->AddDetector(epics);
+
+ 
+
+  THcScalerEvtHandler *pscaler = new THcScalerEvtHandler("PS","Hall C scaler event type 1");
+  pscaler->AddEventType(1);
+  pscaler->SetUseFirstEvent(kTRUE);
+  // pscaler->SetDebugFile("REPORT_OUTPUT/scaler_debug.txt");
+  gHaEvtHandlers->Add (pscaler);
+
+
+  // Set up the analyzer - we use the standard one,
+  // but this could be an experiment-specific one as well.
+  // The Analyzer controls the reading of the data, executes
+  // tests/cuts, loops over Acpparatus's and PhysicsModules,
+  // and executes the output routines.
+  THcAnalyzer* analyzer = new THcAnalyzer;
+
+  // A simple event class to be output to the resulting tree.
+  // Creating your own descendant of THaEvent is one way of
+  // defining and controlling the output.
+  THaEvent* event = new THaEvent;
+
+  // Define the run(s) that we want to analyze.
+  // We just set up one, but this could be many.
+  char RunFileName[100];
+  sprintf(RunFileName, RunFileNamePattern, RunNumber);
+  THaRun* run = new THaRun(RunFileName);
+
+  // Eventually need to learn to skip over, or properly analyze
+  // the pedestal events
+  run->SetEventRange(1, MaxEvent);    // Physics Event number, does not
+                                      // include scaler or control events.
+  run->SetNscan(1);
+  run->SetDataRequired(0x7);
+  run->Print();
+
+  // Define the analysis parameters
+  TString ROOTFileName = Form(ROOTFileNamePattern, RunNumber);
+  analyzer->SetCountMode(2);    // 0 = counter is # of physics triggers
+                                // 1 = counter is # of all decode reads
+                                // 2 = counter is event number
+  analyzer->SetEvent(event);
+  analyzer->SetEpicsEvtType(180);
+  analyzer->SetCrateMapFileName("MAPS/db_cratemap.dat");
+  analyzer->SetOutFile(ROOTFileName.Data());
+  analyzer->SetOdefFile("DEF-files/HMS/EPICS/epics_short.def");  // Call EPICS variables  K.Park
+  //analyzer->SetOdefFile("DEF-files/SHMS/GEN/pstackana_report.def");
+  //analyzer->SetCutFile("DEF-files/SHMS/GEN/pstackana_report_cuts.def");    // optional
+
+  // File to record cuts accounting information
+  //  analyzer->SetSummaryFile(Form("REPORT_OUTPUT/SHMS/summary_%05d.report", RunNumber));    // optional
+
+  // Start the actual analysis.
+  analyzer->Process(run);
+  // Create report file from template.
+  //analyzer->PrintReport("TEMPLATES/pstackana.template",Form("REPORT_OUTPUT/SHMS/replay_shms_%05d.report", RunNumber));
+}
diff --git a/onlineGUI/Config/hms_scaler.cfg b/onlineGUI/Config/hms_scaler.cfg
new file mode 100644
index 00000000..04b618f0
--- /dev/null
+++ b/onlineGUI/Config/hms_scaler.cfg
@@ -0,0 +1,89 @@
+protorootfile ../ROOTfiles/hms_replay_scalers_XXXXX.root
+guicolor lightblue
+canvassize 800 800
+newpage 2 3
+title Trig rates
+macro Macros/plot_hms_scalers.C("uhScalTrigh1X","none")
+macro Macros/plot_hms_scalers.C("uhScalTrigh1Y","none")
+macro Macros/plot_hms_scalers.C("uhScalTrigh2X","none")
+macro Macros/plot_hms_scalers.C("uhScalTrigh2Y","none")
+macro Macros/plot_hms_scalers.C("uhScalTrigh1Xh1y","none")
+macro Macros/plot_hms_scalers.C("uhScalTrighTrig","none")
+newpage 2 2
+title Hod ave rates
+macro Macros/plot_hms_scalers.C("uhScalHodNeg1x","uhScalHodPos1x")
+macro Macros/plot_hms_scalers.C("uhScalHodNeg1y","uhScalHodPos1y")
+macro Macros/plot_hms_scalers.C("uhScalHodNeg2x","uhScalHodPos2x")
+macro Macros/plot_hms_scalers.C("uhScalHodNeg2y","uhScalHodPos2y")
+newpage 2 2
+title BCM rates
+macro Macros/plot_hms_scalers.C("uhScalBCM1","none")
+macro Macros/plot_hms_scalers.C("uhScalBCM2","none")
+macro Macros/plot_hms_scalers.C("uhScalBCM1","uhScalBCM2")
+macro Macros/plot_hms_scalers.C("uhScalUnser","none")
+newpage 2 2
+title BCM current
+macro Macros/plot_hms_scalers.C("uhCurBCM1","none")
+macro Macros/plot_hms_scalers.C("uhCurBCM2","none")
+macro Macros/plot_hms_scalers.C("uhCurBCM1","uhCurBCM2")
+macro Macros/plot_hms_scalers.C("uhCurUnser","none")
+newpage 4 4
+title X1 Scalers
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1xPad01","uhScalEvHodPos1xPad01")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1xPad02","uhScalEvHodPos1xPad02")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1xPad03","uhScalEvHodPos1xPad03")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1xPad04","uhScalEvHodPos1xPad04")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1xPad05","uhScalEvHodPos1xPad05")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1xPad06","uhScalEvHodPos1xPad06")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1xPad07","uhScalEvHodPos1xPad07")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1xPad08","uhScalEvHodPos1xPad08")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1xPad09","uhScalEvHodPos1xPad09")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1xPad10","uhScalEvHodPos1xPad10")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1xPad11","uhScalEvHodPos1xPad11")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1xPad12","uhScalEvHodPos1xPad12")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1xPad13","uhScalEvHodPos1xPad13")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1xPad14","uhScalEvHodPos1xPad14")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1xPad15","uhScalEvHodPos1xPad15")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1xPad16","uhScalEvHodPos1xPad16")
+newpage 3 4
+title Y1 Scalers
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1yPad01","uhScalEvHodPos1yPad01")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1yPad02","uhScalEvHodPos1yPad02")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1yPad03","uhScalEvHodPos1yPad03")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1yPad04","uhScalEvHodPos1yPad04")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1yPad05","uhScalEvHodPos1yPad05")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1yPad06","uhScalEvHodPos1yPad06")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1yPad07","uhScalEvHodPos1yPad07")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1yPad08","uhScalEvHodPos1yPad08")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1yPad09","uhScalEvHodPos1yPad09")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg1yPad10","uhScalEvHodPos1yPad10")
+newpage 4 4
+title X2 Scalers
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2xPad01","uhScalEvHodPos2xPad01")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2xPad02","uhScalEvHodPos2xPad02")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2xPad03","uhScalEvHodPos2xPad03")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2xPad04","uhScalEvHodPos2xPad04")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2xPad05","uhScalEvHodPos2xPad05")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2xPad06","uhScalEvHodPos2xPad06")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2xPad07","uhScalEvHodPos2xPad07")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2xPad08","uhScalEvHodPos2xPad08")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2xPad09","uhScalEvHodPos2xPad09")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2xPad10","uhScalEvHodPos2xPad10")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2xPad11","uhScalEvHodPos2xPad11")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2xPad12","uhScalEvHodPos2xPad12")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2xPad13","uhScalEvHodPos2xPad13")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2xPad14","uhScalEvHodPos2xPad14")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2xPad15","uhScalEvHodPos2xPad15")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2xPad16","uhScalEvHodPos2xPad16")
+newpage 3 4
+title Y2 Scalers
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2yPad01","uhScalEvHodPos2yPad01")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2yPad02","uhScalEvHodPos2yPad02")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2yPad03","uhScalEvHodPos2yPad03")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2yPad04","uhScalEvHodPos2yPad04")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2yPad05","uhScalEvHodPos2yPad05")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2yPad06","uhScalEvHodPos2yPad06")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2yPad07","uhScalEvHodPos2yPad07")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2yPad08","uhScalEvHodPos2yPad08")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2yPad09","uhScalEvHodPos2yPad09")
+macro Macros/plot_hms_scalers.C("uhScalEvHodNeg2yPad10","uhScalEvHodPos2yPad10")
diff --git a/onlineGUI/Config/shms_scaler.cfg b/onlineGUI/Config/shms_scaler.cfg
new file mode 100644
index 00000000..2617c730
--- /dev/null
+++ b/onlineGUI/Config/shms_scaler.cfg
@@ -0,0 +1,74 @@
+protorootfile ../ROOTfiles/shms_replay_scalers_XXXXX.root
+guicolor lightblue
+canvassize 800 800
+newpage 2 3
+title Trig rates
+macro Macros/plot_shms_scalers.C("uhScalTrigs1X","none")
+macro Macros/plot_shms_scalers.C("uhScalTrigs1Y","none")
+macro Macros/plot_shms_scalers.C("uhScalTrigs2X","none")
+macro Macros/plot_shms_scalers.C("uhScalTrigs2Y","none")
+macro Macros/plot_shms_scalers.C("uhScalTrigs1Xs1y","none")
+macro Macros/plot_shms_scalers.C("uhScalTrigsTrig","none")
+newpage 2 2
+title Hod ave rates
+macro Macros/plot_shms_scalers.C("uhScalHodNeg1x","uhScalHodPos1x")
+macro Macros/plot_shms_scalers.C("uhScalHodNeg1y","uhScalHodPos1y")
+macro Macros/plot_shms_scalers.C("uhScalHodNeg2x","uhScalHodPos2x")
+newpage 2 2
+title BCM rates
+macro Macros/plot_shms_scalers.C("uhScalBCM1","none")
+macro Macros/plot_shms_scalers.C("uhScalBCM2","none")
+macro Macros/plot_shms_scalers.C("uhScalBCM1","uhScalBCM2")
+macro Macros/plot_shms_scalers.C("uhScalUnser","none")
+newpage 2 2
+title BCM current
+macro Macros/plot_shms_scalers.C("uhCurBCM1","none")
+macro Macros/plot_shms_scalers.C("uhCurBCM2","none")
+macro Macros/plot_shms_scalers.C("uhCurBCM1","uhCurBCM2")
+macro Macros/plot_shms_scalers.C("uhCurUnser","none")
+newpage 4 4
+title X1 Scalers
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1xPad01","uhScalEvHodPos1xPad01")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1xPad02","uhScalEvHodPos1xPad02")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1xPad03","uhScalEvHodPos1xPad03")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1xPad04","uhScalEvHodPos1xPad04")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1xPad05","uhScalEvHodPos1xPad05")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1xPad06","uhScalEvHodPos1xPad06")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1xPad07","uhScalEvHodPos1xPad07")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1xPad08","uhScalEvHodPos1xPad08")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1xPad09","uhScalEvHodPos1xPad09")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1xPad10","uhScalEvHodPos1xPad10")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1xPad11","uhScalEvHodPos1xPad11")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1xPad12","uhScalEvHodPos1xPad12")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1xPad13","uhScalEvHodPos1xPad13")
+newpage 4 4
+title Y1 Scalers
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1yPad01","uhScalEvHodPos1yPad01")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1yPad02","uhScalEvHodPos1yPad02")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1yPad03","uhScalEvHodPos1yPad03")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1yPad04","uhScalEvHodPos1yPad04")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1yPad05","uhScalEvHodPos1yPad05")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1yPad06","uhScalEvHodPos1yPad06")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1yPad07","uhScalEvHodPos1yPad07")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1yPad08","uhScalEvHodPos1yPad08")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1yPad09","uhScalEvHodPos1yPad09")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1yPad10","uhScalEvHodPos1yPad10")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1yPad11","uhScalEvHodPos1yPad11")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1yPad12","uhScalEvHodPos1yPad12")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg1yPad13","uhScalEvHodPos1yPad13")
+newpage 4 4
+title X2 Scalers
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg2xPad01","uhScalEvHodPos2xPad01")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg2xPad02","uhScalEvHodPos2xPad02")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg2xPad03","uhScalEvHodPos2xPad03")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg2xPad04","uhScalEvHodPos2xPad04")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg2xPad05","uhScalEvHodPos2xPad05")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg2xPad06","uhScalEvHodPos2xPad06")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg2xPad07","uhScalEvHodPos2xPad07")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg2xPad08","uhScalEvHodPos2xPad08")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg2xPad09","uhScalEvHodPos2xPad09")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg2xPad10","uhScalEvHodPos2xPad10")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg2xPad11","uhScalEvHodPos2xPad11")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg2xPad12","uhScalEvHodPos2xPad12")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg2xPad13","uhScalEvHodPos2xPad13")
+macro Macros/plot_shms_scalers.C("uhScalEvHodNeg2xPad14","uhScalEvHodPos2xPad14")
diff --git a/onlineGUI/Macros/plot_hms_scalers.C b/onlineGUI/Macros/plot_hms_scalers.C
new file mode 100644
index 00000000..b7c79fa7
--- /dev/null
+++ b/onlineGUI/Macros/plot_hms_scalers.C
@@ -0,0 +1,289 @@
+// UserScript.C
+//
+// Helper macro to build additional histograms
+
+void UserScript()
+{
+  //
+  const UInt_t NTRIGS  = 6;
+  const TString trig_names[NTRIGS]={"h1X","h1Y","h1Xh1y","h2X","h2Y","hTrig"};
+  TH1F* hScalTrig[NTRIGS];
+  Double_t trig_scal[NTRIGS];
+  Double_t trig_ave[NTRIGS]={0,0,0,0,0,0};
+    TH1F* hAveTrig;
+    hAveTrig=new TH1F("AveTrig","Ave Trig Rates ",NTRIGS,0,NTRIGS);
+  //
+  const UInt_t NBCMS  = 3;
+  const TString bcm_names[NBCMS] = {"BCM1", "BCM2","Unser"};
+    TH1F* hScalBCM[NBCMS];
+    TH1F* hCurBCM[NBCMS];
+    TH1F* hAveCurBCM;
+    hAveCurBCM=new TH1F("AveCurBCM","Ave Current ",NBCMS,0,NBCMS);
+    TH1F* hAveRateBCM;
+    hAveRateBCM=new TH1F("AveRateBCM","Ave BCM Rate ",NBCMS,0,NBCMS);
+   Double_t bcm_scal[NBCMS];
+   Double_t bcm_cur[NBCMS];
+   Double_t bcm_ave_cur[NBCMS]={0.,0.,0.};
+   Double_t bcm_ave_rate[NBCMS]={0.,0.,0.};
+   Double_t bcm_offset[NBCMS]={250000,250000,393000};
+   Double_t bcm_slope[NBCMS]={4500*1.15,4500,4000};
+  //
+  const UInt_t NPLANES  = 4;
+  const TString plane_names[NPLANES] = {"1x", "1y", "2x", "2y"};
+  const UInt_t  nbars[NPLANES] = {16, 10, 16, 10};
+  const UInt_t  nbars_low[NPLANES] = {1, 1, 1, 1};
+  TH1F* hScalHodNegEv[NPLANES][16];
+  TH1F* hScalHodPosEv[NPLANES][16];
+  TH1F* hScalHodNeg[NPLANES];
+  TH1F* hScalHodPos[NPLANES];
+  Double_t hod_scalneg[NPLANES][16];
+  Double_t hod_scalpos[NPLANES][16];
+  Double_t hod_scalneg_rate[NPLANES][16];
+  Double_t hod_scalpos_rate[NPLANES][16];
+  Double_t good_bcm=0;
+  Double_t good_bcm_limit=265000.;
+  //
+ TTree *T=(TTree*)gDirectory->Get("TSHS");
+  Int_t totev=T->GetEntries();
+  // totev=400;
+  //
+  TString i2dbarname;TString h2dttitle;TString h2dtname;TString list_name;
+  for(UInt_t ip = 0; ip < NTRIGS; ip++) {
+     h2dttitle= trig_names[ip]+"; Event Number  ; Rate ";
+     h2dtname="uhScalTrig"+trig_names[ip];
+    hScalTrig[ip]= new TH1F(h2dtname,h2dttitle,totev,0,totev);
+    list_name ="HS"+trig_names[ip]+"r";
+    T->SetBranchAddress(list_name,&trig_scal[ip]);
+  }
+  //
+  for(UInt_t ip = 0; ip < NBCMS; ip++) {
+     h2dttitle= bcm_names[ip]+"; Event Number  ;  Rate ";
+     h2dtname="uhScal"+bcm_names[ip];
+    hScalBCM[ip]= new TH1F(h2dtname,h2dttitle,totev,0,totev);
+     h2dttitle= bcm_names[ip]+"; Event Number  ; Current  ";
+     h2dtname="uhCur"+bcm_names[ip];
+    hCurBCM[ip]= new TH1F(h2dtname,h2dttitle,totev,0,totev);
+    list_name ="HS"+bcm_names[ip]+"r";
+    T->SetBranchAddress(list_name,&bcm_scal[ip]);
+  }
+  //
+  for(UInt_t ip = 0; ip < NPLANES; ip++) {
+	      h2dttitle= "Beam On,Neg"+plane_names[ip]+"; Scintillator Bar  ; Ave Rate ";
+	      h2dtname="uhScalHodNeg"+plane_names[ip];
+              hScalHodNeg[ip]= new TH1F(h2dtname,h2dttitle,nbars[ip],0.5,nbars[ip]+.5);
+	      h2dttitle= "Beam on,Pos"+plane_names[ip]+"; Scintillator Bar  ; Ave Rate   ";
+	      h2dtname="uhScalHodPos"+plane_names[ip];
+              hScalHodPos[ip]= new TH1F(h2dtname,h2dttitle,nbars[ip],0.5,nbars[ip]+.5);
+ 	    for(UInt_t ibar = nbars_low[ip]-1; ibar < nbars[ip]; ibar++) {
+	      i2dbarname = Form("%02d",ibar+1);
+	      h2dttitle= "Neg Hod"+plane_names[ip]+i2dbarname+"; Event Number  ; Rate ";
+	      h2dtname="uhScalEvHodNeg"+plane_names[ip]+"Pad"+i2dbarname;
+             hScalHodNegEv[ip][ibar]= new TH1F(h2dtname,h2dttitle,totev,0,totev);
+	      h2dttitle= "Pos Hod"+plane_names[ip]+i2dbarname+"; Event Number  ; Rate  ";
+	      h2dtname="uhScalEvHodPos"+plane_names[ip]+"Pad"+i2dbarname;
+              hScalHodPosEv[ip][ibar]= new TH1F(h2dtname,h2dttitle,totev,0,totev);
+              hod_scalneg_rate[ip][ibar]=0;
+              hod_scalpos_rate[ip][ibar]=0;
+	    }
+  }
+  //
+  //
+  for(UInt_t ip = 0; ip < NPLANES; ip++) {
+	    for(UInt_t ibar = nbars_low[ip]-1; ibar < nbars[ip]; ibar++) {
+	      i2dbarname = Form("%d",ibar+1);
+	       list_name ="HShhod"+plane_names[ip]+i2dbarname+"Mr";
+	       T->SetBranchAddress(list_name,&hod_scalneg[ip][ibar]);
+	       list_name ="HShhod"+plane_names[ip]+i2dbarname+"Pr";
+	       T->SetBranchAddress(list_name,&hod_scalpos[ip][ibar]);
+	    }
+  }
+  // Loop over the events, filling the histograms
+  //  cout << " looping over data " << endl;
+  for(UInt_t iev = 0; iev < totev; iev++) {
+    //    cout << " iev = " << iev << endl;
+    //       cout << " get entry = " << iev << endl;
+    T->GetEntry(iev);
+    //
+    for(UInt_t ip = 0; ip < NTRIGS; ip++) {
+         hScalTrig[ip]->SetBinContent(iev,trig_scal[ip]);
+        if (bcm_scal[0] > good_bcm_limit) trig_ave[ip]+=trig_scal[ip];
+     }
+    //
+    for(UInt_t ip = 0; ip < NBCMS; ip++) {
+         hScalBCM[ip]->SetBinContent(iev,bcm_scal[ip]);
+         bcm_cur[ip]=(bcm_scal[ip]-bcm_offset[ip])/bcm_slope[ip];
+         hCurBCM[ip]->SetBinContent(iev,bcm_cur[ip]);         
+         if (bcm_scal[0] > good_bcm_limit) bcm_ave_cur[ip]+=bcm_cur[ip];
+         if (bcm_scal[0] > good_bcm_limit) bcm_ave_rate[ip]+=bcm_scal[ip];
+     }
+       if (bcm_scal[0] > good_bcm_limit) good_bcm++;
+//
+  for(UInt_t ip = 0; ip < NPLANES; ip++) {
+	    for(UInt_t ibar = nbars_low[ip]-1; ibar < nbars[ip]; ibar++) {
+	      hScalHodNegEv[ip][ibar]->SetBinContent(iev,hod_scalneg[ip][ibar]);
+	      hScalHodPosEv[ip][ibar]->SetBinContent(iev,hod_scalpos[ip][ibar]);
+             if (bcm_scal[0] > good_bcm_limit) {
+                  hod_scalneg_rate[ip][ibar]+=hod_scalneg[ip][ibar];
+                 hod_scalpos_rate[ip][ibar]+=hod_scalpos[ip][ibar];
+  	      }
+	      // cout << ip+1 << " " << ibar+1 << " " << hod_scalneg[ip][ibar]<< " " << hod_scalpos[ip][ibar] << endl;
+	    }
+  }    
+     //     cout  << " finish event = " << iev << endl; 
+}
+  cout << " Done " << endl;
+// calculate average when beam-on
+if (good_bcm >0) {
+  cout << " tot ev = " << totev << " Good BCm events = " << good_bcm << endl;
+  for(UInt_t ip = 0; ip < NBCMS; ip++) {
+    hAveCurBCM->SetBinContent(ip,bcm_ave_cur[ip]/good_bcm);
+    hAveRateBCM->SetBinContent(ip,bcm_ave_rate[ip]/good_bcm);
+  }
+  for(UInt_t ip = 0; ip < NTRIGS; ip++) {
+    hAveTrig->SetBinContent(ip,trig_ave[ip]/good_bcm);
+  }
+  for(UInt_t ip = 0; ip < NPLANES; ip++) {
+	    for(UInt_t ibar = nbars_low[ip]-1; ibar < nbars[ip]; ibar++) {
+	      hScalHodNeg[ip]->SetBinContent(ibar+1,hod_scalneg_rate[ip][ibar]/good_bcm);
+	      hScalHodPos[ip]->SetBinContent(ibar+1,hod_scalpos_rate[ip][ibar]/good_bcm);
+            }
+  }
+}
+	      //
+  return;
+}
+
+
+
+void plot_hms_scalers(TString histname,TString histname2) {
+  const UInt_t NTRIGS  = 6;
+  const TString trig_names[NTRIGS]={"h1X","h1Y","h1Xh1y","h2X","h2Y","hTrig"};
+  const UInt_t NPLANES  = 4;
+  const TString plane_names[NPLANES] = {"1x", "1y", "2x", "2y"};
+  const TString bar_names[16] = {"Pad01", "Pad02", "Pad03", "Pad04","Pad05", "Pad06", "Pad07", "Pad08","Pad09","Pad10","Pad11", "Pad12", "Pad13", "Pad14","Pad15", "Pad16"};
+  const UInt_t  nbars[NPLANES] = {16, 10, 16, 10};
+  const UInt_t  nbars_low[NPLANES] = {1, 1, 1, 1};
+  TH1F* h;
+  TH1F* hh;
+  TH1F* htrig;
+  TH1F* hhtrig;
+  TText* htext;
+  TText* hhtext;
+  Double_t aveh=0,avehh=0;
+  h = (TH1F*) gDirectory->Get(histname);
+  hh = (TH1F*) gDirectory->Get(histname2);
+  if(!h) {
+    UserScript();
+    h = (TH1F*) gDirectory->Get(histname);
+    if(!h) {
+      cout << "User histogram " << histname << " not found" << endl;
+      exit(1);
+    }
+    if (histname2!="none") {
+    hh = (TH1F*) gDirectory->Get(histname2);
+    if(!hh) {
+      cout << "User histogram " << histname2 << " not found" << endl;
+      exit(1);
+    } 
+    }
+  }
+  if (histname.Contains("Trig")) {
+         htrig = (TH1F*) gDirectory->Get("AveTrig");
+  }
+  if (histname2.Contains("Trig")) {
+         hhtrig = (TH1F*) gDirectory->Get("AveTrig");
+  }
+  for (Int_t ip=0;ip<NTRIGS;ip++) {
+    if (histname.Contains(trig_names[ip])) aveh=htrig->GetBinContent(ip);
+    if (histname2.Contains(trig_names[ip])) avehh=hhtrig->GetBinContent(ip);
+  }
+  // cout << histname.Contains("adcpeak") << endl;
+  Double_t maxf=0,max1=0,max2=0;
+    h->SetStats(0);
+    h->GetXaxis()->SetTitleOffset(.6);
+    h->GetXaxis()->SetTitleSize(0.08);
+    h->GetYaxis()->SetTitleOffset(.6);
+    h->GetYaxis()->SetTitleSize(0.08);
+    h->SetMinimum(0);
+    max1=h->GetBinContent(h->GetMaximumBin());
+    if (histname.Contains("uhScalHod")) {
+         TH1F* h1hod;
+         TH1F* h2hod;
+         TString h1title;
+         TString h2title;
+         UInt_t ipl_f1=0;
+         UInt_t ipl_f2=0;
+         for(UInt_t ipl = 0; ipl < NPLANES; ipl++) {
+	   if (histname.Contains(plane_names[ipl]))ipl_f1 = ipl;
+	   if (histname2.Contains(plane_names[ipl])) ipl_f2=ipl;
+	 }
+	     if (histname.Contains("Neg")) h1title="uhScalHodNeg"+plane_names[ipl_f1];
+	     if (histname.Contains("Pos")) h1title="uhScalHodPos"+plane_names[ipl_f1];
+	     if (histname2.Contains("Neg")) h2title="uhScalHodNeg"+plane_names[ipl_f2];
+	     if (histname2.Contains("Pos")) h2title="uhScalHodPos"+plane_names[ipl_f2];
+	     h1hod = (TH1F*) gDirectory->Get(h1title);
+	     h2hod = (TH1F*) gDirectory->Get(h2title);
+ 	     for(UInt_t ibar = nbars_low[ipl_f1]-1; ibar < nbars[ipl_f1]; ibar++) {
+ 	     if (h1hod) aveh+=h1hod->GetBinContent(ibar+1);
+	     }
+ 	     for(UInt_t ibar = nbars_low[ipl_f2]-1; ibar < nbars[ipl_f2]; ibar++) {
+	     if (h2hod) avehh+=h2hod->GetBinContent(ibar+1);
+	     }
+    }
+    if (histname.Contains("EvHod")) {
+         TH1F* h1hod;
+         TH1F* h2hod;
+         TString h1title;
+         TString h2title;
+         TString i2barname;
+         for(UInt_t ipl = 0; ipl < NPLANES; ipl++) {
+ 	    for(UInt_t ibar = nbars_low[ipl]-1; ibar < nbars[ipl]; ibar++) {
+            if (histname.Contains(plane_names[ipl]) && histname.Contains(bar_names[ibar])) {
+	     if (histname.Contains("Neg")) h1title="uhScalHodNeg"+plane_names[ipl];
+	     if (histname.Contains("Pos")) h1title="uhScalHodPos"+plane_names[ipl];
+	     h1hod = (TH1F*) gDirectory->Get(h1title);
+ 	     if (h1hod) aveh=h1hod->GetBinContent(ibar+1);
+            }
+            if (histname2.Contains(plane_names[ipl]) && histname2.Contains(bar_names[ibar])) {
+	     if (histname2.Contains("Neg")) h2title="uhScalHodNeg"+plane_names[ipl];
+	     if (histname2.Contains("Pos")) h2title="uhScalHodPos"+plane_names[ipl];
+	     h2hod = (TH1F*) gDirectory->Get(h2title);
+ 	     if (h2hod) avehh=h2hod->GetBinContent(ibar+1);
+            }
+	    }
+         }
+    }
+    if (histname.Contains("BCM") || histname.Contains("Unser")) {
+         TH1F* hbcm;
+         if (histname.Contains("Cur") ) hbcm = (TH1F*) gDirectory->Get("AveCurBCM");
+         if (histname.Contains("Scal") ) hbcm = (TH1F*) gDirectory->Get("AveRateBCM");
+         if (histname.Contains("BCM1")) aveh=hbcm->GetBinContent(0);
+         if (histname.Contains("BCM2")) aveh=hbcm->GetBinContent(1);
+         if (histname.Contains("Unser")) aveh=hbcm->GetBinContent(2);
+         if (histname2!="none") {
+         if (histname2.Contains("BCM1")) avehh=hbcm->GetBinContent(0);
+         if (histname2.Contains("BCM2")) avehh=hbcm->GetBinContent(1);
+         if (histname2.Contains("Unser")) avehh=hbcm->GetBinContent(2);
+	 }
+    }
+    if (hh)  max2=hh->GetBinContent(hh->GetMaximumBin());
+    maxf=max1*1.2;
+    if (hh && max2>max1) maxf=max2*1.2;
+    if (h && !histname.Contains("uhScalHod"))  htext = new TText(2,maxf*.95,Form("%s Ave = %7.2f",h->GetTitle(),aveh));
+    if (hh && !histname.Contains("uhScalHod")) hhtext = new TText(2,maxf*.90,Form("%s Ave = %7.2f",hh->GetTitle(),avehh));
+    if (h && histname.Contains("uhScalHod"))  htext = new TText(2,maxf*.95,Form("%s Integral = %7.2f",h->GetTitle(),aveh));
+    if (hh && histname.Contains("uhScalHod")) hhtext = new TText(2,maxf*.90,Form("%s Integral = %7.2f",hh->GetTitle(),avehh));
+    h->SetMaximum(maxf);
+    h->Draw("p");
+    h->SetMarkerStyle(7);
+    h->SetMarkerColor(1);
+    htext->Draw();
+    if (hh) {
+    hh->Draw("p same");
+    hh->SetMarkerColor(2);
+    hh->SetMarkerStyle(7);
+    hhtext->Draw();
+    hhtext->SetTextColor(2);
+    }
+}
+
diff --git a/onlineGUI/Macros/plot_shms_scalers.C b/onlineGUI/Macros/plot_shms_scalers.C
new file mode 100644
index 00000000..5259e871
--- /dev/null
+++ b/onlineGUI/Macros/plot_shms_scalers.C
@@ -0,0 +1,288 @@
+// UserScript.C
+//
+// Helper macro to build additional histograms
+
+void UserScript()
+{
+  //
+  const UInt_t NTRIGS  = 6;
+  const TString trig_names[NTRIGS]={"s1X","s1Y","s1Xs1y","s2X","s2Y","sTrig"};
+  TH1F* hScalTrig[NTRIGS];
+  Double_t trig_scal[NTRIGS];
+  Double_t trig_ave[NTRIGS]={0,0,0,0,0,0};
+    TH1F* hAveTrig;
+    hAveTrig=new TH1F("AveTrig","Ave Trig Rates ",NTRIGS,0,NTRIGS);
+  //
+  const UInt_t NBCMS  = 3;
+  const TString bcm_names[NBCMS] = {"BCM1", "BCM2","Unser"};
+    TH1F* hScalBCM[NBCMS];
+    TH1F* hCurBCM[NBCMS];
+    TH1F* hAveCurBCM;
+    hAveCurBCM=new TH1F("AveCurBCM","Ave Current ",NBCMS,0,NBCMS);
+    TH1F* hAveRateBCM;
+    hAveRateBCM=new TH1F("AveRateBCM","Ave BCM Rate ",NBCMS,0,NBCMS);
+   Double_t bcm_scal[NBCMS];
+   Double_t bcm_cur[NBCMS];
+   Double_t bcm_ave_cur[NBCMS]={0.,0.,0.};
+   Double_t bcm_ave_rate[NBCMS]={0.,0.,0.};
+   Double_t bcm_offset[NBCMS]={250000,250000,393000};
+   Double_t bcm_slope[NBCMS]={4500*1.15,4500,4000};
+  //
+  const UInt_t NPLANES  = 4;
+  const TString plane_names[NPLANES] = {"1x", "1y", "2x", "2y"};
+  const UInt_t  nbars[NPLANES] = {13, 13, 14, 16};
+  const UInt_t  nbars_low[NPLANES] = {1, 1, 1, 7};
+  TH1F* hScalHodNegEv[NPLANES][16];
+  TH1F* hScalHodPosEv[NPLANES][16];
+  TH1F* hScalHodNeg[NPLANES];
+  TH1F* hScalHodPos[NPLANES];
+  Double_t hod_scalneg[NPLANES][16];
+  Double_t hod_scalpos[NPLANES][16];
+  Double_t hod_scalneg_rate[NPLANES][16];
+  Double_t hod_scalpos_rate[NPLANES][16];
+  Double_t good_bcm=0;
+  Double_t good_bcm_limit=260000.;
+  //
+ TTree *T=(TTree*)gDirectory->Get("TSPS");
+  Int_t totev=T->GetEntries();
+  totev=400;
+  //
+  TString i2dbarname;TString h2dttitle;TString h2dtname;TString list_name;
+  for(UInt_t ip = 0; ip < NTRIGS; ip++) {
+     h2dttitle= trig_names[ip]+"; Event Number  ; Rate ";
+     h2dtname="uhScalTrig"+trig_names[ip];
+    hScalTrig[ip]= new TH1F(h2dtname,h2dttitle,totev,0,totev);
+    list_name ="PS"+trig_names[ip]+"r";
+    T->SetBranchAddress(list_name,&trig_scal[ip]);
+  }
+  //
+  for(UInt_t ip = 0; ip < NBCMS; ip++) {
+     h2dttitle= bcm_names[ip]+"; Event Number  ;  Rate ";
+     h2dtname="uhScal"+bcm_names[ip];
+    hScalBCM[ip]= new TH1F(h2dtname,h2dttitle,totev,0,totev);
+     h2dttitle= bcm_names[ip]+"; Event Number  ; Current  ";
+     h2dtname="uhCur"+bcm_names[ip];
+    hCurBCM[ip]= new TH1F(h2dtname,h2dttitle,totev,0,totev);
+    list_name ="PS"+bcm_names[ip]+"r";
+    T->SetBranchAddress(list_name,&bcm_scal[ip]);
+  }
+  //
+  for(UInt_t ip = 0; ip < NPLANES; ip++) {
+	      h2dttitle= "Beam On,Neg"+plane_names[ip]+"; Scintillator Bar  ; Ave Rate ";
+	      h2dtname="uhScalHodNeg"+plane_names[ip];
+              hScalHodNeg[ip]= new TH1F(h2dtname,h2dttitle,nbars[ip],0.5,nbars[ip]+.5);
+	      h2dttitle= "Beam On,Pos"+plane_names[ip]+"; Scintillator Bar  ; Ave Rate   ";
+	      h2dtname="uhScalHodPos"+plane_names[ip];
+              hScalHodPos[ip]= new TH1F(h2dtname,h2dttitle,nbars[ip],0.5,nbars[ip]+.5);
+ 	    for(UInt_t ibar = nbars_low[ip]-1; ibar < nbars[ip]; ibar++) {
+	      i2dbarname = Form("%02d",ibar+1);
+	      h2dttitle= "Neg Hod"+plane_names[ip]+i2dbarname+"; Event Number  ; Rate ";
+	      h2dtname="uhScalEvHodNeg"+plane_names[ip]+"Pad"+i2dbarname;
+             hScalHodNegEv[ip][ibar]= new TH1F(h2dtname,h2dttitle,totev,0,totev);
+	      h2dttitle= "Pos Hod"+plane_names[ip]+i2dbarname+"; Event Number  ; Rate  ";
+	      h2dtname="uhScalEvHodPos"+plane_names[ip]+"Pad"+i2dbarname;
+              hScalHodPosEv[ip][ibar]= new TH1F(h2dtname,h2dttitle,totev,0,totev);
+              hod_scalneg_rate[ip][ibar]=0;
+              hod_scalpos_rate[ip][ibar]=0;
+	    }
+  }
+  //
+  //
+  for(UInt_t ip = 0; ip < NPLANES; ip++) {
+	    for(UInt_t ibar = nbars_low[ip]-1; ibar < nbars[ip]; ibar++) {
+	      i2dbarname = Form("%d",ibar+1);
+	       list_name ="PSshod"+plane_names[ip]+i2dbarname+"Mr";
+	       T->SetBranchAddress(list_name,&hod_scalneg[ip][ibar]);
+	       list_name ="PSshod"+plane_names[ip]+i2dbarname+"Pr";
+	       T->SetBranchAddress(list_name,&hod_scalpos[ip][ibar]);
+	    }
+  }
+  // Loop over the events, filling the histograms
+  //  cout << " looping over data " << endl;
+  for(UInt_t iev = 0; iev < totev; iev++) {
+    //    cout << " iev = " << iev << endl;
+    //       cout << " get entry = " << iev << endl;
+    T->GetEntry(iev);
+    //
+    for(UInt_t ip = 0; ip < NTRIGS; ip++) {
+         hScalTrig[ip]->SetBinContent(iev,trig_scal[ip]);
+        if (bcm_scal[0] > good_bcm_limit) trig_ave[ip]+=trig_scal[ip];
+     }
+    //
+    for(UInt_t ip = 0; ip < NBCMS; ip++) {
+         hScalBCM[ip]->SetBinContent(iev,bcm_scal[ip]);
+         bcm_cur[ip]=(bcm_scal[ip]-bcm_offset[ip])/bcm_slope[ip];
+         hCurBCM[ip]->SetBinContent(iev,bcm_cur[ip]);         
+         if (bcm_scal[0] > good_bcm_limit) bcm_ave_cur[ip]+=bcm_cur[ip];
+         if (bcm_scal[0] > good_bcm_limit) bcm_ave_rate[ip]+=bcm_scal[ip];
+     }
+       if (bcm_scal[0] > good_bcm_limit) good_bcm++;
+//
+  for(UInt_t ip = 0; ip < NPLANES; ip++) {
+	    for(UInt_t ibar = nbars_low[ip]-1; ibar < nbars[ip]; ibar++) {
+	      hScalHodNegEv[ip][ibar]->SetBinContent(iev,hod_scalneg[ip][ibar]);
+	      hScalHodPosEv[ip][ibar]->SetBinContent(iev,hod_scalpos[ip][ibar]);
+             if (bcm_scal[0] > good_bcm_limit) {
+                  hod_scalneg_rate[ip][ibar]+=hod_scalneg[ip][ibar];
+                 hod_scalpos_rate[ip][ibar]+=hod_scalpos[ip][ibar];
+  	      }
+	      // cout << ip+1 << " " << ibar+1 << " " << hod_scalneg[ip][ibar]<< " " << hod_scalpos[ip][ibar] << endl;
+	    }
+  }    
+     //     cout  << " finish event = " << iev << endl; 
+}
+  cout << " Done " << endl;
+// calculate average when beam-on
+if (good_bcm >0) {
+  for(UInt_t ip = 0; ip < NBCMS; ip++) {
+    hAveCurBCM->SetBinContent(ip,bcm_ave_cur[ip]/good_bcm);
+    hAveRateBCM->SetBinContent(ip,bcm_ave_rate[ip]/good_bcm);
+  }
+  for(UInt_t ip = 0; ip < NTRIGS; ip++) {
+    hAveTrig->SetBinContent(ip,trig_ave[ip]/good_bcm);
+  }
+  for(UInt_t ip = 0; ip < NPLANES; ip++) {
+	    for(UInt_t ibar = nbars_low[ip]-1; ibar < nbars[ip]; ibar++) {
+	      hScalHodNeg[ip]->SetBinContent(ibar+1,hod_scalneg_rate[ip][ibar]/good_bcm);
+	      hScalHodPos[ip]->SetBinContent(ibar+1,hod_scalpos_rate[ip][ibar]/good_bcm);
+            }
+  }
+}
+	      //
+  return;
+}
+
+
+
+void plot_shms_scalers(TString histname,TString histname2) {
+  const UInt_t NTRIGS  = 6;
+  const TString trig_names[NTRIGS]={"s1X","s1Y","s1Xs1y","s2X","s2Y","sTrig"};
+  const UInt_t NPLANES  = 4;
+  const TString plane_names[NPLANES] = {"1x", "1y", "2x", "2y"};
+  const TString bar_names[16] = {"Pad01", "Pad02", "Pad03", "Pad04","Pad05", "Pad06", "Pad07", "Pad08","Pad09","Pad10","Pad11", "Pad12", "Pad13", "Pad14","Pad15", "Pad16"};
+  const UInt_t  nbars[NPLANES] = {13, 13, 14, 16};
+  const UInt_t  nbars_low[NPLANES] = {1, 1, 1, 7};
+  TH1F* h;
+  TH1F* hh;
+  TH1F* htrig;
+  TH1F* hhtrig;
+  TText* htext;
+  TText* hhtext;
+  Double_t aveh=0,avehh=0;
+  h = (TH1F*) gDirectory->Get(histname);
+  hh = (TH1F*) gDirectory->Get(histname2);
+  if(!h) {
+    UserScript();
+    h = (TH1F*) gDirectory->Get(histname);
+    if(!h) {
+      cout << "User histogram " << histname << " not found" << endl;
+      exit(1);
+    }
+    if (histname2!="none") {
+    hh = (TH1F*) gDirectory->Get(histname2);
+    if(!hh) {
+      cout << "User histogram " << histname2 << " not found" << endl;
+      exit(1);
+    } 
+    }
+  }
+  if (histname.Contains("Trig")) {
+         htrig = (TH1F*) gDirectory->Get("AveTrig");
+  }
+  if (histname2.Contains("Trig")) {
+         hhtrig = (TH1F*) gDirectory->Get("AveTrig");
+  }
+  for (Int_t ip=0;ip<NTRIGS;ip++) {
+    if (histname.Contains(trig_names[ip])) aveh=htrig->GetBinContent(ip);
+    if (histname2.Contains(trig_names[ip])) avehh=hhtrig->GetBinContent(ip);
+  }
+  // cout << histname.Contains("adcpeak") << endl;
+  Double_t maxf=0,max1=0,max2=0;
+    h->SetStats(0);
+    h->GetXaxis()->SetTitleOffset(.6);
+    h->GetXaxis()->SetTitleSize(0.08);
+    h->GetYaxis()->SetTitleOffset(.6);
+    h->GetYaxis()->SetTitleSize(0.08);
+    h->SetMinimum(0);
+    max1=h->GetBinContent(h->GetMaximumBin());
+    if (histname.Contains("uhScalHod")) {
+         TH1F* h1hod;
+         TH1F* h2hod;
+         TString h1title;
+         TString h2title;
+         UInt_t ipl_f1=0;
+         UInt_t ipl_f2=0;
+         for(UInt_t ipl = 0; ipl < NPLANES; ipl++) {
+	   if (histname.Contains(plane_names[ipl]))ipl_f1 = ipl;
+	   if (histname2.Contains(plane_names[ipl])) ipl_f2=ipl;
+	 }
+	     if (histname.Contains("Neg")) h1title="uhScalHodNeg"+plane_names[ipl_f1];
+	     if (histname.Contains("Pos")) h1title="uhScalHodPos"+plane_names[ipl_f1];
+	     if (histname2.Contains("Neg")) h2title="uhScalHodNeg"+plane_names[ipl_f2];
+	     if (histname2.Contains("Pos")) h2title="uhScalHodPos"+plane_names[ipl_f2];
+	     h1hod = (TH1F*) gDirectory->Get(h1title);
+	     h2hod = (TH1F*) gDirectory->Get(h2title);
+ 	     for(UInt_t ibar = nbars_low[ipl_f1]-1; ibar < nbars[ipl_f1]; ibar++) {
+ 	     if (h1hod) aveh+=h1hod->GetBinContent(ibar+1);
+	     }
+ 	     for(UInt_t ibar = nbars_low[ipl_f2]-1; ibar < nbars[ipl_f2]; ibar++) {
+	     if (h2hod) avehh+=h2hod->GetBinContent(ibar+1);
+	     }
+    }
+    if (histname.Contains("EvHod")) {
+         TH1F* h1hod;
+         TH1F* h2hod;
+         TString h1title;
+         TString h2title;
+         TString i2barname;
+         for(UInt_t ipl = 0; ipl < NPLANES; ipl++) {
+ 	    for(UInt_t ibar = nbars_low[ipl]-1; ibar < nbars[ipl]; ibar++) {
+            if (histname.Contains(plane_names[ipl]) && histname.Contains(bar_names[ibar])) {
+	     if (histname.Contains("Neg")) h1title="uhScalHodNeg"+plane_names[ipl];
+	     if (histname.Contains("Pos")) h1title="uhScalHodPos"+plane_names[ipl];
+	     h1hod = (TH1F*) gDirectory->Get(h1title);
+ 	     if (h1hod) aveh=h1hod->GetBinContent(ibar+1);
+            }
+            if (histname2.Contains(plane_names[ipl]) && histname2.Contains(bar_names[ibar])) {
+	     if (histname2.Contains("Neg")) h2title="uhScalHodNeg"+plane_names[ipl];
+	     if (histname2.Contains("Pos")) h2title="uhScalHodPos"+plane_names[ipl];
+	     h2hod = (TH1F*) gDirectory->Get(h2title);
+ 	     if (h2hod) avehh=h2hod->GetBinContent(ibar+1);
+            }
+	    }
+         }
+    }
+    if (histname.Contains("BCM") || histname.Contains("Unser")) {
+         TH1F* hbcm;
+         if (histname.Contains("Cur") ) hbcm = (TH1F*) gDirectory->Get("AveCurBCM");
+         if (histname.Contains("Scal") ) hbcm = (TH1F*) gDirectory->Get("AveRateBCM");
+         if (histname.Contains("BCM1")) aveh=hbcm->GetBinContent(0);
+         if (histname.Contains("BCM2")) aveh=hbcm->GetBinContent(1);
+         if (histname.Contains("Unser")) aveh=hbcm->GetBinContent(2);
+         if (histname2!="none") {
+         if (histname2.Contains("BCM1")) avehh=hbcm->GetBinContent(0);
+         if (histname2.Contains("BCM2")) avehh=hbcm->GetBinContent(1);
+         if (histname2.Contains("Unser")) avehh=hbcm->GetBinContent(2);
+	 }
+    }
+    if (hh)  max2=hh->GetBinContent(hh->GetMaximumBin());
+    maxf=max1*1.2;
+    if (hh && max2>max1) maxf=max2*1.2;
+    if (h && !histname.Contains("uhScalHod"))  htext = new TText(2,maxf*.95,Form("%s Ave = %7.2f",h->GetTitle(),aveh));
+    if (hh && !histname.Contains("uhScalHod")) hhtext = new TText(2,maxf*.90,Form("%s Ave = %7.2f",hh->GetTitle(),avehh));
+    if (h && histname.Contains("uhScalHod"))  htext = new TText(2,maxf*.95,Form("%s Integral = %7.2f",h->GetTitle(),aveh));
+    if (hh && histname.Contains("uhScalHod"))  hhtext = new TText(2,maxf*.90,Form("%s Integral = %7.2f",hh->GetTitle(),avehh));
+    h->SetMaximum(maxf);
+    h->Draw("p");
+    h->SetMarkerStyle(7);
+    h->SetMarkerColor(1);
+    htext->Draw();
+    if (hh) {
+    hh->Draw("p same");
+    hh->SetMarkerColor(2);
+    hh->SetMarkerStyle(7);
+    hhtext->Draw();
+    hhtext->SetTextColor(2);
+    }
+}
+
-- 
GitLab