From 06041167ca18693b3bca280bb658c16ea7e27ae8 Mon Sep 17 00:00:00 2001
From: wenxingfang <1473717798@qq.com>
Date: Sun, 15 Nov 2020 12:11:11 +0800
Subject: [PATCH] add options for G2CDArbor

---
 Digitisers/G2CDArbor/src/G2CDArborAlg.cpp | 38 ++++------
 Examples/options/LCIO_read_G2CD.py        | 91 +++++++++++++++++++++++
 Examples/options/tut_detsim_G2CD.py       | 81 ++++++++++++++++++++
 3 files changed, 187 insertions(+), 23 deletions(-)
 create mode 100644 Examples/options/LCIO_read_G2CD.py
 create mode 100644 Examples/options/tut_detsim_G2CD.py

diff --git a/Digitisers/G2CDArbor/src/G2CDArborAlg.cpp b/Digitisers/G2CDArbor/src/G2CDArborAlg.cpp
index f6897e6c..50c74229 100644
--- a/Digitisers/G2CDArbor/src/G2CDArborAlg.cpp
+++ b/Digitisers/G2CDArbor/src/G2CDArborAlg.cpp
@@ -211,26 +211,16 @@ StatusCode G2CDArborAlg::initialize() {
        error() << "failed to retrieve dd4hep_geo: " << m_dd4hep_geo << endmsg;
        return StatusCode::FAILURE;
      }
-     /*
-     // get the DD4hep readout
-     const std::string name_readout = "EcalBarrelCollection";
-     m_decoder = m_geosvc->getDecoder(name_readout);
-     if (!m_decoder) {
-       error() << "Failed to get the decoder. " << endmsg;
-       return StatusCode::FAILURE;
-     }
-     */
 
      m_encoder_str = "M:3,S-1:3,I:9,J:9,K-1:6";
 
-     // printParameters();
-     // WeightVector.clear();
-     for(unsigned int i = 0; i < m_ecalReadoutNames.value().size(); i++){
-         m_col_readout_map[m_ecalColNames.value().at(i)] = m_ecalReadoutNames.value().at(i);
-         //std::cout<<"name="<<m_ecalColNames.value().at(i)<<",readout="<<m_ecalReadoutNames.value().at(i)<<std::endl;
-     }
-     for(unsigned int i = 0; i < m_hcalReadoutNames.value().size(); i++){
-         m_col_readout_map[m_hcalColNames.value().at(i)] = m_hcalReadoutNames.value().at(i);
+     if(m_readLCIO==false){
+         for(unsigned int i = 0; i < m_ecalReadoutNames.value().size(); i++){
+             m_col_readout_map[m_ecalColNames.value().at(i)] = m_ecalReadoutNames.value().at(i);
+         }
+         for(unsigned int i = 0; i < m_hcalReadoutNames.value().size(); i++){
+             m_col_readout_map[m_hcalColNames.value().at(i)] = m_hcalReadoutNames.value().at(i);
+         }
      }
 
      for (auto& ecal : m_ecalColNames) {
@@ -499,12 +489,14 @@ StatusCode G2CDArborAlg::execute()
 
 	  // for(int k1 = 0; k1 < NumEcalhit; k1++)
 	  // {	
-	  std::string tmp_readout = m_col_readout_map[m_ecalColNames.value().at(k0)];
-          // get the DD4hep readout
-          m_decoder = m_geosvc->getDecoder(tmp_readout);
-          if (!m_decoder) {
-            error() << "Failed to get the decoder. " << endmsg;
-            return StatusCode::FAILURE;
+	  if(m_readLCIO==false){
+	      std::string tmp_readout = m_col_readout_map[m_ecalColNames.value().at(k0)];
+              // get the DD4hep readout
+              m_decoder = m_geosvc->getDecoder(tmp_readout);
+              if (!m_decoder) {
+                error() << "Failed to get the decoder. " << endmsg;
+                return StatusCode::FAILURE;
+              }
           }
 
 	  edm4hep::CalorimeterHitCollection* ecalcol = _outputEcalCollections[k0]->createAndPut();
diff --git a/Examples/options/LCIO_read_G2CD.py b/Examples/options/LCIO_read_G2CD.py
new file mode 100644
index 00000000..e2df344f
--- /dev/null
+++ b/Examples/options/LCIO_read_G2CD.py
@@ -0,0 +1,91 @@
+#!/usr/bin/env python
+
+from Gaudi.Configuration import *
+from Configurables import K4DataSvc
+dsvc = K4DataSvc("EventDataSvc")
+
+# read LCIO files
+from Configurables import LCIOInput
+read = LCIOInput("read")
+read.inputs = [
+"/cefs/higgs/wxfang/cepc/FS/FS_Barrel_Mom150_1000MeV_x_theta_phi_mom_bin_resVsMom_Etuning/sim_111_0830.slcio"
+]
+read.collections = [
+        "MCParticle:MCParticle",
+        "SimCalorimeterHit:EcalBarrelSiliconCollection",
+        #"CalorimeterHit:ECALBarrel",
+        #"CalorimeterHit:ECALEndcap",
+        #"CalorimeterHit:ECALOther" ,
+        ########## HCAL will effect the reco efficiency close to gap region ######
+        #"CalorimeterHit:HCALBarrel",
+        #"CalorimeterHit:HCALEndcap",
+        #"CalorimeterHit:HCALOther",
+        ##"TrackerHit:VXDTrackerHits",
+        ##"TrackerHit:SITTrackerHits",
+        #"TrackerHit:SITSpacePoints",
+        #"TrackerHit:TPCTrackerHits",
+        ##"TrackerHit:SETTrackerHits",
+        #"TrackerHit:SETSpacePoints",
+        ##"TrackerHit:FTDStripTrackerHits",
+        #"TrackerHit:FTDSpacePoints",
+        ##"TrackerHit:FTDPixelTrackerHits",
+        #"Track:ClupatraTrackSegments", 
+        #"Track:ClupatraTracks", 
+        #"Track:ForwardTracks", 
+        #"Track:SiTracks", 
+        #"Track:SubsetTracks",
+        #"Track:MarlinTrkTracks", 
+        #"Vertex:KinkVertices",
+        #"Vertex:ProngVertices",
+        #"Vertex:V0Vertices",
+        #"ReconstructedParticle:KinkRecoParticles",
+        #"ReconstructedParticle:ProngRecoParticles",
+        #"ReconstructedParticle:V0RecoParticles"
+]
+#########################################################################
+geometry_option = "CepC_v4-onlyECAL.xml"
+
+if not os.getenv("DETCEPCV4ROOT"):
+    print("Can't find the geometry. Please setup envvar DETCEPCV4ROOT." )
+    sys.exit(-1)
+
+geometry_path = os.path.join(os.getenv("DETCEPCV4ROOT"), "compact", geometry_option)
+if not os.path.exists(geometry_path):
+    print("Can't find the compact geometry file: %s"%geometry_path)
+    sys.exit(-1)
+
+from Configurables import GeomSvc
+geosvc = GeomSvc("GeomSvc")
+geosvc.compact = geometry_path
+########################################################################
+from Configurables import GearSvc
+gearSvc  = GearSvc("GearSvc")
+gearSvc.GearXMLFile = "Detector/DetCEPCv4/compact/FullDetGear.xml"
+##############################################################################
+from Configurables import G2CDArborAlg
+caloDigi = G2CDArborAlg("G2CDArborAlg")
+caloDigi.ReadLCIO = True 
+caloDigi.CalibrECAL = [48.16, 96.32]
+caloDigi.ECALCollections = ["EcalBarrelSiliconCollection"]
+caloDigi.DigiECALCollection = ["EcalBarrel"]
+caloDigi.HCALCollections = []
+caloDigi.EventReportEvery = 1
+
+##############################################################################
+
+# write PODIO file
+from Configurables import PodioOutput
+write = PodioOutput("write")
+write.filename = "test.root"
+write.outputCommands = ["keep *"]
+
+# ApplicationMgr
+from Configurables import ApplicationMgr
+ApplicationMgr(
+        #TopAlg = [read, caloDigi, write],
+        TopAlg = [read, caloDigi],
+        EvtSel = 'NONE',
+        EvtMax = 10,
+        ExtSvc = [dsvc, geosvc, gearSvc],
+        OutputLevel=INFO
+)
diff --git a/Examples/options/tut_detsim_G2CD.py b/Examples/options/tut_detsim_G2CD.py
new file mode 100644
index 00000000..b78da615
--- /dev/null
+++ b/Examples/options/tut_detsim_G2CD.py
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+
+from Gaudi.Configuration import *
+from Configurables import K4DataSvc
+#dsvc = K4DataSvc("EventDataSvc", input="detsim_ECAL_gamma_10000evt.root")
+dsvc = K4DataSvc("EventDataSvc", input="ECALonly_gamma_30degree_10000evt.root")
+
+#########################################################################
+geometry_option = "CepC_v4-onlyECAL.xml"
+
+if not os.getenv("DETCEPCV4ROOT"):
+    print("Can't find the geometry. Please setup envvar DETCEPCV4ROOT." )
+    sys.exit(-1)
+
+geometry_path = os.path.join(os.getenv("DETCEPCV4ROOT"), "compact", geometry_option)
+if not os.path.exists(geometry_path):
+    print("Can't find the compact geometry file: %s"%geometry_path)
+    sys.exit(-1)
+
+from Configurables import GeomSvc
+geosvc = GeomSvc("GeomSvc")
+geosvc.compact = geometry_path
+########################################################################
+
+from Configurables import PodioInput
+podioinput = PodioInput("PodioReader", collections=[
+    "MCParticle",
+    "EcalBarrelCollection",
+    "EcalEndcapsCollection"
+])
+
+
+############################################################
+from Configurables import GearSvc
+gearSvc  = GearSvc("GearSvc")
+gearSvc.GearXMLFile = "Detector/DetCEPCv4/compact/FullDetGear.xml"
+
+############################################################
+from Configurables import SimHitMergeAlg
+simHitMerge = SimHitMergeAlg("SimHitMergeAlg")
+simHitMerge.InputCollections=["EcalBarrelCollection", "EcalEndcapsCollection"]
+simHitMerge.OutputCollections=["EcalBarrelCollectionMerged", "EcalEndcapsCollectionMerged"]
+############################################################
+
+from Configurables import G2CDArborAlg
+caloDigi = G2CDArborAlg("G2CDArborAlg")
+caloDigi.ReadLCIO = False 
+#caloDigi.CalibrECAL = [48.16, 96.32]
+caloDigi.CalibrECAL = [46.538, 93.0769]
+caloDigi.ECALCollections = ["EcalBarrelCollectionMerged", "EcalEndcapsCollectionMerged"]
+caloDigi.ECALReadOutNames= ["EcalBarrelCollection", "EcalEndcapsCollection"]
+caloDigi.DigiECALCollection = ["EcalBarrel", "EcalEndcaps"]
+caloDigi.HCALCollections = []
+caloDigi.HCALReadOutNames= []
+caloDigi.DigiHCALCollection = []
+caloDigi.EventReportEvery = 100
+##############################################################################
+
+
+#from Configurables import DumpDigiIDAlgv1
+#dumpIDAlg = DumpDigiIDAlgv1("DumpDigiIDAlgv1")
+#dumpIDAlg.ColName = "EcalEndcaps"
+#dumpIDAlg.Readout = "EcalEndcapsCollection"
+##dumpIDAlg.Output = "id_ECAL_gamma_digi_10000evt_newCalibv2_fromMergedSimHit.root"
+#dumpIDAlg.Output = "id_ECALonly_30degree.root"
+##############################################################################
+
+from Configurables import PodioOutput
+out = PodioOutput("outputalg")
+out.filename = "digi_fix5GeV_EcalOnlyBF.root"
+out.outputCommands = ["keep *"]
+
+# ApplicationMgr
+from Configurables import ApplicationMgr
+ApplicationMgr(
+TopAlg = [podioinput, simHitMerge, caloDigi, out],
+    EvtSel = 'NONE',
+    EvtMax = -1,
+    ExtSvc = [dsvc, gearSvc],
+    OutputLevel=INFO
+)
-- 
GitLab