From 1ac778c478dc285a7a15a24ef87bb2d3c5e3933d Mon Sep 17 00:00:00 2001
From: Nicholas Styles <nicholas.styles@desy.de>
Date: Fri, 23 Oct 2020 09:46:08 +0000
Subject: [PATCH] CondAlg and DetElement validation updates for ITkStrip

---
 .../src/SCT_AlignCondAlg.cxx                  |  4 ++-
 .../src/SCT_AlignCondAlg.h                    |  1 +
 .../src/SCT_DetectorElementCondAlg.cxx        |  5 +--
 .../src/SCT_DetectorElementCondAlg.h          |  1 +
 .../python/ITkStripGeoModelConfig.py          | 33 ++++++++++++-------
 .../InDetDetDescrExample/PrintSiElements.h    |  2 ++
 .../src/PrintSiElements.cxx                   | 26 +++++++++++----
 .../src/ReadSiDetectorElements.cxx            | 16 ++++++---
 8 files changed, 61 insertions(+), 27 deletions(-)

diff --git a/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_AlignCondAlg.cxx b/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_AlignCondAlg.cxx
index 47e93011008..898c2757396 100644
--- a/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_AlignCondAlg.cxx
+++ b/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_AlignCondAlg.cxx
@@ -12,8 +12,10 @@
 SCT_AlignCondAlg::SCT_AlignCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
   : ::AthAlgorithm(name, pSvcLocator)
   , m_writeKey{"SCTAlignmentStore", "SCTAlignmentStore"}
+  , m_DetManagerName("SCT")
 {
   declareProperty("WriteKey", m_writeKey);
+  declareProperty("DetManagerName", m_DetManagerName);
 }
 
 StatusCode SCT_AlignCondAlg::initialize()
@@ -37,7 +39,7 @@ StatusCode SCT_AlignCondAlg::initialize()
   // Register write handle
   ATH_CHECK(m_condSvc->regHandle(this, m_writeKey));
 
-  ATH_CHECK(detStore()->retrieve(m_detManager, "SCT"));
+  ATH_CHECK(detStore()->retrieve(m_detManager, m_DetManagerName));
 
   return StatusCode::SUCCESS;
 }
diff --git a/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_AlignCondAlg.h b/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_AlignCondAlg.h
index 99d94b365ae..609d783f487 100644
--- a/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_AlignCondAlg.h
+++ b/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_AlignCondAlg.h
@@ -56,6 +56,7 @@ class SCT_AlignCondAlg : public AthAlgorithm
 
   ServiceHandle<ICondSvc> m_condSvc{this, "CondSvc", "CondSvc"};
   const InDetDD::SCT_DetectorManager* m_detManager{nullptr};
+  std::string m_DetManagerName;
 };
 
 #endif // SCT_CONDITIONSALGORITHMS_SCT_ALIGNCONDALG_H
diff --git a/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_DetectorElementCondAlg.cxx b/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_DetectorElementCondAlg.cxx
index 20a4b7111c4..6834a1097f5 100644
--- a/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_DetectorElementCondAlg.cxx
+++ b/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_DetectorElementCondAlg.cxx
@@ -14,8 +14,10 @@
 SCT_DetectorElementCondAlg::SCT_DetectorElementCondAlg(const std::string& name, ISvcLocator* pSvcLocator)
   : ::AthReentrantAlgorithm(name, pSvcLocator)
   , m_readKey{"SCTAlignmentStore", "SCTAlignmentStore"}
+  , m_detManagerName("SCT")
 {
   declareProperty("ReadKey", m_readKey);
+  declareProperty("DetManagerName", m_detManagerName);
 }
 
 StatusCode SCT_DetectorElementCondAlg::initialize()
@@ -31,8 +33,7 @@ StatusCode SCT_DetectorElementCondAlg::initialize()
   ATH_CHECK(m_condSvc.retrieve());
   // Register write handle
   ATH_CHECK(m_condSvc->regHandle(this, m_writeKey));
-
-  ATH_CHECK(detStore()->retrieve(m_detManager, "SCT"));
+  ATH_CHECK(detStore()->retrieve(m_detManager, m_detManagerName));
 
   return StatusCode::SUCCESS;
 }
diff --git a/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_DetectorElementCondAlg.h b/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_DetectorElementCondAlg.h
index a48d2bf65f2..d01dfb47521 100644
--- a/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_DetectorElementCondAlg.h
+++ b/InnerDetector/InDetConditions/SCT_ConditionsAlgorithms/src/SCT_DetectorElementCondAlg.h
@@ -38,6 +38,7 @@ class SCT_DetectorElementCondAlg : public AthReentrantAlgorithm
   SG::WriteCondHandleKey<InDetDD::SiDetectorElementCollection> m_writeKey{this, "WriteKey", "SCT_DetectorElementCollection", "Key of output SiDetectorElementCollection for SCT"};
 
   ServiceHandle<ICondSvc> m_condSvc{this, "CondSvc", "CondSvc"};
+  std::string m_detManagerName;
   const InDetDD::SCT_DetectorManager* m_detManager{nullptr};
 };
 
diff --git a/InnerDetector/InDetDetDescr/StripGeoModelXml/python/ITkStripGeoModelConfig.py b/InnerDetector/InDetDetDescr/StripGeoModelXml/python/ITkStripGeoModelConfig.py
index f4093350e75..a1a8e72cbfe 100644
--- a/InnerDetector/InDetDetDescr/StripGeoModelXml/python/ITkStripGeoModelConfig.py
+++ b/InnerDetector/InDetDetDescr/StripGeoModelXml/python/ITkStripGeoModelConfig.py
@@ -1,8 +1,7 @@
 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 
 from AthenaConfiguration.ComponentFactory import CompFactory
-#Comment to avoid python compilation warnings until block below is re-added
-#from IOVDbSvc.IOVDbSvcConfig import addFoldersSplitOnline
+from IOVDbSvc.IOVDbSvcConfig import addFoldersSplitOnline
 
 def ITkStripGeometryCfg( flags ):
     from AtlasGeoModel.GeoModelConfig import GeoModelCfg
@@ -12,7 +11,7 @@ def ITkStripGeometryCfg( flags ):
     acc.addService(GeometryDBSvc("ITkGeometryDBSvc"))
     StripDetectorTool=CompFactory.StripDetectorTool
     ITkStripDetectorTool = StripDetectorTool()
-    #ITkStripDetectorTool.useDynamicAlignFolders = flags.GeoModel.Align.Dynamic
+    #ITkStripDetectorTool.useDynamicAlignFolders = flags.GeoModel.Align.Dynamic #Will we need to do dynamic alignment for ITk?
     ITkStripDetectorTool.Alignable = False # make this a flag? Set true as soon as decided on folder structure
     ITkStripDetectorTool.DetectorName = "ITkStrip"
     if flags.ITk.useLocalGeometry:
@@ -20,6 +19,24 @@ def ITkStripGeometryCfg( flags ):
       ITkStripDetectorTool.GmxFilename = flags.ITk.stripGeometryFilename 
     geoModelSvc.DetectorTools += [ ITkStripDetectorTool ]
     
+    #Alignment corrections and DetElements to conditions
+    if flags.Common.Project != "AthSimulation": # Protection for AthSimulation builds
+        if (not flags.Detector.SimulateITkStrip) or flags.Detector.OverlayITkStrip:
+            acc.merge(addFoldersSplitOnline(flags,"INDET","/Indet/Onl/Align","/Indet/Align",className="AlignableTransformContainer")) #Just load a single static folder for the moment - to be revisted with ITk-specific folders
+            SCT_AlignCondAlg=CompFactory.SCT_AlignCondAlg
+            ITkStripAlignCondAlg = SCT_AlignCondAlg(name = "ITkStripAlignCondAlg",
+                                                    UseDynamicAlignFolders = flags.GeoModel.Align.Dynamic,
+                                                    DetManagerName = "ITkStrip",
+                                                    WriteKey = "ITkStripAlignmentStore")
+            acc.addCondAlgo(ITkStripAlignCondAlg)
+            SCT_DetectorElementCondAlg=CompFactory.SCT_DetectorElementCondAlg
+            ITkStripDetectorElementCondAlg = SCT_DetectorElementCondAlg(name = "ITkStripDetectorElementCondAlg",
+                                                                        ReadKey = "ITkStripAlignmentStore",
+                                                                        WriteKey = "ITkStripDetectorElementCollection",
+                                                                        DetManagerName = "ITkStrip")
+            acc.addCondAlgo(ITkStripDetectorElementCondAlg)
+
+
     """
     # All this stuff probably needs revisting - comment for now...
     if flags.GeoModel.Align.Dynamic:
@@ -31,14 +48,6 @@ def ITkStripGeometryCfg( flags ):
             acc.merge(addFoldersSplitOnline(flags,"INDET","/Indet/Onl/Align","/Indet/Align",className="AlignableTransformContainer"))
         else:
             acc.merge(addFoldersSplitOnline(flags,"INDET","/Indet/Onl/Align","/Indet/Align"))
-    if flags.Common.Project != "AthSimulation": # Protection for AthSimulation builds
-        if (not flags.Detector.SimulateSCT) or flags.Detector.OverlaySCT:
-            SCT_AlignCondAlg=CompFactory.SCT_AlignCondAlg
-            sctAlignCondAlg = SCT_AlignCondAlg(name = "SCT_AlignCondAlg",
-                                               UseDynamicAlignFolders = flags.GeoModel.Align.Dynamic)
-            acc.addCondAlgo(sctAlignCondAlg)
-            SCT_DetectorElementCondAlg=CompFactory.SCT_DetectorElementCondAlg
-            sctDetectorElementCondAlg = SCT_DetectorElementCondAlg(name = "SCT_DetectorElementCondAlg")
-            acc.addCondAlgo(sctDetectorElementCondAlg)
+
     """
     return acc
diff --git a/InnerDetector/InDetExample/InDetDetDescrExample/InDetDetDescrExample/PrintSiElements.h b/InnerDetector/InDetExample/InDetDetDescrExample/InDetDetDescrExample/PrintSiElements.h
index 452cf9e1202..727b249e670 100755
--- a/InnerDetector/InDetExample/InDetDetDescrExample/InDetDetDescrExample/PrintSiElements.h
+++ b/InnerDetector/InDetExample/InDetDetDescrExample/InDetDetDescrExample/PrintSiElements.h
@@ -43,6 +43,8 @@ private:
   ServiceHandle<IGeoModelSvc> m_geoModelSvc;
   SG::ReadCondHandleKey<InDetDD::SiDetectorElementCollection> m_pixelDetEleCollKey{this, "PixelDetEleCollKey", "PixelDetectorElementCollection", "Key of SiDetectorElementCollection for Pixel"};
   SG::ReadCondHandleKey<InDetDD::SiDetectorElementCollection> m_SCTDetEleCollKey{this, "SCTDetEleCollKey", "SCT_DetectorElementCollection", "Key of SiDetectorElementCollection for SCT"};
+  SG::ReadCondHandleKey<InDetDD::SiDetectorElementCollection> m_ITkStripDetEleCollKey{this, "ITkStripDetEleCollKey", "ITkStripDetectorElementCollection", "Key of SiDetectorElementCollection for ITkStrip"};
+  std::vector<std::string> m_detManagerNames;
 };
 
 #endif // InDetDetDescrExample_PrintSiElements_h
diff --git a/InnerDetector/InDetExample/InDetDetDescrExample/src/PrintSiElements.cxx b/InnerDetector/InDetExample/InDetDetDescrExample/src/PrintSiElements.cxx
index 88c8505d5c7..916d3f83a02 100755
--- a/InnerDetector/InDetExample/InDetDetDescrExample/src/PrintSiElements.cxx
+++ b/InnerDetector/InDetExample/InDetDetDescrExample/src/PrintSiElements.cxx
@@ -32,7 +32,8 @@ namespace{
 PrintSiElements::PrintSiElements(const std::string& name, ISvcLocator* pSvcLocator) 
   : AthAlgorithm(name, pSvcLocator), 
     m_firstEvent(true),
-    m_geoModelSvc("GeoModelSvc",name)
+    m_geoModelSvc("GeoModelSvc",name),
+    m_detManagerNames{"Pixel","SCT"}
 {  
   // Get parameter values from jobOptions file
   declareProperty("ModulesOnly", m_modulesOnly = true, "Print transforms of modules");
@@ -42,6 +43,7 @@ PrintSiElements::PrintSiElements(const std::string& name, ISvcLocator* pSvcLocat
   declareProperty("FullRotationMatrix", m_fullRotationMatrix = false, "If true prints the 9 elements of the rotation matrix");
   declareProperty("OutputFile", m_outputFileName = "geometry.dat", "Output file name");
   declareProperty("GeoModelSvc", m_geoModelSvc);
+  declareProperty("DetectorManagerNames", m_detManagerNames);
 }
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
@@ -65,6 +67,7 @@ StatusCode PrintSiElements::initialize(){
   // ReadCondHandleKey
   ATH_CHECK(m_pixelDetEleCollKey.initialize());
   ATH_CHECK(m_SCTDetEleCollKey.initialize());
+  ATH_CHECK(m_ITkStripDetEleCollKey.initialize());
   return StatusCode::SUCCESS;
 }
 
@@ -76,15 +79,23 @@ PrintSiElements::printElements(const std::string & managerName){
     SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> pixelDetEleHandle(m_pixelDetEleCollKey);
     elements = *pixelDetEleHandle;
     if (not pixelDetEleHandle.isValid() or elements==nullptr) {
-      ATH_MSG_FATAL(m_pixelDetEleCollKey.fullKey() << " is not available.");
-      return StatusCode::FAILURE;
+      ATH_MSG_WARNING(m_pixelDetEleCollKey.fullKey() << " is not available.");
+      return StatusCode::RECOVERABLE;
     }
   } else if (managerName=="SCT") {
     SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> sctDetEleHandle(m_SCTDetEleCollKey);
     elements = *sctDetEleHandle;
     if (not sctDetEleHandle.isValid() or elements==nullptr) {
-      ATH_MSG_FATAL(m_SCTDetEleCollKey.fullKey() << " is not available.");
-      return StatusCode::FAILURE;
+      ATH_MSG_WARNING(m_SCTDetEleCollKey.fullKey() << " is not available.");
+      return StatusCode::RECOVERABLE;
+    }
+  }
+  else if (managerName=="ITkStrip") {
+    SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> stripDetEleHandle(m_ITkStripDetEleCollKey);
+    elements = *stripDetEleHandle;
+    if (not stripDetEleHandle.isValid() or elements==nullptr) {
+      ATH_MSG_WARNING(m_ITkStripDetEleCollKey.fullKey() << " is not available.");
+      return StatusCode::RECOVERABLE;
     }
   }
   if (elements==nullptr) {
@@ -163,8 +174,9 @@ PrintSiElements::printElements(const std::string & managerName){
 StatusCode PrintSiElements::execute() {
   if (m_firstEvent) {
     m_firstEvent = false;
-    printElements("Pixel").ignore();
-    printElements("SCT").ignore();
+    for(std::string detManagerName : m_detManagerNames){
+      printElements(detManagerName).ignore();
+    }
   }
   return StatusCode::SUCCESS;
 }
diff --git a/InnerDetector/InDetExample/InDetDetDescrExample/src/ReadSiDetectorElements.cxx b/InnerDetector/InDetExample/InDetDetDescrExample/src/ReadSiDetectorElements.cxx
index 63ecf0fd824..f81ea8b6ad4 100755
--- a/InnerDetector/InDetExample/InDetDetDescrExample/src/ReadSiDetectorElements.cxx
+++ b/InnerDetector/InDetExample/InDetDetDescrExample/src/ReadSiDetectorElements.cxx
@@ -150,7 +150,8 @@ void ReadSiDetectorElements::printAllElements(const bool accessDuringInitializat
         // element->getIdHelper()->show(element->identify());
         //
   
-        ATH_MSG_ALWAYS(" center = " << element->center());
+        ATH_MSG_ALWAYS(" center (x,y,z) = " << element->center().x() << "," << element->center().y() << "," << element->center().z());
+	ATH_MSG_ALWAYS(" center (r,phi,z) = " << element->center().perp() << "," << element->center().phi() << "," <<element->center().z());
         ATH_MSG_ALWAYS(" sin(tilt), sin(stereo) = " <<  element->sinTilt() << " " 
                        << element->sinStereo());
         ATH_MSG_ALWAYS(" width, minWidth, maxWidth, length (mm) = " 
@@ -166,13 +167,16 @@ void ReadSiDetectorElements::printAllElements(const bool accessDuringInitializat
                          << m_siConditionsTool->temperature(hashId) << " "
                          << m_siConditionsTool->biasVoltage(hashId) << " "
                          << m_siConditionsTool->depletionVoltage(hashId));
-        }
+        
+
+	  ATH_MSG_ALWAYS(" Lorentz correction (mm), tanLorentzPhi = "
+			 << m_siLorentzAngleTool->getLorentzShift(hashId)/CLHEP::mm << " "
+			 << m_siLorentzAngleTool->getTanLorentzAngle(hashId));
 
-        ATH_MSG_ALWAYS(" Lorentz correction (mm), tanLorentzPhi = "
-            << m_siLorentzAngleTool->getLorentzShift(hashId)/CLHEP::mm << " "
-            << m_siLorentzAngleTool->getTanLorentzAngle(hashId));
+	}
 
         ATH_MSG_ALWAYS(" HashId, Id : " << hashId << "\t" << element->identify().getString());
+	
 
         // Make some consistency tests for the identifier.
         Identifier idTest;
@@ -207,6 +211,8 @@ void ReadSiDetectorElements::printAllElements(const bool accessDuringInitializat
       } else {
         // ATH_MSG_ALWAYS("Missing element!!!!!!!!!!!");
       }
+      //add divider between elements for readability
+	ATH_MSG_ALWAYS("-----------------------------");
     }
   }
   // Testing numerology
-- 
GitLab