File indexing completed on 2026-04-09 07:51:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "F04Trajectory.hh"
0030
0031 #include "F04TrajectoryPoint.hh"
0032
0033 #include "G4AttDef.hh"
0034 #include "G4AttDefStore.hh"
0035 #include "G4AttValue.hh"
0036 #include "G4ParticleTable.hh"
0037 #include "G4UIcommand.hh"
0038 #include "G4UnitsTable.hh"
0039
0040
0041 #ifdef G4ATTDEBUG
0042 # include "G4AttCheck.hh"
0043 #endif
0044
0045 G4ThreadLocal G4Allocator<F04Trajectory>* F04TrajectoryAllocator = nullptr;
0046
0047
0048
0049 F04Trajectory::F04Trajectory() {}
0050
0051
0052
0053 F04Trajectory::F04Trajectory(const G4Track* aTrack)
0054 {
0055 G4ParticleDefinition* particleDefinition = aTrack->GetDefinition();
0056 fParticleName = particleDefinition->GetParticleName();
0057 fPDGCharge = particleDefinition->GetPDGCharge();
0058 fPDGEncoding = particleDefinition->GetPDGEncoding();
0059 fTrackID = aTrack->GetTrackID();
0060 fParentID = aTrack->GetParentID();
0061 fInitialMomentum = aTrack->GetMomentum();
0062 fpPointsContainer = new TrajectoryPointContainer();
0063
0064 fpPointsContainer->push_back(new F04TrajectoryPoint(aTrack));
0065 }
0066
0067
0068
0069 F04Trajectory::F04Trajectory(F04Trajectory& right) : G4VTrajectory()
0070 {
0071 fParticleName = right.fParticleName;
0072 fPDGCharge = right.fPDGCharge;
0073 fPDGEncoding = right.fPDGEncoding;
0074 fTrackID = right.fTrackID;
0075 fParentID = right.fParentID;
0076 fInitialMomentum = right.fInitialMomentum;
0077 fpPointsContainer = new TrajectoryPointContainer();
0078
0079 for (size_t i = 0; i < right.fpPointsContainer->size(); ++i) {
0080 auto rightPoint = (F04TrajectoryPoint*)((*(right.fpPointsContainer))[i]);
0081 fpPointsContainer->push_back(new F04TrajectoryPoint(*rightPoint));
0082 }
0083 }
0084
0085
0086
0087 F04Trajectory::~F04Trajectory()
0088 {
0089 for (size_t i = 0; i < fpPointsContainer->size(); ++i) {
0090 delete (*fpPointsContainer)[i];
0091 }
0092 fpPointsContainer->clear();
0093
0094 delete fpPointsContainer;
0095 }
0096
0097
0098
0099 void F04Trajectory::ShowTrajectory(std::ostream& os) const
0100 {
0101
0102 G4VTrajectory::ShowTrajectory(os);
0103
0104 }
0105
0106
0107
0108 void F04Trajectory::AppendStep(const G4Step* aStep)
0109 {
0110 fpPointsContainer->push_back(new F04TrajectoryPoint(aStep));
0111 }
0112
0113
0114
0115 G4ParticleDefinition* F04Trajectory::GetParticleDefinition()
0116 {
0117 return (G4ParticleTable::GetParticleTable()->FindParticle(fParticleName));
0118 }
0119
0120
0121
0122 void F04Trajectory::MergeTrajectory(G4VTrajectory* secondTrajectory)
0123 {
0124 if (!secondTrajectory) return;
0125
0126 auto second = (F04Trajectory*)secondTrajectory;
0127 G4int ent = second->GetPointEntries();
0128
0129 for (G4int i = 1; i < ent; ++i) {
0130 fpPointsContainer->push_back((*(second->fpPointsContainer))[i]);
0131 }
0132 delete (*second->fpPointsContainer)[0];
0133 second->fpPointsContainer->clear();
0134 }
0135
0136
0137
0138 const std::map<G4String, G4AttDef>* F04Trajectory::GetAttDefs() const
0139 {
0140 G4bool isNew;
0141 std::map<G4String, G4AttDef>* store = G4AttDefStore::GetInstance("Trajectory", isNew);
0142
0143 if (isNew) {
0144 G4String ID("ID");
0145 (*store)[ID] = G4AttDef(ID, "Track ID", "Bookkeeping", "", "G4int");
0146
0147 G4String PID("PID");
0148 (*store)[PID] = G4AttDef(PID, "Parent ID", "Bookkeeping", "", "G4int");
0149
0150 G4String PN("PN");
0151 (*store)[PN] = G4AttDef(PN, "Particle Name", "Physics", "", "G4String");
0152
0153 G4String Ch("Ch");
0154 (*store)[Ch] = G4AttDef(Ch, "Charge", "Physics", "e+", "G4double");
0155
0156 G4String PDG("PDG");
0157 (*store)[PDG] = G4AttDef(PDG, "PDG Encoding", "Physics", "", "G4int");
0158
0159 G4String IMom("IMom");
0160 (*store)[IMom] = G4AttDef(IMom, "Momentum of track at start of trajectory", "Physics",
0161 "G4BestUnit", "G4ThreeVector");
0162
0163 G4String IMag("IMag");
0164 (*store)[IMag] = G4AttDef(IMag, "Magnitude of momentum of track at start of trajectory",
0165 "Physics", "G4BestUnit", "G4double");
0166
0167 G4String NTP("NTP");
0168 (*store)[NTP] = G4AttDef(NTP, "No. of points", "Bookkeeping", "", "G4int");
0169 }
0170 return store;
0171 }
0172
0173
0174
0175 std::vector<G4AttValue>* F04Trajectory::CreateAttValues() const
0176 {
0177 auto values = new std::vector<G4AttValue>;
0178
0179 values->push_back(G4AttValue("ID", G4UIcommand::ConvertToString(fTrackID), ""));
0180
0181 values->push_back(G4AttValue("PID", G4UIcommand::ConvertToString(fParentID), ""));
0182
0183 values->push_back(G4AttValue("PN", fParticleName, ""));
0184
0185 values->push_back(G4AttValue("Ch", G4UIcommand::ConvertToString(fPDGCharge), ""));
0186
0187 values->push_back(G4AttValue("PDG", G4UIcommand::ConvertToString(fPDGEncoding), ""));
0188
0189 values->push_back(G4AttValue("IMom", G4BestUnit(fInitialMomentum, "Energy"), ""));
0190
0191 values->push_back(G4AttValue("IMag", G4BestUnit(fInitialMomentum.mag(), "Energy"), ""));
0192
0193 values->push_back(G4AttValue("NTP", G4UIcommand::ConvertToString(GetPointEntries()), ""));
0194
0195 #ifdef G4ATTDEBUG
0196 G4cout << G4AttCheck(values, GetAttDefs());
0197 #endif
0198 return values;
0199 }