source: trunk/source/tracking/src/G4Trajectory.cc@ 1234

Last change on this file since 1234 was 1228, checked in by garnier, 16 years ago

update geant4.9.3 tag

File size: 7.5 KB
RevLine 
[827]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//
[1196]27// $Id: G4Trajectory.cc,v 1.33 2009/11/12 09:09:56 allison Exp $
[1228]28// GEANT4 tag $Name: geant4-09-03 $
[827]29//
30// ---------------------------------------------------------------
31//
32// G4Trajectory.cc
33//
34// Contact:
35// Questions and comments to this code should be sent to
36// Katsuya Amako (e-mail: Katsuya.Amako@kek.jp)
37// Makoto Asai (e-mail: asai@kekvax.kek.jp)
38// Takashi Sasaki (e-mail: Takashi.Sasaki@kek.jp)
39//
40// ---------------------------------------------------------------
41
42#include "G4Trajectory.hh"
43#include "G4TrajectoryPoint.hh"
44#include "G4ParticleTable.hh"
45#include "G4AttDefStore.hh"
46#include "G4AttDef.hh"
47#include "G4AttValue.hh"
48#include "G4UIcommand.hh"
49#include "G4UnitsTable.hh"
50
51//#define G4ATTDEBUG
52#ifdef G4ATTDEBUG
53#include "G4AttCheck.hh"
54#endif
55
56G4Allocator<G4Trajectory> aTrajectoryAllocator;
57
58G4Trajectory::G4Trajectory()
59: positionRecord(0), fTrackID(0), fParentID(0),
60 PDGEncoding( 0 ), PDGCharge(0.0), ParticleName(""),
[1196]61 initialKineticEnergy( 0. ), initialMomentum( G4ThreeVector() )
[827]62{;}
63
64G4Trajectory::G4Trajectory(const G4Track* aTrack)
65{
66 G4ParticleDefinition * fpParticleDefinition = aTrack->GetDefinition();
67 ParticleName = fpParticleDefinition->GetParticleName();
68 PDGCharge = fpParticleDefinition->GetPDGCharge();
69 PDGEncoding = fpParticleDefinition->GetPDGEncoding();
70 fTrackID = aTrack->GetTrackID();
71 fParentID = aTrack->GetParentID();
[1196]72 initialKineticEnergy = aTrack->GetKineticEnergy();
[827]73 initialMomentum = aTrack->GetMomentum();
74 positionRecord = new TrajectoryPointContainer();
75 // Following is for the first trajectory point
76 positionRecord->push_back(new G4TrajectoryPoint(aTrack->GetPosition()));
77}
78
79G4Trajectory::G4Trajectory(G4Trajectory & right):G4VTrajectory()
80{
81 ParticleName = right.ParticleName;
82 PDGCharge = right.PDGCharge;
83 PDGEncoding = right.PDGEncoding;
84 fTrackID = right.fTrackID;
85 fParentID = right.fParentID;
[1196]86 initialKineticEnergy = right.initialKineticEnergy;
[827]87 initialMomentum = right.initialMomentum;
88 positionRecord = new TrajectoryPointContainer();
89
90 for(size_t i=0;i<right.positionRecord->size();i++)
91 {
92 G4TrajectoryPoint* rightPoint = (G4TrajectoryPoint*)((*(right.positionRecord))[i]);
93 positionRecord->push_back(new G4TrajectoryPoint(*rightPoint));
94 }
95}
96
97G4Trajectory::~G4Trajectory()
98{
99 if (positionRecord) {
100 // positionRecord->clearAndDestroy();
101 size_t i;
102 for(i=0;i<positionRecord->size();i++){
103 delete (*positionRecord)[i];
104 }
105 positionRecord->clear();
106 delete positionRecord;
107 }
108}
109
110void G4Trajectory::ShowTrajectory(std::ostream& os) const
111{
112 // Invoke the default implementation in G4VTrajectory...
113 G4VTrajectory::ShowTrajectory(os);
114 // ... or override with your own code here.
115}
116
117void G4Trajectory::DrawTrajectory(G4int i_mode) const
118{
119 // Invoke the default implementation in G4VTrajectory...
120 G4VTrajectory::DrawTrajectory(i_mode);
121 // ... or override with your own code here.
122}
123
124const std::map<G4String,G4AttDef>* G4Trajectory::GetAttDefs() const
125{
126 G4bool isNew;
127 std::map<G4String,G4AttDef>* store
128 = G4AttDefStore::GetInstance("G4Trajectory",isNew);
129 if (isNew) {
130
131 G4String ID("ID");
132 (*store)[ID] = G4AttDef(ID,"Track ID","Physics","","G4int");
133
134 G4String PID("PID");
135 (*store)[PID] = G4AttDef(PID,"Parent ID","Physics","","G4int");
136
137 G4String PN("PN");
138 (*store)[PN] = G4AttDef(PN,"Particle Name","Physics","","G4String");
139
140 G4String Ch("Ch");
141 (*store)[Ch] = G4AttDef(Ch,"Charge","Physics","e+","G4double");
142
143 G4String PDG("PDG");
144 (*store)[PDG] = G4AttDef(PDG,"PDG Encoding","Physics","","G4int");
145
[1196]146 G4String IKE("IKE");
147 (*store)[IKE] =
148 G4AttDef(IKE, "Initial kinetic energy",
149 "Physics","G4BestUnit","G4double");
150
[827]151 G4String IMom("IMom");
[1196]152 (*store)[IMom] = G4AttDef(IMom, "Initial momentum",
[827]153 "Physics","G4BestUnit","G4ThreeVector");
154
155 G4String IMag("IMag");
156 (*store)[IMag] =
[1196]157 G4AttDef(IMag, "Initial momentum magnitude",
[827]158 "Physics","G4BestUnit","G4double");
159
160 G4String NTP("NTP");
161 (*store)[NTP] = G4AttDef(NTP,"No. of points","Physics","","G4int");
162
163 }
164 return store;
165}
166
167std::vector<G4AttValue>* G4Trajectory::CreateAttValues() const
168{
169 std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
170
171 values->push_back
172 (G4AttValue("ID",G4UIcommand::ConvertToString(fTrackID),""));
173
174 values->push_back
175 (G4AttValue("PID",G4UIcommand::ConvertToString(fParentID),""));
176
177 values->push_back(G4AttValue("PN",ParticleName,""));
178
179 values->push_back
180 (G4AttValue("Ch",G4UIcommand::ConvertToString(PDGCharge),""));
181
182 values->push_back
183 (G4AttValue("PDG",G4UIcommand::ConvertToString(PDGEncoding),""));
184
185 values->push_back
[1196]186 (G4AttValue("IKE",G4BestUnit(initialKineticEnergy,"Energy"),""));
187
188 values->push_back
[827]189 (G4AttValue("IMom",G4BestUnit(initialMomentum,"Energy"),""));
190
191 values->push_back
192 (G4AttValue("IMag",G4BestUnit(initialMomentum.mag(),"Energy"),""));
193
194 values->push_back
195 (G4AttValue("NTP",G4UIcommand::ConvertToString(GetPointEntries()),""));
196
197#ifdef G4ATTDEBUG
198 G4cout << G4AttCheck(values,GetAttDefs());
199#endif
200
201 return values;
202}
203
204void G4Trajectory::AppendStep(const G4Step* aStep)
205{
206 positionRecord->push_back( new G4TrajectoryPoint(aStep->GetPostStepPoint()->
207 GetPosition() ));
208}
209
210G4ParticleDefinition* G4Trajectory::GetParticleDefinition()
211{
212 return (G4ParticleTable::GetParticleTable()->FindParticle(ParticleName));
213}
214
215void G4Trajectory::MergeTrajectory(G4VTrajectory* secondTrajectory)
216{
217 if(!secondTrajectory) return;
218
219 G4Trajectory* seco = (G4Trajectory*)secondTrajectory;
220 G4int ent = seco->GetPointEntries();
221 for(G4int i=1;i<ent;i++) // initial point of the second trajectory should not be merged
222 {
223 positionRecord->push_back((*(seco->positionRecord))[i]);
224 // positionRecord->push_back(seco->positionRecord->removeAt(1));
225 }
226 delete (*seco->positionRecord)[0];
227 seco->positionRecord->clear();
228}
229
230
Note: See TracBrowser for help on using the repository browser.