Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:35

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
0015 #include <DD4hep/InstanceCount.h>
0016 #include <DDG4/Geant4TrackingPostAction.h>
0017 #include <DDG4/Geant4TrackHandler.h>
0018 
0019 // Geant4 include files
0020 #include <G4TrackingManager.hh>
0021 
0022 // C/C++ include files
0023 #include <algorithm>
0024 
0025 using namespace dd4hep::sim;
0026 
0027 /// Helper class to manipulate strings
0028 /**
0029  *  \author  M.Frank
0030  *  \version 1.0
0031  *  \ingroup DD4HEP_SIMULATION
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   //template <class T> bool operator==(const std::pair<std::string,T>& cmp)  const
0042   //{  return cmp.first == m_name;  }
0043   //template <class T> bool operator==(const std::pair<T,std::string>& cmp)  const
0044   //{  return cmp.second == m_name;  }
0045 };
0046 
0047 /// Standard constructor
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 /// Default destructor
0057 Geant4TrackingPostAction::~Geant4TrackingPostAction() {
0058   InstanceCount::decrement(this);
0059 }
0060 
0061 /// Begin-of-tracking callback
0062 void Geant4TrackingPostAction::begin(const G4Track* track) {
0063 
0064   // Is the track valid? Is tracking manager valid?
0065   // Does trajectory already exist?
0066   if (0 == track || 0 == trackMgr() || 0 != trackMgr()->GimmeTrajectory())
0067     return;
0068   trackMgr()->SetStoreTrajectory(true);
0069   // create GaussTrajectory and inform Tracking Manager
0070   G4VTrajectory* tr = context()->createTrajectory(track);
0071   trackMgr()->SetTrajectory(tr);
0072 }
0073 
0074 /// End-of-tracking callback
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   //Geant4TrackInformation* info = track.info<Geant4TrackInformation>();
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