source: ELYSE/HEAD/source/Trajectory.cxx @ 286

Last change on this file since 286 was 286, checked in by campagne, 17 years ago

ELYSE sauvegarde provisoire (JEC)

File size: 6.7 KB
Line 
1#include "ELYSE/Trajectory.hh"
2
3//Geant4
4#include "G4TrajectoryPoint.hh"
5#include "G4ParticleTable.hh"
6#include "G4AttDefStore.hh"
7#include "G4AttDef.hh"
8#include "G4AttValue.hh"
9#include "G4UnitsTable.hh"
10#include "G4VProcess.hh"
11
12//std
13#include <sstream>
14
15namespace ELYSE {
16  G4Allocator<Trajectory> myTrajectoryAllocator;
17}
18
19ELYSE::Trajectory::Trajectory()
20  :  positionRecord(0), 
21     fTrackID(0), 
22     fParentID(0),
23     PDGEncoding(0), 
24     PDGCharge(0.0), 
25     ParticleName(""),
26     initialMomentum( G4ThreeVector() ),
27     SaveIt(false),
28     creatorProcess(""),
29     globalTime(0.0)
30{;}//Ctor
31
32//----------------------------------------------------------------------------------------------------
33
34ELYSE::Trajectory::Trajectory(const G4Track* aTrack) {
35
36  // Following is for the first trajectory point
37  positionRecord = new TrajectoryPointContainer();
38  positionRecord->push_back(new G4TrajectoryPoint(aTrack->GetPosition()));
39
40  fTrackID = aTrack->GetTrackID();
41  fParentID = aTrack->GetParentID();
42
43
44  G4ParticleDefinition * fpParticleDefinition = aTrack->GetDefinition();
45  PDGEncoding = fpParticleDefinition->GetPDGEncoding();
46  PDGCharge = fpParticleDefinition->GetPDGCharge();
47  ParticleName = fpParticleDefinition->GetParticleName();
48  initialMomentum = aTrack->GetMomentum();
49
50  stoppingPoint  = aTrack->GetPosition();
51  stoppingVolume = aTrack->GetVolume();
52
53  //SaveIt = false at creation time
54  SaveIt = false;
55
56  if (aTrack->GetCreatorProcess() != 0 ) {
57    const G4VProcess* tempproc = aTrack->GetCreatorProcess();
58    creatorProcess = tempproc->GetProcessName();
59  } else {
60    creatorProcess = "";
61  }
62
63  globalTime = aTrack->GetGlobalTime();
64} //Ctor
65
66//----------------------------------------------------------------------------------------------------
67
68ELYSE::Trajectory::Trajectory(ELYSE::Trajectory & right):G4VTrajectory() {
69
70  positionRecord = new TrajectoryPointContainer();
71  for(size_t i=0;i<right.positionRecord->size();i++) {
72    G4TrajectoryPoint* rightPoint = (G4TrajectoryPoint*)((*(right.positionRecord))[i]);
73    positionRecord->push_back(new G4TrajectoryPoint(*rightPoint));
74  }
75
76  fTrackID         = right.fTrackID;
77  fParentID        = right.fParentID;
78  PDGEncoding      = right.PDGEncoding;
79  PDGCharge        = right.PDGCharge;
80  ParticleName     = right.ParticleName;
81  initialMomentum  = right.initialMomentum;
82  stoppingPoint    = right.stoppingPoint;
83  stoppingVolume   = right.stoppingVolume;
84  SaveIt           = right.SaveIt;
85  creatorProcess   = right.creatorProcess;
86  globalTime       = right.globalTime;
87}//Ctor
88
89//----------------------------------------------------------------------------------------------------
90
91ELYSE::Trajectory::~Trajectory() {
92  //  positionRecord->clearAndDestroy();
93  size_t i;
94  for(i=0;i<positionRecord->size();i++){
95    delete  (*positionRecord)[i];
96  }
97  positionRecord->clear();
98 
99  delete positionRecord;
100} //Dtor
101
102//----------------------------------------------------------------------------------------------------
103
104
105void ELYSE::Trajectory::ShowTrajectory(std::ostream& os) const {
106  // Invoke the default implementation in G4VTrajectory...
107  G4VTrajectory::ShowTrajectory(os);
108  // ... or override with your own code here.
109}//ShowTrajectory
110
111//----------------------------------------------------------------------------------------------------
112
113void ELYSE::Trajectory::DrawTrajectory(G4int i_mode) const {
114  // Invoke the default implementation in G4VTrajectory...
115  G4VTrajectory::DrawTrajectory(i_mode);
116  // ... or override with your own code here.
117}//DrawTrajectory
118
119//----------------------------------------------------------------------------------------------------
120
121const std::map<G4String,G4AttDef>* ELYSE::Trajectory::GetAttDefs() const {
122  G4bool isNew;
123  std::map<G4String,G4AttDef>* store = G4AttDefStore::GetInstance("Trajectory",isNew);
124
125  if (isNew) {   
126    G4String ID("ID");
127    (*store)[ID] = G4AttDef(ID,"Track ID","Bookkeeping","","G4int");
128   
129    G4String PID("PID");
130    (*store)[PID] = G4AttDef(PID,"Parent ID","Bookkeeping","","G4int");
131   
132    G4String PN("PN");
133    (*store)[PN] = G4AttDef(PN,"Particle Name","Physics","","G4String");
134   
135    G4String Ch("Ch");
136    (*store)[Ch] = G4AttDef(Ch,"Charge","Physics","","G4double");
137   
138    G4String PDG("PDG");
139    (*store)[PDG] = G4AttDef(PDG,"PDG Encoding","Physics","","G4int");
140   
141    G4String IMom("IMom");
142    (*store)[IMom] = G4AttDef(IMom, "Momentum of track at start of trajectory",
143                              "Physics","","G4ThreeVector");
144   
145    G4String NTP("NTP");
146    (*store)[NTP] = G4AttDef(NTP,"No. of points","Physics","","G4int");
147   
148  }
149  return store;
150}//GetAttDefs
151
152//----------------------------------------------------------------------------------------------------
153
154std::vector<G4AttValue>* ELYSE::Trajectory::CreateAttValues() const {
155
156  //JEC 1/12/05 use sstream std library
157  std::ostringstream s;
158 
159  std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
160 
161  s.str("");
162  s << fTrackID;
163  values->push_back(G4AttValue("ID",s.str(),""));
164 
165  s.str("");
166  s << fParentID;
167  values->push_back(G4AttValue("PID",s.str(),""));
168 
169  values->push_back(G4AttValue("PN",ParticleName,""));
170 
171  s.str("");
172  s << PDGCharge;
173  values->push_back(G4AttValue("Ch",s.str(),""));
174
175  s.str("");
176  s << PDGEncoding;
177  values->push_back(G4AttValue("PDG",s.str(),""));
178
179  s.str("");
180  s << G4BestUnit(initialMomentum,"Energy");
181  values->push_back(G4AttValue("IMom",s.str(),""));
182
183  s.str("");
184  s << GetPointEntries();
185  values->push_back(G4AttValue("NTP",s.str(),""));
186
187  return values;
188}//CreateAttValues
189
190//----------------------------------------------------------------------------------------------------
191
192void ELYSE::Trajectory::AppendStep(const G4Step* aStep) {
193  positionRecord->push_back( new G4TrajectoryPoint(aStep->GetPostStepPoint()->GetPosition() ));
194}//AppendStep
195
196//----------------------------------------------------------------------------------------------------
197
198
199G4ParticleDefinition* ELYSE::Trajectory::GetParticleDefinition() {
200  return (G4ParticleTable::GetParticleTable()->FindParticle(ParticleName));
201}//GetParticleDefinition
202
203//----------------------------------------------------------------------------------------------------
204
205
206void ELYSE::Trajectory::MergeTrajectory(G4VTrajectory* secondTrajectory) {
207  if(!secondTrajectory) return;
208
209  Trajectory* seco         = (Trajectory*)secondTrajectory;
210
211  stoppingPoint  = seco->stoppingPoint;
212  stoppingVolume = seco->stoppingVolume;
213 
214  G4int ent = seco->GetPointEntries();
215  for(G4int i=1;i<ent;i++) // initial point of the second trajectory should not be merged
216  { 
217    positionRecord->push_back((*(seco->positionRecord))[i]);
218    //    positionRecord->push_back(seco->positionRecord->removeAt(1));
219  }
220  delete (*seco->positionRecord)[0];
221  seco->positionRecord->clear();
222}//MergeTrajectory
223
224
Note: See TracBrowser for help on using the repository browser.