From 0c443cfec75323741eb3991299607bb1235cc402 Mon Sep 17 00:00:00 2001
From: John Derek Chapman <chapman@hep.phy.cam.ac.uk>
Date: Thu, 17 Jan 2019 13:38:45 +0000
Subject: [PATCH] Merge branch 'NSWMMHit0701' into '21.3'

NSW MMSimHit (ATLASSIM-3755)

See merge request atlas/athena!20259
---
 .../MuonSimEventAthenaPool/CMakeLists.txt     |   2 +-
 .../src/MMSimHitCollectionCnv.cxx             |  56 ++++++++++
 .../src/MMSimHitCollectionCnv.h               |  40 +++++++
 .../MuonCnv/MuonSimEventTPCnv/CMakeLists.txt  |  12 +++
 .../MMSimHitCollectionCnv_p1.h                |  29 +++++
 .../MMSimHitCollectionCnv_p2.h                |  29 +++++
 .../MuonSimEventTPCnv/MMSimHitCollection_p1.h |  29 +++++
 .../MuonSimEventTPCnv/MMSimHitCollection_p2.h |  29 +++++
 .../MuonSimEventTPCnv/MuonSimEventTPCnvDict.h |   4 +-
 .../MuonSimEventTPCnv/selection.xml           |   2 +
 .../MuonSimEventTPCnv/cmt/requirements        |  54 ++++++++++
 .../share/MMSimHitCollectionCnv_p1_test.ref   |   8 ++
 .../share/MMSimHitCollectionCnv_p2_test.ref   |   8 ++
 .../share/sTGCSimHitCollectionCnv_p1_test.ref |   6 ++
 .../share/sTGCSimHitCollectionCnv_p2_test.ref |   6 ++
 .../src/MMSimHitCollectionCnv_p1.cxx          |  85 +++++++++++++++
 .../src/MMSimHitCollectionCnv_p2.cxx          |  85 +++++++++++++++
 .../test/MMSimHitCollectionCnv_p1_test.cxx    | 102 ++++++++++++++++++
 .../test/MMSimHitCollectionCnv_p2_test.cxx    | 101 +++++++++++++++++
 .../src/MicromegasSensitiveDetector.cxx       |  11 +-
 .../src/MicromegasSensitiveDetector.h         |   4 +-
 .../MuonSimEvent/MuonSimEvent/MMSimHit.h      |  89 +++++++++++++++
 .../MuonSimEvent/MMSimHitCollection.h         |  28 +++++
 .../MuonSimEvent/MuonSimEvent/selection.xml   |   8 ++
 .../MuonSimEvent/src/MMSimHit.cxx             |  76 +++++++++++++
 .../G4Atlas/G4AtlasApps/python/SimSkeleton.py |   3 +-
 .../share/G4Atlas.flat.configuration.py       |   4 +-
 .../share/Tile2000_2003.flat.configuration.py |   4 +-
 .../ISF/ISF_Example/python/ISF_Output.py      |   5 +-
 29 files changed, 907 insertions(+), 12 deletions(-)
 create mode 100644 MuonSpectrometer/MuonCnv/MuonSimEventAthenaPool/src/MMSimHitCollectionCnv.cxx
 create mode 100644 MuonSpectrometer/MuonCnv/MuonSimEventAthenaPool/src/MMSimHitCollectionCnv.h
 create mode 100644 MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MMSimHitCollectionCnv_p1.h
 create mode 100644 MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MMSimHitCollectionCnv_p2.h
 create mode 100644 MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MMSimHitCollection_p1.h
 create mode 100644 MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MMSimHitCollection_p2.h
 create mode 100644 MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/cmt/requirements
 create mode 100644 MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/share/MMSimHitCollectionCnv_p1_test.ref
 create mode 100644 MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/share/MMSimHitCollectionCnv_p2_test.ref
 create mode 100644 MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/src/MMSimHitCollectionCnv_p1.cxx
 create mode 100644 MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/src/MMSimHitCollectionCnv_p2.cxx
 create mode 100644 MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/test/MMSimHitCollectionCnv_p1_test.cxx
 create mode 100644 MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/test/MMSimHitCollectionCnv_p2_test.cxx
 create mode 100644 MuonSpectrometer/MuonSimEvent/MuonSimEvent/MMSimHit.h
 create mode 100644 MuonSpectrometer/MuonSimEvent/MuonSimEvent/MMSimHitCollection.h
 create mode 100644 MuonSpectrometer/MuonSimEvent/src/MMSimHit.cxx

diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventAthenaPool/CMakeLists.txt b/MuonSpectrometer/MuonCnv/MuonSimEventAthenaPool/CMakeLists.txt
index 06bed786bed5..b79622617bc6 100644
--- a/MuonSpectrometer/MuonCnv/MuonSimEventAthenaPool/CMakeLists.txt
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventAthenaPool/CMakeLists.txt
@@ -21,7 +21,7 @@ atlas_depends_on_subdirs( PUBLIC
 # Component(s) in the package:
 atlas_add_poolcnv_library( MuonSimEventAthenaPoolPoolCnv
                            src/*.cxx
-                           FILES MuonSimEvent/CSCSimHitCollection.h MuonSimEvent/MDTSimHitCollection.h MuonSimEvent/RPCSimHitCollection.h MuonSimEvent/TGCSimHitCollection.h MuonSimEvent/GenericMuonSimHitCollection.h MuonSimEvent/sTGCSimHitCollection.h
+                           FILES MuonSimEvent/CSCSimHitCollection.h MuonSimEvent/MDTSimHitCollection.h MuonSimEvent/RPCSimHitCollection.h MuonSimEvent/TGCSimHitCollection.h MuonSimEvent/GenericMuonSimHitCollection.h MuonSimEvent/sTGCSimHitCollection.h MuonSimEvent/MMSimHitCollection.h
                            LINK_LIBRARIES AthenaPoolUtilities AtlasSealCLHEP StoreGateLib SGtests AthenaPoolCnvSvcLib GaudiKernel MuonSimEventTPCnv MuonSimEvent HitManagement )
 
 # Install files from the package:
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventAthenaPool/src/MMSimHitCollectionCnv.cxx b/MuonSpectrometer/MuonCnv/MuonSimEventAthenaPool/src/MMSimHitCollectionCnv.cxx
new file mode 100644
index 000000000000..e6f08f0292a2
--- /dev/null
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventAthenaPool/src/MMSimHitCollectionCnv.cxx
@@ -0,0 +1,56 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+*/
+
+#include "MMSimHitCollectionCnv.h"
+
+// Gaudi
+#include "GaudiKernel/CnvFactory.h"
+#include "GaudiKernel/StatusCode.h"
+#include "GaudiKernel/MsgStream.h"
+
+// Athena
+#include "StoreGate/StoreGateSvc.h"
+
+#include "MuonSimEvent/MMSimHitCollection.h"
+#include "MuonSimEventTPCnv/MMSimHitCollection_p1.h"
+#include "HitManagement/AthenaHitsVector.h" //for back-compatibility
+
+
+MMSimHitCollectionCnv::MMSimHitCollectionCnv(ISvcLocator* svcloc) :
+    MMSimHitCollectionCnvBase(svcloc)
+{
+}
+
+MMSimHitCollectionCnv::~MMSimHitCollectionCnv() {
+}
+
+MMSimHitCollection_PERS*    MMSimHitCollectionCnv::createPersistent (MMSimHitCollection* transCont) {
+    MsgStream log(msgSvc(), "MMSimHitCollectionCnv" );
+    ATH_MSG_DEBUG("createPersistent(): main converter");
+    MMSimHitCollection_PERS *pixdc_p= m_TPConverter_p2.createPersistent( transCont, log );
+    return pixdc_p;
+}
+
+MMSimHitCollection* MMSimHitCollectionCnv::createTransient() {
+    MsgStream log(msgSvc(), "MMSimHitCollectionCnv" );
+    static pool::Guid   p1_guid("ac0b677c-fe08-11e8-b174-02163e018187");
+    static pool::Guid   p2_guid("b9bdd436-fe08-11e8-a40f-02163e018187");
+    ATH_MSG_DEBUG("createTransient(): main converter");
+    MMSimHitCollection* p_collection(0);
+    if( compareClassGuid(p2_guid) ) {
+      ATH_MSG_DEBUG("createTransient(): T/P version 2 detected");
+      std::unique_ptr< Muon::MMSimHitCollection_p2 >   col_vect( this->poolReadObject< Muon::MMSimHitCollection_p2 >() );
+      p_collection = m_TPConverter_p2.createTransient( col_vect.get(), log );
+    } else if( compareClassGuid(p1_guid) ) {
+      ATH_MSG_DEBUG("createTransient(): T/P version 1 detected");
+      std::unique_ptr< Muon::MMSimHitCollection_p1 >   col_vect( this->poolReadObject< Muon::MMSimHitCollection_p1 >() );
+      p_collection = m_TPConverter_p1.createTransient( col_vect.get(), log );
+    }
+  //----------------------------------------------------------------
+    else {
+        throw std::runtime_error("Unsupported persistent version of MMSimHitCollection");
+
+    }
+    return p_collection;
+}
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventAthenaPool/src/MMSimHitCollectionCnv.h b/MuonSpectrometer/MuonCnv/MuonSimEventAthenaPool/src/MMSimHitCollectionCnv.h
new file mode 100644
index 000000000000..8b70b55ab10b
--- /dev/null
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventAthenaPool/src/MMSimHitCollectionCnv.h
@@ -0,0 +1,40 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef MUONSIMEVENTATHENAPOOL_MMSIMHITCOLLECTIONCNV_H
+#define MUONSIMEVENTATHENAPOOL_MMSIMHITCOLLECTIONCNV_H
+
+#include "AthenaPoolCnvSvc/T_AthenaPoolCustomCnv.h"
+#include "MuonSimEvent/MMSimHitCollection.h"
+
+#include "MuonSimEventTPCnv/MMSimHitCollectionCnv_p1.h"
+#include "MuonSimEventTPCnv/MMSimHitCollectionCnv_p2.h"
+
+// the latest persistent representation type of DataCollection:
+typedef  Muon::MMSimHitCollection_p2  MMSimHitCollection_PERS;
+typedef  T_AthenaPoolCustomCnv<MMSimHitCollection, MMSimHitCollection_PERS >  MMSimHitCollectionCnvBase;
+
+/**
+ ** Create derived converter to customize the saving of identifiable
+ ** container
+ **/
+class MMSimHitCollectionCnv : 
+    public MMSimHitCollectionCnvBase 
+{
+    
+    friend class CnvFactory<MMSimHitCollectionCnv>;
+    
+public:
+    MMSimHitCollectionCnv(ISvcLocator* svcloc);
+    virtual ~MMSimHitCollectionCnv();
+    
+    virtual MMSimHitCollection_PERS*   createPersistent (MMSimHitCollection* transCont);
+    virtual MMSimHitCollection*        createTransient ();
+        
+private:
+    MMSimHitCollectionCnv_p1    m_TPConverter_p1;
+    MMSimHitCollectionCnv_p2    m_TPConverter_p2;
+};
+
+#endif
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/CMakeLists.txt b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/CMakeLists.txt
index e6bad227031f..b261fa84cb64 100644
--- a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/CMakeLists.txt
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/CMakeLists.txt
@@ -141,3 +141,15 @@ atlas_add_test( sTGCSimHitCollectionCnv_p2_test
                 test/sTGCSimHitCollectionCnv_p2_test.cxx
                 INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIRS}
                 LINK_LIBRARIES ${ROOT_LIBRARIES} ${EIGEN_LIBRARIES} AthenaPoolCnvSvcLib GaudiKernel GeneratorObjectsTPCnv MuonSimEvent TestTools StoreGateLib SGtests GeoPrimitives MuonSimEventTPCnv )
+
+atlas_add_test( MMSimHitCollectionCnv_p1_test
+                SOURCES
+                test/MMSimHitCollectionCnv_p1_test.cxx
+                INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIRS}
+                LINK_LIBRARIES ${ROOT_LIBRARIES} ${EIGEN_LIBRARIES} AthenaPoolCnvSvcLib GaudiKernel GeneratorObjectsTPCnv MuonSimEvent TestTools StoreGateLib SGtests GeoPrimitives MuonSimEventTPCnv )
+
+atlas_add_test( MMSimHitCollectionCnv_p2_test
+                SOURCES
+                test/MMSimHitCollectionCnv_p2_test.cxx
+                INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIRS}
+                LINK_LIBRARIES ${ROOT_LIBRARIES} ${EIGEN_LIBRARIES} AthenaPoolCnvSvcLib GaudiKernel GeneratorObjectsTPCnv MuonSimEvent TestTools StoreGateLib SGtests GeoPrimitives MuonSimEventTPCnv )
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MMSimHitCollectionCnv_p1.h b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MMSimHitCollectionCnv_p1.h
new file mode 100644
index 000000000000..e431265e5e57
--- /dev/null
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MMSimHitCollectionCnv_p1.h
@@ -0,0 +1,29 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef MMSimHitCOLLECTIONCNV_P1_H
+#define MMSimHitCOLLECTIONCNV_P1_H
+
+#include "AthenaPoolCnvSvc/T_AthenaPoolTPConverter.h"
+#include "MuonSimEvent/MMSimHitCollection.h"
+#include "MMSimHitCollection_p1.h"
+
+class MMSimHitCollectionCnv_p1 : public T_AthenaPoolTPCnvBase<MMSimHitCollection, Muon::MMSimHitCollection_p1>
+{
+ public:
+  
+  MMSimHitCollectionCnv_p1()  {};
+  
+  virtual MMSimHitCollection* createTransient(const Muon::MMSimHitCollection_p1* persObj, MsgStream &log);
+  virtual void  persToTrans(const Muon::MMSimHitCollection_p1* persCont,
+                MMSimHitCollection* transCont,
+                MsgStream &log) ;
+  virtual void  transToPers(const MMSimHitCollection* transCont,
+                Muon::MMSimHitCollection_p1* persCont,
+                MsgStream &log) ;
+
+};
+
+#endif
+
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MMSimHitCollectionCnv_p2.h b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MMSimHitCollectionCnv_p2.h
new file mode 100644
index 000000000000..cc044c3c98c6
--- /dev/null
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MMSimHitCollectionCnv_p2.h
@@ -0,0 +1,29 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef MMSimHitCOLLECTIONCNV_P2_H
+#define MMSimHitCOLLECTIONCNV_P2_H
+
+#include "AthenaPoolCnvSvc/T_AthenaPoolTPConverter.h"
+#include "MuonSimEvent/MMSimHitCollection.h"
+#include "MMSimHitCollection_p2.h"
+
+class MMSimHitCollectionCnv_p2 : public T_AthenaPoolTPCnvBase<MMSimHitCollection, Muon::MMSimHitCollection_p2>
+{
+ public:
+  
+  MMSimHitCollectionCnv_p2()  {};
+  
+  virtual MMSimHitCollection* createTransient(const Muon::MMSimHitCollection_p2* persObj, MsgStream &log);
+  virtual void  persToTrans(const Muon::MMSimHitCollection_p2* persCont,
+                MMSimHitCollection* transCont,
+                MsgStream &log) ;
+  virtual void  transToPers(const MMSimHitCollection* transCont,
+                Muon::MMSimHitCollection_p2* persCont,
+                MsgStream &log) ;
+
+};
+
+#endif
+
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MMSimHitCollection_p1.h b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MMSimHitCollection_p1.h
new file mode 100644
index 000000000000..80eae8cd15a7
--- /dev/null
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MMSimHitCollection_p1.h
@@ -0,0 +1,29 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef MMSIMHITCOLLECTION_P1_H
+#define MMSIMHITCOLLECTION_P1_H
+
+#include <vector>
+#include "GeneratorObjectsTPCnv/HepMcParticleLink_p1.h"
+
+namespace Muon {
+  class MMSimHitCollection_p1   
+  {
+  public:
+    std::vector<int>      m_MMId;
+    std::vector<float>    m_globalTime;
+    //postStep
+    std::vector<float>    m_stX, m_stY, m_stZ;    //!< Represents m_globalPosition in transient class
+    std::vector<float>    m_kineticEnergy;
+    std::vector<int>      m_particleEncoding;
+    std::vector<float>    m_ptX, m_ptY, m_ptZ;
+    std::vector<float>    m_depositEnergy;
+
+    std::vector<HepMcParticleLink_p1>  m_partLink;
+  };
+}
+
+#endif
+
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MMSimHitCollection_p2.h b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MMSimHitCollection_p2.h
new file mode 100644
index 000000000000..ad749d96510c
--- /dev/null
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MMSimHitCollection_p2.h
@@ -0,0 +1,29 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef MMSIMHITCOLLECTION_P2_H
+#define MMSIMHITCOLLECTION_P2_H
+
+#include <vector>
+#include "GeneratorObjectsTPCnv/HepMcParticleLink_p2.h"
+
+namespace Muon {
+  class MMSimHitCollection_p2   
+  {
+  public:
+    std::vector<int>      m_MMId;
+    std::vector<float>    m_globalTime;
+    //postStep
+    std::vector<float>    m_stX, m_stY, m_stZ;    //!< Represents m_globalPosition in transient class
+    std::vector<float>    m_kineticEnergy;
+    std::vector<int>      m_particleEncoding;
+    std::vector<float>    m_ptX, m_ptY, m_ptZ;
+    std::vector<float>    m_depositEnergy;
+
+    std::vector<HepMcParticleLink_p2>  m_partLink;
+  };
+}
+
+#endif
+
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MuonSimEventTPCnvDict.h b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MuonSimEventTPCnvDict.h
index 5d9bf5a5b8a7..125c985204c5 100644
--- a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MuonSimEventTPCnvDict.h
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/MuonSimEventTPCnvDict.h
@@ -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
 */
 
 #ifndef MUONSIMEVENTTPCNV_MUONSIMEVENTTPCNVDICT_H
@@ -28,5 +28,7 @@
 #include "MuonSimEventTPCnv/GenericMuonSimHitCollection_p2.h"
 #include "MuonSimEventTPCnv/sTGCSimHitCollection_p1.h"
 #include "MuonSimEventTPCnv/sTGCSimHitCollection_p2.h"
+#include "MuonSimEventTPCnv/MMSimHitCollection_p1.h"
+#include "MuonSimEventTPCnv/MMSimHitCollection_p2.h"
 
 #endif // MUONSIMEVENTTPCNV_MUONSIMEVENTTPCNVDICT_H
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/selection.xml b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/selection.xml
index 7f677273108c..1d1a467c86bf 100644
--- a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/selection.xml
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/MuonSimEventTPCnv/selection.xml
@@ -20,5 +20,7 @@
     <class name="Muon::GenericMuonSimHitCollection_p2" id="3760C0D8-C7EA-42C7-925A-E841196F2138"/>
     <class name="Muon::sTGCSimHitCollection_p1" id="f8b975d2-8130-11e8-abf4-4b4a6a2b6ee5"/> 
     <class name="Muon::sTGCSimHitCollection_p2" id="b9521cc6-6e3b-11e8-adbb-02163e01bddd"/> 
+    <class name="Muon::MMSimHitCollection_p1" id="ac0b677c-fe08-11e8-b174-02163e018187"/>
+    <class name="Muon::MMSimHitCollection_p2" id="b9bdd436-fe08-11e8-a40f-02163e018187"/>
     
 </lcgdict>
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/cmt/requirements b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/cmt/requirements
new file mode 100644
index 000000000000..19fd3b3bf74d
--- /dev/null
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/cmt/requirements
@@ -0,0 +1,54 @@
+package MuonSimEventTPCnv
+
+author  Edward Moyse <edward.moyse@cern.ch>
+
+public
+
+use  AtlasPolicy                AtlasPolicy-*                   
+use  AthenaPoolCnvSvc           AthenaPoolCnvSvc-*              Database/AthenaPOOL
+use  GaudiInterface             GaudiInterface-*                External
+use  GeneratorObjectsTPCnv      GeneratorObjectsTPCnv-*         Generators
+use  MuonSimEvent               MuonSimEvent-*                  MuonSpectrometer
+
+private
+use  GeoPrimitives              GeoPrimitives-*                 DetectorDescription
+use  StoreGate                  StoreGate-*                     Control
+end_private
+
+public
+#apply_pattern tpcnv_library
+library MuonSimEventTPCnv  *.cxx
+apply_pattern installed_library
+
+# The following use is to get the lcgdict pattern.
+# This is "hidden" behind "private" and "no_auto_imports" to keep 
+# clients of EventInfo from seeing excess dependencies
+private
+use AtlasReflex        AtlasReflex-*        External -no_auto_imports
+
+# Pattern to build the dict lib. User should create a single header
+# file: <package>Dict.h which includes all other .h files. See EventInfoDict
+apply_pattern lcgdict dict=MuonSimEventTPCnv  selectionfile=selection.xml headerfiles="../MuonSimEventTPCnv/MuonSimEventTPCnvDict.h"
+apply_pattern lcgdict dict=OLD_MuonSimEventTPCnv  selectionfile=OLD_selection.xml headerfiles="../MuonSimEventTPCnv/OLD_MuonSimEventTPCnvDict.h"
+
+#private
+# macro cppdebugflags '$(cppdebugflags_s)'
+# macro_remove componentshr_linkopts "-Wl,-s"
+
+
+private
+use TestTools            TestTools-*                AtlasTest
+
+apply_pattern UnitTest_run unit_test=CSCSimHitCollectionCnv_p1
+apply_pattern UnitTest_run unit_test=CSCSimHitCollectionCnv_p2
+apply_pattern UnitTest_run unit_test=GenericMuonSimHitCollectionCnv_p1
+apply_pattern UnitTest_run unit_test=MDTSimHitCollectionCnv_p1
+apply_pattern UnitTest_run unit_test=MDTSimHitCollectionCnv_p2
+apply_pattern UnitTest_run unit_test=RPCSimHitCollectionCnv_p1
+apply_pattern UnitTest_run unit_test=RPCSimHitCollectionCnv_p2
+apply_pattern UnitTest_run unit_test=TGCSimHitCollectionCnv_p1
+apply_pattern UnitTest_run unit_test=TGCSimHitCollectionCnv_p2
+apply_pattern UnitTest_run unit_test=TGCSimHitCollectionCnv_p3
+apply_pattern UnitTest_run unit_test=sTGCSimHitCollectionCnv_p1
+apply_pattern UnitTest_run unit_test=MMSimHitCollectionCnv_p1
+
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/share/MMSimHitCollectionCnv_p1_test.ref b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/share/MMSimHitCollectionCnv_p1_test.ref
new file mode 100644
index 000000000000..8633d8ace9b4
--- /dev/null
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/share/MMSimHitCollectionCnv_p1_test.ref
@@ -0,0 +1,8 @@
+ApplicationMgr       INFO Application Manager Configured successfully
+EventLoopMgr      WARNING Unable to locate service "EventSelector" 
+EventLoopMgr      WARNING No events will be processed from external input.
+HistogramPersis...WARNING Histograms saving not required.
+ApplicationMgr       INFO Application Manager Initialized successfully
+ApplicationMgr Ready
+test1
+HepMcParticleLink    INFO find_hostkey: Using TruthEvent as McEventCollection key for this job 
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/share/MMSimHitCollectionCnv_p2_test.ref b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/share/MMSimHitCollectionCnv_p2_test.ref
new file mode 100644
index 000000000000..8633d8ace9b4
--- /dev/null
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/share/MMSimHitCollectionCnv_p2_test.ref
@@ -0,0 +1,8 @@
+ApplicationMgr       INFO Application Manager Configured successfully
+EventLoopMgr      WARNING Unable to locate service "EventSelector" 
+EventLoopMgr      WARNING No events will be processed from external input.
+HistogramPersis...WARNING Histograms saving not required.
+ApplicationMgr       INFO Application Manager Initialized successfully
+ApplicationMgr Ready
+test1
+HepMcParticleLink    INFO find_hostkey: Using TruthEvent as McEventCollection key for this job 
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/share/sTGCSimHitCollectionCnv_p1_test.ref b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/share/sTGCSimHitCollectionCnv_p1_test.ref
index f00f0d56df77..6b114ba90ace 100644
--- a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/share/sTGCSimHitCollectionCnv_p1_test.ref
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/share/sTGCSimHitCollectionCnv_p1_test.ref
@@ -1,14 +1,20 @@
+<<<<<<< HEAD
 ApplicationMgr    SUCCESS 
 ====================================================================================================================================
                                                    Welcome to ApplicationMgr (GaudiCoreSvc v27r1p99)
                                           running on karma on Sat Oct  6 12:13:52 2018
 ====================================================================================================================================
+=======
+>>>>>>> 1c5e36d24c... Merge branch 'NSWMMHit0701' into '21.3'
 ApplicationMgr       INFO Application Manager Configured successfully
 EventLoopMgr      WARNING Unable to locate service "EventSelector" 
 EventLoopMgr      WARNING No events will be processed from external input.
 HistogramPersis...WARNING Histograms saving not required.
 ApplicationMgr       INFO Application Manager Initialized successfully
 ApplicationMgr Ready
+<<<<<<< HEAD
 ClassIDSvc           INFO  getRegistryEntries: read 2754 CLIDRegistry entries for module ALL
+=======
+>>>>>>> 1c5e36d24c... Merge branch 'NSWMMHit0701' into '21.3'
 test1
 HepMcParticleLink    INFO find_hostkey: Using TruthEvent as McEventCollection key for this job 
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/share/sTGCSimHitCollectionCnv_p2_test.ref b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/share/sTGCSimHitCollectionCnv_p2_test.ref
index 8dae6c25e691..c740456fe190 100644
--- a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/share/sTGCSimHitCollectionCnv_p2_test.ref
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/share/sTGCSimHitCollectionCnv_p2_test.ref
@@ -1,14 +1,20 @@
+<<<<<<< HEAD
 ApplicationMgr    SUCCESS 
 ====================================================================================================================================
                                                    Welcome to ApplicationMgr (GaudiCoreSvc v27r1p99)
                                           running on karma on Sat Oct  6 12:12:27 2018
 ====================================================================================================================================
+=======
+>>>>>>> 1c5e36d24c... Merge branch 'NSWMMHit0701' into '21.3'
 ApplicationMgr       INFO Application Manager Configured successfully
 EventLoopMgr      WARNING Unable to locate service "EventSelector" 
 EventLoopMgr      WARNING No events will be processed from external input.
 HistogramPersis...WARNING Histograms saving not required.
 ApplicationMgr       INFO Application Manager Initialized successfully
 ApplicationMgr Ready
+<<<<<<< HEAD
 ClassIDSvc           INFO  getRegistryEntries: read 2754 CLIDRegistry entries for module ALL
+=======
+>>>>>>> 1c5e36d24c... Merge branch 'NSWMMHit0701' into '21.3'
 test1
 HepMcParticleLink    INFO find_hostkey: Using TruthEvent as McEventCollection key for this job 
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/src/MMSimHitCollectionCnv_p1.cxx b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/src/MMSimHitCollectionCnv_p1.cxx
new file mode 100644
index 000000000000..f6fb20083c1a
--- /dev/null
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/src/MMSimHitCollectionCnv_p1.cxx
@@ -0,0 +1,85 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+*/
+
+#include "MuonSimEvent/MMSimHit.h"
+#include "MuonSimEventTPCnv/MMSimHitCollectionCnv_p1.h"
+#include "MuonSimEventTPCnv/MMSimHitCollection_p1.h"
+#include "GeneratorObjectsTPCnv/HepMcParticleLinkCnv_p1.h"
+
+//#include <cmath>
+#include "GeoPrimitives/GeoPrimitives.h"
+
+// Gaudi
+#include "GaudiKernel/MsgStream.h"
+// Athena
+#include "StoreGate/StoreGateSvc.h"
+
+void MMSimHitCollectionCnv_p1::transToPers(const MMSimHitCollection* transCont, Muon::MMSimHitCollection_p1* persCont, MsgStream &log)
+{
+  // for reasons of efficiency, set size before hand
+  unsigned int size=transCont->size();
+  persCont->m_MMId.reserve(size);
+  persCont->m_globalTime.reserve(size);
+  // postStep Global
+  persCont->m_stX.reserve(size);
+  persCont->m_stY.reserve(size);
+  persCont->m_stZ.reserve(size);
+  persCont->m_kineticEnergy.reserve(size);
+  persCont->m_particleEncoding.reserve(size);
+  persCont->m_ptX.reserve(size);
+  persCont->m_ptY.reserve(size);
+  persCont->m_ptZ.reserve(size);
+  persCont->m_depositEnergy.reserve(size);
+  persCont->m_partLink.reserve(size);
+
+  // make convertor to handle HepMcParticleLinks
+  HepMcParticleLinkCnv_p1 hepMcPLCnv;
+  HepMcParticleLink_p1 persLink; // will use this as a temp object inside the loop
+
+  // loop through container, filling pers object  
+  MMSimHitCollection::const_iterator it = transCont->begin(), itEnd = transCont->end();
+  for (; it != itEnd; ++it) {
+    persCont->m_MMId.push_back(it->MMId());
+    persCont->m_globalTime.push_back(it->globalTime());
+    // postStep Global
+    persCont->m_stX.push_back(it->globalPosition().x());
+    persCont->m_stY.push_back(it->globalPosition().y());
+    persCont->m_stZ.push_back(it->globalPosition().z());
+    persCont->m_kineticEnergy.push_back(it->kineticEnergy());
+    persCont->m_particleEncoding.push_back(it->particleEncoding()); 
+    persCont->m_ptX.push_back(it->globalDirection().x());
+    persCont->m_ptY.push_back(it->globalDirection().y());
+    persCont->m_ptZ.push_back(it->globalDirection().z());
+    persCont->m_depositEnergy.push_back(it->depositEnergy());
+		
+    hepMcPLCnv.transToPers(&it->particleLink(),&persLink, log);   
+    persCont->m_partLink.push_back(persLink);
+
+  }
+}
+
+
+MMSimHitCollection* MMSimHitCollectionCnv_p1::createTransient(const Muon::MMSimHitCollection_p1* persObj, MsgStream &log) {
+  std::unique_ptr<MMSimHitCollection> trans(new MMSimHitCollection("DefaultCollectionName",persObj->m_globalTime.size()));
+  persToTrans(persObj, trans.get(), log);
+  return(trans.release());
+}
+
+
+void MMSimHitCollectionCnv_p1::persToTrans(const Muon::MMSimHitCollection_p1* persCont, MMSimHitCollection* transCont, MsgStream &log) 
+{
+  HepMcParticleLinkCnv_p1 hepMcPLCnv;
+    
+  for (unsigned int i = 0; i < persCont->m_MMId.size(); i++) { 
+    //post
+    Amg::Vector3D position(persCont->m_stX[i], persCont->m_stY[i], persCont->m_stZ[i]);
+    Amg::Vector3D direction(persCont->m_ptX[i], persCont->m_ptY[i], persCont->m_ptZ[i]); 
+
+    HepMcParticleLink link;
+    hepMcPLCnv.persToTrans(&persCont->m_partLink[i],&link, log);   
+
+    transCont->Emplace(persCont->m_MMId[i], persCont->m_globalTime[i], position, persCont->m_particleEncoding[i], persCont->m_kineticEnergy[i], direction, persCont->m_depositEnergy[i], link);
+  }
+}
+
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/src/MMSimHitCollectionCnv_p2.cxx b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/src/MMSimHitCollectionCnv_p2.cxx
new file mode 100644
index 000000000000..879983c96092
--- /dev/null
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/src/MMSimHitCollectionCnv_p2.cxx
@@ -0,0 +1,85 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+*/
+
+#include "MuonSimEvent/MMSimHit.h"
+#include "MuonSimEventTPCnv/MMSimHitCollectionCnv_p2.h"
+#include "MuonSimEventTPCnv/MMSimHitCollection_p2.h"
+#include "GeneratorObjectsTPCnv/HepMcParticleLinkCnv_p2.h"
+
+//#include <cmath>
+#include "GeoPrimitives/GeoPrimitives.h"
+
+// Gaudi
+#include "GaudiKernel/MsgStream.h"
+// Athena
+#include "StoreGate/StoreGateSvc.h"
+
+void MMSimHitCollectionCnv_p2::transToPers(const MMSimHitCollection* transCont, Muon::MMSimHitCollection_p2* persCont, MsgStream &log)
+{
+  // for reasons of efficiency, set size before hand
+  unsigned int size=transCont->size();
+  persCont->m_MMId.reserve(size);
+  persCont->m_globalTime.reserve(size);
+  // postStep Global
+  persCont->m_stX.reserve(size);
+  persCont->m_stY.reserve(size);
+  persCont->m_stZ.reserve(size);
+  persCont->m_kineticEnergy.reserve(size);
+  persCont->m_particleEncoding.reserve(size);
+  persCont->m_ptX.reserve(size);
+  persCont->m_ptY.reserve(size);
+  persCont->m_ptZ.reserve(size);
+  persCont->m_depositEnergy.reserve(size);
+  persCont->m_partLink.reserve(size);
+
+  // make convertor to handle HepMcParticleLinks
+  HepMcParticleLinkCnv_p2 hepMcPLCnv;
+  HepMcParticleLink_p2 persLink; // will use this as a temp object inside the loop
+
+  // loop through container, filling pers object
+  MMSimHitCollection::const_iterator it = transCont->begin(), itEnd = transCont->end();
+  for (; it != itEnd; ++it) {
+    persCont->m_MMId.push_back(it->MMId());
+    persCont->m_globalTime.push_back(it->globalTime());
+    // postStep Global
+    persCont->m_stX.push_back(it->globalPosition().x());
+    persCont->m_stY.push_back(it->globalPosition().y());
+    persCont->m_stZ.push_back(it->globalPosition().z());
+    persCont->m_kineticEnergy.push_back(it->kineticEnergy());
+    persCont->m_particleEncoding.push_back(it->particleEncoding());
+    persCont->m_ptX.push_back(it->globalDirection().x());
+    persCont->m_ptY.push_back(it->globalDirection().y());
+    persCont->m_ptZ.push_back(it->globalDirection().z());
+    persCont->m_depositEnergy.push_back(it->depositEnergy());
+
+    hepMcPLCnv.transToPers(&it->particleLink(),&persLink, log);
+    persCont->m_partLink.push_back(persLink);
+
+  }
+}
+
+
+MMSimHitCollection* MMSimHitCollectionCnv_p2::createTransient(const Muon::MMSimHitCollection_p2* persObj, MsgStream &log) {
+  std::unique_ptr<MMSimHitCollection> trans(new MMSimHitCollection("DefaultCollectionName",persObj->m_globalTime.size()));
+  persToTrans(persObj, trans.get(), log);
+  return(trans.release());
+}
+
+
+void MMSimHitCollectionCnv_p2::persToTrans(const Muon::MMSimHitCollection_p2* persCont, MMSimHitCollection* transCont, MsgStream &log)
+{
+  HepMcParticleLinkCnv_p2 hepMcPLCnv;
+
+  for (unsigned int i = 0; i < persCont->m_MMId.size(); i++) {
+    //post
+    Amg::Vector3D position(persCont->m_stX[i], persCont->m_stY[i], persCont->m_stZ[i]);
+    Amg::Vector3D direction(persCont->m_ptX[i], persCont->m_ptY[i], persCont->m_ptZ[i]);
+
+    HepMcParticleLink link;
+    hepMcPLCnv.persToTrans(&persCont->m_partLink[i],&link, log);
+
+    transCont->Emplace(persCont->m_MMId[i], persCont->m_globalTime[i], position, persCont->m_particleEncoding[i], persCont->m_kineticEnergy[i], direction, persCont->m_depositEnergy[i], link);
+  }
+}
+
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/test/MMSimHitCollectionCnv_p1_test.cxx b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/test/MMSimHitCollectionCnv_p1_test.cxx
new file mode 100644
index 000000000000..66db56d1712e
--- /dev/null
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/test/MMSimHitCollectionCnv_p1_test.cxx
@@ -0,0 +1,102 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+*/
+
+#undef NDEBUG
+#include "MuonSimEventTPCnv/MMSimHitCollectionCnv_p1.h"
+#include "TestTools/leakcheck.h"
+#include <cassert>
+#include <iostream>
+
+#include "GeneratorObjectsTPCnv/initMcEventCollection.h"
+#include "HepMC/GenEvent.h"
+#include "HepMC/GenParticle.h"
+
+
+void compare (const HepMcParticleLink& p1,
+              const HepMcParticleLink& p2)
+{
+  assert ( p1.isValid() == p2.isValid() );
+  assert ( p1.barcode() == p2.barcode() );
+  assert ( p1.eventIndex() == p2.eventIndex() );
+  assert ( p1.getEventCollectionAsChar() == p2.getEventCollectionAsChar() );
+  assert ( p1.cptr() == p2.cptr() );
+  assert ( p1 == p2 );
+}
+
+void compare (const MMSimHit& p1,
+              const MMSimHit& p2)
+{
+  assert (p1.MMId() == p2.MMId());
+  assert (p1.globalTime() == p2.globalTime());
+  assert (p1.globalPosition() == p2.globalPosition());
+  assert (p1.particleEncoding() == p2.particleEncoding());
+  assert (p1.kineticEnergy() == p2.kineticEnergy());
+  assert (p1.globalDirection() == p2.globalDirection());
+  assert (p1.depositEnergy() == p2.depositEnergy());
+  compare(p1.particleLink(), p2.particleLink());
+  assert (p1.particleLink() == p2.particleLink());
+}
+
+
+void compare (const MMSimHitCollection& p1,
+              const MMSimHitCollection& p2)
+{
+  //assert (p1.Name() == p2.Name());
+  assert (p1.size() == p2.size());
+  for (size_t i=0; i < p1.size(); i++)
+    compare (p1[i], p2[i]);
+}
+
+
+void testit (const MMSimHitCollection& trans1)
+{
+  MsgStream log (0, "test");
+  MMSimHitCollectionCnv_p1 cnv;
+  Muon::MMSimHitCollection_p1 pers;
+  cnv.transToPers (&trans1, &pers, log);
+  MMSimHitCollection trans2;
+  cnv.persToTrans (&pers, &trans2, log);
+
+  compare (trans1, trans2);
+}
+
+
+void test1(std::vector<HepMC::GenParticle*> genPartVector)
+{
+  std::cout << "test1\n";
+  const HepMC::GenParticle *particle = genPartVector.at(0);
+  // Create HepMcParticleLink outside of leak check.
+  HepMcParticleLink dummyHMPL(particle->barcode(),particle->parent_event()->event_number());
+  assert(dummyHMPL.cptr()==particle);
+  // Create DVL info outside of leak check.
+  MMSimHitCollection dum ("coll");
+
+  MMSimHitCollection trans1 ("coll");
+  for (int i=0; i < 10; i++) {
+    const HepMC::GenParticle* pGenParticle = genPartVector.at(i);
+    HepMcParticleLink trkLink(pGenParticle->barcode(),pGenParticle->parent_event()->event_number());
+    trans1.Emplace (123, 10.5,
+                    Amg::Vector3D (12.5, 13.5, 14.5),
+                    pGenParticle->pdg_id(), 25.5,
+                    Amg::Vector3D (26.5, 27.5, 28.5),
+                    29.5, trkLink
+                    );
+  }
+
+  testit (trans1);
+}
+
+
+int main()
+{
+  ISvcLocator* pSvcLoc = nullptr;
+  std::vector<HepMC::GenParticle*> genPartVector;
+  if (!Athena_test::initMcEventCollection(pSvcLoc,genPartVector)) {
+    std::cerr << "This test can not be run" << std::endl;
+    return 0;
+  }
+
+  test1(genPartVector);
+  return 0;
+}
diff --git a/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/test/MMSimHitCollectionCnv_p2_test.cxx b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/test/MMSimHitCollectionCnv_p2_test.cxx
new file mode 100644
index 000000000000..a19cee19c9f6
--- /dev/null
+++ b/MuonSpectrometer/MuonCnv/MuonSimEventTPCnv/test/MMSimHitCollectionCnv_p2_test.cxx
@@ -0,0 +1,101 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+*/
+
+#undef NDEBUG
+#include "MuonSimEventTPCnv/MMSimHitCollectionCnv_p2.h"
+#include "TestTools/leakcheck.h"
+#include <cassert>
+#include <iostream>
+
+#include "GeneratorObjectsTPCnv/initMcEventCollection.h"
+#include "HepMC/GenEvent.h"
+#include "HepMC/GenParticle.h"
+
+void compare (const HepMcParticleLink& p1,
+              const HepMcParticleLink& p2)
+{
+  assert ( p1.isValid() == p2.isValid() );
+  assert ( p1.barcode() == p2.barcode() );
+  assert ( p1.eventIndex() == p2.eventIndex() );
+  assert ( p1.getEventCollectionAsChar() == p2.getEventCollectionAsChar() );
+  assert ( p1.cptr() == p2.cptr() );
+  assert ( p1 == p2 );
+}
+
+void compare (const MMSimHit& p1,
+              const MMSimHit& p2)
+{
+  assert (p1.MMId() == p2.MMId());
+  assert (p1.globalTime() == p2.globalTime());
+  assert (p1.globalPosition() == p2.globalPosition());
+  assert (p1.particleEncoding() == p2.particleEncoding());
+  assert (p1.kineticEnergy() == p2.kineticEnergy());
+  assert (p1.globalDirection() == p2.globalDirection());
+  assert (p1.depositEnergy() == p2.depositEnergy());
+  compare(p1.particleLink(), p2.particleLink());
+  assert (p1.particleLink() == p2.particleLink());
+}
+
+
+void compare (const MMSimHitCollection& p1,
+              const MMSimHitCollection& p2)
+{
+  //assert (p1.Name() == p2.Name());
+  assert (p1.size() == p2.size());
+  for (size_t i=0; i < p1.size(); i++)
+    compare (p1[i], p2[i]);
+}
+
+
+void testit (const MMSimHitCollection& trans1)
+{
+  MsgStream log (0, "test");
+  MMSimHitCollectionCnv_p2 cnv;
+  Muon::MMSimHitCollection_p2 pers;
+  cnv.transToPers (&trans1, &pers, log);
+  MMSimHitCollection trans2;
+  cnv.persToTrans (&pers, &trans2, log);
+
+  compare (trans1, trans2);
+}
+
+
+void test1(std::vector<HepMC::GenParticle*> genPartVector)
+{
+  std::cout << "test1\n";
+  const HepMC::GenParticle *particle = genPartVector.at(0);
+  // Create HepMcParticleLink outside of leak check.
+  HepMcParticleLink dummyHMPL(particle->barcode(),particle->parent_event()->event_number());
+  assert(dummyHMPL.cptr()==particle);
+  // Create DVL info outside of leak check.
+  MMSimHitCollection dum ("coll");
+
+  MMSimHitCollection trans1 ("coll");
+  for (int i=0; i < 10; i++) {
+    const HepMC::GenParticle* pGenParticle = genPartVector.at(i);
+    HepMcParticleLink trkLink(pGenParticle->barcode(),pGenParticle->parent_event()->event_number());
+    trans1.Emplace (123, 10.5,
+                    Amg::Vector3D (12.5, 13.5, 14.5),
+                    pGenParticle->pdg_id(), 25.5,
+                    Amg::Vector3D (26.5, 27.5, 28.5),
+                    29.5, trkLink
+                    );
+  }
+
+  testit (trans1);
+}
+
+
+int main()
+{
+  ISvcLocator* pSvcLoc = nullptr;
+  std::vector<HepMC::GenParticle*> genPartVector;
+  if (!Athena_test::initMcEventCollection(pSvcLoc,genPartVector)) {
+    std::cerr << "This test can not be run" << std::endl;
+    return 0;
+  }
+
+  test1(genPartVector);
+  return 0;
+}
diff --git a/MuonSpectrometer/MuonG4/MuonG4SD/src/MicromegasSensitiveDetector.cxx b/MuonSpectrometer/MuonG4/MuonG4SD/src/MicromegasSensitiveDetector.cxx
index 24cb85f1f36c..e6819ea96ca0 100755
--- a/MuonSpectrometer/MuonG4/MuonG4SD/src/MicromegasSensitiveDetector.cxx
+++ b/MuonSpectrometer/MuonG4/MuonG4SD/src/MicromegasSensitiveDetector.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
 */
 
 #include "MicromegasSensitiveDetector.h"
@@ -18,7 +18,8 @@
 // construction/destruction
 MicromegasSensitiveDetector::MicromegasSensitiveDetector(const std::string& name, const std::string& hitCollectionName)
   : G4VSensitiveDetector( name )
-  , m_GenericMuonHitCollection( hitCollectionName )
+  , m_MMSimHitCollection( hitCollectionName )
+  , m_GenericMuonHitCollection( hitCollectionName ) // Also generate GenericMuonSimHit
 {
   m_muonHelper = MicromegasHitIdHelper::GetHelper();
   //m_muonHelper->PrintFields();
@@ -27,7 +28,8 @@ MicromegasSensitiveDetector::MicromegasSensitiveDetector(const std::string& name
 // Implemenation of memebr functions
 void MicromegasSensitiveDetector::Initialize(G4HCofThisEvent*) 
 {
-  if (!m_GenericMuonHitCollection.isValid()) m_GenericMuonHitCollection = CxxUtils::make_unique<GenericMuonSimHitCollection>();
+  if (!m_MMSimHitCollection.isValid()) m_MMSimHitCollection = CxxUtils::make_unique<MMSimHitCollection>();
+  if (!m_GenericMuonHitCollection.isValid()) m_GenericMuonHitCollection = CxxUtils::make_unique<GenericMuonSimHitCollection>(); // Required to generate both HIT containers
 }
 
 G4bool MicromegasSensitiveDetector::ProcessHits(G4Step* aStep,G4TouchableHistory* /*ROHist*/) 
@@ -97,7 +99,8 @@ G4bool MicromegasSensitiveDetector::ProcessHits(G4Step* aStep,G4TouchableHistory
  
   TrackHelper trHelp(aStep->GetTrack());
 
-  m_GenericMuonHitCollection->Emplace(MmId, globalTime,globalpreTime,position,local_position,preposition,local_preposition,pdgCode,eKin,direction,depositEnergy,StepLength,trHelp.GetParticleLink());
+  m_GenericMuonHitCollection->Emplace(MmId,globalTime,globalpreTime,position,local_position,preposition,local_preposition,pdgCode,eKin,direction,depositEnergy,StepLength,trHelp.GetParticleLink());
+  m_MMSimHitCollection->Emplace(MmId, globalTime,position,pdgCode,eKin,direction,depositEnergy,trHelp.GetParticleLink());
 
   //    G4cout << "MMs "<<m_muonHelper->GetStationName(MmId)
   // 	            << " "<<m_muonHelper->GetFieldValue("PhiSector")
diff --git a/MuonSpectrometer/MuonG4/MuonG4SD/src/MicromegasSensitiveDetector.h b/MuonSpectrometer/MuonG4/MuonG4SD/src/MicromegasSensitiveDetector.h
index 6cefcf4ab637..c6f82450244c 100755
--- a/MuonSpectrometer/MuonG4/MuonG4SD/src/MicromegasSensitiveDetector.h
+++ b/MuonSpectrometer/MuonG4/MuonG4SD/src/MicromegasSensitiveDetector.h
@@ -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
 */
 
 #ifndef MicromegasSensitiveDetector_H
@@ -8,6 +8,7 @@
 #include "G4VSensitiveDetector.hh"
 #include "StoreGate/WriteHandle.h"
 #include "MuonSimEvent/GenericMuonSimHitCollection.h"
+#include "MuonSimEvent/MMSimHitCollection.h"
 
 class MicromegasHitIdHelper;
 
@@ -24,6 +25,7 @@ public:
     
 private:
 
+    SG::WriteHandle<MMSimHitCollection> m_MMSimHitCollection;
     SG::WriteHandle<GenericMuonSimHitCollection> m_GenericMuonHitCollection;
     MicromegasHitIdHelper* m_muonHelper;
 
diff --git a/MuonSpectrometer/MuonSimEvent/MuonSimEvent/MMSimHit.h b/MuonSpectrometer/MuonSimEvent/MuonSimEvent/MMSimHit.h
new file mode 100644
index 000000000000..80d37ae3b694
--- /dev/null
+++ b/MuonSpectrometer/MuonSimEvent/MuonSimEvent/MMSimHit.h
@@ -0,0 +1,89 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef MUONSIMEVENT_MMSimHit_H
+#define MUONSIMEVENT_MMSimHit_H 1
+
+#include "GeoPrimitives/GeoPrimitives.h"
+#include "GeneratorObjects/HepMcParticleLink.h"
+
+#include <string>
+
+typedef int HitID;
+
+class MMSimHit {
+ public:
+  //
+  // construction/destruction
+  //
+  // needed by athenaRoot
+  MMSimHit();
+
+  // Destructor:
+  virtual ~MMSimHit();
+   MMSimHit(HitID id, double time, const Amg::Vector3D& position, const int particleEncoding, const double kineticEnergy, const Amg::Vector3D& direction, const double depositEnergy, const int trackNumber);
+      MMSimHit(HitID id, double time, const Amg::Vector3D& position, const int particleEncoding, const double kineticEnergy, const Amg::Vector3D& direction, const double depositEnergy, const HepMcParticleLink hmpl);
+ 
+  //
+  // member functions
+  //
+  
+  //postStep globalTime
+  double  globalTime()    const { return (double) m_globalTime; }
+  
+  //postStep Global and Local Position
+  const Amg::Vector3D& globalPosition() const { return m_globalPosition; }
+  int particleEncoding() const { return m_particleEncoding; }
+  double kineticEnergy() const { return (double) m_kineticEnergy; }
+  const Amg::Vector3D& globalDirection() const { return m_globalDirection; }
+  double depositEnergy() const { return (double) m_depositEnergy; }
+    
+  HitID  MMId() const { return m_MMId; }
+  std::string  print() const;
+    
+  bool operator< (const MMSimHit& rhs) const
+  { return m_MMId < rhs.m_MMId; }
+	
+  double meanTime() const;
+
+  void setGlobalTime( const double time ) { m_globalTime = time; }
+  void setDepositEnergy ( const double depositEnergy ) { m_depositEnergy = depositEnergy ;}
+  void setGlobalPosition ( const Amg::Vector3D& globalPosition ) { m_globalPosition = globalPosition ;} //!< sets the position expressed in global coordinates
+  void setGlobalDirection ( const Amg::Vector3D& globalDirection ) { m_globalDirection = globalDirection ;} //!< sets the direction expressed in global coordinates
+  void setKineticEnergy ( const double kineticEnergy ) { m_kineticEnergy = kineticEnergy ;} 
+    
+  // number of track which released this energy:
+  int trackNumber() const;
+
+  // link to the particle generating the hit
+  const HepMcParticleLink& particleLink() const;
+    
+ private:    
+  //
+  // member data
+  //
+  HitID m_MMId;
+  double m_globalTime;
+  // postStep  
+  Amg::Vector3D m_globalPosition;
+
+  int m_particleEncoding; // PDG id 
+  double m_kineticEnergy;  // kinetic energy of the particle
+
+  Amg::Vector3D m_globalDirection;
+  double m_depositEnergy;
+	
+  HepMcParticleLink m_partLink;
+};
+
+//inline methods
+
+inline const HepMcParticleLink& MMSimHit::particleLink() const
+{ return m_partLink; }
+inline double MMSimHit::meanTime() const
+{ return (double) m_globalTime; }
+inline float hitTime(const MMSimHit& hit)
+{ return (float) hit.meanTime(); }	
+
+#endif
diff --git a/MuonSpectrometer/MuonSimEvent/MuonSimEvent/MMSimHitCollection.h b/MuonSpectrometer/MuonSimEvent/MuonSimEvent/MMSimHitCollection.h
new file mode 100644
index 000000000000..bd2955797736
--- /dev/null
+++ b/MuonSpectrometer/MuonSimEvent/MuonSimEvent/MMSimHitCollection.h
@@ -0,0 +1,28 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef MMSimHitCollection_H
+#define MMSimHitCollection_H
+
+#include "MuonSimEvent/MMSimHit.h"
+#include "HitManagement/AtlasHitsVector.h"
+#include "HitManagement/AthenaHitsVector.h"
+
+#ifndef __CINT__
+  #include "CLIDSvc/CLASS_DEF.h"
+#endif
+
+typedef AthenaHitsVector<MMSimHit> OldMMSimHitCollection;
+
+typedef AtlasHitsVector<MMSimHit> MMSimHitCollection;
+typedef AtlasHitsVector<MMSimHit>::iterator MMSimHitIterator;
+typedef AtlasHitsVector<MMSimHit>::const_iterator MMSimHitConstIterator;
+
+#ifndef __CINT__
+CLASS_DEF( MMSimHitCollection , 20181211 , 1 )
+CLASS_DEF( OldMMSimHitCollection , 20181212 , 1 )
+#endif
+
+#endif
+
diff --git a/MuonSpectrometer/MuonSimEvent/MuonSimEvent/selection.xml b/MuonSpectrometer/MuonSimEvent/MuonSimEvent/selection.xml
index 7df146db287d..32dc65c9a456 100644
--- a/MuonSpectrometer/MuonSimEvent/MuonSimEvent/selection.xml
+++ b/MuonSpectrometer/MuonSimEvent/MuonSimEvent/selection.xml
@@ -17,6 +17,9 @@
   <class name="AtlasHitsVector<sTGCSimHit>" /> 
   <class name="std::vector<sTGCSimHit>" /> 
 
+  <class name="AtlasHitsVector<MMSimHit>" />
+  <class name="std::vector<MMSimHit>" />
+
   <class name="AthenaHitsVector<MDTSimHit>" id="D76D06CC-C15F-43E6-BBC3-480DE5DA065D" />
   <class name="std::vector<MDTSimHit*>" />
 
@@ -35,10 +38,15 @@
   <class name="AthenaHitsVector<sTGCSimHit>" id="9ae1805a-6e3c-11e8-9b02-02163e01bddd" /> 
   <class name="std::vector<sTGCSimHit*>" /> 
 
+  <class name="AthenaHitsVector<MMSimHit>" id="e7b60352-fdf6-11e8-a11b-02163e018187" />
+  <class name="std::vector<MMSimHit*>" />
+
   <class name="MDTSimHit" />
   <class name="CSCSimHit" />
   <class name="RPCSimHit" />
   <class name="TGCSimHit" />
   <class name="GenericMuonSimHit" />
+  <class name="sTGCSimHit" />
+  <class name="MMSimHit" />
 
 </lcgdict>
diff --git a/MuonSpectrometer/MuonSimEvent/src/MMSimHit.cxx b/MuonSpectrometer/MuonSimEvent/src/MMSimHit.cxx
new file mode 100644
index 000000000000..b8b7df501209
--- /dev/null
+++ b/MuonSpectrometer/MuonSimEvent/src/MMSimHit.cxx
@@ -0,0 +1,76 @@
+/*
+  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+*/
+
+#include "MuonSimEvent/MMSimHit.h"
+#include <sstream>
+/*******************************************************************************/
+MMSimHit::MMSimHit():
+  m_MMId(0xffff),
+  m_globalTime(0.),
+  m_particleEncoding(0),// PDG_ID
+  m_kineticEnergy(-9999.),// energy of the particle
+  m_depositEnergy(-9999.),//Geant4 deposited energy
+  m_partLink()
+{
+}
+/*******************************************************************************/
+//virtual destructor required by Pool
+MMSimHit::~MMSimHit()
+{
+}
+/*******************************************************************************/
+MMSimHit::MMSimHit(HitID id, double time, 
+                                     const Amg::Vector3D& position,
+                                     const int particleEncoding,
+                                     const double kineticEnergy,
+                                     const Amg::Vector3D& direction,
+                                     const double depositEnergy,
+                                     const int trackNumber)
+  : m_MMId(id), m_globalTime(time) 
+  , m_globalPosition(position)
+  , m_particleEncoding(particleEncoding)
+  , m_kineticEnergy(kineticEnergy)
+  , m_globalDirection(direction)
+  , m_depositEnergy(depositEnergy)
+  , m_partLink(trackNumber)
+{
+}
+
+MMSimHit::MMSimHit(HitID id, double time,
+                                     const Amg::Vector3D& position,
+                                     const int particleEncoding,
+                                     const double kineticEnergy,
+                                     const Amg::Vector3D& direction,
+                                     const double depositEnergy,
+                                     const HepMcParticleLink hmpl)
+  : m_MMId(id), m_globalTime(time)
+  , m_globalPosition(position)
+  , m_particleEncoding(particleEncoding)
+  , m_kineticEnergy(kineticEnergy)
+  , m_globalDirection(direction)
+  , m_depositEnergy(depositEnergy)
+  , m_partLink(hmpl)
+{
+}
+/*******************************************************************************/
+std::string MMSimHit::print() const {
+
+  std::stringstream ss;
+
+  ss << "-------------------------------------------------------------" << std::endl;
+  ss << "MMSimHit:"<<std::endl;
+  ss << "  identifier: "  << m_MMId;
+  ss << "  t: "  << m_globalTime;
+  ss << "  x : (" << m_globalPosition.x()
+     << ","      << m_globalPosition.y()
+     << ","      << m_globalPosition.z()
+     << ")"<<std::endl;
+  ss << " pdgId: "<<m_particleEncoding<<" kineticEnergy: "<<m_kineticEnergy<<std::endl;
+
+  return ss.str();
+}
+/*******************************************************************************/
+int MMSimHit::trackNumber() const
+{ return m_partLink.barcode(); }
+/*******************************************************************************/
diff --git a/Simulation/G4Atlas/G4AtlasApps/python/SimSkeleton.py b/Simulation/G4Atlas/G4AtlasApps/python/SimSkeleton.py
index 155d900077a6..b96a47695400 100644
--- a/Simulation/G4Atlas/G4AtlasApps/python/SimSkeleton.py
+++ b/Simulation/G4Atlas/G4AtlasApps/python/SimSkeleton.py
@@ -106,8 +106,9 @@ class SimSkeleton(object):
                                  "TrackRecordCollection#MuonExitLayer"]
             from AtlasGeoModel.CommonGMJobProperties import CommonGeometryFlags
             if ( hasattr(simFlags, 'SimulateNewSmallWheel') and simFlags.SimulateNewSmallWheel() ) or CommonGeometryFlags.Run()=="RUN3" :
-                stream1.ItemList += ["GenericMuonSimHitCollection#*"] #MicroMegas only
                 stream1.ItemList += ["sTGCSimHitCollection#*"]
+                stream1.ItemList += ["MMSimHitCollection#*"]
+                stream1.ItemList += ["GenericMuonSimHitCollection#*"]
         ## Lucid
         if DetFlags.Lucid_on():
             stream1.ItemList += ["LUCID_SimHitCollection#*"]
diff --git a/Simulation/G4Atlas/G4AtlasApps/share/G4Atlas.flat.configuration.py b/Simulation/G4Atlas/G4AtlasApps/share/G4Atlas.flat.configuration.py
index f86c04f7f203..9527d6b2a102 100644
--- a/Simulation/G4Atlas/G4AtlasApps/share/G4Atlas.flat.configuration.py
+++ b/Simulation/G4Atlas/G4AtlasApps/share/G4Atlas.flat.configuration.py
@@ -227,8 +227,10 @@ if not simFlags.ISFRun:
                                  "MDTSimHitCollection#*",
                                  "TrackRecordCollection#MuonExitLayer"]
             if ( hasattr(simFlags, 'SimulateNewSmallWheel') and simFlags.SimulateNewSmallWheel() ) or CommonGeometryFlags.Run()=="RUN3" :
-                stream1.ItemList += ["GenericMuonSimHitCollection#*"] #MicroMegas only
                 stream1.ItemList += ["sTGCSimHitCollection#*"]
+                stream1.ItemList += ["MMSimHitCollection#*"]
+                stream1.ItemList += ["GenericMuonSimHitCollection#*"]
+
         ## Lucid
         if DetFlags.Lucid_on():
             stream1.ItemList += ["LUCID_SimHitCollection#*"]
diff --git a/Simulation/G4Atlas/G4AtlasApps/share/Tile2000_2003.flat.configuration.py b/Simulation/G4Atlas/G4AtlasApps/share/Tile2000_2003.flat.configuration.py
index c0bd86bcff73..e416dbcb7ff2 100644
--- a/Simulation/G4Atlas/G4AtlasApps/share/Tile2000_2003.flat.configuration.py
+++ b/Simulation/G4Atlas/G4AtlasApps/share/Tile2000_2003.flat.configuration.py
@@ -195,8 +195,10 @@ if not simFlags.ISFRun:
                                  "TrackRecordCollection#MuonExitLayer"]
             from AtlasGeoModel.CommonGMJobProperties import CommonGeometryFlags
             if ( hasattr(simFlags, 'SimulateNewSmallWheel') and simFlags.SimulateNewSmallWheel() ) or CommonGeometryFlags.Run()=="RUN3" :
-                stream1.ItemList += ["GenericMuonSimHitCollection#*"] #MicroMegas only
                 stream1.ItemList += ["sTGCSimHitCollection#*"]
+                stream1.ItemList += ["MMSimHitCollection#*"]
+                stream1.ItemList += ["GenericMuonSimHitCollection#*"]
+
         ## Lucid
         if DetFlags.Lucid_on():
             stream1.ItemList += ["LUCID_SimHitCollection#*"]
diff --git a/Simulation/ISF/ISF_Example/python/ISF_Output.py b/Simulation/ISF/ISF_Example/python/ISF_Output.py
index a8d5a500f575..9ed14cbc60f6 100644
--- a/Simulation/ISF/ISF_Example/python/ISF_Output.py
+++ b/Simulation/ISF/ISF_Example/python/ISF_Output.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
 
 
 ## Get the logger
@@ -46,8 +46,9 @@ def getHITSStreamItemList():
                          "TrackRecordCollection#MuonExitLayer"]
         from AtlasGeoModel.CommonGMJobProperties import CommonGeometryFlags
         if ( hasattr(simFlags, 'SimulateNewSmallWheel') and simFlags.SimulateNewSmallWheel() ) or CommonGeometryFlags.Run()=="RUN3" :
-            hitsItemList += ["GenericMuonSimHitCollection#*"] #MicroMegas only
             hitsItemList += ["sTGCSimHitCollection#*"]
+            hitsItemList += ["MMSimHitCollection#*"]
+            hitsItemList += ["GenericMuonSimHitCollection#*"]
 
     ## FwdRegion
     if DetFlags.FwdRegion_on():
-- 
GitLab