27#include <TMCManager.h>
30#include <TMCManagerStack.h>
31#include <TMCParticleStatus.h>
32#include <TVirtualMC.h>
33#include <TVirtualMCApplication.h>
35#include <G4PrimaryParticle.hh>
36#include <G4PrimaryVertex.hh>
37#include <G4SystemOfUnits.hh>
38#include <G4TrackVector.hh>
39#include <G4TrackingManager.hh>
40#include <G4UImanager.hh>
48 fG4TrackingManager(0),
53 fSaveDynamicCharge(false),
56 fNofSavedSecondaries(0)
66 fRootNavMgr(TG4RootNavMgr::GetInstance()),
67 fMCManager(TMCManager::Instance())
74 "Cannot create two instances of singleton.");
99#if (defined(USE_G4ROOT) && (!defined(USE_ROOT_VMC) || \
100 (ROOT_VERSION_CODE >= ROOT_VERSION(6, 18, 6))))
102 if (fMCManager && fRootNavMgr) {
103 fRootNavMgr->SetGeometryRestoreFunction([
this](Int_t g4TrackId) -> Bool_t {
104 return fMCManager->RestoreGeometryState(
132 const G4Track* track, G4bool overWrite)
140 "G4TrackingManager has not been set.");
158 if (trackIndex < 0) {
160 G4int trackID = track->GetTrackID();
161 G4int parentID = track->GetParentID();
189 if (overWrite) trackIndex--;
197 G4cout <<
"TG4TrackManager::SetTrackInformation: setting " << trackIndex
218 "G4TrackingManager has not been set.");
223 const G4TrackVector* secondaryTracks =
226 if (!secondaryTracks)
return;
230 G4Track* secondary = (*secondaryTracks)[i];
237 "Parent track has no TG4TrackInformation set.");
253 secondary->SetUserInformation(trackInfo);
267 aTrack->GetDynamicParticle()->GetDefinition();
272#ifdef STACK_WITH_KEEP_FLAG
283 if (VerboseLevel() > 2) G4cout <<
"TG4TrackManager::TrackToStack" << G4endl;
286 G4int parentID = track->GetParentID();
292 motherIndex = GetTrackInformation(track)->GetParentParticleID();
300 G4ThreeVector momentum = track->GetMomentum();
303 G4double px = momentum.x();
304 G4double py = momentum.y();
305 G4double pz = momentum.z();
308 G4ThreeVector position = track->GetPosition();
310 G4double vx = position.x();
311 G4double vy = position.y();
312 G4double vz = position.z();
315 G4ThreeVector polarization = track->GetPolarization();
316 G4double polX = polarization.x();
317 G4double polY = polarization.y();
318 G4double polZ = polarization.z();
321 TMCProcess mcProcess;
322 const G4VProcess* kpProcess = track->GetCreatorProcess();
324 mcProcess = kPPrimary;
329 if (mcProcess == kPEnergyLoss) mcProcess = kPDeltaRay;
332 G4double weight = track->GetWeight();
335 if (fSaveDynamicCharge) {
339 status = G4int(track->GetDynamicParticle()->GetCharge() / eplus);
343#ifdef STACK_WITH_KEEP_FLAG
345 fMCStack->PushTrack(0, motherIndex, pdg, px, py, pz, e, vx, vy, vz, t, polX,
346 polY, polZ, mcProcess, ntr, weight, status, overWrite);
350 fMCStack->PushTrack(0, motherIndex, pdg, px, py, pz, e, vx, vy, vz, t, polX,
351 polY, polZ, mcProcess, ntr, weight, status);
355 GetTrackInformation(track)->SetTrackParticleID(ntr);
360 const G4PrimaryVertex* vertex,
const G4PrimaryParticle* particle)
365 G4int motherIndex = -1;
372 G4ThreeVector momentum = particle->GetMomentum();
374 G4double px = momentum.x();
375 G4double py = momentum.y();
376 G4double pz = momentum.z();
377 G4double mass = particle->GetMass();
378 G4double e = sqrt(momentum.mag() * momentum.mag() + mass * mass);
381 G4ThreeVector position = vertex->GetPosition();
383 G4double vx = position.x();
384 G4double vy = position.y();
385 G4double vz = position.z();
389 G4ThreeVector polarization = particle->GetPolarization();
390 G4double polX = polarization.x();
391 G4double polY = polarization.y();
392 G4double polZ = polarization.z();
395 TMCProcess mcProcess = kPPrimary;
397 G4double weight = particle->GetWeight();
404 status = G4int(particle->GetCharge() / eplus);
409 fMCStack->PushTrack(1, motherIndex, pdg, px, py, pz, e, vx, vy, vz, t, polX,
410 polY, polZ, mcProcess, ntr, weight, status);
415 const G4Track* track,
const G4TrackVector* secondaries)
429 G4Track* secondary = (*secondaries)[i];
469 const G4Track* track)
const
475 if (!trackInfo)
return 0;
483 "Unknown track information type");
Definition of the TG4G3Units class.
Definition of the TG4Globals class and basic container types.
Definition of the TG4ParticlesManager class.
Definition of the TG4PhysicsManager class.
Definition of the TG4SDServices class.
Definition of the TG4SensitiveDetector class.
Definition of the TG4StackPopper class.
Definition of the TG4StepManager class.
Definition of the TG4TrackManager class.
static G4double InverseTime()
static G4double InverseEnergy()
static void Exception(const TString &className, const TString &methodName, const TString &text)
G4int GetPDGEncoding(G4ParticleDefinition *particle)
static TG4ParticlesManager * Instance()
static TG4PhysicsManager * Instance()
TMCProcess GetMCProcess(const G4VProcess *process)
static TG4StackPopper * Instance()
The class for storing G4 tracks in VMC sack.
void SaveSecondaries(const G4Track *track, const G4TrackVector *secondaries)
void ResetParticlesStatus()
G4int fTrackCounter
tracks counter
G4int fCurrentTrackID
current track ID
void AddParticleStatus(const TMCParticleStatus *particleStatus)
G4TrackingManager * fG4TrackingManager
G4 tracking manager.
TG4StackPopper * fStackPopper
Cached pointer to thread-local stack popper.
TVirtualMCStack * fMCStack
Cached pointer to thread-local VMC stack.
void SetBackPDGLifetime(const G4Track *aTrack)
TG4TrackInformation * GetTrackInformation(const G4Track *track) const
virtual ~TG4TrackManager()
void ResetPrimaryParticleIds()
void SetParentToTrackInformation(const G4Track *aTrack)
std::vector< G4int > fPrimaryParticleIds
G4bool IsUserTrack(const G4Track *track) const
void TrackToStack(const G4Track *track, G4bool overWrite=false)
static G4ThreadLocal TG4TrackManager * fgInstance
this instance
std::vector< TMCParticleStatus * > fParticlesStatus
TG4TrackSaveControl fTrackSaveControl
control of saving secondaries
void AddPrimaryParticleId(G4int id)
void PrimaryToStack(const G4PrimaryVertex *vertex, const G4PrimaryParticle *particle)
TG4TrackInformation * SetTrackInformation(const G4Track *aTrack, G4bool overWrite=false)
G4int fNofSavedSecondaries
number of secondaries already saved
G4bool fSaveDynamicCharge
Base class for defining the verbose level and a common messenger.
virtual G4int VerboseLevel() const
@ kSaveInPreTrack
save in pre-track