1 | |
---|
2 | // this : |
---|
3 | #include <G4Lab/Trajectory.h> |
---|
4 | |
---|
5 | // Lib : |
---|
6 | #include <Lib/Debug.h> |
---|
7 | |
---|
8 | // Geant4 : |
---|
9 | #include <G4Track.hh> |
---|
10 | #include <G4VProcess.hh> |
---|
11 | |
---|
12 | static G4Allocator<G4Lab::Trajectory> sTrajectoryAllocator; // Beurk. |
---|
13 | |
---|
14 | namespace G4Lab { |
---|
15 | class TrajectoryPoint { |
---|
16 | public: |
---|
17 | TrajectoryPoint(G4TrajectoryPoint* aPoint,double aGlobalTime) |
---|
18 | :fPoint(aPoint),fGlobalTime(aGlobalTime){} |
---|
19 | virtual ~TrajectoryPoint() { delete fPoint;} |
---|
20 | G4TrajectoryPoint* point() const { return fPoint;} |
---|
21 | double globalTime() const { return fGlobalTime;} |
---|
22 | private: |
---|
23 | G4TrajectoryPoint* fPoint; |
---|
24 | double fGlobalTime; |
---|
25 | Lib::Debug fDebug; // To check memory balance. |
---|
26 | }; |
---|
27 | } |
---|
28 | |
---|
29 | ////////////////////////////////////////////////////////////////////////////// |
---|
30 | G4Lab::Trajectory::Trajectory( |
---|
31 | const G4Track* aTrack |
---|
32 | ) |
---|
33 | :G4Trajectory(aTrack) |
---|
34 | ,fProcess(0) |
---|
35 | ,fSave(false) |
---|
36 | ,fStoppingVolume(0) |
---|
37 | ////////////////////////////////////////////////////////////////////////////// |
---|
38 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
39 | { |
---|
40 | fKineticEnergy = aTrack->GetKineticEnergy(); |
---|
41 | fTotalEnergy = aTrack->GetTotalEnergy(); |
---|
42 | fGlobalTime = aTrack->GetGlobalTime(); |
---|
43 | fProcess = aTrack->GetCreatorProcess(); |
---|
44 | |
---|
45 | fStoppingPoint = aTrack->GetPosition(); |
---|
46 | fStoppingVolume = aTrack->GetVolume(); |
---|
47 | |
---|
48 | /* |
---|
49 | printf("debug : G4Lab::Trajectory : \"%s\", kineticEnergy : %g, totalEnergy : %g, globalTime : %g\n", |
---|
50 | GetParticleName().c_str(), |
---|
51 | fKineticEnergy,fTotalEnergy,fGlobalTime); |
---|
52 | */ |
---|
53 | TrajectoryPoint* tp = |
---|
54 | new TrajectoryPoint( |
---|
55 | new G4TrajectoryPoint(aTrack->GetPosition()), |
---|
56 | aTrack->GetGlobalTime()); |
---|
57 | fPoints.push_back(tp); |
---|
58 | |
---|
59 | } |
---|
60 | ////////////////////////////////////////////////////////////////////////////// |
---|
61 | G4Lab::Trajectory::Trajectory( |
---|
62 | Trajectory& aFrom |
---|
63 | ) |
---|
64 | :G4Trajectory(aFrom) |
---|
65 | //,IGeant4Trajectory(aFrom) |
---|
66 | ////////////////////////////////////////////////////////////////////////////// |
---|
67 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
68 | { |
---|
69 | fKineticEnergy = aFrom.fKineticEnergy; |
---|
70 | fTotalEnergy = aFrom.fTotalEnergy; |
---|
71 | fGlobalTime = aFrom.fGlobalTime; |
---|
72 | fProcess = aFrom.fProcess; |
---|
73 | fSave = aFrom.fSave; |
---|
74 | |
---|
75 | size_t number = aFrom.fPoints.size(); |
---|
76 | for(size_t index=0;index<number;index++) { |
---|
77 | G4TrajectoryPoint* point = aFrom.fPoints[index]->point(); |
---|
78 | TrajectoryPoint* tp = |
---|
79 | new TrajectoryPoint(new G4TrajectoryPoint(*point),aFrom.fGlobalTime); |
---|
80 | fPoints.push_back(tp); |
---|
81 | } |
---|
82 | |
---|
83 | } |
---|
84 | ////////////////////////////////////////////////////////////////////////////// |
---|
85 | G4Lab::Trajectory::~Trajectory( |
---|
86 | ) |
---|
87 | ////////////////////////////////////////////////////////////////////////////// |
---|
88 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
89 | { |
---|
90 | size_t number = fPoints.size(); |
---|
91 | for(size_t index=0;index<number;index++) { |
---|
92 | delete fPoints[index]; |
---|
93 | } |
---|
94 | fPoints.clear(); |
---|
95 | } |
---|
96 | ////////////////////////////////////////////////////////////////////////////// |
---|
97 | ////////////////////////////////////////////////////////////////////////////// |
---|
98 | ////////////////////////////////////////////////////////////////////////////// |
---|
99 | ////////////////////////////////////////////////////////////////////////////// |
---|
100 | double G4Lab::Trajectory::kineticEnergy( |
---|
101 | ) const |
---|
102 | ////////////////////////////////////////////////////////////////////////////// |
---|
103 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
104 | { |
---|
105 | return fKineticEnergy; |
---|
106 | } |
---|
107 | ////////////////////////////////////////////////////////////////////////////// |
---|
108 | double G4Lab::Trajectory::totalEnergy( |
---|
109 | ) const |
---|
110 | ////////////////////////////////////////////////////////////////////////////// |
---|
111 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
112 | { |
---|
113 | return fTotalEnergy; |
---|
114 | } |
---|
115 | ////////////////////////////////////////////////////////////////////////////// |
---|
116 | double G4Lab::Trajectory::globalTime( |
---|
117 | ) const |
---|
118 | ////////////////////////////////////////////////////////////////////////////// |
---|
119 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
120 | { |
---|
121 | return fGlobalTime; |
---|
122 | } |
---|
123 | ////////////////////////////////////////////////////////////////////////////// |
---|
124 | unsigned int G4Lab::Trajectory::pointEntries( |
---|
125 | ) const |
---|
126 | ////////////////////////////////////////////////////////////////////////////// |
---|
127 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
128 | { |
---|
129 | return fPoints.size(); |
---|
130 | } |
---|
131 | ////////////////////////////////////////////////////////////////////////////// |
---|
132 | double G4Lab::Trajectory::pointGlobalTime( |
---|
133 | unsigned int aIndex |
---|
134 | ) const |
---|
135 | ////////////////////////////////////////////////////////////////////////////// |
---|
136 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
137 | { |
---|
138 | return fPoints[aIndex]->globalTime(); |
---|
139 | } |
---|
140 | ////////////////////////////////////////////////////////////////////////////// |
---|
141 | std::string G4Lab::Trajectory::creatorProcessName( |
---|
142 | ) const |
---|
143 | ////////////////////////////////////////////////////////////////////////////// |
---|
144 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
145 | { |
---|
146 | if(!fProcess) return ""; |
---|
147 | return fProcess->GetProcessName(); |
---|
148 | } |
---|
149 | ////////////////////////////////////////////////////////////////////////////// |
---|
150 | std::string G4Lab::Trajectory::creatorProcessType( |
---|
151 | ) const |
---|
152 | ////////////////////////////////////////////////////////////////////////////// |
---|
153 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
154 | { |
---|
155 | if(!fProcess) return "NotDefined"; |
---|
156 | switch(fProcess->GetProcessType()){ |
---|
157 | case fNotDefined: return "NotDefined"; |
---|
158 | case fTransportation: return "Transportation"; |
---|
159 | case fElectromagnetic: return "Electromagnetic"; |
---|
160 | case fOptical: return "Optical"; |
---|
161 | case fHadronic: return "Hadronic"; |
---|
162 | case fPhotolepton_hadron: return "Photolepton_hadron"; |
---|
163 | case fDecay: return "Decay"; |
---|
164 | case fGeneral: return "General"; |
---|
165 | case fParameterisation: return "Parameterisation"; |
---|
166 | case fUserDefined: return "UserDefined"; |
---|
167 | }; |
---|
168 | return "NotDefined"; |
---|
169 | } |
---|
170 | ////////////////////////////////////////////////////////////////////////////// |
---|
171 | void G4Lab::Trajectory::setSave( |
---|
172 | bool aFlag |
---|
173 | ) |
---|
174 | ////////////////////////////////////////////////////////////////////////////// |
---|
175 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
176 | { |
---|
177 | fSave = aFlag; |
---|
178 | } |
---|
179 | ////////////////////////////////////////////////////////////////////////////// |
---|
180 | bool G4Lab::Trajectory::save( |
---|
181 | ) const |
---|
182 | ////////////////////////////////////////////////////////////////////////////// |
---|
183 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
184 | { |
---|
185 | return fSave; |
---|
186 | } |
---|
187 | ////////////////////////////////////////////////////////////////////////////// |
---|
188 | std::vector<double> G4Lab::Trajectory::stoppingPoint( |
---|
189 | ) const |
---|
190 | ////////////////////////////////////////////////////////////////////////////// |
---|
191 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
192 | { |
---|
193 | std::vector<double> v(3); |
---|
194 | v[0] = fStoppingPoint.x(); |
---|
195 | v[1] = fStoppingPoint.y(); |
---|
196 | v[2] = fStoppingPoint.z(); |
---|
197 | return v; |
---|
198 | } |
---|
199 | ////////////////////////////////////////////////////////////////////////////// |
---|
200 | G4VPhysicalVolume* G4Lab::Trajectory::stoppingPhysicalVolume( |
---|
201 | ) const |
---|
202 | ////////////////////////////////////////////////////////////////////////////// |
---|
203 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
204 | { |
---|
205 | return fStoppingVolume; |
---|
206 | } |
---|
207 | ////////////////////////////////////////////////////////////////////////////// |
---|
208 | ////////////////////////////////////////////////////////////////////////////// |
---|
209 | ////////////////////////////////////////////////////////////////////////////// |
---|
210 | void* G4Lab::Trajectory::operator new( |
---|
211 | size_t |
---|
212 | ) |
---|
213 | ////////////////////////////////////////////////////////////////////////////// |
---|
214 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
215 | { |
---|
216 | return (void*)sTrajectoryAllocator.MallocSingle(); |
---|
217 | } |
---|
218 | ////////////////////////////////////////////////////////////////////////////// |
---|
219 | void G4Lab::Trajectory::operator delete( |
---|
220 | void* aTrajectory |
---|
221 | ) |
---|
222 | ////////////////////////////////////////////////////////////////////////////// |
---|
223 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
224 | { |
---|
225 | sTrajectoryAllocator.FreeSingle((G4Lab::Trajectory*)aTrajectory); |
---|
226 | } |
---|
227 | ////////////////////////////////////////////////////////////////////////////// |
---|
228 | int G4Lab::Trajectory::operator == ( |
---|
229 | const G4Lab::Trajectory& aRight |
---|
230 | ) const |
---|
231 | ////////////////////////////////////////////////////////////////////////////// |
---|
232 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
233 | { |
---|
234 | return (this==&aRight); |
---|
235 | } |
---|
236 | ////////////////////////////////////////////////////////////////////////////// |
---|
237 | void G4Lab::Trajectory::ShowTrajectory( |
---|
238 | std::ostream& |
---|
239 | ) const |
---|
240 | ////////////////////////////////////////////////////////////////////////////// |
---|
241 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
242 | { |
---|
243 | } |
---|
244 | ////////////////////////////////////////////////////////////////////////////// |
---|
245 | void G4Lab::Trajectory::DrawTrajectory( |
---|
246 | G4int |
---|
247 | ) const |
---|
248 | ////////////////////////////////////////////////////////////////////////////// |
---|
249 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
250 | { |
---|
251 | } |
---|
252 | ////////////////////////////////////////////////////////////////////////////// |
---|
253 | void G4Lab::Trajectory::AppendStep( |
---|
254 | const G4Step* aStep |
---|
255 | ) |
---|
256 | ////////////////////////////////////////////////////////////////////////////// |
---|
257 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
258 | { |
---|
259 | TrajectoryPoint* tp = |
---|
260 | new TrajectoryPoint( |
---|
261 | new G4TrajectoryPoint(aStep->GetPostStepPoint()->GetPosition()), |
---|
262 | aStep->GetPostStepPoint()->GetGlobalTime()); |
---|
263 | fPoints.push_back(tp); |
---|
264 | } |
---|
265 | ////////////////////////////////////////////////////////////////////////////// |
---|
266 | int G4Lab::Trajectory::GetPointEntries( |
---|
267 | ) const |
---|
268 | ////////////////////////////////////////////////////////////////////////////// |
---|
269 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
270 | { |
---|
271 | return fPoints.size(); |
---|
272 | } |
---|
273 | ////////////////////////////////////////////////////////////////////////////// |
---|
274 | G4VTrajectoryPoint* G4Lab::Trajectory::GetPoint( |
---|
275 | G4int aIndex |
---|
276 | ) const |
---|
277 | ////////////////////////////////////////////////////////////////////////////// |
---|
278 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
279 | { |
---|
280 | return fPoints[aIndex]->point(); |
---|
281 | } |
---|
282 | ////////////////////////////////////////////////////////////////////////////// |
---|
283 | void G4Lab::Trajectory::MergeTrajectory( |
---|
284 | G4VTrajectory* aTrajectory |
---|
285 | ) |
---|
286 | ////////////////////////////////////////////////////////////////////////////// |
---|
287 | // Transfer points from aTrajectory to this. |
---|
288 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
289 | { |
---|
290 | if(!aTrajectory) return; |
---|
291 | Trajectory* tj = (Trajectory*)aTrajectory; |
---|
292 | size_t number = tj->fPoints.size(); |
---|
293 | // initial point of the second trajectory should not be merged |
---|
294 | for(size_t index=1;index<number;index++) { |
---|
295 | fPoints.push_back(tj->fPoints[index]); |
---|
296 | } |
---|
297 | delete tj->fPoints[0]; |
---|
298 | tj->fPoints.clear(); |
---|
299 | } |
---|
300 | ////////////////////////////////////////////////////////////////////////////// |
---|
301 | const std::map<G4String,G4AttDef>* G4Lab::Trajectory::GetAttDefs() const |
---|
302 | ////////////////////////////////////////////////////////////////////////////// |
---|
303 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
304 | { |
---|
305 | //return G4Trajectory::GetAttDefs(); |
---|
306 | return 0; |
---|
307 | } |
---|
308 | ////////////////////////////////////////////////////////////////////////////// |
---|
309 | std::vector<G4AttValue>* G4Lab::Trajectory::CreateAttValues() const |
---|
310 | ////////////////////////////////////////////////////////////////////////////// |
---|
311 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
312 | { |
---|
313 | //return G4Trajectory::CreateAttValues(); |
---|
314 | return 0; |
---|
315 | } |
---|
316 | |
---|