Geant4 VMC
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
source
physics
src
TG4StackPopper.cxx
Go to the documentation of this file.
1
//------------------------------------------------
2
// The Geant4 Virtual Monte Carlo package
3
// Copyright (C) 2007 - 2014 Ivana Hrivnacova
4
// All rights reserved.
5
//
6
// For the licensing terms see geant4_vmc/LICENSE.
7
// Contact: root-vmc@cern.ch
8
//-------------------------------------------------
9
14
15
#include "
TG4StackPopper.h
"
16
#include "
TG4G3Units.h
"
17
#include "
TG4ParticlesManager.h
"
18
#include "
TG4TrackInformation.h
"
19
20
#include <G4IonTable.hh>
21
#include <G4Track.hh>
22
23
#include <TParticle.h>
24
#include <TVirtualMC.h>
25
#include <TVirtualMCStack.h>
26
27
G4ThreadLocal
TG4StackPopper
*
TG4StackPopper::fgInstance
= 0;
28
29
//_____________________________________________________________________________
30
TG4StackPopper::TG4StackPopper
(
const
G4String& processName)
31
:
G4VProcess
(processName, fUserDefined),
32
fMCStack
(0),
33
fNofDoneTracks
(0),
34
fDoExclusiveStep
(false)
35
{
37
38
if
(
fgInstance
) {
39
TG4Globals::Exception
(
"TG4StackPopper"
,
"TG4StackPopper"
,
40
"Cannot create two instances of singleton."
);
41
}
42
43
fgInstance
=
this
;
44
45
// Set process sub type
46
SetProcessSubType(
fStackPopper
);
47
48
// Cache thread-local pointers
49
fMCStack
= gMC->GetStack();
50
}
51
52
//_____________________________________________________________________________
53
TG4StackPopper::~TG4StackPopper
()
54
{
56
57
fgInstance
= 0;
58
}
59
60
//
61
// public methods
62
//
63
64
//_____________________________________________________________________________
65
G4double
TG4StackPopper::PostStepGetPhysicalInteractionLength
(
66
const
G4Track&
/*track*/
, G4double
/*notUsed*/
, G4ForceCondition* condition)
67
{
70
71
*condition = InActivated;
72
if
(
HasPoppedTracks
()) {
73
if
(
fDoExclusiveStep
) {
74
*condition = ExclusivelyForced;
75
}
76
else
{
77
*condition = StronglyForced;
78
}
79
}
80
81
return
DBL_MAX;
82
}
83
84
//_____________________________________________________________________________
85
G4VParticleChange*
TG4StackPopper::PostStepDoIt
(
86
const
G4Track& track,
const
G4Step&
/*step*/
)
87
{
89
90
aParticleChange.Initialize(track);
91
92
if
(
fMCStack
->GetNtrack() ==
fNofDoneTracks
)
return
&aParticleChange;
93
94
Int_t currentTrackId =
fMCStack
->GetCurrentTrackNumber();
95
Int_t nofTracksToPop =
fMCStack
->GetNtrack() -
fNofDoneTracks
;
96
aParticleChange.SetNumberOfSecondaries(
97
aParticleChange.GetNumberOfSecondaries() + nofTracksToPop);
98
99
for
(G4int i = 0; i < nofTracksToPop; ++i) {
100
101
// Pop particle from the stack
102
G4int itrack;
103
TParticle* particle =
fMCStack
->PopNextTrack(itrack);
104
++
fNofDoneTracks
;
105
106
if
(!particle) {
107
TG4Globals::Exception
(
108
"TG4StackPopper"
,
"PostStepDoIt"
,
"No particle popped from stack!"
);
109
return
&aParticleChange;
110
}
111
112
// G4cout << "TG4StackPopper::PostStepDoIt: Popped particle = "
113
// << particle->GetName()
114
// << " trackID = "<< itrack << G4endl;
115
116
// Create dynamic particle
117
G4DynamicParticle* dynamicParticle =
118
TG4ParticlesManager::Instance
()->
CreateDynamicParticle
(particle);
119
if
(!dynamicParticle) {
120
TG4Globals::Exception
(
"TG4StackPopper"
,
"PostStepDoIt"
,
121
"Conversion from Root particle -> G4 particle failed."
);
122
}
123
124
// Define track
125
126
G4ThreeVector position =
127
TG4ParticlesManager::Instance
()->
GetParticlePosition
(particle);
128
G4double time = particle->T() *
TG4G3Units::Time
();
129
130
G4Track* secondaryTrack =
new
G4Track(dynamicParticle, time, position);
131
132
// set track information here to avoid saving track in the stack
133
// for the second time
134
TG4TrackInformation
* trackInformation =
new
TG4TrackInformation
(itrack);
135
// the track information is deleted together with its
136
// G4Track object
137
trackInformation->
SetIsUserTrack
(
true
);
138
trackInformation->
SetPDGEncoding
(particle->GetPdgCode());
139
secondaryTrack->SetUserInformation(trackInformation);
140
141
// Add track as a secondary
142
aParticleChange.AddSecondary(secondaryTrack);
143
}
144
145
// Set back current track number in the track
146
// (as stack may have changed it with popping particles)
147
fMCStack
->SetCurrentTrack(currentTrackId);
148
149
// Set the kept track status if in exclusive step
150
if
(
fDoExclusiveStep
) {
151
aParticleChange.ProposeTrackStatus(
fTrackStatus
);
152
fDoExclusiveStep
=
false
;
153
}
154
155
return
&aParticleChange;
156
}
157
158
//_____________________________________________________________________________
159
void
TG4StackPopper::Notify
()
160
{
162
163
++
fNofDoneTracks
;
164
}
165
166
//_____________________________________________________________________________
167
void
TG4StackPopper::Reset
()
168
{
171
172
fNofDoneTracks
=
fMCStack
->GetNtrack();
173
}
174
175
//_____________________________________________________________________________
176
void
TG4StackPopper::SetDoExclusiveStep
(G4TrackStatus trackStatus)
177
{
179
180
fDoExclusiveStep
=
true
;
181
fTrackStatus
= trackStatus;
182
}
183
184
//_____________________________________________________________________________
185
G4bool
TG4StackPopper::HasPoppedTracks
()
const
186
{
188
189
return
(gMC->GetStack()->GetNtrack() !=
fNofDoneTracks
);
190
}
TG4G3Units.h
Definition of the TG4G3Units class.
TG4ParticlesManager.h
Definition of the TG4ParticlesManager class.
TG4StackPopper.h
Definition of the TG4StackPopper class.
TG4TrackInformation.h
Definition of the TG4TrackInformation class.
G4VProcess
TG4G3Units::Time
static G4double Time()
Definition
TG4G3Units.h:93
TG4Globals::Exception
static void Exception(const TString &className, const TString &methodName, const TString &text)
Definition
TG4Globals.cxx:33
TG4ParticlesManager::CreateDynamicParticle
G4DynamicParticle * CreateDynamicParticle(const TParticle *particle) const
Definition
TG4ParticlesManager.cxx:563
TG4ParticlesManager::GetParticlePosition
G4ThreeVector GetParticlePosition(const TParticle *particle) const
Definition
TG4ParticlesManager.cxx:587
TG4ParticlesManager::Instance
static TG4ParticlesManager * Instance()
Definition
TG4ParticlesManager.h:127
TG4StackPopper
The process which pops particles defined by user from the VMC stack and passes them to tracking.
Definition
TG4StackPopper.h:41
TG4StackPopper::HasPoppedTracks
G4bool HasPoppedTracks() const
Definition
TG4StackPopper.cxx:185
TG4StackPopper::SetDoExclusiveStep
void SetDoExclusiveStep(G4TrackStatus trackStatus)
Definition
TG4StackPopper.cxx:176
TG4StackPopper::fgInstance
static G4ThreadLocal TG4StackPopper * fgInstance
this instance
Definition
TG4StackPopper.h:101
TG4StackPopper::fTrackStatus
G4TrackStatus fTrackStatus
The track status to be restored after performing exclusive step.
Definition
TG4StackPopper.h:116
TG4StackPopper::TG4StackPopper
TG4StackPopper(const G4String &processName="stackPopper")
Definition
TG4StackPopper.cxx:30
TG4StackPopper::PostStepDoIt
virtual G4VParticleChange * PostStepDoIt(const G4Track &track, const G4Step &step)
Definition
TG4StackPopper.cxx:85
TG4StackPopper::fMCStack
TVirtualMCStack * fMCStack
Cached pointer to thread-local VMC stack.
Definition
TG4StackPopper.h:104
TG4StackPopper::fDoExclusiveStep
G4bool fDoExclusiveStep
Definition
TG4StackPopper.h:113
TG4StackPopper::fNofDoneTracks
G4int fNofDoneTracks
the counter for popped tracks
Definition
TG4StackPopper.h:107
TG4StackPopper::PostStepGetPhysicalInteractionLength
virtual G4double PostStepGetPhysicalInteractionLength(const G4Track &track, G4double previousStepSize, G4ForceCondition *condition)
Definition
TG4StackPopper.cxx:65
TG4StackPopper::Reset
void Reset()
Definition
TG4StackPopper.cxx:167
TG4StackPopper::~TG4StackPopper
virtual ~TG4StackPopper()
Definition
TG4StackPopper.cxx:53
TG4StackPopper::Notify
void Notify()
Definition
TG4StackPopper.cxx:159
TG4TrackInformation
Defines additional track information.
Definition
TG4TrackInformation.h:31
TG4TrackInformation::SetIsUserTrack
void SetIsUserTrack(G4bool isUserTrack)
TG4TrackInformation::SetPDGEncoding
void SetPDGEncoding(G4int pdgEncoding)
fStackPopper
@ fStackPopper
Definition
TG4StackPopper.h:31
Generated on
for Geant4 VMC by
1.17.0