From 2fe6f6ed8c17ffe09c49740b4bfd49b4135d3d14 Mon Sep 17 00:00:00 2001 From: wenxingfang <1473717798@qq.com> Date: Fri, 10 Nov 2023 10:20:25 +0800 Subject: [PATCH] move SimPrimaryIonizationCol createAndPut to TrackHeedSimTool --- Examples/options/tut_detsim_SDT_Heed.py | 4 +- .../src/Edm4hepWriterAnaElemTool.cpp | 4 -- .../DetSimAna/src/Edm4hepWriterAnaElemTool.h | 3 -- .../DetSimDedx/src/TrackHeedSimTool.cpp | 51 ++++++++----------- Simulation/DetSimDedx/src/TrackHeedSimTool.h | 28 +++++----- .../include/DetSimInterface/IDedxSimTool.h | 1 - .../src/DriftChamberSensitiveDetector.cpp | 1 - 7 files changed, 39 insertions(+), 53 deletions(-) diff --git a/Examples/options/tut_detsim_SDT_Heed.py b/Examples/options/tut_detsim_SDT_Heed.py index e3ee257b7..d994ae614 100644 --- a/Examples/options/tut_detsim_SDT_Heed.py +++ b/Examples/options/tut_detsim_SDT_Heed.py @@ -178,8 +178,8 @@ #dedx_simtool.IonMobility_file ="/junofs/users/wxfang/MyGit/tmp/check_G4FastSim_20210121/CEPCSW/Digitisers/DigiGarfield/IonMobility_He+_He.txt" dedx_simtool.gas_file ="he_90_isobutane_10.gas" dedx_simtool.IonMobility_file ="IonMobility_He+_He.txt" - dedx_simtool.save_mc = True##IF this is False then ... - dedx_simtool.debug = False + dedx_simtool.save_mc = True + dedx_simtool.debug = False dedx_simtool.sim_pulse = True #dedx_simtool.model='/junofs/users/wxfang/MyGit/tmp/fork_cepcsw_20220418/CEPCSW/Digitisers/SimCurrentONNX/src/model_90He10C4H10_18mm.onnx' dedx_simtool.model='model_90He10C4H10_18mm.onnx' diff --git a/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp b/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp index b6ab38e67..0c687f827 100644 --- a/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp +++ b/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp @@ -87,8 +87,6 @@ Edm4hepWriterAnaElemTool::BeginOfEventAction(const G4Event* anEvent) { // reset m_track2primary.clear(); - - auto SimPIonCol = m_SimPrimaryIonizationCol.createAndPut(); } @@ -97,8 +95,6 @@ Edm4hepWriterAnaElemTool::EndOfEventAction(const G4Event* anEvent) { msg() << "mcCol size (after simulation) : " << mcCol->size() << endmsg; // save all data - auto SimPrimaryIonizationCol = m_SimPrimaryIonizationCol.get(); - //msg() << "SimPrimaryIonizationCol size ="<size()< { @@ -130,8 +129,6 @@ class Edm4hepWriterAnaElemTool: public extends { "DriftChamberHitsCollection", Gaudi::DataHandle::Writer, this}; - // for ionized electron - DataHandle m_SimPrimaryIonizationCol{"SimPrimaryIonizationClusterCollection", Gaudi::DataHandle::Writer, this}; private: // in order to associate the hit contribution with the primary track, diff --git a/Simulation/DetSimDedx/src/TrackHeedSimTool.cpp b/Simulation/DetSimDedx/src/TrackHeedSimTool.cpp index 3bafda261..f66c582b2 100644 --- a/Simulation/DetSimDedx/src/TrackHeedSimTool.cpp +++ b/Simulation/DetSimDedx/src/TrackHeedSimTool.cpp @@ -25,7 +25,10 @@ double TrackHeedSimTool::dndx(double betagamma) {return 0;} double TrackHeedSimTool::dedx(const G4Step* Step) { - + if(m_beginEvt){ + m_SimPrimaryIonizationCol = m_SimPrimaryIonizationColWriter.createAndPut(); + m_beginEvt = false; + } clock_t t0 = clock(); double de = 0; float cm_to_mm = 10; @@ -43,15 +46,12 @@ double TrackHeedSimTool::dedx(const G4Step* Step) if(g4Track->GetKineticEnergy() <=0) return 0; if(pdg_code == 11 && (tmp_str_pro=="phot" || tmp_str_pro=="hIoni" || tmp_str_pro=="eIoni" || tmp_str_pro=="muIoni" || tmp_str_pro=="ionIoni" ) ) return m_eps;//skip the electron produced by Ioni, because it is already simulated by TrackHeed if(m_particle_map.find(pdg_code) == m_particle_map.end() ) return m_eps; - edm4hep::SimPrimaryIonizationClusterCollection* SimPrimaryIonizationCol = nullptr; edm4hep::MCParticleCollection* mcCol = nullptr; try{ - SimPrimaryIonizationCol = const_cast(m_SimPrimaryIonizationCol.get()); mcCol = const_cast(m_mc_handle.get()); } catch(...){ - G4cout<<"Error! Can't find collection in event, please check it have been createAndPut() in Begin of event"<GetCluster(xc, yc, zc, tc, nc, ec, extra)) { //auto chit = SimHitCol->create(); - auto chit = SimPrimaryIonizationCol->create(); + //auto chit = SimPrimaryIonizationCol->create(); + auto chit = m_SimPrimaryIonizationCol->create(); chit.setTime(tc); double cpos[3] = { cm_to_mm*( (xc - init_x)+position_x/CLHEP::cm) , cm_to_mm*((yc - init_y)+position_y/CLHEP::cm), cm_to_mm*(zc + position_z/CLHEP::cm)}; chit.setPosition(edm4hep::Vector3d(cpos)); @@ -395,7 +396,8 @@ StatusCode TrackHeedSimTool::initialize() m_current_Parent_ID = -1; m_change_track = false; m_total_range = 0; - m_isFirst = false; + m_isFirst = true; + m_beginEvt = true; m_tot_edep = 0; m_tot_length = 0; m_pa_KE =0; @@ -555,26 +557,16 @@ float* TrackHeedSimTool::NNPred(std::vector& inputs) void TrackHeedSimTool::endOfEvent() { if(m_sim_pulse){ - edm4hep::SimPrimaryIonizationClusterCollection* SimPrimaryIonizationCol = nullptr; - try{ - SimPrimaryIonizationCol = const_cast(m_SimPrimaryIonizationCol.get()); - } - catch(...){ - G4cout<<"Error! Can't find collection in event, please check it have been createAndPut() in Begin of event"< { double dndx(double betagamma) override; void getMom(float ee, float dx, float dy,float dz, float mom[3] ); void reset(){ + m_beginEvt = true; m_isFirst = true; m_previous_track_ID = 0; m_previous_KE = 0; m_tot_edep = 0; - //std::cout<<"m_tot_length="< { Gaudi::Property m_BField {this, "BField", -3}; Gaudi::Property m_eps { this, "eps" , 1e-6 };//very small value, it is returned dedx for unsimulated step (may needed for SimTrackerHit) // Output collections - DataHandle m_SimPrimaryIonizationCol{"SimPrimaryIonizationClusterCollection", Gaudi::DataHandle::Writer, this}; + DataHandle m_SimPrimaryIonizationColWriter{"SimPrimaryIonizationClusterCollection", Gaudi::DataHandle::Writer, this}; + edm4hep::SimPrimaryIonizationClusterCollection* m_SimPrimaryIonizationCol; // In order to associate MCParticle with contribution, we need to access MC Particle. DataHandle m_mc_handle{"MCParticle", Gaudi::DataHandle::Writer, this}; @@ -102,19 +103,20 @@ class TrackHeedSimTool: public extends { Sensor* m_sensor; std::map m_particle_map; - int m_previous_track_ID=0; - float m_previous_KE=0; + int m_previous_track_ID; + float m_previous_KE; int m_current_track_ID; int m_current_Parent_ID; int m_pdg_code; G4StepPoint* m_pre_point; G4StepPoint* m_post_point; G4double m_total_range; - bool m_isFirst=true; + bool m_isFirst; + bool m_beginEvt; bool m_change_track; edm4hep::MCParticle m_mc_paricle; - float m_tot_edep=0; - float m_tot_length=0; + float m_tot_edep; + float m_tot_length; float m_pa_KE; G4double m_pre_x ; @@ -147,12 +149,12 @@ class TrackHeedSimTool: public extends { Gaudi::Property m_sim_pulse { this, "sim_pulse" , true }; Gaudi::Property m_model_file{ this, "model", "model_test.onnx"}; Gaudi::Property m_batchsize { this, "batchsize", 100}; - Gaudi::Property m_time_scale { this, "time_scale", 99.0}; - Gaudi::Property m_time_shift { this, "time_shift", 166.4}; - Gaudi::Property m_amp_scale { this, "amp_scale" , 1e-2 }; - Gaudi::Property m_amp_shift { this, "amp_shift" , 0 }; - Gaudi::Property m_x_scale { this, "x_scale" , 5. };// in mm - Gaudi::Property m_y_scale { this, "y_scale" , 5. };// in mm + Gaudi::Property m_time_scale { this, "time_scale", 503.0}; + Gaudi::Property m_time_shift { this, "time_shift", 814.0}; + Gaudi::Property m_amp_scale { this, "amp_scale" , 1.15 }; + Gaudi::Property m_amp_shift { this, "amp_shift" , 0.86 }; + Gaudi::Property m_x_scale { this, "x_scale" , 9. };// in mm + Gaudi::Property m_y_scale { this, "y_scale" , 9. };// in mm diff --git a/Simulation/DetSimInterface/include/DetSimInterface/IDedxSimTool.h b/Simulation/DetSimInterface/include/DetSimInterface/IDedxSimTool.h index d4e8e9e4a..4da01d532 100644 --- a/Simulation/DetSimInterface/include/DetSimInterface/IDedxSimTool.h +++ b/Simulation/DetSimInterface/include/DetSimInterface/IDedxSimTool.h @@ -28,7 +28,6 @@ class IDedxSimTool: virtual public IAlgTool { virtual double dedx(const G4Step* aStep) = 0; virtual double dedx(const edm4hep::MCParticle& mc) = 0; virtual double dndx(double betagamma) = 0; - virtual void reset() {} virtual void endOfEvent() {} }; diff --git a/Simulation/DetSimSD/src/DriftChamberSensitiveDetector.cpp b/Simulation/DetSimSD/src/DriftChamberSensitiveDetector.cpp index c1d768021..44bf01d10 100644 --- a/Simulation/DetSimSD/src/DriftChamberSensitiveDetector.cpp +++ b/Simulation/DetSimSD/src/DriftChamberSensitiveDetector.cpp @@ -72,5 +72,4 @@ DriftChamberSensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory*) { void DriftChamberSensitiveDetector::EndOfEvent(G4HCofThisEvent* HCE) { m_dedx_simtool->endOfEvent(); - m_dedx_simtool->reset(); }