Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Trajectory.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4Trajectory class implementation
27//
28// Contact:
29// Questions and comments to this code should be sent to
30// Katsuya Amako (e-mail: [email protected])
31// Makoto Asai (e-mail: [email protected])
32// Takashi Sasaki (e-mail: [email protected])
33// --------------------------------------------------------------------
34
35#include "G4Trajectory.hh"
36
37#include "G4AttDef.hh"
38#include "G4AttDefStore.hh"
39#include "G4AttValue.hh"
40#include "G4ParticleTable.hh"
41#include "G4TrajectoryPoint.hh"
42#include "G4UIcommand.hh"
43#include "G4UnitsTable.hh"
44
45// #define G4ATTDEBUG
46#ifdef G4ATTDEBUG
47# include "G4AttCheck.hh"
48#endif
49
51{
53 return _instance;
54}
55
57{
58 G4ParticleDefinition* fpParticleDefinition = aTrack->GetDefinition();
59 ParticleName = fpParticleDefinition->GetParticleName();
60 PDGCharge = fpParticleDefinition->GetPDGCharge();
61 PDGEncoding = fpParticleDefinition->GetPDGEncoding();
62 fTrackID = aTrack->GetTrackID();
63 fParentID = aTrack->GetParentID();
64 initialKineticEnergy = aTrack->GetKineticEnergy();
65 initialMomentum = aTrack->GetMomentum();
66 positionRecord = new G4TrajectoryPointContainer();
67
68 // Following is for the first trajectory point
69 positionRecord->push_back(new G4TrajectoryPoint(aTrack->GetPosition()));
70}
71
73{
74 ParticleName = right.ParticleName;
75 PDGCharge = right.PDGCharge;
76 PDGEncoding = right.PDGEncoding;
77 fTrackID = right.fTrackID;
78 fParentID = right.fParentID;
79 initialKineticEnergy = right.initialKineticEnergy;
80 initialMomentum = right.initialMomentum;
81 positionRecord = new G4TrajectoryPointContainer();
82
83 for (auto& i : *right.positionRecord) {
84 auto rightPoint = (G4TrajectoryPoint*)i;
85 positionRecord->push_back(new G4TrajectoryPoint(*rightPoint));
86 }
87}
88
90{
91 if (positionRecord != nullptr) {
92 for (auto& i : *positionRecord) {
93 delete i;
94 }
95 positionRecord->clear();
96 delete positionRecord;
97 }
98}
99
100void G4Trajectory::ShowTrajectory(std::ostream& os) const
101{
102 // Invoke the default implementation in G4VTrajectory...
104
105 // ... or override with your own code here.
106}
107
109{
110 // Invoke the default implementation in G4VTrajectory...
112
113 // ... or override with your own code here.
114}
115
116const std::map<G4String, G4AttDef>* G4Trajectory::GetAttDefs() const
117{
118 G4bool isNew;
119 std::map<G4String, G4AttDef>* store = G4AttDefStore::GetInstance("G4Trajectory", isNew);
120 if (isNew) {
121 G4String ID("ID");
122 (*store)[ID] = G4AttDef(ID, "Track ID", "Physics", "", "G4int");
123
124 G4String PID("PID");
125 (*store)[PID] = G4AttDef(PID, "Parent ID", "Physics", "", "G4int");
126
127 G4String PN("PN");
128 (*store)[PN] = G4AttDef(PN, "Particle Name", "Physics", "", "G4String");
129
130 G4String Ch("Ch");
131 (*store)[Ch] = G4AttDef(Ch, "Charge", "Physics", "e+", "G4double");
132
133 G4String PDG("PDG");
134 (*store)[PDG] = G4AttDef(PDG, "PDG Encoding", "Physics", "", "G4int");
135
136 G4String IKE("IKE");
137 (*store)[IKE] = G4AttDef(IKE, "Initial kinetic energy", "Physics", "G4BestUnit", "G4double");
138
139 G4String IMom("IMom");
140 (*store)[IMom] = G4AttDef(IMom, "Initial momentum", "Physics", "G4BestUnit", "G4ThreeVector");
141
142 G4String IMag("IMag");
143 (*store)[IMag] =
144 G4AttDef(IMag, "Initial momentum magnitude", "Physics", "G4BestUnit", "G4double");
145
146 G4String NTP("NTP");
147 (*store)[NTP] = G4AttDef(NTP, "No. of points", "Physics", "", "G4int");
148 }
149 return store;
150}
151
152std::vector<G4AttValue>* G4Trajectory::CreateAttValues() const
153{
154 auto values = new std::vector<G4AttValue>;
155
156 values->push_back(G4AttValue("ID", G4UIcommand::ConvertToString(fTrackID), ""));
157
158 values->push_back(G4AttValue("PID", G4UIcommand::ConvertToString(fParentID), ""));
159
160 values->push_back(G4AttValue("PN", ParticleName, ""));
161
162 values->push_back(G4AttValue("Ch", G4UIcommand::ConvertToString(PDGCharge), ""));
163
164 values->push_back(G4AttValue("PDG", G4UIcommand::ConvertToString(PDGEncoding), ""));
165
166 values->push_back(G4AttValue("IKE", G4BestUnit(initialKineticEnergy, "Energy"), ""));
167
168 values->push_back(G4AttValue("IMom", G4BestUnit(initialMomentum, "Energy"), ""));
169
170 values->push_back(G4AttValue("IMag", G4BestUnit(initialMomentum.mag(), "Energy"), ""));
171
172 values->push_back(G4AttValue("NTP", G4UIcommand::ConvertToString(GetPointEntries()), ""));
173
174#ifdef G4ATTDEBUG
175 G4cout << G4AttCheck(values, GetAttDefs());
176#endif
177
178 return values;
179}
180
182{
183 positionRecord->push_back(new G4TrajectoryPoint(aStep->GetPostStepPoint()->GetPosition()));
184}
185
190
192{
193 if (secondTrajectory == nullptr) return;
194
195 auto seco = (G4Trajectory*)secondTrajectory;
196 G4int ent = seco->GetPointEntries();
197 for (G4int i = 1; i < ent; ++i) // initial pt of 2nd trajectory shouldn't be merged
198 {
199 positionRecord->push_back((*(seco->positionRecord))[i]);
200 }
201 delete (*seco->positionRecord)[0];
202 seco->positionRecord->clear();
203}
#define G4BestUnit(a, b)
G4Allocator< G4Trajectory > *& aTrajectoryAllocator()
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4GLOB_DLL std::ostream G4cout
double mag() const
const G4String & GetParticleName() const
static G4ParticleTable * GetParticleTable()
const G4ThreeVector & GetPosition() const
G4StepPoint * GetPostStepPoint() const
G4int GetTrackID() const
const G4ThreeVector & GetPosition() const
G4ThreeVector GetMomentum() const
G4ParticleDefinition * GetDefinition() const
G4double GetKineticEnergy() const
G4int GetParentID() const
void DrawTrajectory() const override
G4ParticleDefinition * GetParticleDefinition()
void ShowTrajectory(std::ostream &os=G4cout) const override
G4int GetPointEntries() const override
void MergeTrajectory(G4VTrajectory *secondTrajectory) override
const std::map< G4String, G4AttDef > * GetAttDefs() const override
std::vector< G4AttValue > * CreateAttValues() const override
void AppendStep(const G4Step *aStep) override
G4Trajectory()=default
~G4Trajectory() override
static G4String ConvertToString(G4bool boolVal)
virtual G4int GetPointEntries() const =0
virtual void ShowTrajectory(std::ostream &os=G4cout) const
virtual void DrawTrajectory() const
std::map< G4String, G4AttDef > * GetInstance(const G4String &storeKey, G4bool &isNew)
#define G4ThreadLocalStatic
Definition tls.hh:76