From 9d1db85b9be2a9437c94715790460969226c78b7 Mon Sep 17 00:00:00 2001
From: lintao <lintao51@gmail.com>
Date: Mon, 5 Dec 2022 22:25:22 +0800
Subject: [PATCH] WIP: rename the MCParticle collections names at gen and sim
 phases.

---
 Generator/src/GenAlgo.cpp                     |  2 +-
 Generator/src/GenAlgo.h                       |  2 +-
 Generator/src/GenWriter.cpp                   | 44 -------------------
 Generator/src/GenWriter.h                     | 35 ---------------
 .../DetSimAna/src/Edm4hepWriterAnaElemTool.h  |  4 +-
 Simulation/DetSimCore/src/G4PrimaryCnvTool.h  |  2 +-
 6 files changed, 5 insertions(+), 84 deletions(-)
 delete mode 100644 Generator/src/GenWriter.cpp
 delete mode 100644 Generator/src/GenWriter.h

diff --git a/Generator/src/GenAlgo.cpp b/Generator/src/GenAlgo.cpp
index 07b6c322..2d8ec897 100644
--- a/Generator/src/GenAlgo.cpp
+++ b/Generator/src/GenAlgo.cpp
@@ -18,7 +18,7 @@
 DECLARE_COMPONENT(GenAlgo)
 
 GenAlgo::GenAlgo(const std::string& name, ISvcLocator* pSvcLocator): GaudiAlgorithm(name, pSvcLocator) {
-    declareProperty("MCParticle", m_hdl, "MCParticle collection (output)");
+    declareProperty("MCParticleGen", m_hdl, "MCParticle collection (at Generator phase)");
     declareProperty("GenTools", m_genToolNames, "List of GenTools");
     m_evtid = 0;
 
diff --git a/Generator/src/GenAlgo.h b/Generator/src/GenAlgo.h
index 9723e896..2fa42bfa 100644
--- a/Generator/src/GenAlgo.h
+++ b/Generator/src/GenAlgo.h
@@ -36,7 +36,7 @@ private:
     int m_evtid;                               
     int m_evtMax;
     //MyHepMC::GenEvent m_event;
-    DataHandle<edm4hep::MCParticleCollection> m_hdl{"MCParticle", Gaudi::DataHandle::Writer, this};
+    DataHandle<edm4hep::MCParticleCollection> m_hdl{"MCParticleGen", Gaudi::DataHandle::Writer, this};
 
 
 };
diff --git a/Generator/src/GenWriter.cpp b/Generator/src/GenWriter.cpp
deleted file mode 100644
index f1f93a57..00000000
--- a/Generator/src/GenWriter.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-#include "GenWriter.h"
-#include "GenEvent.h"
-
-#include "podio/EventStore.h" //podio
-#include "podio/ROOTWriter.h"
-
-
-#include "plcio/MCParticleCollection.h"//plico
-#include "plcio/EventHeaderCollection.h"
-
-
-GenWriter::GenWriter(string name){
-    m_output_name = name;
-    store  = new podio::EventStore();
-    writer = new podio::ROOTWriter(m_output_name, store);
-    ehc   =  &store->create<plcio::EventHeaderCollection>("EvtHeaders");
-    mcc   =  &store->create<plcio::MCParticleCollection>("MCParticles");
-
-    writer->registerForWrite("EvtHeaders");
-    writer->registerForWrite("MCParticles");
-}
-
-GenWriter::~GenWriter(){
-}
-
-bool GenWriter::mutate(MyHepMC::GenEvent& event){
-    std::cout << "write mc info for event "<< event.getID() << ", mc size ="<< event.m_mc_vec.size() <<  std::endl;
-    mcc=&event.m_mc_vec;
-    auto header = plcio::EventHeader(event.getID(), event.getRun(), event.getTime(), event.getName());
-    ehc->push_back(header);
-    writer->writeEvent();
-    store->clearCollections();
-    return true;
-}
-
-bool GenWriter::configure(){
-return true;
-}
-
-bool GenWriter::finish(){
-    writer->finish();
-    std::cout<<"Saved root "<<m_output_name<<std::endl;
-    return true;
-}
diff --git a/Generator/src/GenWriter.h b/Generator/src/GenWriter.h
deleted file mode 100644
index 30e6db43..00000000
--- a/Generator/src/GenWriter.h
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef GenWriter_h
-#define GenWriter_h 1
-
-#include "GenEvent.h"
-#include "IGenTool.h"
-
-#include "podio/EventStore.h" //podio
-#include "podio/ROOTWriter.h"
-
-
-#include "plcio/MCParticleCollection.h"//plico
-#include "plcio/EventHeaderCollection.h"
-
-
-
-using namespace std;
-
-class GenWriter: public IGenTool{
-
-    public:
-        GenWriter(string name);
-        ~GenWriter();
-        bool configure() override;               
-        bool mutate(MyHepMC::GenEvent& event) override;    
-        bool finish() override;
-    private:
-        string m_output_name;
-        podio::EventStore* store ;
-        podio::ROOTWriter* writer;
-        plcio::EventHeaderCollection*  ehc  ;
-        plcio::MCParticleCollection*   mcc  ;
-
-};
-
-#endif
diff --git a/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.h b/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.h
index 7b992d30..937869b4 100644
--- a/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.h
+++ b/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.h
@@ -42,10 +42,10 @@ public:
 private:
     // In order to associate MCParticle with contribution, we need to access MC Particle.
     // - collection MCParticle: the particles in Generator
-    DataHandle<edm4hep::MCParticleCollection> m_mcParGenCol{"MCParticle", 
+    DataHandle<edm4hep::MCParticleCollection> m_mcParGenCol{"MCParticleGen", 
             Gaudi::DataHandle::Writer, this};
     // - collection MCParticleG4: the simulated particles in Geant4
-    DataHandle<edm4hep::MCParticleCollection> m_mcParCol{"MCParticleG4", 
+    DataHandle<edm4hep::MCParticleCollection> m_mcParCol{"MCParticle", 
             Gaudi::DataHandle::Writer, this};
     edm4hep::MCParticleCollection* mcCol;
 
diff --git a/Simulation/DetSimCore/src/G4PrimaryCnvTool.h b/Simulation/DetSimCore/src/G4PrimaryCnvTool.h
index 1e477721..70b143fc 100644
--- a/Simulation/DetSimCore/src/G4PrimaryCnvTool.h
+++ b/Simulation/DetSimCore/src/G4PrimaryCnvTool.h
@@ -16,7 +16,7 @@ public:
     bool mutate(G4Event* anEvent) override;
 
 private:
-    DataHandle<edm4hep::MCParticleCollection> m_mcParCol{"MCParticle", Gaudi::DataHandle::Reader, this};
+    DataHandle<edm4hep::MCParticleCollection> m_mcParCol{"MCParticleGen", Gaudi::DataHandle::Reader, this};
 
     Gaudi::Property<double> m_chargedgeantino_mass{this, "ChargedGeantinoMass"};
 };
-- 
GitLab