Geant4 11.1.1
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#include "G4TrajectoryPoint.hh"
37#include "G4ParticleTable.hh"
38#include "G4AttDefStore.hh"
39#include "G4AttDef.hh"
40#include "G4AttValue.hh"
41#include "G4UIcommand.hh"
42#include "G4UnitsTable.hh"
43
44// #define G4ATTDEBUG
45#ifdef G4ATTDEBUG
46#include "G4AttCheck.hh"
47#endif
48
50{
52 return _instance;
53}
54
56 : initialMomentum( G4ThreeVector() )
57{
58}
59
61{
62 G4ParticleDefinition* fpParticleDefinition = aTrack->GetDefinition();
63 ParticleName = fpParticleDefinition->GetParticleName();
64 PDGCharge = fpParticleDefinition->GetPDGCharge();
65 PDGEncoding = fpParticleDefinition->GetPDGEncoding();
66 fTrackID = aTrack->GetTrackID();
67 fParentID = aTrack->GetParentID();
68 initialKineticEnergy = aTrack->GetKineticEnergy();
69 initialMomentum = aTrack->GetMomentum();
70 positionRecord = new G4TrajectoryPointContainer();
71
72 // Following is for the first trajectory point
73 positionRecord->push_back(new G4TrajectoryPoint(aTrack->GetPosition()));
74}
75
78{
79 ParticleName = right.ParticleName;
80 PDGCharge = right.PDGCharge;
81 PDGEncoding = right.PDGEncoding;
82 fTrackID = right.fTrackID;
83 fParentID = right.fParentID;
84 initialKineticEnergy = right.initialKineticEnergy;
85 initialMomentum = right.initialMomentum;
86 positionRecord = new G4TrajectoryPointContainer();
87
88 for(std::size_t i=0; i<right.positionRecord->size(); ++i)
89 {
90 G4TrajectoryPoint* rightPoint
91 = (G4TrajectoryPoint*)((*(right.positionRecord))[i]);
92 positionRecord->push_back(new G4TrajectoryPoint(*rightPoint));
93 }
94}
95
97{
98 if (positionRecord != nullptr)
99 {
100 for(std::size_t i=0; i<positionRecord->size(); ++i)
101 {
102 delete (*positionRecord)[i];
103 }
104 positionRecord->clear();
105 delete positionRecord;
106 }
107}
108
109void G4Trajectory::ShowTrajectory(std::ostream& os) const
110{
111 // Invoke the default implementation in G4VTrajectory...
113
114 // ... or override with your own code here.
115}
116
118{
119 // Invoke the default implementation in G4VTrajectory...
121
122 // ... or override with your own code here.
123}
124
125const std::map<G4String,G4AttDef>* G4Trajectory::GetAttDefs() const
126{
127 G4bool isNew;
128 std::map<G4String,G4AttDef>* store
129 = G4AttDefStore::GetInstance("G4Trajectory",isNew);
130 if (isNew)
131 {
132 G4String ID("ID");
133 (*store)[ID] = G4AttDef(ID,"Track ID","Physics","","G4int");
134
135 G4String PID("PID");
136 (*store)[PID] = G4AttDef(PID,"Parent ID","Physics","","G4int");
137
138 G4String PN("PN");
139 (*store)[PN] = G4AttDef(PN,"Particle Name","Physics","","G4String");
140
141 G4String Ch("Ch");
142 (*store)[Ch] = G4AttDef(Ch,"Charge","Physics","e+","G4double");
143
144 G4String PDG("PDG");
145 (*store)[PDG] = G4AttDef(PDG,"PDG Encoding","Physics","","G4int");
146
147 G4String IKE("IKE");
148 (*store)[IKE] =
149 G4AttDef(IKE, "Initial kinetic energy",
150 "Physics","G4BestUnit","G4double");
151
152 G4String IMom("IMom");
153 (*store)[IMom] = G4AttDef(IMom, "Initial momentum",
154 "Physics","G4BestUnit","G4ThreeVector");
155
156 G4String IMag("IMag");
157 (*store)[IMag] =
158 G4AttDef(IMag, "Initial momentum magnitude",
159 "Physics","G4BestUnit","G4double");
160
161 G4String NTP("NTP");
162 (*store)[NTP] = G4AttDef(NTP,"No. of points","Physics","","G4int");
163
164 }
165 return store;
166}
167
168std::vector<G4AttValue>* G4Trajectory::CreateAttValues() const
169{
170 std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
171
172 values->push_back
173 (G4AttValue("ID",G4UIcommand::ConvertToString(fTrackID),""));
174
175 values->push_back
176 (G4AttValue("PID",G4UIcommand::ConvertToString(fParentID),""));
177
178 values->push_back(G4AttValue("PN",ParticleName,""));
179
180 values->push_back
181 (G4AttValue("Ch",G4UIcommand::ConvertToString(PDGCharge),""));
182
183 values->push_back
184 (G4AttValue("PDG",G4UIcommand::ConvertToString(PDGEncoding),""));
185
186 values->push_back
187 (G4AttValue("IKE",G4BestUnit(initialKineticEnergy,"Energy"),""));
188
189 values->push_back
190 (G4AttValue("IMom",G4BestUnit(initialMomentum,"Energy"),""));
191
192 values->push_back
193 (G4AttValue("IMag",G4BestUnit(initialMomentum.mag(),"Energy"),""));
194
195 values->push_back
197
198#ifdef G4ATTDEBUG
199 G4cout << G4AttCheck(values,GetAttDefs());
200#endif
201
202 return values;
203}
204
206{
207 positionRecord->push_back( new G4TrajectoryPoint(aStep->GetPostStepPoint()->
208 GetPosition()) );
209}
210
212{
213 return (G4ParticleTable::GetParticleTable()->FindParticle(ParticleName));
214}
215
217{
218 if(secondTrajectory == nullptr) return;
219
220 G4Trajectory* seco = (G4Trajectory*)secondTrajectory;
221 G4int ent = seco->GetPointEntries();
222 for(G4int i=1; i<ent; ++i) // initial pt of 2nd trajectory shouldn't be merged
223 {
224 positionRecord->push_back((*(seco->positionRecord))[i]);
225 }
226 delete (*seco->positionRecord)[0];
227 seco->positionRecord->clear();
228}
#define G4BestUnit(a, b)
G4Allocator< G4Trajectory > *& aTrajectoryAllocator()
Definition: G4Trajectory.cc:49
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cout
double mag() const
G4double GetPDGCharge() const
const G4String & GetParticleName() const
static G4ParticleTable * GetParticleTable()
Definition: G4Step.hh:62
G4StepPoint * GetPostStepPoint() const
G4int GetTrackID() const
const G4ThreeVector & GetPosition() const
G4ThreeVector GetMomentum() const
G4ParticleDefinition * GetDefinition() const
G4double GetKineticEnergy() const
G4int GetParentID() const
G4ParticleDefinition * GetParticleDefinition()
virtual G4int GetPointEntries() const
virtual void ShowTrajectory(std::ostream &os=G4cout) const
virtual void AppendStep(const G4Step *aStep)
virtual void DrawTrajectory() const
virtual void MergeTrajectory(G4VTrajectory *secondTrajectory)
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
virtual std::vector< G4AttValue > * CreateAttValues() const
virtual ~G4Trajectory()
Definition: G4Trajectory.cc:96
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:446
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