Geant4 VMC Version 6.6
Loading...
Searching...
No Matches
TG4GeoTrackManager.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 "TG4GeoTrackManager.h"
16#include "TG4Globals.h"
17
18#include <G4Track.hh>
19
20#include <TDatabasePDG.h>
21#include <TGeoManager.h>
22#include <TParticlePDG.h>
23#include <TVirtualGeoTrack.h>
24#include <TVirtualMC.h>
25
26// static data members
27const G4double TG4GeoTrackManager::fgkMinPointDistance = 0.01;
28
29//_____________________________________________________________________________
31 : TG4Verbose("geoTrackManager"),
32 fCollectTracks(kFALSE),
33 fCurrentTGeoTrack(0),
34 fParentTGeoTrack(0)
35{
37}
38
39//_____________________________________________________________________________
44
45//
46// public methods
47//
48
49//_____________________________________________________________________________
51{
53
54 G4Track* track = step->GetTrack();
55 G4int stepNumber = track->GetCurrentStepNumber();
56
57 if (stepNumber == 1) {
58 // Find and update parent track if it exists
59 Int_t trackNumber = gMC->GetStack()->GetCurrentTrackNumber();
60 Int_t parentTrackNumber = gMC->GetStack()->GetCurrentParentTrackNumber();
61 Int_t pdg = gMC->TrackPid();
62 if (parentTrackNumber >= 0) {
63 fParentTGeoTrack = gGeoManager->FindTrackWithId(parentTrackNumber);
64 if (!fParentTGeoTrack) {
65 TString text = "No parent track with id=";
66 text += parentTrackNumber;
67 TG4Globals::Exception("TG4GeoTrackManager", "UpdateRootTrack", text);
68 }
69 fCurrentTGeoTrack = fParentTGeoTrack->AddDaughter(trackNumber, pdg);
70 gGeoManager->SetCurrentTrack(fCurrentTGeoTrack);
71
72 if (VerboseLevel() > 1) {
73 G4cout << "New TGeo track with id=" << trackNumber << " pdg=" << pdg
74 << " parent=" << parentTrackNumber << G4endl;
75 }
76 }
77 else {
78 Int_t itrack = gGeoManager->AddTrack(trackNumber, pdg);
79 gGeoManager->SetCurrentTrack(itrack);
80 fCurrentTGeoTrack = gGeoManager->GetCurrentTrack();
81 if (VerboseLevel() > 1) {
82 G4cout << "New primary TGeo track with id=" << trackNumber
83 << " pdg=" << pdg << G4endl;
84 }
85 }
86 TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(pdg);
87 if (particle) {
88 fCurrentTGeoTrack->SetName(particle->GetName());
89 fCurrentTGeoTrack->SetParticle(particle);
90 }
91 }
92
93 // Skip point if its distance from the previous one is smaller than the limit
94 Double_t x, y, z;
95 gMC->TrackPosition(x, y, z);
96 Bool_t skipPoint = kFALSE;
97 if (fCurrentTGeoTrack->HasPoints()) {
98 Double_t xo, yo, zo, to;
99 fCurrentTGeoTrack->GetLastPoint(xo, yo, zo, to);
100 Double_t rdist = TMath::Sqrt(
101 (xo - x) * (xo - x) + (yo - y) * (yo - y) + (zo - z) * (zo - z));
102 if (rdist < fgkMinPointDistance) skipPoint = kTRUE;
103 }
104 if (skipPoint) return;
105
106 // Add point to the track
107 G4double time = gMC->TrackTime();
108 fCurrentTGeoTrack->AddPoint(x, y, z, time);
109 if (VerboseLevel() > 2) {
110 G4cout << "Added point (x,y,z,t)=" << x << ", " << y << ", " << z << ", "
111 << time << G4endl;
112 }
113}
Definition of the TG4GeoTrackManager class.
Definition of the TG4Globals class and basic container types.
TVirtualGeoTrack * fParentTGeoTrack
parent of the current Root track
TVirtualGeoTrack * fCurrentTGeoTrack
current Root track
static const G4double fgkMinPointDistance
minimum point distance to store a point in TGeo track
void UpdateRootTrack(const G4Step *step)
static void Exception(const TString &className, const TString &methodName, const TString &text)
Base class for defining the verbose level and a common messenger.
Definition TG4Verbose.h:36
virtual G4int VerboseLevel() const
Definition TG4Verbose.h:78