DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4TrackingAction.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>
19 
20 // Geant4 include files
21 #include <G4Track.hh>
22 #include <G4Threading.hh>
23 #include <G4AutoLock.hh>
24 #include <G4TrackingManager.hh>
25 #include <G4VUserTrackInformation.hh>
26 
27 using namespace dd4hep::sim;
28 
29 class G4Step;
30 class G4TouchableHistory;
31 namespace {
32  G4Mutex action_mutex=G4MUTEX_INITIALIZER;
33 }
34 
37  : Geant4Action(ctxt, nam) {
38  m_needsControl = true;
40 }
41 
45  m_actors.clear();
46  m_front.clear();
47  m_final.clear();
48  m_begin.clear();
49  m_end.clear();
51 }
52 
55  m_context = ctxt;
56  m_actors.updateContext(ctxt);
57 }
58 
61  m_actors(&Geant4Action::configureFiber, thread_context);
62 }
63 
66  return m_actors.get(FindByName(TypeName::split(nam).second));
67 }
68 
71  if (action) {
72  G4AutoLock protection_lock(&action_mutex);
73  action->addRef();
74  m_actors.add(action);
75  return;
76  }
77  throw std::runtime_error("Geant4TrackingActionSequence: Attempt to add invalid actor!");
78 }
79 
81 void Geant4TrackingActionSequence::begin(const G4Track* track) {
82  m_front(track);
84  m_begin(track);
85 }
86 
88 void Geant4TrackingActionSequence::end(const G4Track* track) {
89  m_end(track);
91  m_final(track);
92 }
93 
96  : Geant4Action(ctxt, nam) {
98 }
99 
103 }
104 
106 void Geant4TrackingAction::begin(const G4Track*) {
107 }
108 
110 void Geant4TrackingAction::end(const G4Track*) {
111 }
112 
114 void Geant4TrackingAction::mark(const G4Track* track) const {
116  if ( truth ) truth->mark(track,true);
117 }
118 
121  : Geant4TrackingAction(ctxt, nam), m_action(0)
122 {
124 }
125 
128  detail::releasePtr(m_action);
130 }
131 
134  m_action->configureFiber(thread_context);
135 }
136 
139  if (action) {
140  action->addRef();
141  m_properties.adopt(action->properties());
142  m_action = action;
143  return;
144  }
145  except("Attempt to use invalid actor!");
146 }
147 
149 void Geant4SharedTrackingAction::begin(const G4Track* track) {
150  if ( m_action ) {
151  G4AutoLock protection_lock(&action_mutex); {
152  ContextSwap swap(m_action,context());
153  m_action->begin(track);
154  }
155  }
156 }
157 
159 void Geant4SharedTrackingAction::end(const G4Track* track) {
160  if ( m_action ) {
161  G4AutoLock protection_lock(&action_mutex); {
162  ContextSwap swap(m_action,context());
163  m_action->end(track);
164  }
165  }
166 }
Geant4MonteCarloTruth.h
dd4hep::sim::Geant4SharedTrackingAction::m_action
Geant4TrackingAction * m_action
Reference to the shared action.
Definition: Geant4TrackingAction.h:80
dd4hep::sim::Geant4Action::m_needsControl
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:123
dd4hep::sim::Geant4TrackingActionSequence::end
virtual void end(const G4Track *track)
Post-tracking action callback.
Definition: Geant4TrackingAction.cpp:88
dd4hep::sim::Geant4TrackingActionSequence::adopt
void adopt(Geant4TrackingAction *action)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4TrackingAction.cpp:70
dd4hep::sim::Geant4Action::configureFiber
virtual void configureFiber(Geant4Context *thread_context)
Set or update client for the use in a new thread fiber.
Definition: Geant4Action.cpp:140
dd4hep::sim::Geant4TrackingAction::begin
virtual void begin(const G4Track *track)
Pre-track action callback.
Definition: Geant4TrackingAction.cpp:106
dd4hep::sim::Geant4Action::FindByName
Functor to access elements by name.
Definition: Geant4Action.h:157
dd4hep::sim::Geant4Action::m_context
Geant4Context * m_context
Reference to the Geant4 context.
Definition: Geant4Action.h:116
Geant4TrackingAction.h
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Geant4Context::event
Geant4Event & event() const
Access the geant4 event – valid only between BeginEvent() and EndEvent()!
Definition: Geant4Context.cpp:84
dd4hep::sim::Geant4TrackingActionSequence::begin
virtual void begin(const G4Track *track)
Pre-tracking action callback.
Definition: Geant4TrackingAction.cpp:81
dd4hep::sim::Geant4Action::ContextSwap
Functor to update the context of a Geant4Action object.
Definition: Geant4Action.h:138
dd4hep::sim::Geant4Action::m_properties
PropertyManager m_properties
Property pool.
Definition: Geant4Action.h:127
Geant4TrackInformation.h
dd4hep::sim::Geant4TrackingActionSequence::get
Geant4TrackingAction * get(const std::string &name) const
Get an action by name.
Definition: Geant4TrackingAction.cpp:65
dd4hep::sim::Geant4TrackingAction::end
virtual void end(const G4Track *track)
Post-track action callback.
Definition: Geant4TrackingAction.cpp:110
dd4hep::sim::Geant4Event::extension
T * extension(bool alert=true)
Access to type safe extension object. Exception is thrown if the object is invalid.
Definition: Geant4Context.h:151
dd4hep::sim::Geant4Action::except
void except(const char *fmt,...) const
Support of exceptions: Print fatal message and throw runtime_error.
Definition: Geant4Action.cpp:256
dd4hep::sim::Geant4SharedTrackingAction::configureFiber
virtual void configureFiber(Geant4Context *thread_context) override
Set or update client for the use in a new thread fiber.
Definition: Geant4TrackingAction.cpp:133
dd4hep::sim::Geant4SharedTrackingAction::end
virtual void end(const G4Track *track) override
End-of-track callback.
Definition: Geant4TrackingAction.cpp:159
dd4hep::PropertyManager::adopt
void adopt(const PropertyManager &copy)
Import properties of another instance.
Definition: ComponentProperties.cpp:97
dd4hep::sim::Geant4TrackingAction::Geant4TrackingAction
Geant4TrackingAction(Geant4Context *context, const std::string &name="")
Standard constructor.
Definition: Geant4TrackingAction.cpp:95
dd4hep::sim::Geant4SharedTrackingAction::~Geant4SharedTrackingAction
virtual ~Geant4SharedTrackingAction()
Default destructor.
Definition: Geant4TrackingAction.cpp:127
dd4hep::sim::Geant4SharedTrackingAction::Geant4SharedTrackingAction
Geant4SharedTrackingAction(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4TrackingAction.cpp:120
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Geant4MonteCarloTruth
Default Interface class to handle monte carlo truth records.
Definition: Geant4MonteCarloTruth.h:43
dd4hep::sim::Geant4SharedTrackingAction::use
virtual void use(Geant4TrackingAction *action)
Underlying object to be used during the execution of this thread.
Definition: Geant4TrackingAction.cpp:138
dd4hep::sim::Geant4Action
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:113
dd4hep::sim::Geant4Action::release
long release()
Decrease reference count. Implicit destruction.
Definition: Geant4Action.cpp:76
dd4hep::sim::Geant4TrackingAction::~Geant4TrackingAction
virtual ~Geant4TrackingAction()
Default destructor.
Definition: Geant4TrackingAction.cpp:101
dd4hep::CallbackSequence::clear
void clear()
Clear the sequence and remove all callbacks.
Definition: Callback.h:363
dd4hep::sim::TypeName::split
static TypeName split(const std::string &type_name)
Split string pair according to default delimiter ('/')
Definition: Geant4Action.cpp:40
dd4hep::sim::Geant4Action::properties
PropertyManager & properties()
Access to the properties of the object.
Definition: Geant4Action.h:292
dd4hep::sim::Geant4TrackingActionSequence::configureFiber
virtual void configureFiber(Geant4Context *thread_context) override
Set or update client for the use in a new thread fiber.
Definition: Geant4TrackingAction.cpp:60
dd4hep::sim::Geant4TrackingActionSequence::~Geant4TrackingActionSequence
virtual ~Geant4TrackingActionSequence()
Default destructor.
Definition: Geant4TrackingAction.cpp:43
dd4hep::sim::Geant4Action::addRef
long addRef()
Increase reference count.
Definition: Geant4Action.cpp:71
dd4hep::sim::Geant4SharedTrackingAction::begin
virtual void begin(const G4Track *track) override
Begin-of-track callback.
Definition: Geant4TrackingAction.cpp:149
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::Geant4TrackingActionSequence::m_begin
CallbackSequence m_begin
Callback sequence for pre tracking action.
Definition: Geant4TrackingAction.h:119
dd4hep::sim::Geant4TrackingActionSequence::m_front
CallbackSequence m_front
Callback sequence for pre tracking action.
Definition: Geant4TrackingAction.h:117
dd4hep::sim::Geant4TrackingActionSequence::m_end
CallbackSequence m_end
Callback sequence for post tracking action.
Definition: Geant4TrackingAction.h:121
dd4hep::sim::Geant4TrackingActionSequence::m_actors
Actors< Geant4TrackingAction > m_actors
The list of action objects to be called.
Definition: Geant4TrackingAction.h:125
dd4hep::sim::Geant4TrackingActionSequence::m_final
CallbackSequence m_final
Callback sequence for pre tracking action.
Definition: Geant4TrackingAction.h:123
dd4hep::sim::Geant4TrackingActionSequence::Geant4TrackingActionSequence
Geant4TrackingActionSequence(Geant4Context *context, const std::string &name)
Standard constructor.
Definition: Geant4TrackingAction.cpp:36
dd4hep::sim::Geant4TrackingActionSequence::updateContext
virtual void updateContext(Geant4Context *ctxt) override
Set or update client context.
Definition: Geant4TrackingAction.cpp:54
dd4hep::sim::Geant4MonteCarloTruth::mark
virtual void mark(const G4Track *track)=0
Mark a Geant4 track to be kept for later MC truth analysis.
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
dd4hep::sim::Geant4TrackingAction::mark
void mark(const G4Track *track) const
Mark the track to be kept for MC truth propagation.
Definition: Geant4TrackingAction.cpp:114