DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4TrackingAction.cpp
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 
15 // Framework include files
16 #include "DD4hep/InstanceCount.h"
20 
21 // Geant4 include files
22 #include "G4Track.hh"
23 #include "G4Threading.hh"
24 #include "G4AutoLock.hh"
25 #include "G4TrackingManager.hh"
26 #include "G4VUserTrackInformation.hh"
27 
28 // C/C++ include files
29 #include <stdexcept>
30 
31 using namespace std;
32 using namespace DD4hep;
33 using namespace DD4hep::Simulation;
34 class G4Step;
35 class G4TouchableHistory;
36 namespace {
37  G4Mutex action_mutex=G4MUTEX_INITIALIZER;
38 }
39 
41 Geant4TrackingActionSequence::Geant4TrackingActionSequence(Geant4Context* ctxt, const string& nam)
42  : Geant4Action(ctxt, nam) {
43  m_needsControl = true;
45 }
46 
50  m_actors.clear();
51  m_front.clear();
52  m_final.clear();
53  m_begin.clear();
54  m_end.clear();
56 }
57 
60  m_context = ctxt;
61  m_actors.updateContext(ctxt);
62 }
63 
66  m_actors(&Geant4Action::configureFiber, thread_context);
67 }
68 
71  return m_actors.get(FindByName(TypeName::split(nam).second));
72 }
73 
76  if (action) {
77  G4AutoLock protection_lock(&action_mutex);
78  action->addRef();
79  m_actors.add(action);
80  return;
81  }
82  throw runtime_error("Geant4TrackingActionSequence: Attempt to add invalid actor!");
83 }
84 
86 void Geant4TrackingActionSequence::begin(const G4Track* track) {
87  m_front(track);
89  m_begin(track);
90 }
91 
93 void Geant4TrackingActionSequence::end(const G4Track* track) {
94  m_end(track);
96  m_final(track);
97 }
98 
101  : Geant4Action(ctxt, nam) {
103 }
104 
108 }
109 
111 void Geant4TrackingAction::begin(const G4Track*) {
112 }
113 
115 void Geant4TrackingAction::end(const G4Track*) {
116 }
117 
119 void Geant4TrackingAction::mark(const G4Track* track) const {
121  if ( truth ) truth->mark(track,true);
122 }
123 
126  : Geant4TrackingAction(ctxt, nam)
127 {
129 }
130 
135 }
136 
139  m_action->configureFiber(thread_context);
140 }
141 
144  if (action) {
145  action->addRef();
146  m_properties.adopt(action->properties());
147  m_action = action;
148  return;
149  }
150  throw runtime_error("Geant4SharedTrackingAction: Attempt to use invalid actor!");
151 }
152 
154 void Geant4SharedTrackingAction::begin(const G4Track* track) {
155  if ( m_action ) {
156  G4AutoLock protection_lock(&action_mutex); {
157  ContextSwap swap(m_action,context());
158  m_action->begin(track);
159  }
160  }
161 }
162 
164 void Geant4SharedTrackingAction::end(const G4Track* track) {
165  if ( m_action ) {
166  G4AutoLock protection_lock(&action_mutex); {
167  ContextSwap swap(m_action,context());
168  m_action->end(track);
169  }
170  }
171 }
Functor to access elements by name.
Definition: Geant4Action.h:135
virtual void use(Geant4TrackingAction *action)
Underlying object to be used during the execution of this thread.
CallbackSequence m_front
Callback sequence for pre tracking action.
virtual void mark(const G4Track *track)=0
Mark a Geant4 track to be kept for later MC truth analysis.
Geant4TrackingAction * get(const std::string &name) const
Get an action by name.
long release()
Decrease reference count. Implicit destruction.
Geant4Event & event() const
Access the geant4 event – valid only between BeginEvent() and EndEvent()!
Geant4TrackingAction * m_action
Reference to the shared action.
void adopt(Geant4TrackingAction *action)
Add an actor responding to all callbacks. Sequence takes ownership.
Default Interface class to handle monte carlo truth records.
virtual void configureFiber(Geant4Context *thread_context)
Set or update client for the use in a new thread fiber.
static void decrement(T *)
Decrement count according to type information.
void adopt(const PropertyManager &copy)
Export properties of another instance.
Default base class for all geant 4 tracking actions used in DDG4.
virtual void configureFiber(Geant4Context *thread_context)
Set or update client for the use in a new thread fiber.
virtual void end(const G4Track *track)
Post-tracking action callback.
void mark(const G4Track *track) const
Mark the track to be kept for MC truth propagation.
Actors< Geant4TrackingAction > m_actors
The list of action objects to be called.
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:261
CallbackSequence m_final
Callback sequence for pre tracking action.
virtual void begin(const G4Track *track)
Pre-track action callback.
Geant4Context * m_context
Reference to the Geant4 context.
Definition: Geant4Action.h:94
virtual void end(const G4Track *track)
End-of-track callback.
void releasePtr(T &p)
Helper to delete objects from heap and reset the pointer. Saves many many lines of code...
Definition: Primitives.h:316
PropertyManager & properties()
Access to the properties of the object.
Definition: Geant4Action.h:283
virtual ~Geant4TrackingActionSequence()
Default destructor.
virtual void configureFiber(Geant4Context *thread_context)
Set or update client for the use in a new thread fiber.
CallbackSequence m_end
Callback sequence for post tracking action.
long addRef()
Increase reference count.
void clear()
Clear the sequence and remove all callbacks.
Definition: Callback.h:358
CallbackSequence m_begin
Callback sequence for pre tracking action.
T * extension(bool alert=true)
Access to type safe extension object. Exception is thrown if the object is invalid.
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:101
Geant4SharedTrackingAction(const Geant4TrackingAction &copy)=delete
Inhibit copy constructor.
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
Functor to update the context of a Geant4Action object.
Definition: Geant4Action.h:116
static TypeName split(const std::string &type_name)
Split string pair according to default delimiter ('/')
virtual void updateContext(Geant4Context *ctxt)
Set or update client context.
Generic context to extend user, run and event information.
virtual void begin(const G4Track *track)
Begin-of-track callback.
PropertyManager m_properties
Property pool.
Definition: Geant4Action.h:105
virtual void end(const G4Track *track)
Post-track action callback.
static const double second
Definition: DD4hepUnits.h:112
virtual ~Geant4TrackingAction()
Default destructor.
Geant4TrackingAction(const Geant4TrackingAction &copy)=delete
Inhibit copy constructor.
virtual ~Geant4SharedTrackingAction()
Default destructor.
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:91
virtual void begin(const G4Track *track)
Pre-tracking action callback.