From b4b2f949dd0731b82e98de92562bd1067153c237 Mon Sep 17 00:00:00 2001
From: Guillaume Unal <Guillaume.Unal@cern.ch>
Date: Thu, 26 Jan 2017 13:00:35 +0100
Subject: [PATCH] Fix for incorrect interpration of HV mapping for endcap
 presampler (LArHV-00-00-36)

	* src/EMECPresamplerHVManager.cpp   Fix for incorrect interpration of HV mapping for endcap presampler:
           There are 32 modules in phi (0-31)
           each module has 2 cell in phi, in the mapping database this is referred by "gapIndex"
           0 is on the low phi side (in the ATLAS frame)
           1 in on the  high phi side
           so in total 64 sectors in phi given by 2*phiIndex+gapIndex
            the two gap of these sectors are powered by the same line and have the same HV
       (while in the previous code, there were 32 sectors for HV in phi, with the two gaps powered by the two different HV lines)
         * tag LArHV-00-00-36
---
 .../LArHV/src/EMECPresamplerHVManager.cpp     | 32 ++++++++++++-------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/LArCalorimeter/LArGeoModel/LArHV/src/EMECPresamplerHVManager.cpp b/LArCalorimeter/LArGeoModel/LArHV/src/EMECPresamplerHVManager.cpp
index 16b16ce7a19..f45028ee402 100644
--- a/LArCalorimeter/LArGeoModel/LArHV/src/EMECPresamplerHVManager.cpp
+++ b/LArCalorimeter/LArGeoModel/LArHV/src/EMECPresamplerHVManager.cpp
@@ -29,7 +29,7 @@
 class EMECPresamplerHVManager::Clockwork {
 public:
   CellBinning *phiBinning;
-  EMECPresamplerHVModuleConstLink linkArray[2][32]; // not dense
+  EMECPresamplerHVModuleConstLink linkArray[2][64]; // not dense
   bool                  init;
   std::vector<EMECPresamplerHVPayload> payloadArray;
 };
@@ -41,7 +41,7 @@ EMECPresamplerHVManager::EMECPresamplerHVManager():
 {
   m_c->init=false;
 
-  m_c->phiBinning = new CellBinning(0.0, 2*M_PI, 32);
+  m_c->phiBinning = new CellBinning(0.0, 2*M_PI, 64);
 }
 
 
@@ -98,7 +98,7 @@ void EMECPresamplerHVManager::update() const {
   if (!m_c->init) {
     m_c->init=true;
     {
-        m_c->payloadArray.reserve(2*32);
+        m_c->payloadArray.reserve(2*64);
         for (unsigned int i=0;i<64;i++) {
           m_c->payloadArray[i].voltage[0]=-99999;
           m_c->payloadArray[i].voltage[1]=-99999;
@@ -168,11 +168,19 @@ void EMECPresamplerHVManager::update() const {
                   if (phiIndex<16) phiIndex=15-phiIndex;
                   else phiIndex=47-phiIndex;
               }
-	  
-	      unsigned int index = 32*sideIndex+phiIndex;
 
+// GU  January 2017  -   fix for HV EMEC PS distribution
+// 0-31 in phi module
+// each module has 2 cell in phi, in the mapping database this is referred by "gapIndex" 
+//   0 is on the low phi side (in the ATLAS frame)
+//   1 in on the  high phi side
+// so in total 64 sectors in phi given by 2*phiIndex+gapIndex
+// the two gap of these sectors are powered by the same line and have the same HV
+    
+            unsigned int gapIndex=elecId->gap(elecHWID);
+ 
+            unsigned int index = 64*sideIndex+2*phiIndex+gapIndex;
 
-	      unsigned int gapIndex=elecId->gap(elecHWID);
 	      
             float voltage = -99999.;
             if (!((*citr).second)["R_VMEAS"].isNull()) voltage = ((*citr).second)["R_VMEAS"].data<float>();
@@ -182,10 +190,12 @@ void EMECPresamplerHVManager::update() const {
             if (!((*citr).second)["R_STAT"].isNull()) status =  ((*citr).second)["R_STAT"].data<unsigned int>(); 
 
 
-	      m_c->payloadArray[index].voltage[gapIndex]=voltage;
-	      m_c->payloadArray[index].current[gapIndex]=current;
-	      m_c->payloadArray[index].status[gapIndex]=status;
-	      m_c->payloadArray[index].hvLineNo[gapIndex]=chanID;
+              for (unsigned int gap=0;gap<2;gap++) {
+	        m_c->payloadArray[index].voltage[gap]=voltage;
+	        m_c->payloadArray[index].current[gap]=current;
+	        m_c->payloadArray[index].status[gap]=status;
+	        m_c->payloadArray[index].hvLineNo[gap]=chanID;
+              }
 	  } // for (electrodeIdVec)
         } // is EMECPresampler
       } // for (atrlistcol)
@@ -201,7 +211,7 @@ EMECPresamplerHVPayload *EMECPresamplerHVManager::getPayload(const EMECPresample
   unsigned int phiIndex          = module.getPhiIndex();
   unsigned int sideIndex         = module.getSideIndex();
 
-  unsigned int index = 32*sideIndex+phiIndex;
+  unsigned int index = 64*sideIndex+phiIndex;
 
   return &m_c->payloadArray[index];
 }
-- 
GitLab