Geant4 11.4.0
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: Katsuya.Amako@kek.jp)
31// Makoto Asai (e-mail: asai@slac.stanford.edu)
32// Takashi Sasaki (e-mail: Takashi.Sasaki@kek.jp)
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 "G4ClonedTrajectory.hh"
43#include "G4UIcommand.hh"
44#include "G4UnitsTable.hh"
45#include "G4AutoLock.hh"
46
47namespace {
48 G4Mutex CloneTrajectoryMutex = G4MUTEX_INITIALIZER;
49}
50
51// #define G4ATTDEBUG
52#ifdef G4ATTDEBUG
53# include "G4AttCheck.hh"
54#endif
55
57{
59 return _instance;
60}
61
63{
64 G4ParticleDefinition* fpParticleDefinition = aTrack->GetDefinition();
65 ParticleName = fpParticleDefinition->GetParticleName();
66 PDGCharge = fpParticleDefinition->GetPDGCharge();
67 PDGEncoding = fpParticleDefinition->GetPDGEncoding();
68 fTrackID = aTrack->GetTrackID();
69 fParentID = aTrack->GetParentID();
70 initialKineticEnergy = aTrack->GetKineticEnergy();
71 initialMomentum = aTrack->GetMomentum();
72 positionRecord = new G4TrajectoryPointContainer();
73
74 // Following is for the first trajectory point
75 positionRecord->push_back(new G4TrajectoryPoint(aTrack->GetPosition()));
76}
77
80{
81 ParticleName = right.ParticleName;
82 PDGCharge = right.PDGCharge;
83 PDGEncoding = right.PDGEncoding;
84 fTrackID = right.fTrackID;
85 fParentID = right.fParentID;
86 initialKineticEnergy = right.initialKineticEnergy;
87 initialMomentum = right.initialMomentum;
88 positionRecord = new G4TrajectoryPointContainer();
89
90 for (auto& i : *right.positionRecord) {
91 auto rightPoint = (G4TrajectoryPoint*)i;
92 positionRecord->push_back(new G4TrajectoryPoint(*rightPoint));
93 }
94}
95
97{
98 G4AutoLock lock(&CloneTrajectoryMutex);
99 auto* cloned = new G4ClonedTrajectory(*this);
100 return cloned;
101}
102
104{
105 if (positionRecord != nullptr) {
106 for (auto& i : *positionRecord) {
107 delete i;
108 }
109 positionRecord->clear();
110 delete positionRecord;
111 }
112}
113
114void G4Trajectory::ShowTrajectory(std::ostream& os) const
115{
116 // Invoke the default implementation in G4VTrajectory...
118
119 // ... or override with your own code here.
120}
121
123{
124 // Invoke the default implementation in G4VTrajectory...
126
127 // ... or override with your own code here.
128}
129
130const std::map<G4String, G4AttDef>* G4Trajectory::GetAttDefs() const
131{
132 G4bool isNew;
133 std::map<G4String, G4AttDef>* store = G4AttDefStore::GetInstance("G4Trajectory", isNew);
134 if (isNew) {
135 G4String ID("ID");
136 (*store)[ID] = G4AttDef(ID, "Track ID", "Physics", "", "G4int");
137
138 G4String PID("PID");
139 (*store)[PID] = G4AttDef(PID, "Parent ID", "Physics", "", "G4int");
140
141 G4String PN("PN");
142 (*store)[PN] = G4AttDef(PN, "Particle Name", "Physics", "", "G4String");
143
144 G4String Ch("Ch");
145 (*store)[Ch] = G4AttDef(Ch, "Charge", "Physics", "e+", "G4double");
146
147 G4String PDG("PDG");
148 (*store)[PDG] = G4AttDef(PDG, "PDG Encoding", "Physics", "", "G4int");
149
150 G4String IKE("IKE");
151 (*store)[IKE] = G4AttDef(IKE, "Initial kinetic energy", "Physics", "G4BestUnit", "G4double");
152
153 G4String IMom("IMom");
154 (*store)[IMom] = G4AttDef(IMom, "Initial momentum", "Physics", "G4BestUnit", "G4ThreeVector");
155
156 G4String IMag("IMag");
157 (*store)[IMag] =
158 G4AttDef(IMag, "Initial momentum magnitude", "Physics", "G4BestUnit", "G4double");
159
160 G4String NTP("NTP");
161 (*store)[NTP] = G4AttDef(NTP, "No. of points", "Physics", "", "G4int");
162 }
163 return store;
164}
165
166std::vector<G4AttValue>* G4Trajectory::CreateAttValues() const
167{
168 auto values = new std::vector<G4AttValue>;
169
170 values->push_back(G4AttValue("ID", G4UIcommand::ConvertToString(fTrackID), ""));
171
172 values->push_back(G4AttValue("PID", G4UIcommand::ConvertToString(fParentID), ""));
173
174 values->push_back(G4AttValue("PN", ParticleName, ""));
175
176 values->push_back(G4AttValue("Ch", G4UIcommand::ConvertToString(PDGCharge), ""));
177
178 values->push_back(G4AttValue("PDG", G4UIcommand::ConvertToString(PDGEncoding), ""));
179
180 values->push_back(G4AttValue("IKE", G4BestUnit(initialKineticEnergy, "Energy"), ""));
181
182 values->push_back(G4AttValue("IMom", G4BestUnit(initialMomentum, "Energy"), ""));
183
184 values->push_back(G4AttValue("IMag", G4BestUnit(initialMomentum.mag(), "Energy"), ""));
185
186 values->push_back(G4AttValue("NTP", G4UIcommand::ConvertToString(GetPointEntries()), ""));
187
188#ifdef G4ATTDEBUG
189 G4cout << G4AttCheck(values, GetAttDefs());
190#endif
191
192 return values;
193}
194
196{
197 positionRecord->push_back(new G4TrajectoryPoint(aStep->GetPostStepPoint()->GetPosition()));
198}
199
204
206{
207 if (secondTrajectory == nullptr) return;
208
209 auto seco = (G4Trajectory*)secondTrajectory;
210 G4int ent = seco->GetPointEntries();
211 for (G4int i = 1; i < ent; ++i) // initial pt of 2nd trajectory shouldn't be merged
212 {
213 positionRecord->push_back((*(seco->positionRecord))[i]);
214 }
215 delete (*seco->positionRecord)[0];
216 seco->positionRecord->clear();
217}
G4TemplateAutoLock< G4Mutex > G4AutoLock
#define G4BestUnit(a, b)
#define G4MUTEX_INITIALIZER
std::mutex G4Mutex
G4Allocator< G4Trajectory > *& aTrajectoryAllocator()
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4GLOB_DLL std::ostream G4cout
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
friend class G4ClonedTrajectory
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
G4VTrajectory * CloneForMaster() const override
static G4String ConvertToString(G4bool boolVal)
G4VTrajectory()=default
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