Skip to content

Commit

Permalink
check if TrackHeedSimTool exist in Edm4hepWriterAnaElemTool
Browse files Browse the repository at this point in the history
  • Loading branch information
wenxingfang committed Nov 9, 2023
1 parent 1b76060 commit 3aac145
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
1 change: 0 additions & 1 deletion Examples/options/tut_detsim_SDT_Heed.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@
dedx_simtool.save_mc = True##IF this is False then ...
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_test.onnx'
#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'
dedx_simtool.batchsize = 100
Expand Down
25 changes: 12 additions & 13 deletions Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "DDG4/Geant4HitCollection.h"
#include "DDG4/Geant4Data.h"
#include "DetSimSD/Geant4Hits.h"
#include <DetSimInterface/IDedxSimTool.h>

DECLARE_COMPONENT(Edm4hepWriterAnaElemTool)

Expand Down Expand Up @@ -90,11 +89,9 @@ Edm4hepWriterAnaElemTool::BeginOfEventAction(const G4Event* anEvent) {
m_track2primary.clear();

auto SimPIonCol = m_SimPrimaryIonizationCol.createAndPut();
ToolHandleArray<IDedxSimTool> tmp_m_dedx_tools;
tmp_m_dedx_tools.push_back("TrackHeedSimTool");
for (auto dedxtool: tmp_m_dedx_tools) {
debug() << "reset dedx_tool:" <<dedxtool << endmsg;
dedxtool->reset();
if(hasTrackHeedSimTool){
debug() << "reset TrackHeedSimTool" << endmsg;
m_TrackHeedSimTool->reset();
}

}
Expand All @@ -106,14 +103,10 @@ Edm4hepWriterAnaElemTool::EndOfEventAction(const G4Event* anEvent) {
// save all data
auto SimPrimaryIonizationCol = m_SimPrimaryIonizationCol.get();
msg() << "SimPrimaryIonizationCol size ="<<SimPrimaryIonizationCol->size()<<endmsg;
ToolHandleArray<IDedxSimTool> tmp_m_dedx_tools;
tmp_m_dedx_tools.push_back("TrackHeedSimTool");
for (auto dedxtool: tmp_m_dedx_tools) {
debug() << "call endOfEvent() for dedx_tool:" << dedxtool << endmsg;
dedxtool->endOfEvent();
if(hasTrackHeedSimTool){
debug() << "call endOfEvent() for TrackHeedSimTool" << endmsg;
m_TrackHeedSimTool->endOfEvent();
}


// create collections.
auto trackercols = m_trackerCol.createAndPut();
auto calorimetercols = m_calorimeterCol.createAndPut();
Expand Down Expand Up @@ -580,6 +573,12 @@ StatusCode
Edm4hepWriterAnaElemTool::initialize() {
StatusCode sc;

m_TrackHeedSimTool = ToolHandle<IDedxSimTool>("TrackHeedSimTool",nullptr,false);
if(m_TrackHeedSimTool){
msg() << "find TrackHeedSimTool" << endmsg;
hasTrackHeedSimTool = true;
}

return sc;
}

Expand Down
3 changes: 3 additions & 0 deletions Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "edm4hep/SimCalorimeterHitCollection.h"
#include "edm4hep/CaloHitContributionCollection.h"
#include "edm4hep/SimPrimaryIonizationClusterCollection.h"
#include <DetSimInterface/IDedxSimTool.h>

class Edm4hepWriterAnaElemTool: public extends<AlgTool, IAnaElemTool> {

Expand Down Expand Up @@ -155,6 +156,8 @@ class Edm4hepWriterAnaElemTool: public extends<AlgTool, IAnaElemTool> {
double Z = 0;

bool verboseOutput = false;
ToolHandle<IDedxSimTool> m_TrackHeedSimTool;
bool hasTrackHeedSimTool = false;
};

#endif

0 comments on commit 3aac145

Please sign in to comment.