DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4TrackingPostAction.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DD4hep/InstanceCount.h>
18 
19 // Geant4 include files
20 #include <G4TrackingManager.hh>
21 
22 // C/C++ include files
23 #include <algorithm>
24 
25 using namespace dd4hep::sim;
26 
28 
33 struct FindString {
34  const std::string& m_name;
35  FindString(const std::string& n)
36  : m_name(n) {
37  }
38  bool operator()(const std::string& n) const {
39  return m_name == n;
40  }
41  //template <class T> bool operator==(const std::pair<std::string,T>& cmp) const
42  //{ return cmp.first == m_name; }
43  //template <class T> bool operator==(const std::pair<T,std::string>& cmp) const
44  //{ return cmp.second == m_name; }
45 };
46 
49 : Geant4TrackingAction(ctxt, nam) {
51  declareProperty("IgnoredProcesses", m_ignoredProcs);
52  declareProperty("RequiredProcesses", m_requiredProcs);
53  declareProperty("StoreMarkedTracks", m_storeMarkedTracks=true);
54 }
55 
59 }
60 
62 void Geant4TrackingPostAction::begin(const G4Track* track) {
63 
64  // Is the track valid? Is tracking manager valid?
65  // Does trajectory already exist?
66  if (0 == track || 0 == trackMgr() || 0 != trackMgr()->GimmeTrajectory())
67  return;
68  trackMgr()->SetStoreTrajectory(true);
69  // create GaussTrajectory and inform Tracking Manager
70  G4VTrajectory* tr = context()->createTrajectory(track);
71  trackMgr()->SetTrajectory(tr);
72 }
73 
75 void Geant4TrackingPostAction::end(const G4Track* tr) {
76  if (0 == tr)
77  return;
78  else if (0 == trackMgr())
79  return;
80 
81  Geant4TrackHandler track(tr);
82  //Geant4TrackInformation* info = track.info<Geant4TrackInformation>();
83  const std::string& proc = track.creatorProcess()->GetProcessName();
84  StringV::const_iterator trIt = find_if(m_ignoredProcs.begin(), m_ignoredProcs.end(), FindString(proc));
85  if (trIt != m_ignoredProcs.end()) {
86  warning("Particles created by processes of type %s are not kept!", (*trIt).c_str());
87  return;
88  }
89  trIt = find_if(m_requiredProcs.begin(), m_requiredProcs.end(), FindString(proc));
90  if (trIt != m_requiredProcs.end()) {
91  saveTrack(track);
92  return;
93  }
94 
95  if (m_storeMarkedTracks) {
96  }
97 
98 }
99 
100 void Geant4TrackingPostAction::saveTrack(const G4Track* track) {
101  if (0 != track) {
102  }
103 }
104 
Geant4TrackHandler.h
dd4hep::sim::Geant4TrackingPostAction::~Geant4TrackingPostAction
virtual ~Geant4TrackingPostAction()
Default destructor.
Definition: Geant4TrackingPostAction.cpp:57
FindString
Helper class to manipulate strings.
Definition: Geant4TrackingPostAction.cpp:33
dd4hep::sim::Geant4TrackingPostAction::saveTrack
void saveTrack(const G4Track *track)
Definition: Geant4TrackingPostAction.cpp:100
FindString::m_name
const std::string & m_name
Definition: Geant4TrackingPostAction.cpp:34
FindString::operator()
bool operator()(const std::string &n) const
Definition: Geant4TrackingPostAction.cpp:38
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Geant4TrackingPostAction::end
virtual void end(const G4Track *track) override
End-of-tracking callback.
Definition: Geant4TrackingPostAction.cpp:75
FindString::FindString
FindString(const std::string &n)
Definition: Geant4TrackingPostAction.cpp:35
dd4hep::sim::Geant4Action::warning
void warning(const char *fmt,...) const
Support of warning messages.
Definition: Geant4Action.cpp:223
dd4hep::sim::Geant4TrackingPostAction::m_storeMarkedTracks
bool m_storeMarkedTracks
Definition: Geant4TrackingPostAction.h:37
dd4hep::sim::Geant4TrackingPostAction::m_requiredProcs
StringV m_requiredProcs
Definition: Geant4TrackingPostAction.h:35
dd4hep::sim::Geant4Action::declareProperty
Geant4Action & declareProperty(const std::string &nam, T &val)
Declare property.
Definition: Geant4Action.h:366
dd4hep::sim::Geant4TrackHandler::creatorProcess
const G4VProcess * creatorProcess() const
Physical process of the track generation.
Definition: Geant4TrackHandler.h:174
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Geant4TrackHandler
Helper class to ease the extraction of information from a G4Track object.
Definition: Geant4TrackHandler.h:53
dd4hep::sim::Geant4TrackingPostAction::begin
virtual void begin(const G4Track *track) override
Begin-of-tracking callback.
Definition: Geant4TrackingPostAction.cpp:62
dd4hep::sim::Geant4TrackingAction::trackMgr
G4TrackingManager * trackMgr() const
Access the Geant4 tracking manager. Only use between tracking pre- and post action.
Definition: Geant4TrackingAction.h:53
Geant4TrackingPostAction.h
dd4hep::sim::Geant4Context::createTrajectory
virtual G4VTrajectory * createTrajectory(const G4Track *track) const
Create a user trajectory.
Definition: Geant4Context.cpp:101
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4TrackingAction
Default base class for all geant 4 tracking actions used in DDG4.
Definition: Geant4TrackingAction.h:41
dd4hep::sim::Geant4TrackingPostAction::m_ignoredProcs
StringV m_ignoredProcs
Definition: Geant4TrackingPostAction.h:36
dd4hep::sim::Geant4TrackingPostAction::Geant4TrackingPostAction
Geant4TrackingPostAction(Geant4Context *context, const std::string &name="")
Standard constructor.
Definition: Geant4TrackingPostAction.cpp:48
InstanceCount.h
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270