source: trunk/examples/extended/runAndEvent/RE01/src/RE01Trajectory.cc@ 1036

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

update

File size: 10.0 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// $Id: RE01Trajectory.cc,v 1.3 2006/06/29 17:44:37 gunter Exp $
28// GEANT4 tag $Name: $
29//
30
31
32#include "RE01Trajectory.hh"
33#include "G4ParticleTable.hh"
34#include "G4ParticleTypes.hh"
35#include "G4Polyline.hh"
36#include "G4Circle.hh"
37#include "G4Colour.hh"
38#include "G4AttDefStore.hh"
39#include "G4AttDef.hh"
40#include "G4AttValue.hh"
41#include "G4UIcommand.hh"
42#include "G4VisAttributes.hh"
43#include "G4VVisManager.hh"
44#include "G4UnitsTable.hh"
45#include "G4DynamicParticle.hh"
46#include "G4PrimaryParticle.hh"
47#include "RE01TrackInformation.hh"
48
49G4Allocator<RE01Trajectory> myTrajectoryAllocator;
50
51RE01Trajectory::RE01Trajectory()
52:G4VTrajectory()
53{
54 fpParticleDefinition = 0;
55 ParticleName = "";
56 PDGCharge = 0;
57 PDGEncoding = 0;
58 fTrackID = 0;
59 fParentID = 0;
60 fTrackStatus = 0;
61 positionRecord = 0;
62 momentum = G4ThreeVector(0.,0.,0.);
63 vertexPosition = G4ThreeVector(0.,0.,0.);
64 globalTime = 0.;
65}
66
67RE01Trajectory::RE01Trajectory(const G4Track* aTrack)
68:G4VTrajectory()
69{
70 fpParticleDefinition = aTrack->GetDefinition();
71 ParticleName = fpParticleDefinition->GetParticleName();
72 PDGCharge = fpParticleDefinition->GetPDGCharge();
73 PDGEncoding = fpParticleDefinition->GetPDGEncoding();
74 if(ParticleName=="unknown")
75 {
76 G4PrimaryParticle*pp = aTrack->GetDynamicParticle()->GetPrimaryParticle();
77 if(pp)
78 {
79 if(pp->GetCharge()<DBL_MAX) PDGCharge = pp->GetCharge();
80 PDGEncoding = pp->GetPDGcode();
81 if(pp->GetG4code()!=0)
82 {
83 ParticleName += " : ";
84 ParticleName += pp->GetG4code()->GetParticleName();
85 }
86 }
87 }
88 fTrackID = aTrack->GetTrackID();
89 RE01TrackInformation* trackInfo
90 = (RE01TrackInformation*)(aTrack->GetUserInformation());
91 fTrackStatus = trackInfo->GetTrackingStatus();
92 if(fTrackStatus == 1)
93 { fParentID = aTrack->GetParentID(); }
94 else if(fTrackStatus == 2)
95 { fParentID = trackInfo->GetSourceTrackID(); }
96 else
97 { fParentID = -1; }
98 positionRecord = new RE01TrajectoryPointContainer();
99 positionRecord->push_back(new G4TrajectoryPoint(aTrack->GetPosition()));
100 momentum = aTrack->GetMomentum();
101 vertexPosition = aTrack->GetPosition();
102 globalTime = aTrack->GetGlobalTime();
103}
104
105RE01Trajectory::RE01Trajectory(RE01Trajectory & right)
106:G4VTrajectory()
107{
108 ParticleName = right.ParticleName;
109 fpParticleDefinition = right.fpParticleDefinition;
110 PDGCharge = right.PDGCharge;
111 PDGEncoding = right.PDGEncoding;
112 fTrackID = right.fTrackID;
113 fParentID = right.fParentID;
114 fTrackStatus = right.fTrackStatus;
115 positionRecord = new RE01TrajectoryPointContainer();
116 for(size_t i=0;i<right.positionRecord->size();i++)
117 {
118 G4TrajectoryPoint* rightPoint = (G4TrajectoryPoint*)((*(right.positionRecord))[i]);
119 positionRecord->push_back(new G4TrajectoryPoint(*rightPoint));
120 }
121 momentum = right.momentum;
122 vertexPosition = right.vertexPosition;
123 globalTime = right.globalTime;
124}
125
126RE01Trajectory::~RE01Trajectory()
127{
128 size_t i;
129 for(i=0;i<positionRecord->size();i++){
130 delete (*positionRecord)[i];
131 }
132 positionRecord->clear();
133
134 delete positionRecord;
135}
136
137void RE01Trajectory::ShowTrajectory(std::ostream& os) const
138{
139 os << G4endl << "TrackID =" << fTrackID
140 << " : ParentID=" << fParentID << " : TrackStatus=" << fTrackStatus << G4endl;
141 os << "Particle name : " << ParticleName << " PDG code : " << PDGEncoding
142 << " Charge : " << PDGCharge << G4endl;
143 os << "Original momentum : " <<
144 G4BestUnit(momentum,"Energy") << G4endl;
145 os << "Vertex : " << G4BestUnit(vertexPosition,"Length")
146 << " Global time : " << G4BestUnit(globalTime,"Time") << G4endl;
147 os << " Current trajectory has " << positionRecord->size()
148 << " points." << G4endl;
149
150 for( size_t i=0 ; i < positionRecord->size() ; i++){
151 G4TrajectoryPoint* aTrajectoryPoint = (G4TrajectoryPoint*)((*positionRecord)[i]);
152 os << "Point[" << i << "]"
153 << " Position= " << aTrajectoryPoint->GetPosition() << G4endl;
154 }
155}
156
157void RE01Trajectory::DrawTrajectory(G4int) const
158{
159
160 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
161 G4ThreeVector pos;
162
163 G4Polyline pPolyline;
164 for (size_t i = 0; i < positionRecord->size() ; i++) {
165 G4TrajectoryPoint* aTrajectoryPoint = (G4TrajectoryPoint*)((*positionRecord)[i]);
166 pos = aTrajectoryPoint->GetPosition();
167 pPolyline.push_back( pos );
168 }
169
170 G4Colour colour(0.2,0.2,0.2);
171 if(fpParticleDefinition==G4Gamma::GammaDefinition())
172 colour = G4Colour(0.,0.,1.);
173 else if(fpParticleDefinition==G4Electron::ElectronDefinition()
174 ||fpParticleDefinition==G4Positron::PositronDefinition())
175 colour = G4Colour(1.,1.,0.);
176 else if(fpParticleDefinition==G4MuonMinus::MuonMinusDefinition()
177 ||fpParticleDefinition==G4MuonPlus::MuonPlusDefinition())
178 colour = G4Colour(0.,1.,0.);
179 else if(fpParticleDefinition->GetParticleType()=="meson")
180 {
181 if(PDGCharge!=0.)
182 colour = G4Colour(1.,0.,0.);
183 else
184 colour = G4Colour(0.5,0.,0.);
185 }
186 else if(fpParticleDefinition->GetParticleType()=="baryon")
187 {
188 if(PDGCharge!=0.)
189 colour = G4Colour(0.,1.,1.);
190 else
191 colour = G4Colour(0.,0.5,0.5);
192 }
193
194 G4VisAttributes attribs(colour);
195 pPolyline.SetVisAttributes(attribs);
196 if(pVVisManager) pVVisManager->Draw(pPolyline);
197}
198
199const std::map<G4String,G4AttDef>* RE01Trajectory::GetAttDefs() const
200{
201 G4bool isNew;
202 std::map<G4String,G4AttDef>* store
203 = G4AttDefStore::GetInstance("RE01Trajectory",isNew);
204 if (isNew) {
205
206 G4String ID("ID");
207 (*store)[ID] = G4AttDef(ID,"Track ID","Bookkeeping","","G4int");
208
209 G4String PID("PID");
210 (*store)[PID] = G4AttDef(PID,"Parent ID","Bookkeeping","","G4int");
211
212 G4String Status("Status");
213 (*store)[Status] = G4AttDef(Status,"Track Status","Bookkeeping","","G4int");
214
215 G4String PN("PN");
216 (*store)[PN] = G4AttDef(PN,"Particle Name","Bookkeeping","","G4String");
217
218 G4String Ch("Ch");
219 (*store)[Ch] = G4AttDef(Ch,"Charge","Physics","e+","G4double");
220
221 G4String PDG("PDG");
222 (*store)[PDG] = G4AttDef(PDG,"PDG Encoding","Bookkeeping","","G4int");
223
224 G4String IMom("IMom");
225 (*store)[IMom] = G4AttDef(IMom, "Momentum of track at start of trajectory",
226 "Physics","G4BestUnit","G4ThreeVector");
227
228 G4String IMag("IMag");
229 (*store)[IMag] =
230 G4AttDef(IMag, "Magnitude of momentum of track at start of trajectory",
231 "Physics","G4BestUnit","G4double");
232
233 G4String VtxPos("VtxPos");
234 (*store)[VtxPos] = G4AttDef(VtxPos, "Vertex position",
235 "Physics","G4BestUnit","G4ThreeVector");
236
237 G4String NTP("NTP");
238 (*store)[NTP] = G4AttDef(NTP,"No. of points","Bookkeeping","","G4int");
239
240 }
241 return store;
242}
243
244std::vector<G4AttValue>* RE01Trajectory::CreateAttValues() const
245{
246 std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
247
248 values->push_back
249 (G4AttValue("ID",G4UIcommand::ConvertToString(fTrackID),""));
250
251 values->push_back
252 (G4AttValue("PID",G4UIcommand::ConvertToString(fParentID),""));
253
254 values->push_back
255 (G4AttValue("Status",G4UIcommand::ConvertToString(fTrackStatus),""));
256
257 values->push_back(G4AttValue("PN",ParticleName,""));
258
259 values->push_back
260 (G4AttValue("Ch",G4UIcommand::ConvertToString(PDGCharge),""));
261
262 values->push_back
263 (G4AttValue("PDG",G4UIcommand::ConvertToString(PDGEncoding),""));
264
265 values->push_back
266 (G4AttValue("IMom",G4BestUnit(momentum,"Energy"),""));
267
268 values->push_back
269 (G4AttValue("IMag",G4BestUnit(momentum.mag(),"Energy"),""));
270
271 values->push_back
272 (G4AttValue("VtxPos",G4BestUnit(vertexPosition,"Length"),""));
273
274 values->push_back
275 (G4AttValue("NTP",G4UIcommand::ConvertToString(GetPointEntries()),""));
276
277 return values;
278}
279
280void RE01Trajectory::AppendStep(const G4Step* aStep)
281{
282 positionRecord->push_back( new G4TrajectoryPoint(aStep->GetPostStepPoint()->
283 GetPosition() ));
284}
285
286G4ParticleDefinition* RE01Trajectory::GetParticleDefinition()
287{
288 return (G4ParticleTable::GetParticleTable()->FindParticle(ParticleName));
289}
290
291void RE01Trajectory::MergeTrajectory(G4VTrajectory* secondTrajectory)
292{
293 if(!secondTrajectory) return;
294
295 RE01Trajectory* seco = (RE01Trajectory*)secondTrajectory;
296 G4int ent = seco->GetPointEntries();
297 for(int i=1;i<ent;i++) // initial point of the second trajectory should not be merged
298 {
299 positionRecord->push_back((*(seco->positionRecord))[i]);
300 }
301 delete (*seco->positionRecord)[0];
302 seco->positionRecord->clear();
303
304}
305
306
307
Note: See TracBrowser for help on using the repository browser.