From b87674cb87ebceaf825af6c640354910e098d79c Mon Sep 17 00:00:00 2001
From: Thomas Strebler <thomas.strebler@cern.ch>
Date: Fri, 22 Apr 2022 16:24:37 +0200
Subject: [PATCH] Extended prd info writing for CA tracking config

---
 .../PixelCalibAlgs/CMakeLists.txt             |   6 +-
 .../PixelCalibAlgs/PixelChargeToTConversion.h |  11 +-
 .../src/PixelChargeToTConversion.cxx          |  57 +++++-----
 .../InDetConfig/python/ITkConfigFlags.py      |   1 +
 .../InDetConfig/python/ITkTrackRecoConfig.py  |  31 +++++-
 .../InDetConfig/python/InDetConfigFlags.py    |   1 +
 .../python/InDetPrepRawDataToxAODConfig.py    | 101 ++++++++++++++++++
 .../python/PixelCalibAlgsConfig.py            |  32 ++++++
 .../InDetConfig/python/TrackRecoConfig.py     |  20 ++++
 .../src/PixelPrepDataToxAOD.h                 |   4 +-
 .../python/InDetPhysValDecorationConfig.py    |   4 +-
 .../python/TrkMeasurementUpdatorConfig.py     |   1 -
 12 files changed, 230 insertions(+), 39 deletions(-)
 create mode 100644 InnerDetector/InDetConfig/python/InDetPrepRawDataToxAODConfig.py
 create mode 100644 InnerDetector/InDetConfig/python/PixelCalibAlgsConfig.py

diff --git a/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/CMakeLists.txt b/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/CMakeLists.txt
index 3a113171374c..40e99062ce62 100755
--- a/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/CMakeLists.txt
+++ b/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
 
 # Declare the package name:
 atlas_subdir( PixelCalibAlgs )
@@ -13,8 +13,8 @@ atlas_add_library( PixelCalibAlgsLib
    PUBLIC_HEADERS PixelCalibAlgs
    INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
    LINK_LIBRARIES ${ROOT_LIBRARIES} AthenaBaseComps CxxUtils GaudiKernel InDetConditionsSummaryService 
-   InDetPrepRawData InDetReadoutGeometry PixelReadoutGeometryLib PixelConditionsData StoreGateLib
-   PRIVATE_LINK_LIBRARIES AthenaPoolUtilities EventInfo InDetIdentifier InDetRawData PixelGeoModelLib )
+   InDetPrepRawData InDetReadoutGeometry PixelGeoModelLib PixelReadoutGeometryLib PixelConditionsData StoreGateLib
+   PRIVATE_LINK_LIBRARIES AthenaPoolUtilities EventInfo InDetIdentifier InDetRawData )
 
 atlas_add_component( PixelCalibAlgs
    src/components/*.cxx
diff --git a/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/PixelCalibAlgs/PixelChargeToTConversion.h b/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/PixelCalibAlgs/PixelChargeToTConversion.h
index cd39ac04f26a..68263cab2cf1 100755
--- a/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/PixelCalibAlgs/PixelChargeToTConversion.h
+++ b/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/PixelCalibAlgs/PixelChargeToTConversion.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef PIXELCALIBALGS_PIXELCHARGETOTCONVERSION_H
@@ -12,6 +12,7 @@
 #include "InDetReadoutGeometry/SiDetectorElementCollection.h"
 #include "PixelConditionsData/PixelModuleData.h"
 #include "PixelConditionsData/PixelChargeCalibCondData.h"
+#include "PixelGeoModel/IBLParameterSvc.h"
 #include "PixelReadoutGeometry/IPixelReadoutManager.h"
 #include "StoreGate/ReadCondHandleKey.h"
 
@@ -20,8 +21,6 @@
 #include <string>
 #include <vector>
 
-class IBLParameterSvc;
-
 // FIXME: Modifies data in SG!
 class ATLAS_NOT_THREAD_SAFE PixelChargeToTConversion : public AthAlgorithm{
   
@@ -34,7 +33,8 @@ class ATLAS_NOT_THREAD_SAFE PixelChargeToTConversion : public AthAlgorithm{
   StatusCode finalize();
   
  private:
-  ServiceHandle<IBLParameterSvc> m_IBLParameterSvc;
+  ServiceHandle<IBLParameterSvc> m_IBLParameterSvc
+  {this, "IBLParameterSvc", "IBLParameterSvc"};
 
   SG::ReadHandleKey<InDet::PixelClusterContainer> m_pixelsClustersKey
   {this, "PixelClusterContainer",  "PixelClusters", ""};
@@ -52,6 +52,9 @@ class ATLAS_NOT_THREAD_SAFE PixelChargeToTConversion : public AthAlgorithm{
   SG::ReadCondHandleKey<InDetDD::SiDetectorElementCollection>
     m_pixelDetEleCollKey{this, "PixelDetEleCollKey", "PixelDetectorElementCollection",
       "Key of SiDetectorElementCollection for Pixel"};
+
+  bool m_doIBL = true; // Properly set in initialize()
+
 };
 
 #endif
diff --git a/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/src/PixelChargeToTConversion.cxx b/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/src/PixelChargeToTConversion.cxx
index f7b8e1103413..3b4655dbf79e 100644
--- a/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/src/PixelChargeToTConversion.cxx
+++ b/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/src/PixelChargeToTConversion.cxx
@@ -6,14 +6,12 @@
 #include "PixelCalibAlgs/PixelChargeToTConversion.h"
 #include "AthenaPoolUtilities/CondAttrListCollection.h" 
 #include "CxxUtils/checker_macros.h"
-#include "PixelGeoModel/IBLParameterSvc.h" 
 #include "InDetIdentifier/PixelID.h"
 #include "InDetPrepRawData/PixelCluster.h"
 #include "InDetReadoutGeometry/SiDetectorElement.h"
 
 PixelChargeToTConversion::PixelChargeToTConversion(const std::string& name, ISvcLocator* pSvcLocator) :
-  AthAlgorithm(name, pSvcLocator),
-  m_IBLParameterSvc("IBLParameterSvc",name)
+  AthAlgorithm(name, pSvcLocator)
 {
 }
 
@@ -27,11 +25,15 @@ StatusCode PixelChargeToTConversion::initialize(){
 
   ATH_MSG_INFO( "Initializing PixelChargeToTConversion" );
 
-  if (m_IBLParameterSvc.retrieve().isFailure()) { 
+  if (!m_IBLParameterSvc.empty()) {
+    if (m_IBLParameterSvc.retrieve().isFailure()) {
       ATH_MSG_FATAL("Could not retrieve IBLParameterSvc"); 
       return StatusCode::FAILURE; 
-  } else  
+    } else
       ATH_MSG_INFO("Retrieved service " << m_IBLParameterSvc); 
+  }
+
+  m_doIBL = !m_IBLParameterSvc.empty() && m_IBLParameterSvc->containsIBL();
 
   ATH_CHECK(m_pixelReadout.retrieve());
   ATH_CHECK(m_moduleDataKey.initialize());
@@ -53,7 +55,7 @@ StatusCode PixelChargeToTConversion::execute(){
   ATH_MSG_DEBUG( "Pixel Cluster container found:  " << pixel_container->size() << " collections" );
 
   int overflowIBLToT=0;
-  if( m_IBLParameterSvc->containsIBL()) {
+  if(m_doIBL) {
     overflowIBLToT = SG::ReadCondHandle<PixelModuleData>(m_moduleDataKey)->getFEI4OverflowToT(0,0);
   }
 
@@ -101,28 +103,29 @@ StatusCode PixelChargeToTConversion::execute(){
 	//
 	int sumToT = 0;
 	std::vector<int> totList;
-  for (int i=0; i<nRDO; i++) {
-    Identifier pixid=RDOs[i];
-    int Charge=Charges[i];
-
-    Identifier moduleID = pixelID.wafer_id(pixid);
-    IdentifierHash moduleHash = pixelID.wafer_hash(moduleID);
-    unsigned int FE = m_pixelReadout->getFE(pixid, moduleID);
-    InDetDD::PixelDiodeType type = m_pixelReadout->getDiodeType(pixid);
-    int totInt = calibData->getToT(type, moduleHash, FE, Charges[i]);
-
-    if( m_IBLParameterSvc->containsIBL() && pixelID.barrel_ec(pixid) == 0 && pixelID.layer_disk(pixid) == 0 ) {
-      int tot0 = totInt;
-      if ( totInt >= overflowIBLToT ) totInt = overflowIBLToT;
-      msg(MSG::DEBUG) << "barrel_ec = " << pixelID.barrel_ec(pixid) << " layer_disque = " <<  pixelID.layer_disk(pixid) << " ToT = " << tot0 << " Real ToT = " << totInt << endmsg;
-    }
 
-    totList.push_back( totInt ) ; // Fudge to make sure we round to the correct number
-    ATH_MSG_DEBUG( "from Charge --> ToT   " << Charge <<"  "<< totInt);
-    sumToT += totInt;
-  }
-  ATH_MSG_DEBUG( "sumToT   " << sumToT);
-  theNonConstCluster->setToTList (std::move (totList));
+	for (int i=0; i<nRDO; i++) {
+	  Identifier pixid=RDOs[i];
+	  int Charge=Charges[i];
+
+	  Identifier moduleID = pixelID.wafer_id(pixid);
+	  IdentifierHash moduleHash = pixelID.wafer_hash(moduleID);
+	  unsigned int FE = m_pixelReadout->getFE(pixid, moduleID);
+	  InDetDD::PixelDiodeType type = m_pixelReadout->getDiodeType(pixid);
+	  int totInt = calibData->getToT(type, moduleHash, FE, Charges[i]);
+
+	  if( m_doIBL && pixelID.barrel_ec(pixid) == 0 && pixelID.layer_disk(pixid) == 0 ) {
+	    int tot0 = totInt;
+	    if ( totInt >= overflowIBLToT ) totInt = overflowIBLToT;
+	    msg(MSG::DEBUG) << "barrel_ec = " << pixelID.barrel_ec(pixid) << " layer_disque = " <<  pixelID.layer_disk(pixid) << " ToT = " << tot0 << " Real ToT = " << totInt << endmsg;
+	  }
+
+	  totList.push_back( totInt ) ; // Fudge to make sure we round to the correct number
+	  ATH_MSG_DEBUG( "from Charge --> ToT   " << Charge <<"  "<< totInt);
+	  sumToT += totInt;
+	}
+	ATH_MSG_DEBUG( "sumToT   " << sumToT);
+	theNonConstCluster->setToTList (std::move (totList));
       }
 
     }//loop over clusters
diff --git a/InnerDetector/InDetConfig/python/ITkConfigFlags.py b/InnerDetector/InDetConfig/python/ITkConfigFlags.py
index 4b457e683172..32d91184c095 100644
--- a/InnerDetector/InDetConfig/python/ITkConfigFlags.py
+++ b/InnerDetector/InDetConfig/python/ITkConfigFlags.py
@@ -56,6 +56,7 @@ def createITkConfigFlags():
   itkcf.addFlag("ITk.Tracking.doSharedHits", True) # control if the shared hits are recorded in TrackParticles
   itkcf.addFlag("ITk.Tracking.materialInteractions", True)
   itkcf.addFlag("ITk.Tracking.writeSeedValNtuple", False) # Turn writing of seed validation ntuple on and off
+  itkcf.addFlag("ITk.Tracking.writeExtendedPRDInfo", False)
   
   # config flags for tracking geometry configuration
   from InDetConfig.TrackingGeometryFlags import createITkTrackingGeometryFlags
diff --git a/InnerDetector/InDetConfig/python/ITkTrackRecoConfig.py b/InnerDetector/InDetConfig/python/ITkTrackRecoConfig.py
index 5c314ebbc262..3384758ecd73 100644
--- a/InnerDetector/InDetConfig/python/ITkTrackRecoConfig.py
+++ b/InnerDetector/InDetConfig/python/ITkTrackRecoConfig.py
@@ -170,9 +170,38 @@ def ITkTrackRecoCfg(flags):
         from InDetConfig.VertexFindingConfig import primaryVertexFindingCfg
         result.merge(primaryVertexFindingCfg(flags))
 
+    if flags.ITk.Tracking.writeExtendedPRDInfo:
+        from InDetConfig.InDetPrepRawDataToxAODConfig import ITkPixelPrepDataToxAODCfg, ITkStripPrepDataToxAODCfg
+        result.merge(ITkPixelPrepDataToxAODCfg(flags, ClusterSplitProbabilityName = ClusterSplitProbContainer))
+        result.merge(ITkStripPrepDataToxAODCfg(flags))
+        if flags.Input.isMC:
+            from InDetPhysValMonitoring.InDetPhysValDecorationConfig import InDetPhysHitDecoratorAlgCfg
+            result.merge(InDetPhysHitDecoratorAlgCfg(flags))
+
+    # output
+    result.merge(ITkTrackRecoOutputCfg(flags))
+
+    return result
+
+def ITkTrackRecoOutputCfg(flags):
     from OutputStreamAthenaPool.OutputStreamConfig import addToESD,addToAOD
-    toAOD = ["xAOD::TrackParticleContainer#InDetTrackParticles", "xAOD::TrackParticleAuxContainer#InDetTrackParticlesAux."]
+    toAOD = []
     toESD = []
+
+    toAOD += [
+        "xAOD::TrackParticleContainer#InDetTrackParticles",
+        "xAOD::TrackParticleAuxContainer#InDetTrackParticlesAux."
+    ]
+
+    if flags.ITk.Tracking.writeExtendedPRDInfo:
+        toAOD += [
+            "xAOD::TrackMeasurementValidationContainer#ITkPixelClusters",
+            "xAOD::TrackMeasurementValidationAuxContainer#ITkPixelClustersAux.",
+            "xAOD::TrackMeasurementValidationContainer#ITkStripClusters",
+            "xAOD::TrackMeasurementValidationAuxContainer#ITkStripClustersAux."
+        ]
+
+    result = ComponentAccumulator()
     result.merge(addToESD(flags, toAOD+toESD))
     result.merge(addToAOD(flags, toAOD))
     return result
diff --git a/InnerDetector/InDetConfig/python/InDetConfigFlags.py b/InnerDetector/InDetConfig/python/InDetConfigFlags.py
index 6fd963010015..721e58e7009a 100644
--- a/InnerDetector/InDetConfig/python/InDetConfigFlags.py
+++ b/InnerDetector/InDetConfig/python/InDetConfigFlags.py
@@ -83,6 +83,7 @@ def createInDetConfigFlags():
   icf.addFlag("InDet.Tracking.doVtxLumi", False) # Special reconstruction for vertex lumi measurement
   icf.addFlag("InDet.Tracking.doVtxBeamSpot", False) # Special reconstruction for vertex beamspot measurement
   icf.addFlag("InDet.Tracking.doLowMu", False) # Special configuration for low-mu runs
+  icf.addFlag("InDet.Tracking.writeExtendedPRDInfo", False)
 
   from InDetConfig.TrackingPassFlags import createTrackingPassFlags, createHighPileupTrackingPassFlags, \
     createMinBiasTrackingPassFlags, createLargeD0TrackingPassFlags, createR3LargeD0TrackingPassFlags, createLowPtLargeD0TrackingPassFlags, \
diff --git a/InnerDetector/InDetConfig/python/InDetPrepRawDataToxAODConfig.py b/InnerDetector/InDetConfig/python/InDetPrepRawDataToxAODConfig.py
new file mode 100644
index 000000000000..2c0031cc2e61
--- /dev/null
+++ b/InnerDetector/InDetConfig/python/InDetPrepRawDataToxAODConfig.py
@@ -0,0 +1,101 @@
+# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
+# Configuration of InDetPrepRawDataToxAOD package
+from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
+from AthenaConfiguration.ComponentFactory import CompFactory
+
+def InDetPixelPrepDataToxAODCfg(flags, name='InDetPixelPrepDataToxAOD', ClusterSplitProbabilityName='', **kwargs):
+    from PixelGeoModel.PixelGeoModelConfig import PixelReadoutGeometryCfg
+    acc = PixelReadoutGeometryCfg(flags)
+
+    from PixelConditionsAlgorithms.PixelConditionsConfig import PixelChargeCalibCondAlgCfg, PixelDCSCondStateAlgCfg, PixelDCSCondStatusAlgCfg, PixelDCSCondTempAlgCfg, PixelDCSCondHVAlgCfg
+    acc.merge(PixelChargeCalibCondAlgCfg(flags))
+    acc.merge(PixelDCSCondStateAlgCfg(flags))
+    acc.merge(PixelDCSCondStatusAlgCfg(flags))
+    acc.merge(PixelDCSCondTempAlgCfg(flags))
+    acc.merge(PixelDCSCondHVAlgCfg(flags))
+
+    from InDetConfig.PixelCalibAlgsConfig import PixelChargeToTConversionCfg
+    acc.merge(PixelChargeToTConversionCfg(flags))
+
+    if "PixelConditionsSummaryTool" not in kwargs:
+        from PixelConditionsTools.PixelConditionsSummaryConfig import PixelConditionsSummaryCfg
+        kwargs.setdefault("PixelConditionsSummaryTool", acc.popToolsAndMerge(PixelConditionsSummaryCfg(flags)))
+
+    if "LorentzAngleTool" not in kwargs:
+        from SiLorentzAngleTool.PixelLorentzAngleConfig import PixelLorentzAngleToolCfg
+        kwargs.setdefault("LorentzAngleTool", acc.popToolsAndMerge(PixelLorentzAngleToolCfg(flags)))
+
+    kwargs.setdefault("UseTruthInfo", flags.Input.isMC)
+    kwargs.setdefault("ClusterSplitProbabilityName", ClusterSplitProbabilityName)
+
+    acc.addEventAlgo(CompFactory.PixelPrepDataToxAOD(name, **kwargs))
+    return acc
+
+def ITkPixelPrepDataToxAODCfg(flags, name='ITkPixelPrepDataToxAOD', ClusterSplitProbabilityName='', **kwargs):
+    from PixelGeoModelXml.ITkPixelGeoModelConfig import ITkPixelReadoutGeometryCfg
+    acc = ITkPixelReadoutGeometryCfg(flags)
+
+    from PixelConditionsAlgorithms.ITkPixelConditionsConfig import ITkPixelChargeCalibCondAlgCfg, ITkPixelDCSCondStateAlgCfg, ITkPixelDCSCondStatusAlgCfg, ITkPixelDCSCondTempAlgCfg, ITkPixelDCSCondHVAlgCfg
+    acc.merge(ITkPixelChargeCalibCondAlgCfg(flags))
+    acc.merge(ITkPixelDCSCondStateAlgCfg(flags))
+    acc.merge(ITkPixelDCSCondStatusAlgCfg(flags))
+    acc.merge(ITkPixelDCSCondTempAlgCfg(flags))
+    acc.merge(ITkPixelDCSCondHVAlgCfg(flags))
+
+    from InDetConfig.PixelCalibAlgsConfig import ITkPixelChargeToTConversionCfg
+    acc.merge(ITkPixelChargeToTConversionCfg(flags))
+
+    if "PixelConditionsSummaryTool" not in kwargs:
+        from PixelConditionsTools.ITkPixelConditionsSummaryConfig import ITkPixelConditionsSummaryCfg
+        kwargs.setdefault("PixelConditionsSummaryTool", acc.popToolsAndMerge(ITkPixelConditionsSummaryCfg(flags)))
+
+    if "LorentzAngleTool" not in kwargs:
+        from SiLorentzAngleTool.ITkPixelLorentzAngleConfig import ITkPixelLorentzAngleToolCfg
+        kwargs.setdefault("LorentzAngleTool", acc.popToolsAndMerge(ITkPixelLorentzAngleToolCfg(flags)))
+
+    kwargs.setdefault("UseTruthInfo", flags.Input.isMC)
+    kwargs.setdefault("ClusterSplitProbabilityName", ClusterSplitProbabilityName)
+    kwargs.setdefault("PixelReadoutManager", "ITkPixelReadoutManager")
+    kwargs.setdefault("PixelChargeCalibCondData", "ITkPixelChargeCalibCondData")
+    kwargs.setdefault("PixelDCSStateCondData", "ITkPixelDCSStateCondData")
+    kwargs.setdefault("PixelDCSStatusCondData", "ITkPixelDCSStatusCondData")
+    kwargs.setdefault("ReadKeyTemp", "ITkPixelDCSTempCondData")
+    kwargs.setdefault("ReadKeyHV", "ITkPixelDCSHVCondData")    
+    kwargs.setdefault("SiClusterContainer", "ITkPixelClusters")
+    kwargs.setdefault("MC_SDOs", "ITkPixelSDO_Map")
+    kwargs.setdefault("MC_Hits", "ITkPixelHits")
+    kwargs.setdefault("PRD_MultiTruth", "PRD_MultiTruthITkPixel")
+    kwargs.setdefault("OutputClusterContainer", "ITkPixelClusters")
+
+    acc.addEventAlgo(CompFactory.PixelPrepDataToxAOD(name, **kwargs))
+    return acc
+    
+def InDetSCT_PrepDataToxAODCfg(flags, name='InDetSCTPrepDataToxAOD', **kwargs):
+    from SCT_GeoModel.SCT_GeoModelConfig import SCT_ReadoutGeometryCfg
+    acc = SCT_ReadoutGeometryCfg(flags)
+    kwargs.setdefault("UseTruthInfo", flags.Input.isMC)
+    acc.addEventAlgo(CompFactory.SCT_PrepDataToxAOD(name, **kwargs))
+    return acc
+
+def ITkStripPrepDataToxAODCfg(flags, name='ITkStripPrepDataToxAOD', **kwargs):
+    from StripGeoModelXml.ITkStripGeoModelConfig import ITkStripReadoutGeometryCfg
+    acc = ITkStripReadoutGeometryCfg(flags)
+
+    kwargs.setdefault("SiClusterContainer", "ITkStripClusters")
+    kwargs.setdefault("MC_SDOs", "ITkStripSDO_Map")
+    kwargs.setdefault("MC_Hits", "ITkStripHits")
+    kwargs.setdefault("PRD_MultiTruth", "PRD_MultiTruthITkStrip")
+    kwargs.setdefault("SctRdoContainer", "ITkStripRDOs")
+    kwargs.setdefault("SctxAodContainer", "ITkStripClusters")
+    kwargs.setdefault("SctxAodOffset", "ITkStripClustersOffsets")
+    kwargs.setdefault("SCTDetEleCollKey", "ITkStripDetectorElementCollection")
+    kwargs.setdefault("UseTruthInfo", flags.Input.isMC)
+
+    acc.addEventAlgo(CompFactory.SCT_PrepDataToxAOD(name, **kwargs))
+    return acc
+
+def InDetTRT_PrepDataToxAODCfg(flags, name='InDetTRTPrepDataToxAOD', **kwargs):
+    acc = ComponentAccumulator()
+    kwargs.setdefault("UseTruthInfo", flags.Input.isMC)
+    acc.addEventAlgo(CompFactory.TRT_PrepDataToxAOD(name, **kwargs))
+    return acc
diff --git a/InnerDetector/InDetConfig/python/PixelCalibAlgsConfig.py b/InnerDetector/InDetConfig/python/PixelCalibAlgsConfig.py
new file mode 100644
index 000000000000..781c28132787
--- /dev/null
+++ b/InnerDetector/InDetConfig/python/PixelCalibAlgsConfig.py
@@ -0,0 +1,32 @@
+# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
+# Configuration of PixelCalibAlgs package
+from AthenaConfiguration.ComponentFactory import CompFactory
+
+def PixelChargeToTConversionCfg(flags, name='InDetPixelChargeToTConversion', **kwargs):
+    from PixelReadoutGeometry.PixelReadoutGeometryConfig import PixelReadoutManagerCfg
+    acc = PixelReadoutManagerCfg(flags)
+
+    from PixelConditionsAlgorithms.PixelConditionsConfig import PixelConfigCondAlgCfg, PixelChargeCalibCondAlgCfg
+    acc.merge(PixelConfigCondAlgCfg(flags))
+    acc.merge(PixelChargeCalibCondAlgCfg(flags))
+    
+    acc.addEventAlgo(CompFactory.PixelChargeToTConversion(name, **kwargs))
+    return acc
+
+def ITkPixelChargeToTConversionCfg(flags, name='ITkPixelChargeToTConversion', **kwargs):
+    from PixelReadoutGeometry.PixelReadoutGeometryConfig import ITkPixelReadoutManagerCfg
+    acc = ITkPixelReadoutManagerCfg(flags)
+
+    from PixelConditionsAlgorithms.ITkPixelConditionsConfig import ITkPixelModuleConfigCondAlgCfg, ITkPixelChargeCalibCondAlgCfg
+    acc.merge(ITkPixelModuleConfigCondAlgCfg(flags))
+    acc.merge(ITkPixelChargeCalibCondAlgCfg(flags))
+    
+    kwargs.setdefault("PixelClusterContainer", "ITkPixelClusters")
+    kwargs.setdefault("PixelReadoutManager", "ITkPixelReadoutManager")
+    kwargs.setdefault("PixelModuleData", "ITkPixelModuleData")
+    kwargs.setdefault("PixelChargeCalibCondData", "ITkPixelChargeCalibCondData")
+    kwargs.setdefault("PixelDetEleCollKey", "ITkPixelDetectorElementCollection")
+    kwargs.setdefault("IBLParameterSvc", "")
+
+    acc.addEventAlgo(CompFactory.PixelChargeToTConversion(name, **kwargs))
+    return acc
diff --git a/InnerDetector/InDetConfig/python/TrackRecoConfig.py b/InnerDetector/InDetConfig/python/TrackRecoConfig.py
index 5c6adb02a594..6d2160559fb3 100644
--- a/InnerDetector/InDetConfig/python/TrackRecoConfig.py
+++ b/InnerDetector/InDetConfig/python/TrackRecoConfig.py
@@ -431,6 +431,16 @@ def InDetTrackRecoCfg(flags):
         from InDetConfig.VertexFindingConfig import primaryVertexFindingCfg
         result.merge(primaryVertexFindingCfg(flags))
 
+    if flags.InDet.Tracking.writeExtendedPRDInfo:
+        from InDetConfig.InDetPrepRawDataToxAODConfig import InDetPixelPrepDataToxAODCfg, InDetSCT_PrepDataToxAODCfg, InDetTRT_PrepDataToxAODCfg
+        result.merge(InDetPixelPrepDataToxAODCfg(flags, ClusterSplitProbabilityName = ClusterSplitProbContainer))
+        result.merge(InDetSCT_PrepDataToxAODCfg(flags))
+        result.merge(InDetTRT_PrepDataToxAODCfg(flags))
+
+        if flags.Input.isMC:
+            from InDetPhysValMonitoring.InDetPhysValDecorationConfig import InDetPhysHitDecoratorAlgCfg
+            result.merge(InDetPhysHitDecoratorAlgCfg(flags))
+
     # output
     result.merge(InDetTrackRecoOutputCfg(flags))
 
@@ -630,6 +640,16 @@ def InDetTrackRecoOutputCfg(flags):
             toAOD += ["TrackTruthCollection#InDetObservedTrackTruthCollection"]
             toAOD += ["DetailedTrackTruthCollection#ObservedDetailedTracksTruth"]
 
+    if flags.InDet.Tracking.writeExtendedPRDInfo:
+        toAOD += [
+            "xAOD::TrackMeasurementValidationContainer#PixelClusters",
+            "xAOD::TrackMeasurementValidationAuxContainer#PixelClustersAux.",
+            "xAOD::TrackMeasurementValidationContainer#SCT_Clusters",
+            "xAOD::TrackMeasurementValidationAuxContainer#SCT_ClustersAux.",
+            "xAOD::TrackMeasurementValidationContainer#TRT_DriftCircles",
+            "xAOD::TrackMeasurementValidationAuxContainer#TRT_DriftCirclesAux."
+        ]
+
     result = ComponentAccumulator()
     result.merge(addToESD(flags, toESD + toAOD))
     result.merge(addToAOD(flags, toAOD))
diff --git a/InnerDetector/InDetEventCnv/InDetPrepRawDataToxAOD/src/PixelPrepDataToxAOD.h b/InnerDetector/InDetEventCnv/InDetPrepRawDataToxAOD/src/PixelPrepDataToxAOD.h
index 7574dd281f8a..61ab63710b97 100644
--- a/InnerDetector/InDetEventCnv/InDetPrepRawDataToxAOD/src/PixelPrepDataToxAOD.h
+++ b/InnerDetector/InDetEventCnv/InDetPrepRawDataToxAOD/src/PixelPrepDataToxAOD.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
 */
 /**
  * @file InDetPrepRawDataToxAOD/PixelPrepDataToxAOD.h
@@ -129,7 +129,7 @@ private:
   {this, "PixelDCSStatusCondData", "PixelDCSStatusCondData", "Pixel FSM status key"};
 
   SG::ReadCondHandleKey<PixelDCSTempData> m_readKeyTemp
-  {this, "ReadKeyeTemp", "PixelDCSTempCondData", "Key of input sensor temperature conditions folder"};
+  {this, "ReadKeyTemp", "PixelDCSTempCondData", "Key of input sensor temperature conditions folder"};
 
   SG::ReadCondHandleKey<PixelDCSHVData> m_readKeyHV
   {this, "ReadKeyHV",    "PixelDCSHVCondData", "Key of input bias voltage conditions folder"};
diff --git a/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/InDetPhysValDecorationConfig.py b/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/InDetPhysValDecorationConfig.py
index 05aa69bfd4f1..677461792957 100644
--- a/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/InDetPhysValDecorationConfig.py
+++ b/InnerDetector/InDetValidation/InDetPhysValMonitoring/python/InDetPhysValDecorationConfig.py
@@ -96,11 +96,13 @@ def InDetPhysHitDecoratorAlgCfg(flags, **kwargs):
     acc = ComponentAccumulator()
 
     from InDetConfig.InDetTrackHoleSearchConfig import InDetTrackHoleSearchToolCfg
-    InDetTrackHoleSearchTool = acc.popToolsAndMerge(InDetTrackHoleSearchToolCfg(flags, name="PhysValMonInDetHoleSearchTool"))
+    InDetTrackHoleSearchTool = acc.popToolsAndMerge(InDetTrackHoleSearchToolCfg(flags))
+    acc.addPublicTool(InDetTrackHoleSearchTool)
     kwargs.setdefault( "InDetTrackHoleSearchTool", InDetTrackHoleSearchTool)
 
     from TrkConfig.TrkMeasurementUpdatorConfig import InDetUpdatorCfg
     Updator = acc.popToolsAndMerge(InDetUpdatorCfg(flags))
+    acc.addPublicTool(Updator)
     kwargs.setdefault( "Updator", Updator )
 
     acc.merge(createExtendNameIfNotDefaultCfg(CompFactory.InDetPhysHitDecoratorAlg,
diff --git a/Tracking/TrkConfig/python/TrkMeasurementUpdatorConfig.py b/Tracking/TrkConfig/python/TrkMeasurementUpdatorConfig.py
index 112656b4336f..ec79ad5be802 100644
--- a/Tracking/TrkConfig/python/TrkMeasurementUpdatorConfig.py
+++ b/Tracking/TrkConfig/python/TrkMeasurementUpdatorConfig.py
@@ -16,7 +16,6 @@ def KalmanUpdatorCfg(flags, name='KalmanUpdator', **kwargs):
 def InDetUpdatorCfg(flags, name = 'InDetUpdator', **kwargs):
     if flags.Detector.GeometryITk:
         name = name.replace("InDet", "ITk")
-        from InDetConfig.ITkRecToolConfig import ITkUpdatorCfg
         return ITkUpdatorCfg(flags, name, **kwargs)
 
     acc = ComponentAccumulator()
-- 
GitLab