diff --git a/InnerDetector/InDetConditions/TRT_ConditionsAlgs/src/TRTPhaseCondAlg.cxx b/InnerDetector/InDetConditions/TRT_ConditionsAlgs/src/TRTPhaseCondAlg.cxx
new file mode 100644
index 0000000000000000000000000000000000000000..3344094ed3812e4bf23e5bb9ac09e274632793e1
--- /dev/null
+++ b/InnerDetector/InDetConditions/TRT_ConditionsAlgs/src/TRTPhaseCondAlg.cxx
@@ -0,0 +1,148 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+*/
+
+#include "TRTPhaseCondAlg.h"
+#include "TRT_ConditionsData/RtRelation.h"
+#include "TRT_ConditionsData/BasicRtRelation.h"
+#include "InDetIdentifier/TRT_ID.h"
+
+TRTPhaseCondAlg::TRTPhaseCondAlg(const std::string& name
+				 , ISvcLocator* pSvcLocator )
+  : ::AthAlgorithm(name,pSvcLocator),
+    m_condSvc("CondSvc",name),
+    m_caldbtool("TRT_CalDbTool",this),
+    m_trtId(0)
+{ declareProperty("TRTCalDbTool",m_caldbtool); }
+
+TRTPhaseCondAlg::~TRTPhaseCondAlg(){}
+
+StatusCode TRTPhaseCondAlg::initialize()
+{
+
+  // CondSvc
+  ATH_CHECK( m_condSvc.retrieve() );
+
+  // Straw status
+  ATH_CHECK ( m_caldbtool.retrieve() );
+
+  // Read key
+  ATH_CHECK( m_T0ReadKey.initialize() );
+
+
+  // Register write handle
+  ATH_CHECK( m_T0WriteKey.initialize() );
+
+  if (m_condSvc->regHandle(this, m_T0WriteKey).isFailure()) {
+    ATH_MSG_ERROR("unable to register WriteCondHandle " << m_T0WriteKey.fullKey() << " with CondSvc");
+    return StatusCode::FAILURE;
+  }
+
+  // TRT ID helper
+  ATH_CHECK(detStore()->retrieve(m_trtId,"TRT_ID"));
+
+  return StatusCode::SUCCESS;
+}
+
+StatusCode TRTPhaseCondAlg::execute() 
+{
+  ATH_MSG_DEBUG("execute " << name());
+
+  // ____________ Construct Write Cond Handle and check its validity ____________
+
+  SG::WriteCondHandle<TRTCond::AverageT0> writeHandle{m_T0WriteKey};
+
+  // Do we have a valid Write Cond Handle for current time?
+  if(writeHandle.isValid()) {
+    ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid."
+                  << ". In theory this should not be called, but may happen"
+                  << " if multiple concurrent events are being processed out of order.");
+
+    return StatusCode::SUCCESS; 
+  }
+
+
+
+  // ____________ Construct new Write Cond Object  ____________
+  std::unique_ptr<TRTCond::AverageT0> writeCdo{std::make_unique<TRTCond::AverageT0>()};
+  
+
+  // ____________ Average T0 for Write Cond object (code adapted from InDetCosmicsEventPhaseTool::beginRun()) _____
+  int countAverageT0 = 0;
+  double rtShift = 0.;
+  double averageT0 = 0.;
+
+  for (std::vector<Identifier>::const_iterator it = m_trtId->straw_layer_begin(); it != m_trtId->straw_layer_end(); it++  ) {
+
+    int nStrawsInLayer = m_trtId->straw_max(*it);
+
+    for (int i = 0; i <= nStrawsInLayer; i++) {
+      Identifier id = m_trtId->straw_id(*it, i);
+      if (std::abs(m_trtId->barrel_ec(id)) != 1) continue; // average over barrel only
+      averageT0 += m_caldbtool->getT0(id);
+      countAverageT0++;
+      const TRTCond::RtRelation* rtRelation = m_caldbtool->getRtRelation(id);
+      if (!rtRelation) {
+        ATH_MSG_DEBUG("rtRelation missing for straw ");
+        continue;
+      }
+      rtShift += rtRelation->drifttime(0.);
+    }
+  }
+  if (countAverageT0 != 0){
+    averageT0 /= double(countAverageT0);
+  } else {
+    averageT0 = 0.;
+  }
+
+  if (countAverageT0 != 0) {
+    rtShift /= double(countAverageT0);
+  } else {
+    rtShift = 0.;
+  }
+
+  double evtPhaseT0 = averageT0-20.+rtShift; // (Correction to be checked /PH)
+
+  ATH_MSG_INFO(" Subtracting: " << evtPhaseT0 << " ns (average T0: " << averageT0 << " ns, average t(r=0): " << rtShift << " ns )");
+
+  writeCdo->update(evtPhaseT0);
+
+  //__________ Assign range of writeCdo to that of the ReadHandle___________ 
+  EventIDRange rangeW;
+
+    SG::ReadCondHandle<StrawT0Container> T0ReadHandle{m_T0ReadKey};
+    const StrawT0Container* T0Container{*T0ReadHandle};
+    if(T0Container==nullptr) {
+        ATH_MSG_ERROR("Null pointer to the straw T0 container");
+        return StatusCode::FAILURE;
+    }
+
+    // Get range
+    if(!T0ReadHandle.range(rangeW)) {
+        ATH_MSG_ERROR("Failed to retrieve validity range for " << T0ReadHandle.key());
+        return StatusCode::FAILURE;
+    }
+
+
+  // Record  CDO
+ if(writeHandle.record(rangeW,std::move(writeCdo)).isFailure()) {
+    ATH_MSG_ERROR("Could not record AverageT0 " << writeHandle.key() 
+		  << " with EventRange " << rangeW
+		  << " into Conditions Store");
+    return StatusCode::FAILURE;
+ } else {
+    ATH_MSG_INFO(" Recorded AverageT0 " << writeHandle.key() 
+		  << " with EventRange " << rangeW
+		  << " into Conditions Store");
+
+ }
+  return StatusCode::SUCCESS;
+}
+
+StatusCode TRTPhaseCondAlg::finalize()
+{
+  ATH_MSG_DEBUG("finalize " << name());
+  return StatusCode::SUCCESS;
+}
+
+
diff --git a/InnerDetector/InDetConditions/TRT_ConditionsAlgs/src/TRTPhaseCondAlg.h b/InnerDetector/InDetConditions/TRT_ConditionsAlgs/src/TRTPhaseCondAlg.h
new file mode 100644
index 0000000000000000000000000000000000000000..afec6df0873ae2dc6b0d3b94f8bf078a12ccf777
--- /dev/null
+++ b/InnerDetector/InDetConditions/TRT_ConditionsAlgs/src/TRTPhaseCondAlg.h
@@ -0,0 +1,38 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef TRTPHASECONDALG_H
+#define TRTPHASECONDALG_H
+
+#include "AthenaBaseComps/AthAlgorithm.h"
+#include "StoreGate/WriteCondHandleKey.h"
+#include "GaudiKernel/ToolHandle.h"
+#include "TRT_ConditionsData/AverageT0.h"
+#include "TRT_ConditionsServices/ITRT_CalDbTool.h"
+#include "GaudiKernel/ICondSvc.h"
+#include "GaudiKernel/Property.h"
+
+class TRT_ID;
+
+class TRTPhaseCondAlg : public AthAlgorithm
+{
+ public:
+  typedef TRTCond::StrawT0MultChanContainer StrawT0Container ;
+  TRTPhaseCondAlg(const std::string& name, ISvcLocator* pSvcLocator);
+  virtual ~TRTPhaseCondAlg() override;
+
+  virtual StatusCode initialize() override;
+  virtual StatusCode execute() override;
+  virtual StatusCode finalize() override;
+
+
+ private:
+  ServiceHandle<ICondSvc> m_condSvc;
+  SG::ReadCondHandleKey<StrawT0Container> m_T0ReadKey{this,"T0ReadKey","/TRT/Calib/T0","T0 in-key"};
+  SG::WriteCondHandleKey<TRTCond::AverageT0> m_T0WriteKey{this,"T0WriteKey","AverageT0","Average T0 out-key"};
+  ToolHandle<ITRT_CalDbTool> m_caldbtool;
+  const TRT_ID *m_trtId;
+
+};
+#endif
diff --git a/InnerDetector/InDetConditions/TRT_ConditionsAlgs/src/components/TRT_ConditionsAlgs_entries.cxx b/InnerDetector/InDetConditions/TRT_ConditionsAlgs/src/components/TRT_ConditionsAlgs_entries.cxx
index 6b8505f1a7d944631cddaf082e593886d736b057..cc000e46d8df5ad4e7c6b7c10a1e23b0cc455a5e 100644
--- a/InnerDetector/InDetConditions/TRT_ConditionsAlgs/src/components/TRT_ConditionsAlgs_entries.cxx
+++ b/InnerDetector/InDetConditions/TRT_ConditionsAlgs/src/components/TRT_ConditionsAlgs_entries.cxx
@@ -7,6 +7,7 @@
 #include "../TRTToTCondAlg.h"
 #include "../TRTActiveCondAlg.h"
 #include "../TRTHWMapCondAlg.h"
+#include "../TRTPhaseCondAlg.h"
 
 
 DECLARE_COMPONENT( TRTCondWrite )
@@ -18,3 +19,4 @@ DECLARE_COMPONENT( TRTHTCondAlg )
 DECLARE_COMPONENT( TRTToTCondAlg )
 DECLARE_COMPONENT( TRTActiveCondAlg )
 DECLARE_COMPONENT( TRTHWMapCondAlg )
+DECLARE_COMPONENT( TRTPhaseCondAlg )
diff --git a/InnerDetector/InDetConditions/TRT_ConditionsData/TRT_ConditionsData/AverageT0.h b/InnerDetector/InDetConditions/TRT_ConditionsData/TRT_ConditionsData/AverageT0.h
new file mode 100644
index 0000000000000000000000000000000000000000..d4e27c8cbea3450ac1e40a012deb294217f7f5ad
--- /dev/null
+++ b/InnerDetector/InDetConditions/TRT_ConditionsData/TRT_ConditionsData/AverageT0.h
@@ -0,0 +1,27 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef AVERAGET0_H
+#define AVERAGET0_H
+#include "AthenaKernel/CLASS_DEF.h"
+#include "AthenaKernel/CondCont.h"
+namespace TRTCond{
+  class AverageT0{
+  public:
+    AverageT0() {
+       m_avgT0 = 0.;
+    }
+
+    virtual ~AverageT0() {}
+    // Store average T0
+    void update(const float& at0 ) { m_avgT0=at0; }
+    double get() const {return m_avgT0;}
+
+  private:
+    double m_avgT0;
+  };
+}
+CLASS_DEF(TRTCond::AverageT0,221681781,1)
+CONDCONT_DEF(TRTCond::AverageT0,71803019);
+#endif
diff --git a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/IInDetCosmicsEventPhaseTool.h b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/IInDetCosmicsEventPhaseTool.h
index 61b6e37237f7b90bf734d036eb0699b05f2d374e..164aee3bb8fbb88c711ada067444f85544acda0f 100644
--- a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/IInDetCosmicsEventPhaseTool.h
+++ b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/IInDetCosmicsEventPhaseTool.h
@@ -23,9 +23,6 @@ namespace InDet
   public:
     static const InterfaceID& interfaceID( ) ;
 
-    /** if m_useNewEP = True, set averageT0 != 0 */
-    virtual void beginRun()=0; 
-
     /** finds event phase of a track from the leading edge */
     virtual double findPhase(const Trk::Track *track) const =0;
 
diff --git a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/InDetCosmicsEventPhase.h b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/InDetCosmicsEventPhase.h
index 02516c65614d86ca39254fc40324c47672c651a5..c3b94fe1e28303c4f4dbeb0c781cf73858d1ceb0 100755
--- a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/InDetCosmicsEventPhase.h
+++ b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/InDetCosmicsEventPhase.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
 */
 
 #include "AthenaBaseComps/AthAlgorithm.h"
@@ -15,7 +15,7 @@
 
 /////////////////////////////////////////////////////////////////////////////
 //class TrackCollection;
-class ITRT_CalDbSvc ;
+class ITRT_CalDbTool ;
 
 namespace InDet 
 {
@@ -29,19 +29,17 @@ namespace InDet
     public:
       InDetCosmicsEventPhase (const std::string& name, ISvcLocator* pSvcLocator);
       StatusCode initialize();
-      StatusCode beginRun();
       StatusCode execute();
       StatusCode finalize();
       StatusCode storePhase();
       
     private:
-      int 	m_event;
       double	m_phase;
 
       SG::ReadHandleKeyArray<TrackCollection>	m_readKey_tracks 	{this, "InputTracksNames"	,{"Tracks"}, "Tracks to extract event phase" };
       SG::WriteHandleKey<ComTime> 		m_writeKey_TRTPhase	{this, "EventPhaseName"		,"TRT_Phase", "TRT Event Phase name to store" };
 
-      ServiceHandle<ITRT_CalDbSvc>       m_trtconddbsvc ;//!< TRT Calibration DB tool
+      ToolHandle<ITRT_CalDbTool>       m_caldbtool ;//!< TRT Calibration DB tool
       ToolHandle<Trk::ITrackSummaryTool> m_trackSumTool; //<! Track summary tool
       ToolHandle<InDet::IInDetCosmicsEventPhaseTool> m_eventPhaseTool; //<! Cosmics Event Phase tool
     };
diff --git a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/InDetCosmicsEventPhaseTool.h b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/InDetCosmicsEventPhaseTool.h
index 14a027ef10409db431828d0722d9059fc7f809de..0e6c36fb769c0c289277c1f684d7af1947264968 100644
--- a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/InDetCosmicsEventPhaseTool.h
+++ b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/InDetCosmicsEventPhaseTool.h
@@ -11,10 +11,12 @@
 
 #include "GaudiKernel/AlgTool.h"
 #include "AthenaBaseComps/AthAlgTool.h"
-#include "GaudiKernel/ServiceHandle.h"
+#include "GaudiKernel/ToolHandle.h"
 
-#include "TRT_ConditionsServices/ITRT_CalDbSvc.h"
+#include "TRT_ConditionsServices/ITRT_CalDbTool.h"
 #include "InDetCosmicsEventPhase/IInDetCosmicsEventPhaseTool.h"
+#include "TRT_ConditionsData/AverageT0.h"
+#include "StoreGate/ReadCondHandleKey.h"
 
 class AtlasDetectorID;
 class Identifier;
@@ -45,9 +47,6 @@ namespace InDet
       /** standard Athena-Algorithm method */
       virtual StatusCode finalize  ();
       
-      /** if m_useNewEP = True, set averageT0 != 0 */
-      void beginRun();
-      
       /** finds event phase of a track from the leading edge */
       double findPhase(const Trk::Track *track) const;
       
@@ -59,13 +58,13 @@ namespace InDet
       
     private:
       
-      double m_averageT0; // subtract average T0 in EP calculation (new April 2009)
+
+      SG::ReadCondHandleKey<TRTCond::AverageT0> m_T0ReadKey{this,"T0ReadKey","AverageT0","Average T0 in-key"};      
       
-      ServiceHandle<ITRT_CalDbSvc> m_trtconddbsvc ;//!< TRT Calibration DB tool
+      ToolHandle<ITRT_CalDbTool> m_caldbtool ;//!< TRT Calibration DB tool
       
-      bool m_gett0;
-      bool m_useNewEP;
       double m_globalOffset; 
+      bool m_useNewEP; 
     }; 
 }
 
diff --git a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/InDetFixedWindowTrackTimeTool.h b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/InDetFixedWindowTrackTimeTool.h
index 1f2d1719503cf3eaa5a92f14586fced1e94dca1e..3109807de1a860c833afb882fc0c7f219afceecf 100644
--- a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/InDetFixedWindowTrackTimeTool.h
+++ b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/InDetFixedWindowTrackTimeTool.h
@@ -11,13 +11,13 @@
 
 #include "GaudiKernel/AlgTool.h"
 #include "AthenaBaseComps/AthAlgTool.h"
-#include "GaudiKernel/ServiceHandle.h"
+#include "GaudiKernel/ToolHandle.h"
 #include "GaudiKernel/MsgStream.h"
-
+#include "StoreGate/ReadCondHandleKey.h"
 #include "TrkTrack/Track.h"
 #include "TrkSegment/TrackSegment.h"
-
-#include "TRT_ConditionsServices/ITRT_CalDbSvc.h"
+#include "TRT_ConditionsData/AverageT0.h"
+#include "TRT_ConditionsServices/ITRT_CalDbTool.h"
 #include "InDetCosmicsEventPhase/IInDetCosmicsEventPhaseTool.h"
 
 class AtlasDetectorID;
@@ -45,9 +45,6 @@ namespace InDet
       /** standard Athena-Algorithm method */
       virtual StatusCode finalize  ();
       
-      /** if m_useNewEP = True, set averageT0 != 0 */
-      void beginRun();
-      
       /** finds event phase of a track from the leading edge */
       double findPhase(const Trk::Track *track) const;
       
@@ -59,14 +56,11 @@ namespace InDet
       
     private:
       
-      double m_averageT0; // subtract average T0 in EP calculation (new April 2009)
-      
-      ServiceHandle<ITRT_CalDbSvc> m_trtconddbsvc ;//!< TRT Calibration DB tool
+      SG::ReadCondHandleKey<TRTCond::AverageT0> m_T0ReadKey{this,"T0ReadKey","AverageT0","Average T0 in-key"};            
+      ToolHandle<ITRT_CalDbTool> m_caldbtool ;//!< TRT Calibration DB tool
       
-      bool m_gett0;
-      bool m_useNewEP;
       double m_globalOffset; 
-
+      bool m_useNewEP;
       double m_windowCenter;
       double m_windowSize;
     }; 
diff --git a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/InDetSlidingWindowTrackTimeTool.h b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/InDetSlidingWindowTrackTimeTool.h
index fff96f77a491394d273688719b580d4632aa4dc7..66f87a806e8b28f3f64604a8c65dadf5008d762b 100644
--- a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/InDetSlidingWindowTrackTimeTool.h
+++ b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/InDetSlidingWindowTrackTimeTool.h
@@ -11,12 +11,12 @@
 
 #include "GaudiKernel/AlgTool.h"
 #include "AthenaBaseComps/AthAlgTool.h"
-#include "GaudiKernel/ServiceHandle.h"
+#include "GaudiKernel/ToolHandle.h"
 #include "GaudiKernel/MsgStream.h"
+#include "StoreGate/ReadCondHandleKey.h"
+#include "TRT_ConditionsData/AverageT0.h"
 
-
-
-#include "TRT_ConditionsServices/ITRT_CalDbSvc.h"
+#include "TRT_ConditionsServices/ITRT_CalDbTool.h"
 #include "InDetCosmicsEventPhase/IInDetCosmicsEventPhaseTool.h"
 
 class AtlasDetectorID;
@@ -48,9 +48,6 @@ namespace InDet
       /** standard Athena-Algorithm method */
       virtual StatusCode finalize  ();
       
-      /** if m_useNewEP = True, set averageT0 != 0 */
-      void beginRun();
-      
       /** finds event phase of a track from the leading edge */
       double findPhase(const Trk::Track *track) const;
       
@@ -62,15 +59,12 @@ namespace InDet
       
     private:
       
-      double m_averageT0; // subtract average T0 in EP calculation (new April 2009)
-      
-      ServiceHandle<ITRT_CalDbSvc> m_trtconddbsvc ;//!< TRT Calibration DB tool
       
-      bool m_gett0;
-      bool m_useNewEP;
+      ToolHandle<ITRT_CalDbTool> m_caldbtool ;//!< TRT Calibration DB tool
+      SG::ReadCondHandleKey<TRTCond::AverageT0> m_T0ReadKey{this,"T0ReadKey","AverageT0","Average T0 in-key"};            
       double m_globalOffset; 
-
-      double m_nIterations;
+      bool m_useNewEP;
+      int m_nIterations;
       double m_windowSize;
     }; 
 }
diff --git a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/TRT_TrackTimingTool.h b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/TRT_TrackTimingTool.h
index d32c0b289765eb7f052bb4920b5abe87c4f90b2c..8982daceb71d0998caceb49da275053bbd7dc6d7 100644
--- a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/TRT_TrackTimingTool.h
+++ b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/InDetCosmicsEventPhase/TRT_TrackTimingTool.h
@@ -12,6 +12,7 @@
 #include <vector>
 
 #include "GaudiKernel/ToolHandle.h"
+#include "GaudiKernel/ServiceHandle.h"
 #include "AthenaBaseComps/AthAlgTool.h"
 #include "InDetCosmicsEventPhase/ITRT_TrackTimingTool.h"
 #include "TrkTrack/Track.h"
@@ -72,7 +73,7 @@ class TRT_TrackTimingTool : virtual public ITRT_TrackTimingTool, public AthAlgTo
     ToolHandle<Trk::ITrackFitter>    m_ITrackFitter; // refit the ID track if measurements on track are not available
     ToolHandle<InDet::IInDetCosmicsEventPhaseTool> m_eventPhaseTool; //<! Cosmics Event Phase tool
 
-	ServiceHandle<ITRT_CalDbSvc> m_trtconddbsvc ;//!< TRT Calibration DB tool
+    ServiceHandle<ITRT_CalDbSvc> m_caldbsvc ;//!< TRT Calibration DB tool
 
     bool m_doEtaCorrection;
     bool m_debug;
diff --git a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/InDetCosmicsEventPhase.cxx b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/InDetCosmicsEventPhase.cxx
index 87ffc9393445e893b6f9959c995da02488a5ec89..ef8ba713511fcf661c73d67e6eb54d3410dd548c 100644
--- a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/InDetCosmicsEventPhase.cxx
+++ b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/InDetCosmicsEventPhase.cxx
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+   Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
  */
 
 #include "InDetCosmicsEventPhase/InDetCosmicsEventPhase.h"
@@ -12,7 +12,7 @@
 #include "InDetRIO_OnTrack/TRT_DriftCircleOnTrack.h"
 #include "GaudiKernel/ListItem.h"
 
-#include "TRT_ConditionsServices/ITRT_CalDbSvc.h"
+#include "TRT_ConditionsServices/ITRT_CalDbTool.h"
 #include "TRT_ConditionsData/RtRelation.h"
 #include "TRT_ConditionsData/BasicRtRelation.h"
 #include "TrkToolInterfaces/ITrackSummaryTool.h"
@@ -27,9 +27,9 @@ namespace InDet
 {
   InDetCosmicsEventPhase::InDetCosmicsEventPhase(const std::string& name, ISvcLocator* pSvcLocator) :
     AthAlgorithm(name, pSvcLocator),
-    m_trtconddbsvc("TRT_CalDbSvc", name),
+    m_caldbtool("TRT_CalDbTool", this),
     m_eventPhaseTool() {
-    declareProperty("TRTCalDbSvc", m_trtconddbsvc);
+    declareProperty("TRTCalDbTool", m_caldbtool);
     declareProperty("TrackSummaryTool", m_trackSumTool);
     declareProperty("EventPhaseTool", m_eventPhaseTool);
   }
@@ -37,7 +37,7 @@ namespace InDet
   StatusCode InDetCosmicsEventPhase::initialize() {
     ATH_MSG_INFO("initialize()");
 
-    StatusCode sc = m_trtconddbsvc.retrieve();
+    StatusCode sc = m_caldbtool.retrieve();
     if (sc.isFailure()) {
       ATH_MSG_FATAL("Failed to retrieve TRT Calibration DB Service!");
       return sc;
@@ -52,17 +52,10 @@ namespace InDet
     return StatusCode::SUCCESS;
   }
 
-  StatusCode InDetCosmicsEventPhase::beginRun() {
-    m_event = 0;
-    //m_eventPhaseTool->beginRun();  // To access conditions, move this
-    return StatusCode::SUCCESS;
-  }
 
   StatusCode InDetCosmicsEventPhase::execute() {
-    ++m_event;
-    ATH_MSG_DEBUG("execute() event: " << m_event);
+
     m_phase = 0;
-    if (m_event == 1) m_eventPhaseTool->beginRun(); //to here
 
     const Trk::Track* selected = 0;
     int maxTRT = -1;
@@ -139,10 +132,9 @@ namespace InDet
 
   StatusCode InDetCosmicsEventPhase::storePhase() {
     ATH_MSG_DEBUG("Recording phase...  " << m_phase);
-    SG::WriteHandle<ComTime> writeKey_TRTPhase(m_writeKey_TRTPhase);
-    writeKey_TRTPhase = std::make_unique<ComTime>(m_phase, m_phase); //handle assignment actually does a record
-                                                                     // operation
-    ATH_CHECK(writeKey_TRTPhase.isValid());
+    SG::WriteHandle<ComTime> writeTRTPhase(m_writeKey_TRTPhase);
+    writeTRTPhase = std::make_unique<ComTime>(m_phase, m_phase);
+    ATH_CHECK(writeTRTPhase.isValid());
     return StatusCode::SUCCESS;
   }
 }
diff --git a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/InDetCosmicsEventPhaseTool.cxx b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/InDetCosmicsEventPhaseTool.cxx
index 1988ab071bb5c011eedc484d0882a14a26c6bcb6..6549c398cf32af1803d74320094bb3bacbf4d1bf 100644
--- a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/InDetCosmicsEventPhaseTool.cxx
+++ b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/InDetCosmicsEventPhaseTool.cxx
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+   Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
  */
 
 ///////////////////////////////////////////////////////////////////
@@ -10,7 +10,6 @@
 
 #include "InDetRIO_OnTrack/TRT_DriftCircleOnTrack.h"
 
-#include "TRT_ConditionsServices/ITRT_CalDbSvc.h"
 #include "TRT_ConditionsData/RtRelation.h"
 #include "TRT_ConditionsData/BasicRtRelation.h"
 
@@ -18,7 +17,7 @@
 #include "TrkTrack/Track.h"
 #include "TrkSegment/TrackSegment.h"
 
-#include <limits>
+#include "StoreGate/ReadCondHandle.h"
 #include <cmath>
 //================ Constructor =================================================
 
@@ -26,11 +25,9 @@ InDet::InDetCosmicsEventPhaseTool::InDetCosmicsEventPhaseTool(std::string const&
                                                               , std::string const& n
                                                               , IInterface const* p
                                                               ) : AthAlgTool(t, n, p)
-  , m_averageT0(0.)
-  , m_trtconddbsvc("TRT_CalDbSvc", n) {
+  , m_caldbtool("TRT_CalDbTool", this) {
   declareInterface<IInDetCosmicsEventPhaseTool>(this);
-  declareProperty("TRTCalDbSvc", m_trtconddbsvc);
-  declareProperty("UseTRTCalibration", m_gett0 = true);
+  declareProperty("TRTCalDbTool", m_caldbtool);
   declareProperty("UseNewEP", m_useNewEP = true);
   declareProperty("GlobalOffset", m_globalOffset = 10.);
 }
@@ -44,7 +41,11 @@ InDet::InDetCosmicsEventPhaseTool::~InDetCosmicsEventPhaseTool()
 //================ Initialisation =================================================
 
 StatusCode InDet::InDetCosmicsEventPhaseTool::initialize() {
-  ATH_CHECK( m_trtconddbsvc.retrieve());
+
+  ATH_CHECK( m_caldbtool.retrieve());
+  // Read key
+  ATH_CHECK( m_T0ReadKey.initialize() );
+
   return StatusCode::SUCCESS;
 }
 
@@ -56,72 +57,19 @@ StatusCode InDet::InDetCosmicsEventPhaseTool::finalize() {
 
 //============================================================================================
 
-void InDet::InDetCosmicsEventPhaseTool::beginRun() {
-  m_averageT0 = 0.;
+double InDet::InDetCosmicsEventPhaseTool::findPhase(Trk::Track const* track) const {
+  ATH_MSG_DEBUG("Finding phase...");
 
+  double aT0=0.;
   if (!m_useNewEP) {
-    ATH_MSG_INFO("InDetCosmicsEventPhaseTool::beginRun, averageT0 = 0 (m_useNewEP=false) ");
-    return;
-  }
-  TRT_ID const* TRTHelper;
-  if (detStore()->retrieve(TRTHelper, "TRT_ID").isFailure()) {
-    ATH_MSG_FATAL("Could not get TRT ID helper");
-    return;
-  }
-  int countAverageT0 = 0; // should be equal to 32*2*1642  105088
-  double rtShift = 0.; // shift from 0 of the RT relation
-  for (std::vector<Identifier>::const_iterator it = TRTHelper->straw_layer_begin(); it != TRTHelper->straw_layer_end();
-       it++) {
-    int nStrawsInLayer = TRTHelper->straw_max(*it);
-    for (int i = 0; i <= nStrawsInLayer; i++) {
-      Identifier id = TRTHelper->straw_id(*it, i);
-      if (std::abs(TRTHelper->barrel_ec(id)) != 1)                                               // average only for
-                                                                                                 // barrel straws
-        continue;
-      m_averageT0 += m_trtconddbsvc->getT0(id); // access straw T0 same as elsewhere, countAverageT0++;
-      countAverageT0++;
-      const TRTCond::RtRelation* rtRelation = m_trtconddbsvc->getRtRelation(id);
-      if (!rtRelation) {
-        ATH_MSG_DEBUG("rtRelation missing in InDetCosmicsEventPhase::initialize!");
-        continue;
-      }
-      rtShift += rtRelation->drifttime(0.);
-    }
-  }
-  if (countAverageT0 != 0){
-    m_averageT0 /= (double(countAverageT0));
-  } else {
-    m_averageT0 = std::numeric_limits<double>::infinity();
-  }
-  double averageT0 = m_averageT0;
-  if (countAverageT0 != 0) {
-    rtShift /= (double(countAverageT0));
+    ATH_MSG_INFO(" Set averageT0 = 0 (m_useNewEP=false) ");
   } else {
-    rtShift = std::numeric_limits<double>::infinity();
+    SG::ReadCondHandle<TRTCond::AverageT0> rhl{m_T0ReadKey};
+    const TRTCond::AverageT0* avgT0{*rhl};
+    aT0=avgT0->get();
   }
 
-  m_averageT0 -= 20.; // shift so that the range is about the same as before
-  m_averageT0 += rtShift;
-  //print value for test
-  ATH_MSG_DEBUG("The number of straws seen is: " << countAverageT0
-                                                 << " and the values expected is:  " << 105088);
-  ATH_MSG_DEBUG("The average T0 is: " << averageT0
-                                      << ", average RT(r=0) is " << rtShift
-                                      << " and we are subtracting: " << m_averageT0);
-  ATH_MSG_INFO("InDetCosmicsEventPhaseTool::beginRun Using updated EP calculation (December 2009), subtracting: " << m_averageT0
-                                                                                                                  << " ns (average T0: " << averageT0
-                                                                                                                  << " ns, average RT(r=0): " << rtShift << " ns), GlobalOffset: " << m_globalOffset <<
-  " ns.");
-
-  return;
-}
-
-double InDet::InDetCosmicsEventPhaseTool::findPhase(Trk::Track const* track) const {
-  ATH_MSG_DEBUG("Finding phase...");
-
-  std::vector<float> data{0., 0.1, -0.00087,0.};
-  TRTCond::RtRelation const* rtr = (m_gett0) ? 0
-                                   : new TRTCond::BasicRtRelation(data);
+  TRTCond::RtRelation const* rtr = 0;
   double timeresidualsum = 0;
   size_t ntrthits = 0;
   for (Trk::TrackStateOnSurface const* state : *track->trackStateOnSurfaces()) {
@@ -139,15 +87,15 @@ double InDet::InDetCosmicsEventPhaseTool::findPhase(Trk::Track const* track) con
         ) continue;
     Identifier const& ident = trtcirc->identify();
     double rawdrifttime = rawhit->rawDriftTime();
-    double t0 = (m_gett0) ? m_trtconddbsvc->getT0(ident)
-                : 0;
+    double t0 = m_caldbtool->getT0(ident);
     ATH_MSG_DEBUG("T0 : " << t0);
-    if (m_gett0) rtr = m_trtconddbsvc->getRtRelation(ident);
+    rtr = m_caldbtool->getRtRelation(ident);
     Trk::TrackParameters const* tparp = (state->trackParameters());
     if (!tparp) continue;
     double trkdistance = tparp->parameters()[Trk::driftRadius];
     double trkdrifttime = rtr->drifttime(fabs(trkdistance));
-    double timeresidual = rawdrifttime - t0 + m_averageT0 - trkdrifttime;
+
+    double timeresidual = rawdrifttime - t0 + aT0 - trkdrifttime;
     ATH_MSG_DEBUG("trkdistance=" << trkdistance
                                  << "  trkdrifttime=" << trkdrifttime
                                  << "  timeresidual=" << timeresidual
@@ -158,19 +106,22 @@ double InDet::InDetCosmicsEventPhaseTool::findPhase(Trk::Track const* track) con
       ++ntrthits;
     }
   }
-  if (!m_gett0) delete rtr;
+
   ATH_MSG_DEBUG("timeresidualsum = " << timeresidualsum);
   ATH_MSG_DEBUG("ntrtrhits = " << ntrthits);
-  if (ntrthits > 1) return timeresidualsum / ntrthits + m_globalOffset;
+
+  if (ntrthits > 1) {
+     return timeresidualsum / ntrthits + m_globalOffset;
+  }
   return 0.;
 }
 
 double InDet::InDetCosmicsEventPhaseTool::findPhase(Trk::Segment const* segment) const {
-  std::vector<float> data{0., 0.1, -0.00087, 0.};
-  TRTCond::RtRelation const* rtr = (m_gett0) ? 0
-                                   : new TRTCond::BasicRtRelation(data);
+
   double sum_tr = 0.;
   double sum_goodhits = 0.;
+
+  TRTCond::RtRelation const* rtr = 0;
   int nhits = segment->numberOfMeasurementBases();
   for (int i = 0; i < nhits; ++i) {
     Trk::RIO_OnTrack const* rio = dynamic_cast<Trk::RIO_OnTrack const*>(segment->measurement(i));
@@ -180,7 +131,7 @@ double InDet::InDetCosmicsEventPhaseTool::findPhase(Trk::Segment const* segment)
     if (!rawhit) continue;
     if (!rawhit->lastBinHigh() && !rawhit->isNoise()) {
       Identifier const& ident = trtcirc->identify();
-      if (m_gett0) rtr = m_trtconddbsvc->getRtRelation(ident);
+      rtr = m_caldbtool->getRtRelation(ident);
       if (not rtr) {
         ATH_MSG_WARNING("Rt relation pointer is null!");
         return 0.;
@@ -195,7 +146,7 @@ double InDet::InDetCosmicsEventPhaseTool::findPhase(Trk::Segment const* segment)
       ATH_MSG_VERBOSE("Hit has lastbin high");
     }
   }
-  if (!m_gett0) delete rtr;
+
   if (sum_goodhits > 1) return sum_tr / sum_goodhits + m_globalOffset;
   return 0;
 }
@@ -203,6 +154,16 @@ double InDet::InDetCosmicsEventPhaseTool::findPhase(Trk::Segment const* segment)
 double InDet::InDetCosmicsEventPhaseTool::findPhaseFromTE(Trk::Track const* track) const {
   ATH_MSG_DEBUG("Finding phase...");
 
+  double aT0=0.;
+  if (!m_useNewEP) {
+    ATH_MSG_INFO(" Set averageT0 = 0 (m_useNewEP=false) ");
+  } else {
+    SG::ReadCondHandle<TRTCond::AverageT0> rhl{m_T0ReadKey};
+    const TRTCond::AverageT0* avgT0{*rhl};
+    aT0=avgT0->get();
+  }
+
+
   double timeresidualsum = 0;
   size_t ntrthits = 0;
 
@@ -217,10 +178,10 @@ double InDet::InDetCosmicsEventPhaseTool::findPhaseFromTE(Trk::Track const* trac
     if (!rawhit) continue;
     Identifier const& ident = trtcirc->identify();
     double rawtrailingedge = rawhit->trailingEdge() * 3.125;
-    double t0 = (m_gett0) ? m_trtconddbsvc->getT0(ident)
-                : 0;
+    double t0 = m_caldbtool->getT0(ident);
     ATH_MSG_DEBUG("T0 : " << t0);
-    double timeresidual = rawtrailingedge - t0 + m_averageT0;
+
+    double timeresidual = rawtrailingedge - t0 + aT0;
     ATH_MSG_DEBUG("timeresidual=" << timeresidual);
     if (timeresidual < 2000) {
       timeresidualsum += timeresidual;
diff --git a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/InDetFixedWindowTrackTimeTool.cxx b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/InDetFixedWindowTrackTimeTool.cxx
index 938162cc66ac62f78b5b41faa50649c1718eacd6..09b3d7ce97da016d84d7b2bd5a1614bf6fd05499 100644
--- a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/InDetFixedWindowTrackTimeTool.cxx
+++ b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/InDetFixedWindowTrackTimeTool.cxx
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+   Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
  */
 
 ///////////////////////////////////////////////////////////////////
@@ -10,25 +10,22 @@
 
 #include "InDetRIO_OnTrack/TRT_DriftCircleOnTrack.h"
 
-#include "TRT_ConditionsServices/ITRT_CalDbSvc.h"
 #include "TRT_ConditionsData/RtRelation.h"
 #include "TRT_ConditionsData/BasicRtRelation.h"
 
 #include "InDetIdentifier/TRT_ID.h"
-
+#include "StoreGate/ReadCondHandle.h"
 //================ Constructor =================================================
 
 InDet::InDetFixedWindowTrackTimeTool::InDetFixedWindowTrackTimeTool(std::string const& t
                                                                     , std::string const& n
                                                                     , IInterface const* p
                                                                     ) : AthAlgTool(t, n, p)
-  , m_averageT0(0.)
-  , m_trtconddbsvc("TRT_CalDbSvc", n) {
+  , m_caldbtool("TRT_CalDbTool", this) {
   declareInterface<IInDetCosmicsEventPhaseTool>(this);
-  declareProperty("TRTCalDbSvc", m_trtconddbsvc);
-  declareProperty("UseTRTCalibration", m_gett0 = true);
-  declareProperty("UseNewEP", m_useNewEP = true);
+  declareProperty("TRTCalDbTool", m_caldbtool);
   declareProperty("GlobalOffset", m_globalOffset = 10.);
+  declareProperty("UseNewEP", m_useNewEP = true);
   declareProperty("WindowCenter", m_windowCenter = -8.5);
   declareProperty("WindowSize", m_windowSize = 7.);
 }
@@ -42,7 +39,9 @@ InDet::InDetFixedWindowTrackTimeTool::~InDetFixedWindowTrackTimeTool()
 //================ Initialisation =================================================
 
 StatusCode InDet::InDetFixedWindowTrackTimeTool::initialize() {
-  ATH_CHECK(m_trtconddbsvc.retrieve());
+  ATH_CHECK(m_caldbtool.retrieve());
+  // Read key
+  ATH_CHECK( m_T0ReadKey.initialize() );
 
   return StatusCode::SUCCESS;
 }
@@ -55,77 +54,14 @@ StatusCode InDet::InDetFixedWindowTrackTimeTool::finalize() {
 
 //============================================================================================
 
-void InDet::InDetFixedWindowTrackTimeTool::beginRun() {
-  m_averageT0 = 0.;
-
-  if (!m_useNewEP) {
-    ATH_MSG_INFO("InDetFixedWindowTrackTimeTool::beginRun, averageT0 = 0 (m_useNewEP=false) ");
-    return;
-  }
-
-  TRT_ID const* TRTHelper;
-
-  if (detStore()->retrieve(TRTHelper, "TRT_ID").isFailure()) {
-    ATH_MSG_FATAL("Could not get TRT ID helper");
-    return;
-  }
-
-  int countAverageT0 = 0; // should be equal to 32*2*1642  105088
-  double rtShift = 0.; // shift from 0 of the RT relation
-
-  for (std::vector<Identifier>::const_iterator it = TRTHelper->straw_layer_begin(); it != TRTHelper->straw_layer_end();
-       it++) {
-    int nStrawsInLayer = TRTHelper->straw_max(*it);
-    for (int i = 0; i <= nStrawsInLayer; i++) {
-      Identifier id = TRTHelper->straw_id(*it, i);
-      if (abs(TRTHelper->barrel_ec(id)) != 1)                                                    // average only for
-                                                                                                 // barrel straws
-        continue;
-      m_averageT0 += m_trtconddbsvc->getT0(id); // access straw T0 same as elsewhere, countAverageT0++;
-      countAverageT0++;
-      const TRTCond::RtRelation* rtRelation = m_trtconddbsvc->getRtRelation(id);
-      if (!rtRelation) {
-        ATH_MSG_DEBUG("rtRelation missing in InDetCosmicsEventPhase::initialize!");
-        continue;
-      }
-      rtShift += rtRelation->drifttime(0.);
-    }
-  }
-
-  if (countAverageT0) //CID 13692
-    m_averageT0 /= (double(countAverageT0));
-  double averageT0 = m_averageT0;
-  if (countAverageT0) //CID 13693
-    rtShift /= (double(countAverageT0));
-
-  m_averageT0 -= 20.; // shift so that the range is about the same as before
-  m_averageT0 += rtShift;
-
-  //print value for test
-  ATH_MSG_DEBUG("The number of straws seen is: " << countAverageT0
-                                                 << " and the values expected is:  " << 105088);
-  ATH_MSG_DEBUG("The average T0 is: " << averageT0
-                                      << ", average RT(r=0) is " << rtShift
-                                      << " and we are subtracting: " << m_averageT0);
-  ATH_MSG_INFO("InDetFixedWindowTrackTimoeol::beginRun Using updated EP calculation (December 2009), subtracting: " << m_averageT0
-                                                                                                                    << " ns (average T0: " << averageT0
-                                                                                                                    << " ns, average RT(r=0): " << rtShift << " ns), GlobalOffset: " << m_globalOffset <<
-  " ns.");
-
-  return;
-}
 
 double InDet::InDetFixedWindowTrackTimeTool::findPhase(Trk::Track const* track) const {
   ATH_MSG_DEBUG("Finding phase...");
 
-  std::vector<float> data(4);
-  data.push_back(0.); //0 0.1 -0.00087 0
-  data.push_back(0.1);
-  data.push_back(-0.00087);
-  data.push_back(0.);
+  SG::ReadCondHandle<TRTCond::AverageT0> rhl{m_T0ReadKey};
+  const TRTCond::AverageT0* avgT0{*rhl};
 
-  TRTCond::RtRelation const* rtr = (m_gett0) ? 0
-                                   : new TRTCond::BasicRtRelation(data);
+  TRTCond::RtRelation const* rtr = 0;
 
   double timeresidualsum = 0;
   size_t ntrthits = 0;
@@ -150,18 +86,16 @@ double InDet::InDetFixedWindowTrackTimeTool::findPhase(Trk::Track const* track)
     Identifier const& ident = trtcirc->identify();
     double rawdrifttime = rawhit->rawDriftTime();
 
-    double t0 = (m_gett0) ? m_trtconddbsvc->getT0(ident)
-                : 0;
+    double t0 = m_caldbtool->getT0(ident);
     ATH_MSG_DEBUG("T0 : " << t0);
-
-    if (m_gett0) rtr = m_trtconddbsvc->getRtRelation(ident);
+    rtr = m_caldbtool->getRtRelation(ident);
 
     Trk::TrackParameters const* tparp = state->trackParameters();
     if (!tparp) continue;
 
     double trkdistance = tparp->parameters()[Trk::driftRadius];
     double trkdrifttime = rtr->drifttime(fabs(trkdistance));
-    double timeresidual = rawdrifttime - t0 + m_averageT0 - trkdrifttime;
+    double timeresidual = rawdrifttime - t0 + avgT0->get() - trkdrifttime;
 
     ATH_MSG_DEBUG("trkdistance=" << trkdistance
                                  << "  trkdrifttime=" << trkdrifttime
@@ -174,7 +108,6 @@ double InDet::InDetFixedWindowTrackTimeTool::findPhase(Trk::Track const* track)
       ++ntrthits;
     }
   }
-  if (!m_gett0) delete rtr;
 
   ATH_MSG_DEBUG("timeresidualsum = " << timeresidualsum);
   ATH_MSG_DEBUG("ntrtrhits = " << ntrthits);
@@ -185,14 +118,12 @@ double InDet::InDetFixedWindowTrackTimeTool::findPhase(Trk::Track const* track)
 }
 
 double InDet::InDetFixedWindowTrackTimeTool::findPhase(Trk::Segment const* segment) const {
-  std::vector<float> data{0., 0.1, -0.00087,0.};
-  
-  TRTCond::RtRelation const* rtr = (m_gett0) ? 0
-                                   : new TRTCond::BasicRtRelation(data);
 
   double sum_tr = 0.;
   double sum_goodhits = 0.;
 
+  TRTCond::RtRelation const* rtr = 0;
+
   int nhits = segment->numberOfMeasurementBases();
   for (int i = 0; i < nhits; ++i) {
     Trk::RIO_OnTrack const* rio = dynamic_cast<Trk::RIO_OnTrack const*>(segment->measurement(i));
@@ -205,8 +136,8 @@ double InDet::InDetFixedWindowTrackTimeTool::findPhase(Trk::Segment const* segme
 
     if (!rawhit->lastBinHigh() && !rawhit->isNoise()) {
       Identifier const& ident = trtcirc->identify();
-
-      if (m_gett0) rtr = m_trtconddbsvc->getRtRelation(ident);
+      rtr = m_caldbtool->getRtRelation(ident);
+  
       if (not rtr) {
         ATH_MSG_WARNING("Rt relation pointer is null!");
         return 0.;
@@ -225,8 +156,6 @@ double InDet::InDetFixedWindowTrackTimeTool::findPhase(Trk::Segment const* segme
     }
   }
 
-  if (!m_gett0) delete rtr;
-
 
   if (sum_goodhits > 1) return sum_tr / sum_goodhits + m_globalOffset;
 
@@ -236,6 +165,9 @@ double InDet::InDetFixedWindowTrackTimeTool::findPhase(Trk::Segment const* segme
 double InDet::InDetFixedWindowTrackTimeTool::findPhaseFromTE(Trk::Track const* track) const {
   ATH_MSG_DEBUG("Finding phase...");
 
+  SG::ReadCondHandle<TRTCond::AverageT0> rhl{m_T0ReadKey};
+  const TRTCond::AverageT0* avgT0{*rhl};
+
   double timeresidualsum = 0;
   size_t ntrthits = 0;
 
@@ -254,12 +186,11 @@ double InDet::InDetFixedWindowTrackTimeTool::findPhaseFromTE(Trk::Track const* t
     Identifier const& ident = trtcirc->identify();
     double rawtrailingedge = rawhit->trailingEdge() * 3.125;
 
-    double t0 = (m_gett0) ? m_trtconddbsvc->getT0(ident)
-                : 0;
+    double t0 = m_caldbtool->getT0(ident);
 
     ATH_MSG_DEBUG("T0 : " << t0);
 
-    double timeresidual = rawtrailingedge - t0 + m_averageT0;
+    double timeresidual = rawtrailingedge - t0 + avgT0->get();
 
     ATH_MSG_DEBUG("timeresidual=" << timeresidual);
 
diff --git a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/InDetSlidingWindowTrackTimeTool.cxx b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/InDetSlidingWindowTrackTimeTool.cxx
index 5c652311195c11322b76c5a70f6dca5975d88c0d..cd0fd35f546e62f69b91d0a1dc93ce31c786e326 100644
--- a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/InDetSlidingWindowTrackTimeTool.cxx
+++ b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/InDetSlidingWindowTrackTimeTool.cxx
@@ -10,14 +10,14 @@
 
 #include "InDetRIO_OnTrack/TRT_DriftCircleOnTrack.h"
 
-#include "TRT_ConditionsServices/ITRT_CalDbSvc.h"
 #include "TRT_ConditionsData/RtRelation.h"
 #include "TRT_ConditionsData/BasicRtRelation.h"
 
 #include "InDetIdentifier/TRT_ID.h"
 #include "TrkTrack/Track.h"
 #include "TrkSegment/TrackSegment.h"
-#include <limits>
+
+#include "StoreGate/ReadCondHandle.h"
 #include <cmath>
 
 //================ Constructor =================================================
@@ -26,13 +26,11 @@ InDet::InDetSlidingWindowTrackTimeTool::InDetSlidingWindowTrackTimeTool(std::str
                                                                         , std::string const& n
                                                                         , IInterface const* p
                                                                         ) : AthAlgTool(t, n, p)
-  , m_averageT0(0.)
-  , m_trtconddbsvc("TRT_CalDbSvc", n) {
+  , m_caldbtool("TRT_CalDbTool", this) {
   declareInterface<IInDetCosmicsEventPhaseTool>(this);
-  declareProperty("TRTCalDbSvc", m_trtconddbsvc);
-  declareProperty("UseTRTCalibration", m_gett0 = true);
-  declareProperty("UseNewEP", m_useNewEP = true);
+  declareProperty("TRTCalDbTool", m_caldbtool);
   declareProperty("GlobalOffset", m_globalOffset = 10.);
+  declareProperty("UseNewEP", m_useNewEP = true);
   declareProperty("NumberIterations", m_nIterations = 5);
   declareProperty("WindowSize", m_windowSize = 7.);
 }
@@ -46,7 +44,10 @@ InDet::InDetSlidingWindowTrackTimeTool::~InDetSlidingWindowTrackTimeTool()
 //================ Initialisation =================================================
 
 StatusCode InDet::InDetSlidingWindowTrackTimeTool::initialize() {
-  ATH_CHECK( m_trtconddbsvc.retrieve());
+  ATH_CHECK( m_caldbtool.retrieve());
+  // Read key
+  ATH_CHECK( m_T0ReadKey.initialize() );
+
   return StatusCode::SUCCESS;
 }
 
@@ -57,69 +58,22 @@ StatusCode InDet::InDetSlidingWindowTrackTimeTool::finalize() {
   return StatusCode::SUCCESS;
 }
 
-//============================================================================================
 
-void InDet::InDetSlidingWindowTrackTimeTool::beginRun() {
-  m_averageT0 = 0.;
+double InDet::InDetSlidingWindowTrackTimeTool::findPhase(Trk::Track const* track) const {
+  ATH_MSG_DEBUG("Finding phase...");
+  
+  double aT0=0.;
   if (!m_useNewEP) {
-    ATH_MSG_INFO("InDetSlidingWindowTrackTimeTool::beginRun, averageT0 = 0 (m_useNewEP=false) ");
-    return;
-  }
-  TRT_ID const* TRTHelper;
-  if (detStore()->retrieve(TRTHelper, "TRT_ID").isFailure()) {
-    ATH_MSG_FATAL("Could not get TRT ID helper");
-    return;
-  }
-  int countAverageT0 = 0; // should be equal to 32*2*1642  105088
-  double rtShift = 0.; // shift from 0 of the RT relation
-  for (std::vector<Identifier>::const_iterator it = TRTHelper->straw_layer_begin(); it != TRTHelper->straw_layer_end();
-       it++) {
-    int nStrawsInLayer = TRTHelper->straw_max(*it);
-    for (int i = 0; i <= nStrawsInLayer; i++) {
-      Identifier id = TRTHelper->straw_id(*it, i);
-      if (std::abs(TRTHelper->barrel_ec(id)) != 1)   // average only for barrel straws
-        continue;
-      m_averageT0 += m_trtconddbsvc->getT0(id); // access straw T0 same as elsewhere, countAverageT0++;
-      countAverageT0++;
-      const TRTCond::RtRelation* rtRelation = m_trtconddbsvc->getRtRelation(id);
-      if (!rtRelation) {
-        ATH_MSG_DEBUG("rtRelation missing in InDetCosmicsEventPhase::initialize!");
-        continue;
-      }
-      rtShift += rtRelation->drifttime(0.);
-    }
-  }
-  if (countAverageT0 == 0) {
-    m_averageT0 = std::numeric_limits<double>::infinity();
-    rtShift = std::numeric_limits<double>::infinity();
+    ATH_MSG_INFO(" Set averageT0 = 0 (m_useNewEP=false) ");
   } else {
-    m_averageT0 /= (double(countAverageT0));
-    rtShift /= (double(countAverageT0));
+    SG::ReadCondHandle<TRTCond::AverageT0> rhl{m_T0ReadKey};
+    const TRTCond::AverageT0* avgT0{*rhl};
+    aT0=avgT0->get();
   }
 
-  double averageT0 = m_averageT0;
-  m_averageT0 -= 20.; // shift so that the range is about the same as before
-  m_averageT0 += rtShift;
-
-  //print value for test
-  ATH_MSG_DEBUG("The number of straws seen is: " << countAverageT0
-                                                 << " and the values expected is:  " << 105088);
-  ATH_MSG_DEBUG("The average T0 is: " << averageT0
-                                      << ", average RT(r=0) is " << rtShift
-                                      << " and we are subtracting: " << m_averageT0);
-  ATH_MSG_INFO("InDetSlidingWindowTrackTimoeol::beginRun Using updated EP calculation (December 2009), subtracting: " << m_averageT0
-                                                                                                                      << " ns (average T0: " << averageT0
-                                                                                                                      << " ns, average RT(r=0): " << rtShift << " ns), GlobalOffset: " << m_globalOffset <<
-  " ns.");
-
-  return;
-}
 
-double InDet::InDetSlidingWindowTrackTimeTool::findPhase(Trk::Track const* track) const {
-  ATH_MSG_DEBUG("Finding phase...");
-  std::vector<float> data{0., 0.1, -0.00087, 0.};
-  TRTCond::RtRelation const* rtr = (m_gett0) ? 0
-                                   : new TRTCond::BasicRtRelation(data);
+  TRTCond::RtRelation const* rtr = 0;
+
   double timeresidualsum = 0;
   size_t ntrthits = 0;
   double windowCenter = 0;
@@ -140,15 +94,16 @@ double InDet::InDetSlidingWindowTrackTimeTool::findPhase(Trk::Track const* track
           ) continue;
       Identifier const& ident = trtcirc->identify();
       double rawdrifttime = rawhit->rawDriftTime();
-      double t0 = (m_gett0) ? m_trtconddbsvc->getT0(ident)
-                  : 0;
+      double t0 = m_caldbtool->getT0(ident);
+
       ATH_MSG_DEBUG("T0 : " << t0);
-      if (m_gett0) rtr = m_trtconddbsvc->getRtRelation(ident);
+      rtr = m_caldbtool->getRtRelation(ident);
+
       Trk::TrackParameters const* tparp = state->trackParameters();
       if (!tparp) continue;
       double trkdistance = tparp->parameters()[Trk::driftRadius];
       double trkdrifttime = rtr->drifttime(fabs(trkdistance));
-      double timeresidual = rawdrifttime - t0 + m_averageT0 - trkdrifttime;
+      double timeresidual = rawdrifttime - t0 + aT0 - trkdrifttime;
       ATH_MSG_DEBUG("trkdistance=" << trkdistance
                                    << "  trkdrifttime=" << trkdrifttime
                                    << "  timeresidual=" << timeresidual
@@ -166,21 +121,24 @@ double InDet::InDetSlidingWindowTrackTimeTool::findPhase(Trk::Track const* track
       windowCenter = timeresidualsum / ntrthits;
     } else break;
   }
-  if (!m_gett0) delete rtr;
+
   ATH_MSG_DEBUG("timeresidualsum = " << timeresidualsum);
   ATH_MSG_DEBUG("ntrtrhits = " << ntrthits);
+
   if (ntrthits > 1)
     return windowCenter + m_globalOffset;
   return 0.;
 }
 
 double InDet::InDetSlidingWindowTrackTimeTool::findPhase(Trk::Segment const* segment) const {
-  std::vector<float> data{0., 0.1, -0.00087, 0.};
-  TRTCond::RtRelation const* rtr = (m_gett0) ? 0
-                                   : new TRTCond::BasicRtRelation(data);
+
   double sum_tr = 0.;
   double sum_goodhits = 0.;
   int nhits = segment->numberOfMeasurementBases();
+
+  std::vector<double> data{0., 0.1, -0.00087,0.};
+  TRTCond::RtRelation const* rtr = 0;
+
   for (int i = 0; i < nhits; ++i) {
     Trk::RIO_OnTrack const* rio = dynamic_cast<Trk::RIO_OnTrack const*>(segment->measurement(i));
     InDet::TRT_DriftCircleOnTrack const* trtcirc = dynamic_cast<InDet::TRT_DriftCircleOnTrack const*>(rio);
@@ -189,7 +147,7 @@ double InDet::InDetSlidingWindowTrackTimeTool::findPhase(Trk::Segment const* seg
     if (!rawhit) continue;
     if (!rawhit->lastBinHigh() && !rawhit->isNoise()) {
       Identifier const& ident = trtcirc->identify();
-      if (m_gett0) rtr = m_trtconddbsvc->getRtRelation(ident);
+      rtr = m_caldbtool->getRtRelation(ident);
       if (not rtr) {
         ATH_MSG_WARNING("Rt relation pointer is null!");
         return 0.;
@@ -204,13 +162,23 @@ double InDet::InDetSlidingWindowTrackTimeTool::findPhase(Trk::Segment const* seg
       ATH_MSG_VERBOSE("Hit has lastbin high");
     }
   }
-  if (!m_gett0) delete rtr;
   if (sum_goodhits > 1) return sum_tr / sum_goodhits + m_globalOffset;
   return 0;
 }
 
 double InDet::InDetSlidingWindowTrackTimeTool::findPhaseFromTE(Trk::Track const* track) const {
+
   ATH_MSG_DEBUG("Finding phase...");
+
+  double aT0=0.;
+  if (!m_useNewEP) {
+    ATH_MSG_INFO(" Set averageT0 = 0 (m_useNewEP=false) ");
+  } else {
+    SG::ReadCondHandle<TRTCond::AverageT0> rhl{m_T0ReadKey};
+    const TRTCond::AverageT0* avgT0{*rhl};
+    aT0=avgT0->get();
+  }
+
   double timeresidualsum = 0;
   size_t ntrthits = 0;
   for (Trk::TrackStateOnSurface const* state : *track->trackStateOnSurfaces()) {
@@ -224,10 +192,9 @@ double InDet::InDetSlidingWindowTrackTimeTool::findPhaseFromTE(Trk::Track const*
     if (!rawhit) continue;
     Identifier const& ident = trtcirc->identify();
     double rawtrailingedge = rawhit->trailingEdge() * 3.125;
-    double t0 = (m_gett0) ? m_trtconddbsvc->getT0(ident)
-                : 0;
+    double t0 = m_caldbtool->getT0(ident);
     ATH_MSG_DEBUG("T0 : " << t0);
-    double timeresidual = rawtrailingedge - t0 + m_averageT0;
+    double timeresidual = rawtrailingedge - t0 + aT0;
     ATH_MSG_DEBUG("timeresidual=" << timeresidual);
     if (timeresidual < 2000) {
       timeresidualsum += timeresidual;
diff --git a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/TRT_TrackTimingTool.cxx b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/TRT_TrackTimingTool.cxx
index 6109efef1bf5039098ed01e3f67bc8d3487b050c..0d52cc4e7036987af2117500092092b5a8614024 100644
--- a/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/TRT_TrackTimingTool.cxx
+++ b/InnerDetector/InDetCosmics/InDetCosmicsEventPhase/src/TRT_TrackTimingTool.cxx
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+   Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
  */
 
 ///////////////////////////////////////////////////////////////////
@@ -10,7 +10,7 @@
 
 #include "InDetIdentifier/TRT_ID.h"
 
-#include "TRT_ConditionsServices/ITRT_CalDbSvc.h"
+
 #include "TRT_ConditionsData/RtRelation.h"
 #include "TRT_ConditionsData/BasicRtRelation.h"
 
@@ -22,7 +22,7 @@ using CLHEP::GeV;
 InDet::TRT_TrackTimingTool::TRT_TrackTimingTool(const std::string& t,
                                                 const std::string& n,
                                                 const IInterface* p) :
-  AthAlgTool(t, n, p), m_ITrackFitter("Trk::GlobalChi2Fitter/InDetTrackFitter"), m_eventPhaseTool(), m_trtconddbsvc(
+  AthAlgTool(t, n, p), m_ITrackFitter("Trk::GlobalChi2Fitter/InDetTrackFitter"), m_eventPhaseTool(), m_caldbsvc(
     "TRT_CalDbSvc", n), m_doEtaCorrection(true), m_debug(false) {
   declareInterface<ITRT_TrackTimingTool>(this);
   declareInterface<Trk::ITrackTimingTool>(this);
@@ -30,7 +30,7 @@ InDet::TRT_TrackTimingTool::TRT_TrackTimingTool(const std::string& t,
   // retrieve properties from job options
   declareProperty("FitterTool", m_ITrackFitter);
   declareProperty("EventPhaseTool", m_eventPhaseTool);
-  declareProperty("TRTCalDbSvc", m_trtconddbsvc);
+  declareProperty("TRTCalDbSvc", m_caldbsvc);
   declareProperty("DoEtaCorrection", m_doEtaCorrection);
   declareProperty("DebugMissingMeasurement", m_debug);
   declareProperty("EventInfoKey", m_EventInfoKey = "ByteStreamEventInfo");
@@ -195,7 +195,7 @@ float InDet::TRT_TrackTimingTool::getTrackTimeFromDriftRadius(const Trk::Track*
     float trackR = tparp->parameters()[Trk::driftRadius];
 
     Identifier id = trtcirc->identify();
-    const TRTCond::RtRelation* rtRelation = m_trtconddbsvc->getRtRelation(id);
+    const TRTCond::RtRelation* rtRelation = m_caldbsvc->getRtRelation(id);
     if (not rtRelation) {
       ATH_MSG_WARNING("Rt relation pointer is null!");
       continue;
diff --git a/InnerDetector/InDetExample/InDetRecExample/share/ConfiguredInDetPreProcessingTRT.py b/InnerDetector/InDetExample/InDetRecExample/share/ConfiguredInDetPreProcessingTRT.py
index 02c64f0765f882e670af80e78637fddc955d9b91..a5e2ce74bf4f592a463a25ca10c4a3da3b3e0fa0 100644
--- a/InnerDetector/InDetExample/InDetRecExample/share/ConfiguredInDetPreProcessingTRT.py
+++ b/InnerDetector/InDetExample/InDetRecExample/share/ConfiguredInDetPreProcessingTRT.py
@@ -169,9 +169,6 @@ class ConfiguredInDetPreProcessingTRT:
          if jobproperties.Beam.beamType()=="cosmics": 
             InDetTRT_DriftCircleTool.SimpleOutOfTimePileupSupression=False 
 
-# --- overwrite for phase usage
-         if usePhase:
-            InDetTRT_DriftCircleTool.ComTimeName = "TRT_Phase"
 
          ToolSvc += InDetTRT_DriftCircleTool
          if (InDetFlags.doPrintConfigurables()):
diff --git a/InnerDetector/InDetExample/InDetRecExample/share/ConfiguredInDetTRTPhase.py b/InnerDetector/InDetExample/InDetRecExample/share/ConfiguredInDetTRTPhase.py
index 3bbc1ca0598682eb82a4337727698c264047dce0..5aeff241e7f445a040b6d73ee56ac7d1ad06616b 100644
--- a/InnerDetector/InDetExample/InDetRecExample/share/ConfiguredInDetTRTPhase.py
+++ b/InnerDetector/InDetExample/InDetRecExample/share/ConfiguredInDetTRTPhase.py
@@ -38,15 +38,20 @@ class ConfiguredInDetTRTPhase:
             cutWindowCenter  = -8.5
             numberIterations = 5
             cutWindowSize    = 7
+            # CalDb tool
+            from TRT_ConditionsServices.TRT_ConditionsServicesConf import TRT_CalDbTool
+            InDetTRTCalDbTool = TRT_CalDbTool(name = "TRT_CalDbTool",
+                                      isGEANT4 = DetFlags.simulate.any_on())
+
                                                     
             #    
             # --- load tool
             #
             from InDetCosmicsEventPhase.InDetCosmicsEventPhaseConf import InDet__InDetCosmicsEventPhaseTool
             InDetCosmicsEventPhaseTool = InDet__InDetCosmicsEventPhaseTool(name              = "InDetCosmicsEventPhaseTool",
-                                                                           UseTRTCalibration = True,
                                                                            UseNewEP          = useNewEP,
-                                                                           GlobalOffset      = globalOffset
+                                                                           GlobalOffset      = globalOffset,
+                                                                           TRTCalDbTool      = InDetTRTCalDbTool
                                                                            )
                                                                            
             ToolSvc += InDetCosmicsEventPhaseTool
@@ -55,11 +60,11 @@ class ConfiguredInDetTRTPhase:
             
             from InDetCosmicsEventPhase.InDetCosmicsEventPhaseConf import InDet__InDetFixedWindowTrackTimeTool
             InDetFixedWindowTrackTimeTool = InDet__InDetFixedWindowTrackTimeTool(name              = "InDetFixedWindowTrackTimeTool",
-                                                                                 UseTRTCalibration = True,
                                                                                  UseNewEP          = useNewEP,
                                                                                  GlobalOffset      = globalOffset,
                                                                                  WindowCenter      = cutWindowCenter,
-                                                                                 WindowSize        = cutWindowSize
+                                                                                 WindowSize        = cutWindowSize,
+                                                                                 TRTCalDbTool      = InDetTRTCalDbTool
                                                                                  )
                                                                            
             ToolSvc += InDetFixedWindowTrackTimeTool
@@ -69,11 +74,11 @@ class ConfiguredInDetTRTPhase:
             
             from InDetCosmicsEventPhase.InDetCosmicsEventPhaseConf import InDet__InDetSlidingWindowTrackTimeTool
             InDetSlidingWindowTrackTimeTool = InDet__InDetSlidingWindowTrackTimeTool(name              = "InDetSlidingWindowTrackTimeTool",
-                                                                                     UseTRTCalibration = True,
                                                                                      UseNewEP          = useNewEP,
                                                                                      GlobalOffset      = globalOffset,
                                                                                      NumberIterations  = numberIterations,
-                                                                                     WindowSize        = cutWindowSize
+                                                                                     WindowSize        = cutWindowSize,
+                                                                                     TRTCalDbTool      = InDetTRTCalDbTool
                                                                                      )
                                                                            
             ToolSvc += InDetSlidingWindowTrackTimeTool
@@ -87,6 +92,7 @@ class ConfiguredInDetTRTPhase:
             InDetCosmicsEventPhase = InDet__InDetCosmicsEventPhase(name              = "InDetCosmicsEventPhase",
                                                                    InputTracksNames  = InputTrackCollections,
                                                                    TrackSummaryTool  = InDetTrackSummaryTool,
+                                                                   TRTCalDbTool      = InDetTRTCalDbTool,
                                                                    #EventPhaseTool    = InDetCosmicsEventPhaseTool)
                                                                    #EventPhaseTool    = InDetFixedWindowTrackTimeTool)
                                                                    EventPhaseTool    = InDetSlidingWindowTrackTimeTool)
diff --git a/InnerDetector/InDetExample/InDetRecExample/share/InDetRecConditionsAccess.py b/InnerDetector/InDetExample/InDetRecExample/share/InDetRecConditionsAccess.py
index e8b217407652d3ea2a1c6402d5d6b364e85513db..8f1aae956dbd24d910ddb08eb03d8f40a415b991 100644
--- a/InnerDetector/InDetExample/InDetRecExample/share/InDetRecConditionsAccess.py
+++ b/InnerDetector/InDetExample/InDetRecExample/share/InDetRecConditionsAccess.py
@@ -395,6 +395,11 @@ if DetFlags.haveRIO.TRT_on():
     from TRT_ConditionsServices.TRT_ConditionsServicesConf import TRT_StrawStatusSummaryTool
     InDetTRTStrawStatusSummaryTool = TRT_StrawStatusSummaryTool(name = "TRT_StrawStatusSummaryTool",
                                                             isGEANT4 = useOldStyle)
+    # CalDb tool
+    from TRT_ConditionsServices.TRT_ConditionsServicesConf import TRT_CalDbTool
+    InDetTRTCalDbTool = TRT_CalDbTool(name = "TRT_CalDbTool",
+                                      isGEANT4 = useOldStyle)
+
     # Alive straws algorithm
     from TRT_ConditionsAlgs.TRT_ConditionsAlgsConf import TRTStrawCondAlg
     TRTStrawCondAlg = TRTStrawCondAlg(name = "TRTStrawCondAlg",
@@ -413,6 +418,13 @@ if DetFlags.haveRIO.TRT_on():
     from TRT_ConditionsAlgs.TRT_ConditionsAlgsConf import TRTToTCondAlg
     TRTToTCondAlg = TRTToTCondAlg(name = "TRTToTCondAlg")
 
+    if InDetFlags.doCosmics() :
+        # Average T0 CondAlg
+        from TRT_ConditionsAlgs.TRT_ConditionsAlgsConf import TRTPhaseCondAlg
+        TRTPhaseCondAlg = TRTPhaseCondAlg(name = "TRTPhaseCondAlg",
+                                          TRTCalDbTool = InDetTRTCalDbTool)
+        condSeq += TRTPhaseCondAlg
+
     # Condition algorithms for straw conditions
     if not hasattr(condSeq, "TRTStrawCondAlg"):
         condSeq += TRTStrawCondAlg
diff --git a/InnerDetector/InDetRecTools/TRT_DriftCircleTool/TRT_DriftCircleTool/TRT_DriftCircleToolCosmics.h b/InnerDetector/InDetRecTools/TRT_DriftCircleTool/TRT_DriftCircleTool/TRT_DriftCircleToolCosmics.h
index 5065ff068f23dc3efe858c6c6e0e688abd1ebede..e0afd13d4de03ec4a7df9e1b0f17c00d6511ea3f 100755
--- a/InnerDetector/InDetRecTools/TRT_DriftCircleTool/TRT_DriftCircleTool/TRT_DriftCircleToolCosmics.h
+++ b/InnerDetector/InDetRecTools/TRT_DriftCircleTool/TRT_DriftCircleTool/TRT_DriftCircleToolCosmics.h
@@ -23,7 +23,6 @@
 #include "GaudiKernel/ToolHandle.h"
 #include "GaudiKernel/ServiceHandle.h"
 #include "TRT_ConditionsServices/ITRT_StrawStatusSummaryTool.h"
-
 #include "CommissionEvent/ComTime.h"
 #include "StoreGate/ReadHandleKey.h"
 
@@ -61,11 +60,9 @@ public:
   virtual StatusCode finalize  ();
   /** make the conversion from RDOs to DriftCircles */
   virtual InDet::TRT_DriftCircleCollection*  
-  convert(int,const InDetRawDataCollection<TRT_RDORawData>*, const bool  m_CTBBadChannels );  
-  /** test validity gate for corrected drift times */
+  convert(int,const InDetRawDataCollection<TRT_RDORawData>*, const bool  m_CTBBadChannels ); 
   virtual bool passValidityGate(unsigned int word, float lowGate, float highGate, float t0) const;
 
-
   ///////////////////////////////////////////////////////////////////
   // Private methods:
   ///////////////////////////////////////////////////////////////////
@@ -75,20 +72,18 @@ public:
   ///////////////////////////////////////////////////////////////////
   // Private data:
   ///////////////////////////////////////////////////////////////////
-  SG::ReadHandleKey<ComTime> m_comTimeName {this,"ComTimeName","ComTime","RHK to retrieve ComTime"}; //!< RHK for ComTime
+  SG::ReadHandleKey<ComTime> m_evtPhaseKey {this,"TRT_Phase","TRT_Phase","RHK to retrieve TRT Phase"};
+
 
   ToolHandle< ITRT_DriftFunctionTool > m_driftFunctionTool;  //!< DriftFunctionTool
-//  ServiceHandle< IInDetConditionsSvc> m_ConditionsSummary; //!< The ConditionsSummaryTool
   ToolHandle<ITRT_StrawStatusSummaryTool> m_ConditionsSummary; //!< The ConditionsSummaryTool
 
   bool                                 m_useConditionsStatus;     //!< SHall the ConditionsSummaryTool be used?
   bool                                 m_useConditionsHTStatus;     //!< Shall the ConditionsSummaryTool be used for HT to find argon straws? 
   std::string                          m_trt_mgr_location ;  //!< Manager name
-  //std::string                          m_comTimeName      ;  //!< Phase handler name
   const InDetDD::TRT_DetectorManager * m_trt_mgr          ;  //!< Manager handle
   const TRT_ID                       * m_trtid            ;  //!< TRT id helper handle
-  unsigned int                         m_coll_pll         ;  //!< phase offset (in clock bins)
-  double                               m_global_offset    ;  //!< Global offset to TRT Phase to make TRT Calibration happy ...
+  float                                m_global_offset    ;  //!< Global offset to TRT Phase to make TRT Calibration happy ...
   bool				       m_useToTCorrection;  //!< Shall the Time over Threshold correction be used?
   bool                                 m_useHTCorrection;  //!< Shall the High Threshold correction be used?
 
diff --git a/InnerDetector/InDetRecTools/TRT_DriftCircleTool/src/TRT_DriftCircleTool.cxx b/InnerDetector/InDetRecTools/TRT_DriftCircleTool/src/TRT_DriftCircleTool.cxx
index 7693f1a997da3587c9b350827343edf4f41537fc..986a6cf5512cea882d5e39c05f689c7ba2bab21b 100755
--- a/InnerDetector/InDetRecTools/TRT_DriftCircleTool/src/TRT_DriftCircleTool.cxx
+++ b/InnerDetector/InDetRecTools/TRT_DriftCircleTool/src/TRT_DriftCircleTool.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
 */
 
 ///////////////////////////////////////////////////////////////////
diff --git a/InnerDetector/InDetRecTools/TRT_DriftCircleTool/src/TRT_DriftCircleToolCosmics.cxx b/InnerDetector/InDetRecTools/TRT_DriftCircleTool/src/TRT_DriftCircleToolCosmics.cxx
index cc45fa915a473b2bc436bdc10bee04f168939324..13462f76942bf61ce7a6f2bbe7dfa61dca1ca7e0 100755
--- a/InnerDetector/InDetRecTools/TRT_DriftCircleTool/src/TRT_DriftCircleToolCosmics.cxx
+++ b/InnerDetector/InDetRecTools/TRT_DriftCircleTool/src/TRT_DriftCircleToolCosmics.cxx
@@ -24,9 +24,13 @@
 #include "TRT_DriftFunctionTool/ITRT_DriftFunctionTool.h"
 #include "InDetReadoutGeometry/TRT_DetectorManager.h"
 #include "InDetIdentifier/TRT_ID.h"
-#include "InDetConditionsSummaryService/IInDetConditionsSvc.h"
+#include "InDetConditionsSummaryService/IInDetConditionsTool.h"
 
-#include "CommissionEvent/ComTime.h"
+#include "GeoPrimitives/GeoPrimitives.h"
+#include "EventPrimitives/EventPrimitives.h"
+#include "xAODEventInfo/EventInfo.h"
+
+#include "StoreGate/ReadHandle.h"
 
 #include "GeoPrimitives/GeoPrimitives.h"
 #include "EventPrimitives/EventPrimitives.h"
@@ -46,7 +50,6 @@ InDet::TRT_DriftCircleToolCosmics::TRT_DriftCircleToolCosmics(const std::string&
   m_trt_mgr_location("TRT"),
   m_trt_mgr(0),
   m_trtid(0),
-  m_coll_pll(0),
   m_global_offset(0),
   m_useToTCorrection(false),
   m_useHTCorrection(false),
@@ -110,6 +113,29 @@ InDet::TRT_DriftCircleToolCosmics::TRT_DriftCircleToolCosmics(const std::string&
 
 InDet::TRT_DriftCircleToolCosmics::~TRT_DriftCircleToolCosmics(){}
 
+///////////////////////////////////////////////////////////////////
+// Test validity gate
+///////////////////////////////////////////////////////////////////
+bool InDet::TRT_DriftCircleToolCosmics::passValidityGate(unsigned int word, float lowGate, float highGate, float t0) const
+{
+  bool foundInterval = false;
+  unsigned  mask = 0x02000000;
+  int i = 0;
+  while ( !foundInterval && (i < 24) ) {
+    if (word & mask) {
+      float thisTime = ((0.5+i)*3.125)-t0;
+      if (thisTime >= lowGate && thisTime <= highGate) foundInterval = true;
+    }
+    mask >>= 1;
+    if (i == 7 || i == 15) 
+      mask >>= 1;
+    i++;
+  }
+  if (foundInterval) return true;
+  return false;
+}
+
+
 ///////////////////////////////////////////////////////////////////
 // Initialisation
 ///////////////////////////////////////////////////////////////////
@@ -155,7 +181,7 @@ StatusCode InDet::TRT_DriftCircleToolCosmics::initialize()
   }
 
   // Initialize Read handle key
-  ATH_CHECK(m_comTimeName.initialize());
+  ATH_CHECK(m_evtPhaseKey.initialize());
   return sc;
 }
 
@@ -167,28 +193,6 @@ StatusCode InDet::TRT_DriftCircleToolCosmics::finalize()
 {
    StatusCode sc = AthAlgTool::finalize(); return sc;
 }
-///////////////////////////////////////////////////////////////////
-// Test validity gate
-///////////////////////////////////////////////////////////////////
-bool InDet::TRT_DriftCircleToolCosmics::passValidityGate(unsigned int word, float lowGate, float highGate, float t0) const
-{
-  bool foundInterval = false;
-  unsigned  mask = 0x02000000;
-  int i = 0;
-  while ( !foundInterval && (i < 24) ) {
-    if (word & mask) {
-      float thisTime = ((0.5+i)*3.125)-t0;
-      if (thisTime >= lowGate && thisTime <= highGate) foundInterval = true;
-    }
-    mask >>= 1;
-    if (i == 7 || i == 15) 
-      mask >>= 1;
-    i++;
-  }
-  if (foundInterval) return true;
-  return false;
-}
-
 
 ///////////////////////////////////////////////////////////////////
 // Trk::TRT_DriftCircles collection production
@@ -205,19 +209,18 @@ InDet::TRT_DriftCircleCollection* InDet::TRT_DriftCircleToolCosmics::convert(int
     return rio;
   }
 
-  SG::ReadHandle<ComTime> theComTime(m_comTimeName);
+  SG::ReadHandle<ComTime> theComTime(m_evtPhaseKey);
   
 
   	 
-  double timecor=0.;
+  float timecor=0.;
   if (theComTime.isValid()) {
     timecor = theComTime->getTime() + m_global_offset;
-    ATH_MSG_VERBOSE("Retrieved ComTime object with name "
-		    << m_comTimeName<<" found! Time="<<timecor);
+    ATH_MSG_VERBOSE("Retrieved event phase with name "
+		    << theComTime.key() <<" found! Time="<<timecor);
   }else{
-    ATH_MSG_VERBOSE("ComTime object not found with name "<<m_comTimeName<<"!!!");
+    ATH_MSG_VERBOSE("Event phase not found with name "<<theComTime.key()<<"!!!");
     timecor=m_global_offset; // cannot correct drifttime
-    //return rio;
   }
 
   DataVector<TRT_RDORawData>::const_iterator r,rb=rdo->begin(),re=rdo->end(); 
@@ -230,48 +233,20 @@ InDet::TRT_DriftCircleCollection* InDet::TRT_DriftCircleToolCosmics::convert(int
     rio->setIdentifier(rdo->identify());
     rio->reserve( std::distance(rb, re) );
 
-    //In case of real CTB data: 
-    if(m_driftFunctionTool->isTestBeamData()) {
-      //   perform initial loop to find the trigger pll in first layer
-       for(r=rb; r!=re; ++r) {
-          // skip if rdo is not testbeam or cosmic flavor
-          const TRT_TB04_RawData* tb_rdo = dynamic_cast<const TRT_TB04_RawData*>(*r);
-          if(tb_rdo) {
-            Identifier   id  = tb_rdo->identify();
-            // skip if not first layer
-            if(m_trtid->layer_or_wheel(id)) continue;
-            // store the trigger pll first time encountered
-            m_coll_pll = tb_rdo->getTrigType(); 
-          }
-       }
-    }
-
-    ATH_MSG_VERBOSE( " choose timepll for rdo collection: " << m_coll_pll);
 
     // Loop through all RDOs in the collection
     //
-    for(r=rb; r!=re; ++r) {
 
-      if (!*r) { 
-        ATH_MSG_ERROR(" No RDO pointer! ");
-	continue;
-      }
+    for(r=rb; r!=re; ++r) {
 
       Identifier   id  = (*r)->identify();
-      int          tdcvalue  = (*r)->driftTimeBin();
-      int          newtdcvalue  = tdcvalue;
-      unsigned int timepll = 0;
-
-      // Fix hardware bug in testbeam
-      if(m_driftFunctionTool->isTestBeamData()) {
-        const TRT_TB04_RawData* tb_rdo = dynamic_cast<const TRT_TB04_RawData*>(*r);
-        if(tb_rdo) timepll = tb_rdo->getTrigType();
-        if(m_coll_pll) {
-          newtdcvalue = tdcvalue - timepll/2 + m_coll_pll/2;
-        }
-        // Increase precision of timing
-        newtdcvalue=2*newtdcvalue+(m_coll_pll%2);
-      }
+      int   LTbin      = (*r)->driftTimeBin(); 
+      bool  isOK       =true;
+      double t0         =0.;
+      double rawTime    = m_driftFunctionTool->rawTime(LTbin);
+      double radius     =0.;
+      double driftTime  =0.;
+      unsigned int word    = (*r)->getWord(); 
 
       //
       //Get straw status
@@ -282,40 +257,38 @@ InDet::TRT_DriftCircleCollection* InDet::TRT_DriftCircleToolCosmics::convert(int
             || (m_ConditionsSummary->getStatusPermanent(id))) {
             strawstat = 0;
          }
+         if(!strawstat) continue;
       }
 
+      //correct for phase
+      rawTime-=timecor;
 
-      
-      bool  isOK=true;
-      double t0=0.;
-      double driftTime=0.;
-      double radius=0.;
-      double rawTime   = m_driftFunctionTool->rawTime(newtdcvalue);
+      // ToT and HT Corrections            
 
+      bool isArgonStraw=true;
+      if (m_useToTCorrection) rawTime -= m_driftFunctionTool->driftTimeToTCorrection((*r)->timeOverThreshold(), id, isArgonStraw);
+      if (m_useHTCorrection)  rawTime += m_driftFunctionTool->driftTimeHTCorrection(id, isArgonStraw);           
 
-      //correct for phase
-      rawTime-=timecor;
       //make tube hit if first bin is high and no later LE appears
-      if( newtdcvalue==0 || newtdcvalue==24 ) {
+      if( LTbin==0 || LTbin==24 ) {
         isOK=false;
       } else {
         radius    = m_driftFunctionTool->driftRadius(rawTime,id,t0,isOK);
         driftTime = rawTime-t0;
       }
 
-      unsigned int word = (*r)->getWord(); 
       if(!isOK) word &= 0xF7FFFFFF; 
       else word |= 0x08000000;
 
+
       //std::vector<Identifier>    dvi // we dont need this                                   ;
       ATH_MSG_VERBOSE( " id " << m_trtid->layer_or_wheel(id)
 	  << " " << m_trtid->straw_layer(id)
 	  << " " << m_trtid->straw(id)
-          << " new time bin  " << newtdcvalue << " old bin " << (*r)->driftTimeBin()
+          << " time bin  " << LTbin
           << " timecor " << timecor
-	  << " old timepll " << timepll  << " new time " << rawTime );
+	  << " corrected time " << rawTime );
          
-
       double error=0;
       if(Mode<2) {
 	error = m_driftFunctionTool->errorOfDriftRadius(driftTime,id)         ;
@@ -347,6 +320,7 @@ InDet::TRT_DriftCircleCollection* InDet::TRT_DriftCircleToolCosmics::convert(int
                 // setting the index (via -> size) has to be done just before the push_back! (for safety) 
                 tdc->setHashAndIndex(rio->identifyHash(), rio->size());
                 rio->push_back(tdc);
+
            }else{
              if(strawstat){
                 tdc->setHashAndIndex(rio->identifyHash(), rio->size());
diff --git a/Reconstruction/MuonIdentification/MuonCombinedTimingTools/python/MuonCombinedTimingConfig.py b/Reconstruction/MuonIdentification/MuonCombinedTimingTools/python/MuonCombinedTimingConfig.py
index fdb8e836538951ea9f39823d2dc6720af1bcdb99..8a8bdab474a8d8257819ea5d2935ac7606fe94dd 100644
--- a/Reconstruction/MuonIdentification/MuonCombinedTimingTools/python/MuonCombinedTimingConfig.py
+++ b/Reconstruction/MuonIdentification/MuonCombinedTimingTools/python/MuonCombinedTimingConfig.py
@@ -3,16 +3,22 @@
 ########################## start of MuonTiming Filter Fragment ##################################
 from AthenaCommon.AppMgr import ToolSvc
 from AthenaCommon.AppMgr import ServiceMgr
+from AthenaCommon.DetFlags import DetFlags
 import AthenaCommon.CfgMgr      as CfgMgr
 from MuonCombinedRecExample.MuonCombinedRecFlags import muonCombinedRecFlags
 from AthenaCommon.Include import include
 include( "TrackInCaloTools/TrackInCaloTools_jobOptions.py" )
 #from TrackInCaloTools import TrackInCaloTools_jobOptions
 
+# CalDb tool
+from TRT_ConditionsServices.TRT_ConditionsServicesConf import TRT_CalDbTool
+InDetTRTCalDbTool = TRT_CalDbTool(name = "TRT_CalDbTool",
+                                      isGEANT4 = DetFlags.simulate.any_on() )
+
 # set up TRT tool
 InDetSlidingWindowTrackTimeToolMCP = CfgMgr.InDet__InDetSlidingWindowTrackTimeTool \
    (name              = "InDetSlidingWindowTrackTimeToolMCP",
-    UseTRTCalibration = True,
+    TRTCalDbTool      = InDetTRTCalDbTool,
     UseNewEP          = False,
     GlobalOffset      = 0.,
     NumberIterations  = 5,
@@ -21,7 +27,7 @@ ToolSvc += InDetSlidingWindowTrackTimeToolMCP
 
 TRT_TrackTimingTool = CfgMgr.InDet__TRT_TrackTimingTool \
    (name = "TRT_TrackTimingTool",
-    EventPhaseTool = InDetSlidingWindowTrackTimeToolMCP )
+    EventPhaseTool = InDetSlidingWindowTrackTimeToolMCP)
 ToolSvc += TRT_TrackTimingTool
 #TRT_TrackTimingTool.OutputLevel = 1
 #if muonCombinedRecFlags.printConfigurables():