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: G4RichTrajectory.cc,v 1.9 2010/02/22 21:26:56 allison Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-04-beta-01 $ |
---|
29 | // |
---|
30 | // --------------------------------------------------------------- |
---|
31 | // |
---|
32 | // G4RichTrajectory.cc |
---|
33 | // |
---|
34 | // Contact: |
---|
35 | // Questions and comments on G4Trajectory, on which this is based, |
---|
36 | // should be sent to |
---|
37 | // Katsuya Amako (e-mail: Katsuya.Amako@kek.jp) |
---|
38 | // Makoto Asai (e-mail: asai@kekvax.kek.jp) |
---|
39 | // Takashi Sasaki (e-mail: Takashi.Sasaki@kek.jp) |
---|
40 | // and on the extended code to: |
---|
41 | // John Allison (e-mail: John.Allison@manchester.ac.uk) |
---|
42 | // Joseph Perl (e-mail: perl@slac.stanford.edu) |
---|
43 | // |
---|
44 | // --------------------------------------------------------------- |
---|
45 | |
---|
46 | #include "G4RichTrajectory.hh" |
---|
47 | #include "G4RichTrajectoryPoint.hh" |
---|
48 | #include "G4AttDefStore.hh" |
---|
49 | #include "G4AttDef.hh" |
---|
50 | #include "G4AttValue.hh" |
---|
51 | #include "G4UnitsTable.hh" |
---|
52 | #include "G4VProcess.hh" |
---|
53 | |
---|
54 | //#define G4ATTDEBUG |
---|
55 | #ifdef G4ATTDEBUG |
---|
56 | #include "G4AttCheck.hh" |
---|
57 | #endif |
---|
58 | |
---|
59 | #include <sstream> |
---|
60 | |
---|
61 | G4Allocator<G4RichTrajectory> aRichTrajectoryAllocator; |
---|
62 | |
---|
63 | G4RichTrajectory::G4RichTrajectory(): |
---|
64 | fpRichPointsContainer(0), |
---|
65 | fpCreatorProcess(0), |
---|
66 | fpEndingProcess(0), |
---|
67 | fFinalKineticEnergy(0.) |
---|
68 | {} |
---|
69 | |
---|
70 | G4RichTrajectory::G4RichTrajectory(const G4Track* aTrack): |
---|
71 | G4Trajectory(aTrack) // Note: this initialises the base class data |
---|
72 | // members and, unfortunately but never mind, |
---|
73 | // creates a G4TrajectoryPoint in |
---|
74 | // TrajectoryPointContainer that we cannot |
---|
75 | // access because it's private. We store the |
---|
76 | // same information (plus more) in a |
---|
77 | // G4RichTrajectoryPoint in the |
---|
78 | // RichTrajectoryPointsContainer |
---|
79 | { |
---|
80 | fpInitialVolume = aTrack->GetTouchableHandle(); |
---|
81 | fpInitialNextVolume = aTrack->GetNextTouchableHandle(); |
---|
82 | fpCreatorProcess = aTrack->GetCreatorProcess(); |
---|
83 | // On construction, set final values to initial values. |
---|
84 | // Final values are updated at the addition of every step - see AppendStep. |
---|
85 | fpFinalVolume = aTrack->GetTouchableHandle(); |
---|
86 | fpFinalNextVolume = aTrack->GetNextTouchableHandle(); |
---|
87 | fpEndingProcess = aTrack->GetCreatorProcess(); |
---|
88 | fFinalKineticEnergy = aTrack->GetKineticEnergy(); |
---|
89 | // Insert the first rich trajectory point (see note above)... |
---|
90 | fpRichPointsContainer = new RichTrajectoryPointsContainer; |
---|
91 | fpRichPointsContainer->push_back(new G4RichTrajectoryPoint(aTrack)); |
---|
92 | } |
---|
93 | |
---|
94 | G4RichTrajectory::G4RichTrajectory(G4RichTrajectory & right): |
---|
95 | G4Trajectory(right) |
---|
96 | { |
---|
97 | fpInitialVolume = right.fpInitialVolume; |
---|
98 | fpInitialNextVolume = right.fpInitialNextVolume; |
---|
99 | fpCreatorProcess = right.fpCreatorProcess; |
---|
100 | fpFinalVolume = right.fpFinalVolume; |
---|
101 | fpFinalNextVolume = right.fpFinalNextVolume; |
---|
102 | fpEndingProcess = right.fpEndingProcess; |
---|
103 | fFinalKineticEnergy = right.fFinalKineticEnergy; |
---|
104 | fpRichPointsContainer = new RichTrajectoryPointsContainer; |
---|
105 | for(size_t i=0;i<right.fpRichPointsContainer->size();i++) |
---|
106 | { |
---|
107 | G4RichTrajectoryPoint* rightPoint = |
---|
108 | (G4RichTrajectoryPoint*)((*(right.fpRichPointsContainer))[i]); |
---|
109 | fpRichPointsContainer->push_back(new G4RichTrajectoryPoint(*rightPoint)); |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | G4RichTrajectory::~G4RichTrajectory() |
---|
114 | { |
---|
115 | if (fpRichPointsContainer) { |
---|
116 | // fpRichPointsContainer->clearAndDestroy(); |
---|
117 | size_t i; |
---|
118 | for(i=0;i<fpRichPointsContainer->size();i++){ |
---|
119 | delete (*fpRichPointsContainer)[i]; |
---|
120 | } |
---|
121 | fpRichPointsContainer->clear(); |
---|
122 | delete fpRichPointsContainer; |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | void G4RichTrajectory::AppendStep(const G4Step* aStep) |
---|
127 | { |
---|
128 | fpRichPointsContainer->push_back(new G4RichTrajectoryPoint(aStep)); |
---|
129 | // Except for first step, which is a sort of virtual step to start |
---|
130 | // the track, compute the final values... |
---|
131 | const G4Track* track = aStep->GetTrack(); |
---|
132 | const G4StepPoint* postStepPoint = aStep->GetPostStepPoint(); |
---|
133 | if (track->GetCurrentStepNumber() > 0) { |
---|
134 | fpFinalVolume = track->GetTouchableHandle(); |
---|
135 | fpFinalNextVolume = track->GetNextTouchableHandle(); |
---|
136 | fpEndingProcess = postStepPoint->GetProcessDefinedStep(); |
---|
137 | fFinalKineticEnergy = |
---|
138 | aStep->GetPreStepPoint()->GetKineticEnergy() - |
---|
139 | aStep->GetTotalEnergyDeposit(); |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | void G4RichTrajectory::MergeTrajectory(G4VTrajectory* secondTrajectory) |
---|
144 | { |
---|
145 | if(!secondTrajectory) return; |
---|
146 | |
---|
147 | G4RichTrajectory* seco = (G4RichTrajectory*)secondTrajectory; |
---|
148 | G4int ent = seco->GetPointEntries(); |
---|
149 | for(G4int i=1;i<ent;i++) { |
---|
150 | // initial point of the second trajectory should not be merged |
---|
151 | fpRichPointsContainer->push_back((*(seco->fpRichPointsContainer))[i]); |
---|
152 | // fpRichPointsContainer->push_back(seco->fpRichPointsContainer->removeAt(1)); |
---|
153 | } |
---|
154 | delete (*seco->fpRichPointsContainer)[0]; |
---|
155 | seco->fpRichPointsContainer->clear(); |
---|
156 | } |
---|
157 | |
---|
158 | const std::map<G4String,G4AttDef>* G4RichTrajectory::GetAttDefs() const |
---|
159 | { |
---|
160 | G4bool isNew; |
---|
161 | std::map<G4String,G4AttDef>* store |
---|
162 | = G4AttDefStore::GetInstance("G4RichTrajectory",isNew); |
---|
163 | if (isNew) { |
---|
164 | |
---|
165 | // Get att defs from base class... |
---|
166 | *store = *(G4Trajectory::GetAttDefs()); |
---|
167 | |
---|
168 | G4String ID; |
---|
169 | |
---|
170 | ID = "IVPath"; |
---|
171 | (*store)[ID] = G4AttDef(ID,"Initial Volume Path", |
---|
172 | "Physics","","G4String"); |
---|
173 | |
---|
174 | ID = "INVPath"; |
---|
175 | (*store)[ID] = G4AttDef(ID,"Initial Next Volume Path", |
---|
176 | "Physics","","G4String"); |
---|
177 | |
---|
178 | ID = "CPN"; |
---|
179 | (*store)[ID] = G4AttDef(ID,"Creator Process Name", |
---|
180 | "Physics","","G4String"); |
---|
181 | |
---|
182 | ID = "CPTN"; |
---|
183 | (*store)[ID] = G4AttDef(ID,"Creator Process Type Name", |
---|
184 | "Physics","","G4String"); |
---|
185 | |
---|
186 | ID = "FVPath"; |
---|
187 | (*store)[ID] = G4AttDef(ID,"Final Volume Path", |
---|
188 | "Physics","","G4String"); |
---|
189 | |
---|
190 | ID = "FNVPath"; |
---|
191 | (*store)[ID] = G4AttDef(ID,"Final Next Volume Path", |
---|
192 | "Physics","","G4String"); |
---|
193 | |
---|
194 | ID = "EPN"; |
---|
195 | (*store)[ID] = G4AttDef(ID,"Ending Process Name", |
---|
196 | "Physics","","G4String"); |
---|
197 | |
---|
198 | ID = "EPTN"; |
---|
199 | (*store)[ID] = G4AttDef(ID,"Ending Process Type Name", |
---|
200 | "Physics","","G4String"); |
---|
201 | |
---|
202 | ID = "FKE"; |
---|
203 | (*store)[ID] = G4AttDef(ID,"Final kinetic energy", |
---|
204 | "Physics","G4BestUnit","G4double"); |
---|
205 | |
---|
206 | } |
---|
207 | |
---|
208 | return store; |
---|
209 | } |
---|
210 | |
---|
211 | static G4String Path(const G4TouchableHandle& th) |
---|
212 | { |
---|
213 | std::ostringstream oss; |
---|
214 | G4int depth = th->GetHistoryDepth(); |
---|
215 | for (G4int i = depth; i >= 0; --i) { |
---|
216 | oss << th->GetVolume(i)->GetName() |
---|
217 | << ':' << th->GetCopyNumber(i); |
---|
218 | if (i != 0) oss << '/'; |
---|
219 | } |
---|
220 | return oss.str(); |
---|
221 | } |
---|
222 | |
---|
223 | std::vector<G4AttValue>* G4RichTrajectory::CreateAttValues() const |
---|
224 | { |
---|
225 | // Create base class att values... |
---|
226 | std::vector<G4AttValue>* values = G4Trajectory::CreateAttValues(); |
---|
227 | |
---|
228 | if (fpInitialVolume && fpInitialVolume->GetVolume()) { |
---|
229 | values->push_back(G4AttValue("IVPath",Path(fpInitialVolume),"")); |
---|
230 | } else { |
---|
231 | values->push_back(G4AttValue("IVPath","None","")); |
---|
232 | } |
---|
233 | |
---|
234 | if (fpInitialNextVolume && fpInitialNextVolume->GetVolume()) { |
---|
235 | values->push_back(G4AttValue("INVPath",Path(fpInitialNextVolume),"")); |
---|
236 | } else { |
---|
237 | values->push_back(G4AttValue("INVPath","None","")); |
---|
238 | } |
---|
239 | |
---|
240 | if (fpCreatorProcess) { |
---|
241 | values->push_back(G4AttValue("CPN",fpCreatorProcess->GetProcessName(),"")); |
---|
242 | G4ProcessType type = fpCreatorProcess->GetProcessType(); |
---|
243 | values->push_back(G4AttValue("CPTN",G4VProcess::GetProcessTypeName(type),"")); |
---|
244 | } else { |
---|
245 | values->push_back(G4AttValue("CPN","None","")); |
---|
246 | values->push_back(G4AttValue("CPTN","None","")); |
---|
247 | } |
---|
248 | |
---|
249 | if (fpFinalVolume && fpFinalVolume->GetVolume()) { |
---|
250 | values->push_back(G4AttValue("FVPath",Path(fpFinalVolume),"")); |
---|
251 | } else { |
---|
252 | values->push_back(G4AttValue("FVPath","None","")); |
---|
253 | } |
---|
254 | |
---|
255 | if (fpFinalNextVolume && fpFinalNextVolume->GetVolume()) { |
---|
256 | values->push_back(G4AttValue("FNVPath",Path(fpFinalNextVolume),"")); |
---|
257 | } else { |
---|
258 | values->push_back(G4AttValue("FNVPath","None","")); |
---|
259 | } |
---|
260 | |
---|
261 | if (fpEndingProcess) { |
---|
262 | values->push_back(G4AttValue("EPN",fpEndingProcess->GetProcessName(),"")); |
---|
263 | G4ProcessType type = fpEndingProcess->GetProcessType(); |
---|
264 | values->push_back(G4AttValue("EPTN",G4VProcess::GetProcessTypeName(type),"")); |
---|
265 | } else { |
---|
266 | values->push_back(G4AttValue("EPN","None","")); |
---|
267 | values->push_back(G4AttValue("EPTN","None","")); |
---|
268 | } |
---|
269 | |
---|
270 | values->push_back |
---|
271 | (G4AttValue("FKE",G4BestUnit(fFinalKineticEnergy,"Energy"),"")); |
---|
272 | |
---|
273 | #ifdef G4ATTDEBUG |
---|
274 | G4cout << G4AttCheck(values,GetAttDefs()); |
---|
275 | #endif |
---|
276 | |
---|
277 | return values; |
---|
278 | } |
---|