From 189808f528f128e993f141a27ed0e8c83a3b39f5 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Wed, 21 Jun 2017 19:55:48 +0200
Subject: [PATCH 01/59] Fixed code to provide monitoring histograms properly if
 the zeroth iteration is the only iteration.

---
 .../python/PyMirrAlignOnline/AlignSummary.py      | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignSummary.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignSummary.py
index d7b778291..599700bc8 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignSummary.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignSummary.py
@@ -358,15 +358,22 @@ class AlignSummary:
                 resHistoTrend.SetBinError(j+1, fitRes[j][2] * 1000)        
 
                 title[j] = 'RICH ' + str(self.whichRich) + ' Cherenkov angle resolution It. ' + str(j) 
-                if j == 0:
+                if (j == 0) and (j == self.maxIt) :
                     resHistograms[j].SetName('resHisto0')
                     self.monSvc.publishHistogram(self.monitoring_folder, resHistograms[j].Clone(), add=False)
-                    print "INFO: resHisto0 sent to Monitoring."
-                elif j == self.maxIt:
+                    print "INFO: resHisto0 sent to Monitoring."  
+                    resHistograms[j].SetName('resHistoN')
+                    self.monSvc.publishHistogram(self.monitoring_folder, resHistograms[j].Clone(), add=False)
+                    print "INFO: resHistoN sent to Monitoring."                  
+                elif (j == self.maxIt):
                     resHistograms[j].SetName('resHistoN')
                     self.monSvc.publishHistogram(self.monitoring_folder, resHistograms[j].Clone(), add=False)
                     print "INFO: resHistoN sent to Monitoring."
-                else:
+                elif (j == 0):
+                    resHistograms[j].SetName('resHisto0')
+                    self.monSvc.publishHistogram(self.monitoring_folder, resHistograms[j].Clone(), add=False)
+                    print "INFO: resHisto0 sent to Monitoring." 
+                if (j != 0):     
                     resHistograms[j].SetName('resHisto'+str(j))
 
                 resHistograms[j].SetTitle(title[j])
-- 
GitLab


From caf835f3eacafa699cc6de1f9783d1510da8c85e Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Fri, 23 Jun 2017 15:49:47 +0200
Subject: [PATCH 02/59] typo fix

---
 Rich/RichMirrorAlignmentOnline/doc/release.notes | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/doc/release.notes b/Rich/RichMirrorAlignmentOnline/doc/release.notes
index 2424b490d..637820d6e 100644
--- a/Rich/RichMirrorAlignmentOnline/doc/release.notes
+++ b/Rich/RichMirrorAlignmentOnline/doc/release.notes
@@ -10,6 +10,8 @@ Get into the habit of committing on every change (that compiles of course)
 
 ! Improvements since the previous "tagged" release of this code was tagged should be noted here, if any:
 
+! Notes pertaining to already "tagged" releases:
+
 ! 2017-06-20 - Paras Naik
   - "Tagged" as v3r3 (internally, since only Panoptes gets a tag now).
   - Now sending monitoring plots to the Presenter/Monet!
@@ -61,8 +63,6 @@ Get into the habit of committing on every change (that compiles of course)
       This is not ideal, because "System_19" could change to something else if a new RICH System is added in the ELOG.
   - Added workDir to the .conf file writer for RichMirrCombinFit, in RichAlignmentHelper.py
 
-! Notes pertaining to already "tagged" releases:
-
 ! 2017-06-03 - Paras Naik
   - "Tagged" as v3r2 (internally, since only Panoptes gets a tag now).
   - We now make a copy of Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnlineConfiguration.py every time we run.
-- 
GitLab


From 1aa1490194fd72ca05e6877ea365771a0034db8c Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Fri, 23 Jun 2017 16:13:58 +0200
Subject: [PATCH 03/59] typo fix (2)

---
 .../python/RichMirrorAlignmentOnline/Configuration.py            | 1 -
 1 file changed, 1 deletion(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py
index b5c2b9ec2..629288722 100644
--- a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py
+++ b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py
@@ -33,7 +33,6 @@ __authors__  = "Claire Prouve <Claire.Prouve@cern.ch>, Paras Naik <Paras.Naik@ce
 # In light of this, the RICH2 tolerances for 2017 should be set to: [0.032, 0.030, 0.043, 0.057] mrad
 #===============================================================================
 
-
 import os
 from Gaudi.Configuration  import *
 import GaudiKernel.ProcessJobOptions
-- 
GitLab


From 67c5bbeb930fa94eb3f1add529757382c126f97d Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Fri, 23 Jun 2017 16:24:45 +0200
Subject: [PATCH 04/59] Added warningFactor configurable to Configuration.py

---
 .../RichMirrorAlignmentOnline/Configuration.py       | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py
index 629288722..245e0cc0a 100644
--- a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py
+++ b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py
@@ -3,6 +3,9 @@
 # @date   08/07/2015
 __authors__  = "Claire Prouve <Claire.Prouve@cern.ch>, Paras Naik <Paras.Naik@cern.ch>"
 
+### The Configurables below can be picked up and used by RichMirrorAlignmentOnline
+### The Configurables below can also be sent by RichMirrorAlignmentOnline to RichMirrCombinFit and RichMirrAlign
+
 ### NOTE: these are not installed yet, but they exist and can be provided to MirrCombinFit if deemed necessary:
 # ("sinusoidShift"       , po::value<double>(& m_sinusoidShift         )->default_value( 0.0 ), "shift parameter in fitting formula; if fixSinusoidShift !=0, it is fixed at this value; othrewise this is just initial value"    )
 # ("zeroGlobalFitMean"   , po::value<int   >(& m_zeroGlobalFitMean     )->default_value( 0   ), "default =0 : \"mean\" in global fit is not fixed; if !=0 it is fixed at zero"                                                    )
@@ -10,10 +13,9 @@ __authors__  = "Claire Prouve <Claire.Prouve@cern.ch>, Paras Naik <Paras.Naik@ce
 # ("combAndMirrSubsets"  , po::value<string>(& m_combAndMirrSubsetsFile)                      , "File with chosen mirrors and combinations subsets"                                                                               )
 # ("backgroundOrder"     , po::value<int   >(& m_backgroundOrder       )->default_value( 2   ), "order for the polynomial background"                                                                                             )
 # ("plotOutputLevel"     , po::value<int   >(& m_plotOutputLevel       )->default_value( 2   ), "what plots should be saved (0) plot nothing (1) plot ...(2) only plot fits with chi2 worse than 3.0 (3) plot everything"         )
-# ("warningFactor"       , po::value<double>(& m_warningFactor         )->default_value( 20  ), "alerts the alignment shifter if any of the mirrors have shifted more than warningFactor*stopTolerance"                           )
 ### NOTE: these are not installed yet, but they exist and can be provided to RichMirrAlign if deemed necessary:
-# ("combAndMirrSubsets"  , po::value<string>(&combAndMirrSubsetsFile  )->default_value( ""         ), "file with subsets of mirror combinations and mirrors"                                                        )
-# ("usePremisaligned"    , po::bool_switch  (&usePremisaligned        )->default_value( false, "no"), "if true, then pre-misaligned xml files will be used (MC case), default=false"                                )
+# ("combAndMirrSubsets"  , po::value<string>(&combAndMirrSubsetsFile   )->default_value( ""         ), "file with subsets of mirror combinations and mirrors"                                                                     )
+# ("usePremisaligned"    , po::bool_switch  (&usePremisaligned         )->default_value( false, "no"), "if true, then pre-misaligned xml files will be used (MC case), default=false"                                             )
 
 #===============================================================================
 # regularizationMode has changed from 1 (used in 2016) to 0 (used in 2017). 
@@ -77,6 +79,7 @@ class Rich1MirrAlignOnConf(LHCbConfigurableUser):
        ,"stopTolerancePriZ"      : 0.03
        ,"stopToleranceSecY"      : 0.46
        ,"stopToleranceSecZ"      : 0.37
+       ,"warningFactor"          : 3
        ,"EvtMax"                 : -1
        ,"dataVariant"            : "Collision17"
        ,"fixSinusoidShift"       : 1
@@ -115,6 +118,7 @@ class Rich1MirrAlignOnConf(LHCbConfigurableUser):
        ,"stopTolerancePriZ"      : """ RICH-dependent tolerance for primary   mirrors rotation around Z correction in mrad to stop the alignment """
        ,"stopToleranceSecY"      : """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """
        ,"stopToleranceSecZ"      : """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """
+       ,"warningFactor"          : """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """
        ,"EvtMax"                 : """ maximal number of events processed by brunel PER NODE (hlt farm has ~1500 nodes), -1 = infinite """
        ,"dataVariant"            : """ Helps us decide which Brunel options to use; also used for the naming convention. """
        ,"fixSinusoidShift"       : """ 1 : fix at sinusoidShift; 0 : it is not fixed """
@@ -207,6 +211,7 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser):
        ,"stopTolerancePriZ"      : 0.03
        ,"stopToleranceSecY"      : 0.05
        ,"stopToleranceSecZ"      : 0.06
+       ,"warningFactor"          : 3
        ,"EvtMax"                 : -1
        ,"dataVariant"            : "Collision17"
        ,"fixSinusoidShift"       : 1
@@ -245,6 +250,7 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser):
        ,"stopTolerancePriZ"      : """ RICH-dependent tolerance for primary   mirrors rotation around Z correction in mrad to stop the alignment """
        ,"stopToleranceSecY"      : """ RICH-dependent tolerance for secondary mirrors rotation around Y correction in mrad to stop the alignment """
        ,"stopToleranceSecZ"      : """ RICH-dependent tolerance for secondary mirrors rotation around Z correction in mrad to stop the alignment """
+       ,"warningFactor"          : """ alerts the alignment if any of the mirrors have shifted more than warningFactor times a particular mirror rotation stopTolerance """
        ,"EvtMax"          	     : """ maximal number of events processed by brunel PER NODE (hlt farm has ~1500 nodes), -1 = infinite """
        ,"dataVariant"            : """ Helps us decide which Brunel options to use; also used for the naming convention. """
        ,"fixSinusoidShift"       : """ 1 : fix at sinusoidShift; 0 : it is not fixed """
-- 
GitLab


From 055820d5f3df532f45d1434f30ec4126f7e73ded Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Fri, 23 Jun 2017 16:27:15 +0200
Subject: [PATCH 05/59] typo fix

---
 .../RichMirrorAlignmentOnline/Configuration.py   | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py
index 245e0cc0a..7993a7908 100644
--- a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py
+++ b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py
@@ -43,12 +43,12 @@ from Configurables import (LHCbConfigurableUser)
 class Rich1MirrAlignOnConf(LHCbConfigurableUser):
     __used_configurables__ = [ ]
     __slots__ = {
-       #### Only change these if you want to pick up from where you left off in iterations, experts only
-        "MajItStart"             : 0
-       ,"MinItStart"             : 0
        #### Do not change these!!! Just DON'T!
-       ,"Rich"                   : 1
+        "Rich"                   : 1
        ,"HistoDir"               : ""
+       #### Only change these if you want to pick up from where you left off in iterations, experts only
+       ,"MajItStart"             : 0
+       ,"MinItStart"             : 0
        ### Better not change these, only for very very VERY good reasons
        ,"WorkDir"                : "/group/online/AligWork/Rich1/"
        ,"SaveDir"                : "/group/online/AligWork/MirrorAlignments/"
@@ -175,12 +175,12 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser):
     __used_configurables__ = [ ]
 
     __slots__ = {
-       #### Only change these if you want to pick up from where you left off in iterations, experts only
-        "MajItStart"             : 0
-       ,"MinItStart"             : 0
        #### Do not ever change these!!! Just DONT!
-       ,"Rich"                   : 2
+        "Rich"                   : 2
        ,"HistoDir"               : ""
+       #### Only change these if you want to pick up from where you left off in iterations, experts only
+       ,"MajItStart"             : 0
+       ,"MinItStart"             : 0
        ### Better not change these, only for very very VERY good reasons
        ,"WorkDir"                : "/group/online/AligWork/Rich2/"
        ,"SaveDir"                : "/group/online/AligWork/MirrorAlignments/"
-- 
GitLab


From ca207fbf0c5126109d4bfd17170dd30ac6cb08f1 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Fri, 23 Jun 2017 16:39:32 +0200
Subject: [PATCH 06/59] Added displayMode configurable to Configuration.py

---
 .../python/RichMirrorAlignmentOnline/Configuration.py         | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py
index 7993a7908..46c02f3ab 100644
--- a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py
+++ b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py
@@ -84,6 +84,7 @@ class Rich1MirrAlignOnConf(LHCbConfigurableUser):
        ,"dataVariant"            : "Collision17"
        ,"fixSinusoidShift"       : 1
        ,"nameStr"                : ""
+       ,"displayMode"            : 1
         }
 
     _propertyDocDct = {
@@ -123,6 +124,7 @@ class Rich1MirrAlignOnConf(LHCbConfigurableUser):
        ,"dataVariant"            : """ Helps us decide which Brunel options to use; also used for the naming convention. """
        ,"fixSinusoidShift"       : """ 1 : fix at sinusoidShift; 0 : it is not fixed """
        ,"nameStr"                : """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """
+       ,"displayMode"            : """ 1 : Curent TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)"""
         }
 
     def setNameStr(self):
@@ -216,6 +218,7 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser):
        ,"dataVariant"            : "Collision17"
        ,"fixSinusoidShift"       : 1
        ,"nameStr"                : ""
+       ,"displayMode"            : 1
         }
 
     _propertyDocDct = {
@@ -255,6 +258,7 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser):
        ,"dataVariant"            : """ Helps us decide which Brunel options to use; also used for the naming convention. """
        ,"fixSinusoidShift"       : """ 1 : fix at sinusoidShift; 0 : it is not fixed """
        ,"nameStr"                : """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """
+       ,"displayMode"            : """ 1 : Curent TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)"""
         }
 
     ### Dont mess with this filename!!!
-- 
GitLab


From 09878660e372e37b10ea098a6cbf29c20c6629ca Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Sat, 24 Jun 2017 15:43:35 +0200
Subject: [PATCH 07/59] Prepare code for Anatoly to introduce second 2D Histo
 plotting style

---
 .../python/PyMirrAlignOnline/AlignSummary.py  | 173 +++++++++---------
 .../python/PyMirrAlignOnline/SetupHelper.py   |   2 +-
 2 files changed, 89 insertions(+), 86 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignSummary.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignSummary.py
index 599700bc8..9dc58e37d 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignSummary.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignSummary.py
@@ -55,13 +55,14 @@ class AlignSummary:
         print "INFO: monitoring_folder = " + self.monitoring_folder
         sys.stdout.flush()
     
-    def makeSummaryPlot(self, compareXML):
+    def performMonitoring(self, compareXML):
         import os
         gStyle.SetOptFit(1111)
         gStyle.SetOptStat(000000000)
                 
         saveName   = self.workdir + 'Rich' + str(self.whichRich) + '_AlignSummary.pdf'
         saveNameDM = self.workdir + 'Rich' + str(self.whichRich) + '_AlignMonitor.pdf'
+        saveNameA  = self.workdir + 'Rich' + str(self.whichRich) + '_AlignAnatoly.pdf'
         
         cPlot = TCanvas('cPlot', 'AlignExpert')
         cPlot.Divide(2,2,0.001,0.001)
@@ -69,6 +70,7 @@ class AlignSummary:
         dPlot = TCanvas('dPlot', 'AlignDM')
         dPlot.Divide(2,2,0.001,0.001)
 
+######### Start of 2D histos section
         # heatHistos
         from tiltObj import tiltObj
         mirrtilts = []
@@ -84,11 +86,16 @@ class AlignSummary:
             heatHistoPriZ = TH2D('heatHistoPriZ', 'RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation (mrad)', 2, -1, 1, 2, -1, 1)
             heatHistoSecY = TH2D('heatHistoSecY', 'RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation (mrad)', 4, -1, 1, 4, -1, 1)
             heatHistoSecZ = TH2D('heatHistoSecZ', 'RICH' + str(self.whichRich) + ' Secondary mirrors local Z rotation (mrad)', 4, -1, 1, 4, -1, 1)
+            numbersHistoPri = TH2D('numbersHistoPri', 'RICH' + str(self.whichRich) + ' Primary mirror numbers', 2, -1, 1, 2, -1, 1)
+            numbersHistoSec = TH2D('numbersHistoSec', 'RICH' + str(self.whichRich) + ' Secondary mirror numbers', 4, -1, 1, 4, -1, 1)
+            
         if (self.whichRich == 2):
             heatHistoPriY = TH2D('heatHistoPriY', 'RICH' + str(self.whichRich) + ' Primary mirrors local Y rotation (mrad)', 8, -1, 1, 7, -1, 1)
             heatHistoPriZ = TH2D('heatHistoPriZ', 'RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation (mrad)', 8, -1, 1, 7, -1, 1)
             heatHistoSecY = TH2D('heatHistoSecY', 'RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation (mrad)', 8, -1, 1, 5, -1, 1)
             heatHistoSecZ = TH2D('heatHistoSecZ', 'RICH' + str(self.whichRich) + ' Secondary mirrors local Z rotation (mrad)', 8, -1, 1, 5, -1, 1)        
+            numbersHistoPri = TH2D('numbersHistoPri', 'RICH' + str(self.whichRich) + ' Primary mirror numbers', 8, -1, 1, 7, -1, 1)
+            numbersHistoSec = TH2D('numbersHistoSec', 'RICH' + str(self.whichRich) + ' Secondary mirror numbers', 8, -1, 1, 5, -1, 1)
         
         xTitle = 'relative global X position (not to scale)'
         yTitle = 'relative global Y position (not to scale)'
@@ -99,18 +106,23 @@ class AlignSummary:
         heatHistoPriZ.SetXTitle(xTitle)
         heatHistoPriZ.SetYTitle(yTitle)     
         heatHistoSecZ.SetXTitle(xTitle) 
-        heatHistoSecZ.SetYTitle(yTitle) 
+        heatHistoSecZ.SetYTitle(yTitle)
+        numbersHistoPri.SetXTitle(xTitle)
+        numbersHistoPri.SetYTitle(yTitle)
+        numbersHistoSec.SetXTitle(xTitle)
+        numbersHistoSec.SetYTitle(yTitle)
 
         heatHistoPriY.SetMarkerSize(2.0*heatHistoPriY.GetMarkerSize())
         heatHistoPriZ.SetMarkerSize(2.0*heatHistoPriZ.GetMarkerSize())
         heatHistoSecY.SetMarkerSize(2.0*heatHistoSecY.GetMarkerSize())
         heatHistoSecZ.SetMarkerSize(2.0*heatHistoSecZ.GetMarkerSize())
+        numbersHistoPri.SetMarkerSize(1.0*heatHistoPriY.GetMarkerSize())
+        numbersHistoSec.SetMarkerSize(1.0*heatHistoPriY.GetMarkerSize())
 
-        # Color scheme before 2017 June 19
-        #self.colorsLow  = [923,921,0,390,622,624,627,631,636,635,634,633,632,807,797,800,400,416]
-        #self.colorsHigh = [416,432,867,857,600,616,617,618,619,620,615,611,608,606,590,920,922,1]
-
-        # Improved Color scheme
+        # Flexible Range Color scheme before 2017 June 19
+        #   self.colorsLow  = [923,921,0,390,622,624,627,631,636,635,634,633,632,807,797,800,400,416]
+        #   self.colorsHigh = [416,432,867,857,600,616,617,618,619,620,615,611,608,606,590,920,922,1]
+        # Flexible Range Improved Color scheme after 2017 June 19
         # 634 = kRed + 2
         # 632 = kRed
         # 797 = kOrange - 3
@@ -124,21 +136,30 @@ class AlignSummary:
         self.colorsLow  += [602,602,602,602,602,602,602,602,602,602,602,602,602,602,600,857,867,416]
         self.colorsHigh  = [416,400,797,632,634,634,634,634,634,634,634,634,634,634,634,634,634,634]
         self.colorsHigh += [634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634]
-        
         colorsList = self.colorsLow + self.colorsHigh
-               
+######### Fixed Range Color scheme 
+        if self.alignConf.getProp('displayMode') == 0: 
+            colorsList = [602,600,857,867,416,416,400,797,632,634] 
+
+        # We need to get a mechanism to get the stopTolerances used if stopToleranceMode is 0
+        # The best option, for consistency, is to calculate them in 
+        #    RichMirrCombinFit and/or RichMirrAlign, then print them to a file and
+        #    pick them up in RichMirrAlign and/or RichMirrorAlignmentOnline (via setProp).
+        # For now, we just use the stopTolerances from the Configuration in all cases.
         self.sTPY = float(self.alignConf.getProp('stopTolerancePriY'))
         self.sTPZ = float(self.alignConf.getProp('stopTolerancePriZ'))
         self.sTSY = float(self.alignConf.getProp('stopToleranceSecY'))
         self.sTSZ = float(self.alignConf.getProp('stopToleranceSecZ'))
-
         biggestTilt = [None] * (self.maxIt + 1)
 
         for its in reversed(range(0, self.maxIt + 1)):
+        # Compensations Histograms
             heatHistoPriY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Y rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded}' )
             heatHistoPriZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded}' )
             heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded}' )
             heatHistoSecZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Z rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded}' )
+            numbersHistoPri.SetTitle('RICH' + str(self.whichRich) + ' Primary mirror numbers')
+            numbersHistoSec.SetTitle('RICH' + str(self.whichRich) + ' Secondary mirror numbers')
             
             # sets priYtrunc, etc... otherwise these will be empty
             mirrtilts[its].setTrunc()
@@ -150,6 +171,7 @@ class AlignSummary:
                     #truncated, not rounded
                     heatHistoPriY.SetBinContent(col+1, row+1, mirrtilts[its].priYtrunc[self.binToPriMirr[row][col]]) 
                     heatHistoPriZ.SetBinContent(col+1, row+1, mirrtilts[its].priZtrunc[self.binToPriMirr[row][col]])
+                    numbersHistoPri.SetBinContent(col+1, row+1, self.binToPriMirr[row][col])
     
             rowsSec = len(self.binToSecMirr)
             colsSec = len(self.binToSecMirr[0])
@@ -158,58 +180,48 @@ class AlignSummary:
                     #truncated, not rounded
                     heatHistoSecY.SetBinContent(col+1, row+1, mirrtilts[its].secYtrunc[self.binToSecMirr[row][col]])
                     heatHistoSecZ.SetBinContent(col+1, row+1, mirrtilts[its].secZtrunc[self.binToSecMirr[row][col]])
+                    numbersHistoSec.SetBinContent(col+1, row+1, self.binToSecMirr[row][col])
 
             # Get the maximum tilt in any plot, this lets us set the scales only as relevant, 
             #   and in a controlled manner across all possible mirrors and tilts.    
             biggestTilt[its] = mirrtilts[its].getAbsMax() 
-                     
-            if int(self.alignConf.getProp('stopToleranceMode')) == 1:
-                for n in reversed(range(0,35)):
-                    if biggestTilt[its][0] > n*self.sTPY or biggestTilt[its][1] > n*self.sTPZ or biggestTilt[its][2] > n*self.sTSY or biggestTilt[its][3] > n*self.sTSZ:
-                        break
-                heatHistoPriY.GetZaxis().SetRangeUser((n+2)*(0-self.sTPY), (n+2)*(self.sTPY))
-                heatHistoPriZ.GetZaxis().SetRangeUser((n+2)*(0-self.sTPZ), (n+2)*(self.sTPZ))
-                heatHistoSecY.GetZaxis().SetRangeUser((n+2)*(0-self.sTSY), (n+2)*(self.sTSY))
-                heatHistoSecZ.GetZaxis().SetRangeUser((n+2)*(0-self.sTSZ), (n+2)*(self.sTSZ))
-                colorsLowClone = list(self.colorsLow)
-                colorsLowClone.reverse()
-                colorsLowSubset = list(colorsLowClone[0:n+2])
-                colorsLowSubset.reverse()
-                colorsList = list(colorsLowSubset + self.colorsHigh[0:n+2])
-                levelsPY = []
-                levelsPZ = []
-                levelsSY = []
-                levelsSZ = []             
-                for i in range(-(n+2),(n+2)+1):
-                    levelsPY += [i*self.sTPY]
-                    levelsPZ += [i*self.sTPZ]
-                    levelsSY += [i*self.sTSY]
-                    levelsSZ += [i*self.sTSZ]
-            else:
-                 # for now this is OK, however it is wrong to rely on the values of the stop tolerances in the configuration file, since those are not actually being used
-                heatHistoPriY.GetZaxis().SetRangeUser(-36*self.sTPY, 36*self.sTPY) # Eventually we will have to extract these tolerances from RichMirrAlign
-                heatHistoPriZ.GetZaxis().SetRangeUser(-36*self.sTPZ, 36*self.sTPZ) # Eventually we will have to extract these tolerances from RichMirrAlign
-                heatHistoSecY.GetZaxis().SetRangeUser(-36*self.sTSY, 36*self.sTSY) # Eventually we will have to extract these tolerances from RichMirrAlign
-                heatHistoSecZ.GetZaxis().SetRangeUser(-36*self.sTSZ, 36*self.sTSZ) # Eventually we will have to extract these tolerances from RichMirrAlign
-                levelsPY = []
-                levelsPZ = []
-                levelsSY = []
-                levelsSZ = []         
-                for i in range(-(36),(36)+1):
-                    levelsPY += [i*self.sTPY]
-                    levelsPZ += [i*self.sTPZ]
-                    levelsSY += [i*self.sTSY]
-                    levelsSZ += [i*self.sTSZ]  
-
-            gStyle.SetPalette(len(list(colorsList)), numpy.array(list(colorsList), dtype = 'intc'))
             
+            # Original plotting choice
+            for n in reversed(range(0,35)):
+                if biggestTilt[its][0] > n*self.sTPY or biggestTilt[its][1] > n*self.sTPZ or biggestTilt[its][2] > n*self.sTSY or biggestTilt[its][3] > n*self.sTSZ:
+                    break
+#           heatHistoPriY.GetZaxis().SetRangeUser(-36*self.sTPY, 36*self.sTPY)
+            heatHistoPriY.GetZaxis().SetRangeUser((n+2)*(0-self.sTPY), (n+2)*(self.sTPY))
+            heatHistoPriZ.GetZaxis().SetRangeUser((n+2)*(0-self.sTPZ), (n+2)*(self.sTPZ))
+            heatHistoSecY.GetZaxis().SetRangeUser((n+2)*(0-self.sTSY), (n+2)*(self.sTSY))
+            heatHistoSecZ.GetZaxis().SetRangeUser((n+2)*(0-self.sTSZ), (n+2)*(self.sTSZ))
+            colorsLowClone = list(self.colorsLow)
+            colorsLowClone.reverse()
+            colorsLowSubset = list(colorsLowClone[0:n+2])
+            colorsLowSubset.reverse()
+            colorsList = list(colorsLowSubset + self.colorsHigh[0:n+2])
+            levelsPY = []
+            levelsPZ = []
+            levelsSY = []
+            levelsSZ = []
+#           for i in range(-(36),(36)+1):
+            for i in range(-(n+2),(n+2)+1):
+                levelsPY += [i*self.sTPY]
+                levelsPZ += [i*self.sTPZ]
+                levelsSY += [i*self.sTSY]
+                levelsSZ += [i*self.sTSZ]
+            gStyle.SetPalette(len(list(colorsList)), numpy.array(list(colorsList), dtype = 'intc'))
             heatHistoPriY.SetContour(len(list(levelsPY)), numpy.array(list(levelsPY), dtype = 'float64'))
             heatHistoPriZ.SetContour(len(list(levelsPZ)), numpy.array(list(levelsPZ), dtype = 'float64'))
             heatHistoSecY.SetContour(len(list(levelsSY)), numpy.array(list(levelsSY), dtype = 'float64'))
             heatHistoSecZ.SetContour(len(list(levelsSZ)), numpy.array(list(levelsSZ), dtype = 'float64'))
-
             gStyle.SetPaintTextFormat('4.2f') # formerly 5.3f
 
+############# Anatoly's plotting choices here
+            if self.alignConf.getProp('displayMode') == 0: 
+                # Change the plotting style
+                pass
+
             cPlot.cd(1)
             heatHistoPriY.Draw("COLZ")
             heatHistoPriY.Draw("TEXT SAME")
@@ -224,8 +236,7 @@ class AlignSummary:
             heatHistoSecZ.Draw("TEXT SAME")
             cPlot.Print(saveName + '(')
 
-            #dPlot 
-            
+        # Compensations-divided-by-tolerances Histograms
             heatHistoPriY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Y rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded}' )
             heatHistoPriZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded}' )
             heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded}' )
@@ -250,44 +261,34 @@ class AlignSummary:
                     heatHistoSecY.SetBinContent(col+1, row+1, mirrtilts[its].secYdiv[self.binToSecMirr[row][col]])
                     heatHistoSecZ.SetBinContent(col+1, row+1, mirrtilts[its].secZdiv[self.binToSecMirr[row][col]])
 
-            if int(self.alignConf.getProp('stopToleranceMode')) == 1:
-                # steal n from previous loop, the palette is also already set.
-                heatHistoPriY.GetZaxis().SetRangeUser((n+2)*(0-1), (n+2)*(1))
-                heatHistoPriZ.GetZaxis().SetRangeUser((n+2)*(0-1), (n+2)*(1))
-                heatHistoSecY.GetZaxis().SetRangeUser((n+2)*(0-1), (n+2)*(1))
-                heatHistoSecZ.GetZaxis().SetRangeUser((n+2)*(0-1), (n+2)*(1))
-                levelsPY = []
-                levelsPZ = []
-                levelsSY = []
-                levelsSZ = []              
-                for i in range(-(n+2),(n+2)+1):
-                    levelsPY += [i*1]
-                    levelsPZ += [i*1]
-                    levelsSY += [i*1]
-                    levelsSZ += [i*1]
-            else:
-                 # for now this is OK, however it is wrong to rely on the values of the stop tolerances in the configuration file, since those are not actually being used
-                heatHistoPriY.GetZaxis().SetRangeUser(-36*1, 36*1) # Eventually we will have to extract these tolerances from RichMirrAlign
-                heatHistoPriZ.GetZaxis().SetRangeUser(-36*1, 36*1) # Eventually we will have to extract these tolerances from RichMirrAlign
-                heatHistoSecY.GetZaxis().SetRangeUser(-36*1, 36*1) # Eventually we will have to extract these tolerances from RichMirrAlign
-                heatHistoSecZ.GetZaxis().SetRangeUser(-36*1, 36*1) # Eventually we will have to extract these tolerances from RichMirrAlign
-                levelsPY = []
-                levelsPZ = []
-                levelsSY = []
-                levelsSZ = []    
-                for i in range(-(36),(36)+1):
-                    levelsPY += [i*1]
-                    levelsPZ += [i*1]
-                    levelsSY += [i*1]
-                    levelsSZ += [i*1]
+            # steal n from previous loop, the color palette is also already set.
+#           heatHistoPriY.GetZaxis().SetRangeUser(-36*1, 36*1) # Eventually we will have to extract these tolerances from RichMirrAlign
+            heatHistoPriY.GetZaxis().SetRangeUser((n+2)*(0-1), (n+2)*(1))
+            heatHistoPriZ.GetZaxis().SetRangeUser((n+2)*(0-1), (n+2)*(1))
+            heatHistoSecY.GetZaxis().SetRangeUser((n+2)*(0-1), (n+2)*(1))
+            heatHistoSecZ.GetZaxis().SetRangeUser((n+2)*(0-1), (n+2)*(1))
+            levelsPY = []
+            levelsPZ = []
+            levelsSY = []
+            levelsSZ = []           
+#           for i in range(-(36),(36)+1):
+            for i in range(-(n+2),(n+2)+1):
+                levelsPY += [i*1]
+                levelsPZ += [i*1]
+                levelsSY += [i*1]
+                levelsSZ += [i*1]
 
             heatHistoPriY.SetContour(len(list(levelsPY)), numpy.array(list(levelsPY), dtype = 'float64'))
             heatHistoPriZ.SetContour(len(list(levelsPZ)), numpy.array(list(levelsPZ), dtype = 'float64'))
             heatHistoSecY.SetContour(len(list(levelsSY)), numpy.array(list(levelsSY), dtype = 'float64'))
-            heatHistoSecZ.SetContour(len(list(levelsSZ)), numpy.array(list(levelsSZ), dtype = 'float64'))
-            
+            heatHistoSecZ.SetContour(len(list(levelsSZ)), numpy.array(list(levelsSZ), dtype = 'float64'))        
             gStyle.SetPaintTextFormat('2.0f')
             
+############# Anatoly's plotting choices here
+            if self.alignConf.getProp('displayMode') == 0: 
+                # Change the plotting style
+                pass
+            
             dPlot.cd(1)
             heatHistoPriY.Draw("COLZ")
             heatHistoPriY.Draw("TEXT SAME")
@@ -333,6 +334,8 @@ class AlignSummary:
             cPlot.Divide(3,3,0.0025,0.0025)
         else:
             cPlot.Divide(4,4,0.0025,0.0025)
+        
+######### End of 2D histos section
             
         # reserve spaces for resHistograms      
         resHistograms = [None] * (self.maxIt + 1) 
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index a0d03206a..a06709494 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -82,7 +82,7 @@ class SetupHelper:
 
         from AlignSummary import AlignSummary
         alignSummary = AlignSummary(self.alignConf, n_it)
-        alignSummary.makeSummaryPlot(compareXML)
+        alignSummary.performMonitoring(compareXML)
 
         ChangeWRTDBFile  = self.workdir + "/Rich" + str(self.whichRich) + '_ChangeWRTDB_'+ str(n_it + 1) +'.txt'
         shutil.copy2(ChangeWRTDBFile, self.savedir)
-- 
GitLab


From 42f2bee9e7d88ada6f4758b1a10c9514bcd60bad Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@bristol.ac.uk>
Date: Sat, 24 Jun 2017 13:59:57 +0000
Subject: [PATCH 08/59] Update AlignSummary.py

---
 .../python/PyMirrAlignOnline/{AlignSummary.py => AlignMonitor.py} | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/{AlignSummary.py => AlignMonitor.py} (100%)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignSummary.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
similarity index 100%
rename from Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignSummary.py
rename to Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
-- 
GitLab


From 84976b90baf2ff0627e9948da29b3a8adabc3be4 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Sat, 24 Jun 2017 16:11:51 +0200
Subject: [PATCH 09/59] Renamed AlignSummary.py to AlignMonitor.py, and changed
 things in SetupHelper.py accordingly.

---
 .../python/PyMirrAlignOnline/AlignMonitor.py                | 2 +-
 .../python/PyMirrAlignOnline/SetupHelper.py                 | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 9dc58e37d..972920f0b 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -3,7 +3,7 @@
 import sys, numpy
 from ROOT import TH1D, TCanvas, TFile, TF1, gStyle, TGraph, TMultiGraph, TLine, TH2D
 
-class AlignSummary:
+class AlignMonitor:
     def __init__(self, _alignConf, _maxIt, ):
         self.alignConf = _alignConf
         self.nameStr = self.alignConf.getProp('nameStr')
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index a06709494..070ac59af 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -80,9 +80,9 @@ class SetupHelper:
 
         shutil.copy2(summaryFile, self.savedir)
 
-        from AlignSummary import AlignSummary
-        alignSummary = AlignSummary(self.alignConf, n_it)
-        alignSummary.performMonitoring(compareXML)
+        from AlignMonitor import AlignMonitor
+        alignMonitor = AlignMonitor(self.alignConf, n_it)
+        alignMonitor.performMonitoring(compareXML)
 
         ChangeWRTDBFile  = self.workdir + "/Rich" + str(self.whichRich) + '_ChangeWRTDB_'+ str(n_it + 1) +'.txt'
         shutil.copy2(ChangeWRTDBFile, self.savedir)
-- 
GitLab


From 9841497928f1a890a4a09cfb67fb5da796161222 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Sat, 24 Jun 2017 16:17:43 +0200
Subject: [PATCH 10/59] typo fix

---
 .../python/RichMirrorAlignmentOnline/Configuration.py         | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py
index 46c02f3ab..1e36f0e5d 100644
--- a/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py
+++ b/Rich/RichMirrorAlignmentOnline/python/RichMirrorAlignmentOnline/Configuration.py
@@ -124,7 +124,7 @@ class Rich1MirrAlignOnConf(LHCbConfigurableUser):
        ,"dataVariant"            : """ Helps us decide which Brunel options to use; also used for the naming convention. """
        ,"fixSinusoidShift"       : """ 1 : fix at sinusoidShift; 0 : it is not fixed """
        ,"nameStr"                : """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """
-       ,"displayMode"            : """ 1 : Curent TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)"""
+       ,"displayMode"            : """ 1 : Current TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)"""
         }
 
     def setNameStr(self):
@@ -258,7 +258,7 @@ class Rich2MirrAlignOnConf(LHCbConfigurableUser):
        ,"dataVariant"            : """ Helps us decide which Brunel options to use; also used for the naming convention. """
        ,"fixSinusoidShift"       : """ 1 : fix at sinusoidShift; 0 : it is not fixed """
        ,"nameStr"                : """ Right now this is used only for the naming convention, but will be set when initiating the Configuration. """
-       ,"displayMode"            : """ 1 : Curent TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)"""
+       ,"displayMode"            : """ 1 : Current TH2D display style (auto-scaling Z-axis, granular colors, using same colors for > 4*threshold); 0: Anatoly's development TH2D display style (similar, but with printed mirror number also, and fixed scale)"""
         }
 
     ### Dont mess with this filename!!!
-- 
GitLab


From fa57693e0a3b822230ff7f67396938d9570b60e3 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Sat, 24 Jun 2017 19:13:14 +0200
Subject: [PATCH 11/59] Prepare code further for Anatoly to introduce second 2D
 Histo plotting style

---
 .../python/PyMirrAlignOnline/AlignMonitor.py  | 189 +++++++++++-------
 1 file changed, 114 insertions(+), 75 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 972920f0b..49f6a068b 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -9,21 +9,21 @@ class AlignMonitor:
         self.nameStr = self.alignConf.getProp('nameStr')
         self.whichRich = self.alignConf.getProp('Rich')
         self.workdir = self.alignConf.getProp('WorkDir')
+        self.displayMode = self.alignConf.getProp('displayMode')
         self.maxIt = _maxIt # the maximum labeled number of the iterations that we are looping through
-        self.prename =  "RichRecQCHistos_rich" + str(self.whichRich) + "_" + self.nameStr + "_"
-        self.fitMin = -0.007 # default: RICH1
-        self.fitMax = 0.007 # default: RICH1
-        if (self.whichRich == 2):
-            self.fitMin = -0.0039
-            self.fitMax = 0.0035
-        self.maxpri = 3 # default: RICH1
+        self.prename = "RichRecQCHistos_rich" + str(self.whichRich) + "_" + self.nameStr + "_"
+        # RICH1 settings
+        self.maxpri = 3
         self.binToPriMirr = [[2,3],
                              [0,1]]
-        self.maxsec = 15 # default: RICH1
+        self.maxsec = 15
         self.binToSecMirr = [[10,11,14,15],
                              [8,9,12,13],
                              [2,3,6,7],
                              [0,1,4,5]]
+        self.fitMin = -0.007
+        self.fitMax = 0.007
+        # if RICH2, use RICH2 settings
         if (self.whichRich == 2):
             self.maxpri = 55
             self.binToPriMirr = [[3,2,1,0,31,30,29,28],
@@ -39,10 +39,10 @@ class AlignMonitor:
                                  [11,10,9,8,31,30,29,28],
                                  [15,14,13,12,35,34,33,32],
                                  [19,18,17,16,39,38,37,36]]
+            self.fitMin = -0.0039
+            self.fitMax = 0.0035
             
-        # Initialize Monitoring Job "Sender" to send plots to the presenter
-        # The Monitoring Job "Saver" is part of a monitoring script by Giulio Dujany
-        #   This monitoring script is always being run at the pit by the Alignment group
+        # Initialize the Monitoring Job "Sender" to send plots to the presenter
         from Configurables import MonitoringJob
         from Monitoring.MonitoringJob import start
         self.mj = MonitoringJob()
@@ -54,21 +54,27 @@ class AlignMonitor:
         self.monitoring_folder = 'MoniOnlineAligRich' + str(self.whichRich)
         print "INFO: monitoring_folder = " + self.monitoring_folder
         sys.stdout.flush()
+        # The Monitoring Job "Saver" is part of a monitoring script by Giulio Dujany (elsewhere)
+        #   That monitoring script is always being run at the pit by the Alignment group
     
     def performMonitoring(self, compareXML):
         import os
         gStyle.SetOptFit(1111)
         gStyle.SetOptStat(000000000)
-                
-        saveName   = self.workdir + 'Rich' + str(self.whichRich) + '_AlignSummary.pdf'
-        saveNameDM = self.workdir + 'Rich' + str(self.whichRich) + '_AlignMonitor.pdf'
-        saveNameA  = self.workdir + 'Rich' + str(self.whichRich) + '_AlignAnatoly.pdf'
+
+        # File for the RICH piquet
+        piquetFile   = self.workdir + 'Rich' + str(self.whichRich) + '_AlignSummary.pdf'
+        # File with additional plots for the RICH mirror alignment experts
+        expertFile = self.workdir + 'Rich' + str(self.whichRich) + '_AlignMonitor.pdf'
+        # File with for testing purposes
+        testingFile = self.workdir + 'Rich' + str(self.whichRich) + '_AlignTesting.pdf'
+        # Data Manager can only get histograms sent via self.monSvc
         
-        cPlot = TCanvas('cPlot', 'AlignExpert')
-        cPlot.Divide(2,2,0.001,0.001)
+        theCanvas = TCanvas('theCanvas', 'MirrAlign')
+        theCanvas.Divide(2,2,0.001,0.001)
         
-        dPlot = TCanvas('dPlot', 'AlignDM')
-        dPlot.Divide(2,2,0.001,0.001)
+        testCanvas = TCanvas('testCanvas', 'MirrAlignTest')
+        testCanvas.Divide(2,2,0.001,0.001)
 
 ######### Start of 2D histos section
         # heatHistos
@@ -136,10 +142,12 @@ class AlignMonitor:
         self.colorsLow  += [602,602,602,602,602,602,602,602,602,602,602,602,602,602,600,857,867,416]
         self.colorsHigh  = [416,400,797,632,634,634,634,634,634,634,634,634,634,634,634,634,634,634]
         self.colorsHigh += [634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634,634]
-        colorsList = self.colorsLow + self.colorsHigh
+        colorsListFlex = self.colorsLow + self.colorsHigh
 ######### Fixed Range Color scheme 
-        if self.alignConf.getProp('displayMode') == 0: 
-            colorsList = [602,600,857,867,416,416,400,797,632,634] 
+        if self.displayMode == 0: 
+            # Anatoly, define your color palette here, then there are places for you to set your style below.
+            colorsListFixed = [602,600,857,867,416,416,400,797,632,634] 
+#########
 
         # We need to get a mechanism to get the stopTolerances used if stopToleranceMode is 0
         # The best option, for consistency, is to calculate them in 
@@ -158,6 +166,7 @@ class AlignMonitor:
             heatHistoPriZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded}' )
             heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded}' )
             heatHistoSecZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Z rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded}' )
+            # Histograms that contain only the mirror numbers
             numbersHistoPri.SetTitle('RICH' + str(self.whichRich) + ' Primary mirror numbers')
             numbersHistoSec.SetTitle('RICH' + str(self.whichRich) + ' Secondary mirror numbers')
             
@@ -186,11 +195,11 @@ class AlignMonitor:
             #   and in a controlled manner across all possible mirrors and tilts.    
             biggestTilt[its] = mirrtilts[its].getAbsMax() 
             
-            # Original plotting choice
+            # Flexible range plotting style
             for n in reversed(range(0,35)):
                 if biggestTilt[its][0] > n*self.sTPY or biggestTilt[its][1] > n*self.sTPZ or biggestTilt[its][2] > n*self.sTSY or biggestTilt[its][3] > n*self.sTSZ:
                     break
-#           heatHistoPriY.GetZaxis().SetRangeUser(-36*self.sTPY, 36*self.sTPY)
+            # max: heatHistoPriY.GetZaxis().SetRangeUser(-36*self.sTPY, 36*self.sTPY)
             heatHistoPriY.GetZaxis().SetRangeUser((n+2)*(0-self.sTPY), (n+2)*(self.sTPY))
             heatHistoPriZ.GetZaxis().SetRangeUser((n+2)*(0-self.sTPZ), (n+2)*(self.sTPZ))
             heatHistoSecY.GetZaxis().SetRangeUser((n+2)*(0-self.sTSY), (n+2)*(self.sTSY))
@@ -199,42 +208,57 @@ class AlignMonitor:
             colorsLowClone.reverse()
             colorsLowSubset = list(colorsLowClone[0:n+2])
             colorsLowSubset.reverse()
-            colorsList = list(colorsLowSubset + self.colorsHigh[0:n+2])
+            colorsListFlex = list(colorsLowSubset + self.colorsHigh[0:n+2])
             levelsPY = []
             levelsPZ = []
             levelsSY = []
             levelsSZ = []
-#           for i in range(-(36),(36)+1):
+            # max: for i in range(-(36),(36)+1):
             for i in range(-(n+2),(n+2)+1):
                 levelsPY += [i*self.sTPY]
                 levelsPZ += [i*self.sTPZ]
                 levelsSY += [i*self.sTSY]
                 levelsSZ += [i*self.sTSZ]
-            gStyle.SetPalette(len(list(colorsList)), numpy.array(list(colorsList), dtype = 'intc'))
+            gStyle.SetPalette(len(list(colorsListFlex)), numpy.array(list(colorsListFlex), dtype = 'intc'))
             heatHistoPriY.SetContour(len(list(levelsPY)), numpy.array(list(levelsPY), dtype = 'float64'))
             heatHistoPriZ.SetContour(len(list(levelsPZ)), numpy.array(list(levelsPZ), dtype = 'float64'))
             heatHistoSecY.SetContour(len(list(levelsSY)), numpy.array(list(levelsSY), dtype = 'float64'))
             heatHistoSecZ.SetContour(len(list(levelsSZ)), numpy.array(list(levelsSZ), dtype = 'float64'))
             gStyle.SetPaintTextFormat('4.2f') # formerly 5.3f
 
-############# Anatoly's plotting choices here
-            if self.alignConf.getProp('displayMode') == 0: 
-                # Change the plotting style
-                pass
-
-            cPlot.cd(1)
+            theCanvas.cd(1)
             heatHistoPriY.Draw("COLZ")
             heatHistoPriY.Draw("TEXT SAME")
-            cPlot.cd(2)
+            theCanvas.cd(2)
             heatHistoPriZ.Draw("COLZ")
             heatHistoPriZ.Draw("TEXT SAME")
-            cPlot.cd(3)
+            theCanvas.cd(3)
             heatHistoSecY.Draw("COLZ")
             heatHistoSecY.Draw("TEXT SAME")
-            cPlot.cd(4)
+            theCanvas.cd(4)
             heatHistoSecZ.Draw("COLZ")
             heatHistoSecZ.Draw("TEXT SAME")
-            cPlot.Print(saveName + '(')
+            theCanvas.Print(expertFile + '(')
+            
+############# Fixed range plotting style (testing)
+            if self.displayMode == 0: 
+                # Anatoly, change the plotting styles here only (but define colorsListFixed above)
+                
+                # Print to testing file
+                testCanvas.cd(1)
+                heatHistoPriY.Draw("COLZ")
+                heatHistoPriY.Draw("TEXT SAME")
+                testCanvas.cd(2)
+                heatHistoPriZ.Draw("COLZ")
+                heatHistoPriZ.Draw("TEXT SAME")
+                testCanvas.cd(3)
+                heatHistoSecY.Draw("COLZ")
+                heatHistoSecY.Draw("TEXT SAME")
+                testCanvas.cd(4)
+                heatHistoSecZ.Draw("COLZ")
+                heatHistoSecZ.Draw("TEXT SAME")
+                testCanvas.Print(testingFile + '(')
+#############
 
         # Compensations-divided-by-tolerances Histograms
             heatHistoPriY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Y rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded}' )
@@ -261,8 +285,9 @@ class AlignMonitor:
                     heatHistoSecY.SetBinContent(col+1, row+1, mirrtilts[its].secYdiv[self.binToSecMirr[row][col]])
                     heatHistoSecZ.SetBinContent(col+1, row+1, mirrtilts[its].secZdiv[self.binToSecMirr[row][col]])
 
+            # Flexible range plotting style
             # steal n from previous loop, the color palette is also already set.
-#           heatHistoPriY.GetZaxis().SetRangeUser(-36*1, 36*1) # Eventually we will have to extract these tolerances from RichMirrAlign
+            # max: heatHistoPriY.GetZaxis().SetRangeUser(-36*1, 36*1)
             heatHistoPriY.GetZaxis().SetRangeUser((n+2)*(0-1), (n+2)*(1))
             heatHistoPriZ.GetZaxis().SetRangeUser((n+2)*(0-1), (n+2)*(1))
             heatHistoSecY.GetZaxis().SetRangeUser((n+2)*(0-1), (n+2)*(1))
@@ -271,38 +296,32 @@ class AlignMonitor:
             levelsPZ = []
             levelsSY = []
             levelsSZ = []           
-#           for i in range(-(36),(36)+1):
+            #max: for i in range(-(36),(36)+1):
             for i in range(-(n+2),(n+2)+1):
                 levelsPY += [i*1]
                 levelsPZ += [i*1]
                 levelsSY += [i*1]
                 levelsSZ += [i*1]
-
             heatHistoPriY.SetContour(len(list(levelsPY)), numpy.array(list(levelsPY), dtype = 'float64'))
             heatHistoPriZ.SetContour(len(list(levelsPZ)), numpy.array(list(levelsPZ), dtype = 'float64'))
             heatHistoSecY.SetContour(len(list(levelsSY)), numpy.array(list(levelsSY), dtype = 'float64'))
             heatHistoSecZ.SetContour(len(list(levelsSZ)), numpy.array(list(levelsSZ), dtype = 'float64'))        
             gStyle.SetPaintTextFormat('2.0f')
             
-############# Anatoly's plotting choices here
-            if self.alignConf.getProp('displayMode') == 0: 
-                # Change the plotting style
-                pass
-            
-            dPlot.cd(1)
+            theCanvas.cd(1)
             heatHistoPriY.Draw("COLZ")
             heatHistoPriY.Draw("TEXT SAME")
-            dPlot.cd(2)
+            theCanvas.cd(2)
             heatHistoPriZ.Draw("COLZ")
             heatHistoPriZ.Draw("TEXT SAME")
-            dPlot.cd(3)
+            theCanvas.cd(3)
             heatHistoSecY.Draw("COLZ")
             heatHistoSecY.Draw("TEXT SAME")
-            dPlot.cd(4)
+            theCanvas.cd(4)
             heatHistoSecZ.Draw("COLZ")
             heatHistoSecZ.Draw("TEXT SAME")
-            dPlot.Print(saveNameDM + '(')
-            
+            theCanvas.Print(piquetFile + '(')
+
             if its == self.maxIt:
                 self.monSvc.publishHistogram(self.monitoring_folder, heatHistoPriY.Clone(), add=False)
                 print "INFO: heatHistoPriY sent to Monitoring."
@@ -314,29 +333,50 @@ class AlignMonitor:
                 print "INFO: heatHistoSecZ sent to Monitoring."
                 sys.stdout.flush()
 
-        # resHistograms           
-        dPlot.Clear()
-        cPlot.Clear()
+############# Fixed range plotting style (testing)
+            if self.displayMode == 0: 
+                # Anatoly, change the plotting styles here only (but define colorsListFixed above)
+                
+                # Print to testing file
+                testCanvas.cd(1)
+                heatHistoPriY.Draw("COLZ")
+                heatHistoPriY.Draw("TEXT SAME")
+                testCanvas.cd(2)
+                heatHistoPriZ.Draw("COLZ")
+                heatHistoPriZ.Draw("TEXT SAME")
+                testCanvas.cd(3)
+                heatHistoSecY.Draw("COLZ")
+                heatHistoSecY.Draw("TEXT SAME")
+                testCanvas.cd(4)
+                heatHistoSecZ.Draw("COLZ")
+                heatHistoSecZ.Draw("TEXT SAME")
+                testCanvas.Print(testingFile + ')')
+#############
+
+        # End of 2D histos section #############
+
+        testCanvas.Clear()
+        theCanvas.Clear()
+        
+        # generate resHistograms           
         
         if self.maxIt == 0:
             pass
         elif self.maxIt < 2:
-            cPlot.Divide(2,1,0.0025,0.0025)
+            theCanvas.Divide(2,1,0.0025,0.0025)
         elif self.maxIt < 3:
-            cPlot.Divide(3,1,0.0025,0.0025)       
+            theCanvas.Divide(3,1,0.0025,0.0025)       
         elif self.maxIt < 4:
-            cPlot.Divide(2,2,0.0025,0.0025)    
+            theCanvas.Divide(2,2,0.0025,0.0025)    
         elif self.maxIt < 6:
-            cPlot.Divide(3,2,0.0025,0.0025)     
+            theCanvas.Divide(3,2,0.0025,0.0025)     
         elif self.maxIt < 8:
-            cPlot.Divide(4,2,0.0025,0.0025)  
+            theCanvas.Divide(4,2,0.0025,0.0025)  
         elif self.maxIt < 9:
-            cPlot.Divide(3,3,0.0025,0.0025)
+            theCanvas.Divide(3,3,0.0025,0.0025)
         else:
-            cPlot.Divide(4,4,0.0025,0.0025)
-        
-######### End of 2D histos section
-            
+            theCanvas.Divide(4,4,0.0025,0.0025)
+                    
         # reserve spaces for resHistograms      
         resHistograms = [None] * (self.maxIt + 1) 
         polbkg = [None] * (self.maxIt + 1)
@@ -391,12 +431,12 @@ class AlignMonitor:
                 polbkg[j].SetParameter(3, histFunc[j].GetParameter(6))
                 polbkg[j].SetLineColor(4)
                 
-                cPlot.cd(j+1)                      
+                theCanvas.cd(j+1)                      
                 resHistograms[j].Draw()
                 polbkg[j].Draw("SAME")   
             
-        cPlot.Print(saveName)
-        cPlot.Print(saveNameDM)
+        theCanvas.Print(piquetFile)
+        #theCanvas.Print(expertFile)
         
         sys.stdout.flush()
     
@@ -405,11 +445,10 @@ class AlignMonitor:
         resHistoTrend.SetXTitle('iteration number')
         resHistoTrend.SetYTitle('') # resHistoTrend.SetYTitle('Cherenkov angle resolution (mrad)')
         
-        cPlot.Clear()
+        theCanvas.Clear()
         resHistoTrend.DrawCopy()
-        cPlot.Print(saveName)
-#        cPlot.Print(saveNameDM)
-        cPlot.Print(saveNameDM + ')')
+        theCanvas.Print(piquetFile + ')')
+        #theCanvas.Print(expertFile)
         
         self.monSvc.publishHistogram(self.monitoring_folder, resHistoTrend.Clone(), add=False)
         print "INFO: resHistoTrend sent to Monitoring."
@@ -445,7 +484,7 @@ class AlignMonitor:
         minSecZ.SetLineStyle(21)
         
         # compensations graphs        
-        cPlot.Clear()
+        theCanvas.Clear()
         tops = self.sTPZ 
         if tops < self.sTPY: 
             tops = self.sTPY
@@ -464,9 +503,9 @@ class AlignMonitor:
         mgraphs[0].GetXaxis().SetTitle("primary mirror number")
         mgraphs[0].GetYaxis().SetTitle("change in compensation (mrad) [{red, blue}: local {Y, Z}]")
 
-        cPlot.Print(saveName)
+        theCanvas.Print(expertFile)
         
-        cPlot.Clear()
+        theCanvas.Clear()
         tops = self.sTSZ 
         if tops < self.sTSY: 
             tops = self.sTSY
@@ -485,7 +524,7 @@ class AlignMonitor:
         mgraphs[1].GetXaxis().SetTitle("secondary mirror number")
         mgraphs[1].GetYaxis().SetTitle("change in compensation (mrad) [{red, blue}: local {Y, Z}]")
 
-        cPlot.Print(saveName + ')')
+        theCanvas.Print(expertFile + ')')
         
         for its in range(0, self.maxIt + 1):
             mirrtilts[self.maxIt].writeChange(self.maxIt +  1)
-- 
GitLab


From 3c43f2e856eabf4c9287ecf0b5cbd667badf36b5 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Sat, 24 Jun 2017 19:58:37 +0200
Subject: [PATCH 12/59] 2D histograms with mirror numbers have been created and
 are sent to the presenter.

---
 .../python/PyMirrAlignOnline/AlignMonitor.py  | 21 +++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 49f6a068b..89666c1a2 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -63,9 +63,9 @@ class AlignMonitor:
         gStyle.SetOptStat(000000000)
 
         # File for the RICH piquet
-        piquetFile   = self.workdir + 'Rich' + str(self.whichRich) + '_AlignSummary.pdf'
+        piquetFile  = self.workdir + 'Rich' + str(self.whichRich) + '_AlignSummary.pdf'
         # File with additional plots for the RICH mirror alignment experts
-        expertFile = self.workdir + 'Rich' + str(self.whichRich) + '_AlignMonitor.pdf'
+        expertFile  = self.workdir + 'Rich' + str(self.whichRich) + '_AlignMonitor.pdf'
         # File with for testing purposes
         testingFile = self.workdir + 'Rich' + str(self.whichRich) + '_AlignTesting.pdf'
         # Data Manager can only get histograms sent via self.monSvc
@@ -331,6 +331,16 @@ class AlignMonitor:
                 print "INFO: heatHistoSecY sent to Monitoring."
                 self.monSvc.publishHistogram(self.monitoring_folder, heatHistoSecZ.Clone(), add=False)
                 print "INFO: heatHistoSecZ sent to Monitoring."
+                
+                self.monSvc.publishHistogram(self.monitoring_folder, numbersHistoPri.Clone("numbersHistoPriY"), add=False)
+                print "INFO: numbersHistoPriY sent to Monitoring."
+                self.monSvc.publishHistogram(self.monitoring_folder, numbersHistoPri.Clone("numbersHistoPriZ"), add=False)
+                print "INFO: numbersHistoPriZ sent to Monitoring."
+                self.monSvc.publishHistogram(self.monitoring_folder, numbersHistoSec.Clone("numbersHistoSecY"), add=False)
+                print "INFO: numbersHistoSecY sent to Monitoring."
+                self.monSvc.publishHistogram(self.monitoring_folder, numbersHistoSec.Clone("numbersHistoSecZ"), add=False)
+                print "INFO: numbersHistoSecZ sent to Monitoring."
+                
                 sys.stdout.flush()
 
 ############# Fixed range plotting style (testing)
@@ -453,7 +463,6 @@ class AlignMonitor:
         self.monSvc.publishHistogram(self.monitoring_folder, resHistoTrend.Clone(), add=False)
         print "INFO: resHistoTrend sent to Monitoring."
         sys.stdout.flush()
-        
 
         maxPriY = TLine(0, self.sTPY, self.maxpri, self.sTPY)
         minPriY = TLine(0, -self.sTPY, self.maxpri, -self.sTPY) 
@@ -532,7 +541,11 @@ class AlignMonitor:
         mgraphs[1].Delete()
 
         # Close the Monitoring Job; the histograms are now in the presenter (Page Editor Online).
-        # To adjust the histos, see 
+        # New Histograms need to be added to the Histogram Database https://lbhistogramdb.cern.ch
+        #   in order to be viewed at the pit.
+        # This database is only accessible on the CERN network (or ssh to plus, start Firefox).
+        # One can adjust the histo styles on the presenter view there, 
+        #   but not all normal ROOT options are available.
         self.gaudi.stop()
         self.gaudi.finalize()
 
-- 
GitLab


From 428af4359974431cf666c82bf0948cb4b0788bff Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Sat, 24 Jun 2017 20:09:30 +0200
Subject: [PATCH 13/59] Big DeltathetaCherenkov angle plots now made for
 experts.

---
 .../python/PyMirrAlignOnline/AlignMonitor.py          | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 89666c1a2..2679b9d80 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -440,13 +440,17 @@ class AlignMonitor:
                 polbkg[j].SetParameter(2, histFunc[j].GetParameter(5))
                 polbkg[j].SetParameter(3, histFunc[j].GetParameter(6))
                 polbkg[j].SetLineColor(4)
-                
+
+                testCanvas.cd()
+                resHistograms[j].Draw()
+                polbkg[j].Draw("SAME") 
+                testCanvas.Print(expertFile)
+
                 theCanvas.cd(j+1)                      
                 resHistograms[j].Draw()
                 polbkg[j].Draw("SAME")   
             
         theCanvas.Print(piquetFile)
-        #theCanvas.Print(expertFile)
         
         sys.stdout.flush()
     
@@ -454,7 +458,8 @@ class AlignMonitor:
         resHistoTrend.SetMarkerStyle(8)
         resHistoTrend.SetXTitle('iteration number')
         resHistoTrend.SetYTitle('') # resHistoTrend.SetYTitle('Cherenkov angle resolution (mrad)')
-        
+
+        testCanvas.Clear()
         theCanvas.Clear()
         resHistoTrend.DrawCopy()
         theCanvas.Print(piquetFile + ')')
-- 
GitLab


From e67eb1c29919e866eca695063aa948ecba4a87f8 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Sat, 24 Jun 2017 20:37:19 +0200
Subject: [PATCH 14/59] Added F and M options to hopefully now get consistent
 errors from Summary deltaTheta fits.

---
 .../python/PyMirrAlignOnline/AlignMonitor.py          | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 2679b9d80..60f3cf5e5 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -558,7 +558,7 @@ class AlignMonitor:
         richStr = 'Rich' + str(self.whichRich)
         m_maxErrorForOK = 1e-3;
         
-        xPeak = hist.GetBinCenter( hist.GetMaximumBin() )
+        xPeak = hist.GetBinCenter(hist.GetMaximumBin())
         delta = 0
         if (richStr == 'Rich1'):
             delta = 0.0025
@@ -569,8 +569,8 @@ class AlignMonitor:
         fitMax = xPeak + delta
         
         preFitFName = richStr + "PreFitF"
-        preFitF = TF1( preFitFName, "gaus", fitMin, fitMax )
-        preFitF.SetParameter(1, 0 )
+        preFitF = TF1(preFitFName, "gaus", fitMin, fitMax)
+        preFitF.SetParameter(1, 0)
         
         if (richStr == 'Rich1'):
             preFitF.SetParameter(2, 0.0015)
@@ -599,7 +599,7 @@ class AlignMonitor:
             if ( nPol > 1 ):
                 nParamsToSet = 3 + nPol
                 
-            for p in range(0, nParamsToSet ):
+            for p in range(0, nParamsToSet):
                 fFitF.SetParameter(p,lastFitF.GetParameter(p));
                 
             hist.Fit( fFitF, "RFQ" )
@@ -610,7 +610,8 @@ class AlignMonitor:
                 bestNPol = nPol
             else:
                 if ( nPol == nPolFull ):
-                    hist.Fit( fFitF, "RSE0Q" )
+                    #hist.Fit( fFitF, "RSE0Q" )
+                    hist.Fit( fFitF, "RFSE0QM" )
                     fitOK = True         
                 if nPol > 1:
                     break 
-- 
GitLab


From 8a2957ae4880946fd544fb30bde87720a8384169 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Sat, 24 Jun 2017 20:40:06 +0200
Subject: [PATCH 15/59] Added F and M options to hopefully now get consistent
 errors from Summary deltaTheta fits. (2)

---
 .../python/PyMirrAlignOnline/AlignMonitor.py                   | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 60f3cf5e5..2acc80eaa 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -602,7 +602,8 @@ class AlignMonitor:
             for p in range(0, nParamsToSet):
                 fFitF.SetParameter(p,lastFitF.GetParameter(p));
                 
-            hist.Fit( fFitF, "RFQ" )
+            #hist.Fit( fFitF, "RFQ" )
+            hist.Fit( fFitF, "RFQM" )
             lastFitF = fFitF
             fitOK = fFitF.GetParError(1) < m_maxErrorForOK 
             if fitOK:
-- 
GitLab


From f7a92076bd06eefa9af047b1a6092cf769c0afb6 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Sat, 24 Jun 2017 21:00:53 +0200
Subject: [PATCH 16/59] typo change

---
 .../python/PyMirrAlignOnline/AlignMonitor.py  | 32 +++++++++----------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 2acc80eaa..3dbf60d3a 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -73,8 +73,8 @@ class AlignMonitor:
         theCanvas = TCanvas('theCanvas', 'MirrAlign')
         theCanvas.Divide(2,2,0.001,0.001)
         
-        testCanvas = TCanvas('testCanvas', 'MirrAlignTest')
-        testCanvas.Divide(2,2,0.001,0.001)
+        theCanvas2 = TCanvas('theCanvas2', 'MirrAlignTest')
+        theCanvas2.Divide(2,2,0.001,0.001)
 
 ######### Start of 2D histos section
         # heatHistos
@@ -245,19 +245,19 @@ class AlignMonitor:
                 # Anatoly, change the plotting styles here only (but define colorsListFixed above)
                 
                 # Print to testing file
-                testCanvas.cd(1)
+                theCanvas2.cd(1)
                 heatHistoPriY.Draw("COLZ")
                 heatHistoPriY.Draw("TEXT SAME")
-                testCanvas.cd(2)
+                theCanvas2.cd(2)
                 heatHistoPriZ.Draw("COLZ")
                 heatHistoPriZ.Draw("TEXT SAME")
-                testCanvas.cd(3)
+                theCanvas2.cd(3)
                 heatHistoSecY.Draw("COLZ")
                 heatHistoSecY.Draw("TEXT SAME")
-                testCanvas.cd(4)
+                theCanvas2.cd(4)
                 heatHistoSecZ.Draw("COLZ")
                 heatHistoSecZ.Draw("TEXT SAME")
-                testCanvas.Print(testingFile + '(')
+                theCanvas2.Print(testingFile + '(')
 #############
 
         # Compensations-divided-by-tolerances Histograms
@@ -348,24 +348,24 @@ class AlignMonitor:
                 # Anatoly, change the plotting styles here only (but define colorsListFixed above)
                 
                 # Print to testing file
-                testCanvas.cd(1)
+                theCanvas2.cd(1)
                 heatHistoPriY.Draw("COLZ")
                 heatHistoPriY.Draw("TEXT SAME")
-                testCanvas.cd(2)
+                theCanvas2.cd(2)
                 heatHistoPriZ.Draw("COLZ")
                 heatHistoPriZ.Draw("TEXT SAME")
-                testCanvas.cd(3)
+                theCanvas2.cd(3)
                 heatHistoSecY.Draw("COLZ")
                 heatHistoSecY.Draw("TEXT SAME")
-                testCanvas.cd(4)
+                theCanvas2.cd(4)
                 heatHistoSecZ.Draw("COLZ")
                 heatHistoSecZ.Draw("TEXT SAME")
-                testCanvas.Print(testingFile + ')')
+                theCanvas2.Print(testingFile + ')')
 #############
 
         # End of 2D histos section #############
 
-        testCanvas.Clear()
+        theCanvas2.Clear()
         theCanvas.Clear()
         
         # generate resHistograms           
@@ -441,10 +441,10 @@ class AlignMonitor:
                 polbkg[j].SetParameter(3, histFunc[j].GetParameter(6))
                 polbkg[j].SetLineColor(4)
 
-                testCanvas.cd()
+                theCanvas2.cd()
                 resHistograms[j].Draw()
                 polbkg[j].Draw("SAME") 
-                testCanvas.Print(expertFile)
+                theCanvas2.Print(expertFile)
 
                 theCanvas.cd(j+1)                      
                 resHistograms[j].Draw()
@@ -459,7 +459,7 @@ class AlignMonitor:
         resHistoTrend.SetXTitle('iteration number')
         resHistoTrend.SetYTitle('') # resHistoTrend.SetYTitle('Cherenkov angle resolution (mrad)')
 
-        testCanvas.Clear()
+        theCanvas2.Clear()
         theCanvas.Clear()
         resHistoTrend.DrawCopy()
         theCanvas.Print(piquetFile + ')')
-- 
GitLab


From eb4d03a4065bec765da68736edf49d0c89289421 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Sun, 25 Jun 2017 19:02:29 +0200
Subject: [PATCH 17/59] Added mirror numbers to AlignSummary.pdf and
 AlignMonitor.pdf 2D Histos

---
 .../python/PyMirrAlignOnline/AlignMonitor.py  | 115 ++++++++++++------
 1 file changed, 75 insertions(+), 40 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 3dbf60d3a..211ac31a8 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -118,13 +118,6 @@ class AlignMonitor:
         numbersHistoSec.SetXTitle(xTitle)
         numbersHistoSec.SetYTitle(yTitle)
 
-        heatHistoPriY.SetMarkerSize(2.0*heatHistoPriY.GetMarkerSize())
-        heatHistoPriZ.SetMarkerSize(2.0*heatHistoPriZ.GetMarkerSize())
-        heatHistoSecY.SetMarkerSize(2.0*heatHistoSecY.GetMarkerSize())
-        heatHistoSecZ.SetMarkerSize(2.0*heatHistoSecZ.GetMarkerSize())
-        numbersHistoPri.SetMarkerSize(1.0*heatHistoPriY.GetMarkerSize())
-        numbersHistoSec.SetMarkerSize(1.0*heatHistoPriY.GetMarkerSize())
-
         # Flexible Range Color scheme before 2017 June 19
         #   self.colorsLow  = [923,921,0,390,622,624,627,631,636,635,634,633,632,807,797,800,400,416]
         #   self.colorsHigh = [416,432,867,857,600,616,617,618,619,620,615,611,608,606,590,920,922,1]
@@ -145,7 +138,8 @@ class AlignMonitor:
         colorsListFlex = self.colorsLow + self.colorsHigh
 ######### Fixed Range Color scheme 
         if self.displayMode == 0: 
-            # Anatoly, define your color palette here, then there are places for you to set your style below.
+            # Anatoly, define your color palette here, or use this if you agree with it, 
+            #   then there are places for you to set your style below.
             colorsListFixed = [602,600,857,867,416,416,400,797,632,634] 
 #########
 
@@ -161,15 +155,7 @@ class AlignMonitor:
         biggestTilt = [None] * (self.maxIt + 1)
 
         for its in reversed(range(0, self.maxIt + 1)):
-        # Compensations Histograms
-            heatHistoPriY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Y rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded}' )
-            heatHistoPriZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded}' )
-            heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded}' )
-            heatHistoSecZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Z rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded}' )
-            # Histograms that contain only the mirror numbers
-            numbersHistoPri.SetTitle('RICH' + str(self.whichRich) + ' Primary mirror numbers')
-            numbersHistoSec.SetTitle('RICH' + str(self.whichRich) + ' Secondary mirror numbers')
-            
+        # Compensations Histograms           
             # sets priYtrunc, etc... otherwise these will be empty
             mirrtilts[its].setTrunc()
             
@@ -196,25 +182,25 @@ class AlignMonitor:
             biggestTilt[its] = mirrtilts[its].getAbsMax() 
             
             # Flexible range plotting style
-            for n in reversed(range(0,35)):
-                if biggestTilt[its][0] > n*self.sTPY or biggestTilt[its][1] > n*self.sTPZ or biggestTilt[its][2] > n*self.sTSY or biggestTilt[its][3] > n*self.sTSZ:
+            for nFlex in reversed(range(0,35)):
+                if biggestTilt[its][0] > nFlex*self.sTPY or biggestTilt[its][1] > nFlex*self.sTPZ or biggestTilt[its][2] > nFlex*self.sTSY or biggestTilt[its][3] > nFlex*self.sTSZ:
                     break
             # max: heatHistoPriY.GetZaxis().SetRangeUser(-36*self.sTPY, 36*self.sTPY)
-            heatHistoPriY.GetZaxis().SetRangeUser((n+2)*(0-self.sTPY), (n+2)*(self.sTPY))
-            heatHistoPriZ.GetZaxis().SetRangeUser((n+2)*(0-self.sTPZ), (n+2)*(self.sTPZ))
-            heatHistoSecY.GetZaxis().SetRangeUser((n+2)*(0-self.sTSY), (n+2)*(self.sTSY))
-            heatHistoSecZ.GetZaxis().SetRangeUser((n+2)*(0-self.sTSZ), (n+2)*(self.sTSZ))
+            heatHistoPriY.GetZaxis().SetRangeUser((nFlex+2)*(0-self.sTPY), (nFlex+2)*(self.sTPY))
+            heatHistoPriZ.GetZaxis().SetRangeUser((nFlex+2)*(0-self.sTPZ), (nFlex+2)*(self.sTPZ))
+            heatHistoSecY.GetZaxis().SetRangeUser((nFlex+2)*(0-self.sTSY), (nFlex+2)*(self.sTSY))
+            heatHistoSecZ.GetZaxis().SetRangeUser((nFlex+2)*(0-self.sTSZ), (nFlex+2)*(self.sTSZ))
             colorsLowClone = list(self.colorsLow)
             colorsLowClone.reverse()
-            colorsLowSubset = list(colorsLowClone[0:n+2])
+            colorsLowSubset = list(colorsLowClone[0:nFlex+2])
             colorsLowSubset.reverse()
-            colorsListFlex = list(colorsLowSubset + self.colorsHigh[0:n+2])
+            colorsListFlex = list(colorsLowSubset + self.colorsHigh[0:nFlex+2])
             levelsPY = []
             levelsPZ = []
             levelsSY = []
             levelsSZ = []
             # max: for i in range(-(36),(36)+1):
-            for i in range(-(n+2),(n+2)+1):
+            for i in range(-(nFlex+2),(nFlex+2)+1):
                 levelsPY += [i*self.sTPY]
                 levelsPZ += [i*self.sTPZ]
                 levelsSY += [i*self.sTSY]
@@ -225,47 +211,69 @@ class AlignMonitor:
             heatHistoSecY.SetContour(len(list(levelsSY)), numpy.array(list(levelsSY), dtype = 'float64'))
             heatHistoSecZ.SetContour(len(list(levelsSZ)), numpy.array(list(levelsSZ), dtype = 'float64'))
             gStyle.SetPaintTextFormat('4.2f') # formerly 5.3f
+            heatHistoPriY.SetMarkerSize(1.8*heatHistoPriY.GetMarkerSize())
+            heatHistoPriZ.SetMarkerSize(1.8*heatHistoPriZ.GetMarkerSize())
+            heatHistoSecY.SetMarkerSize(1.8*heatHistoSecY.GetMarkerSize())
+            heatHistoSecZ.SetMarkerSize(1.8*heatHistoSecZ.GetMarkerSize())
+            numbersHistoPri.SetMarkerSize(0.9*heatHistoPriY.GetMarkerSize())
+            numbersHistoSec.SetMarkerSize(0.9*heatHistoPriY.GetMarkerSize())
+            heatHistoPriY.SetBarOffset(0.2)
+            heatHistoPriZ.SetBarOffset(0.2)
+            heatHistoSecY.SetBarOffset(0.2)
+            heatHistoSecZ.SetBarOffset(0.2)
+            numbersHistoPri.SetBarOffset(-0.2)
+            numbersHistoSec.SetBarOffset(-0.2)
+            heatHistoPriY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Y rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
+            heatHistoPriZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
+            heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
+            heatHistoSecZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Z rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
 
             theCanvas.cd(1)
             heatHistoPriY.Draw("COLZ")
             heatHistoPriY.Draw("TEXT SAME")
+            numbersHistoPri.Draw("TEXT SAME")
             theCanvas.cd(2)
             heatHistoPriZ.Draw("COLZ")
             heatHistoPriZ.Draw("TEXT SAME")
+            numbersHistoPri.Draw("TEXT SAME")
             theCanvas.cd(3)
             heatHistoSecY.Draw("COLZ")
             heatHistoSecY.Draw("TEXT SAME")
+            numbersHistoSec.Draw("TEXT SAME")
             theCanvas.cd(4)
             heatHistoSecZ.Draw("COLZ")
             heatHistoSecZ.Draw("TEXT SAME")
+            numbersHistoSec.Draw("TEXT SAME")
             theCanvas.Print(expertFile + '(')
             
 ############# Fixed range plotting style (testing)
             if self.displayMode == 0: 
                 # Anatoly, change the plotting styles here only (but define colorsListFixed above)
-                
+                # If you do not need to change a particular style setting then leave it out
+                #   and it will use the default from just above.
+                pass
+            
                 # Print to testing file
                 theCanvas2.cd(1)
                 heatHistoPriY.Draw("COLZ")
                 heatHistoPriY.Draw("TEXT SAME")
+                numbersHistoPri.Draw("TEXT SAME")
                 theCanvas2.cd(2)
                 heatHistoPriZ.Draw("COLZ")
                 heatHistoPriZ.Draw("TEXT SAME")
+                numbersHistoPri.Draw("TEXT SAME")
                 theCanvas2.cd(3)
                 heatHistoSecY.Draw("COLZ")
                 heatHistoSecY.Draw("TEXT SAME")
+                numbersHistoSec.Draw("TEXT SAME")
                 theCanvas2.cd(4)
                 heatHistoSecZ.Draw("COLZ")
                 heatHistoSecZ.Draw("TEXT SAME")
+                numbersHistoSec.Draw("TEXT SAME")
                 theCanvas2.Print(testingFile + '(')
 #############
 
         # Compensations-divided-by-tolerances Histograms
-            heatHistoPriY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Y rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded}' )
-            heatHistoPriZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded}' )
-            heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded}' )
-            heatHistoSecZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Z rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded}' )
-
             # sets priYdiv, etc... otherwise these will be empty            
             mirrtilts[its].setDiv(tolerances = [self.sTPY,self.sTPZ,self.sTSY,self.sTSZ])
             
@@ -286,18 +294,18 @@ class AlignMonitor:
                     heatHistoSecZ.SetBinContent(col+1, row+1, mirrtilts[its].secZdiv[self.binToSecMirr[row][col]])
 
             # Flexible range plotting style
-            # steal n from previous loop, the color palette is also already set.
+            # steal nFlex from previous loop, the color palette is also already set.
             # max: heatHistoPriY.GetZaxis().SetRangeUser(-36*1, 36*1)
-            heatHistoPriY.GetZaxis().SetRangeUser((n+2)*(0-1), (n+2)*(1))
-            heatHistoPriZ.GetZaxis().SetRangeUser((n+2)*(0-1), (n+2)*(1))
-            heatHistoSecY.GetZaxis().SetRangeUser((n+2)*(0-1), (n+2)*(1))
-            heatHistoSecZ.GetZaxis().SetRangeUser((n+2)*(0-1), (n+2)*(1))
+            heatHistoPriY.GetZaxis().SetRangeUser((nFlex+2)*(0-1), (nFlex+2)*(1))
+            heatHistoPriZ.GetZaxis().SetRangeUser((nFlex+2)*(0-1), (nFlex+2)*(1))
+            heatHistoSecY.GetZaxis().SetRangeUser((nFlex+2)*(0-1), (nFlex+2)*(1))
+            heatHistoSecZ.GetZaxis().SetRangeUser((nFlex+2)*(0-1), (nFlex+2)*(1))
             levelsPY = []
             levelsPZ = []
             levelsSY = []
             levelsSZ = []           
             #max: for i in range(-(36),(36)+1):
-            for i in range(-(n+2),(n+2)+1):
+            for i in range(-(nFlex+2),(nFlex+2)+1):
                 levelsPY += [i*1]
                 levelsPZ += [i*1]
                 levelsSY += [i*1]
@@ -307,19 +315,39 @@ class AlignMonitor:
             heatHistoSecY.SetContour(len(list(levelsSY)), numpy.array(list(levelsSY), dtype = 'float64'))
             heatHistoSecZ.SetContour(len(list(levelsSZ)), numpy.array(list(levelsSZ), dtype = 'float64'))        
             gStyle.SetPaintTextFormat('2.0f')
-            
+            heatHistoPriY.SetMarkerSize(1.8*heatHistoPriY.GetMarkerSize())
+            heatHistoPriZ.SetMarkerSize(1.8*heatHistoPriZ.GetMarkerSize())
+            heatHistoSecY.SetMarkerSize(1.8*heatHistoSecY.GetMarkerSize())
+            heatHistoSecZ.SetMarkerSize(1.8*heatHistoSecZ.GetMarkerSize())
+            numbersHistoPri.SetMarkerSize(0.9*heatHistoPriY.GetMarkerSize())
+            numbersHistoSec.SetMarkerSize(0.9*heatHistoPriY.GetMarkerSize())
+            heatHistoPriY.SetBarOffset(0.2)
+            heatHistoPriZ.SetBarOffset(0.2)
+            heatHistoSecY.SetBarOffset(0.2)
+            heatHistoSecZ.SetBarOffset(0.2)
+            numbersHistoPri.SetBarOffset(-0.2)
+            numbersHistoSec.SetBarOffset(-0.2)
+            heatHistoPriY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Y rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
+            heatHistoPriZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
+            heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
+            heatHistoSecZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Z rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
+
             theCanvas.cd(1)
             heatHistoPriY.Draw("COLZ")
             heatHistoPriY.Draw("TEXT SAME")
+            numbersHistoPri.Draw("TEXT SAME")
             theCanvas.cd(2)
             heatHistoPriZ.Draw("COLZ")
             heatHistoPriZ.Draw("TEXT SAME")
+            numbersHistoPri.Draw("TEXT SAME")
             theCanvas.cd(3)
             heatHistoSecY.Draw("COLZ")
             heatHistoSecY.Draw("TEXT SAME")
+            numbersHistoSec.Draw("TEXT SAME")
             theCanvas.cd(4)
             heatHistoSecZ.Draw("COLZ")
             heatHistoSecZ.Draw("TEXT SAME")
+            numbersHistoSec.Draw("TEXT SAME")
             theCanvas.Print(piquetFile + '(')
 
             if its == self.maxIt:
@@ -346,20 +374,27 @@ class AlignMonitor:
 ############# Fixed range plotting style (testing)
             if self.displayMode == 0: 
                 # Anatoly, change the plotting styles here only (but define colorsListFixed above)
-                
+                # If you do not need to change a particular style setting then leave it out
+                #   and it will use the default from just above.
+                pass
+            
                 # Print to testing file
                 theCanvas2.cd(1)
                 heatHistoPriY.Draw("COLZ")
                 heatHistoPriY.Draw("TEXT SAME")
+                numbersHistoPri.Draw("TEXT SAME")
                 theCanvas2.cd(2)
                 heatHistoPriZ.Draw("COLZ")
                 heatHistoPriZ.Draw("TEXT SAME")
+                numbersHistoPri.Draw("TEXT SAME")
                 theCanvas2.cd(3)
                 heatHistoSecY.Draw("COLZ")
                 heatHistoSecY.Draw("TEXT SAME")
+                numbersHistoSec.Draw("TEXT SAME")
                 theCanvas2.cd(4)
                 heatHistoSecZ.Draw("COLZ")
                 heatHistoSecZ.Draw("TEXT SAME")
+                numbersHistoSec.Draw("TEXT SAME")
                 theCanvas2.Print(testingFile + ')')
 #############
 
-- 
GitLab


From 5f3ee146de0ade735cb5afe267d3d0fd23bea092 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Sun, 25 Jun 2017 19:27:02 +0200
Subject: [PATCH 18/59] Added mirror numbers to AlignSummary.pdf and
 AlignMonitor.pdf 2D Histos (2)

---
 .../python/PyMirrAlignOnline/AlignMonitor.py  | 31 ++++++++++---------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 211ac31a8..ad85fdcd2 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -182,25 +182,25 @@ class AlignMonitor:
             biggestTilt[its] = mirrtilts[its].getAbsMax() 
             
             # Flexible range plotting style
-            for nFlex in reversed(range(0,35)):
-                if biggestTilt[its][0] > nFlex*self.sTPY or biggestTilt[its][1] > nFlex*self.sTPZ or biggestTilt[its][2] > nFlex*self.sTSY or biggestTilt[its][3] > nFlex*self.sTSZ:
+            for self.nFlex in reversed(range(0,35)):
+                if biggestTilt[its][0] > self.nFlex*self.sTPY or biggestTilt[its][1] > self.nFlex*self.sTPZ or biggestTilt[its][2] > self.nFlex*self.sTSY or biggestTilt[its][3] > self.nFlex*self.sTSZ:
                     break
             # max: heatHistoPriY.GetZaxis().SetRangeUser(-36*self.sTPY, 36*self.sTPY)
-            heatHistoPriY.GetZaxis().SetRangeUser((nFlex+2)*(0-self.sTPY), (nFlex+2)*(self.sTPY))
-            heatHistoPriZ.GetZaxis().SetRangeUser((nFlex+2)*(0-self.sTPZ), (nFlex+2)*(self.sTPZ))
-            heatHistoSecY.GetZaxis().SetRangeUser((nFlex+2)*(0-self.sTSY), (nFlex+2)*(self.sTSY))
-            heatHistoSecZ.GetZaxis().SetRangeUser((nFlex+2)*(0-self.sTSZ), (nFlex+2)*(self.sTSZ))
+            heatHistoPriY.GetZaxis().SetRangeUser((self.nFlex+2)*(0-self.sTPY), (self.nFlex+2)*(self.sTPY))
+            heatHistoPriZ.GetZaxis().SetRangeUser((self.nFlex+2)*(0-self.sTPZ), (self.nFlex+2)*(self.sTPZ))
+            heatHistoSecY.GetZaxis().SetRangeUser((self.nFlex+2)*(0-self.sTSY), (self.nFlex+2)*(self.sTSY))
+            heatHistoSecZ.GetZaxis().SetRangeUser((self.nFlex+2)*(0-self.sTSZ), (self.nFlex+2)*(self.sTSZ))
             colorsLowClone = list(self.colorsLow)
             colorsLowClone.reverse()
-            colorsLowSubset = list(colorsLowClone[0:nFlex+2])
+            colorsLowSubset = list(colorsLowClone[0:self.nFlex+2])
             colorsLowSubset.reverse()
-            colorsListFlex = list(colorsLowSubset + self.colorsHigh[0:nFlex+2])
+            colorsListFlex = list(colorsLowSubset + self.colorsHigh[0:self.nFlex+2])
             levelsPY = []
             levelsPZ = []
             levelsSY = []
             levelsSZ = []
             # max: for i in range(-(36),(36)+1):
-            for i in range(-(nFlex+2),(nFlex+2)+1):
+            for i in range(-(self.nFlex+2),(self.nFlex+2)+1):
                 levelsPY += [i*self.sTPY]
                 levelsPZ += [i*self.sTPZ]
                 levelsSY += [i*self.sTSY]
@@ -294,22 +294,23 @@ class AlignMonitor:
                     heatHistoSecZ.SetBinContent(col+1, row+1, mirrtilts[its].secZdiv[self.binToSecMirr[row][col]])
 
             # Flexible range plotting style
-            # steal nFlex from previous loop, the color palette is also already set.
+            # self.nFlex should be unchanged from previous determination.
             # max: heatHistoPriY.GetZaxis().SetRangeUser(-36*1, 36*1)
-            heatHistoPriY.GetZaxis().SetRangeUser((nFlex+2)*(0-1), (nFlex+2)*(1))
-            heatHistoPriZ.GetZaxis().SetRangeUser((nFlex+2)*(0-1), (nFlex+2)*(1))
-            heatHistoSecY.GetZaxis().SetRangeUser((nFlex+2)*(0-1), (nFlex+2)*(1))
-            heatHistoSecZ.GetZaxis().SetRangeUser((nFlex+2)*(0-1), (nFlex+2)*(1))
+            heatHistoPriY.GetZaxis().SetRangeUser((self.nFlex+2)*(0-1), (self.nFlex+2)*(1))
+            heatHistoPriZ.GetZaxis().SetRangeUser((self.nFlex+2)*(0-1), (self.nFlex+2)*(1))
+            heatHistoSecY.GetZaxis().SetRangeUser((self.nFlex+2)*(0-1), (self.nFlex+2)*(1))
+            heatHistoSecZ.GetZaxis().SetRangeUser((self.nFlex+2)*(0-1), (self.nFlex+2)*(1))
             levelsPY = []
             levelsPZ = []
             levelsSY = []
             levelsSZ = []           
             #max: for i in range(-(36),(36)+1):
-            for i in range(-(nFlex+2),(nFlex+2)+1):
+            for i in range(-(self.nFlex+2),(self.nFlex+2)+1):
                 levelsPY += [i*1]
                 levelsPZ += [i*1]
                 levelsSY += [i*1]
                 levelsSZ += [i*1]
+            gStyle.SetPalette(len(list(colorsListFlex)), numpy.array(list(colorsListFlex), dtype = 'intc'))
             heatHistoPriY.SetContour(len(list(levelsPY)), numpy.array(list(levelsPY), dtype = 'float64'))
             heatHistoPriZ.SetContour(len(list(levelsPZ)), numpy.array(list(levelsPZ), dtype = 'float64'))
             heatHistoSecY.SetContour(len(list(levelsSY)), numpy.array(list(levelsSY), dtype = 'float64'))
-- 
GitLab


From f2eb47841447cf7386bfb7a5ae7d45fe161ec362 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Mon, 26 Jun 2017 09:50:57 +0200
Subject: [PATCH 19/59] Added mirror numbers to AlignSummary.pdf and
 AlignMonitor.pdf 2D Histos (3)

---
 .../python/PyMirrAlignOnline/AlignMonitor.py  | 45 +++++++++++--------
 1 file changed, 26 insertions(+), 19 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index ad85fdcd2..7b4fc508d 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -117,6 +117,8 @@ class AlignMonitor:
         numbersHistoPri.SetYTitle(yTitle)
         numbersHistoSec.SetXTitle(xTitle)
         numbersHistoSec.SetYTitle(yTitle)
+        
+        self.origMarkerSize = heatHistoPriY.GetMarkerSize() # default MarkerSize should be same for all histos
 
         # Flexible Range Color scheme before 2017 June 19
         #   self.colorsLow  = [923,921,0,390,622,624,627,631,636,635,634,633,632,807,797,800,400,416]
@@ -166,7 +168,7 @@ class AlignMonitor:
                     #truncated, not rounded
                     heatHistoPriY.SetBinContent(col+1, row+1, mirrtilts[its].priYtrunc[self.binToPriMirr[row][col]]) 
                     heatHistoPriZ.SetBinContent(col+1, row+1, mirrtilts[its].priZtrunc[self.binToPriMirr[row][col]])
-                    numbersHistoPri.SetBinContent(col+1, row+1, self.binToPriMirr[row][col])
+                    numbersHistoPri.SetBinContent(col+1, row+1, self.binToPriMirr[row][col] if self.binToPriMirr[row][col] != 0 else 0.0000001)
     
             rowsSec = len(self.binToSecMirr)
             colsSec = len(self.binToSecMirr[0])
@@ -175,7 +177,7 @@ class AlignMonitor:
                     #truncated, not rounded
                     heatHistoSecY.SetBinContent(col+1, row+1, mirrtilts[its].secYtrunc[self.binToSecMirr[row][col]])
                     heatHistoSecZ.SetBinContent(col+1, row+1, mirrtilts[its].secZtrunc[self.binToSecMirr[row][col]])
-                    numbersHistoSec.SetBinContent(col+1, row+1, self.binToSecMirr[row][col])
+                    numbersHistoSec.SetBinContent(col+1, row+1, self.binToSecMirr[row][col] if self.binToSecMirr[row][col] != 0 else 0.0000001)
 
             # Get the maximum tilt in any plot, this lets us set the scales only as relevant, 
             #   and in a controlled manner across all possible mirrors and tilts.    
@@ -210,13 +212,12 @@ class AlignMonitor:
             heatHistoPriZ.SetContour(len(list(levelsPZ)), numpy.array(list(levelsPZ), dtype = 'float64'))
             heatHistoSecY.SetContour(len(list(levelsSY)), numpy.array(list(levelsSY), dtype = 'float64'))
             heatHistoSecZ.SetContour(len(list(levelsSZ)), numpy.array(list(levelsSZ), dtype = 'float64'))
-            gStyle.SetPaintTextFormat('4.2f') # formerly 5.3f
-            heatHistoPriY.SetMarkerSize(1.8*heatHistoPriY.GetMarkerSize())
-            heatHistoPriZ.SetMarkerSize(1.8*heatHistoPriZ.GetMarkerSize())
-            heatHistoSecY.SetMarkerSize(1.8*heatHistoSecY.GetMarkerSize())
-            heatHistoSecZ.SetMarkerSize(1.8*heatHistoSecZ.GetMarkerSize())
-            numbersHistoPri.SetMarkerSize(0.9*heatHistoPriY.GetMarkerSize())
-            numbersHistoSec.SetMarkerSize(0.9*heatHistoPriY.GetMarkerSize())
+            heatHistoPriY.SetMarkerSize(1.8*self.origMarkerSize)
+            heatHistoPriZ.SetMarkerSize(1.8*self.origMarkerSize)
+            heatHistoSecY.SetMarkerSize(1.8*self.origMarkerSize)
+            heatHistoSecZ.SetMarkerSize(1.8*self.origMarkerSize)
+            numbersHistoPri.SetMarkerSize(0.9*self.origMarkerSize)
+            numbersHistoSec.SetMarkerSize(0.9*self.origMarkerSize)
             heatHistoPriY.SetBarOffset(0.2)
             heatHistoPriZ.SetBarOffset(0.2)
             heatHistoSecY.SetBarOffset(0.2)
@@ -228,21 +229,27 @@ class AlignMonitor:
             heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
             heatHistoSecZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Z rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
 
+            gStyle.SetPaintTextFormat('4.2f') # formerly 5.3f
             theCanvas.cd(1)
             heatHistoPriY.Draw("COLZ")
             heatHistoPriY.Draw("TEXT SAME")
-            numbersHistoPri.Draw("TEXT SAME")
             theCanvas.cd(2)
             heatHistoPriZ.Draw("COLZ")
             heatHistoPriZ.Draw("TEXT SAME")
-            numbersHistoPri.Draw("TEXT SAME")
             theCanvas.cd(3)
             heatHistoSecY.Draw("COLZ")
             heatHistoSecY.Draw("TEXT SAME")
-            numbersHistoSec.Draw("TEXT SAME")
             theCanvas.cd(4)
             heatHistoSecZ.Draw("COLZ")
             heatHistoSecZ.Draw("TEXT SAME")
+            gStyle.SetPaintTextFormat('2.0f')
+            theCanvas.cd(1)
+            numbersHistoPri.Draw("TEXT SAME")
+            theCanvas.cd(2)
+            numbersHistoPri.Draw("TEXT SAME")
+            theCanvas.cd(3)
+            numbersHistoSec.Draw("TEXT SAME")
+            theCanvas.cd(4)
             numbersHistoSec.Draw("TEXT SAME")
             theCanvas.Print(expertFile + '(')
             
@@ -315,13 +322,12 @@ class AlignMonitor:
             heatHistoPriZ.SetContour(len(list(levelsPZ)), numpy.array(list(levelsPZ), dtype = 'float64'))
             heatHistoSecY.SetContour(len(list(levelsSY)), numpy.array(list(levelsSY), dtype = 'float64'))
             heatHistoSecZ.SetContour(len(list(levelsSZ)), numpy.array(list(levelsSZ), dtype = 'float64'))        
-            gStyle.SetPaintTextFormat('2.0f')
-            heatHistoPriY.SetMarkerSize(1.8*heatHistoPriY.GetMarkerSize())
-            heatHistoPriZ.SetMarkerSize(1.8*heatHistoPriZ.GetMarkerSize())
-            heatHistoSecY.SetMarkerSize(1.8*heatHistoSecY.GetMarkerSize())
-            heatHistoSecZ.SetMarkerSize(1.8*heatHistoSecZ.GetMarkerSize())
-            numbersHistoPri.SetMarkerSize(0.9*heatHistoPriY.GetMarkerSize())
-            numbersHistoSec.SetMarkerSize(0.9*heatHistoPriY.GetMarkerSize())
+            heatHistoPriY.SetMarkerSize(1.8*self.origMarkerSize)
+            heatHistoPriZ.SetMarkerSize(1.8*self.origMarkerSize)
+            heatHistoSecY.SetMarkerSize(1.8*self.origMarkerSize)
+            heatHistoSecZ.SetMarkerSize(1.8*self.origMarkerSize)
+            numbersHistoPri.SetMarkerSize(0.9*self.origMarkerSize)
+            numbersHistoSec.SetMarkerSize(0.9*self.origMarkerSize)
             heatHistoPriY.SetBarOffset(0.2)
             heatHistoPriZ.SetBarOffset(0.2)
             heatHistoSecY.SetBarOffset(0.2)
@@ -333,6 +339,7 @@ class AlignMonitor:
             heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
             heatHistoSecZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Z rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
 
+            gStyle.SetPaintTextFormat('2.0f')
             theCanvas.cd(1)
             heatHistoPriY.Draw("COLZ")
             heatHistoPriY.Draw("TEXT SAME")
-- 
GitLab


From bfb302d3515181b60aea52f7b2f6367f9ef003ae Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Mon, 26 Jun 2017 09:56:12 +0200
Subject: [PATCH 20/59] Added mirror numbers to AlignSummary.pdf and
 AlignMonitor.pdf 2D Histos (4)

---
 .../python/PyMirrAlignOnline/AlignMonitor.py  | 29 +++++++++++++------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 7b4fc508d..2046fe8a3 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -159,7 +159,7 @@ class AlignMonitor:
         for its in reversed(range(0, self.maxIt + 1)):
         # Compensations Histograms           
             # sets priYtrunc, etc... otherwise these will be empty
-            mirrtilts[its].setTrunc()
+            mirrtilts[its].setTrunc(digits = 2)
             
             rowsPri = len(self.binToPriMirr)
             colsPri = len(self.binToPriMirr[0])
@@ -251,6 +251,7 @@ class AlignMonitor:
             numbersHistoSec.Draw("TEXT SAME")
             theCanvas.cd(4)
             numbersHistoSec.Draw("TEXT SAME")
+            
             theCanvas.Print(expertFile + '(')
             
 ############# Fixed range plotting style (testing)
@@ -261,22 +262,29 @@ class AlignMonitor:
                 pass
             
                 # Print to testing file
-                theCanvas2.cd(1)
+                gStyle.SetPaintTextFormat('4.2f') # formerly 5.3f
+                theCanvas.cd(1)
                 heatHistoPriY.Draw("COLZ")
                 heatHistoPriY.Draw("TEXT SAME")
-                numbersHistoPri.Draw("TEXT SAME")
-                theCanvas2.cd(2)
+                theCanvas.cd(2)
                 heatHistoPriZ.Draw("COLZ")
                 heatHistoPriZ.Draw("TEXT SAME")
-                numbersHistoPri.Draw("TEXT SAME")
-                theCanvas2.cd(3)
+                theCanvas.cd(3)
                 heatHistoSecY.Draw("COLZ")
                 heatHistoSecY.Draw("TEXT SAME")
-                numbersHistoSec.Draw("TEXT SAME")
-                theCanvas2.cd(4)
+                theCanvas.cd(4)
                 heatHistoSecZ.Draw("COLZ")
                 heatHistoSecZ.Draw("TEXT SAME")
+                gStyle.SetPaintTextFormat('2.0f')
+                theCanvas.cd(1)
+                numbersHistoPri.Draw("TEXT SAME")
+                theCanvas.cd(2)
+                numbersHistoPri.Draw("TEXT SAME")
+                theCanvas.cd(3)
                 numbersHistoSec.Draw("TEXT SAME")
+                theCanvas.cd(4)
+                numbersHistoSec.Draw("TEXT SAME")
+                
                 theCanvas2.Print(testingFile + '(')
 #############
 
@@ -356,6 +364,7 @@ class AlignMonitor:
             heatHistoSecZ.Draw("COLZ")
             heatHistoSecZ.Draw("TEXT SAME")
             numbersHistoSec.Draw("TEXT SAME")
+            
             theCanvas.Print(piquetFile + '(')
 
             if its == self.maxIt:
@@ -403,6 +412,7 @@ class AlignMonitor:
                 heatHistoSecZ.Draw("COLZ")
                 heatHistoSecZ.Draw("TEXT SAME")
                 numbersHistoSec.Draw("TEXT SAME")
+                
                 theCanvas2.Print(testingFile + ')')
 #############
 
@@ -487,6 +497,7 @@ class AlignMonitor:
                 theCanvas2.cd()
                 resHistograms[j].Draw()
                 polbkg[j].Draw("SAME") 
+                
                 theCanvas2.Print(expertFile)
 
                 theCanvas.cd(j+1)                      
@@ -505,8 +516,8 @@ class AlignMonitor:
         theCanvas2.Clear()
         theCanvas.Clear()
         resHistoTrend.DrawCopy()
+        
         theCanvas.Print(piquetFile + ')')
-        #theCanvas.Print(expertFile)
         
         self.monSvc.publishHistogram(self.monitoring_folder, resHistoTrend.Clone(), add=False)
         print "INFO: resHistoTrend sent to Monitoring."
-- 
GitLab


From ef152b90ad91f943e8c28e3db184f87f64e1abfa Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Mon, 26 Jun 2017 10:05:06 +0200
Subject: [PATCH 21/59] Added mirror numbers to AlignSummary.pdf and
 AlignMonitor.pdf 2D Histos (5)

---
 .../python/PyMirrAlignOnline/AlignMonitor.py     | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 2046fe8a3..eb6f92170 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -263,26 +263,26 @@ class AlignMonitor:
             
                 # Print to testing file
                 gStyle.SetPaintTextFormat('4.2f') # formerly 5.3f
-                theCanvas.cd(1)
+                theCanvas2.cd(1)
                 heatHistoPriY.Draw("COLZ")
                 heatHistoPriY.Draw("TEXT SAME")
-                theCanvas.cd(2)
+                theCanvas2.cd(2)
                 heatHistoPriZ.Draw("COLZ")
                 heatHistoPriZ.Draw("TEXT SAME")
-                theCanvas.cd(3)
+                theCanvas2.cd(3)
                 heatHistoSecY.Draw("COLZ")
                 heatHistoSecY.Draw("TEXT SAME")
-                theCanvas.cd(4)
+                theCanvas2.cd(4)
                 heatHistoSecZ.Draw("COLZ")
                 heatHistoSecZ.Draw("TEXT SAME")
                 gStyle.SetPaintTextFormat('2.0f')
-                theCanvas.cd(1)
+                theCanvas2.cd(1)
                 numbersHistoPri.Draw("TEXT SAME")
-                theCanvas.cd(2)
+                theCanvas2.cd(2)
                 numbersHistoPri.Draw("TEXT SAME")
-                theCanvas.cd(3)
+                theCanvas2.cd(3)
                 numbersHistoSec.Draw("TEXT SAME")
-                theCanvas.cd(4)
+                theCanvas2.cd(4)
                 numbersHistoSec.Draw("TEXT SAME")
                 
                 theCanvas2.Print(testingFile + '(')
-- 
GitLab


From 8d1338b696822e0cbf4fb74b7c2602882542cada Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Mon, 26 Jun 2017 12:46:38 +0200
Subject: [PATCH 22/59] Added insanity function to SetupHelper, to perform
 sanity checks

---
 .../python/PyMirrAlignOnline/Iterator.py                     | 2 ++
 .../python/PyMirrAlignOnline/SetupHelper.py                  | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 38177c349..218e6e58a 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -368,11 +368,13 @@ def run(whichRich):
               if autoUpdate:
                 xmlHelper.finalXML( str(int(latest_vN) + 1) , True) # current + 1
                 setupHelper.finalize(conv, n_it, compareXML, elapsed_time_config, elapsed_runtimes, True, nEventsListList)
+                insanity = setupHelper.insanity()
                 if testing is not True:
                     updateHelper.updateDB( int(latest_vN) + 1 , True) # current + 1
               else:
                 xmlHelper.finalXML( str(int(latest_vN) + 1) + '_maybe_' + setupHelper.directoryTime, True) # (current + 1)_maybe
                 setupHelper.finalize(conv, n_it, compareXML, elapsed_time_config, elapsed_runtimes, None, nEventsListList)
+                insanity = setupHelper.insanity()
                 if testing is not True:
                     updateHelper.updateDB( int(latest_vN) , False)
               #updateHelper.stopUpdateDIM()    
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index 070ac59af..33a87ee16 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -431,4 +431,7 @@ class SetupHelper:
         subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
   
         return 0
-    
\ No newline at end of file
+    
+    def insanity(self):
+        # perform sanity Checks
+        return False
\ No newline at end of file
-- 
GitLab


From 72056f06eab0e9478d53ed70dc146e5fea1c46a0 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Mon, 26 Jun 2017 13:01:27 +0200
Subject: [PATCH 23/59] Added monitor function to SetupHelper, to perform
 monitoring first

---
 .../python/PyMirrAlignOnline/Iterator.py       |  9 ++++++---
 .../python/PyMirrAlignOnline/SetupHelper.py    | 18 +++++++++++-------
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 218e6e58a..56d67c922 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -352,6 +352,11 @@ def run(whichRich):
           elapsed_runtimes['elapsed_time_run'] = time() - start_time_run # Actual total iterating time
           print "INFO: Elapsed time to run the Mirror Alignment set as", elapsed_runtimes['elapsed_time_run'], "seconds."
 
+          sys.stdout.flush()  
+
+          setupHelper.monitor(n_it)
+          insanity = setupHelper.insanity()
+
           nEventsListList = setupHelper.getNEventsListList(n_it)
           if nEventsListList[1] < int(alignConf.getProp('requiredEvents')):
               if autoUpdate is True:
@@ -359,7 +364,7 @@ def run(whichRich):
                 print "INFO: We processed an average number of events per iteration of " + str(nEventsListList[1]) + ", which is too low to allow mirror alignment " + setupHelper.directoryTime + " to automatically update, should an update be deemed necessary."
                 setupHelper.sendEmail( 'autoUpdate disabled for RICH' + str(whichRich) + ' alignment ' + setupHelper.directoryTime + '.' , 'RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' will not automatically be updated, should an update be deemed necessary. \n Average number of events processed per iteration: ' + str(nEventsListList[1]) , setupHelper.emails)        
 
-          sys.stdout.flush()  
+          sys.stdout.flush()            
           
           if forcedUpdate_ChMagPol and conv:
               # if we are forcing the update we use the newXML from RichMirrAlign, not the currentXML
@@ -368,13 +373,11 @@ def run(whichRich):
               if autoUpdate:
                 xmlHelper.finalXML( str(int(latest_vN) + 1) , True) # current + 1
                 setupHelper.finalize(conv, n_it, compareXML, elapsed_time_config, elapsed_runtimes, True, nEventsListList)
-                insanity = setupHelper.insanity()
                 if testing is not True:
                     updateHelper.updateDB( int(latest_vN) + 1 , True) # current + 1
               else:
                 xmlHelper.finalXML( str(int(latest_vN) + 1) + '_maybe_' + setupHelper.directoryTime, True) # (current + 1)_maybe
                 setupHelper.finalize(conv, n_it, compareXML, elapsed_time_config, elapsed_runtimes, None, nEventsListList)
-                insanity = setupHelper.insanity()
                 if testing is not True:
                     updateHelper.updateDB( int(latest_vN) , False)
               #updateHelper.stopUpdateDIM()    
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index 33a87ee16..fbb9c1b39 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -62,10 +62,12 @@ class SetupHelper:
         if os.path.exists(self.workdir + "/" + rootFile):
             os.remove(self.workdir + "/" + rootFile)
 
-    def finalize(self, conv, n_it, compareXML, farm_config_time, elapsed_runtimes, DBUpdated, nEventsListList):
-        nEventsList = nEventsListList[0]
-        nEvents = nEventsListList[1]
+    def monitor(self):
+        from AlignMonitor import AlignMonitor
+        alignMonitor = AlignMonitor(self.alignConf, n_it)
+        alignMonitor.performMonitoring(compareXML)
 
+    def finalize(self, conv, n_it, compareXML, farm_config_time, elapsed_runtimes, DBUpdated, nEventsListList):
         if not os.path.exists(self.savedir):
             os.makedirs(self.savedir)
         for f in os.listdir(self.workdir):
@@ -75,21 +77,23 @@ class SetupHelper:
                 shutil.copy2(self.workdir + "/" + f, self.savedir)
         print "INFO: savedir " + self.savedir
 
+        nEventsList = nEventsListList[0]
+        nEvents = nEventsListList[1]
+        
         summaryFile = self.workdir + "/summary.txt"
         self.writeSummary(conv, n_it, farm_config_time, elapsed_runtimes, summaryFile, DBUpdated, nEvents, nEventsList)
 
         shutil.copy2(summaryFile, self.savedir)
 
-        from AlignMonitor import AlignMonitor
-        alignMonitor = AlignMonitor(self.alignConf, n_it)
-        alignMonitor.performMonitoring(compareXML)
-
         ChangeWRTDBFile  = self.workdir + "/Rich" + str(self.whichRich) + '_ChangeWRTDB_'+ str(n_it + 1) +'.txt'
         shutil.copy2(ChangeWRTDBFile, self.savedir)
         AlignSummaryFile = self.workdir + "/Rich" + str(self.whichRich) + '_AlignSummary.pdf'    
         shutil.copy2(AlignSummaryFile, self.savedir)
         AlignMonitorFile = self.workdir + "/Rich" + str(self.whichRich) + '_AlignMonitor.pdf'    
         shutil.copy2(AlignMonitorFile, self.savedir)
+        AlignTestingFile = self.workdir + "/Rich" + str(self.whichRich) + '_AlignTesting.pdf'    
+        if os.path.exists(AlignTestingFile):
+            shutil.copy2(AlignTestingFile, self.savedir)
 
         # Write summary.txt, _AlignSummary.pdf, and _ChangeWRTDB.txt to the ELOG
         alignment_time = elapsed_runtimes['elapsed_time_run']
-- 
GitLab


From 0d7e5b7626f2d498dd5fae3a8e42b9ef2f1ebd42 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Mon, 26 Jun 2017 13:01:47 +0200
Subject: [PATCH 24/59] Added monitor function to SetupHelper, to perform
 monitoring first (2)

---
 .../python/PyMirrAlignOnline/SetupHelper.py                     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index fbb9c1b39..d92d34e0f 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -62,7 +62,7 @@ class SetupHelper:
         if os.path.exists(self.workdir + "/" + rootFile):
             os.remove(self.workdir + "/" + rootFile)
 
-    def monitor(self):
+    def monitor(self, n_it):
         from AlignMonitor import AlignMonitor
         alignMonitor = AlignMonitor(self.alignConf, n_it)
         alignMonitor.performMonitoring(compareXML)
-- 
GitLab


From f65f8e2c919adeec95e7c428e27bdfa7209382c7 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Mon, 26 Jun 2017 13:03:15 +0200
Subject: [PATCH 25/59] Added monitor function to SetupHelper, to perform
 monitoring first (3)

---
 .../python/PyMirrAlignOnline/Iterator.py                        | 2 +-
 .../python/PyMirrAlignOnline/SetupHelper.py                     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 56d67c922..706af51a8 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -354,7 +354,7 @@ def run(whichRich):
 
           sys.stdout.flush()  
 
-          setupHelper.monitor(n_it)
+          setupHelper.monitor(n_it, compareXML)
           insanity = setupHelper.insanity()
 
           nEventsListList = setupHelper.getNEventsListList(n_it)
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index d92d34e0f..d85c4ecf2 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -62,7 +62,7 @@ class SetupHelper:
         if os.path.exists(self.workdir + "/" + rootFile):
             os.remove(self.workdir + "/" + rootFile)
 
-    def monitor(self, n_it):
+    def monitor(self, n_it, compareXML):
         from AlignMonitor import AlignMonitor
         alignMonitor = AlignMonitor(self.alignConf, n_it)
         alignMonitor.performMonitoring(compareXML)
-- 
GitLab


From f79199f5ce9fc9c6fac9cb7d0ee69e29d46bccd2 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Mon, 26 Jun 2017 13:09:03 +0200
Subject: [PATCH 26/59] Changed it so that everything gets written to the
 workDir first, then everything gets moved.

---
 .../python/PyMirrAlignOnline/SetupHelper.py   | 30 ++++++++++---------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index d85c4ecf2..2ae2ce46e 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -68,6 +68,14 @@ class SetupHelper:
         alignMonitor.performMonitoring(compareXML)
 
     def finalize(self, conv, n_it, compareXML, farm_config_time, elapsed_runtimes, DBUpdated, nEventsListList):
+        nEventsList = nEventsListList[0]
+        nEvents = nEventsListList[1]
+        
+        summaryFile = self.workdir + "/summary.txt"
+        self.writeSummary(conv, n_it, farm_config_time, elapsed_runtimes, summaryFile, DBUpdated, nEvents, nEventsList)
+
+        #shutil.copy2(summaryFile, self.savedir)
+        
         if not os.path.exists(self.savedir):
             os.makedirs(self.savedir)
         for f in os.listdir(self.workdir):
@@ -76,24 +84,18 @@ class SetupHelper:
             else:
                 shutil.copy2(self.workdir + "/" + f, self.savedir)
         print "INFO: savedir " + self.savedir
-
-        nEventsList = nEventsListList[0]
-        nEvents = nEventsListList[1]
-        
-        summaryFile = self.workdir + "/summary.txt"
-        self.writeSummary(conv, n_it, farm_config_time, elapsed_runtimes, summaryFile, DBUpdated, nEvents, nEventsList)
-
-        shutil.copy2(summaryFile, self.savedir)
+        # NOTE: Any file created after this in the workdir 
+        #   needs to be *manually* saved in the savedir
 
         ChangeWRTDBFile  = self.workdir + "/Rich" + str(self.whichRich) + '_ChangeWRTDB_'+ str(n_it + 1) +'.txt'
-        shutil.copy2(ChangeWRTDBFile, self.savedir)
+        #shutil.copy2(ChangeWRTDBFile, self.savedir)
         AlignSummaryFile = self.workdir + "/Rich" + str(self.whichRich) + '_AlignSummary.pdf'    
-        shutil.copy2(AlignSummaryFile, self.savedir)
+        #shutil.copy2(AlignSummaryFile, self.savedir)
         AlignMonitorFile = self.workdir + "/Rich" + str(self.whichRich) + '_AlignMonitor.pdf'    
-        shutil.copy2(AlignMonitorFile, self.savedir)
-        AlignTestingFile = self.workdir + "/Rich" + str(self.whichRich) + '_AlignTesting.pdf'    
-        if os.path.exists(AlignTestingFile):
-            shutil.copy2(AlignTestingFile, self.savedir)
+        #shutil.copy2(AlignMonitorFile, self.savedir)
+        #AlignTestingFile = self.workdir + "/Rich" + str(self.whichRich) + '_AlignTesting.pdf'    
+        #if os.path.exists(AlignTestingFile):
+            #shutil.copy2(AlignTestingFile, self.savedir)
 
         # Write summary.txt, _AlignSummary.pdf, and _ChangeWRTDB.txt to the ELOG
         alignment_time = elapsed_runtimes['elapsed_time_run']
-- 
GitLab


From ccd4577af4336c465e7dfeb9f2826d25ecd5c37f Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Mon, 26 Jun 2017 13:55:31 +0200
Subject: [PATCH 27/59] Removed insanity function in SetupHelper, now result of
 sanity checks is returned by the monitor function.

---
 .../python/PyMirrAlignOnline/AlignMonitor.py       |  8 +++++++-
 .../python/PyMirrAlignOnline/Iterator.py           | 14 ++++++++++----
 .../python/PyMirrAlignOnline/SetupHelper.py        |  5 +----
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index eb6f92170..3e5d06d63 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -56,6 +56,7 @@ class AlignMonitor:
         sys.stdout.flush()
         # The Monitoring Job "Saver" is part of a monitoring script by Giulio Dujany (elsewhere)
         #   That monitoring script is always being run at the pit by the Alignment group
+        self.isInsane = False
     
     def performMonitoring(self, compareXML):
         import os
@@ -161,6 +162,11 @@ class AlignMonitor:
             # sets priYtrunc, etc... otherwise these will be empty
             mirrtilts[its].setTrunc(digits = 2)
             
+            # sanity check
+            if its == self.maxIt:
+                if biggestTilt[its][0] >= 3*self.sTPY or biggestTilt[its][1] >= 3*self.sTPZ or biggestTilt[its][2] >= 3*self.sTSY or biggestTilt[its][3] >= 3*self.sTSZ:
+                    self.isInsane = True
+            
             rowsPri = len(self.binToPriMirr)
             colsPri = len(self.binToPriMirr[0])
             for row in xrange(rowsPri):
@@ -185,7 +191,7 @@ class AlignMonitor:
             
             # Flexible range plotting style
             for self.nFlex in reversed(range(0,35)):
-                if biggestTilt[its][0] > self.nFlex*self.sTPY or biggestTilt[its][1] > self.nFlex*self.sTPZ or biggestTilt[its][2] > self.nFlex*self.sTSY or biggestTilt[its][3] > self.nFlex*self.sTSZ:
+                if biggestTilt[its][0] >= self.nFlex*self.sTPY or biggestTilt[its][1] >= self.nFlex*self.sTPZ or biggestTilt[its][2] >= self.nFlex*self.sTSY or biggestTilt[its][3] >= self.nFlex*self.sTSZ:
                     break
             # max: heatHistoPriY.GetZaxis().SetRangeUser(-36*self.sTPY, 36*self.sTPY)
             heatHistoPriY.GetZaxis().SetRangeUser((self.nFlex+2)*(0-self.sTPY), (self.nFlex+2)*(self.sTPY))
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 706af51a8..2241e43e0 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -354,8 +354,9 @@ def run(whichRich):
 
           sys.stdout.flush()  
 
-          setupHelper.monitor(n_it, compareXML)
-          insanity = setupHelper.insanity()
+          # Run the monitoring, send plots to the Presenter, and generate PDF files;
+          #   this returns True if any sanity check failed.
+          insane = setupHelper.monitor(n_it, compareXML)
 
           nEventsListList = setupHelper.getNEventsListList(n_it)
           if nEventsListList[1] < int(alignConf.getProp('requiredEvents')):
@@ -363,8 +364,13 @@ def run(whichRich):
                 autoUpdate = False
                 print "INFO: We processed an average number of events per iteration of " + str(nEventsListList[1]) + ", which is too low to allow mirror alignment " + setupHelper.directoryTime + " to automatically update, should an update be deemed necessary."
                 setupHelper.sendEmail( 'autoUpdate disabled for RICH' + str(whichRich) + ' alignment ' + setupHelper.directoryTime + '.' , 'RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' will not automatically be updated, should an update be deemed necessary. \n Average number of events processed per iteration: ' + str(nEventsListList[1]) , setupHelper.emails)        
-
-          sys.stdout.flush()            
+          sys.stdout.flush()
+          if insane and not forcedUpdate_ChMagPol: # We disable the sanity check on magnet polarity change, because we expect a large variation
+              if autoUpdate is True:
+                autoUpdate = False
+                print "INFO: Sanity checks have failed, we will not allow mirror alignment " + setupHelper.directoryTime + " to automatically update, should an update be deemed necessary."
+                setupHelper.sendEmail( 'autoUpdate disabled for RICH' + str(whichRich) + ' alignment ' + setupHelper.directoryTime + '.' , 'RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' will not automatically be updated, should an update be deemed necessary. \n Sanity checks have failed for this alignment.' , setupHelper.emails)        
+          sys.stdout.flush()                 
           
           if forcedUpdate_ChMagPol and conv:
               # if we are forcing the update we use the newXML from RichMirrAlign, not the currentXML
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index 2ae2ce46e..220429a5c 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -66,6 +66,7 @@ class SetupHelper:
         from AlignMonitor import AlignMonitor
         alignMonitor = AlignMonitor(self.alignConf, n_it)
         alignMonitor.performMonitoring(compareXML)
+        return alignMonitor.isInsane
 
     def finalize(self, conv, n_it, compareXML, farm_config_time, elapsed_runtimes, DBUpdated, nEventsListList):
         nEventsList = nEventsListList[0]
@@ -437,7 +438,3 @@ class SetupHelper:
         subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
   
         return 0
-    
-    def insanity(self):
-        # perform sanity Checks
-        return False
\ No newline at end of file
-- 
GitLab


From fd6da99c9a7b3468381865aa52a1a6f150bda23b Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Mon, 26 Jun 2017 14:01:58 +0200
Subject: [PATCH 28/59] fixed typos

---
 .../python/PyMirrAlignOnline/Iterator.py                      | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 2241e43e0..f27ab303c 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -360,13 +360,13 @@ def run(whichRich):
 
           nEventsListList = setupHelper.getNEventsListList(n_it)
           if nEventsListList[1] < int(alignConf.getProp('requiredEvents')):
-              if autoUpdate is True:
+              if autoUpdate:
                 autoUpdate = False
                 print "INFO: We processed an average number of events per iteration of " + str(nEventsListList[1]) + ", which is too low to allow mirror alignment " + setupHelper.directoryTime + " to automatically update, should an update be deemed necessary."
                 setupHelper.sendEmail( 'autoUpdate disabled for RICH' + str(whichRich) + ' alignment ' + setupHelper.directoryTime + '.' , 'RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' will not automatically be updated, should an update be deemed necessary. \n Average number of events processed per iteration: ' + str(nEventsListList[1]) , setupHelper.emails)        
           sys.stdout.flush()
           if insane and not forcedUpdate_ChMagPol: # We disable the sanity check on magnet polarity change, because we expect a large variation
-              if autoUpdate is True:
+              if autoUpdate:
                 autoUpdate = False
                 print "INFO: Sanity checks have failed, we will not allow mirror alignment " + setupHelper.directoryTime + " to automatically update, should an update be deemed necessary."
                 setupHelper.sendEmail( 'autoUpdate disabled for RICH' + str(whichRich) + ' alignment ' + setupHelper.directoryTime + '.' , 'RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' will not automatically be updated, should an update be deemed necessary. \n Sanity checks have failed for this alignment.' , setupHelper.emails)        
-- 
GitLab


From 69cc65940aaa84a5ec73299ede831ddc8b2acd86 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Mon, 26 Jun 2017 14:07:40 +0200
Subject: [PATCH 29/59] fixed typo

---
 .../python/PyMirrAlignOnline/SetupHelper.py                     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index 220429a5c..9f7f9cd10 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -92,7 +92,7 @@ class SetupHelper:
         #shutil.copy2(ChangeWRTDBFile, self.savedir)
         AlignSummaryFile = self.workdir + "/Rich" + str(self.whichRich) + '_AlignSummary.pdf'    
         #shutil.copy2(AlignSummaryFile, self.savedir)
-        AlignMonitorFile = self.workdir + "/Rich" + str(self.whichRich) + '_AlignMonitor.pdf'    
+        #AlignMonitorFile = self.workdir + "/Rich" + str(self.whichRich) + '_AlignMonitor.pdf'    
         #shutil.copy2(AlignMonitorFile, self.savedir)
         #AlignTestingFile = self.workdir + "/Rich" + str(self.whichRich) + '_AlignTesting.pdf'    
         #if os.path.exists(AlignTestingFile):
-- 
GitLab


From 8c3636359481a6809539f8c7451a5d3597af1a22 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Mon, 26 Jun 2017 14:14:56 +0200
Subject: [PATCH 30/59] fixed typo (2)

---
 .../python/PyMirrAlignOnline/Iterator.py                    | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index f27ab303c..383a9688d 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -351,20 +351,20 @@ def run(whichRich):
 
           elapsed_runtimes['elapsed_time_run'] = time() - start_time_run # Actual total iterating time
           print "INFO: Elapsed time to run the Mirror Alignment set as", elapsed_runtimes['elapsed_time_run'], "seconds."
-
           sys.stdout.flush()  
 
           # Run the monitoring, send plots to the Presenter, and generate PDF files;
           #   this returns True if any sanity check failed.
           insane = setupHelper.monitor(n_it, compareXML)
-
+          print "INFO: alignMonitor.isInsane = " + str(insane)
+          sys.stdout.flush()
+          
           nEventsListList = setupHelper.getNEventsListList(n_it)
           if nEventsListList[1] < int(alignConf.getProp('requiredEvents')):
               if autoUpdate:
                 autoUpdate = False
                 print "INFO: We processed an average number of events per iteration of " + str(nEventsListList[1]) + ", which is too low to allow mirror alignment " + setupHelper.directoryTime + " to automatically update, should an update be deemed necessary."
                 setupHelper.sendEmail( 'autoUpdate disabled for RICH' + str(whichRich) + ' alignment ' + setupHelper.directoryTime + '.' , 'RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' will not automatically be updated, should an update be deemed necessary. \n Average number of events processed per iteration: ' + str(nEventsListList[1]) , setupHelper.emails)        
-          sys.stdout.flush()
           if insane and not forcedUpdate_ChMagPol: # We disable the sanity check on magnet polarity change, because we expect a large variation
               if autoUpdate:
                 autoUpdate = False
-- 
GitLab


From e27087172f8f539ce42bb2cd87b34f794e39eb68 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Mon, 26 Jun 2017 14:21:33 +0200
Subject: [PATCH 31/59] removed compareXML from inputs to SetupHelper.finalize,
 it is not needed there

---
 .../python/PyMirrAlignOnline/Iterator.py                  | 8 ++++----
 .../python/PyMirrAlignOnline/SetupHelper.py               | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 383a9688d..f7e19cee6 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -378,17 +378,17 @@ def run(whichRich):
           if (forcedUpdate_ChMagPol or updateHelper.updateDecision(n_it)) and conv:
               if autoUpdate:
                 xmlHelper.finalXML( str(int(latest_vN) + 1) , True) # current + 1
-                setupHelper.finalize(conv, n_it, compareXML, elapsed_time_config, elapsed_runtimes, True, nEventsListList)
+                setupHelper.finalize(conv, n_it, elapsed_time_config, elapsed_runtimes, True, nEventsListList)
                 if testing is not True:
                     updateHelper.updateDB( int(latest_vN) + 1 , True) # current + 1
               else:
                 xmlHelper.finalXML( str(int(latest_vN) + 1) + '_maybe_' + setupHelper.directoryTime, True) # (current + 1)_maybe
-                setupHelper.finalize(conv, n_it, compareXML, elapsed_time_config, elapsed_runtimes, None, nEventsListList)
+                setupHelper.finalize(conv, n_it, elapsed_time_config, elapsed_runtimes, None, nEventsListList)
                 if testing is not True:
                     updateHelper.updateDB( int(latest_vN) , False)
               #updateHelper.stopUpdateDIM()    
           else:
-              setupHelper.finalize(conv, n_it, compareXML, elapsed_time_config, elapsed_runtimes, False, nEventsListList)
+              setupHelper.finalize(conv, n_it, elapsed_time_config, elapsed_runtimes, False, nEventsListList)
               if testing is not True:
                   updateHelper.updateDB( int(latest_vN) , False) # current 
                   #updateHelper.stopUpdateDIM()  
@@ -430,7 +430,7 @@ def run(whichRich):
       elapsed_runtimes['elapsed_time_run'] = time() - start_time_run # Actual iterating time
       print "INFO: Elapsed time to run the Mirror Alignment set as", elapsed_runtimes['elapsed_time_run'], "seconds."
       nEventsListList = setupHelper.getNEventsListList(n_it)
-      setupHelper.finalize(conv, n_it, compareXML, elapsed_time_config, elapsed_runtimes, False, nEventsListList)
+      setupHelper.finalize(conv, n_it, elapsed_time_config, elapsed_runtimes, False, nEventsListList)
       if testing is not True:
           updateHelper.updateDB( int(latest_vN) , False) # current
           #updateHelper.stopUpdateDIM()   
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index 9f7f9cd10..0f22eedf1 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -68,7 +68,7 @@ class SetupHelper:
         alignMonitor.performMonitoring(compareXML)
         return alignMonitor.isInsane
 
-    def finalize(self, conv, n_it, compareXML, farm_config_time, elapsed_runtimes, DBUpdated, nEventsListList):
+    def finalize(self, conv, n_it, farm_config_time, elapsed_runtimes, DBUpdated, nEventsListList):
         nEventsList = nEventsListList[0]
         nEvents = nEventsListList[1]
         
-- 
GitLab


From 5bb704684d85ae21edcf094c0f3aa279329612dc Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Mon, 26 Jun 2017 18:06:49 +0200
Subject: [PATCH 32/59] slight change to 2D plot style

---
 .../python/PyMirrAlignOnline/AlignMonitor.py  | 24 +++++++++----------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 3e5d06d63..25a4b7029 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -224,12 +224,12 @@ class AlignMonitor:
             heatHistoSecZ.SetMarkerSize(1.8*self.origMarkerSize)
             numbersHistoPri.SetMarkerSize(0.9*self.origMarkerSize)
             numbersHistoSec.SetMarkerSize(0.9*self.origMarkerSize)
-            heatHistoPriY.SetBarOffset(0.2)
-            heatHistoPriZ.SetBarOffset(0.2)
-            heatHistoSecY.SetBarOffset(0.2)
-            heatHistoSecZ.SetBarOffset(0.2)
-            numbersHistoPri.SetBarOffset(-0.2)
-            numbersHistoSec.SetBarOffset(-0.2)
+            heatHistoPriY.SetBarOffset(-0.2)
+            heatHistoPriZ.SetBarOffset(-0.2)
+            heatHistoSecY.SetBarOffset(-0.2)
+            heatHistoSecZ.SetBarOffset(-0.2)
+            numbersHistoPri.SetBarOffset(0.2)
+            numbersHistoSec.SetBarOffset(0.2)
             heatHistoPriY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Y rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
             heatHistoPriZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
             heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
@@ -342,12 +342,12 @@ class AlignMonitor:
             heatHistoSecZ.SetMarkerSize(1.8*self.origMarkerSize)
             numbersHistoPri.SetMarkerSize(0.9*self.origMarkerSize)
             numbersHistoSec.SetMarkerSize(0.9*self.origMarkerSize)
-            heatHistoPriY.SetBarOffset(0.2)
-            heatHistoPriZ.SetBarOffset(0.2)
-            heatHistoSecY.SetBarOffset(0.2)
-            heatHistoSecZ.SetBarOffset(0.2)
-            numbersHistoPri.SetBarOffset(-0.2)
-            numbersHistoSec.SetBarOffset(-0.2)
+            heatHistoPriY.SetBarOffset(-0.2)
+            heatHistoPriZ.SetBarOffset(-0.2)
+            heatHistoSecY.SetBarOffset(-0.2)
+            heatHistoSecZ.SetBarOffset(-0.2)
+            numbersHistoPri.SetBarOffset(0.2)
+            numbersHistoSec.SetBarOffset(0.2)
             heatHistoPriY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Y rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
             heatHistoPriZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
             heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
-- 
GitLab


From 47f861e0e306af34d110f67b1dc5472495f4b2c4 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Tue, 27 Jun 2017 12:01:18 +0200
Subject: [PATCH 33/59] Fixed bug

---
 .../python/PyMirrAlignOnline/AlignMonitor.py           | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 25a4b7029..18d851eab 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -162,11 +162,6 @@ class AlignMonitor:
             # sets priYtrunc, etc... otherwise these will be empty
             mirrtilts[its].setTrunc(digits = 2)
             
-            # sanity check
-            if its == self.maxIt:
-                if biggestTilt[its][0] >= 3*self.sTPY or biggestTilt[its][1] >= 3*self.sTPZ or biggestTilt[its][2] >= 3*self.sTSY or biggestTilt[its][3] >= 3*self.sTSZ:
-                    self.isInsane = True
-            
             rowsPri = len(self.binToPriMirr)
             colsPri = len(self.binToPriMirr[0])
             for row in xrange(rowsPri):
@@ -189,6 +184,11 @@ class AlignMonitor:
             #   and in a controlled manner across all possible mirrors and tilts.    
             biggestTilt[its] = mirrtilts[its].getAbsMax() 
             
+            # sanity check
+            if its == self.maxIt:
+                if biggestTilt[its][0] >= 3*self.sTPY or biggestTilt[its][1] >= 3*self.sTPZ or biggestTilt[its][2] >= 3*self.sTSY or biggestTilt[its][3] >= 3*self.sTSZ:
+                    self.isInsane = True
+            
             # Flexible range plotting style
             for self.nFlex in reversed(range(0,35)):
                 if biggestTilt[its][0] >= self.nFlex*self.sTPY or biggestTilt[its][1] >= self.nFlex*self.sTPZ or biggestTilt[its][2] >= self.nFlex*self.sTSY or biggestTilt[its][3] >= self.nFlex*self.sTSZ:
-- 
GitLab


From ef2982bc7d7a3099946e86812bd5b07caba66a02 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Tue, 27 Jun 2017 13:20:12 +0200
Subject: [PATCH 34/59] Fixed bug

---
 .../python/PyMirrAlignOnline/AlignMonitor.py             | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 18d851eab..3993da8c9 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -1,7 +1,7 @@
 # Authors: Paras Naik, Claire Prouve
 
 import sys, numpy
-from ROOT import TH1D, TCanvas, TFile, TF1, gStyle, TGraph, TMultiGraph, TLine, TH2D
+from ROOT import TH1D, TCanvas, TFile, TF1, gStyle, TGraph, TMultiGraph, TLine, TH2D, TExec
 
 class AlignMonitor:
     def __init__(self, _alignConf, _maxIt, ):
@@ -248,14 +248,19 @@ class AlignMonitor:
             theCanvas.cd(4)
             heatHistoSecZ.Draw("COLZ")
             heatHistoSecZ.Draw("TEXT SAME")
-            gStyle.SetPaintTextFormat('2.0f')
+            execStyle = TExec("ex1","gStyle->SetPaintTextFormat(\"2.0f\");")
+            #gStyle.SetPaintTextFormat('2.0f')
             theCanvas.cd(1)
+            execStyle.Draw()
             numbersHistoPri.Draw("TEXT SAME")
             theCanvas.cd(2)
+            execStyle.Draw()
             numbersHistoPri.Draw("TEXT SAME")
             theCanvas.cd(3)
+            execStyle.Draw()
             numbersHistoSec.Draw("TEXT SAME")
             theCanvas.cd(4)
+            execStyle.Draw()
             numbersHistoSec.Draw("TEXT SAME")
             
             theCanvas.Print(expertFile + '(')
-- 
GitLab


From b58c0772cb4675a17fcc4734828ebbebb1b81645 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Tue, 27 Jun 2017 13:36:29 +0200
Subject: [PATCH 35/59] Fixed bug

---
 .../python/PyMirrAlignOnline/AlignMonitor.py   | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 3993da8c9..1e10f9cde 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -234,33 +234,37 @@ class AlignMonitor:
             heatHistoPriZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
             heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
             heatHistoSecZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Z rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
+            execStyle1 = TExec("execStyle1","gStyle->SetPaintTextFormat(\"4.2f\");")  # formerly 5.3f
+            execStyle2 = TExec("execStyle2","gStyle->SetPaintTextFormat(\"2.0f\");")
 
-            gStyle.SetPaintTextFormat('4.2f') # formerly 5.3f
             theCanvas.cd(1)
             heatHistoPriY.Draw("COLZ")
+            execStyle1.Draw()
             heatHistoPriY.Draw("TEXT SAME")
             theCanvas.cd(2)
             heatHistoPriZ.Draw("COLZ")
+            execStyle1.Draw()
             heatHistoPriZ.Draw("TEXT SAME")
             theCanvas.cd(3)
             heatHistoSecY.Draw("COLZ")
+            execStyle1.Draw()
             heatHistoSecY.Draw("TEXT SAME")
             theCanvas.cd(4)
             heatHistoSecZ.Draw("COLZ")
+            execStyle1.Draw()
             heatHistoSecZ.Draw("TEXT SAME")
-            execStyle = TExec("ex1","gStyle->SetPaintTextFormat(\"2.0f\");")
-            #gStyle.SetPaintTextFormat('2.0f')
+
             theCanvas.cd(1)
-            execStyle.Draw()
+            execStyle2.Draw()
             numbersHistoPri.Draw("TEXT SAME")
             theCanvas.cd(2)
-            execStyle.Draw()
+            execStyle2.Draw()
             numbersHistoPri.Draw("TEXT SAME")
             theCanvas.cd(3)
-            execStyle.Draw()
+            execStyle2.Draw()
             numbersHistoSec.Draw("TEXT SAME")
             theCanvas.cd(4)
-            execStyle.Draw()
+            execStyle2.Draw()
             numbersHistoSec.Draw("TEXT SAME")
             
             theCanvas.Print(expertFile + '(')
-- 
GitLab


From 9579736f6d4a2ad0314403ab05d87e7b85078ae6 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Tue, 27 Jun 2017 13:54:49 +0200
Subject: [PATCH 36/59] Add small offset to results of setTrunc and setDiv in
 order to make sure the color is correct at the contour boundary.

---
 .../python/PyMirrAlignOnline/AlignMonitor.py  | 32 +++++++++----------
 .../python/PyMirrAlignOnline/tiltObj.py       | 16 +++++-----
 2 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 1e10f9cde..e8d933ba8 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -222,14 +222,14 @@ class AlignMonitor:
             heatHistoPriZ.SetMarkerSize(1.8*self.origMarkerSize)
             heatHistoSecY.SetMarkerSize(1.8*self.origMarkerSize)
             heatHistoSecZ.SetMarkerSize(1.8*self.origMarkerSize)
-            numbersHistoPri.SetMarkerSize(0.9*self.origMarkerSize)
-            numbersHistoSec.SetMarkerSize(0.9*self.origMarkerSize)
-            heatHistoPriY.SetBarOffset(-0.2)
-            heatHistoPriZ.SetBarOffset(-0.2)
-            heatHistoSecY.SetBarOffset(-0.2)
-            heatHistoSecZ.SetBarOffset(-0.2)
-            numbersHistoPri.SetBarOffset(0.2)
-            numbersHistoSec.SetBarOffset(0.2)
+            numbersHistoPri.SetMarkerSize(1.2*self.origMarkerSize)
+            numbersHistoSec.SetMarkerSize(1.2*self.origMarkerSize)
+            heatHistoPriY.SetBarOffset(-0.175)
+            heatHistoPriZ.SetBarOffset(-0.175)
+            heatHistoSecY.SetBarOffset(-0.175)
+            heatHistoSecZ.SetBarOffset(-0.175)
+            numbersHistoPri.SetBarOffset(0.175)
+            numbersHistoSec.SetBarOffset(0.175)
             heatHistoPriY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Y rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
             heatHistoPriZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
             heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
@@ -349,14 +349,14 @@ class AlignMonitor:
             heatHistoPriZ.SetMarkerSize(1.8*self.origMarkerSize)
             heatHistoSecY.SetMarkerSize(1.8*self.origMarkerSize)
             heatHistoSecZ.SetMarkerSize(1.8*self.origMarkerSize)
-            numbersHistoPri.SetMarkerSize(0.9*self.origMarkerSize)
-            numbersHistoSec.SetMarkerSize(0.9*self.origMarkerSize)
-            heatHistoPriY.SetBarOffset(-0.2)
-            heatHistoPriZ.SetBarOffset(-0.2)
-            heatHistoSecY.SetBarOffset(-0.2)
-            heatHistoSecZ.SetBarOffset(-0.2)
-            numbersHistoPri.SetBarOffset(0.2)
-            numbersHistoSec.SetBarOffset(0.2)
+            numbersHistoPri.SetMarkerSize(1.2*self.origMarkerSize)
+            numbersHistoSec.SetMarkerSize(1.2*self.origMarkerSize)
+            heatHistoPriY.SetBarOffset(-0.175)
+            heatHistoPriZ.SetBarOffset(-0.175)
+            heatHistoSecY.SetBarOffset(-0.175)
+            heatHistoSecZ.SetBarOffset(-0.175)
+            numbersHistoPri.SetBarOffset(0.175)
+            numbersHistoSec.SetBarOffset(0.175)
             heatHistoPriY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Y rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
             heatHistoPriZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
             heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/tiltObj.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/tiltObj.py
index 10ad3be81..bb12a54d3 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/tiltObj.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/tiltObj.py
@@ -167,28 +167,28 @@ class tiltObj:
         divisor = float(math.pow(10, int(digits)))
         for pY in self.priY.keys():
             if not abs(self.priY[pY]) < math.pow(10, int(0-digits)):
-                self.priYtrunc[pY] = math.floor(self.priY[pY]*divisor)/divisor if self.priY[pY] >= 0. else math.ceil(self.priY[pY]*divisor)/divisor
+                self.priYtrunc[pY] = math.floor(self.priY[pY]*divisor)/divisor + 0.0000001 if self.priY[pY] >= 0. else math.ceil(self.priY[pY]*divisor)/divisor - 0.0000001
             elif self.priY[pY] >= 0:
                 self.priYtrunc[pY] = 0.0000001
             else:
                 self.priYtrunc[pY] = -0.0000001               
         for pZ in self.priZ.keys():
             if not abs(self.priZ[pZ]) < math.pow(10, int(0-digits)):
-                self.priZtrunc[pZ] = math.floor(self.priZ[pZ]*divisor)/divisor if self.priZ[pZ] >= 0. else math.ceil(self.priZ[pZ]*divisor)/divisor
+                self.priZtrunc[pZ] = math.floor(self.priZ[pZ]*divisor)/divisor + 0.0000001 if self.priZ[pZ] >= 0. else math.ceil(self.priZ[pZ]*divisor)/divisor - 0.0000001
             elif self.priZ[pZ] >= 0:
                 self.priZtrunc[pZ] = 0.0000001
             else:
                 self.priZtrunc[pZ] = -0.0000001     
         for sY in self.secY.keys():
             if not abs(self.secY[sY]) < math.pow(10, int(0-digits)):
-                self.secYtrunc[sY] = math.floor(self.secY[sY]*divisor)/divisor if self.secY[sY] >= 0. else math.ceil(self.secY[sY]*divisor)/divisor
+                self.secYtrunc[sY] = math.floor(self.secY[sY]*divisor)/divisor + 0.0000001 if self.secY[sY] >= 0. else math.ceil(self.secY[sY]*divisor)/divisor - 0.0000001
             elif self.secY[sY] >= 0:
                 self.secYtrunc[sY] = 0.0000001
             else:
                 self.secYtrunc[sY] = -0.0000001        
         for sZ in self.secZ.keys():
             if not abs(self.secZ[sZ]) < math.pow(10, int(0-digits)):
-                self.secZtrunc[sZ] = math.floor(self.secZ[sZ]*divisor)/divisor if self.secZ[sZ] >= 0. else math.ceil(self.secZ[sZ]*divisor)/divisor
+                self.secZtrunc[sZ] = math.floor(self.secZ[sZ]*divisor)/divisor + 0.0000001 if self.secZ[sZ] >= 0. else math.ceil(self.secZ[sZ]*divisor)/divisor - 0.0000001
             elif self.secZ[sZ] >= 0:
                 self.secZtrunc[sZ] = 0.0000001
             else:
@@ -207,28 +207,28 @@ class tiltObj:
             tolerances = [0.1,0.1,0.1,0.1]
         for pY in self.priY.keys():
             if not abs(self.priY[pY]/tolerances[0]) < math.pow(10, int(0-digits)):
-                self.priYdiv[pY] = math.floor(self.priY[pY]/tolerances[0]*divisor)/divisor if self.priY[pY] >= 0. else math.ceil(self.priY[pY]/tolerances[0]*divisor)/divisor
+                self.priYdiv[pY] = math.floor(self.priY[pY]/tolerances[0]*divisor)/divisor + 0.0000001 if self.priY[pY] >= 0. else math.ceil(self.priY[pY]/tolerances[0]*divisor)/divisor - 0.0000001 
             elif self.priY[pY] >= 0:
                 self.priYdiv[pY] = 0.0000001
             else:
                 self.priYdiv[pY] = -0.0000001    
         for pZ in self.priZ.keys():
             if not abs(self.priZ[pZ]/tolerances[1]) < math.pow(10, int(0-digits)):
-                self.priZdiv[pZ] = math.floor(self.priZ[pZ]/tolerances[1]*divisor)/divisor if self.priZ[pZ] >= 0. else math.ceil(self.priZ[pZ]/tolerances[1]*divisor)/divisor
+                self.priZdiv[pZ] = math.floor(self.priZ[pZ]/tolerances[1]*divisor)/divisor + 0.0000001 if self.priZ[pZ] >= 0. else math.ceil(self.priZ[pZ]/tolerances[1]*divisor)/divisor - 0.0000001 
             elif self.priZ[pZ] >= 0:
                 self.priZdiv[pZ] = 0.0000001
             else:
                 self.priZdiv[pZ] = -0.0000001   
         for sY in self.secY.keys():
             if not abs(self.secY[sY]/tolerances[2]) < math.pow(10, int(0-digits)):
-                self.secYdiv[sY] = math.floor(self.secY[sY]/tolerances[2]*divisor)/divisor if self.secY[sY] >= 0. else math.ceil(self.secY[sY]/tolerances[2]*divisor)/divisor
+                self.secYdiv[sY] = math.floor(self.secY[sY]/tolerances[2]*divisor)/divisor + 0.0000001 if self.secY[sY] >= 0. else math.ceil(self.secY[sY]/tolerances[2]*divisor)/divisor - 0.0000001 
             elif self.secY[sY] >= 0:
                 self.secYdiv[sY] = 0.0000001
             else:
                 self.secYdiv[sY] = -0.0000001  
         for sZ in self.secZ.keys():
             if not abs(self.secZ[sZ]/tolerances[3]) < math.pow(10, int(0-digits)):
-                self.secZdiv[sZ] = math.floor(self.secZ[sZ]/tolerances[3]*divisor)/divisor if self.secZ[sZ] >= 0. else math.ceil(self.secZ[sZ]/tolerances[3]*divisor)/divisor
+                self.secZdiv[sZ] = math.floor(self.secZ[sZ]/tolerances[3]*divisor)/divisor + 0.0000001 if self.secZ[sZ] >= 0. else math.ceil(self.secZ[sZ]/tolerances[3]*divisor)/divisor - 0.0000001 
             elif self.secZ[sZ] >= 0:
                 self.secZdiv[sZ] = 0.0000001
             else:
-- 
GitLab


From b021814a3e84f59f902728c8eb6aebcbf0333f59 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Tue, 27 Jun 2017 17:51:10 +0200
Subject: [PATCH 37/59] Send a starting message to the ELOG

---
 .../python/PyMirrAlignOnline/Iterator.py                       | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index f7e19cee6..13462c8cc 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -159,6 +159,9 @@ def run(whichRich):
       leadText += 'TEST [' + alignConf.getProp('dataVariant') + ']: '
     setupHelper.sendEmail( leadText + preSubject + 'RICH' + str(whichRich) + ' alignment ' + setupHelper.directoryTime + ' has started.' + postSubject , preText + ' RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' has started. \n Runs: ' + str(runs) + ' \n Fills: ' + str(fills) + ' \n Polarities: ' + str(polsStr) + postText + ' \n dataVariant: ' + alignConf.getProp('dataVariant'), setupHelper.emails)        
     print 'INFO: RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' has started, dataVariant: ' + alignConf.getProp('dataVariant')
+    subject = "has started."
+    text = "that it has started. If it does not finish, please report this via the RICH ELOG."
+    setupHelper.quickWriteInLogbook(subject, text)
 
   sys.stdout.flush()
 
-- 
GitLab


From e52b18a79e5369cc6937c6f2ddaeb8618ef580c3 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Tue, 27 Jun 2017 18:13:07 +0200
Subject: [PATCH 38/59] remove junk from log file

---
 .../python/PyMirrAlignOnline/Iterator.py                 | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 13462c8cc..58c2b529c 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -507,11 +507,16 @@ def run(whichRich):
   sys.stdout.flush()
     
   try:
-    print "INFO: logging hlt02 ended, storing in file: " + setupHelper.savedir + 'hlt02.log'
+    print 'INFO: logging hlt02 ended, storing in file: ' + setupHelper.savedir + 'hlt02.log'
     shutil.copy2(loggingDir + 'Rich' + str(whichRich) + '_' + 'hlt02.log', setupHelper.savedir + 'hlt02.log')  
+    # remove what we currently believe are extraneous items
+    os.system('grep -vE "(tmSrv|LHCb2_HLT02_Hlt2Adder_0|Hlt2SaverSvc|MARK)" ' + setupHelper.savedir + 'hlt02.log > ' + setupHelper.savedir + 'hlt02_reduced.log')
   except:
-    print "INFO: logging hlt02 ended, storing in file: " + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log'
+    print 'INFO: logging hlt02 ended, storing in file: ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log'
     shutil.copy2(loggingDir + 'Rich' + str(whichRich) + '_' + 'hlt02.log', loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log')  
+    os.system('grep -vE "(tmSrv|LHCb2_HLT02_Hlt2Adder_0|Hlt2SaverSvc|MARK)" ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log > ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log')
+    # remove what we currently believe are extraneous items
+
   sys.stdout.flush()  
   
   sleep(5)
-- 
GitLab


From 6c96dec4e4b6d8c4a3fabb63e479b290e1d4fd32 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Tue, 27 Jun 2017 18:18:16 +0200
Subject: [PATCH 39/59] remove junk from log file (2)

---
 .../python/PyMirrAlignOnline/Iterator.py                        | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 58c2b529c..56f9d534c 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -514,8 +514,8 @@ def run(whichRich):
   except:
     print 'INFO: logging hlt02 ended, storing in file: ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log'
     shutil.copy2(loggingDir + 'Rich' + str(whichRich) + '_' + 'hlt02.log', loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log')  
-    os.system('grep -vE "(tmSrv|LHCb2_HLT02_Hlt2Adder_0|Hlt2SaverSvc|MARK)" ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log > ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log')
     # remove what we currently believe are extraneous items
+    os.system('grep -vE "(tmSrv|LHCb2_HLT02_Hlt2Adder_0|Hlt2SaverSvc|MARK)" ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log > ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log')
 
   sys.stdout.flush()  
   
-- 
GitLab


From fed94b661cc1ad5db256872a2710b2aef9e9bc87 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Tue, 27 Jun 2017 18:30:48 +0200
Subject: [PATCH 40/59] typo fix

---
 .../python/PyMirrAlignOnline/SetupHelper.py                     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index 0f22eedf1..2f5433e9a 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -409,7 +409,7 @@ class SetupHelper:
         text += str(activity)
         text += " for RICH"
         text += str(self.whichRich)
-        text += "is reporting "
+        text += " is reporting "
         text += textB
         text += " Shifter's instructions can be found at "
         text += str(instruction_file)
-- 
GitLab


From 63b8573d5cf18616e3a5b9f8aaf79782bd0ebfba Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Tue, 27 Jun 2017 18:57:01 +0200
Subject: [PATCH 41/59] extend sleep time at end so that log file can be moved

---
 .../python/PyMirrAlignOnline/Iterator.py                      | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 56f9d534c..76bcee573 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -505,6 +505,8 @@ def run(whichRich):
     # can't kill a dead process
     print "INFO: hlt02 logProcess already dead."
   sys.stdout.flush()
+  
+  sleep(2)
     
   try:
     print 'INFO: logging hlt02 ended, storing in file: ' + setupHelper.savedir + 'hlt02.log'
@@ -519,7 +521,7 @@ def run(whichRich):
 
   sys.stdout.flush()  
   
-  sleep(5)
+  sleep(11)
      
 if __name__ == '__main__':
     run()
-- 
GitLab


From e4504cc91bde5efd8f526b2af65101d037083276 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Tue, 27 Jun 2017 18:59:29 +0200
Subject: [PATCH 42/59] extend sleep time at end so that log file can be moved
 (2)

---
 .../python/PyMirrAlignOnline/Iterator.py                  | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 76bcee573..ab6be6aca 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -511,12 +511,14 @@ def run(whichRich):
   try:
     print 'INFO: logging hlt02 ended, storing in file: ' + setupHelper.savedir + 'hlt02.log'
     shutil.copy2(loggingDir + 'Rich' + str(whichRich) + '_' + 'hlt02.log', setupHelper.savedir + 'hlt02.log')  
-    # remove what we currently believe are extraneous items
-    os.system('grep -vE "(tmSrv|LHCb2_HLT02_Hlt2Adder_0|Hlt2SaverSvc|MARK)" ' + setupHelper.savedir + 'hlt02.log > ' + setupHelper.savedir + 'hlt02_reduced.log')
   except:
     print 'INFO: logging hlt02 ended, storing in file: ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log'
     shutil.copy2(loggingDir + 'Rich' + str(whichRich) + '_' + 'hlt02.log', loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log')  
-    # remove what we currently believe are extraneous items
+    
+  # remove what we currently believe are extraneous items
+  try:
+    os.system('grep -vE "(tmSrv|LHCb2_HLT02_Hlt2Adder_0|Hlt2SaverSvc|MARK)" ' + setupHelper.savedir + 'hlt02.log > ' + setupHelper.savedir + 'hlt02_reduced.log')
+  except:  
     os.system('grep -vE "(tmSrv|LHCb2_HLT02_Hlt2Adder_0|Hlt2SaverSvc|MARK)" ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log > ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log')
 
   sys.stdout.flush()  
-- 
GitLab


From 5d99582c710846ba4f80784af14a8648d8ea503e Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Tue, 27 Jun 2017 19:07:00 +0200
Subject: [PATCH 43/59] typo fix

---
 .../python/PyMirrAlignOnline/Iterator.py                      | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index ab6be6aca..c2bbc6aa9 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -517,9 +517,9 @@ def run(whichRich):
     
   # remove what we currently believe are extraneous items
   try:
-    os.system('grep -vE "(tmSrv|LHCb2_HLT02_Hlt2Adder_0|Hlt2SaverSvc|MARK)" ' + setupHelper.savedir + 'hlt02.log > ' + setupHelper.savedir + 'hlt02_reduced.log')
+    os.system('grep -vE "(tmSrv|LHCb2_HLT02_Hlt2Adder_0|Hlt2SaverSvc|MARK|GEN_hlt02_BusyMon)" ' + setupHelper.savedir + 'hlt02.log > ' + setupHelper.savedir + 'hlt02_reduced.log')
   except:  
-    os.system('grep -vE "(tmSrv|LHCb2_HLT02_Hlt2Adder_0|Hlt2SaverSvc|MARK)" ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log > ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log')
+    os.system('grep -vE "(tmSrv|LHCb2_HLT02_Hlt2Adder_0|Hlt2SaverSvc|MARK|GEN_hlt02_BusyMon)" ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log > ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log')
 
   sys.stdout.flush()  
   
-- 
GitLab


From 3f8210efa49b3f7cc6f20a55a3bbea3edad20a74 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Wed, 28 Jun 2017 18:55:30 +0200
Subject: [PATCH 44/59] Now sending deltaTheta histograms to prsenter without
 hist->fit attached

---
 .../python/PyMirrAlignOnline/AlignMonitor.py  | 31 ++++++++++---------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index e8d933ba8..2e930c7f8 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -472,31 +472,32 @@ class AlignMonitor:
             filename[j] = self.workdir + '/' + self.prename + 'i' +  str(j) + '.root'
             if os.path.exists(filename[j]):    
                 thisFile[j] = TFile(filename[j], 'read')
-                hist[j] = (thisFile[j].Get('RICH/RiCKResLongTightMirror/Rich' + str(self.whichRich) + 'Gas/ckResAll')).Clone()
-                fitRes[j] = self.fitCherenkovAngle(hist[j])
-                resHistograms[j] = fitRes[j][0]       
-                resHistoTrend.SetBinContent(j+1, fitRes[j][1] * 1000)
-                resHistoTrend.SetBinError(j+1, fitRes[j][2] * 1000)        
+                hist[j] = (thisFile[j].Get('RICH/RiCKResLongTightMirror/Rich' + str(self.whichRich) + 'Gas/ckResAll')).Clone()  
 
-                title[j] = 'RICH ' + str(self.whichRich) + ' Cherenkov angle resolution It. ' + str(j) 
                 if (j == 0) and (j == self.maxIt) :
-                    resHistograms[j].SetName('resHisto0')
-                    self.monSvc.publishHistogram(self.monitoring_folder, resHistograms[j].Clone(), add=False)
+                    hist[j].SetName('resHisto0')
+                    self.monSvc.publishHistogram(self.monitoring_folder, hist[j].Clone(), add=False)
                     print "INFO: resHisto0 sent to Monitoring."  
-                    resHistograms[j].SetName('resHistoN')
-                    self.monSvc.publishHistogram(self.monitoring_folder, resHistograms[j].Clone(), add=False)
+                    hist[j].SetName('resHistoN')
+                    self.monSvc.publishHistogram(self.monitoring_folder, hist[j].Clone(), add=False)
                     print "INFO: resHistoN sent to Monitoring."                  
                 elif (j == self.maxIt):
-                    resHistograms[j].SetName('resHistoN')
-                    self.monSvc.publishHistogram(self.monitoring_folder, resHistograms[j].Clone(), add=False)
+                    hist[j].SetName('resHistoN')
+                    self.monSvc.publishHistogram(self.monitoring_folder, hist[j].Clone(), add=False)
                     print "INFO: resHistoN sent to Monitoring."
                 elif (j == 0):
-                    resHistograms[j].SetName('resHisto0')
-                    self.monSvc.publishHistogram(self.monitoring_folder, resHistograms[j].Clone(), add=False)
+                    hist[j].SetName('resHisto0')
+                    self.monSvc.publishHistogram(self.monitoring_folder, hist[j].Clone(), add=False)
                     print "INFO: resHisto0 sent to Monitoring." 
                 if (j != 0):     
-                    resHistograms[j].SetName('resHisto'+str(j))
+                    hist[j].SetName('resHisto'+str(j))
 
+                fitRes[j] = self.fitCherenkovAngle(hist[j])
+                resHistograms[j] = fitRes[j][0]       
+                resHistoTrend.SetBinContent(j+1, fitRes[j][1] * 1000)
+                resHistoTrend.SetBinError(j+1, fitRes[j][2] * 1000)      
+
+                title[j] = 'RICH ' + str(self.whichRich) + ' Cherenkov angle resolution It. ' + str(j) 
                 resHistograms[j].SetTitle(title[j])
                 resHistograms[j].SetXTitle('#Delta#theta_{Cherenkov} (rad)')
                 resHistograms[j].SetYTitle('Entries')
-- 
GitLab


From c54a96cf8e5dea1901cc25854089db0be94602e0 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Wed, 28 Jun 2017 19:27:03 +0200
Subject: [PATCH 45/59] trying to fix problem with Log file not being copied

---
 .../python/PyMirrAlignOnline/Iterator.py           | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index c2bbc6aa9..44df2dadc 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -508,22 +508,22 @@ def run(whichRich):
   
   sleep(2)
     
+  removeExtraneous = '(tmSrv|LHCb2_HLT02_Hlt2Adder_0|Hlt2SaverSvc|MARK|GEN_hlt02_BusyMon)'
+    
   try:
     print 'INFO: logging hlt02 ended, storing in file: ' + setupHelper.savedir + 'hlt02.log'
     shutil.copy2(loggingDir + 'Rich' + str(whichRich) + '_' + 'hlt02.log', setupHelper.savedir + 'hlt02.log')  
+    # remove what we currently believe are extraneous items
+    os.system('grep -vE "' + removeExtraneous + '" ' + setupHelper.savedir + 'hlt02.log > ' + setupHelper.savedir + 'hlt02_reduced.log')
   except:
     print 'INFO: logging hlt02 ended, storing in file: ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log'
     shutil.copy2(loggingDir + 'Rich' + str(whichRich) + '_' + 'hlt02.log', loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log')  
-    
-  # remove what we currently believe are extraneous items
-  try:
-    os.system('grep -vE "(tmSrv|LHCb2_HLT02_Hlt2Adder_0|Hlt2SaverSvc|MARK|GEN_hlt02_BusyMon)" ' + setupHelper.savedir + 'hlt02.log > ' + setupHelper.savedir + 'hlt02_reduced.log')
-  except:  
-    os.system('grep -vE "(tmSrv|LHCb2_HLT02_Hlt2Adder_0|Hlt2SaverSvc|MARK|GEN_hlt02_BusyMon)" ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log > ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log')
+    # remove what we currently believe are extraneous items
+    os.system('grep -vE "' + removeExtraneous + '" ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log > ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log')
 
   sys.stdout.flush()  
   
-  sleep(11)
+  sleep(16)
      
 if __name__ == '__main__':
     run()
-- 
GitLab


From ace202973bdc821bbdb8d2c308c06cbb18cdc38a Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Wed, 28 Jun 2017 22:12:32 +0200
Subject: [PATCH 46/59] More fixes to try to get hlt02 log to save properly.
 Added test message to go to Alignment ELOG.

---
 .../python/PyMirrAlignOnline/AlignMonitor.py  |  3 +-
 .../python/PyMirrAlignOnline/Iterator.py      | 37 ++++++++--------
 .../python/PyMirrAlignOnline/SetupHelper.py   | 44 +++++++++++++++++++
 3 files changed, 64 insertions(+), 20 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 2e930c7f8..291d1593e 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -516,7 +516,8 @@ class AlignMonitor:
                 
                 theCanvas2.Print(expertFile)
 
-                theCanvas.cd(j+1)                      
+                theCanvas.cd()
+                theCanvas.cd(1+j)                      
                 resHistograms[j].Draw()
                 polbkg[j].Draw("SAME")   
             
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 44df2dadc..771146659 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -479,6 +479,7 @@ def run(whichRich):
   
   if not os.path.exists(setupHelper.savedir):
     print "INFO: Expect log file to be written to: " + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log'
+    print "INFO: Expect reduced log file to be written to: " + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log'
     if cancel:
       print "INFO: We choose to not execute the mirror alignment. "
       print "INFO: The input data is of mixed polarity, or some it is magnet OFF data."
@@ -488,42 +489,40 @@ def run(whichRich):
     else:
       setupHelper.sendEmail( 'WARNING: RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' did not complete normally.', 'Warning: RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' did not complete normally. \n No output directory was written. \n Log may be found on plus.cern.ch (via lbgw) in /group/rich/AlignmentFiles/Logging/ with timestamp ' + setupHelper.directoryTime + '. \n Runs: ' + str(runs) + ' \n Fills: ' + str(fills) + ' \n Polarities: ' + str(polsStr) + postText + ' \n dataVariant: ' + alignConf.getProp('dataVariant'), setupHelper.emails)        
       print 'WARNING: RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' did not complete normally. No output directory was written.'
-      
   else:
     print "INFO: Expect log file to be written to: " + setupHelper.savedir + 'hlt02.log'
+    print "INFO: Expect reduced log file to be written to: " + setupHelper.savedir + 'hlt02reduced.log'
   sys.stdout.flush()
 
   print "INFO: End of run(whichRich = " + str(whichRich) + "). Killing logProcess and writing hlt02 log file."
   sys.stdout.flush()  
-
-  sleep(2)
-
-  try:
-    logProcess.kill()
-    print "INFO: hlt02 logProcess killed."
-  except OSError:
-    # can't kill a dead process
-    print "INFO: hlt02 logProcess already dead."
-  sys.stdout.flush()
-  
-  sleep(2)
     
+  logProcess.kill()
+  print "INFO: hlt02 logProcess killed."
+  sys.stdout.flush()
+
   removeExtraneous = '(tmSrv|LHCb2_HLT02_Hlt2Adder_0|Hlt2SaverSvc|MARK|GEN_hlt02_BusyMon)'
-    
-  try:
+
+  if os.path.exists(setupHelper.savedir):
     print 'INFO: logging hlt02 ended, storing in file: ' + setupHelper.savedir + 'hlt02.log'
     shutil.copy2(loggingDir + 'Rich' + str(whichRich) + '_' + 'hlt02.log', setupHelper.savedir + 'hlt02.log')  
     # remove what we currently believe are extraneous items
+    print 'INFO: storing reduced file: ' + setupHelper.savedir + 'hlt02reduced.log'
+    print 'INFO: Executing: ' + 'grep -vE "' + removeExtraneous + '" ' + setupHelper.savedir + 'hlt02.log > ' + setupHelper.savedir + 'hlt02_reduced.log'
     os.system('grep -vE "' + removeExtraneous + '" ' + setupHelper.savedir + 'hlt02.log > ' + setupHelper.savedir + 'hlt02_reduced.log')
-  except:
+  else:
     print 'INFO: logging hlt02 ended, storing in file: ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log'
     shutil.copy2(loggingDir + 'Rich' + str(whichRich) + '_' + 'hlt02.log', loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log')  
     # remove what we currently believe are extraneous items
+    print 'INFO: storing reduced file: ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log'
+    print 'INFO: Executing: ' + 'grep -vE "' + removeExtraneous + '" ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log > ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log'
     os.system('grep -vE "' + removeExtraneous + '" ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log > ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log')
-
   sys.stdout.flush()  
-  
-  sleep(16)
+
+  print "INFO: Made it to End"
+  print "INFO: Now sleeping 30"
+  sleep(30)
+  print "INFO: Goodbye!"
      
 if __name__ == '__main__':
     run()
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index 2f5433e9a..34f0f8f78 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -109,6 +109,8 @@ class SetupHelper:
         hh, r = divmod(alignment_time, 3600)
         mm, ss = divmod(r, 60)
         alignment_time_str = "{:0>2}:{:0>2}:{:05.2f}".format(int(hh),int(mm),ss)
+        
+        # RICH ELOG
         host = 'lblogbook.cern.ch' 
         port = 8080
         username = 'common Common\\!'
@@ -190,6 +192,48 @@ class SetupHelper:
         FNULL = open(os.devnull, 'w')
         subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
 
+        # Alignment ELOG
+        logbookAlignment = 'Alignment monitoring'
+        authorAlignment = 'monibot'
+        activityAlignment = 'Rich'+str(self.whichRich)+' Mirrors'
+        TypeAlignment = 'Convergence'
+        #subject = 'Monitoring plots'
+        subjectAlignment = 'This is only a test'
+        StatusAlignment = '' # Good or Bad or Unchecked     
+        
+        command = 'elog -h "'
+        command += str(host)
+        command += '" -p '
+        command += str(port)
+        command += ' -l "'
+        command += str(logbookAlignment)
+        command += '" -u '
+        command += str(username)
+        command += ' -a "Author='
+        command += str(authorAlignment)
+        command += '" -a "System='
+        command += str(activityAlignment)
+        command += '" -a "Subject='
+        command += str(subjectAlignment)
+        command += '" -a "Type='
+        command += str(TypeAlignment)
+        command += '" -a "Status='
+        command += str(StatusAlignment)
+        command += '" "'
+        command += str(text)
+        command += '"'
+        
+#        if os.path.exists(summaryFile):
+#            command += ' -f "{0}"'.format(summaryFile)
+#        if os.path.exists(ChangeWRTDBFile):
+#            command += ' -f "{0}"'.format(ChangeWRTDBFile)
+        if os.path.exists(AlignSummaryFile):
+            command += ' -f "{0}"'.format(AlignSummaryFile)
+        cmd = shlex.split(command)
+        FNULL = open(os.devnull, 'w')
+        subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
+        
+        # Email
         subj2 = ''
         if self.alignConf.getProp('testing') is True:
             subj2 += 'TEST [' + self.alignConf.getProp('dataVariant') + ']: '        
-- 
GitLab


From c3129daf8300c3ad0ed69281bd2c4749fc7e202c Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Wed, 28 Jun 2017 22:20:37 +0200
Subject: [PATCH 47/59] More printouts

---
 .../python/PyMirrAlignOnline/Iterator.py                    | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 771146659..7ec22eab7 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -505,17 +505,23 @@ def run(whichRich):
 
   if os.path.exists(setupHelper.savedir):
     print 'INFO: logging hlt02 ended, storing in file: ' + setupHelper.savedir + 'hlt02.log'
+    sys.stdout.flush()  
     shutil.copy2(loggingDir + 'Rich' + str(whichRich) + '_' + 'hlt02.log', setupHelper.savedir + 'hlt02.log')  
     # remove what we currently believe are extraneous items
     print 'INFO: storing reduced file: ' + setupHelper.savedir + 'hlt02reduced.log'
+    sys.stdout.flush()  
     print 'INFO: Executing: ' + 'grep -vE "' + removeExtraneous + '" ' + setupHelper.savedir + 'hlt02.log > ' + setupHelper.savedir + 'hlt02_reduced.log'
+    sys.stdout.flush()  
     os.system('grep -vE "' + removeExtraneous + '" ' + setupHelper.savedir + 'hlt02.log > ' + setupHelper.savedir + 'hlt02_reduced.log')
   else:
     print 'INFO: logging hlt02 ended, storing in file: ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log'
     shutil.copy2(loggingDir + 'Rich' + str(whichRich) + '_' + 'hlt02.log', loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log')  
+    sys.stdout.flush()  
     # remove what we currently believe are extraneous items
     print 'INFO: storing reduced file: ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log'
+    sys.stdout.flush()  
     print 'INFO: Executing: ' + 'grep -vE "' + removeExtraneous + '" ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log > ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log'
+    sys.stdout.flush()  
     os.system('grep -vE "' + removeExtraneous + '" ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log > ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log')
   sys.stdout.flush()  
 
-- 
GitLab


From edc598bcea1dcb1bf28bf2285eec71cd5fd741b1 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Wed, 28 Jun 2017 23:07:31 +0200
Subject: [PATCH 48/59] More printouts (2)

---
 .../python/PyMirrAlignOnline/Iterator.py         | 16 +++++++++++-----
 .../python/PyMirrAlignOnline/SetupHelper.py      |  7 ++++++-
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 7ec22eab7..30df6a85d 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -496,7 +496,9 @@ def run(whichRich):
 
   print "INFO: End of run(whichRich = " + str(whichRich) + "). Killing logProcess and writing hlt02 log file."
   sys.stdout.flush()  
-    
+  
+  sleep(5)
+  
   logProcess.kill()
   print "INFO: hlt02 logProcess killed."
   sys.stdout.flush()
@@ -525,10 +527,14 @@ def run(whichRich):
     os.system('grep -vE "' + removeExtraneous + '" ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log > ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log')
   sys.stdout.flush()  
 
-  print "INFO: Made it to End"
-  print "INFO: Now sleeping 30"
-  sleep(30)
-  print "INFO: Goodbye!"
+  print "INFO: Now sleeping 25 seconds to let mystery things finish."
+  sys.stdout.flush()  
+
+  sleep(25)
+  
+  print "INFO: Goodbye from the Rich"+str(whichRich)+" Mirror Alignment!"
+  sys.stdout.flush()  
+
      
 if __name__ == '__main__':
     run()
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index 34f0f8f78..770f476b0 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -199,7 +199,10 @@ class SetupHelper:
         TypeAlignment = 'Convergence'
         #subject = 'Monitoring plots'
         subjectAlignment = 'This is only a test'
-        StatusAlignment = '' # Good or Bad or Unchecked     
+        StatusAlignment = '' # Good or Bad or Unchecked  
+        
+        import OnlineEnv as Online
+        FillAlignment = self.getFillNumber(Online.DeferredRuns[0])   
         
         command = 'elog -h "'
         command += str(host)
@@ -217,6 +220,8 @@ class SetupHelper:
         command += str(subjectAlignment)
         command += '" -a "Type='
         command += str(TypeAlignment)
+        command += '" -a "Fill='
+        command += str(FillAlignment)
         command += '" -a "Status='
         command += str(StatusAlignment)
         command += '" "'
-- 
GitLab


From cbc61ea414ec5380c98f01b791c6ef090f99cacf Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Thu, 29 Jun 2017 02:10:28 +0200
Subject: [PATCH 49/59] Small filename change

---
 .../python/PyMirrAlignOnline/Iterator.py      | 22 ++++++++++---------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 30df6a85d..ec1fc9c8c 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -478,8 +478,8 @@ def run(whichRich):
   sys.stdout.flush()
   
   if not os.path.exists(setupHelper.savedir):
-    print "INFO: Expect log file to be written to: " + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log'
-    print "INFO: Expect reduced log file to be written to: " + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log'
+    print "INFO: Expect log file to be written to: " + loggingDir + 'Rich' + str(whichRich) + '_' + setupHelper.directoryTime + '_hlt02.log'
+    print "INFO: Expect reduced log file to be written to: " + loggingDir + 'Rich' + str(whichRich) + '_' + setupHelper.directoryTime + '_hlt02reduced.log'
     if cancel:
       print "INFO: We choose to not execute the mirror alignment. "
       print "INFO: The input data is of mixed polarity, or some it is magnet OFF data."
@@ -497,6 +497,8 @@ def run(whichRich):
   print "INFO: End of run(whichRich = " + str(whichRich) + "). Killing logProcess and writing hlt02 log file."
   sys.stdout.flush()  
   
+  print "INFO: Now sleeping 5 seconds to let output be stored before hlt02 logProcess is killed."
+  sys.stdout.flush()  
   sleep(5)
   
   logProcess.kill()
@@ -512,22 +514,22 @@ def run(whichRich):
     # remove what we currently believe are extraneous items
     print 'INFO: storing reduced file: ' + setupHelper.savedir + 'hlt02reduced.log'
     sys.stdout.flush()  
-    print 'INFO: Executing: ' + 'grep -vE "' + removeExtraneous + '" ' + setupHelper.savedir + 'hlt02.log > ' + setupHelper.savedir + 'hlt02_reduced.log'
+    print 'INFO: Executing: ' + 'grep -vE "' + removeExtraneous + '" ' + setupHelper.savedir + 'hlt02.log > ' + setupHelper.savedir + 'hlt02reduced.log'
     sys.stdout.flush()  
-    os.system('grep -vE "' + removeExtraneous + '" ' + setupHelper.savedir + 'hlt02.log > ' + setupHelper.savedir + 'hlt02_reduced.log')
+    os.system('grep -vE "' + removeExtraneous + '" ' + setupHelper.savedir + 'hlt02.log > ' + setupHelper.savedir + 'hlt02reduced.log')
   else:
-    print 'INFO: logging hlt02 ended, storing in file: ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log'
-    shutil.copy2(loggingDir + 'Rich' + str(whichRich) + '_' + 'hlt02.log', loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log')  
+    print 'INFO: logging hlt02 ended, storing in file: ' + loggingDir + 'Rich' + str(whichRich) + '_' + setupHelper.directoryTime + '_hlt02.log'
+    shutil.copy2(loggingDir + 'Rich' + str(whichRich) + '_' + 'hlt02.log', loggingDir + 'Rich' + str(whichRich) + '_' + setupHelper.directoryTime + '_hlt02.log')  
     sys.stdout.flush()  
     # remove what we currently believe are extraneous items
-    print 'INFO: storing reduced file: ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log'
+    print 'INFO: storing reduced file: ' + loggingDir + 'Rich' + str(whichRich) + '_' + setupHelper.directoryTime + '_hlt02reduced.log'
     sys.stdout.flush()  
-    print 'INFO: Executing: ' + 'grep -vE "' + removeExtraneous + '" ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log > ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log'
+    print 'INFO: Executing: ' + 'grep -vE "' + removeExtraneous + '" ' + loggingDir + 'Rich' + str(whichRich) + '_' + setupHelper.directoryTime + '_hlt02.log > ' + loggingDir + 'Rich' + str(whichRich) + '_' + setupHelper.directoryTime + '_hlt02reduced.log'
     sys.stdout.flush()  
-    os.system('grep -vE "' + removeExtraneous + '" ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02_' + setupHelper.directoryTime + '.log > ' + loggingDir + 'Rich' + str(whichRich) + '_hlt02reduced_' + setupHelper.directoryTime + '.log')
+    os.system('grep -vE "' + removeExtraneous + '" ' + loggingDir + 'Rich' + str(whichRich) + '_' + setupHelper.directoryTime + '_hlt02.log > ' + loggingDir + 'Rich' + str(whichRich) + '_' + setupHelper.directoryTime + '_hlt02reduced.log')
   sys.stdout.flush()  
 
-  print "INFO: Now sleeping 25 seconds to let mystery things finish."
+  print "INFO: Now sleeping 25 seconds to let hlt02 and hlt02reduced log files to be stored."
   sys.stdout.flush()  
 
   sleep(25)
-- 
GitLab


From 476a2081c565b5e92d1653d9a6a9535031e9db22 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Thu, 29 Jun 2017 02:11:32 +0200
Subject: [PATCH 50/59] Small filename change (2)

---
 .../python/PyMirrAlignOnline/Iterator.py                        | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index ec1fc9c8c..7c17f6285 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -17,7 +17,6 @@ from   subprocess import *
 from   distutils  import dir_util
 
 print "INFO: Iterator.py launched at " + strftime("%Y-%m-%d %H:%M:%S", gmtime()) + " UTC"
-print 'INFO: Claire says miezmiezmiez'
 sys.stdout.flush()
 
 ########################################################################################################################                                    
@@ -535,6 +534,7 @@ def run(whichRich):
   sleep(25)
   
   print "INFO: Goodbye from the Rich"+str(whichRich)+" Mirror Alignment!"
+  print 'INFO: Claire says miezmiezmiez'
   sys.stdout.flush()  
 
      
-- 
GitLab


From e2150897d06888e920526772c2ffb4fb19292070 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Thu, 29 Jun 2017 14:34:33 +0200
Subject: [PATCH 51/59] Completed items to be written to the Alignment
 Monitoring ELOG.

---
 .../python/PyMirrAlignOnline/SetupHelper.py   | 60 +++++++++++--------
 1 file changed, 36 insertions(+), 24 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index 770f476b0..b1b8890d1 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -27,6 +27,7 @@ class SetupHelper:
         self.solutionMethod = self.alignConf.getProp('solutionMethod')
         self.coeffCalibTilt = self.alignConf.getProp('coeffCalibTilt')
         self.magnifDir = self.alignConf.getProp('magnifDir') 
+        self.testing = self.alignConf.getProp('testing')
         self.fixSinusoidShift = self.alignConf.getProp('fixSinusoidShift')
         self.fileprename = self.workdir + '/' + "RichRecQCHistos_rich" + str(self.whichRich) + "_" + self.nameStr + "_" +'i' 
         self.experts = ['Paras.Naik@cern.ch','samuel.maddrell-mander@cern.ch','matthew.george.chapman@cern.ch','claire.prouve@cern.ch']
@@ -34,11 +35,11 @@ class SetupHelper:
         self.emails = ['lhcb-rich-mirror-alignment-development@cern.ch','jonesc@hep.phy.cam.ac.uk','antonis.papanestis@stfc.ac.uk','m.mccann@imperial.ac.uk','silvia.gambetta@cern.ch']
         self.directoryTime = strftime("%Y%m%d_%H%M%S", gmtime())
         self.savedir = self.alignConf.getProp('SaveDir') + 'Rich' + str(self.whichRich) + '/' + self.directoryTime + '/'
+        self.dataVariant = self.alignConf.getProp('dataVariant')
 
     def setupMagnifFiles(self):
-        magnifDir = self.alignConf.getProp('magnifDir')
-        for f in os.listdir(magnifDir):
-            shutil.copy(magnifDir + "/" + f, self.workdir)
+        for f in os.listdir(self.magnifDir):
+            shutil.copy(self.magnifDir + "/" + f, self.workdir)
     
     def startMinIt(self, m_it):
         removeIt = (m_it - m_it % 9) / 9
@@ -109,6 +110,9 @@ class SetupHelper:
         hh, r = divmod(alignment_time, 3600)
         mm, ss = divmod(r, 60)
         alignment_time_str = "{:0>2}:{:0>2}:{:05.2f}".format(int(hh),int(mm),ss)
+
+        import OnlineEnv as Online
+        FillAlignment = self.getFillNumber(Online.DeferredRuns[0])   
         
         # RICH ELOG
         host = 'lblogbook.cern.ch' 
@@ -127,8 +131,8 @@ class SetupHelper:
             subjText += ' needs MirrAlign expert decision,'
         else:
             subjText += ''
-        if self.alignConf.getProp('testing') is True:
-            subject += 'TEST [' + self.alignConf.getProp('dataVariant') + ']: '
+        if self.testing is True:
+            subject += 'TEST [' + self.dataVariant + ']: '
         text += "The Mirror "
         text += str(activity)
         text += " for RICH"
@@ -193,17 +197,28 @@ class SetupHelper:
         subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
 
         # Alignment ELOG
+        
         logbookAlignment = 'Alignment monitoring'
         authorAlignment = 'monibot'
-        activityAlignment = 'Rich'+str(self.whichRich)+' Mirrors'
+        activityAlignment = 'Rich' + str(self.whichRich) + ' Mirrors'
         TypeAlignment = 'Convergence'
-        #subject = 'Monitoring plots'
-        subjectAlignment = 'This is only a test'
-        StatusAlignment = '' # Good or Bad or Unchecked  
-        
-        import OnlineEnv as Online
-        FillAlignment = self.getFillNumber(Online.DeferredRuns[0])   
+        subjectAlignment = ''
+        textAlignment = ''
+        StatusAlignment = 'Good' # or 'Bad' or 'Unchecked'  
         
+        if self.testing is True:
+            subjectAlignment += 'This is only a test: '
+            textAlignment += 'A test mirror alignment for Rich' + str(self.whichRich) + ' was performed for fill ' + str(FillAlignment) + ". No action necessary; ignore the following. \n "
+        if DBUpdated is None:
+            subjectAlignment += 'No alignment update: Needs MirrAlign expert decision'
+            textAlignment += 'Rich' + str(self.whichRich) + ' mirror alignment for fill ' + str(FillAlignment) + " is requesting an update be made, but for some reason this was not done automatically. Please ask the Rich Mirror Alignment experts to investigate (v???). Monitoring plots in the attachment; shifter's instructions can be found at: " + instruction_file
+        elif DBUpdated:
+            subjectAlignment += 'Monitoring plots'
+            textAlignment += 'Updated Rich' + str(self.whichRich) + ' mirror alignment for fill ' + str(FillAlignment) + " (v???), monitoring plots in the attachment; shifter's instructions can be found at: " + instruction_file
+        else:
+            subjectAlignment += 'No alignment update'
+            textAlignment += 'No Rich' + str(self.whichRich) + ' alignment update needed for fill ' + str(FillAlignment) + '.'            
+
         command = 'elog -h "'
         command += str(host)
         command += '" -p '
@@ -228,20 +243,17 @@ class SetupHelper:
         command += str(text)
         command += '"'
         
-#        if os.path.exists(summaryFile):
-#            command += ' -f "{0}"'.format(summaryFile)
-#        if os.path.exists(ChangeWRTDBFile):
-#            command += ' -f "{0}"'.format(ChangeWRTDBFile)
-        if os.path.exists(AlignSummaryFile):
-            command += ' -f "{0}"'.format(AlignSummaryFile)
+        if DBUpdated or DBUpdated is None:
+            if os.path.exists(AlignSummaryFile):
+                command += ' -f "{0}"'.format(AlignSummaryFile)
         cmd = shlex.split(command)
         FNULL = open(os.devnull, 'w')
         subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
         
         # Email
         subj2 = ''
-        if self.alignConf.getProp('testing') is True:
-            subj2 += 'TEST [' + self.alignConf.getProp('dataVariant') + ']: '        
+        if self.testing is True:
+            subj2 += 'TEST [' + self.dataVariant + ']: '        
         text2 = "The Mirror "
         text2 += str(activity)
         text2 += " for RICH"
@@ -317,7 +329,7 @@ class SetupHelper:
         args += 'runs                    = ' + runsString + '\n'
         args += 'fills                   = ' + fillsString + '\n'
         args += 'polarities              = ' + polaritiesString + '\n'
-        args += 'dataVariant             = ' + str(self.alignConf.getProp('dataVariant')) + '\n'
+        args += 'dataVariant             = ' + str(self.dataVariant) + '\n'
         args += 'magnFactorsMode         = ' + str(self.magnFactorsMode) + '\n'
         args += 'savedir                 = ' + self.savedir + '\n'
         print "INFO: LHCbA config time (readable): " + farm_config_time_str
@@ -328,7 +340,7 @@ class SetupHelper:
         args += '\n'
         args += 'Final iteration label   = ' + 'i' + str(n_it) + '\n'
         args += 'autoUpdate              = ' + str(self.autoUpdate) + '\n'
-        args += 'testing                 = ' + str(self.alignConf.getProp('testing')) + '\n'
+        args += 'testing                 = ' + str(self.testing) + '\n'
         args += 'requiredEvents          = ' + str(self.alignConf.getProp('requiredEvents')) + '\n'
         args += 'magnifDir               = ' + str(self.magnifDir) + '\n'
         args += 'minAverageBinPop        = ' + str(self.minAverageBinPop) + '\n'
@@ -447,8 +459,8 @@ class SetupHelper:
         if subjectB is None:
             subjectB = ''            
         subject  = ''
-        if self.alignConf.getProp('testing') is True:
-            subject += 'TEST [' + self.alignConf.getProp('dataVariant') + ']: '
+        if self.testing is True:
+            subject += 'TEST [' + self.dataVariant + ']: '
         subject += 'RICH' + str(self.whichRich) + ' alignment ' + subjectB
 
         if textB is None:
-- 
GitLab


From 50b441f1072ffe51326a5ef30a45c867ab5380e6 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Thu, 29 Jun 2017 16:04:04 +0200
Subject: [PATCH 52/59] ...

---
 .../python/PyMirrAlignOnline/SetupHelper.py                   | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index b1b8890d1..4c0f031c9 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -202,8 +202,8 @@ class SetupHelper:
         authorAlignment = 'monibot'
         activityAlignment = 'Rich' + str(self.whichRich) + ' Mirrors'
         TypeAlignment = 'Convergence'
-        subjectAlignment = ''
-        textAlignment = ''
+        subjectAlignment = 'Testing, please ignore: '
+        textAlignment = 'Please Ignore: \n '
         StatusAlignment = 'Good' # or 'Bad' or 'Unchecked'  
         
         if self.testing is True:
-- 
GitLab


From 249e0102aad262dd86f87f2eb19d4366e27bd348 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Thu, 29 Jun 2017 18:22:17 +0200
Subject: [PATCH 53/59] Added sanity check for magnet polarity flip

---
 .../python/PyMirrAlignOnline/AlignMonitor.py  | 64 ++++++++++---------
 .../python/PyMirrAlignOnline/Iterator.py      |  4 +-
 .../python/PyMirrAlignOnline/SetupHelper.py   |  4 +-
 3 files changed, 38 insertions(+), 34 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index 291d1593e..a2a9c08f1 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -58,7 +58,7 @@ class AlignMonitor:
         #   That monitoring script is always being run at the pit by the Alignment group
         self.isInsane = False
     
-    def performMonitoring(self, compareXML):
+    def performMonitoring(self, compareXML, forcedUpdate_ChMagPol):
         import os
         gStyle.SetOptFit(1111)
         gStyle.SetOptStat(000000000)
@@ -81,11 +81,11 @@ class AlignMonitor:
         # heatHistos
         from tiltObj import tiltObj
         mirrtilts = []
-        for its in range(0, self.maxIt + 1):
-            XMLFile = self.workdir + 'Rich' + str(self.whichRich) + 'CondDBUpdate_' + self.nameStr + '_i' + str(its + 1) + '.xml' 
+        for n_it in range(0, self.maxIt + 1):
+            XMLFile = self.workdir + 'Rich' + str(self.whichRich) + 'CondDBUpdate_' + self.nameStr + '_i' + str(n_it + 1) + '.xml' 
             mirrtilts.append( tiltObj(self.alignConf) )
             # fills mirrtilts with the exact change in mirror compensation from compareXML to XMLFile
-            mirrtilts[its].setChange([compareXML, XMLFile])
+            mirrtilts[n_it].setChange([compareXML, XMLFile])
         mgraphs = mirrtilts[self.maxIt].getGraphs()
         
         if (self.whichRich == 1):
@@ -157,18 +157,18 @@ class AlignMonitor:
         self.sTSZ = float(self.alignConf.getProp('stopToleranceSecZ'))
         biggestTilt = [None] * (self.maxIt + 1)
 
-        for its in reversed(range(0, self.maxIt + 1)):
+        for n_it in reversed(range(0, self.maxIt + 1)):
         # Compensations Histograms           
             # sets priYtrunc, etc... otherwise these will be empty
-            mirrtilts[its].setTrunc(digits = 2)
+            mirrtilts[n_it].setTrunc(digits = 2)
             
             rowsPri = len(self.binToPriMirr)
             colsPri = len(self.binToPriMirr[0])
             for row in xrange(rowsPri):
                 for col in xrange(colsPri):
                     #truncated, not rounded
-                    heatHistoPriY.SetBinContent(col+1, row+1, mirrtilts[its].priYtrunc[self.binToPriMirr[row][col]]) 
-                    heatHistoPriZ.SetBinContent(col+1, row+1, mirrtilts[its].priZtrunc[self.binToPriMirr[row][col]])
+                    heatHistoPriY.SetBinContent(col+1, row+1, mirrtilts[n_it].priYtrunc[self.binToPriMirr[row][col]]) 
+                    heatHistoPriZ.SetBinContent(col+1, row+1, mirrtilts[n_it].priZtrunc[self.binToPriMirr[row][col]])
                     numbersHistoPri.SetBinContent(col+1, row+1, self.binToPriMirr[row][col] if self.binToPriMirr[row][col] != 0 else 0.0000001)
     
             rowsSec = len(self.binToSecMirr)
@@ -176,22 +176,26 @@ class AlignMonitor:
             for row in xrange(rowsSec):
                 for col in xrange(colsSec):
                     #truncated, not rounded
-                    heatHistoSecY.SetBinContent(col+1, row+1, mirrtilts[its].secYtrunc[self.binToSecMirr[row][col]])
-                    heatHistoSecZ.SetBinContent(col+1, row+1, mirrtilts[its].secZtrunc[self.binToSecMirr[row][col]])
+                    heatHistoSecY.SetBinContent(col+1, row+1, mirrtilts[n_it].secYtrunc[self.binToSecMirr[row][col]])
+                    heatHistoSecZ.SetBinContent(col+1, row+1, mirrtilts[n_it].secZtrunc[self.binToSecMirr[row][col]])
                     numbersHistoSec.SetBinContent(col+1, row+1, self.binToSecMirr[row][col] if self.binToSecMirr[row][col] != 0 else 0.0000001)
 
             # Get the maximum tilt in any plot, this lets us set the scales only as relevant, 
             #   and in a controlled manner across all possible mirrors and tilts.    
-            biggestTilt[its] = mirrtilts[its].getAbsMax() 
+            biggestTilt[n_it] = mirrtilts[n_it].getAbsMax() 
             
             # sanity check
-            if its == self.maxIt:
-                if biggestTilt[its][0] >= 3*self.sTPY or biggestTilt[its][1] >= 3*self.sTPZ or biggestTilt[its][2] >= 3*self.sTSY or biggestTilt[its][3] >= 3*self.sTSZ:
+            if n_it == self.maxIt:
+                if not forcedUpdate_ChMagPol:
+                    crazy = 3
+                else:
+                    crazy = 6
+                if biggestTilt[n_it][0] >= crazy*self.sTPY or biggestTilt[n_it][1] >= crazy*self.sTPZ or biggestTilt[n_it][2] >= crazy*self.sTSY or biggestTilt[n_it][3] >= crazy*self.sTSZ:
                     self.isInsane = True
-            
+                        
             # Flexible range plotting style
             for self.nFlex in reversed(range(0,35)):
-                if biggestTilt[its][0] >= self.nFlex*self.sTPY or biggestTilt[its][1] >= self.nFlex*self.sTPZ or biggestTilt[its][2] >= self.nFlex*self.sTSY or biggestTilt[its][3] >= self.nFlex*self.sTSZ:
+                if biggestTilt[n_it][0] >= self.nFlex*self.sTPY or biggestTilt[n_it][1] >= self.nFlex*self.sTPZ or biggestTilt[n_it][2] >= self.nFlex*self.sTSY or biggestTilt[n_it][3] >= self.nFlex*self.sTSZ:
                     break
             # max: heatHistoPriY.GetZaxis().SetRangeUser(-36*self.sTPY, 36*self.sTPY)
             heatHistoPriY.GetZaxis().SetRangeUser((self.nFlex+2)*(0-self.sTPY), (self.nFlex+2)*(self.sTPY))
@@ -230,10 +234,10 @@ class AlignMonitor:
             heatHistoSecZ.SetBarOffset(-0.175)
             numbersHistoPri.SetBarOffset(0.175)
             numbersHistoSec.SetBarOffset(0.175)
-            heatHistoPriY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Y rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
-            heatHistoPriZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
-            heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
-            heatHistoSecZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Z rotation (mrad) after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
+            heatHistoPriY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Y rotation (mrad) after It. ' + str(n_it) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
+            heatHistoPriZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation (mrad) after It. ' + str(n_it) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
+            heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation (mrad) after It. ' + str(n_it) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
+            heatHistoSecZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Z rotation (mrad) after It. ' + str(n_it) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
             execStyle1 = TExec("execStyle1","gStyle->SetPaintTextFormat(\"4.2f\");")  # formerly 5.3f
             execStyle2 = TExec("execStyle2","gStyle->SetPaintTextFormat(\"2.0f\");")
 
@@ -305,23 +309,23 @@ class AlignMonitor:
 
         # Compensations-divided-by-tolerances Histograms
             # sets priYdiv, etc... otherwise these will be empty            
-            mirrtilts[its].setDiv(tolerances = [self.sTPY,self.sTPZ,self.sTSY,self.sTSZ])
+            mirrtilts[n_it].setDiv(tolerances = [self.sTPY,self.sTPZ,self.sTSY,self.sTSZ])
             
             rowsPri = len(self.binToPriMirr)
             colsPri = len(self.binToPriMirr[0])
             for row in xrange(rowsPri):
                 for col in xrange(colsPri):
                     #truncated, not rounded
-                    heatHistoPriY.SetBinContent(col+1, row+1, mirrtilts[its].priYdiv[self.binToPriMirr[row][col]]) 
-                    heatHistoPriZ.SetBinContent(col+1, row+1, mirrtilts[its].priZdiv[self.binToPriMirr[row][col]])
+                    heatHistoPriY.SetBinContent(col+1, row+1, mirrtilts[n_it].priYdiv[self.binToPriMirr[row][col]]) 
+                    heatHistoPriZ.SetBinContent(col+1, row+1, mirrtilts[n_it].priZdiv[self.binToPriMirr[row][col]])
     
             rowsSec = len(self.binToSecMirr)
             colsSec = len(self.binToSecMirr[0])
             for row in xrange(rowsSec):
                 for col in xrange(colsSec):
                     #truncated, not rounded
-                    heatHistoSecY.SetBinContent(col+1, row+1, mirrtilts[its].secYdiv[self.binToSecMirr[row][col]])
-                    heatHistoSecZ.SetBinContent(col+1, row+1, mirrtilts[its].secZdiv[self.binToSecMirr[row][col]])
+                    heatHistoSecY.SetBinContent(col+1, row+1, mirrtilts[n_it].secYdiv[self.binToSecMirr[row][col]])
+                    heatHistoSecZ.SetBinContent(col+1, row+1, mirrtilts[n_it].secZdiv[self.binToSecMirr[row][col]])
 
             # Flexible range plotting style
             # self.nFlex should be unchanged from previous determination.
@@ -357,10 +361,10 @@ class AlignMonitor:
             heatHistoSecZ.SetBarOffset(-0.175)
             numbersHistoPri.SetBarOffset(0.175)
             numbersHistoSec.SetBarOffset(0.175)
-            heatHistoPriY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Y rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
-            heatHistoPriZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
-            heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
-            heatHistoSecZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Z rotation divided by tolerance, after It. ' + str(its) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
+            heatHistoPriY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Y rotation divided by tolerance, after It. ' + str(n_it) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
+            heatHistoPriZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation divided by tolerance, after It. ' + str(n_it) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
+            heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation divided by tolerance, after It. ' + str(n_it) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
+            heatHistoSecZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Z rotation divided by tolerance, after It. ' + str(n_it) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
 
             gStyle.SetPaintTextFormat('2.0f')
             theCanvas.cd(1)
@@ -382,7 +386,7 @@ class AlignMonitor:
             
             theCanvas.Print(piquetFile + '(')
 
-            if its == self.maxIt:
+            if n_it == self.maxIt:
                 self.monSvc.publishHistogram(self.monitoring_folder, heatHistoPriY.Clone(), add=False)
                 print "INFO: heatHistoPriY sent to Monitoring."
                 self.monSvc.publishHistogram(self.monitoring_folder, heatHistoPriZ.Clone(), add=False)
@@ -611,7 +615,7 @@ class AlignMonitor:
 
         theCanvas.Print(expertFile + ')')
         
-        for its in range(0, self.maxIt + 1):
+        for n_it in range(0, self.maxIt + 1):
             mirrtilts[self.maxIt].writeChange(self.maxIt +  1)
         mgraphs[0].Delete()
         mgraphs[1].Delete()
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 7c17f6285..0b158ca34 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -357,7 +357,7 @@ def run(whichRich):
 
           # Run the monitoring, send plots to the Presenter, and generate PDF files;
           #   this returns True if any sanity check failed.
-          insane = setupHelper.monitor(n_it, compareXML)
+          insane = setupHelper.monitor(n_it, compareXML, forcedUpdate_ChMagPol)
           print "INFO: alignMonitor.isInsane = " + str(insane)
           sys.stdout.flush()
           
@@ -367,7 +367,7 @@ def run(whichRich):
                 autoUpdate = False
                 print "INFO: We processed an average number of events per iteration of " + str(nEventsListList[1]) + ", which is too low to allow mirror alignment " + setupHelper.directoryTime + " to automatically update, should an update be deemed necessary."
                 setupHelper.sendEmail( 'autoUpdate disabled for RICH' + str(whichRich) + ' alignment ' + setupHelper.directoryTime + '.' , 'RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' will not automatically be updated, should an update be deemed necessary. \n Average number of events processed per iteration: ' + str(nEventsListList[1]) , setupHelper.emails)        
-          if insane and not forcedUpdate_ChMagPol: # We disable the sanity check on magnet polarity change, because we expect a large variation
+          if insane: 
               if autoUpdate:
                 autoUpdate = False
                 print "INFO: Sanity checks have failed, we will not allow mirror alignment " + setupHelper.directoryTime + " to automatically update, should an update be deemed necessary."
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index 4c0f031c9..7aedf3e29 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -63,10 +63,10 @@ class SetupHelper:
         if os.path.exists(self.workdir + "/" + rootFile):
             os.remove(self.workdir + "/" + rootFile)
 
-    def monitor(self, n_it, compareXML):
+    def monitor(self, n_it, compareXML, forcedUpdate_ChMagPol):
         from AlignMonitor import AlignMonitor
         alignMonitor = AlignMonitor(self.alignConf, n_it)
-        alignMonitor.performMonitoring(compareXML)
+        alignMonitor.performMonitoring(compareXML, forcedUpdate_ChMagPol)
         return alignMonitor.isInsane
 
     def finalize(self, conv, n_it, farm_config_time, elapsed_runtimes, DBUpdated, nEventsListList):
-- 
GitLab


From ccccad6b057d6f1cd0ea7815f155033170865879 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Thu, 29 Jun 2017 22:01:15 +0200
Subject: [PATCH 54/59] Set it up so that a RICH ELOG message can overwrite
 itself (e.g. if it converges, overwrite the starting message). We also remove
 the email that is sent to setupHelper.emails when the alignment starts.

---
 .../python/PyMirrAlignOnline/Iterator.py      | 26 ++++----
 .../python/PyMirrAlignOnline/SetupHelper.py   | 62 +++++++++++--------
 2 files changed, 51 insertions(+), 37 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 0b158ca34..9e0a0f8a8 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -132,8 +132,11 @@ def run(whichRich):
       break
     if (polarities[i] == 'OFF') or (polarities[i] != polarities[0]):
       cancel = True
-      setupHelper.sendEmail('RICH' + str(whichRich) + ' mirror alignment started, but skipped', 'Some of the chosen runs contain magnet OFF data *or* Data for these runs is of mixed polarity: \n Runs: ' + str(runs) + ' \n Fills: ' + str(fills) + ' \n Polarities: ' + str(polsStr) , setupHelper.emails)
+      cancelSubject = 'WARNING: RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + 'started, but has been cancelled.'
+      cancelText = 'RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + 'started, but has been cancelled. Some of the chosen runs contain magnet OFF data *or* Data for these runs is of mixed polarity: \n Runs: ' + str(runs) + ' \n Fills: ' + str(fills) + ' \n Polarities: ' + str(polsStr) 
+      setupHelper.sendEmail(cancelSubject, cancelText, setupHelper.emails)
       print 'INFO: Mirror alignment will be skipped. Some of these runs contain magnet OFF data *or* Data for these runs is of mixed polarity: ' + str(runs)
+      messageID = setupHelper.quickWriteInLogbook(cancelSubject, cancelText)      
       break      
   polarityDir = '/group/rich/AlignmentFiles/Polarity/'
   forcedUpdate_ChMagPol = False
@@ -156,11 +159,13 @@ def run(whichRich):
     leadText = ''
     if testing is True:
       leadText += 'TEST [' + alignConf.getProp('dataVariant') + ']: '
-    setupHelper.sendEmail( leadText + preSubject + 'RICH' + str(whichRich) + ' alignment ' + setupHelper.directoryTime + ' has started.' + postSubject , preText + ' RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' has started. \n Runs: ' + str(runs) + ' \n Fills: ' + str(fills) + ' \n Polarities: ' + str(polsStr) + postText + ' \n dataVariant: ' + alignConf.getProp('dataVariant'), setupHelper.emails)        
+    totalSubject = leadText + preSubject + 'RICH' + str(whichRich) + ' alignment ' + setupHelper.directoryTime + ' has started.' + postSubject
+    totalText = preText + ' RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' has started. \n Runs: ' + str(runs) + ' \n Fills: ' + str(fills) + ' \n Polarities: ' + str(polsStr) + postText + ' \n dataVariant: ' + alignConf.getProp('dataVariant')
+    # setupHelper.sendEmail( totalSubject , totalText, setupHelper.emails)       
+    postText +=" If this alignment does not finish, please report this via the RICH ELOG." 
+    totalText = preText + ' RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' has started. \n Runs: ' + str(runs) + ' \n Fills: ' + str(fills) + ' \n Polarities: ' + str(polsStr) + postText + ' \n dataVariant: ' + alignConf.getProp('dataVariant')
     print 'INFO: RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' has started, dataVariant: ' + alignConf.getProp('dataVariant')
-    subject = "has started."
-    text = "that it has started. If it does not finish, please report this via the RICH ELOG."
-    setupHelper.quickWriteInLogbook(subject, text)
+    messageID = setupHelper.quickWriteInLogbook(totalSubject, totalText)
 
   sys.stdout.flush()
 
@@ -380,17 +385,17 @@ def run(whichRich):
           if (forcedUpdate_ChMagPol or updateHelper.updateDecision(n_it)) and conv:
               if autoUpdate:
                 xmlHelper.finalXML( str(int(latest_vN) + 1) , True) # current + 1
-                setupHelper.finalize(conv, n_it, elapsed_time_config, elapsed_runtimes, True, nEventsListList)
+                setupHelper.finalize(conv, n_it, elapsed_time_config, elapsed_runtimes, True, nEventsListList, messageID)
                 if testing is not True:
                     updateHelper.updateDB( int(latest_vN) + 1 , True) # current + 1
               else:
                 xmlHelper.finalXML( str(int(latest_vN) + 1) + '_maybe_' + setupHelper.directoryTime, True) # (current + 1)_maybe
-                setupHelper.finalize(conv, n_it, elapsed_time_config, elapsed_runtimes, None, nEventsListList)
+                setupHelper.finalize(conv, n_it, elapsed_time_config, elapsed_runtimes, None, nEventsListList, messageID)
                 if testing is not True:
                     updateHelper.updateDB( int(latest_vN) , False)
               #updateHelper.stopUpdateDIM()    
           else:
-              setupHelper.finalize(conv, n_it, elapsed_time_config, elapsed_runtimes, False, nEventsListList)
+              setupHelper.finalize(conv, n_it, elapsed_time_config, elapsed_runtimes, False, nEventsListList, messageID)
               if testing is not True:
                   updateHelper.updateDB( int(latest_vN) , False) # current 
                   #updateHelper.stopUpdateDIM()  
@@ -432,7 +437,7 @@ def run(whichRich):
       elapsed_runtimes['elapsed_time_run'] = time() - start_time_run # Actual iterating time
       print "INFO: Elapsed time to run the Mirror Alignment set as", elapsed_runtimes['elapsed_time_run'], "seconds."
       nEventsListList = setupHelper.getNEventsListList(n_it)
-      setupHelper.finalize(conv, n_it, elapsed_time_config, elapsed_runtimes, False, nEventsListList)
+      setupHelper.finalize(conv, n_it, elapsed_time_config, elapsed_runtimes, False, nEventsListList, messageID)
       if testing is not True:
           updateHelper.updateDB( int(latest_vN) , False) # current
           #updateHelper.stopUpdateDIM()   
@@ -482,9 +487,6 @@ def run(whichRich):
     if cancel:
       print "INFO: We choose to not execute the mirror alignment. "
       print "INFO: The input data is of mixed polarity, or some it is magnet OFF data."
-      subject = "has been cancelled."
-      text = "that it has been cancelled. The input data is of mixed polarity, or some it is magnet OFF data."
-      setupHelper.quickWriteInLogbook(subject, text)
     else:
       setupHelper.sendEmail( 'WARNING: RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' did not complete normally.', 'Warning: RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' did not complete normally. \n No output directory was written. \n Log may be found on plus.cern.ch (via lbgw) in /group/rich/AlignmentFiles/Logging/ with timestamp ' + setupHelper.directoryTime + '. \n Runs: ' + str(runs) + ' \n Fills: ' + str(fills) + ' \n Polarities: ' + str(polsStr) + postText + ' \n dataVariant: ' + alignConf.getProp('dataVariant'), setupHelper.emails)        
       print 'WARNING: RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' did not complete normally. No output directory was written.'
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index 7aedf3e29..4ce5b4644 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -69,7 +69,7 @@ class SetupHelper:
         alignMonitor.performMonitoring(compareXML, forcedUpdate_ChMagPol)
         return alignMonitor.isInsane
 
-    def finalize(self, conv, n_it, farm_config_time, elapsed_runtimes, DBUpdated, nEventsListList):
+    def finalize(self, conv, n_it, farm_config_time, elapsed_runtimes, DBUpdated, nEventsListList, edit = None):
         nEventsList = nEventsListList[0]
         nEvents = nEventsListList[1]
         
@@ -101,9 +101,9 @@ class SetupHelper:
 
         # Write summary.txt, _AlignSummary.pdf, and _ChangeWRTDB.txt to the ELOG
         alignment_time = elapsed_runtimes['elapsed_time_run']
-        self.writeInLogbook(conv, n_it, farm_config_time, alignment_time, summaryFile, ChangeWRTDBFile, AlignSummaryFile, DBUpdated, nEvents)
+        self.writeInLogbook(conv, n_it, farm_config_time, alignment_time, summaryFile, ChangeWRTDBFile, AlignSummaryFile, DBUpdated, nEvents, edit)
 
-    def writeInLogbook(self, conv, n_it, farm_config_time, alignment_time, summaryFile, ChangeWRTDBFile, AlignSummaryFile, DBUpdated, nEvents):
+    def writeInLogbook(self, conv, n_it, farm_config_time, alignment_time, summaryFile, ChangeWRTDBFile, AlignSummaryFile, DBUpdated, nEvents, edit):
         hh, r = divmod(farm_config_time, 3600)
         mm, ss = divmod(r, 60)
         farm_config_time_str = "{:0>2}:{:0>2}:{:05.2f}".format(int(hh),int(mm),ss)
@@ -167,11 +167,15 @@ class SetupHelper:
         if DBUpdated:
             text += " Due to a significant change from the alignment in the DB, or a change in magnet polarity, the DB was automatically updated." # We should probably provide more info here
         if DBUpdated is None:
-            text += " There was a significant change from the alignment in the DB, or a change in magnet polarity. However the automatic update feature is off (or was disabled during the alignment), so the DB was not updated. Please notify a MirrAlign expert to investigate whether this alignment should be installed." # We should maybe provide more info here
+            text += " There was a significant change from the alignment in the DB, or a change in magnet polarity. However the automatic update feature is off, or was disabled during the alignment, so the DB was not updated. If the automatic update feature was disabled, there may not have been enough events processed, or a sanity check was not satisfied. Please notify a MirrAlign expert to investigate whether this alignment should be installed." # We should maybe provide more info here
         command = 'elog -h "'
         command += str(host)
         command += '" -p '
         command += str(port)
+        try:
+            command += ' -e ' + str(int(edit))
+        except:
+            pass
         command += ' -l "'
         command += str(logbook)
         command += '" -u '
@@ -186,6 +190,7 @@ class SetupHelper:
         command += '" "'
         command += str(text)
         command += '"'
+
         if os.path.exists(summaryFile):
             command += ' -f "{0}"'.format(summaryFile)
         if os.path.exists(ChangeWRTDBFile):
@@ -193,9 +198,14 @@ class SetupHelper:
         if os.path.exists(AlignSummaryFile):
             command += ' -f "{0}"'.format(AlignSummaryFile)
         cmd = shlex.split(command)
-        FNULL = open(os.devnull, 'w')
-        subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
-
+        #FNULL = open(os.devnull, 'w')
+        #subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
+        try:
+            elogret = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
+            messageID = int(re.search('.*Message successfully transmitted, ID=(\d*)', elogret).groups()[0])
+        except:
+            messageID = None
+  
         # Alignment ELOG
         
         logbookAlignment = 'Alignment monitoring'
@@ -275,13 +285,13 @@ class SetupHelper:
         if DBUpdated:
             text2 += "\n Due to a significant change from the alignment in the DB, or a change in magnet polarity, the DB was automatically updated. \n" # We should probably provide more info here
         if DBUpdated is None:
-            text2 += "\n There was a significant change from the alignment in the DB, or a change in magnet polarity. However the automatic update feature is off (or was disabled during the alignment), so the DB was not updated. Please notify a MirrAlign expert to investigate whether this alignment should be installed. \n" # We should probably provide more info here
+            text2 += "\n There was a significant change from the alignment in the DB, or a change in magnet polarity. However the automatic update feature is off, or was disabled during the alignment, so the DB was not updated. If the automatic update feature was disabled, there may not have been enough events processed, or a sanity check was not satisfied. A MirrAlign expert should investigate whether this alignment should be installed. \n" # We should probably provide more info here
         text2 += "\n More information is available at the following link: \n\n "
         text2 += 'https://lblogbook.cern.ch/RICH/?System=%5EAlignment%24&Subject={0}&mode=full'.format(self.directoryTime)
         
         self.sendEmail(subj2, text2, self.emails)
   
-        return 0
+        return messageID
 
     def writeSummary(self, conv, n_it, farm_config_time, elapsed_runtimes, summaryFile, DBUpdated, nEvents, nEventsList):
         hh, r = divmod(farm_config_time, 3600)
@@ -447,7 +457,7 @@ class SetupHelper:
         nEvents = int( round( float(sum(nEventsList)) / float(n_it + 1) ) ) # If mag factors float, this only reports for the data with untilted XML
         return [nEventsList , nEvents]
 
-    def quickWriteInLogbook(self, subjectB, textB):
+    def quickWriteInLogbook(self, subjectB, textB, edit = None):
         host = 'lblogbook.cern.ch' 
         port = 8080
         username = 'common Common\\!'
@@ -458,21 +468,12 @@ class SetupHelper:
 
         if subjectB is None:
             subjectB = ''            
-        subject  = ''
-        if self.testing is True:
-            subject += 'TEST [' + self.dataVariant + ']: '
-        subject += 'RICH' + str(self.whichRich) + ' alignment ' + subjectB
+        subject  = '' + subjectB
 
         if textB is None:
             textB = ''
-        text  = ''
-        text += "The Mirror "
-        text += str(activity)
-        text += " for RICH"
-        text += str(self.whichRich)
-        text += " is reporting "
-        text += textB
-        text += " Shifter's instructions can be found at "
+        text = '' + textB
+        text += " \n Shifter's instructions can be found at "
         text += str(instruction_file)
         text += "."
         
@@ -480,6 +481,10 @@ class SetupHelper:
         command += str(host)
         command += '" -p '
         command += str(port)
+        try:
+            command += ' -e ' + str(int(edit))
+        except:
+            pass
         command += ' -l "'
         command += str(logbook)
         command += '" -u '
@@ -495,7 +500,14 @@ class SetupHelper:
         command += str(text)
         command += '"'
         cmd = shlex.split(command)
-        FNULL = open(os.devnull, 'w')
-        subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
+        #FNULL = open(os.devnull, 'w')
+        #subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
+        try:
+            elogret = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
+            messageID = int(re.search('.*Message successfully transmitted, ID=(\d*)', elogret).groups()[0])
+        except:
+            messageID = None
   
-        return 0
+        return messageID
+    
+    
\ No newline at end of file
-- 
GitLab


From 67204eb8924aa8977b560b3fbd74298b4d81c7f4 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Fri, 30 Jun 2017 01:21:26 +0200
Subject: [PATCH 55/59] more tweaks to messages

---
 .../python/PyMirrAlignOnline/Iterator.py           | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 9e0a0f8a8..836310845 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -140,6 +140,8 @@ def run(whichRich):
       break      
   polarityDir = '/group/rich/AlignmentFiles/Polarity/'
   forcedUpdate_ChMagPol = False
+  ChMagPolSubject = ''
+  ChMagPolText = ''
   if (not cancel) and (polarities[0] is not None):
     oldPolarityFilename = polarityDir + 'previousPolarity_RICH' + str(whichRich) +'.txt'
     newPolarityFilename = polarityDir + 'currentPolarity_RICH' + str(whichRich) +'.txt'
@@ -150,9 +152,13 @@ def run(whichRich):
         first_line = previousAlignPolarityFile.readline()
       if (first_line != polarities[0] + '\n'):
         forcedUpdate_ChMagPol = True
-        postSubject += ' Magnet Polarity Changed; possibly forcing update.'
-        postText += ' \n If this alignment converges, the alignment will be updated due to a change in magnet polarity (unless autoUpdate is/becomes False, or testing is True).'
+        ChMagPolSubject += 'Magnet Polarity Changed; possibly forcing update.'
+        ChMagPolText += 'If this alignment converges, the alignment will be updated due to a change in magnet polarity (unless autoUpdate is/becomes False, or testing is True). If there are any problems with this alignment, please contact the Mirror Alignment expert! They should re-flip the magnet polarity in ' + polarityDir + ' in order to have the proper behavior on the next attempt!'       
+        postSubject += ' ' + ChMagPolSubject
+        postText += ' \n ' + ChMagPolText
         print 'INFO: Magnet Polarity Changed; if this alignment converges under normal conditions, then the alignment will be updated.'
+        ChMagPolSubject = ' WARNING: The magnet polarity changed!!!'
+        ChMagPolText = ' \n WARNING: The magnet polarity changed, but this alignment did not produce an output directory before it was decided that an update was needed! The expert should re-flip the magnet polarity for this Rich detector in ' + polarityDir + ' in order to have the proper behavior on the next attempt!!!'      
     shutil.copy2(newPolarityFilename, oldPolarityFilename) 
 
   if (not cancel):
@@ -162,7 +168,7 @@ def run(whichRich):
     totalSubject = leadText + preSubject + 'RICH' + str(whichRich) + ' alignment ' + setupHelper.directoryTime + ' has started.' + postSubject
     totalText = preText + ' RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' has started. \n Runs: ' + str(runs) + ' \n Fills: ' + str(fills) + ' \n Polarities: ' + str(polsStr) + postText + ' \n dataVariant: ' + alignConf.getProp('dataVariant')
     # setupHelper.sendEmail( totalSubject , totalText, setupHelper.emails)       
-    postText +=" If this alignment does not finish, please report this via the RICH ELOG." 
+    postText +=" \n \n If this alignment does not finish, please report this via the RICH ELOG. \n " 
     totalText = preText + ' RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' has started. \n Runs: ' + str(runs) + ' \n Fills: ' + str(fills) + ' \n Polarities: ' + str(polsStr) + postText + ' \n dataVariant: ' + alignConf.getProp('dataVariant')
     print 'INFO: RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' has started, dataVariant: ' + alignConf.getProp('dataVariant')
     messageID = setupHelper.quickWriteInLogbook(totalSubject, totalText)
@@ -488,7 +494,7 @@ def run(whichRich):
       print "INFO: We choose to not execute the mirror alignment. "
       print "INFO: The input data is of mixed polarity, or some it is magnet OFF data."
     else:
-      setupHelper.sendEmail( 'WARNING: RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' did not complete normally.', 'Warning: RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' did not complete normally. \n No output directory was written. \n Log may be found on plus.cern.ch (via lbgw) in /group/rich/AlignmentFiles/Logging/ with timestamp ' + setupHelper.directoryTime + '. \n Runs: ' + str(runs) + ' \n Fills: ' + str(fills) + ' \n Polarities: ' + str(polsStr) + postText + ' \n dataVariant: ' + alignConf.getProp('dataVariant'), setupHelper.emails)        
+      setupHelper.sendEmail( 'WARNING: RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' did not complete normally.' + ChMagPolSubject, 'Warning: RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' did not complete normally. \n No output directory was written. \n Log may be found on plus.cern.ch (via lbgw) in /group/rich/AlignmentFiles/Logging/ with timestamp ' + setupHelper.directoryTime + '.' + ChMagPolText + ' \n Runs: ' + str(runs) + ' \n Fills: ' + str(fills) + ' \n Polarities: ' + str(polsStr) + postText + ' \n dataVariant: ' + alignConf.getProp('dataVariant'), setupHelper.emails)        
       print 'WARNING: RICH' + str(whichRich) + ' mirror alignment ' + setupHelper.directoryTime + ' did not complete normally. No output directory was written.'
   else:
     print "INFO: Expect log file to be written to: " + setupHelper.savedir + 'hlt02.log'
-- 
GitLab


From 5a8c987c0e6c2cff7f5a89fb64bf30fb4968b601 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Fri, 30 Jun 2017 10:43:20 +0200
Subject: [PATCH 56/59] Now print out the new alignment name (or new draft
 alignment name) in final email, ELOG, and summary.

---
 .../python/PyMirrAlignOnline/Iterator.py      | 16 +++++----
 .../python/PyMirrAlignOnline/SetupHelper.py   | 34 +++++++++++--------
 .../python/PyMirrAlignOnline/XMLFileHelper.py |  4 +--
 3 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 836310845..e05e030d2 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -390,18 +390,21 @@ def run(whichRich):
               shutil.copy2(newXMLfile,currentXML) 
           if (forcedUpdate_ChMagPol or updateHelper.updateDecision(n_it)) and conv:
               if autoUpdate:
-                xmlHelper.finalXML( str(int(latest_vN) + 1) , True) # current + 1
-                setupHelper.finalize(conv, n_it, elapsed_time_config, elapsed_runtimes, True, nEventsListList, messageID)
+                vN_DB_str = 'v' + str(int(latest_vN) + 1)
+                xmlHelper.finalXML(vN_DB_str , True) # current + 1
+                setupHelper.finalize(vN_DB_str, conv, n_it, elapsed_time_config, elapsed_runtimes, True, nEventsListList, messageID)
                 if testing is not True:
                     updateHelper.updateDB( int(latest_vN) + 1 , True) # current + 1
               else:
-                xmlHelper.finalXML( str(int(latest_vN) + 1) + '_maybe_' + setupHelper.directoryTime, True) # (current + 1)_maybe
-                setupHelper.finalize(conv, n_it, elapsed_time_config, elapsed_runtimes, None, nEventsListList, messageID)
+                vN_DB_str = 'v' + str(int(latest_vN) + 1) + '_maybe_' + setupHelper.directoryTime
+                xmlHelper.finalXML(vN_DB_str, True) # (current + 1)_maybe
+                setupHelper.finalize(vN_DB_str, conv, n_it, elapsed_time_config, elapsed_runtimes, None, nEventsListList, messageID)
                 if testing is not True:
                     updateHelper.updateDB( int(latest_vN) , False)
               #updateHelper.stopUpdateDIM()    
           else:
-              setupHelper.finalize(conv, n_it, elapsed_time_config, elapsed_runtimes, False, nEventsListList, messageID)
+              vN_DB_str = 'v' + str(int(latest_vN))
+              setupHelper.finalize(vN_DB_str, conv, n_it, elapsed_time_config, elapsed_runtimes, False, nEventsListList, messageID)
               if testing is not True:
                   updateHelper.updateDB( int(latest_vN) , False) # current 
                   #updateHelper.stopUpdateDIM()  
@@ -443,7 +446,8 @@ def run(whichRich):
       elapsed_runtimes['elapsed_time_run'] = time() - start_time_run # Actual iterating time
       print "INFO: Elapsed time to run the Mirror Alignment set as", elapsed_runtimes['elapsed_time_run'], "seconds."
       nEventsListList = setupHelper.getNEventsListList(n_it)
-      setupHelper.finalize(conv, n_it, elapsed_time_config, elapsed_runtimes, False, nEventsListList, messageID)
+      vN_DB_str = 'v' + str(int(latest_vN))
+      setupHelper.finalize(vN_DB_str, conv, n_it, elapsed_time_config, elapsed_runtimes, False, nEventsListList, messageID)
       if testing is not True:
           updateHelper.updateDB( int(latest_vN) , False) # current
           #updateHelper.stopUpdateDIM()   
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index 4ce5b4644..5b968d94d 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -69,12 +69,12 @@ class SetupHelper:
         alignMonitor.performMonitoring(compareXML, forcedUpdate_ChMagPol)
         return alignMonitor.isInsane
 
-    def finalize(self, conv, n_it, farm_config_time, elapsed_runtimes, DBUpdated, nEventsListList, edit = None):
+    def finalize(self, vN_DB_str, conv, n_it, farm_config_time, elapsed_runtimes, DBUpdated, nEventsListList, edit = None):
         nEventsList = nEventsListList[0]
         nEvents = nEventsListList[1]
         
         summaryFile = self.workdir + "/summary.txt"
-        self.writeSummary(conv, n_it, farm_config_time, elapsed_runtimes, summaryFile, DBUpdated, nEvents, nEventsList)
+        self.writeSummary(vN_DB_str, conv, n_it, farm_config_time, elapsed_runtimes, summaryFile, DBUpdated, nEvents, nEventsList)
 
         #shutil.copy2(summaryFile, self.savedir)
         
@@ -101,9 +101,9 @@ class SetupHelper:
 
         # Write summary.txt, _AlignSummary.pdf, and _ChangeWRTDB.txt to the ELOG
         alignment_time = elapsed_runtimes['elapsed_time_run']
-        self.writeInLogbook(conv, n_it, farm_config_time, alignment_time, summaryFile, ChangeWRTDBFile, AlignSummaryFile, DBUpdated, nEvents, edit)
+        self.writeInLogbook(vN_DB_str, conv, n_it, farm_config_time, alignment_time, summaryFile, ChangeWRTDBFile, AlignSummaryFile, DBUpdated, nEvents, edit)
 
-    def writeInLogbook(self, conv, n_it, farm_config_time, alignment_time, summaryFile, ChangeWRTDBFile, AlignSummaryFile, DBUpdated, nEvents, edit):
+    def writeInLogbook(self, vN_DB_str, conv, n_it, farm_config_time, alignment_time, summaryFile, ChangeWRTDBFile, AlignSummaryFile, DBUpdated, nEvents, edit):
         hh, r = divmod(farm_config_time, 3600)
         mm, ss = divmod(r, 60)
         farm_config_time_str = "{:0>2}:{:0>2}:{:05.2f}".format(int(hh),int(mm),ss)
@@ -164,10 +164,12 @@ class SetupHelper:
         text += " and the output directory timestamp is "
         text += self.directoryTime
         text += "."
-        if DBUpdated:
-            text += " Due to a significant change from the alignment in the DB, or a change in magnet polarity, the DB was automatically updated." # We should probably provide more info here
         if DBUpdated is None:
-            text += " There was a significant change from the alignment in the DB, or a change in magnet polarity. However the automatic update feature is off, or was disabled during the alignment, so the DB was not updated. If the automatic update feature was disabled, there may not have been enough events processed, or a sanity check was not satisfied. Please notify a MirrAlign expert to investigate whether this alignment should be installed." # We should maybe provide more info here
+            text += " There was a significant change from the alignment in the DB, or a change in magnet polarity. However the automatic update feature is off, or was disabled during the alignment, so the DB was not updated. If the automatic update feature was disabled, there may not have been enough events processed, or a sanity check was not satisfied. Please notify a MirrAlign expert to investigate whether this alignment (" + vN_DB_str + ") should be installed." # We should maybe provide more info here
+        elif DBUpdated:
+            text += " Due to a significant change from the alignment in the DB, or a change in magnet polarity, the DB was automatically updated to " + vN_DB_str + "." # We should probably provide more info here
+        else:
+            text += " The alignment in the DB is still " + vN_DB_str + "."          
         command = 'elog -h "'
         command += str(host)
         command += '" -p '
@@ -221,13 +223,13 @@ class SetupHelper:
             textAlignment += 'A test mirror alignment for Rich' + str(self.whichRich) + ' was performed for fill ' + str(FillAlignment) + ". No action necessary; ignore the following. \n "
         if DBUpdated is None:
             subjectAlignment += 'No alignment update: Needs MirrAlign expert decision'
-            textAlignment += 'Rich' + str(self.whichRich) + ' mirror alignment for fill ' + str(FillAlignment) + " is requesting an update be made, but for some reason this was not done automatically. Please ask the Rich Mirror Alignment experts to investigate (v???). Monitoring plots in the attachment; shifter's instructions can be found at: " + instruction_file
+            textAlignment += 'Rich' + str(self.whichRich) + ' mirror alignment for fill ' + str(FillAlignment) + " is requesting an update be made, but for some reason this was not done automatically. Please ask the Rich Mirror Alignment experts to investigate the draft alignment (" + vN_DB_str + "). Monitoring plots in the attachment; shifter's instructions can be found at: " + instruction_file
         elif DBUpdated:
             subjectAlignment += 'Monitoring plots'
-            textAlignment += 'Updated Rich' + str(self.whichRich) + ' mirror alignment for fill ' + str(FillAlignment) + " (v???), monitoring plots in the attachment; shifter's instructions can be found at: " + instruction_file
+            textAlignment += 'Updated Rich' + str(self.whichRich) + ' mirror alignment for fill ' + str(FillAlignment) + " (" + vN_DB_str + "), monitoring plots in the attachment; shifter's instructions can be found at: " + instruction_file
         else:
             subjectAlignment += 'No alignment update'
-            textAlignment += 'No Rich' + str(self.whichRich) + ' alignment update needed for fill ' + str(FillAlignment) + '.'            
+            textAlignment += 'No Rich' + str(self.whichRich) + ' alignment update needed for fill ' + str(FillAlignment) + '. The DB alignment is still ' + vN_DB_str + '.'            
 
         command = 'elog -h "'
         command += str(host)
@@ -282,10 +284,13 @@ class SetupHelper:
         text2 += " events per iteration were processed. "
         text2 += str(n_it + 1)
         text2 += " iteration(s) occured. \n"
-        if DBUpdated:
-            text2 += "\n Due to a significant change from the alignment in the DB, or a change in magnet polarity, the DB was automatically updated. \n" # We should probably provide more info here
         if DBUpdated is None:
-            text2 += "\n There was a significant change from the alignment in the DB, or a change in magnet polarity. However the automatic update feature is off, or was disabled during the alignment, so the DB was not updated. If the automatic update feature was disabled, there may not have been enough events processed, or a sanity check was not satisfied. A MirrAlign expert should investigate whether this alignment should be installed. \n" # We should probably provide more info here
+            text2 += "\n There was a significant change from the alignment in the DB, or a change in magnet polarity. However the automatic update feature is off, or was disabled during the alignment, so the DB was not updated. If the automatic update feature was disabled, there may not have been enough events processed, or a sanity check was not satisfied. A MirrAlign expert should investigate whether this draft alignment (" + vN_DB_str + ") should be installed. \n" # We should probably provide more info here
+        elif DBUpdated:
+            text2 += "\n Due to a significant change from the alignment in the DB, or a change in magnet polarity, the DB was automatically updated to " + vN_DB_str + ". \n" # We should probably provide more info here
+        else:
+            text2 += "\n The alignment in the DB is still " + vN_DB_str + "."   
+            
         text2 += "\n More information is available at the following link: \n\n "
         text2 += 'https://lblogbook.cern.ch/RICH/?System=%5EAlignment%24&Subject={0}&mode=full'.format(self.directoryTime)
         
@@ -293,7 +298,7 @@ class SetupHelper:
   
         return messageID
 
-    def writeSummary(self, conv, n_it, farm_config_time, elapsed_runtimes, summaryFile, DBUpdated, nEvents, nEventsList):
+    def writeSummary(self, vN_DB_str, conv, n_it, farm_config_time, elapsed_runtimes, summaryFile, DBUpdated, nEvents, nEventsList):
         hh, r = divmod(farm_config_time, 3600)
         mm, ss = divmod(r, 60)
         farm_config_time_str = "{:0>2}:{:0>2}:{:05.2f}".format(int(hh),int(mm),ss)
@@ -333,6 +338,7 @@ class SetupHelper:
         args += 'DB updated              = ' + str(DBUpdated) + '\n'
         if DBUpdated is None:
             args += '                          (Alignment changed, but autoUpdate is False or was disabled) \n '
+        args += 'resulting DB            = ' + str(vN_DB_str) + '\n'
         args += 'converged               = ' + str(conv) + '\n'
         args += 'Number of iterations    = ' + str(n_it + 1) + '\n'
         args += 'Number of events        = ' + str(nEvents) + '\n'
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/XMLFileHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/XMLFileHelper.py
index 16d8ebd65..aacf3cd8d 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/XMLFileHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/XMLFileHelper.py
@@ -126,7 +126,7 @@ class XMLFileHelper:
                     outfile.write(line)
                 outfile.write('</DDDB> \n')
 
-    def finalXML(self, N_DB_str, Update):
+    def finalXML(self, vN_DB_str, Update):
         workdir = self.alignConf.getProp('WorkDir')
         
         finalXML = workdir + "CondDB_Update_Rich" + str(self.whichRich) + ".xml"
@@ -140,7 +140,7 @@ class XMLFileHelper:
                     if "<?xml version=\'1.0\' encoding=\'iso-8859-1\'?>" not in line and '<!DOCTYPE DDDB SYSTEM "conddb:/DTD/structure.dtd">' not in line and '<DDDB>' not in line and '</DDDB>' not in line:
                         outfile.write(line)
         if Update:
-            latest = 'v' + N_DB_str + '.xml'
+            latest = vN_DB_str + '.xml'
             latest = os.path.join(self.base_dir, latest)
             shutil.copyfile(finalXML, latest)
     
-- 
GitLab


From c8c0c3ef4cc858eb59cc781046b0eb9726eef8ec Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Fri, 30 Jun 2017 14:08:08 +0200
Subject: [PATCH 57/59] Added and removed several comments. Changed which plots
 go to the RICH elog, and which go to the Alignment Monitor elog.

---
 .../python/PyMirrAlignOnline/AlignMonitor.py  | 31 +++++++------
 .../python/PyMirrAlignOnline/Iterator.py      | 11 ++---
 .../python/PyMirrAlignOnline/SetupHelper.py   | 43 ++++++-------------
 .../python/PyMirrAlignOnline/tiltObj.py       |  4 +-
 4 files changed, 37 insertions(+), 52 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
index a2a9c08f1..0a080ceea 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/AlignMonitor.py
@@ -10,6 +10,7 @@ class AlignMonitor:
         self.whichRich = self.alignConf.getProp('Rich')
         self.workdir = self.alignConf.getProp('WorkDir')
         self.displayMode = self.alignConf.getProp('displayMode')
+        self.warningFactor = self.alignConf.getProp('warningFactor')
         self.maxIt = _maxIt # the maximum labeled number of the iterations that we are looping through
         self.prename = "RichRecQCHistos_rich" + str(self.whichRich) + "_" + self.nameStr + "_"
         # RICH1 settings
@@ -63,10 +64,10 @@ class AlignMonitor:
         gStyle.SetOptFit(1111)
         gStyle.SetOptStat(000000000)
 
-        # File for the RICH piquet
-        piquetFile  = self.workdir + 'Rich' + str(self.whichRich) + '_AlignSummary.pdf'
-        # File with additional plots for the RICH mirror alignment experts
-        expertFile  = self.workdir + 'Rich' + str(self.whichRich) + '_AlignMonitor.pdf'
+        # File for the RICH piquet AND for the RICH mirror alignment experts
+        expertFile  = self.workdir + 'Rich' + str(self.whichRich) + '_AlignSummary.pdf'
+        # File for the Alignment piquet ("duplicating" what goes to the Presenter for the Data Manager)
+        monitorFile  = self.workdir + 'Rich' + str(self.whichRich) + '_AlignMonitor.pdf'
         # File with for testing purposes
         testingFile = self.workdir + 'Rich' + str(self.whichRich) + '_AlignTesting.pdf'
         # Data Manager can only get histograms sent via self.monSvc
@@ -180,16 +181,18 @@ class AlignMonitor:
                     heatHistoSecZ.SetBinContent(col+1, row+1, mirrtilts[n_it].secZtrunc[self.binToSecMirr[row][col]])
                     numbersHistoSec.SetBinContent(col+1, row+1, self.binToSecMirr[row][col] if self.binToSecMirr[row][col] != 0 else 0.0000001)
 
-            # Get the maximum tilt in any plot, this lets us set the scales only as relevant, 
+            # Get the absolute value of the maximum tilt in any plot, 
+            #   this lets us set the scales only as relevant, 
             #   and in a controlled manner across all possible mirrors and tilts.    
             biggestTilt[n_it] = mirrtilts[n_it].getAbsMax() 
             
             # sanity check
             if n_it == self.maxIt:
                 if not forcedUpdate_ChMagPol:
-                    crazy = 3
+                    crazy = self.warningFactor 
                 else:
-                    crazy = 6
+                    expandCrazyFactor = 2 # The choice of expandCrazyFactor is completely arbitrary, and should be re-evaluated later.
+                    crazy = expandCrazyFactor*self.warningFactor 
                 if biggestTilt[n_it][0] >= crazy*self.sTPY or biggestTilt[n_it][1] >= crazy*self.sTPZ or biggestTilt[n_it][2] >= crazy*self.sTSY or biggestTilt[n_it][3] >= crazy*self.sTSZ:
                     self.isInsane = True
                         
@@ -238,6 +241,7 @@ class AlignMonitor:
             heatHistoPriZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Primary mirrors local Z rotation (mrad) after It. ' + str(n_it) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
             heatHistoSecY.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Y rotation (mrad) after It. ' + str(n_it) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
             heatHistoSecZ.SetTitle('#splitline{RICH' + str(self.whichRich) + ' Secondary mirrors local Z rotation (mrad) after It. ' + str(n_it) + '}{Values truncated, not rounded. Mirror number displayed smaller.}' )
+            # we need TExec in order to have multiple text formats drawn on the same TPad
             execStyle1 = TExec("execStyle1","gStyle->SetPaintTextFormat(\"4.2f\");")  # formerly 5.3f
             execStyle2 = TExec("execStyle2","gStyle->SetPaintTextFormat(\"2.0f\");")
 
@@ -384,7 +388,7 @@ class AlignMonitor:
             heatHistoSecZ.Draw("TEXT SAME")
             numbersHistoSec.Draw("TEXT SAME")
             
-            theCanvas.Print(piquetFile + '(')
+            theCanvas.Print(monitorFile + '(')
 
             if n_it == self.maxIt:
                 self.monSvc.publishHistogram(self.monitoring_folder, heatHistoPriY.Clone(), add=False)
@@ -525,20 +529,21 @@ class AlignMonitor:
                 resHistograms[j].Draw()
                 polbkg[j].Draw("SAME")   
             
-        theCanvas.Print(piquetFile)
+        theCanvas.Print(monitorFile)
         
         sys.stdout.flush()
     
         # Make resHistoTrend iteration trend plot
         resHistoTrend.SetMarkerStyle(8)
         resHistoTrend.SetXTitle('iteration number')
-        resHistoTrend.SetYTitle('') # resHistoTrend.SetYTitle('Cherenkov angle resolution (mrad)')
+        resHistoTrend.SetYTitle('#splitline{Cherenkov angle resolution (mrad)}{}') 
 
         theCanvas2.Clear()
         theCanvas.Clear()
         resHistoTrend.DrawCopy()
-        
-        theCanvas.Print(piquetFile + ')')
+
+        theCanvas.Print(expertFile)
+        theCanvas.Print(monitorFile + ')')
         
         self.monSvc.publishHistogram(self.monitoring_folder, resHistoTrend.Clone(), add=False)
         print "INFO: resHistoTrend sent to Monitoring."
@@ -677,7 +682,6 @@ class AlignMonitor:
             for p in range(0, nParamsToSet):
                 fFitF.SetParameter(p,lastFitF.GetParameter(p));
                 
-            #hist.Fit( fFitF, "RFQ" )
             hist.Fit( fFitF, "RFQM" )
             lastFitF = fFitF
             fitOK = fFitF.GetParError(1) < m_maxErrorForOK 
@@ -686,7 +690,6 @@ class AlignMonitor:
                 bestNPol = nPol
             else:
                 if ( nPol == nPolFull ):
-                    #hist.Fit( fFitF, "RSE0Q" )
                     hist.Fit( fFitF, "RFSE0QM" )
                     fitOK = True         
                 if nPol > 1:
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index e05e030d2..0bb473fe0 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -52,9 +52,9 @@ def run(whichRich):
   sys.stdout.flush()
 
   from HistoHelper import SaveSetRetriever
-  ssRetr = None  #the SavesetRetriever, this thing will give us the path to the histogram files produced by the analyzers
+  ssRetr = None  #the SaveSetRetriever, this thing will give us the path to the histogram files produced by the analyzers
   from HistoHelper import HistoCopier
-  histCopier = None  #the Histcopier, it will wait after each minor iteration for the savesets to be written and copy it under the approriate name into workdir
+  histCopier = None  #the HistoCopier, it will wait after each minor iteration for the savesets to be written and copy it under the approriate name into workdir
   from XMLFileHelper import XMLFileHelper
   xmlHelper = None  
   from RichAlignmentHelper import RichAlignmentHelper
@@ -102,7 +102,7 @@ def run(whichRich):
   ### before each new minor iteration the new xml file will be copied here
   currentXML = workdir + "CondDB_Rich" + str(whichRich) + ".xml"
 
-  ### path in the workdirectory of the database-file that the final database will be compared to  
+  ### path in the workdirectory of the database-file that the final database will be compared to in the AlignMonitor
   compareXML = workdir + 'Rich' + str(whichRich) + '_compareXMLFile.xml'
   
   # We do this before a "configure" because we need run and directoryTime info for the next part
@@ -121,7 +121,7 @@ def run(whichRich):
   print "INFO: runs = " + str(runs)
   print "INFO: fills = " + str(fills)
   polsStr = [str(item) for item in polarities]
-  print "INFO: polarities = " + str(polsStr) # gets rid of unicode flag preceding each string
+  print "INFO: polarities = " + str(polsStr) # str() gets rid of unicode flag preceding each string
   cancel = False
   preSubject, preText, postSubject, postText = [''] * 4 # this is a nice variable defining strategy, but note it does not work on mutable elements (such as lists)!
   for i in range(0, len(runs)):
@@ -473,7 +473,7 @@ def run(whichRich):
   print 'INFO: Iterator state = ' + str(state)
     
 ########################################################################################################################                                    
-##### This is where the party ends!
+##### This is where the party ends! (well, almost...)
 ########################################################################################################################   
     
   if not cancel:
@@ -516,6 +516,7 @@ def run(whichRich):
   print "INFO: hlt02 logProcess killed."
   sys.stdout.flush()
 
+  # string used to help remove lines from the hlt02 log, using grep -vE (E = Enhanced Mode, required to parse the string)
   removeExtraneous = '(tmSrv|LHCb2_HLT02_Hlt2Adder_0|Hlt2SaverSvc|MARK|GEN_hlt02_BusyMon)'
 
   if os.path.exists(setupHelper.savedir):
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index 5b968d94d..87e3c3ff4 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -13,7 +13,7 @@ from ROOT import TH1, TFile
 class SetupHelper:
     def __init__(self, _alignConf):
         self.alignConf = _alignConf
-        # maybe put combAndMirrSubsets here later somehow
+        # put combAndMirrSubsets here later somehow
         self.nameStr = self.alignConf.getProp('nameStr')
         self.tiltNames = self.alignConf.getProp('tiltNames')
         self.workdir = self.alignConf.getProp('WorkDir')
@@ -75,8 +75,6 @@ class SetupHelper:
         
         summaryFile = self.workdir + "/summary.txt"
         self.writeSummary(vN_DB_str, conv, n_it, farm_config_time, elapsed_runtimes, summaryFile, DBUpdated, nEvents, nEventsList)
-
-        #shutil.copy2(summaryFile, self.savedir)
         
         if not os.path.exists(self.savedir):
             os.makedirs(self.savedir)
@@ -86,24 +84,19 @@ class SetupHelper:
             else:
                 shutil.copy2(self.workdir + "/" + f, self.savedir)
         print "INFO: savedir " + self.savedir
-        # NOTE: Any file created after this in the workdir 
+        # NOTE: *Any file created after this in the workdir* 
         #   needs to be *manually* saved in the savedir
 
         ChangeWRTDBFile  = self.workdir + "/Rich" + str(self.whichRich) + '_ChangeWRTDB_'+ str(n_it + 1) +'.txt'
-        #shutil.copy2(ChangeWRTDBFile, self.savedir)
         AlignSummaryFile = self.workdir + "/Rich" + str(self.whichRich) + '_AlignSummary.pdf'    
-        #shutil.copy2(AlignSummaryFile, self.savedir)
-        #AlignMonitorFile = self.workdir + "/Rich" + str(self.whichRich) + '_AlignMonitor.pdf'    
-        #shutil.copy2(AlignMonitorFile, self.savedir)
-        #AlignTestingFile = self.workdir + "/Rich" + str(self.whichRich) + '_AlignTesting.pdf'    
-        #if os.path.exists(AlignTestingFile):
-            #shutil.copy2(AlignTestingFile, self.savedir)
+        AlignMonitorFile = self.workdir + "/Rich" + str(self.whichRich) + '_AlignMonitor.pdf' # Not used just yet   
+        AlignTestingFile = self.workdir + "/Rich" + str(self.whichRich) + '_AlignTesting.pdf' # Not used just yet; May not exist   
 
-        # Write summary.txt, _AlignSummary.pdf, and _ChangeWRTDB.txt to the ELOG
+        # Write files and information to the RICH and Alignment Monitor ELOGs, and also send email
         alignment_time = elapsed_runtimes['elapsed_time_run']
-        self.writeInLogbook(vN_DB_str, conv, n_it, farm_config_time, alignment_time, summaryFile, ChangeWRTDBFile, AlignSummaryFile, DBUpdated, nEvents, edit)
+        self.writeInLogbook(vN_DB_str, conv, n_it, farm_config_time, alignment_time, summaryFile, ChangeWRTDBFile, AlignSummaryFile, AlignMonitorFile, DBUpdated, nEvents, edit)
 
-    def writeInLogbook(self, vN_DB_str, conv, n_it, farm_config_time, alignment_time, summaryFile, ChangeWRTDBFile, AlignSummaryFile, DBUpdated, nEvents, edit):
+    def writeInLogbook(self, vN_DB_str, conv, n_it, farm_config_time, alignment_time, summaryFile, ChangeWRTDBFile, AlignSummaryFile, AlignMonitorFile, DBUpdated, nEvents, edit):
         hh, r = divmod(farm_config_time, 3600)
         mm, ss = divmod(r, 60)
         farm_config_time_str = "{:0>2}:{:0>2}:{:05.2f}".format(int(hh),int(mm),ss)
@@ -185,7 +178,7 @@ class SetupHelper:
         command += ' -a "Author='
         command += str(author)
         #command += '" -a "System='
-        command += '" -a "System_19='
+        command += '" -a "System_19=' # Change 19 if Alignment changes its order in the ELOG (ask the current RICH expert)
         command += str(activity)
         command += '" -a "Subject='
         command += str(subject)
@@ -200,8 +193,6 @@ class SetupHelper:
         if os.path.exists(AlignSummaryFile):
             command += ' -f "{0}"'.format(AlignSummaryFile)
         cmd = shlex.split(command)
-        #FNULL = open(os.devnull, 'w')
-        #subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
         try:
             elogret = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
             messageID = int(re.search('.*Message successfully transmitted, ID=(\d*)', elogret).groups()[0])
@@ -209,7 +200,6 @@ class SetupHelper:
             messageID = None
   
         # Alignment ELOG
-        
         logbookAlignment = 'Alignment monitoring'
         authorAlignment = 'monibot'
         activityAlignment = 'Rich' + str(self.whichRich) + ' Mirrors'
@@ -256,8 +246,8 @@ class SetupHelper:
         command += '"'
         
         if DBUpdated or DBUpdated is None:
-            if os.path.exists(AlignSummaryFile):
-                command += ' -f "{0}"'.format(AlignSummaryFile)
+            if os.path.exists(AlignMonitorFile):
+                command += ' -f "{0}"'.format(AlignMonitorFile)
         cmd = shlex.split(command)
         FNULL = open(os.devnull, 'w')
         subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
@@ -463,7 +453,7 @@ class SetupHelper:
         nEvents = int( round( float(sum(nEventsList)) / float(n_it + 1) ) ) # If mag factors float, this only reports for the data with untilted XML
         return [nEventsList , nEvents]
 
-    def quickWriteInLogbook(self, subjectB, textB, edit = None):
+    def quickWriteInLogbook(self, subject, text, edit = None):
         host = 'lblogbook.cern.ch' 
         port = 8080
         username = 'common Common\\!'
@@ -472,13 +462,6 @@ class SetupHelper:
         activity = 'Alignment'
         instruction_file = 'https://twiki.cern.ch/twiki/bin/view/LHCb/LHCbRichMirrorAlignShiftInfo'
 
-        if subjectB is None:
-            subjectB = ''            
-        subject  = '' + subjectB
-
-        if textB is None:
-            textB = ''
-        text = '' + textB
         text += " \n Shifter's instructions can be found at "
         text += str(instruction_file)
         text += "."
@@ -498,7 +481,7 @@ class SetupHelper:
         command += ' -a "Author='
         command += str(author)
         #command += '" -a "System='
-        command += '" -a "System_19='
+        command += '" -a "System_19=' # Change 19 if Alignment changes its order in the ELOG (ask the current RICH expert)
         command += str(activity)
         command += '" -a "Subject='
         command += str(subject)
@@ -506,8 +489,6 @@ class SetupHelper:
         command += str(text)
         command += '"'
         cmd = shlex.split(command)
-        #FNULL = open(os.devnull, 'w')
-        #subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
         try:
             elogret = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
             messageID = int(re.search('.*Message successfully transmitted, ID=(\d*)', elogret).groups()[0])
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/tiltObj.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/tiltObj.py
index bb12a54d3..a613ee50f 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/tiltObj.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/tiltObj.py
@@ -159,7 +159,7 @@ class tiltObj:
         return biggestTilt
     
     def setTrunc(self, digits = 2):
-        # must be done after a setChange(files)
+        # can only be done *after* a setChange(files)
         # truncated-not-rounded-version of the mirror compensations already stored in self.priY, self.priZ, etc...
         import math
         if int(digits) < 0:
@@ -195,7 +195,7 @@ class tiltObj:
                 self.secZtrunc[sZ] = -0.0000001        
                 
     def setDiv(self, digits = 0, tolerances = None): # [pYtol,pZtol,sYtol,sZtol]
-        # must be done after a setChange(files)
+        # can only be done *after* a setChange(files)
         # truncated-not-rounded-version of the mirror compensations, already stored in self.priY, self.priZ, etc..., divided by the tolerances
         # NOTE: If digits = 0, values within the tolerances will all show up as "-0" or "0"
         import math
-- 
GitLab


From 9841cd930ebc8e270f9c12c0c8c79147acbf58f1 Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Fri, 30 Jun 2017 16:47:02 +0200
Subject: [PATCH 58/59] We now only overwrite the old magnet polarity file if
 the alignment converges.

---
 .../python/PyMirrAlignOnline/Iterator.py             | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
index 0bb473fe0..7b99f5bf2 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/Iterator.py
@@ -157,9 +157,9 @@ def run(whichRich):
         postSubject += ' ' + ChMagPolSubject
         postText += ' \n ' + ChMagPolText
         print 'INFO: Magnet Polarity Changed; if this alignment converges under normal conditions, then the alignment will be updated.'
-        ChMagPolSubject = ' WARNING: The magnet polarity changed!!!'
-        ChMagPolText = ' \n WARNING: The magnet polarity changed, but this alignment did not produce an output directory before it was decided that an update was needed! The expert should re-flip the magnet polarity for this Rich detector in ' + polarityDir + ' in order to have the proper behavior on the next attempt!!!'      
-    shutil.copy2(newPolarityFilename, oldPolarityFilename) 
+        ChMagPolSubject = ' WARNING: The magnet polarity changed!'
+        ChMagPolText = ' \n WARNING: The magnet polarity changed! Make sure that everything (e.g. previousPolarity_RICH) is in order for the next alignment!!!'
+        # OUTDATED: The expert should re-flip the magnet polarity for this Rich detector in ' + polarityDir + ' in order to have the proper behavior on the next attempt!!!     
 
   if (not cancel):
     leadText = ''
@@ -352,6 +352,10 @@ def run(whichRich):
         ### check if the alignment has converged or failed
         conv = alignHelper.hasConverged()
         print "INFO: The alignment after Iteration", n_it, "returns converged =", conv
+
+        # if the alignment has converged, overwrite the old polarity file with the new polarity file
+        if conv:
+            shutil.copy2(newPolarityFilename, oldPolarityFilename)   
         
         if(conv or n_it >= maxIters):
           allDone = True
@@ -387,7 +391,7 @@ def run(whichRich):
           
           if forcedUpdate_ChMagPol and conv:
               # if we are forcing the update we use the newXML from RichMirrAlign, not the currentXML
-              shutil.copy2(newXMLfile,currentXML) 
+              shutil.copy2(newXMLfile,currentXML)
           if (forcedUpdate_ChMagPol or updateHelper.updateDecision(n_it)) and conv:
               if autoUpdate:
                 vN_DB_str = 'v' + str(int(latest_vN) + 1)
-- 
GitLab


From 2e6394584c186f264e93da38b759d72a1550912b Mon Sep 17 00:00:00 2001
From: Paras Naik <paras.naik@cern.ch>
Date: Wed, 5 Jul 2017 00:13:22 +0200
Subject: [PATCH 59/59] Rich/RichMirrorAlignmentOnline "Tagged" as v3r4.
 Updated Release Notes.

---
 Rich/RichMirrorAlignmentOnline/CMakeLists.txt |  2 +-
 .../cmt/requirements                          |  2 +-
 .../doc/release.notes                         | 28 +++++++++++++++++++
 .../python/PyMirrAlignOnline/SetupHelper.py   | 16 ++++++-----
 4 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/Rich/RichMirrorAlignmentOnline/CMakeLists.txt b/Rich/RichMirrorAlignmentOnline/CMakeLists.txt
index e6785b46b..26972668e 100644
--- a/Rich/RichMirrorAlignmentOnline/CMakeLists.txt
+++ b/Rich/RichMirrorAlignmentOnline/CMakeLists.txt
@@ -1,7 +1,7 @@
 ################################################################################
 # Package: RichMirrorAlignmentOnline
 ################################################################################
-gaudi_subdir(RichMirrorAlignmentOnline v3r3)
+gaudi_subdir(RichMirrorAlignmentOnline v3r4)
 
 gaudi_depends_on_subdirs(Online/Gaucho
                          Event/DAQEvent
diff --git a/Rich/RichMirrorAlignmentOnline/cmt/requirements b/Rich/RichMirrorAlignmentOnline/cmt/requirements
index f80efa218..77a096a2b 100644
--- a/Rich/RichMirrorAlignmentOnline/cmt/requirements
+++ b/Rich/RichMirrorAlignmentOnline/cmt/requirements
@@ -3,7 +3,7 @@
 # Maintainer : Paras Naik, Claire Prouve
 #============================================================================
 package           RichMirrorAlignmentOnline
-version           v3r3
+version           v3r4
 
 #============================================================================
 # Structure, i.e. directories to process. 
diff --git a/Rich/RichMirrorAlignmentOnline/doc/release.notes b/Rich/RichMirrorAlignmentOnline/doc/release.notes
index 637820d6e..77d6eb516 100644
--- a/Rich/RichMirrorAlignmentOnline/doc/release.notes
+++ b/Rich/RichMirrorAlignmentOnline/doc/release.notes
@@ -12,6 +12,34 @@ Get into the habit of committing on every change (that compiles of course)
 
 ! Notes pertaining to already "tagged" releases:
 
+! 2017-07-04 - Paras Naik
+  - "Tagged" as v3r4 (internally, since only Panoptes gets a tag now).
+  - Changed name of AlignSummary.py to AlignMonitor.py
+  - Fixed code to provide monitoring histograms properly if the zeroth iteration is the only iteration.
+  - Added sanity check to prevent the alignment from updating automatically
+     if the changes in the mirror alignment are abnormally large.
+  - Added warningFactor configurable to Configuration.py
+      This configurable determines how many times the tolerance is the level of the sanity check
+      When the magnet polarity changes, this sanity check is currently made looser by a factor of 2 (2 is hard coded!)
+  - Added displayMode configurable to Configuration.py
+      This configurable allows an alternate plotting style for the monitoring to be tried
+  - 2D histograms with mirror numbers are now created
+      They now appear in AlignMonitor.pdf and AlignSummary.pdf 2D Histos
+      They are also sent to the monitoring/Presenter for later use
+  - Per iteration deltaTheta plots now available for experts in AlignSummary.pdf
+  - Added F and M ROOT options to the hist->fit to the deltaTheta plot in AlignMonitor.py
+  - Added monitor function to SetupHelper.py, which now performs the monitoring 
+      separately to the finalize function, and also returns the result of the sanity check.
+  - Added small offset to setTrunc and setDiv to make sure the color in the 2D histograms 
+      is correct if a value is exactly on the boundary.
+  - Now posting an "alignment starting" message to the RICH ELOG, 
+      which gets overwritten by the result if the alignment completes properly.
+  - Junk messages in the hlt02 log file are now removed, and the result is placed 
+      in an "hlt02reduced" log file.
+  - Now sending deltaTheta histograms to the monitoring/Presenter without hist->fit already performed.
+  - Now sending AlignMonitor.pdf and a message to the Alignment Monitoring ELOG.
+  - We now only overwrite the old magnet polarity name storage file if the alignment converges.
+  
 ! 2017-06-20 - Paras Naik
   - "Tagged" as v3r3 (internally, since only Panoptes gets a tag now).
   - Now sending monitoring plots to the Presenter/Monet!
diff --git a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
index 87e3c3ff4..80e28b85b 100644
--- a/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
+++ b/Rich/RichMirrorAlignmentOnline/python/PyMirrAlignOnline/SetupHelper.py
@@ -200,13 +200,13 @@ class SetupHelper:
             messageID = None
   
         # Alignment ELOG
-        logbookAlignment = 'Alignment monitoring'
-        authorAlignment = 'monibot'
-        activityAlignment = 'Rich' + str(self.whichRich) + ' Mirrors'
-        TypeAlignment = 'Convergence'
-        subjectAlignment = 'Testing, please ignore: '
-        textAlignment = 'Please Ignore: \n '
-        StatusAlignment = 'Good' # or 'Bad' or 'Unchecked'  
+        logbookAlignment = 'Alignment monitoring' # always
+        authorAlignment = 'monibot' # always
+        activityAlignment = 'Rich' + str(self.whichRich) + ' Mirrors' # always
+        TypeAlignment = 'Convergence' # always
+        subjectAlignment = 'Only A Test: ' # change to '' when operational
+        textAlignment = 'Please Ignore: \n ' # change to '' when operational
+        StatusAlignment = 'Good' # or can be changed below to 'Unchecked' or 'Bad' (for now 'Bad' never happens) 
         
         if self.testing is True:
             subjectAlignment += 'This is only a test: '
@@ -214,9 +214,11 @@ class SetupHelper:
         if DBUpdated is None:
             subjectAlignment += 'No alignment update: Needs MirrAlign expert decision'
             textAlignment += 'Rich' + str(self.whichRich) + ' mirror alignment for fill ' + str(FillAlignment) + " is requesting an update be made, but for some reason this was not done automatically. Please ask the Rich Mirror Alignment experts to investigate the draft alignment (" + vN_DB_str + "). Monitoring plots in the attachment; shifter's instructions can be found at: " + instruction_file
+            StatusAlignment = 'Unchecked'
         elif DBUpdated:
             subjectAlignment += 'Monitoring plots'
             textAlignment += 'Updated Rich' + str(self.whichRich) + ' mirror alignment for fill ' + str(FillAlignment) + " (" + vN_DB_str + "), monitoring plots in the attachment; shifter's instructions can be found at: " + instruction_file
+            StatusAlignment = 'Unchecked'
         else:
             subjectAlignment += 'No alignment update'
             textAlignment += 'No Rich' + str(self.whichRich) + ' alignment update needed for fill ' + str(FillAlignment) + '. The DB alignment is still ' + vN_DB_str + '.'            
-- 
GitLab