From a0d8c16f22052b300308198324dba8a73d864545 Mon Sep 17 00:00:00 2001
From: Mingrui Zhao <mingrui.zhao@mail.labz0.org>
Date: Thu, 17 Sep 2020 22:48:13 +0800
Subject: [PATCH] Correct data type and add LCIOTrackPropagators

---
 .../TrackSystemSvc/IMarlinTrack.h             |  33 +++---
 ...gators.h.remove => LCIOTrackPropagators.h} |  17 +--
 .../MarlinTrkDiagnostics.h.remove             |   4 +-
 .../TrackSystemSvc/MarlinTrkUtils.h           |  15 +--
 .../src/DiagnosticsController.cc.remove       |  16 +--
 ...tors.cc.remove => LCIOTrackPropagators.cc} |  90 +++++++--------
 Service/TrackSystemSvc/src/MarlinKalTest.cc   |   6 +-
 Service/TrackSystemSvc/src/MarlinKalTest.h    |   3 +-
 .../TrackSystemSvc/src/MarlinKalTestTrack.cc  | 109 +++++++++---------
 .../TrackSystemSvc/src/MarlinKalTestTrack.h   |  52 ++++-----
 .../src/MarlinTrkDiagnostics.cc.remove        |  12 +-
 Service/TrackSystemSvc/src/MarlinTrkUtils.cc  |  80 ++++++-------
 12 files changed, 214 insertions(+), 223 deletions(-)
 rename Service/TrackSystemSvc/TrackSystemSvc/{LCIOTrackPropagators.h.remove => LCIOTrackPropagators.h} (69%)
 rename Service/TrackSystemSvc/src/{LCIOTrackPropagators.cc.remove => LCIOTrackPropagators.cc} (87%)

diff --git a/Service/TrackSystemSvc/TrackSystemSvc/IMarlinTrack.h b/Service/TrackSystemSvc/TrackSystemSvc/IMarlinTrack.h
index 2abcdd52..901b5a27 100644
--- a/Service/TrackSystemSvc/TrackSystemSvc/IMarlinTrack.h
+++ b/Service/TrackSystemSvc/TrackSystemSvc/IMarlinTrack.h
@@ -6,6 +6,7 @@
 //#include "lcio.h"
 
 #include "edm4hep/TrackerHit.h"
+#include "edm4hep/TrackerHitConst.h"
 #include "edm4hep/TrackState.h"
 
 //#include "gearimpl/Vector3D.h"
@@ -54,7 +55,7 @@ namespace MarlinTrk{
     /** add hit to track - the hits have to be added ordered in time ( i.e. typically outgoing )
      *  this order will define the direction of the energy loss used in the fit
      */
-    virtual int addHit(edm4hep::TrackerHit* hit) = 0 ;
+    virtual int addHit(edm4hep::ConstTrackerHit hit) = 0 ;
     
     /** initialise the fit using the hits added up to this point -
      *  the fit direction has to be specified using IMarlinTrack::backward or IMarlinTrack::forward. 
@@ -81,12 +82,12 @@ namespace MarlinTrk{
     /** update the current fit using the supplied hit, return code via int. Provides the Chi2 increment to the fit from adding the hit via reference. 
      *  the given hit will not be added if chi2increment > maxChi2Increment. 
      */
-    virtual int addAndFit( edm4hep::TrackerHit* hit, double& chi2increment, double maxChi2Increment=DBL_MAX ) = 0 ;
+    virtual int addAndFit( edm4hep::ConstTrackerHit hit, double& chi2increment, double maxChi2Increment=DBL_MAX ) = 0 ;
 
     
     /** obtain the chi2 increment which would result in adding the hit to the fit. This method will not alter the current fit, and the hit will not be stored in the list of hits or outliers
      */
-    virtual int testChi2Increment( edm4hep::TrackerHit* hit, double& chi2increment ) = 0 ;
+    virtual int testChi2Increment( edm4hep::ConstTrackerHit hit, double& chi2increment ) = 0 ;
 
     
     /** smooth all track states 
@@ -96,7 +97,7 @@ namespace MarlinTrk{
     
     /** smooth track states from the last filtered hit back to the measurement site associated with the given hit 
      */
-    virtual int smooth( edm4hep::TrackerHit* hit ) = 0 ;
+    virtual int smooth( edm4hep::ConstTrackerHit hit ) = 0 ;
     
     
     
@@ -109,21 +110,21 @@ namespace MarlinTrk{
     
     /** get track state at measurement associated with the given hit, returning TrackState, chi2 and ndf via reference 
      */
-    virtual int getTrackState( edm4hep::TrackerHit* hit, edm4hep::TrackState& ts, double& chi2, int& ndf ) = 0 ;
+    virtual int getTrackState( edm4hep::ConstTrackerHit hit, edm4hep::TrackState& ts, double& chi2, int& ndf ) = 0 ;
     
     /** get the list of hits included in the fit, together with the chi2 contributions of the hits. 
      *  Pointers to the hits together with their chi2 contribution will be filled into a vector of 
      *  pairs consitining of the pointer as the first part of the pair and the chi2 contribution as
      *  the second.
      */
-    virtual int getHitsInFit( std::vector<std::pair<edm4hep::TrackerHit*, double> >& hits ) = 0 ;
+    virtual int getHitsInFit( std::vector<std::pair<edm4hep::ConstTrackerHit, double> >& hits ) = 0 ;
 
     /** get the list of hits which have been rejected by from the fit due to the a chi2 increment greater than threshold,
      *  Pointers to the hits together with their chi2 contribution will be filled into a vector of 
      *  pairs consitining of the pointer as the first part of the pair and the chi2 contribution as
      *  the second.
      */
-    virtual int getOutliers( std::vector<std::pair<edm4hep::TrackerHit*, double> >& hits ) = 0 ;
+    virtual int getOutliers( std::vector<std::pair<edm4hep::ConstTrackerHit, double> >& hits ) = 0 ;
     
     /** get the current number of degrees of freedom for the fit.
      */
@@ -131,7 +132,7 @@ namespace MarlinTrk{
     
     /** get TrackeHit at which fit became constrained, i.e. ndf >= 0
      */
-    virtual int getTrackerHitAtPositiveNDF( edm4hep::TrackerHit*& trkhit ) = 0 ;
+    virtual int getTrackerHitAtPositiveNDF( edm4hep::ConstTrackerHit& trkhit ) = 0 ;
     
     // PROPAGATORS 
     
@@ -143,7 +144,7 @@ namespace MarlinTrk{
     /** propagate the fit at the measurement site associated with the given hit, to the point of closest approach to the given point,
      *  returning TrackState, chi2 and ndf via reference   
      */
-    virtual int propagate( const edm4hep::Vector3d& point, edm4hep::TrackerHit* hit, edm4hep::TrackState& ts, double& chi2, int& ndf ) = 0 ;
+    virtual int propagate( const edm4hep::Vector3d& point, edm4hep::ConstTrackerHit hit, edm4hep::TrackState& ts, double& chi2, int& ndf ) = 0 ;
     
     
     /** propagate fit to numbered sensitive layer, returning TrackState, chi2, ndf and integer ID of the intersected sensitive detector element via reference 
@@ -153,7 +154,7 @@ namespace MarlinTrk{
     /** propagate the fit at the measurement site associated with the given hit, to numbered sensitive layer, 
      *  returning TrackState, chi2, ndf and integer ID of the intersected sensitive detector element via reference 
      */
-    virtual int propagateToLayer(int layerID, edm4hep::TrackerHit* hit, edm4hep::TrackState& ts, double& chi2, int& ndf, int& detElementID, int mode=modeClosest ) = 0;
+    virtual int propagateToLayer(int layerID, edm4hep::ConstTrackerHit hit, edm4hep::TrackState& ts, double& chi2, int& ndf, int& detElementID, int mode=modeClosest ) = 0;
     
     /** propagate the fit to sensitive detector element, returning TrackState, chi2 and ndf via reference
      */
@@ -162,7 +163,7 @@ namespace MarlinTrk{
     /** propagate the fit at the measurement site associated with the given hit, to sensitive detector element, 
      *  returning TrackState, chi2 and ndf via reference 
      */
-    virtual int propagateToDetElement( int detEementID, edm4hep::TrackerHit* hit, edm4hep::TrackState& ts, double& chi2, int& ndf, int mode=modeClosest ) = 0  ;
+    virtual int propagateToDetElement( int detEementID, edm4hep::ConstTrackerHit hit, edm4hep::TrackState& ts, double& chi2, int& ndf, int mode=modeClosest ) = 0  ;
     
     
     
@@ -175,7 +176,7 @@ namespace MarlinTrk{
     /** extrapolate the fit at the measurement site associated with the given hit, to the point of closest approach to the given point, 
      *  returning TrackState, chi2 and ndf via reference   
      */
-    virtual int extrapolate( const edm4hep::Vector3d& point, edm4hep::TrackerHit* hit, edm4hep::TrackState& ts, double& chi2, int& ndf ) = 0 ;
+    virtual int extrapolate( const edm4hep::Vector3d& point, edm4hep::ConstTrackerHit hit, edm4hep::TrackState& ts, double& chi2, int& ndf ) = 0 ;
     
     /** extrapolate the fit to numbered sensitive layer, returning TrackState, chi2, ndf and integer ID of the intersected sensitive detector element via reference
      */
@@ -184,7 +185,7 @@ namespace MarlinTrk{
     /** extrapolate the fit at the measurement site associated with the given hit, to numbered sensitive layer, 
      *  returning TrackState, chi2, ndf and integer ID of the intersected sensitive detector element via reference 
      */
-    virtual int extrapolateToLayer( int layerID, edm4hep::TrackerHit* hit, edm4hep::TrackState& ts, double& chi2, int& ndf, int& detElementID, int mode=modeClosest ) = 0  ;
+    virtual int extrapolateToLayer( int layerID, edm4hep::ConstTrackerHit hit, edm4hep::TrackState& ts, double& chi2, int& ndf, int& detElementID, int mode=modeClosest ) = 0  ;
     
     /** extrapolate the fit to sensitive detector element, returning TrackState, chi2 and ndf via reference
      */
@@ -193,7 +194,7 @@ namespace MarlinTrk{
     /** extrapolate the fit at the measurement site associated with the given hit, to sensitive detector element, 
      *  returning TrackState, chi2 and ndf via reference 
      */
-    virtual int extrapolateToDetElement( int detEementID, edm4hep::TrackerHit* hit, edm4hep::TrackState& ts, double& chi2, int& ndf, int mode=modeClosest ) = 0  ;
+    virtual int extrapolateToDetElement( int detEementID, edm4hep::ConstTrackerHit hit, edm4hep::TrackState& ts, double& chi2, int& ndf, int mode=modeClosest ) = 0  ;
     
     
     // INTERSECTORS
@@ -206,7 +207,7 @@ namespace MarlinTrk{
     /** extrapolate the fit at the measurement site associated with the given hit, to numbered sensitive layer,
      *  returning intersection point in global coordinates and integer ID of the intersected sensitive detector element via reference 
      */
-    virtual int intersectionWithLayer( int layerID, edm4hep::TrackerHit* hit, edm4hep::Vector3d& point, int& detElementID, int mode=modeClosest ) = 0  ;
+    virtual int intersectionWithLayer( int layerID, edm4hep::ConstTrackerHit hit, edm4hep::Vector3d& point, int& detElementID, int mode=modeClosest ) = 0  ;
     
     
     /** extrapolate the fit to numbered sensitive detector element, returning intersection point in global coordinates via reference 
@@ -216,7 +217,7 @@ namespace MarlinTrk{
     /** extrapolate the fit at the measurement site associated with the given hit, to sensitive detector element,
      *  returning intersection point in global coordinates via reference 
      */
-    virtual int intersectionWithDetElement( int detEementID, edm4hep::TrackerHit* hit, edm4hep::Vector3d& point, int mode=modeClosest ) = 0  ;
+    virtual int intersectionWithDetElement( int detEementID, edm4hep::ConstTrackerHit hit, edm4hep::Vector3d& point, int mode=modeClosest ) = 0  ;
     
     
   protected:
diff --git a/Service/TrackSystemSvc/TrackSystemSvc/LCIOTrackPropagators.h.remove b/Service/TrackSystemSvc/TrackSystemSvc/LCIOTrackPropagators.h
similarity index 69%
rename from Service/TrackSystemSvc/TrackSystemSvc/LCIOTrackPropagators.h.remove
rename to Service/TrackSystemSvc/TrackSystemSvc/LCIOTrackPropagators.h
index a697cbd3..73e5a7c1 100644
--- a/Service/TrackSystemSvc/TrackSystemSvc/LCIOTrackPropagators.h.remove
+++ b/Service/TrackSystemSvc/TrackSystemSvc/LCIOTrackPropagators.h
@@ -1,39 +1,32 @@
 #ifndef LCIOTrackPropagators_h
 #define LCIOTrackPropagators_h
 
-namespace EVENT{
-  class TrackState ;
-}
-
-namespace IMPL{
-  class TrackStateImpl ;
-}
-
+#include <edm4hep/TrackState.h>
 
 namespace LCIOTrackPropagators{
   
   /** Propagate trackstate to a new reference point
    */
-  int PropagateLCIOToNewRef( IMPL::TrackStateImpl& ts, double xref, double yref, double zref) ;
+  int PropagateLCIOToNewRef( edm4hep::TrackState& ts, double xref, double yref, double zref) ;
   
   /** Propagate trackstate to a new reference point taken as its crossing point with a cylinder of infinite length centered at x0,y0, parallel to the z axis. 
    For direction== 0  the closest crossing point will be taken
    For direction== 1  the first crossing traversing in positive s will be taken
    For direction==-1  the first crossing traversing in negative s will be taken
    */
-  int PropagateLCIOToCylinder( IMPL::TrackStateImpl& ts, float r, float x0, float y0, int direction=0, double epsilon=1.0e-8) ;
+  int PropagateLCIOToCylinder( edm4hep::TrackState& ts, float r, float x0, float y0, int direction=0, double epsilon=1.0e-8) ;
   
   
   /** Propagate trackstate to a new reference point taken as its crossing point with an infinite plane located at z, perpendicular to the z axis 
    */
-  int PropagateLCIOToZPlane( IMPL::TrackStateImpl& ts, float z) ;
+  int PropagateLCIOToZPlane( edm4hep::TrackState& ts, float z) ;
   
   /** Propagate trackstate to a new reference point taken as its crossing point with a plane parallel to the z axis, containing points x1,x2 and y1,y2. Tolerance for intersection determined by epsilon.
    For direction== 0  the closest crossing point will be taken
    For direction== 1  the first crossing traversing in positive s will be taken
    For direction==-1  the first crossing traversing in negative s will be taken
    */
-  int PropagateLCIOToPlaneParralelToZ( IMPL::TrackStateImpl& ts, float x1, float y1, float x2, float y2, int direction=0, double epsilon=1.0e-8) ;
+  int PropagateLCIOToPlaneParralelToZ( edm4hep::TrackState& ts, float x1, float y1, float x2, float y2, int direction=0, double epsilon=1.0e-8) ;
   
   
   
diff --git a/Service/TrackSystemSvc/TrackSystemSvc/MarlinTrkDiagnostics.h.remove b/Service/TrackSystemSvc/TrackSystemSvc/MarlinTrkDiagnostics.h.remove
index ffa97ef3..26854ec6 100644
--- a/Service/TrackSystemSvc/TrackSystemSvc/MarlinTrkDiagnostics.h.remove
+++ b/Service/TrackSystemSvc/TrackSystemSvc/MarlinTrkDiagnostics.h.remove
@@ -17,12 +17,12 @@ namespace MarlinTrk{
   // LCIO Extension creating a pointer to the simhit for trackerhits 
   struct MCTruth4HitExtStruct{
     MCTruth4HitExtStruct() : simhit(0) {}
-    EVENT::SimTrackerHit* simhit;
+    EVENT::SimConstTrackerHit simhit;
   } ; 
   struct MCTruth4HitExt : lcio::LCOwnedExtension<MCTruth4HitExt, MCTruth4HitExtStruct> {} ;
   
   // fills a vector of MCParticle pointers with the MCParticles assosiated with the provided tracker hit using MCTruth4HitExtStruct
-  void getMCParticlesForTrackerHit(EVENT::TrackerHit* trkhit, std::vector<EVENT::MCParticle*>& mcps) ;
+  void getMCParticlesForTrackerHit(EVENT::ConstTrackerHit trkhit, std::vector<EVENT::MCParticle*>& mcps) ;
   
 }
 
diff --git a/Service/TrackSystemSvc/TrackSystemSvc/MarlinTrkUtils.h b/Service/TrackSystemSvc/TrackSystemSvc/MarlinTrkUtils.h
index 73826c71..31eabb18 100644
--- a/Service/TrackSystemSvc/TrackSystemSvc/MarlinTrkUtils.h
+++ b/Service/TrackSystemSvc/TrackSystemSvc/MarlinTrkUtils.h
@@ -4,6 +4,7 @@
 #include <vector>
 #include <array>
 #include <cfloat>
+#include <edm4hep/TrackerHitConst.h>
 
 #include <LCIOSTLTypes.h>
 
@@ -38,7 +39,7 @@ namespace MarlinTrk{
    *  it @IP, @First_Hit, @Last_Hit and @CaloFace */
   int createFinalisedLCIOTrack(
       IMarlinTrack* marlinTrk,
-      std::vector<edm4hep::TrackerHit*>& hit_list,
+      std::vector<edm4hep::ConstTrackerHit>& hit_list,
       edm4hep::Track* track,
       bool fit_backwards,
       edm4hep::TrackState* pre_fit,
@@ -50,7 +51,7 @@ namespace MarlinTrk{
    *  it @IP, @First_Hit, @Last_Hit and @CaloFace */
   int createFinalisedLCIOTrack(
       IMarlinTrack* marlinTrk,
-      std::vector<edm4hep::TrackerHit*>& hit_list,
+      std::vector<edm4hep::ConstTrackerHit>& hit_list,
       edm4hep::Track* track,
       bool fit_backwards,
       const std::array<float,15>& initial_cov_for_prefit,
@@ -58,10 +59,10 @@ namespace MarlinTrk{
       double maxChi2Increment=DBL_MAX);
   
   /** Provides the values of a track state from the first, middle and last hits in the hit_list. */
-  int createPrefit( std::vector<edm4hep::TrackerHit*>& hit_list, edm4hep::TrackState* pre_fit, float bfield_z, bool fit_backwards );
+  int createPrefit( std::vector<edm4hep::ConstTrackerHit>& hit_list, edm4hep::TrackState* pre_fit, float bfield_z, bool fit_backwards );
 
   /** Takes a list of hits and uses the IMarlinTrack inferface to fit them using a supplied prefit containing a covariance matrix for the initialisation. */  
-  int createFit( std::vector<edm4hep::TrackerHit*>& hit_list, IMarlinTrack* marlinTrk, edm4hep::TrackState* pre_fit, float bfield_z, bool fit_backwards, double maxChi2Increment=DBL_MAX );
+  int createFit( std::vector<edm4hep::ConstTrackerHit>& hit_list, IMarlinTrack* marlinTrk, edm4hep::TrackState* pre_fit, float bfield_z, bool fit_backwards, double maxChi2Increment=DBL_MAX );
 
   /** Takes a fitted MarlinTrack, TrackImpl to record the fit and the hits which have been added to the fit.
    *  The TrackImpl will have the 4 trackstates added to it @IP, @First_Hit, @Last_Hit and @CaloFace.
@@ -71,15 +72,15 @@ namespace MarlinTrk{
   int finaliseLCIOTrack(
       IMarlinTrack* marlinTrk,
       edm4hep::Track* track,
-      std::vector<edm4hep::TrackerHit*>& hit_list,
+      std::vector<edm4hep::ConstTrackerHit>& hit_list,
       edm4hep::TrackState* atLastHit=0,
       edm4hep::TrackState* atCaloFace=0);
   
   /** Set the subdetector hit numbers for the TrackImpl */
-  void addHitNumbersToTrack(edm4hep::Track* track, std::vector<edm4hep::TrackerHit*>& hit_list, bool hits_in_fit, UTIL::BitField64& cellID_encoder);
+  void addHitNumbersToTrack(edm4hep::Track* track, std::vector<edm4hep::ConstTrackerHit>& hit_list, bool hits_in_fit, UTIL::BitField64& cellID_encoder);
 
   /** Set the subdetector hit numbers for the TrackImpl */
-  void addHitNumbersToTrack(edm4hep::Track* track, std::vector<std::pair<edm4hep::TrackerHit* , double> >& hit_list, bool hits_in_fit, UTIL::BitField64& cellID_encoder);
+  void addHitNumbersToTrack(edm4hep::Track* track, std::vector<std::pair<edm4hep::ConstTrackerHit , double> >& hit_list, bool hits_in_fit, UTIL::BitField64& cellID_encoder);
   
 }
 
diff --git a/Service/TrackSystemSvc/src/DiagnosticsController.cc.remove b/Service/TrackSystemSvc/src/DiagnosticsController.cc.remove
index cbdf6b64..b99e38d6 100644
--- a/Service/TrackSystemSvc/src/DiagnosticsController.cc.remove
+++ b/Service/TrackSystemSvc/src/DiagnosticsController.cc.remove
@@ -419,9 +419,9 @@ namespace MarlinTrk{
     
     if(_skip_track) return;
     
-    EVENT::TrackerHit* trkhit = hit->getLCIOTrackerHit();
+    EVENT::ConstTrackerHit trkhit = hit->getLCIOTrackerHit();
     
-    MarlinTrk::MCTruth4HitExtStruct* ext = trkhit->ext<MarlinTrk::MCTruth4HitExt>();
+    MarlinTrk::MCTruth4HitExtStruct* ext = trkhit.ext<MarlinTrk::MCTruth4HitExt>();
     
     if ( ! ext ) {
       
@@ -435,7 +435,7 @@ namespace MarlinTrk{
       
     }
     
-    EVENT::SimTrackerHit* simhit = trkhit->ext<MarlinTrk::MCTruth4HitExt>()->simhit;
+    EVENT::SimConstTrackerHit simhit = trkhit.ext<MarlinTrk::MCTruth4HitExt>()->simhit;
     
     if ( ! simhit ) {
       
@@ -522,10 +522,10 @@ namespace MarlinTrk{
       }
       
                   
-      _track_record->CellID0[_track_record->nsites] = trkhit->getCellID0() ;
+      _track_record->CellID0[_track_record->nsites] = trkhit.getCellID0() ;
       
       UTIL::BitField64 encoder(lcio::ILDCellID0::encoder_string);
-      encoder.setValue( trkhit->getCellID0() );
+      encoder.setValue( trkhit.getCellID0() );
       
       if (encoder[lcio::ILDCellID0::subdet] == lcio::ILDDetID::VXD) {
         ++_track_record->nsites_vxd;
@@ -575,9 +575,9 @@ namespace MarlinTrk{
       _track_record->z0_mc[_track_record->nsites] = helixMC.getZ0();
       _track_record->tanL_mc[_track_record->nsites] = helixMC.getTanLambda();
             
-      double rec_x = trkhit->getPosition()[0];
-      double rec_y = trkhit->getPosition()[1];
-      double rec_z = trkhit->getPosition()[2];
+      double rec_x = trkhit.getPosition()[0];
+      double rec_y = trkhit.getPosition()[1];
+      double rec_z = trkhit.getPosition()[2];
       
       _track_record->site_x[_track_record->nsites] = rec_x;
       _track_record->site_y[_track_record->nsites] = rec_y;
diff --git a/Service/TrackSystemSvc/src/LCIOTrackPropagators.cc.remove b/Service/TrackSystemSvc/src/LCIOTrackPropagators.cc
similarity index 87%
rename from Service/TrackSystemSvc/src/LCIOTrackPropagators.cc.remove
rename to Service/TrackSystemSvc/src/LCIOTrackPropagators.cc
index 19a4f650..22fb8665 100644
--- a/Service/TrackSystemSvc/src/LCIOTrackPropagators.cc.remove
+++ b/Service/TrackSystemSvc/src/LCIOTrackPropagators.cc
@@ -1,10 +1,10 @@
 
-#include "LCIOTrackPropagators.h"
+#include "TrackSystemSvc/LCIOTrackPropagators.h"
 
 #include <cmath>
 #include <iostream>
 
-#include "IMPL/TrackStateImpl.h"
+#include "edm4hep/TrackState.h"
 
 #include "CLHEP/Matrix/Matrix.h"
 #include "CLHEP/Matrix/SymMatrix.h"
@@ -15,20 +15,20 @@
 
 namespace LCIOTrackPropagators{
   
-  int PropagateLCIOToNewRef( IMPL::TrackStateImpl& ts, double xref, double yref, double zref ) {
+  int PropagateLCIOToNewRef( edm4hep::TrackState& ts, double xref, double yref, double zref ) {
     
     //    std::cout << "PropagateLCIOToNewRef: x:y:z = " << xref << " : " << yref << " : " << zref << std::endl ;
     
     // Convert Parameters
     
-    const double d0    = ts.getD0() ;
-    const double phi0  = ts.getPhi() ;
-    const double omega = ts.getOmega() ;
-    const double z0    = ts.getZ0() ;
-    const double tanL  = ts.getTanLambda() ;
+    const double d0    = ts.D0 ;
+    const double phi0  = ts.phi ;
+    const double omega = ts.omega ;
+    const double z0    = ts.Z0 ;
+    const double tanL  = ts.tanLambda ;
     
     //   const double charge = omega/fabs(omega) ;
-    const float* ref = ts.getReferencePoint() ;  
+    edm4hep::Vector3f ref = ts.referencePoint ;  
     
     const double radius = 1.0/omega ; 
     
@@ -65,7 +65,7 @@ namespace LCIOTrackPropagators{
       for(int jcol=0; jcol<irow+1; ++jcol){
         //      std::cout << "row = " << irow << " col = " << jcol << std::endl ;
         //      std::cout << "cov["<< icov << "] = " << _cov[icov] << std::endl ;
-        cov0[irow][jcol] = ts.getCovMatrix()[icov] ;
+        cov0[irow][jcol] = ts.covMatrix[icov] ;
         ++icov ;
       }
     }
@@ -100,7 +100,7 @@ namespace LCIOTrackPropagators{
     
     CLHEP::HepSymMatrix covPrime =  cov0.similarity(propagatorMatrix);
     
-    EVENT::FloatVec cov( 15 )  ; 
+    std::array<float,15> cov;
     
     icov = 0 ;
     
@@ -116,11 +116,11 @@ namespace LCIOTrackPropagators{
     while ( phi0Prime < -M_PI  ) phi0Prime += 2.0*M_PI ;
     while ( phi0Prime >= M_PI )  phi0Prime -= 2.0*M_PI ;
     
-    ts.setD0( d0Prime ) ;  
-    ts.setPhi( phi0Prime  ) ; 
-    ts.setOmega( omega ) ;
-    ts.setZ0( z0Prime ) ;  
-    ts.setTanLambda( tanL ) ;  
+    ts.D0 = d0Prime;  
+    ts.phi = phi0Prime ; 
+    ts.omega = omega;
+    ts.Z0 = z0Prime ;  
+    ts.tanLambda = tanL;  
     
     
     float refPointPrime[3] ;
@@ -128,9 +128,9 @@ namespace LCIOTrackPropagators{
     refPointPrime[1] = yref ;
     refPointPrime[2] = zref ;
     
-    ts.setReferencePoint(refPointPrime) ;
+    ts.referencePoint = refPointPrime;
     
-    ts.setCovMatrix( cov ) ;
+    ts.covMatrix = cov;
     
     return 0 ;
     
@@ -142,22 +142,22 @@ namespace LCIOTrackPropagators{
   // For direction== 1  the first crossing traversing in positive s will be taken
   // For direction==-1  the first crossing traversing in negative s will be taken
   
-  int PropagateLCIOToCylinder( IMPL::TrackStateImpl& ts, float r0, float x0, float y0, int direction, double epsilon){
+  int PropagateLCIOToCylinder( edm4hep::TrackState& ts, float r0, float x0, float y0, int direction, double epsilon){
     
     // taken from http://paulbourke.net/geometry/2circle/tvoght.c
     
     //    std::cout << "PropagateLCIOToCylinder: r = " << r0 << " x0:y0 = " << x0 << " : " << y0 << " direction = " << direction << std::endl ;
     
     
-    const double x_ref = ts.getReferencePoint()[0] ; 
-    const double y_ref = ts.getReferencePoint()[1] ; 
-    const double z_ref = ts.getReferencePoint()[2] ; 
+    const double x_ref = ts.referencePoint[0] ; 
+    const double y_ref = ts.referencePoint[1] ; 
+    const double z_ref = ts.referencePoint[2] ; 
     
-    const double d0    = ts.getD0() ;
-    const double z0    = ts.getZ0() ;
-    const double phi0  = ts.getPhi() ;
-    const double tanl  = ts.getTanLambda() ;
-    const double omega = ts.getOmega() ;
+    const double d0    = ts.D0 ;
+    const double z0    = ts.Z0 ;
+    const double phi0  = ts.phi ;
+    const double tanl  = ts.tanLambda ;
+    const double omega = ts.omega ;
     
     const double rho   = 1.0 / omega ;
     const double x_pca = x_ref - d0 * sin(phi0) ; 
@@ -305,18 +305,18 @@ namespace LCIOTrackPropagators{
     
   }
   
-  int PropagateLCIOToZPlane( IMPL::TrackStateImpl& ts, float z) {
+  int PropagateLCIOToZPlane( edm4hep::TrackState& ts, float z) {
     
     
-    const double x_ref = ts.getReferencePoint()[0] ; 
-    const double y_ref = ts.getReferencePoint()[1] ; 
-    const double z_ref = ts.getReferencePoint()[2] ; 
+    const double x_ref = ts.referencePoint[0] ; 
+    const double y_ref = ts.referencePoint[1] ; 
+    const double z_ref = ts.referencePoint[2] ; 
     
-    const double d0    = ts.getD0() ;
-    const double z0    = ts.getZ0() ;
-    const double phi0  = ts.getPhi() ;
-    const double tanl  = ts.getTanLambda() ;
-    const double omega = ts.getOmega() ;
+    const double d0    = ts.D0 ;
+    const double z0    = ts.Z0 ;
+    const double phi0  = ts.phi ;
+    const double tanl  = ts.tanLambda ;
+    const double omega = ts.omega ;
     
     const double x_pca = x_ref - d0 * sin(phi0) ; 
     const double y_pca = y_ref + d0 * cos(phi0) ; 
@@ -340,22 +340,22 @@ namespace LCIOTrackPropagators{
   // For direction ==  0  the closest crossing point will be taken
   // For direction ==  1  the first crossing traversing in positive s will be taken
   // For direction == -1  the first crossing traversing in negative s will be taken
-  int PropagateLCIOToPlaneParralelToZ( IMPL::TrackStateImpl& ts, float x1, float y1, float x2, float y2, int direction, double epsilon) {
+  int PropagateLCIOToPlaneParralelToZ( edm4hep::TrackState& ts, float x1, float y1, float x2, float y2, int direction, double epsilon) {
     
     // check that direction has one of the correct values
     if( !( direction == 0 || direction == 1 || direction == -1) ) return -1 ;
     
     // taken from http://paulbourke.net/geometry/sphereline/raysphere.c
     
-    const double x_ref = ts.getReferencePoint()[0] ; 
-    const double y_ref = ts.getReferencePoint()[1] ; 
-    const double z_ref = ts.getReferencePoint()[2] ; 
+    const double x_ref = ts.referencePoint[0] ; 
+    const double y_ref = ts.referencePoint[1] ; 
+    const double z_ref = ts.referencePoint[2] ; 
     
-    const double d0    = ts.getD0() ;
-    const double z0    = ts.getZ0() ;
-    const double phi0  = ts.getPhi() ;
-    const double tanl  = ts.getTanLambda() ;
-    const double omega = ts.getOmega() ;
+    const double d0    = ts.D0 ;
+    const double z0    = ts.Z0 ;
+    const double phi0  = ts.phi ;
+    const double tanl  = ts.tanLambda ;
+    const double omega = ts.omega ;
     
     const double rho   = 1.0 / omega ;
     const double x_pca = x_ref - d0 * sin(phi0) ; 
diff --git a/Service/TrackSystemSvc/src/MarlinKalTest.cc b/Service/TrackSystemSvc/src/MarlinKalTest.cc
index b6e32021..38a4f5fc 100644
--- a/Service/TrackSystemSvc/src/MarlinKalTest.cc
+++ b/Service/TrackSystemSvc/src/MarlinKalTest.cc
@@ -418,11 +418,11 @@ namespace MarlinTrk{
     return ml_retval;
   }
   
-  const ILDVMeasLayer* MarlinKalTest::findMeasLayer( edm4hep::TrackerHit* trkhit) const {
+  const ILDVMeasLayer* MarlinKalTest::findMeasLayer( edm4hep::ConstTrackerHit trkhit) const {
     
-    const TVector3 hit_pos( trkhit->getPosition()[0], trkhit->getPosition()[1], trkhit->getPosition()[2]) ;
+    const TVector3 hit_pos( trkhit.getPosition()[0], trkhit.getPosition()[1], trkhit.getPosition()[2]) ;
     
-    return this->findMeasLayer( trkhit->getCellID(), hit_pos ) ;
+    return this->findMeasLayer( trkhit.getCellID(), hit_pos ) ;
     
   }
   
diff --git a/Service/TrackSystemSvc/src/MarlinKalTest.h b/Service/TrackSystemSvc/src/MarlinKalTest.h
index ac9ed152..2e62bd09 100644
--- a/Service/TrackSystemSvc/src/MarlinKalTest.h
+++ b/Service/TrackSystemSvc/src/MarlinKalTest.h
@@ -2,6 +2,7 @@
 #define MarlinKalTest_h
 
 #include "TrackSystemSvc/IMarlinTrkSystem.h"
+#include "edm4hep/TrackerHitConst.h"
 
 #include "gear/GearMgr.h"
 
@@ -79,7 +80,7 @@ namespace MarlinTrk{
     bool is_initialised ;
     
     //** find the measurment layer for a given hit 
-    const ILDVMeasLayer* findMeasLayer(edm4hep::TrackerHit* trkhit) const ; 
+    const ILDVMeasLayer* findMeasLayer(edm4hep::ConstTrackerHit trkhit) const ; 
     //** find the measurment layer for a given det element ID and point in space 
     const ILDVMeasLayer* findMeasLayer(int detElementID, const TVector3& point) const ;
     
diff --git a/Service/TrackSystemSvc/src/MarlinKalTestTrack.cc b/Service/TrackSystemSvc/src/MarlinKalTestTrack.cc
index 4c0bf153..6a4ec592 100644
--- a/Service/TrackSystemSvc/src/MarlinKalTestTrack.cc
+++ b/Service/TrackSystemSvc/src/MarlinKalTestTrack.cc
@@ -109,33 +109,28 @@ namespace MarlinTrk {
   
   
   
-  int MarlinKalTestTrack::addHit( edm4hep::TrackerHit* trkhit) {
-    const ILDVMeasLayer* ml = 0;
-    try{
-      ml = _ktest->findMeasLayer( trkhit );
-    }
-    catch(MarlinTrk::Exception& e){
-      std::cout << e.what() << std::endl;
-    }
-    return this->addHit( trkhit, ml) ;
+  int MarlinKalTestTrack::addHit( edm4hep::ConstTrackerHit trkhit) {
+    
+    return this->addHit( trkhit, _ktest->findMeasLayer( trkhit )) ;
     
   } 
   
-  int MarlinKalTestTrack::addHit( edm4hep::TrackerHit* trkhit, const ILDVMeasLayer* ml) {
-    //std::cout << "MarlinKalTestTrack::addHit: trkhit = "  << trkhit->id() << " addr: " << trkhit << " ml = " << ml << std::endl ;
-    if( trkhit && ml ) {
+  int MarlinKalTestTrack::addHit( edm4hep::ConstTrackerHit trkhit, const ILDVMeasLayer* ml) {
+    //std::cout << "MarlinKalTestTrack::addHit: trkhit = "  << trkhit.id() << " addr: " << trkhit << " ml = " << ml << std::endl ;
+    if( trkhit.isAvailable() && ml ) {
       //if(ml){
       return this->addHit( trkhit, ml->ConvertLCIOTrkHit(trkhit), ml) ;
     }
     else {
-      //std::cout << "MarlinKalTestTrack::addHit: trkhit = "  << trkhit->id() << " addr: " << trkhit << " ml = " << ml << std::endl ;
+      std::cout << "MarlinKalTestTrack::addHit: trkhit = "  << trkhit.id() << " addr: " << trkhit << " ml = " << ml << std::endl ;
+      //streamlog_out( ERROR ) << " MarlinKalTestTrack::addHit - bad inputs " <<  trkhit << " ml : " << ml << std::endl ;
       return bad_intputs ;
     }
     return bad_intputs ;
   }
   
-  int MarlinKalTestTrack::addHit( edm4hep::TrackerHit* trkhit, ILDVTrackHit* kalhit, const ILDVMeasLayer* ml) {
-    //std::cout << "MarlinKalTestTrack::addHit: trkhit = "  << trkhit->id() << " ILDVTrackHit: " << kalhit << " ml = " << ml << std::endl ;
+  int MarlinKalTestTrack::addHit( edm4hep::ConstTrackerHit trkhit, ILDVTrackHit* kalhit, const ILDVMeasLayer* ml) {
+    //std::cout << "MarlinKalTestTrack::addHit: trkhit = "  << trkhit.id() << " ILDVTrackHit: " << kalhit << " ml = " << ml << std::endl ;
     if( kalhit && ml ) {
       //if(ml){
       _kalhits->Add(kalhit ) ;  // Add hit and set surface found 
@@ -143,7 +138,7 @@ namespace MarlinTrk {
                                                     //    _kaltest_hits_to_lcio_hits[kalhit] = trkhit ; // add hit to map relating kaltest and lcio hits
     }
     else {
-      //std::cout << "MarlinKalTestTrack::addHit: trkhit = "  << trkhit->id() << " ILDVTrackHit: " << kalhit << " ml = " << ml << std::endl ;
+      //std::cout << "MarlinKalTestTrack::addHit: trkhit = "  << trkhit.id() << " ILDVTrackHit: " << kalhit << " ml = " << ml << std::endl ;
       if(kalhit) delete kalhit;
       return bad_intputs ;
     }
@@ -614,21 +609,21 @@ namespace MarlinTrk {
       // get the measurement layer of the current hit
       const ILDVMeasLayer* ml =  dynamic_cast<const ILDVMeasLayer*>( &(kalhit->GetMeasLayer() ) ) ;
       TVector3 pos = ml->HitToXv(*kalhit);
-      /*
       std::cout << "debug: Kaltrack::addAndFit : site discarded! at index : " << ml->GetIndex()
-	<< " for type " << ml->GetName() 
-	<< " chi2increment = " << chi2increment
-	<< " maxChi2Increment = " << maxChi2Increment
-	<< " x = " << pos.x()
-	<< " y = " << pos.y()
-	<< " z = " << pos.z()
-	<< " with CellIDs: " << std::endl;
+      << " for type " << ml->GetName() 
+      << " chi2increment = " << chi2increment
+      << " maxChi2Increment = " << maxChi2Increment
+      << " x = " << pos.x()
+      << " y = " << pos.y()
+      << " z = " << pos.z()
+      << " with CellIDs: " << std::endl;
+      
       for (unsigned int i = 0; i < (dynamic_cast<const ILDVMeasLayer*>( &(kalhit->GetMeasLayer() ) )->getNCellIDs());++i) {
 	std::cout << "debug: CellID = " 
         << dynamic_cast<const ILDVMeasLayer*>( &(kalhit->GetMeasLayer() ) )->getCellIDs()[i] 
         << std::endl ;
       }
-      */
+      
 
 #ifdef MARLINTRK_DIAGNOSTICS_ON
       _ktest->_diagnostics.record_rejected_site(kalhit, temp_site); 
@@ -674,9 +669,9 @@ namespace MarlinTrk {
     
   }
   
-  int MarlinKalTestTrack::addAndFit( edm4hep::TrackerHit* trkhit, double& chi2increment, double maxChi2Increment) {
+  int MarlinKalTestTrack::addAndFit( edm4hep::ConstTrackerHit trkhit, double& chi2increment, double maxChi2Increment) {
     
-    if( ! trkhit ) { 
+    if( ! trkhit.isAvailable() ) { 
       std::cout << "Error: MarlinKalTestTrack::addAndFit(edm4hep::TrackerHit trkhit, double& chi2increment, double maxChi2Increment): trkhit == 0" << std::endl;
       return bad_intputs ; 
     }
@@ -688,8 +683,8 @@ namespace MarlinTrk {
       //     if point is not on surface and more than one surface exists ...
       
       std::cout << "Error>>>>>>>>>>>  no measurment layer found for trkhit cellid0 : " 
-		<< decodeILD( trkhit->getCellID() ) << " at " 
-		<< trkhit->getPosition() << std::endl ;
+		<< decodeILD( trkhit.getCellID() ) << " at " 
+		<< trkhit.getPosition() << std::endl ;
       
       return  IMarlinTrack::bad_intputs ; 
     }
@@ -726,14 +721,14 @@ namespace MarlinTrk {
     }
     
     // set the values for the point at which the fit becomes constained 
-    if( _trackHitAtPositiveNDF == 0 && _kaltrack->GetNDF() >= 0){
+    if(! _trackHitAtPositiveNDF.isAvailable() && _kaltrack->GetNDF() >= 0){
 
       _trackHitAtPositiveNDF = trkhit;
       _hitIndexAtPositiveNDF = _kaltrack->IndexOf( site );
       /*
       streamlog_out( DEBUG2 ) << ">>>>>>>>>>>  Fit is now constrained at : "
-      << decodeILD( trkhit->getCellID() ) 
-      << " pos " << trkhit->getPosition()
+      << decodeILD( trkhit.getCellID() ) 
+      << " pos " << trkhit.getPosition()
       << " trkhit = " << _trackHitAtPositiveNDF
       << " index of kalhit = " << _hitIndexAtPositiveNDF
       << " NDF = " << _kaltrack->GetNDF() 
@@ -747,7 +742,7 @@ namespace MarlinTrk {
   
   
   
-  int MarlinKalTestTrack::testChi2Increment( edm4hep::TrackerHit* trkhit, double& chi2increment ) {
+  int MarlinKalTestTrack::testChi2Increment( edm4hep::ConstTrackerHit trkhit, double& chi2increment ) {
     
     //if( ! trkhit ) { 
     //  streamlog_out( ERROR) << "MarlinKalTestTrack::addAndFit(edm4hep::TrackerHit trkhit, double& chi2increment, double maxChi2Increment): trkhit == 0" << std::endl;
@@ -761,8 +756,8 @@ namespace MarlinTrk {
       //     if point is not on surface and more than one surface exists ...
       
       std::cout << "Error>>>>>>>>>>>  no measurment layer found for trkhit cellid0 : " 
-		<< decodeILD( trkhit->getCellID() ) << " at " 
-		<< trkhit->getPosition() << std::endl ;
+		<< decodeILD( trkhit.getCellID() ) << " at " 
+		<< trkhit.getPosition() << std::endl ;
       
       return  IMarlinTrack::bad_intputs ; 
       
@@ -821,21 +816,21 @@ namespace MarlinTrk {
       int error_code = this->addAndFit( kalhit, chi2increment, site, maxChi2Increment );
       
       
-      edm4hep::TrackerHit* trkhit = kalhit->getLCIOTrackerHit();
+      edm4hep::ConstTrackerHit trkhit = kalhit->getLCIOTrackerHit();
       
       if( error_code == 0 ){ // add trkhit to map associating trkhits and sites
         _hit_used_for_sites[trkhit] = site;
         _hit_chi2_values.push_back(std::make_pair(trkhit, chi2increment));
 
         // set the values for the point at which the fit becomes constained 
-        if( _trackHitAtPositiveNDF == 0 && _kaltrack->GetNDF() >= 0){
+        if( !_trackHitAtPositiveNDF.isAvailable() && _kaltrack->GetNDF() >= 0){
           
           _trackHitAtPositiveNDF = trkhit;
           _hitIndexAtPositiveNDF = _kaltrack->IndexOf( site );
           /*
           streamlog_out( DEBUG2 ) << ">>>>>>>>>>>  Fit is now constrained at : "
-          << decodeILD( trkhit->getCellID() ) 
-          << " pos " << trkhit->getPosition()
+          << decodeILD( trkhit.getCellID() ) 
+          << " pos " << trkhit.getPosition()
           << " trkhit = " << _trackHitAtPositiveNDF
           << " index of kalhit = " << _hitIndexAtPositiveNDF
           << " NDF = " << _kaltrack->GetNDF() 
@@ -907,15 +902,15 @@ namespace MarlinTrk {
   
   /** smooth track states from the last filtered hit back to the measurement site associated with the given hit 
    */
-  int MarlinKalTestTrack::smooth( edm4hep::TrackerHit* trkhit ) {
+  int MarlinKalTestTrack::smooth( edm4hep::ConstTrackerHit trkhit ) {
     
     //streamlog_out( DEBUG2 )  << "MarlinKalTestTrack::smooth( edm4hep::TrackerHit " << trkhit << "  ) " << std::endl ;
 
-    if ( !trkhit ) {
+    if ( !trkhit.isAvailable() ) {
       return bad_intputs ;
     }
         
-    std::map<edm4hep::TrackerHit*, TKalTrackSite*>::const_iterator it;
+    std::map<edm4hep::ConstTrackerHit, TKalTrackSite*>::const_iterator it;
         
     TKalTrackSite* site = 0 ;
     int error_code = getSiteFromLCIOHit(trkhit, site);
@@ -948,9 +943,9 @@ namespace MarlinTrk {
   }
   
   
-  int MarlinKalTestTrack::getTrackState( edm4hep::TrackerHit* trkhit, edm4hep::TrackState& ts, double& chi2, int& ndf ) {
+  int MarlinKalTestTrack::getTrackState( edm4hep::ConstTrackerHit trkhit, edm4hep::TrackState& ts, double& chi2, int& ndf ) {
     
-    //streamlog_out( DEBUG2 )  << "MarlinKalTestTrack::getTrackState(edm4hep::TrackerHit* trkhit, edm4hep::TrackState& ts ) using hit: " << trkhit << " with cellID0 = " << trkhit->getCellID() << std::endl ;
+    //streamlog_out( DEBUG2 )  << "MarlinKalTestTrack::getTrackState(edm4hep::ConstTrackerHit trkhit, edm4hep::TrackState& ts ) using hit: " << trkhit << " with cellID0 = " << trkhit.getCellID() << std::endl ;
     
     TKalTrackSite* site = 0 ;
     int error_code = getSiteFromLCIOHit(trkhit, site);
@@ -965,7 +960,7 @@ namespace MarlinTrk {
   }
   
   
-  int MarlinKalTestTrack::getHitsInFit( std::vector<std::pair<edm4hep::TrackerHit*, double> >& hits ) {
+  int MarlinKalTestTrack::getHitsInFit( std::vector<std::pair<edm4hep::ConstTrackerHit, double> >& hits ) {
     //std::cout << "debug: _hit_chi2_values address= " << &_hit_chi2_values << " " << &(*(_hit_chi2_values.begin())) << " want to copy to hits address=" << &hits << std::endl; 
     std::copy( _hit_chi2_values.begin() , _hit_chi2_values.end() , std::back_inserter(  hits  )  ) ;
     //hits.resize(_hit_chi2_values.size());
@@ -987,7 +982,7 @@ namespace MarlinTrk {
     
   }
   
-  int MarlinKalTestTrack::getOutliers( std::vector<std::pair<edm4hep::TrackerHit*, double> >& hits ) {
+  int MarlinKalTestTrack::getOutliers( std::vector<std::pair<edm4hep::ConstTrackerHit, double> >& hits ) {
 
     std::copy( _outlier_chi2_values.begin() , _outlier_chi2_values.end() , std::back_inserter(  hits  )  ) ;
    
@@ -1018,7 +1013,7 @@ namespace MarlinTrk {
     
   }
   
-  int MarlinKalTestTrack::getTrackerHitAtPositiveNDF( edm4hep::TrackerHit*& trkhit ) {
+  int MarlinKalTestTrack::getTrackerHitAtPositiveNDF( edm4hep::ConstTrackerHit& trkhit ) {
 
       trkhit = _trackHitAtPositiveNDF;
       return success;    
@@ -1034,7 +1029,7 @@ namespace MarlinTrk {
     
   }
   
-  int MarlinKalTestTrack::extrapolate( const edm4hep::Vector3d& point, edm4hep::TrackerHit* trkhit, edm4hep::TrackState& ts, double& chi2, int& ndf ) {
+  int MarlinKalTestTrack::extrapolate( const edm4hep::Vector3d& point, edm4hep::ConstTrackerHit trkhit, edm4hep::TrackState& ts, double& chi2, int& ndf ) {
     
     TKalTrackSite* site = 0 ;
     int error_code = getSiteFromLCIOHit(trkhit, site);
@@ -1086,7 +1081,7 @@ namespace MarlinTrk {
   }
   
   
-  int MarlinKalTestTrack::extrapolateToLayer( int layerID, edm4hep::TrackerHit* trkhit, edm4hep::TrackState& ts, double& chi2, int& ndf, int& detElementID, int mode ) { 
+  int MarlinKalTestTrack::extrapolateToLayer( int layerID, edm4hep::ConstTrackerHit trkhit, edm4hep::TrackState& ts, double& chi2, int& ndf, int& detElementID, int mode ) { 
     
     TKalTrackSite* site = 0;
     int error_code = getSiteFromLCIOHit(trkhit, site);
@@ -1123,7 +1118,7 @@ namespace MarlinTrk {
   }
   
   
-  int MarlinKalTestTrack::extrapolateToDetElement( int detElementID, edm4hep::TrackerHit* trkhit, edm4hep::TrackState& ts, double& chi2, int& ndf, int mode ) { 
+  int MarlinKalTestTrack::extrapolateToDetElement( int detElementID, edm4hep::ConstTrackerHit trkhit, edm4hep::TrackState& ts, double& chi2, int& ndf, int mode ) { 
     
     TKalTrackSite* site = 0;
     int error_code = getSiteFromLCIOHit(trkhit, site);
@@ -1164,7 +1159,7 @@ namespace MarlinTrk {
     
   }
   
-  int MarlinKalTestTrack::propagate( const edm4hep::Vector3d& point, edm4hep::TrackerHit* trkhit, edm4hep::TrackState& ts, double& chi2, int& ndf ){
+  int MarlinKalTestTrack::propagate( const edm4hep::Vector3d& point, edm4hep::ConstTrackerHit trkhit, edm4hep::TrackState& ts, double& chi2, int& ndf ){
     
     TKalTrackSite* site = 0;
     int error_code = getSiteFromLCIOHit(trkhit, site);
@@ -1274,7 +1269,7 @@ namespace MarlinTrk {
   }
   
   
-  int MarlinKalTestTrack::propagateToLayer( int layerID, edm4hep::TrackerHit* trkhit, edm4hep::TrackState& ts, double& chi2, int& ndf, int& detElementID, int mode ) { 
+  int MarlinKalTestTrack::propagateToLayer( int layerID, edm4hep::ConstTrackerHit trkhit, edm4hep::TrackState& ts, double& chi2, int& ndf, int& detElementID, int mode ) { 
     
     TKalTrackSite* site = 0;
     int error_code = getSiteFromLCIOHit(trkhit, site);
@@ -1312,7 +1307,7 @@ namespace MarlinTrk {
   }
   
   
-  int MarlinKalTestTrack::propagateToDetElement( int detElementID, edm4hep::TrackerHit* trkhit, edm4hep::TrackState& ts, double& chi2, int& ndf, int mode ) { 
+  int MarlinKalTestTrack::propagateToDetElement( int detElementID, edm4hep::ConstTrackerHit trkhit, edm4hep::TrackState& ts, double& chi2, int& ndf, int mode ) { 
     
     TKalTrackSite* site = 0;
     int error_code = getSiteFromLCIOHit(trkhit, site);
@@ -1350,7 +1345,7 @@ namespace MarlinTrk {
   }
   
   
-  int MarlinKalTestTrack::intersectionWithDetElement( int detElementID,  edm4hep::TrackerHit* trkhit, edm4hep::Vector3d& point, int mode ) {  
+  int MarlinKalTestTrack::intersectionWithDetElement( int detElementID,  edm4hep::ConstTrackerHit trkhit, edm4hep::Vector3d& point, int mode ) {  
     
     TKalTrackSite* site = 0;
     int error_code = getSiteFromLCIOHit(trkhit, site);
@@ -1417,7 +1412,7 @@ namespace MarlinTrk {
   }
   
   
-  int MarlinKalTestTrack::intersectionWithLayer( int layerID,  edm4hep::TrackerHit* trkhit, edm4hep::Vector3d& point, int& detElementID, int mode ) {  
+  int MarlinKalTestTrack::intersectionWithLayer( int layerID,  edm4hep::ConstTrackerHit trkhit, edm4hep::Vector3d& point, int& detElementID, int mode ) {  
     
     TKalTrackSite* site = 0;
     int error_code = getSiteFromLCIOHit(trkhit, site);
@@ -1668,9 +1663,9 @@ namespace MarlinTrk {
   }
   
   
-  int MarlinKalTestTrack::getSiteFromLCIOHit( edm4hep::TrackerHit* trkhit, TKalTrackSite*& site ) const {
+  int MarlinKalTestTrack::getSiteFromLCIOHit( edm4hep::ConstTrackerHit trkhit, TKalTrackSite*& site ) const {
     
-    std::map<edm4hep::TrackerHit*,TKalTrackSite*>::const_iterator it;
+    std::map<edm4hep::ConstTrackerHit,TKalTrackSite*>::const_iterator it;
     
     it = _hit_used_for_sites.find(trkhit) ;  
     
diff --git a/Service/TrackSystemSvc/src/MarlinKalTestTrack.h b/Service/TrackSystemSvc/src/MarlinKalTestTrack.h
index 50551db8..1df08e49 100644
--- a/Service/TrackSystemSvc/src/MarlinKalTestTrack.h
+++ b/Service/TrackSystemSvc/src/MarlinKalTestTrack.h
@@ -49,17 +49,17 @@ namespace MarlinTrk{
     /** add hit to track - the hits have to be added ordered in time ( i.e. typically outgoing )
      *  this order will define the direction of the energy loss used in the fit
      */
-    int addHit(edm4hep::TrackerHit* hit) ;
+    int addHit(edm4hep::ConstTrackerHit hit) ;
     
     /** add hit to track - the hits have to be added ordered in time ( i.e. typically outgoing )
      *  this order will define the direction of the energy loss used in the fit
      */    
-    int addHit(edm4hep::TrackerHit* trkhit, const ILDVMeasLayer* ml) ;
+    int addHit(edm4hep::ConstTrackerHit trkhit, const ILDVMeasLayer* ml) ;
     
     /** add hit to track - the hits have to be added ordered in time ( i.e. typically outgoing )
      *  this order will define the direction of the energy loss used in the fit
      */    
-    int addHit( edm4hep::TrackerHit* trkhit, ILDVTrackHit* kalhit, const ILDVMeasLayer* ml) ;
+    int addHit( edm4hep::ConstTrackerHit trkhit, ILDVTrackHit* kalhit, const ILDVMeasLayer* ml) ;
     
     /** initialise the fit using the hits added up to this point -
      *  the fit direction has to be specified using IMarlinTrack::backward or IMarlinTrack::forward. 
@@ -90,13 +90,13 @@ namespace MarlinTrk{
     
     /** smooth track states from the last filtered hit back to the measurement site associated with the given hit 
      */
-    int smooth( edm4hep::TrackerHit* hit )  ;
+    int smooth( edm4hep::ConstTrackerHit hit )  ;
     
     
     /** update the current fit using the supplied hit, return code via int. Provides the Chi2 increment to the fit from adding the hit via reference. 
      *  the given hit will not be added if chi2increment > maxChi2Increment. 
      */
-    int addAndFit( edm4hep::TrackerHit* hit, double& chi2increment, double maxChi2Increment=DBL_MAX ) ;
+    int addAndFit( edm4hep::ConstTrackerHit hit, double& chi2increment, double maxChi2Increment=DBL_MAX ) ;
     
     /** update the current fit using the supplied hit, return code via int. Provides the Chi2 increment to the fit from adding the hit via reference. 
      *  the given hit will not be added if chi2increment > maxChi2Increment. 
@@ -106,7 +106,7 @@ namespace MarlinTrk{
     
     /** obtain the chi2 increment which would result in adding the hit to the fit. This method will not alter the current fit, and the hit will not be stored in the list of hits or outliers
      */
-    int testChi2Increment( edm4hep::TrackerHit* hit, double& chi2increment ) ;
+    int testChi2Increment( edm4hep::ConstTrackerHit hit, double& chi2increment ) ;
     
     
     // Track State Accessesors
@@ -118,7 +118,7 @@ namespace MarlinTrk{
     
     /** get track state at measurement associated with the given hit, returning TrackState, chi2 and ndf via reference 
      */
-    int getTrackState( edm4hep::TrackerHit* hit, edm4hep::TrackState& ts, double& chi2, int& ndf ) ;
+    int getTrackState( edm4hep::ConstTrackerHit hit, edm4hep::TrackState& ts, double& chi2, int& ndf ) ;
     
     
     /** get the list of hits included in the fit, together with the chi2 contributions of the hits. 
@@ -126,14 +126,14 @@ namespace MarlinTrk{
      *  pairs consitining of the pointer as the first part of the pair and the chi2 contribution as
      *  the second.
      */
-    int getHitsInFit( std::vector<std::pair<edm4hep::TrackerHit*, double> >& hits ) ;
+    int getHitsInFit( std::vector<std::pair<edm4hep::ConstTrackerHit, double> >& hits ) ;
     
     /** get the list of hits which have been rejected by from the fit due to the a chi2 increment greater than threshold,
      *  Pointers to the hits together with their chi2 contribution will be filled into a vector of 
      *  pairs consitining of the pointer as the first part of the pair and the chi2 contribution as
      *  the second.
      */
-    int getOutliers( std::vector<std::pair<edm4hep::TrackerHit*, double> >& hits ) ;
+    int getOutliers( std::vector<std::pair<edm4hep::ConstTrackerHit, double> >& hits ) ;
     
     
     /** get the current number of degrees of freedom for the fit.
@@ -142,7 +142,7 @@ namespace MarlinTrk{
     
     /** get TrackeHit at which fit became constrained, i.e. ndf >= 0
      */
-    int getTrackerHitAtPositiveNDF( edm4hep::TrackerHit*& trkhit ) ;
+    int getTrackerHitAtPositiveNDF( edm4hep::ConstTrackerHit& trkhit ) ;
     
     // PROPAGATORS 
   
@@ -154,7 +154,7 @@ namespace MarlinTrk{
     /** propagate the fit at the measurement site associated with the given hit, to the point of closest approach to the given point,
      *  returning TrackState, chi2 and ndf via reference   
      */
-    int propagate( const edm4hep::Vector3d& point, edm4hep::TrackerHit* hit, edm4hep::TrackState& ts, double& chi2, int& ndf ) ;
+    int propagate( const edm4hep::Vector3d& point, edm4hep::ConstTrackerHit hit, edm4hep::TrackState& ts, double& chi2, int& ndf ) ;
     
     
     /** propagate the fit at the provided measurement site, to the point of closest approach to the given point,
@@ -170,7 +170,7 @@ namespace MarlinTrk{
     /** propagate the fit at the measurement site associated with the given hit, to numbered sensitive layer, 
      *  returning TrackState, chi2, ndf and integer ID of sensitive detector element via reference 
      */
-    int propagateToLayer( int layerID, edm4hep::TrackerHit* hit, edm4hep::TrackState& ts, double& chi2, int& ndf, int& detElementID, int mode=modeClosest )  ;
+    int propagateToLayer( int layerID, edm4hep::ConstTrackerHit hit, edm4hep::TrackState& ts, double& chi2, int& ndf, int& detElementID, int mode=modeClosest )  ;
     
     /** propagate the fit at the measurement site, to numbered sensitive layer, 
      *  returning TrackState, chi2, ndf and integer ID of sensitive detector element via reference 
@@ -184,7 +184,7 @@ namespace MarlinTrk{
     /** propagate the fit at the measurement site associated with the given hit, to sensitive detector element, 
      *  returning TrackState, chi2 and ndf via reference 
      */
-    int propagateToDetElement( int detEementID, edm4hep::TrackerHit* hit, edm4hep::TrackState& ts, double& chi2, int& ndf, int mode=modeClosest ) ;
+    int propagateToDetElement( int detEementID, edm4hep::ConstTrackerHit hit, edm4hep::TrackState& ts, double& chi2, int& ndf, int mode=modeClosest ) ;
   
     /** propagate the fit at the measurement site, to sensitive detector element, 
      *  returning TrackState, chi2, ndf and integer ID of sensitive detector element via reference 
@@ -202,7 +202,7 @@ namespace MarlinTrk{
     /** extrapolate the fit at the measurement site associated with the given hit, to the point of closest approach to the given point, 
      *    returning TrackState, chi2 and ndf via reference   
      */
-    int extrapolate( const edm4hep::Vector3d& point, edm4hep::TrackerHit* hit, edm4hep::TrackState& ts, double& chi2, int& ndf ) ;
+    int extrapolate( const edm4hep::Vector3d& point, edm4hep::ConstTrackerHit hit, edm4hep::TrackState& ts, double& chi2, int& ndf ) ;
     
     /** extrapolate the fit at the measurement site, to the point of closest approach to the given point, 
      *    returning TrackState, chi2 and ndf via reference   
@@ -216,7 +216,7 @@ namespace MarlinTrk{
     /** extrapolate the fit at the measurement site associated with the given hit, to numbered sensitive layer, 
      *  returning TrackState, chi2, ndf and integer ID of sensitive detector element via reference 
      */
-    int extrapolateToLayer( int layerID, edm4hep::TrackerHit* hit, edm4hep::TrackState& ts, double& chi2, int& ndf, int& detElementID, int mode=modeClosest )  ;
+    int extrapolateToLayer( int layerID, edm4hep::ConstTrackerHit hit, edm4hep::TrackState& ts, double& chi2, int& ndf, int& detElementID, int mode=modeClosest )  ;
     
     /** extrapolate the fit at the measurement site, to numbered sensitive layer, 
      *  returning TrackState, chi2, ndf and integer ID of sensitive detector element via reference 
@@ -230,7 +230,7 @@ namespace MarlinTrk{
     /** extrapolate the fit at the measurement site associated with the given hit, to sensitive detector element, 
      *  returning TrackState, chi2 and ndf via reference 
    */
-    int extrapolateToDetElement( int detEementID, edm4hep::TrackerHit* hit, edm4hep::TrackState& ts, double& chi2, int& ndf, int mode=modeClosest ) ;
+    int extrapolateToDetElement( int detEementID, edm4hep::ConstTrackerHit hit, edm4hep::TrackState& ts, double& chi2, int& ndf, int mode=modeClosest ) ;
     
     /** extrapolate the fit at the measurement site, to sensitive detector element, 
      *  returning TrackState, chi2, ndf and integer ID of sensitive detector element via reference 
@@ -250,7 +250,7 @@ namespace MarlinTrk{
     /** extrapolate the fit at the measurement site associated with the given hit, to numbered sensitive layer,
      *  returning intersection point in global coordinates and integer ID of the intersected sensitive detector element via reference 
      */
-    int intersectionWithLayer( int layerID, edm4hep::TrackerHit* hit, edm4hep::Vector3d& point, int& detElementID, int mode=modeClosest )  ;
+    int intersectionWithLayer( int layerID, edm4hep::ConstTrackerHit hit, edm4hep::Vector3d& point, int& detElementID, int mode=modeClosest )  ;
     
     /** extrapolate the fit at the measurement site, to numbered sensitive layer,
      *  returning intersection point in global coordinates and integer ID of the intersected sensitive detector element via reference 
@@ -265,7 +265,7 @@ namespace MarlinTrk{
     /** extrapolate the fit at the measurement site associated with the given hit, to sensitive detector element,
      *  returning intersection point in global coordinates via reference 
      */ 
-    int intersectionWithDetElement( int detElementID, edm4hep::TrackerHit* hit, edm4hep::Vector3d& point, int mode=modeClosest )  ;
+    int intersectionWithDetElement( int detElementID, edm4hep::ConstTrackerHit hit, edm4hep::Vector3d& point, int mode=modeClosest )  ;
     
     /** extrapolate the fit at the measurement site, to sensitive detector element,
      *  returning intersection point in global coordinates via reference 
@@ -297,7 +297,7 @@ namespace MarlinTrk{
     
     /** get the measurement site associated with the given lcio TrackerHit trkhit
      */
-    int getSiteFromLCIOHit( edm4hep::TrackerHit* trkhit, TKalTrackSite*& site ) const ;
+    int getSiteFromLCIOHit( edm4hep::ConstTrackerHit trkhit, TKalTrackSite*& site ) const ;
     
     
     
@@ -313,13 +313,13 @@ namespace MarlinTrk{
     
     TKalTrack* _kaltrack;
     
-    std::vector<edm4hep::TrackerHit*> _lcioHits ; 
+    std::vector<edm4hep::ConstTrackerHit> _lcioHits ; 
     
     TObjArray* _kalhits;
     
     MarlinKalTest* _ktest;
   
-    edm4hep::TrackerHit* _trackHitAtPositiveNDF;
+    edm4hep::ConstTrackerHit _trackHitAtPositiveNDF;
     int _hitIndexAtPositiveNDF;
     
     /** used to store whether initial track state has been supplied or created 
@@ -337,23 +337,23 @@ namespace MarlinTrk{
     
     /** map to store relation between lcio hits and measurement sites
      */
-    std::map<edm4hep::TrackerHit*, TKalTrackSite*> _hit_used_for_sites ;
+    std::map<edm4hep::ConstTrackerHit, TKalTrackSite*> _hit_used_for_sites ;
   
     /** map to store relation between lcio hits kaltest hits
      */
-    std::map<edm4hep::TrackerHit*, ILDVTrackHit*> _lcio_hits_to_kaltest_hits ;
+    std::map<edm4hep::ConstTrackerHit, ILDVTrackHit*> _lcio_hits_to_kaltest_hits ;
     
     /** vector to store lcio hits rejected for measurement sites
      */
-    std::vector<edm4hep::TrackerHit*> _hit_not_used_for_sites ;
+    std::vector<edm4hep::ConstTrackerHit> _hit_not_used_for_sites ;
     
     /** vector to store the chi-sqaure increment for measurement sites
      */
-    std::vector< std::pair<edm4hep::TrackerHit*, double> > _hit_chi2_values ;
+    std::vector< std::pair<edm4hep::ConstTrackerHit, double> > _hit_chi2_values ;
     
     /** vector to store the chi-sqaure increment for measurement sites
      */
-    std::vector< std::pair<edm4hep::TrackerHit*, double> > _outlier_chi2_values ;
+    std::vector< std::pair<edm4hep::ConstTrackerHit, double> > _outlier_chi2_values ;
     
   } ;
 }
diff --git a/Service/TrackSystemSvc/src/MarlinTrkDiagnostics.cc.remove b/Service/TrackSystemSvc/src/MarlinTrkDiagnostics.cc.remove
index 46aebfe6..8ceaa81a 100644
--- a/Service/TrackSystemSvc/src/MarlinTrkDiagnostics.cc.remove
+++ b/Service/TrackSystemSvc/src/MarlinTrkDiagnostics.cc.remove
@@ -10,7 +10,7 @@
 namespace MarlinTrk{
 
 
-  void getMCParticlesForTrackerHit(EVENT::TrackerHit* trkhit, std::vector<EVENT::MCParticle*>& mcps){
+  void getMCParticlesForTrackerHit(EVENT::ConstTrackerHit trkhit, std::vector<EVENT::MCParticle*>& mcps){
 
     if ( !trkhit ) {
       return;
@@ -20,13 +20,13 @@ namespace MarlinTrk{
     mcps.clear();
     
     // first check if this is a composite space point
-    if(UTIL::BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ]){
+    if(UTIL::BitSet32( trkhit.getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ]){
       
-      const EVENT::LCObjectVec rawObjects = trkhit->getRawHits();
+      const EVENT::LCObjectVec rawObjects = trkhit.getRawHits();
 
       for (unsigned iraw = 0; iraw < rawObjects.size(); ++iraw) {
 
-        EVENT::TrackerHit* rawHit = dynamic_cast< EVENT::TrackerHit* >( rawObjects[iraw] );
+        EVENT::ConstTrackerHit rawHit = dynamic_cast< EVENT::ConstTrackerHit >( rawObjects[iraw] );
 
         if( rawHit && rawHit->ext<MarlinTrk::MCTruth4HitExt>()){
           
@@ -51,8 +51,8 @@ namespace MarlinTrk{
     } else {
      
       
-      if( trkhit->ext<MarlinTrk::MCTruth4HitExt>()){
-        mcps.push_back(trkhit->ext<MarlinTrk::MCTruth4HitExt>()->simhit->getMCParticle());
+      if( trkhit.ext<MarlinTrk::MCTruth4HitExt>()){
+        mcps.push_back(trkhit.ext<MarlinTrk::MCTruth4HitExt>()->simhit->getMCParticle());
       }
 
       
diff --git a/Service/TrackSystemSvc/src/MarlinTrkUtils.cc b/Service/TrackSystemSvc/src/MarlinTrkUtils.cc
index f28442a2..a3654ec7 100644
--- a/Service/TrackSystemSvc/src/MarlinTrkUtils.cc
+++ b/Service/TrackSystemSvc/src/MarlinTrkUtils.cc
@@ -91,9 +91,9 @@ namespace MarlinTrk {
   
   
   
-  int createTrackStateAtCaloFace( IMarlinTrack* marlinTrk, edm4hep::TrackState* track, edm4hep::TrackerHit* trkhit, bool tanL_is_positive );
+  int createTrackStateAtCaloFace( IMarlinTrack* marlinTrk, edm4hep::TrackState* track, edm4hep::ConstTrackerHit trkhit, bool tanL_is_positive );
   
-  int createFinalisedLCIOTrack( IMarlinTrack* marlinTrk, std::vector<edm4hep::TrackerHit*>& hit_list, edm4hep::Track* track, bool fit_backwards, const std::array<float,15>& initial_cov_for_prefit, float bfield_z, double maxChi2Increment){
+  int createFinalisedLCIOTrack( IMarlinTrack* marlinTrk, std::vector<edm4hep::ConstTrackerHit>& hit_list, edm4hep::Track* track, bool fit_backwards, const std::array<float,15>& initial_cov_for_prefit, float bfield_z, double maxChi2Increment){
     
     ///////////////////////////////////////////////////////
     // check inputs 
@@ -130,7 +130,7 @@ namespace MarlinTrk {
     return return_error;
   }
   
-  int createFinalisedLCIOTrack( IMarlinTrack* marlinTrk, std::vector<edm4hep::TrackerHit*>& hit_list, edm4hep::Track* track, bool fit_backwards, edm4hep::TrackState* pre_fit, float bfield_z, double maxChi2Increment){
+  int createFinalisedLCIOTrack( IMarlinTrack* marlinTrk, std::vector<edm4hep::ConstTrackerHit>& hit_list, edm4hep::Track* track, bool fit_backwards, edm4hep::TrackState* pre_fit, float bfield_z, double maxChi2Increment){
     
     
     ///////////////////////////////////////////////////////
@@ -164,7 +164,7 @@ namespace MarlinTrk {
   
   
   
-  int createFit( std::vector<edm4hep::TrackerHit*>& hit_list, IMarlinTrack* marlinTrk, edm4hep::TrackState* pre_fit, float bfield_z, bool fit_backwards, double maxChi2Increment){
+  int createFit( std::vector<edm4hep::ConstTrackerHit>& hit_list, IMarlinTrack* marlinTrk, edm4hep::TrackState* pre_fit, float bfield_z, bool fit_backwards, double maxChi2Increment){
     
     
     ///////////////////////////////////////////////////////
@@ -203,27 +203,27 @@ namespace MarlinTrk {
     // add hits to IMarlinTrk  
     ///////////////////////////////////////////////////////
     
-    std::vector<edm4hep::TrackerHit*>::iterator it = hit_list.begin();
+    std::vector<edm4hep::ConstTrackerHit>::iterator it = hit_list.begin();
     
     //  start by trying to add the hits to the track we want to finally use. 
     //std::cout << "MarlinTrk::createFit Start Fit: AddHits: number of hits to fit " << hit_list.size() << std::endl;
     
-    std::vector<edm4hep::TrackerHit*> added_hits;
+    std::vector<edm4hep::ConstTrackerHit> added_hits;
     unsigned int ndof_added = 0;
     
     for( it = hit_list.begin() ; it != hit_list.end() ; ++it ) {
       
-      edm4hep::TrackerHit* trkHit = *it;
+      edm4hep::ConstTrackerHit trkHit = *it;
       bool isSuccessful = false; 
       //std::cout << "debug: TrackerHit pointer " << trkHit << std::endl;
-      if( UTIL::BitSet32( trkHit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ]   ){ //it is a composite spacepoint        
+      if( UTIL::BitSet32( trkHit.getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ]   ){ //it is a composite spacepoint        
         //Split it up and add both hits to the MarlinTrk
         //const EVENT::LCObjectVec rawObjects = trkHit->getRawHits();
 	//std::cout << "space point is not still valid! pelease wait updating..." <<std::endl;
 	//exit(1);
-        int nRawHit = trkHit->rawHits_size();
+        int nRawHit = trkHit.rawHits_size();
         for( unsigned k=0; k< nRawHit; k++ ){
-          edm4hep::TrackerHit* rawHit = Navigation::Instance()->GetTrackerHit(trkHit->getRawHits(k));
+          edm4hep::ConstTrackerHit rawHit = Navigation::Instance()->GetTrackerHit(trkHit.getRawHits(k));
 	  if( marlinTrk->addHit( rawHit ) == IMarlinTrack::success ){
 	    isSuccessful = true; //if at least one hit from the spacepoint gets added
             ++ndof_added;
@@ -280,7 +280,7 @@ namespace MarlinTrk {
   
   
   
-  int createPrefit( std::vector<edm4hep::TrackerHit*>& hit_list, edm4hep::TrackState* pre_fit, float bfield_z, bool fit_backwards){
+  int createPrefit( std::vector<edm4hep::ConstTrackerHit>& hit_list, edm4hep::TrackState* pre_fit, float bfield_z, bool fit_backwards){
     
     ///////////////////////////////////////////////////////
     // check inputs 
@@ -295,12 +295,12 @@ namespace MarlinTrk {
     // loop over all the hits and create a list consisting only 2D hits 
     ///////////////////////////////////////////////////////
     
-    std::vector<edm4hep::TrackerHit*> twoD_hits;
+    std::vector<edm4hep::ConstTrackerHit> twoD_hits;
     
     for (unsigned ihit=0; ihit < hit_list.size(); ++ihit) {
       
       // check if this a space point or 2D hit 
-      if(UTIL::BitSet32( hit_list[ihit]->getType() )[ UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL ] == false ){
+      if(UTIL::BitSet32( hit_list[ihit].getType() )[ UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL ] == false ){
         // then add to the list 
         twoD_hits.push_back(hit_list[ihit]);
         
@@ -321,18 +321,18 @@ namespace MarlinTrk {
     ///////////////////////////////////////////////////////
     
     // SJA:FIXME: this may not be the optimal 3 hits to take in certain cases where the 3 hits are not well spread over the track length 
-    const edm4hep::Vector3d& x1 = twoD_hits[0]->getPosition();
-    const edm4hep::Vector3d& x2 = twoD_hits[ twoD_hits.size()/2 ]->getPosition();
-    const edm4hep::Vector3d& x3 = twoD_hits.back()->getPosition();
+    const edm4hep::Vector3d& x1 = twoD_hits[0].getPosition();
+    const edm4hep::Vector3d& x2 = twoD_hits[ twoD_hits.size()/2 ].getPosition();
+    const edm4hep::Vector3d& x3 = twoD_hits.back().getPosition();
     
     HelixTrack helixTrack( x1, x2, x3, bfield_z, HelixTrack::forwards );
 
     if ( fit_backwards == IMarlinTrack::backward ) {
       pre_fit->location = MarlinTrk::Location::AtLastHit;
-      helixTrack.moveRefPoint(hit_list.back()->getPosition()[0], hit_list.back()->getPosition()[1], hit_list.back()->getPosition()[2]);      
+      helixTrack.moveRefPoint(hit_list.back().getPosition()[0], hit_list.back().getPosition()[1], hit_list.back().getPosition()[2]);      
     } else {
       pre_fit->location = MarlinTrk::Location::AtFirstHit;
-      helixTrack.moveRefPoint(hit_list.front()->getPosition()[0], hit_list.front()->getPosition()[1], hit_list.front()->getPosition()[2]);      
+      helixTrack.moveRefPoint(hit_list.front().getPosition()[0], hit_list.front().getPosition()[1], hit_list.front().getPosition()[2]);      
     }
     
     
@@ -350,7 +350,7 @@ namespace MarlinTrk {
     
   }
   
-  int finaliseLCIOTrack( IMarlinTrack* marlintrk, edm4hep::Track* track, std::vector<edm4hep::TrackerHit*>& hit_list, edm4hep::TrackState* atLastHit, edm4hep::TrackState* atCaloFace){
+  int finaliseLCIOTrack( IMarlinTrack* marlintrk, edm4hep::Track* track, std::vector<edm4hep::ConstTrackerHit>& hit_list, edm4hep::TrackState* atLastHit, edm4hep::TrackState* atCaloFace){
     
     ///////////////////////////////////////////////////////
     // check inputs 
@@ -405,9 +405,9 @@ namespace MarlinTrk {
     // add these to the track, add spacepoints as long as at least on strip hit is used.  
     ////////////////////////////////////////////////////////////////////////////////////////////////////////
     
-    std::vector<std::pair<edm4hep::TrackerHit*, double> > hits_in_fit;
-    std::vector<std::pair<edm4hep::TrackerHit*, double> > outliers;
-    std::vector<edm4hep::TrackerHit*> used_hits;
+    std::vector<std::pair<edm4hep::ConstTrackerHit, double> > hits_in_fit;
+    std::vector<std::pair<edm4hep::ConstTrackerHit, double> > outliers;
+    std::vector<edm4hep::ConstTrackerHit> used_hits;
         
     hits_in_fit.reserve(300);
     outliers.reserve(300);
@@ -423,26 +423,26 @@ namespace MarlinTrk {
     
     for ( unsigned ihit = 0; ihit < hit_list.size(); ++ihit) {
       
-      edm4hep::TrackerHit* trkHit = hit_list[ihit];
+      edm4hep::ConstTrackerHit trkHit = hit_list[ihit];
       
-      if( UTIL::BitSet32( trkHit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ]   ){ //it is a composite spacepoint
+      if( UTIL::BitSet32( trkHit.getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ]   ){ //it is a composite spacepoint
 	//std::cout << "Error: space point is not still valid! pelease wait updating..." <<std::endl;
         //exit(1);
 	// get strip hits 
-        int nRawHit = trkHit->rawHits_size();
+        int nRawHit = trkHit.rawHits_size();
         for( unsigned k=0; k< nRawHit; k++ ){
-	  edm4hep::TrackerHit* rawHit = Navigation::Instance()->GetTrackerHit(trkHit->getRawHits(k));
+	  edm4hep::ConstTrackerHit rawHit = Navigation::Instance()->GetTrackerHit(trkHit.getRawHits(k));
 	  bool is_outlier = false;
 	  // here we loop over outliers as this will be faster than looping over the used hits
           for ( unsigned ohit = 0; ohit < outliers.size(); ++ohit) {
-	    if ( rawHit->id() == outliers[ohit].first->id() ) { 
+	    if ( rawHit.id() == outliers[ohit].first.id() ) { 
               is_outlier = true;                                    
               break; // break out of loop over outliers
             }
           }
           if (is_outlier == false) {
             used_hits.push_back(hit_list[ihit]);
-            track->addToTrackerHits(*used_hits.back());
+            track->addToTrackerHits(used_hits.back());
             break; // break out of loop over rawObjects
           }          
         }
@@ -457,7 +457,7 @@ namespace MarlinTrk {
         }
         if (is_outlier == false) {
           used_hits.push_back(hit_list[ihit]);
-          track->addToTrackerHits(*used_hits.back());
+          track->addToTrackerHits(used_hits.back());
         }          
       }
     }
@@ -475,16 +475,16 @@ namespace MarlinTrk {
     ///////////////////////////////////////////////////////
     
     edm4hep::TrackState* trkStateAtFirstHit = new edm4hep::TrackState() ;
-    edm4hep::TrackerHit* firstHit = hits_in_fit.back().first;
+    edm4hep::ConstTrackerHit firstHit = hits_in_fit.back().first;
 
     ///////////////////////////////////////////////////////
     // last hit
     ///////////////////////////////////////////////////////
     
     edm4hep::TrackState* trkStateAtLastHit = new edm4hep::TrackState() ;
-    edm4hep::TrackerHit* lastHit = hits_in_fit.front().first;
+    edm4hep::ConstTrackerHit lastHit = hits_in_fit.front().first;
           
-    edm4hep::TrackerHit* last_constrained_hit = 0 ;     
+    edm4hep::ConstTrackerHit last_constrained_hit = 0 ;     
     marlintrk->getTrackerHitAtPositiveNDF(last_constrained_hit);
 
     return_error = marlintrk->smooth(lastHit);
@@ -547,7 +547,7 @@ namespace MarlinTrk {
       delete trkStateAtFirstHit;
     }
     
-    double r_first = firstHit->getPosition()[0]*firstHit->getPosition()[0] + firstHit->getPosition()[1]*firstHit->getPosition()[1];
+    double r_first = firstHit.getPosition()[0]*firstHit.getPosition()[0] + firstHit.getPosition()[1]*firstHit.getPosition()[1];
     
     track->setRadiusOfInnermostHit(sqrt(r_first));
     
@@ -559,7 +559,7 @@ namespace MarlinTrk {
       
       //streamlog_out( DEBUG5 ) << "  >>>>>>>>>>> create TrackState AtLastHit : using trkhit " << last_constrained_hit << std::endl ;
       
-      edm4hep::Vector3d last_hit_pos(lastHit->getPosition());
+      edm4hep::Vector3d last_hit_pos(lastHit.getPosition());
       
       return_error = marlintrk->propagate(last_hit_pos, last_constrained_hit, *trkStateAtLastHit, chi2, ndf);
             
@@ -606,7 +606,7 @@ namespace MarlinTrk {
   }
   
   
-  int createTrackStateAtCaloFace( IMarlinTrack* marlintrk, edm4hep::TrackState* trkStateCalo, edm4hep::TrackerHit* trkhit, bool tanL_is_positive ){
+  int createTrackStateAtCaloFace( IMarlinTrack* marlintrk, edm4hep::TrackState* trkStateCalo, edm4hep::ConstTrackerHit trkhit, bool tanL_is_positive ){
     
     //streamlog_out( DEBUG5 ) << "  >>>>>>>>>>> createTrackStateAtCaloFace : using trkhit " << trkhit << " tanL_is_positive = " << tanL_is_positive << std::endl ;
     
@@ -621,7 +621,7 @@ namespace MarlinTrk {
       throw EVENT::Exception( std::string("MarlinTrk::createTrackStateAtCaloFace: TrackImpl == NULL ")  ) ;
     }
     
-    if( trkhit == 0 ){
+    if( !trkhit.isAvailable() ){
       throw EVENT::Exception( std::string("MarlinTrk::createTrackStateAtCaloFace: TrackHit == NULL ")  ) ;
     }
         
@@ -661,7 +661,7 @@ namespace MarlinTrk {
     
   }
   
-  void addHitNumbersToTrack(edm4hep::Track* track, std::vector<edm4hep::TrackerHit*>& hit_list, bool hits_in_fit, UTIL::BitField64& cellID_encoder){
+  void addHitNumbersToTrack(edm4hep::Track* track, std::vector<edm4hep::ConstTrackerHit>& hit_list, bool hits_in_fit, UTIL::BitField64& cellID_encoder){
     
     ///////////////////////////////////////////////////////
     // check inputs 
@@ -679,7 +679,7 @@ namespace MarlinTrk {
     hitNumbers[UTIL::ILDDetID::ETD] = 0;
     
     for(unsigned int j=0; j<hit_list.size(); ++j) {
-      cellID_encoder.setValue(hit_list.at(j)->getCellID()) ;
+      cellID_encoder.setValue(hit_list.at(j).getCellID()) ;
       int detID = cellID_encoder[UTIL::ILDCellID0::subdet];
       ++hitNumbers[detID];
       //std::cout << "debug: " << "Hit from Detector " << detID << std::endl;     
@@ -704,7 +704,7 @@ namespace MarlinTrk {
     //track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::ETD - offset ] = hitNumbers[lcio::ILDDetID::ETD];
   }
   
-  void addHitNumbersToTrack(edm4hep::Track* track, std::vector<std::pair<edm4hep::TrackerHit* , double> >& hit_list, bool hits_in_fit, UTIL::BitField64& cellID_encoder){
+  void addHitNumbersToTrack(edm4hep::Track* track, std::vector<std::pair<edm4hep::ConstTrackerHit , double> >& hit_list, bool hits_in_fit, UTIL::BitField64& cellID_encoder){
     
     ///////////////////////////////////////////////////////
     // check inputs 
@@ -723,7 +723,7 @@ namespace MarlinTrk {
     hitNumbers[lcio::ILDDetID::ETD] = 0;
     
     for(unsigned int j=0; j<hit_list.size(); ++j) {
-      cellID_encoder.setValue(hit_list.at(j).first->getCellID()) ;
+      cellID_encoder.setValue(hit_list.at(j).first.getCellID()) ;
       int detID = cellID_encoder[UTIL::ILDCellID0::subdet];
       ++hitNumbers[detID];
       //std::cout << "debug: Hit from Detector " << detID << std::endl;     
-- 
GitLab