source: trunk/examples/extended/field/field04/src/F04Trajectory.cc@ 1036

Last change on this file since 1036 was 807, checked in by garnier, 17 years ago

update

File size: 6.8 KB
Line 
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//
27//
28
29#include "G4AttDef.hh"
30#include "G4AttValue.hh"
31#include "G4AttDefStore.hh"
32
33#include "G4UIcommand.hh"
34#include "G4UnitsTable.hh"
35
36#include "F04Trajectory.hh"
37#include "F04TrajectoryPoint.hh"
38#include "G4ParticleTable.hh"
39
40//#define G4ATTDEBUG
41#ifdef G4ATTDEBUG
42#include "G4AttCheck.hh"
43#endif
44
45G4Allocator<F04Trajectory> aTrajectoryAllocator;
46
47F04Trajectory::F04Trajectory()
48 : fpPointsContainer(0), fTrackID(0), fParentID(0),
49 PDGCharge(0.0), PDGEncoding(0), ParticleName(""),
50 initialMomentum(G4ThreeVector()) {;}
51
52F04Trajectory::F04Trajectory(const G4Track* aTrack)
53{
54 G4ParticleDefinition * fpParticleDefinition = aTrack->GetDefinition();
55 ParticleName = fpParticleDefinition->GetParticleName();
56 PDGCharge = fpParticleDefinition->GetPDGCharge();
57 PDGEncoding = fpParticleDefinition->GetPDGEncoding();
58 fTrackID = aTrack->GetTrackID();
59 fParentID = aTrack->GetParentID();
60 initialMomentum = aTrack->GetMomentum();
61 fpPointsContainer = new TrajectoryPointContainer();
62 // Following is for the first trajectory point
63 fpPointsContainer->push_back(new F04TrajectoryPoint(aTrack));
64}
65
66F04Trajectory::F04Trajectory(F04Trajectory & right) : G4VTrajectory()
67{
68 ParticleName = right.ParticleName;
69 PDGCharge = right.PDGCharge;
70 PDGEncoding = right.PDGEncoding;
71 fTrackID = right.fTrackID;
72 fParentID = right.fParentID;
73 initialMomentum = right.initialMomentum;
74 fpPointsContainer = new TrajectoryPointContainer();
75
76 for(size_t i=0;i<right.fpPointsContainer->size();++i) {
77 F04TrajectoryPoint* rightPoint
78 = (F04TrajectoryPoint*)((*(right.fpPointsContainer))[i]);
79 fpPointsContainer->push_back(new F04TrajectoryPoint(*rightPoint));
80 }
81}
82
83F04Trajectory::~F04Trajectory()
84{
85 for(size_t i=0;i<fpPointsContainer->size();++i){
86 delete (*fpPointsContainer)[i];
87 }
88 fpPointsContainer->clear();
89
90 delete fpPointsContainer;
91}
92
93void F04Trajectory::ShowTrajectory(std::ostream& os) const
94{
95 // Invoke the default implementation in G4VTrajectory...
96 G4VTrajectory::ShowTrajectory(os);
97 // ... or override with your own code here.
98}
99
100void F04Trajectory::DrawTrajectory(G4int i_mode) const
101{
102 // Invoke the default implementation in G4VTrajectory...
103 G4VTrajectory::DrawTrajectory(i_mode);
104 // ... or override with your own code here.
105}
106
107void F04Trajectory::AppendStep(const G4Step* aStep)
108{
109 fpPointsContainer->push_back(new F04TrajectoryPoint(aStep));
110}
111
112G4ParticleDefinition* F04Trajectory::GetParticleDefinition()
113{
114 return (G4ParticleTable::GetParticleTable()->FindParticle(ParticleName));
115}
116
117void F04Trajectory::MergeTrajectory(G4VTrajectory* secondTrajectory)
118{
119 if(!secondTrajectory) return;
120
121 F04Trajectory* second = (F04Trajectory*)secondTrajectory;
122 G4int ent = second->GetPointEntries();
123 // initial point of the second trajectory should not be merged
124 for(G4int i=1; i<ent; ++i) {
125 fpPointsContainer->push_back((*(second->fpPointsContainer))[i]);
126 }
127 delete (*second->fpPointsContainer)[0];
128 second->fpPointsContainer->clear();
129}
130
131const std::map<G4String,G4AttDef>* F04Trajectory::GetAttDefs() const
132{
133 G4bool isNew;
134 std::map<G4String,G4AttDef>* store
135 = G4AttDefStore::GetInstance("Trajectory",isNew);
136
137 if (isNew) {
138
139 G4String ID("ID");
140 (*store)[ID] = G4AttDef(ID,"Track ID","Bookkeeping","","G4int");
141
142 G4String PID("PID");
143 (*store)[PID] = G4AttDef(PID,"Parent ID","Bookkeeping","","G4int");
144
145 G4String PN("PN");
146 (*store)[PN] = G4AttDef(PN,"Particle Name","Physics","","G4String");
147
148 G4String Ch("Ch");
149 (*store)[Ch] = G4AttDef(Ch,"Charge","Physics","e+","G4double");
150
151 G4String PDG("PDG");
152 (*store)[PDG] = G4AttDef(PDG,"PDG Encoding","Physics","","G4int");
153
154 G4String IMom("IMom");
155 (*store)[IMom] = G4AttDef(IMom,
156 "Momentum of track at start of trajectory",
157 "Physics","G4BestUnit","G4ThreeVector");
158
159 G4String IMag("IMag");
160 (*store)[IMag] = G4AttDef(IMag,
161 "Magnitude of momentum of track at start of trajectory",
162 "Physics","G4BestUnit","G4double");
163
164 G4String NTP("NTP");
165 (*store)[NTP] = G4AttDef(NTP,"No. of points","Bookkeeping","","G4int");
166
167 }
168 return store;
169}
170
171std::vector<G4AttValue>* F04Trajectory::CreateAttValues() const
172{
173 std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
174
175 values->push_back
176 (G4AttValue("ID",G4UIcommand::ConvertToString(fTrackID),""));
177
178 values->push_back
179 (G4AttValue("PID",G4UIcommand::ConvertToString(fParentID),""));
180
181 values->push_back(G4AttValue("PN",ParticleName,""));
182
183 values->push_back
184 (G4AttValue("Ch",G4UIcommand::ConvertToString(PDGCharge),""));
185
186 values->push_back
187 (G4AttValue("PDG",G4UIcommand::ConvertToString(PDGEncoding),""));
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
196 (G4AttValue("NTP",G4UIcommand::ConvertToString(GetPointEntries()),""));
197
198#ifdef G4ATTDEBUG
199 G4cout << G4AttCheck(values,GetAttDefs());
200#endif
201 return values;
202}
Note: See TracBrowser for help on using the repository browser.