File indexing completed on 2025-01-30 09:17:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/InstanceCount.h>
0016 #include <DDG4/Geant4TrackingPostAction.h>
0017 #include <DDG4/Geant4TrackHandler.h>
0018
0019
0020 #include <G4TrackingManager.hh>
0021
0022
0023 #include <algorithm>
0024
0025 using namespace dd4hep::sim;
0026
0027
0028
0029
0030
0031
0032
0033 struct FindString {
0034 const std::string& m_name;
0035 FindString(const std::string& n)
0036 : m_name(n) {
0037 }
0038 bool operator()(const std::string& n) const {
0039 return m_name == n;
0040 }
0041
0042
0043
0044
0045 };
0046
0047
0048 Geant4TrackingPostAction::Geant4TrackingPostAction(Geant4Context* ctxt, const std::string& nam)
0049 : Geant4TrackingAction(ctxt, nam) {
0050 InstanceCount::increment(this);
0051 declareProperty("IgnoredProcesses", m_ignoredProcs);
0052 declareProperty("RequiredProcesses", m_requiredProcs);
0053 declareProperty("StoreMarkedTracks", m_storeMarkedTracks=true);
0054 }
0055
0056
0057 Geant4TrackingPostAction::~Geant4TrackingPostAction() {
0058 InstanceCount::decrement(this);
0059 }
0060
0061
0062 void Geant4TrackingPostAction::begin(const G4Track* track) {
0063
0064
0065
0066 if (0 == track || 0 == trackMgr() || 0 != trackMgr()->GimmeTrajectory())
0067 return;
0068 trackMgr()->SetStoreTrajectory(true);
0069
0070 G4VTrajectory* tr = context()->createTrajectory(track);
0071 trackMgr()->SetTrajectory(tr);
0072 }
0073
0074
0075 void Geant4TrackingPostAction::end(const G4Track* tr) {
0076 if (0 == tr)
0077 return;
0078 else if (0 == trackMgr())
0079 return;
0080
0081 Geant4TrackHandler track(tr);
0082
0083 const std::string& proc = track.creatorProcess()->GetProcessName();
0084 StringV::const_iterator trIt = find_if(m_ignoredProcs.begin(), m_ignoredProcs.end(), FindString(proc));
0085 if (trIt != m_ignoredProcs.end()) {
0086 warning("Particles created by processes of type %s are not kept!", (*trIt).c_str());
0087 return;
0088 }
0089 trIt = find_if(m_requiredProcs.begin(), m_requiredProcs.end(), FindString(proc));
0090 if (trIt != m_requiredProcs.end()) {
0091 saveTrack(track);
0092 return;
0093 }
0094
0095 if (m_storeMarkedTracks) {
0096 }
0097
0098 }
0099
0100 void Geant4TrackingPostAction::saveTrack(const G4Track* track) {
0101 if (0 != track) {
0102 }
0103 }
0104