Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// $Id: Geant4Converter.cpp 603 2013-06-13 21:15:14Z markus.frank $
//====================================================================
// AIDA Detector description implementation for LCD
//--------------------------------------------------------------------
//
// Author : M.Frank
//
//====================================================================
// Framework include files
#include "DD4hep/InstanceCount.h"
#include "DDG4/Geant4TrackingAction.h"
// Geant4 include files
#include "G4Track.hh"
#include "G4TrackingManager.hh"
#include "G4VUserTrackInformation.hh"
// C/C++ include files
#include <stdexcept>
using namespace std;
using namespace DD4hep;
using namespace DD4hep::Simulation;
class G4Step;
class G4TouchableHistory;
/// Standard constructor
Geant4TrackingActionSequence::Geant4TrackingActionSequence(Geant4Context* context, const std::string& name)
: Geant4Action(context,name)
{
InstanceCount::increment(this);
}
/// Default destructor
Geant4TrackingActionSequence::~Geant4TrackingActionSequence() {
m_actors(&Geant4TrackingAction::release);
m_actors.clear();
m_begin.clear();
m_end.clear();
InstanceCount::decrement(this);
}
/// Add an actor responding to all callbacks. Sequence takes ownership.
void Geant4TrackingActionSequence::adopt(Geant4TrackingAction* action) {
if ( action ) {
action->addRef();
m_actors.add(action);
return;
}
throw std::runtime_error("Geant4TrackingActionSequence: Attempt to add invalid actor!");
}
/// Pre-track action callback
void Geant4TrackingActionSequence::begin(const G4Track* track) {
m_actors(&Geant4TrackingAction::begin,track);
m_begin(track);
}
/// Post-track action callback
void Geant4TrackingActionSequence::end(const G4Track* track) {
m_end(track);
m_actors(&Geant4TrackingAction::end,track);
}
/// Standard constructor
Geant4TrackingAction::Geant4TrackingAction(Geant4Context* context, const std::string& name)
: Geant4Action(context,name)
{
InstanceCount::increment(this);
}
/// Default destructor
Geant4TrackingAction::~Geant4TrackingAction() {
InstanceCount::decrement(this);
}
/// Pre-track action callback
void Geant4TrackingAction::begin(const G4Track* ) {
}
/// Post-track action callback
void Geant4TrackingAction::end(const G4Track* ) {
}
/// Get the valid Geant4 tarck information
Geant4TrackInformation* Geant4TrackingAction::trackInfo(G4Track* track) const {
if ( track ) {
Geant4TrackInformation* gau = 0;
G4VUserTrackInformation* g4 = track->GetUserInformation();
if ( 0 == g4 ) {
gau = new Geant4TrackInformation();
track->SetUserInformation(gau);
return gau; // RETURN
}
gau = fast_cast<Geant4TrackInformation*>(g4);
if( !gau ) {
error("trackInfo: invalid cast to Geant4TrajckInformation");
}
return gau ;
}
error("trackInfo: [Invalid G4Track]");
return 0;
}
/// Mark all children of the track to be stored
bool Geant4TrackingAction::storeChildren() const {
G4TrackVector* v = trackMgr()->GimmeSecondaries();
if( v ) { // loop over all children
for(G4TrackVector::const_iterator i = v->begin(); i != v->end(); ++i) {
G4Track* t = *i ;
if ( t ) {
storeChild(trackInfo(t));
}
}
return true;
}
return false;
}
/// Mark a single child of the track to be stored
bool Geant4TrackingAction::storeChild(Geant4TrackInformation* info) const {
if ( 0 != info ) {
if ( !info->storeTrack() ) {
info->storeTrack(true);
}
return true;
}
return error(false,"storeChild: Geant4TrackInformation points to NULL!");
}