From ceb142eb4a627b26ce3bd54f5bd05c4f27da6f0d Mon Sep 17 00:00:00 2001
From: Placido Fernandez Declara <placido.fernandez@cern.ch>
Date: Tue, 6 Jul 2021 00:01:20 +0200
Subject: [PATCH] save encoding string for edm4hep format

---
 DDG4/edm4hep/Geant4Output2EDM4hep.cpp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/DDG4/edm4hep/Geant4Output2EDM4hep.cpp b/DDG4/edm4hep/Geant4Output2EDM4hep.cpp
index 555e4e52f..504fb8e4f 100644
--- a/DDG4/edm4hep/Geant4Output2EDM4hep.cpp
+++ b/DDG4/edm4hep/Geant4Output2EDM4hep.cpp
@@ -20,6 +20,7 @@
 #include "DDG4/Geant4HitCollection.h"
 #include "DDG4/Geant4OutputAction.h"
 #include "DDG4/Geant4SensDetAction.h"
+#include "DDG4/Geant4DataConversion.h"
 #include "DDG4/EventParameters.h"
 
 // Geant4 headers
@@ -563,16 +564,23 @@ void Geant4Output2EDM4hep::createCollections(OutputContext<G4Event>& ctxt){
       continue ;
     }
 
+    Geant4Sensitive* sd = coll->sensitive();
+    string sd_enc = dd4hep::sim::Geant4ConversionHelper::encoding(sd->sensitiveDetector());
+
     if( typeid( Geant4Tracker::Hit ) == coll->type().type()  ){
 
-      m_store->create<edm4hep::SimTrackerHitCollection>(colName);
+      auto& sthc = m_store->create<edm4hep::SimTrackerHitCollection>(colName);
       m_file->registerForWrite(colName);
+      auto& sthc_md = m_store->getCollectionMetaData( sthc.getID() );
+      sthc_md.setValue("CellIDEncodingString", sd_enc);
       printout(DEBUG,"Geant4Output2EDM4hep","+++ created collection %s",colName.c_str() );
     }
     else if( typeid( Geant4Calorimeter::Hit ) == coll->type().type() ){
 
-      m_store->create<edm4hep::SimCalorimeterHitCollection>(colName);
+      auto& schc = m_store->create<edm4hep::SimCalorimeterHitCollection>(colName);
       m_file->registerForWrite(colName);
+      auto& schc_md = m_store->getCollectionMetaData( schc.getID() );
+      schc_md.setValue("CellIDEncodingString", sd_enc);
       printout(DEBUG,"Geant4Output2EDM4hep","+++ created collection %s",colName.c_str() );
 
       colName += "Contributions"  ;
-- 
GitLab