source: snovis/trunk/source/G4Lab/cxx/Trajectory.cxx @ 233

Last change on this file since 233 was 233, checked in by barrand, 17 years ago
  • Property svn:eol-style set to native
File size: 7.2 KB
Line 
1
2// this :
3#include <G4Lab/Trajectory.h>
4
5// Lib :
6#include <Lib/Debug.h>
7
8// Geant4 :
9#include <G4Track.hh>
10
11static G4Allocator<G4Lab::Trajectory> sTrajectoryAllocator; // Beurk.
12
13namespace G4Lab {
14class TrajectoryPoint {
15public:
16  TrajectoryPoint(G4TrajectoryPoint* aPoint,double aGlobalTime)
17    :fPoint(aPoint),fGlobalTime(aGlobalTime){}
18  virtual ~TrajectoryPoint() { delete fPoint;}
19  G4TrajectoryPoint* point() const { return fPoint;}
20  double globalTime() const { return fGlobalTime;}
21private:
22  G4TrajectoryPoint* fPoint;
23  double fGlobalTime;
24  Lib::Debug fDebug; // To check memory balance.
25};
26}
27
28//////////////////////////////////////////////////////////////////////////////
29G4Lab::Trajectory::Trajectory(
30 const G4Track* aTrack
31)
32:G4Trajectory(aTrack) 
33//////////////////////////////////////////////////////////////////////////////
34//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
35{
36  fKineticEnergy = aTrack->GetKineticEnergy();
37  fTotalEnergy = aTrack->GetTotalEnergy();
38  fGlobalTime = aTrack->GetGlobalTime();
39  /*
40  printf("debug : G4Lab::Trajectory : \"%s\", kineticEnergy : %g, totalEnergy : %g, globalTime : %g\n",
41         GetParticleName().c_str(),
42         fKineticEnergy,fTotalEnergy,fGlobalTime);
43  */
44  TrajectoryPoint* tp = 
45    new TrajectoryPoint(
46     new G4TrajectoryPoint(aTrack->GetPosition()),
47     aTrack->GetGlobalTime());
48  fPoints.push_back(tp);
49}
50//////////////////////////////////////////////////////////////////////////////
51G4Lab::Trajectory::Trajectory(
52 Trajectory& aRight
53)
54:G4Trajectory(aRight) 
55//////////////////////////////////////////////////////////////////////////////
56//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
57{
58  fKineticEnergy = aRight.fKineticEnergy;
59  fTotalEnergy = aRight.fTotalEnergy;
60  fGlobalTime = aRight.fGlobalTime;
61
62  size_t number = aRight.fPoints.size();
63  for(size_t index=0;index<number;index++) {
64    G4TrajectoryPoint* point = aRight.fPoints[index]->point();
65    TrajectoryPoint* tp = 
66      new TrajectoryPoint(new G4TrajectoryPoint(*point),aRight.fGlobalTime);
67    fPoints.push_back(tp);
68  }
69 
70}
71//////////////////////////////////////////////////////////////////////////////
72G4Lab::Trajectory::~Trajectory(
73) 
74//////////////////////////////////////////////////////////////////////////////
75//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
76{
77  size_t number = fPoints.size();
78  for(size_t index=0;index<number;index++) {
79    delete fPoints[index];
80  }
81  fPoints.clear();
82}
83//////////////////////////////////////////////////////////////////////////////
84G4double G4Lab::Trajectory::GetKineticEnergy(
85) const 
86//////////////////////////////////////////////////////////////////////////////
87//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
88{
89  return fKineticEnergy;
90}
91//////////////////////////////////////////////////////////////////////////////
92G4double G4Lab::Trajectory::GetTotalEnergy(
93) const 
94//////////////////////////////////////////////////////////////////////////////
95//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
96{
97  return fTotalEnergy;
98}
99//////////////////////////////////////////////////////////////////////////////
100G4double G4Lab::Trajectory::GetGlobalTime(
101) const 
102//////////////////////////////////////////////////////////////////////////////
103//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
104{
105  return fGlobalTime;
106}
107//////////////////////////////////////////////////////////////////////////////
108/*inline*/ void* G4Lab::Trajectory::operator new(
109 size_t
110) 
111//////////////////////////////////////////////////////////////////////////////
112//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
113{
114  return (void*)sTrajectoryAllocator.MallocSingle();
115}
116//////////////////////////////////////////////////////////////////////////////
117/*inline*/ void G4Lab::Trajectory::operator delete(
118 void* aTrajectory
119) 
120//////////////////////////////////////////////////////////////////////////////
121//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
122{
123  sTrajectoryAllocator.FreeSingle((G4Lab::Trajectory*)aTrajectory);
124}
125//////////////////////////////////////////////////////////////////////////////
126/*inline*/ int G4Lab::Trajectory::operator == (
127 const G4Lab::Trajectory& aRight
128) const 
129//////////////////////////////////////////////////////////////////////////////
130//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
131{
132  return (this==&aRight);
133} 
134//////////////////////////////////////////////////////////////////////////////
135void G4Lab::Trajectory::ShowTrajectory(
136 std::ostream&
137) const
138//////////////////////////////////////////////////////////////////////////////
139//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
140{
141}
142//////////////////////////////////////////////////////////////////////////////
143void G4Lab::Trajectory::DrawTrajectory(
144 G4int
145) const
146//////////////////////////////////////////////////////////////////////////////
147//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
148{
149}
150//////////////////////////////////////////////////////////////////////////////
151void G4Lab::Trajectory::AppendStep(
152 const G4Step* aStep
153)
154//////////////////////////////////////////////////////////////////////////////
155//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
156{
157  TrajectoryPoint* tp = 
158    new TrajectoryPoint(
159      new G4TrajectoryPoint(aStep->GetPostStepPoint()->GetPosition()),
160      aStep->GetPostStepPoint()->GetGlobalTime());
161  fPoints.push_back(tp);
162}
163//////////////////////////////////////////////////////////////////////////////
164int G4Lab::Trajectory::GetPointEntries(
165) const
166//////////////////////////////////////////////////////////////////////////////
167//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
168{
169  return fPoints.size();
170}
171//////////////////////////////////////////////////////////////////////////////
172G4VTrajectoryPoint* G4Lab::Trajectory::GetPoint(
173 G4int aIndex
174) const
175//////////////////////////////////////////////////////////////////////////////
176//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
177{
178  return fPoints[aIndex]->point();
179}
180//////////////////////////////////////////////////////////////////////////////
181G4double G4Lab::Trajectory::GetPointGlobalTime(
182 G4int aIndex
183) const
184//////////////////////////////////////////////////////////////////////////////
185//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
186{
187  return fPoints[aIndex]->globalTime();
188}
189//////////////////////////////////////////////////////////////////////////////
190void G4Lab::Trajectory::MergeTrajectory(
191 G4VTrajectory* aTrajectory
192)
193//////////////////////////////////////////////////////////////////////////////
194// Transfer points from aTrajectory to this.
195//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
196{
197  if(!aTrajectory) return;
198  Trajectory* tj = (Trajectory*)aTrajectory;
199  size_t number = tj->fPoints.size();
200  // initial point of the second trajectory should not be merged
201  for(size_t index=1;index<number;index++) { 
202    fPoints.push_back(tj->fPoints[index]);
203  }
204  delete tj->fPoints[0];
205  tj->fPoints.clear();
206}
Note: See TracBrowser for help on using the repository browser.