File indexing completed on 2025-02-23 09:22:25
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
0030
0031
0032 #include "WLSTrajectory.hh"
0033
0034 #include "WLSTrajectoryPoint.hh"
0035
0036 #include "G4AttDef.hh"
0037 #include "G4AttDefStore.hh"
0038 #include "G4AttValue.hh"
0039 #include "G4Colour.hh"
0040 #include "G4ParticleTable.hh"
0041 #include "G4ParticleTypes.hh"
0042 #include "G4Polyline.hh"
0043 #include "G4Polymarker.hh"
0044 #include "G4UIcommand.hh"
0045 #include "G4UnitsTable.hh"
0046 #include "G4VVisManager.hh"
0047 #include "G4VisAttributes.hh"
0048
0049 G4ThreadLocal G4Allocator<WLSTrajectory>* WLSTrajectoryAllocator = nullptr;
0050
0051
0052
0053 WLSTrajectory::WLSTrajectory(const G4Track* aTrack)
0054 {
0055 fParticleDefinition = aTrack->GetDefinition();
0056 fParticleName = fParticleDefinition->GetParticleName();
0057 fPDGCharge = fParticleDefinition->GetPDGCharge();
0058 fPDGEncoding = fParticleDefinition->GetPDGEncoding();
0059 fTrackID = aTrack->GetTrackID();
0060 fParentID = aTrack->GetParentID();
0061 fInitialMomentum = aTrack->GetMomentum();
0062 fpPointsContainer = new WLSTrajectoryPointContainer();
0063
0064 fpPointsContainer->push_back(new WLSTrajectoryPoint(aTrack));
0065 }
0066
0067
0068
0069 WLSTrajectory::WLSTrajectory(WLSTrajectory& right) : G4VTrajectory()
0070 {
0071 fParticleDefinition = right.fParticleDefinition;
0072 fParticleName = right.fParticleName;
0073 fPDGCharge = right.fPDGCharge;
0074 fPDGEncoding = right.fPDGEncoding;
0075 fTrackID = right.fTrackID;
0076 fParentID = right.fParentID;
0077 fInitialMomentum = right.fInitialMomentum;
0078 fpPointsContainer = new WLSTrajectoryPointContainer();
0079
0080 for (size_t i = 0; i < right.fpPointsContainer->size(); ++i) {
0081 auto rightPoint = (WLSTrajectoryPoint*)((*(right.fpPointsContainer))[i]);
0082 fpPointsContainer->push_back(new WLSTrajectoryPoint(*rightPoint));
0083 }
0084 }
0085
0086
0087
0088 WLSTrajectory::~WLSTrajectory()
0089 {
0090 for (size_t i = 0; i < fpPointsContainer->size(); ++i) {
0091 delete (*fpPointsContainer)[i];
0092 }
0093 fpPointsContainer->clear();
0094 delete fpPointsContainer;
0095 }
0096
0097
0098
0099 void WLSTrajectory::ShowTrajectory(std::ostream& os) const
0100 {
0101
0102 G4VTrajectory::ShowTrajectory(os);
0103
0104 }
0105
0106
0107
0108 void WLSTrajectory::AppendStep(const G4Step* aStep)
0109 {
0110 fpPointsContainer->push_back(new WLSTrajectoryPoint(aStep));
0111 }
0112
0113
0114
0115 G4ParticleDefinition* WLSTrajectory::GetParticleDefinition()
0116 {
0117 return (G4ParticleTable::GetParticleTable()->FindParticle(fParticleName));
0118 }
0119
0120
0121
0122 void WLSTrajectory::MergeTrajectory(G4VTrajectory* secondTrajectory)
0123 {
0124 if (!secondTrajectory) return;
0125
0126 auto second = (WLSTrajectory*)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>* WLSTrajectory::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>* WLSTrajectory::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 return values;
0196 }