Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4RichTrajectory.cc
Go to the documentation of this file.
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// G4RichTrajectory class implementation
27//
28// Contact:
29// Questions and comments on G4Trajectory, on which this is based,
30// should be sent to
31// Katsuya Amako (e-mail: Katsuya.Amako@kek.jp)
32// Makoto Asai (e-mail: asai@slac.stanford.edu)
33// Takashi Sasaki (e-mail: Takashi.Sasaki@kek.jp)
34// and on the extended code to:
35// John Allison (e-mail: John.Allison@manchester.ac.uk)
36// Joseph Perl (e-mail: perl@slac.stanford.edu)
37// --------------------------------------------------------------------
38
39#include "G4RichTrajectory.hh"
41
42#include "G4ParticleTable.hh"
43#include "G4AttDef.hh"
44#include "G4AttDefStore.hh"
45#include "G4AttValue.hh"
48#include "G4UIcommand.hh"
49#include "G4UnitsTable.hh"
50#include "G4VProcess.hh"
51
52namespace {
53 G4Mutex CloneRichTrajectoryMutex = G4MUTEX_INITIALIZER;
54}
55
56// #define G4ATTDEBUG
57#ifdef G4ATTDEBUG
58# include "G4AttCheck.hh"
59#endif
60
61#include <sstream>
62
68
70{
71 G4ParticleDefinition* fpParticleDefinition = aTrack->GetDefinition();
72 ParticleName = fpParticleDefinition->GetParticleName();
73 PDGCharge = fpParticleDefinition->GetPDGCharge();
74 PDGEncoding = fpParticleDefinition->GetPDGEncoding();
75 fTrackID = aTrack->GetTrackID();
76 fParentID = aTrack->GetParentID();
77 initialKineticEnergy = aTrack->GetKineticEnergy();
78 initialMomentum = aTrack->GetMomentum();
79 positionRecord = new G4TrajectoryPointContainer();
80
81 // Following is for the first trajectory point
82 positionRecord->push_back(new G4RichTrajectoryPoint(aTrack));
83
84 fpInitialVolume = aTrack->GetTouchableHandle();
85 fpInitialNextVolume = aTrack->GetNextTouchableHandle();
86 fpCreatorProcess = aTrack->GetCreatorProcess();
87 fCreatorModelID = aTrack->GetCreatorModelID();
88
89 // On construction, set final values to initial values.
90 // Final values are updated at the addition of every step - see AppendStep.
91 //
92 fpFinalVolume = aTrack->GetTouchableHandle();
93 fpFinalNextVolume = aTrack->GetNextTouchableHandle();
94 fpEndingProcess = aTrack->GetCreatorProcess();
95 fFinalKineticEnergy = aTrack->GetKineticEnergy();
96
97 // Insert the first rich trajectory point (see note above)...
98 //
99 fpRichPointContainer = new G4TrajectoryPointContainer;
100 fpRichPointContainer->push_back(new G4RichTrajectoryPoint(aTrack));
101}
102
105{
106 ParticleName = right.ParticleName;
107 PDGCharge = right.PDGCharge;
108 PDGEncoding = right.PDGEncoding;
109 fTrackID = right.fTrackID;
110 fParentID = right.fParentID;
111 initialKineticEnergy = right.initialKineticEnergy;
112 initialMomentum = right.initialMomentum;
113 positionRecord = new G4TrajectoryPointContainer();
114
115 for (auto& i : *right.positionRecord) {
116 auto rightPoint = (G4RichTrajectoryPoint*)i;
117 positionRecord->push_back(new G4RichTrajectoryPoint(*rightPoint));
118 }
119
120 fpInitialVolume = right.fpInitialVolume;
121 fpInitialNextVolume = right.fpInitialNextVolume;
122 fpCreatorProcess = right.fpCreatorProcess;
123 fCreatorModelID = right.fCreatorModelID;
124 fpFinalVolume = right.fpFinalVolume;
125 fpFinalNextVolume = right.fpFinalNextVolume;
126 fpEndingProcess = right.fpEndingProcess;
127 fFinalKineticEnergy = right.fFinalKineticEnergy;
128 fpRichPointContainer = new G4TrajectoryPointContainer;
129 for (auto& i : *right.fpRichPointContainer) {
130 auto rightPoint = (G4RichTrajectoryPoint*)i;
131 fpRichPointContainer->push_back(new G4RichTrajectoryPoint(*rightPoint));
132 }
133}
134
136{
137 if (fpRichPointContainer != nullptr) {
138 for (auto& i : *fpRichPointContainer) {
139 delete i;
140 }
141 fpRichPointContainer->clear();
142 delete fpRichPointContainer;
143 }
144}
145
147{
148 fpRichPointContainer->push_back(new G4RichTrajectoryPoint(aStep));
149
150 // Except for first step, which is a sort of virtual step to start
151 // the track, compute the final values...
152 //
153 const G4Track* track = aStep->GetTrack();
154 const G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
155 if (track->GetCurrentStepNumber() > 0) {
156 fpFinalVolume = track->GetTouchableHandle();
157 fpFinalNextVolume = track->GetNextTouchableHandle();
158 fpEndingProcess = postStepPoint->GetProcessDefinedStep();
159 fFinalKineticEnergy =
161 }
162}
163
165{
166 if (secondTrajectory == nullptr) return;
167
168 auto seco = (G4RichTrajectory*)secondTrajectory;
169 G4int ent = seco->GetPointEntries();
170 for (G4int i = 1; i < ent; ++i) {
171 // initial point of the second trajectory should not be merged
172 //
173 fpRichPointContainer->push_back((*(seco->fpRichPointContainer))[i]);
174 }
175 delete (*seco->fpRichPointContainer)[0];
176 seco->fpRichPointContainer->clear();
177}
178
179void G4RichTrajectory::ShowTrajectory(std::ostream& os) const
180{
181 // Invoke the default implementation in G4VTrajectory...
182 //
184
185 // ... or override with your own code here.
186}
187
189{
190 // Invoke the default implementation in G4VTrajectory...
191 //
193
194 // ... or override with your own code here.
195}
196
197const std::map<G4String, G4AttDef>* G4RichTrajectory::GetAttDefs() const
198{
199 G4bool isNew;
200 std::map<G4String, G4AttDef>* store = G4AttDefStore::GetInstance("G4RichTrajectory", isNew);
201 if (isNew) {
202 G4String ID;
203
204 ID = "ID";
205 (*store)[ID] = G4AttDef(ID, "Track ID", "Physics", "", "G4int");
206
207 ID = "PID";
208 (*store)[ID] = G4AttDef(ID, "Parent ID", "Physics", "", "G4int");
209
210 ID = "PN";
211 (*store)[ID] = G4AttDef(ID, "Particle Name", "Physics", "", "G4String");
212
213 ID = "Ch";
214 (*store)[ID] = G4AttDef(ID, "Charge", "Physics", "e+", "G4double");
215
216 ID = "PDG";
217 (*store)[ID] = G4AttDef(ID, "PDG Encoding", "Physics", "", "G4int");
218
219 ID = "IKE";
220 (*store)[ID] = G4AttDef(ID, "Initial kinetic energy", "Physics", "G4BestUnit", "G4double");
221
222 ID = "IMom";
223 (*store)[ID] = G4AttDef(ID, "Initial momentum", "Physics", "G4BestUnit", "G4ThreeVector");
224
225 ID = "IMag";
226 (*store)[ID] = G4AttDef(ID, "Initial momentum magnitude", "Physics", "G4BestUnit", "G4double");
227
228 ID = "NTP";
229 (*store)[ID] = G4AttDef(ID, "No. of points", "Physics", "", "G4int");
230
231 ID = "IVPath";
232 (*store)[ID] = G4AttDef(ID, "Initial Volume Path", "Physics", "", "G4String");
233
234 ID = "INVPath";
235 (*store)[ID] = G4AttDef(ID, "Initial Next Volume Path", "Physics", "", "G4String");
236
237 ID = "CPN";
238 (*store)[ID] = G4AttDef(ID, "Creator Process Name", "Physics", "", "G4String");
239
240 ID = "CPTN";
241 (*store)[ID] = G4AttDef(ID, "Creator Process Type Name", "Physics", "", "G4String");
242
243 ID = "CMID";
244 (*store)[ID] = G4AttDef(ID, "Creator Model ID", "Physics", "", "G4int");
245
246 ID = "CMN";
247 (*store)[ID] = G4AttDef(ID, "Creator Model Name", "Physics", "", "G4String");
248
249 ID = "FVPath";
250 (*store)[ID] = G4AttDef(ID, "Final Volume Path", "Physics", "", "G4String");
251
252 ID = "FNVPath";
253 (*store)[ID] = G4AttDef(ID, "Final Next Volume Path", "Physics", "", "G4String");
254
255 ID = "EPN";
256 (*store)[ID] = G4AttDef(ID, "Ending Process Name", "Physics", "", "G4String");
257
258 ID = "EPTN";
259 (*store)[ID] = G4AttDef(ID, "Ending Process Type Name", "Physics", "", "G4String");
260
261 ID = "FKE";
262 (*store)[ID] = G4AttDef(ID, "Final kinetic energy", "Physics", "G4BestUnit", "G4double");
263 }
264
265 return store;
266}
267
268static G4String Path(const G4TouchableHandle& th)
269{
270 std::ostringstream oss;
271 G4int depth = th->GetHistoryDepth();
272 for (G4int i = depth; i >= 0; --i) {
273 oss << th->GetVolume(i)->GetName() << ':' << th->GetCopyNumber(i);
274 if (i != 0) oss << '/';
275 }
276 return oss.str();
277}
278
279std::vector<G4AttValue>* G4RichTrajectory::CreateAttValues() const
280{
281 // Create base class att values...
282 //std::vector<G4AttValue>* values = G4VTrajectory::CreateAttValues();
283 auto values = new std::vector<G4AttValue>;
284 values->push_back(G4AttValue("ID", G4UIcommand::ConvertToString(fTrackID), ""));
285 values->push_back(G4AttValue("PID", G4UIcommand::ConvertToString(fParentID), ""));
286 values->push_back(G4AttValue("PN", ParticleName, ""));
287 values->push_back(G4AttValue("Ch", G4UIcommand::ConvertToString(PDGCharge), ""));
288 values->push_back(G4AttValue("PDG", G4UIcommand::ConvertToString(PDGEncoding), ""));
289 values->push_back(G4AttValue("IKE", G4BestUnit(initialKineticEnergy, "Energy"), ""));
290 values->push_back(G4AttValue("IMom", G4BestUnit(initialMomentum, "Energy"), ""));
291 values->push_back(G4AttValue("IMag", G4BestUnit(initialMomentum.mag(), "Energy"), ""));
292 values->push_back(G4AttValue("NTP", G4UIcommand::ConvertToString(GetPointEntries()), ""));
293
294 if (fpInitialVolume && (fpInitialVolume->GetVolume() != nullptr)) {
295 values->push_back(G4AttValue("IVPath", Path(fpInitialVolume), ""));
296 }
297 else {
298 values->push_back(G4AttValue("IVPath", "None", ""));
299 }
300
301 if (fpInitialNextVolume && (fpInitialNextVolume->GetVolume() != nullptr)) {
302 values->push_back(G4AttValue("INVPath", Path(fpInitialNextVolume), ""));
303 }
304 else {
305 values->push_back(G4AttValue("INVPath", "None", ""));
306 }
307
308 if (fpCreatorProcess != nullptr) {
309 values->push_back(G4AttValue("CPN", fpCreatorProcess->GetProcessName(), ""));
310 G4ProcessType type = fpCreatorProcess->GetProcessType();
311 values->push_back(G4AttValue("CPTN", G4VProcess::GetProcessTypeName(type), ""));
312 values->push_back(G4AttValue("CMID", G4UIcommand::ConvertToString(fCreatorModelID), ""));
313 const G4String& creatorModelName = G4PhysicsModelCatalog::GetModelNameFromID(fCreatorModelID);
314 values->push_back(G4AttValue("CMN", creatorModelName, ""));
315 }
316 else {
317 values->push_back(G4AttValue("CPN", "None", ""));
318 values->push_back(G4AttValue("CPTN", "None", ""));
319 values->push_back(G4AttValue("CMID", "None", ""));
320 values->push_back(G4AttValue("CMN", "None", ""));
321 }
322
323 if (fpFinalVolume && (fpFinalVolume->GetVolume() != nullptr)) {
324 values->push_back(G4AttValue("FVPath", Path(fpFinalVolume), ""));
325 }
326 else {
327 values->push_back(G4AttValue("FVPath", "None", ""));
328 }
329
330 if (fpFinalNextVolume && (fpFinalNextVolume->GetVolume() != nullptr)) {
331 values->push_back(G4AttValue("FNVPath", Path(fpFinalNextVolume), ""));
332 }
333 else {
334 values->push_back(G4AttValue("FNVPath", "None", ""));
335 }
336
337 if (fpEndingProcess != nullptr) {
338 values->push_back(G4AttValue("EPN", fpEndingProcess->GetProcessName(), ""));
339 G4ProcessType type = fpEndingProcess->GetProcessType();
340 values->push_back(G4AttValue("EPTN", G4VProcess::GetProcessTypeName(type), ""));
341 }
342 else {
343 values->push_back(G4AttValue("EPN", "None", ""));
344 values->push_back(G4AttValue("EPTN", "None", ""));
345 }
346
347 values->push_back(G4AttValue("FKE", G4BestUnit(fFinalKineticEnergy, "Energy"), ""));
348
349#ifdef G4ATTDEBUG
350 G4cout << G4AttCheck(values, GetAttDefs());
351#endif
352
353 return values;
354}
355
360
362{
363 G4AutoLock lock(&CloneRichTrajectoryMutex);
364 auto* cloned = new G4ClonedRichTrajectory(*this);
365 return cloned;
366}
367
G4TemplateAutoLock< G4Mutex > G4AutoLock
G4ProcessType
G4Allocator< G4RichTrajectory > *& aRichTrajectoryAllocator()
#define G4BestUnit(a, b)
#define G4MUTEX_INITIALIZER
std::mutex G4Mutex
G4ReferenceCountedHandle< G4VTouchable > G4TouchableHandle
G4TouchableHandle is a type providing reference counting mechanism for any kind of touchable objects....
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4GLOB_DLL std::ostream G4cout
const G4String & GetParticleName() const
static G4ParticleTable * GetParticleTable()
static const G4String GetModelNameFromID(const G4int modelID)
void AppendStep(const G4Step *aStep) override
const std::map< G4String, G4AttDef > * GetAttDefs() const override
G4int GetPointEntries() const override
void DrawTrajectory() const override
G4VTrajectory * CloneForMaster() const override
friend class G4ClonedRichTrajectory
G4ParticleDefinition * GetParticleDefinition()
void MergeTrajectory(G4VTrajectory *secondTrajectory) override
~G4RichTrajectory() override
G4RichTrajectory()=default
void ShowTrajectory(std::ostream &os=G4cout) const override
std::vector< G4AttValue > * CreateAttValues() const override
const G4VProcess * GetProcessDefinedStep() const
G4double GetKineticEnergy() const
G4Track * GetTrack() const
G4StepPoint * GetPreStepPoint() const
G4double GetTotalEnergyDeposit() const
G4StepPoint * GetPostStepPoint() const
G4int GetCopyNumber(G4int depth=0) const
G4VPhysicalVolume * GetVolume(G4int depth=0) const
G4int GetHistoryDepth() const
G4int GetTrackID() const
const G4TouchableHandle & GetNextTouchableHandle() const
const G4VProcess * GetCreatorProcess() const
G4int GetCreatorModelID() const
G4int GetCurrentStepNumber() const
G4ThreeVector GetMomentum() const
G4ParticleDefinition * GetDefinition() const
const G4TouchableHandle & GetTouchableHandle() const
G4double GetKineticEnergy() const
G4int GetParentID() const
static G4String ConvertToString(G4bool boolVal)
const G4String & GetName() const
static const G4String & GetProcessTypeName(G4ProcessType)
G4VTrajectory()=default
virtual void ShowTrajectory(std::ostream &os=G4cout) const
virtual void DrawTrajectory() const
std::map< G4String, G4AttDef > * GetInstance(const G4String &storeKey, G4bool &isNew)
#define G4ThreadLocalStatic
Definition tls.hh:76