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 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 /// \file field/field04/src/F04Trajectory.cc
 28 /// \brief Implementation of the F04Trajectory class
 29 //
 30 
 31 #include "F04Trajectory.hh"
 32 
 33 #include "F04TrajectoryPoint.hh"
 34 
 35 #include "G4AttDef.hh"
 36 #include "G4AttDefStore.hh"
 37 #include "G4AttValue.hh"
 38 #include "G4ParticleTable.hh"
 39 #include "G4UIcommand.hh"
 40 #include "G4UnitsTable.hh"
 41 
 42 // #define G4ATTDEBUG
 43 #ifdef G4ATTDEBUG
 44 #  include "G4AttCheck.hh"
 45 #endif
 46 
 47 G4ThreadLocal G4Allocator<F04Trajectory>* F04TrajectoryAllocator = nullptr;
 48 
 49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 50 
 51 F04Trajectory::F04Trajectory() {}
 52 
 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 54 
 55 F04Trajectory::F04Trajectory(const G4Track* aTrack)
 56 {
 57   G4ParticleDefinition* particleDefinition = aTrack->GetDefinition();
 58   fParticleName = particleDefinition->GetParticleName();
 59   fPDGCharge = particleDefinition->GetPDGCharge();
 60   fPDGEncoding = particleDefinition->GetPDGEncoding();
 61   fTrackID = aTrack->GetTrackID();
 62   fParentID = aTrack->GetParentID();
 63   fInitialMomentum = aTrack->GetMomentum();
 64   fpPointsContainer = new TrajectoryPointContainer();
 65   // Following is for the first trajectory point
 66   fpPointsContainer->push_back(new F04TrajectoryPoint(aTrack));
 67 }
 68 
 69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 70 
 71 F04Trajectory::F04Trajectory(F04Trajectory& right) : G4VTrajectory()
 72 {
 73   fParticleName = right.fParticleName;
 74   fPDGCharge = right.fPDGCharge;
 75   fPDGEncoding = right.fPDGEncoding;
 76   fTrackID = right.fTrackID;
 77   fParentID = right.fParentID;
 78   fInitialMomentum = right.fInitialMomentum;
 79   fpPointsContainer = new TrajectoryPointContainer();
 80 
 81   for (size_t i = 0; i < right.fpPointsContainer->size(); ++i) {
 82     auto rightPoint = (F04TrajectoryPoint*)((*(right.fpPointsContainer))[i]);
 83     fpPointsContainer->push_back(new F04TrajectoryPoint(*rightPoint));
 84   }
 85 }
 86 
 87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 88 
 89 F04Trajectory::~F04Trajectory()
 90 {
 91   for (size_t i = 0; i < fpPointsContainer->size(); ++i) {
 92     delete (*fpPointsContainer)[i];
 93   }
 94   fpPointsContainer->clear();
 95 
 96   delete fpPointsContainer;
 97 }
 98 
 99 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
100 
101 void F04Trajectory::ShowTrajectory(std::ostream& os) const
102 {
103   // Invoke the default implementation in G4VTrajectory...
104   G4VTrajectory::ShowTrajectory(os);
105   // ... or override with your own code here.
106 }
107 
108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
109 
110 void F04Trajectory::AppendStep(const G4Step* aStep)
111 {
112   fpPointsContainer->push_back(new F04TrajectoryPoint(aStep));
113 }
114 
115 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
116 
117 G4ParticleDefinition* F04Trajectory::GetParticleDefinition()
118 {
119   return (G4ParticleTable::GetParticleTable()->FindParticle(fParticleName));
120 }
121 
122 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
123 
124 void F04Trajectory::MergeTrajectory(G4VTrajectory* secondTrajectory)
125 {
126   if (!secondTrajectory) return;
127 
128   auto second = (F04Trajectory*)secondTrajectory;
129   G4int ent = second->GetPointEntries();
130   // initial point of the second trajectory should not be merged
131   for (G4int i = 1; i < ent; ++i) {
132     fpPointsContainer->push_back((*(second->fpPointsContainer))[i]);
133   }
134   delete (*second->fpPointsContainer)[0];
135   second->fpPointsContainer->clear();
136 }
137 
138 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
139 
140 const std::map<G4String, G4AttDef>* F04Trajectory::GetAttDefs() const
141 {
142   G4bool isNew;
143   std::map<G4String, G4AttDef>* store = G4AttDefStore::GetInstance("Trajectory", isNew);
144 
145   if (isNew) {
146     G4String ID("ID");
147     (*store)[ID] = G4AttDef(ID, "Track ID", "Bookkeeping", "", "G4int");
148 
149     G4String PID("PID");
150     (*store)[PID] = G4AttDef(PID, "Parent ID", "Bookkeeping", "", "G4int");
151 
152     G4String PN("PN");
153     (*store)[PN] = G4AttDef(PN, "Particle Name", "Physics", "", "G4String");
154 
155     G4String Ch("Ch");
156     (*store)[Ch] = G4AttDef(Ch, "Charge", "Physics", "e+", "G4double");
157 
158     G4String PDG("PDG");
159     (*store)[PDG] = G4AttDef(PDG, "PDG Encoding", "Physics", "", "G4int");
160 
161     G4String IMom("IMom");
162     (*store)[IMom] = G4AttDef(IMom, "Momentum of track at start of trajectory", "Physics",
163                               "G4BestUnit", "G4ThreeVector");
164 
165     G4String IMag("IMag");
166     (*store)[IMag] = G4AttDef(IMag, "Magnitude of momentum of track at start of trajectory",
167                               "Physics", "G4BestUnit", "G4double");
168 
169     G4String NTP("NTP");
170     (*store)[NTP] = G4AttDef(NTP, "No. of points", "Bookkeeping", "", "G4int");
171   }
172   return store;
173 }
174 
175 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
176 
177 std::vector<G4AttValue>* F04Trajectory::CreateAttValues() const
178 {
179   auto values = new std::vector<G4AttValue>;
180 
181   values->push_back(G4AttValue("ID", G4UIcommand::ConvertToString(fTrackID), ""));
182 
183   values->push_back(G4AttValue("PID", G4UIcommand::ConvertToString(fParentID), ""));
184 
185   values->push_back(G4AttValue("PN", fParticleName, ""));
186 
187   values->push_back(G4AttValue("Ch", G4UIcommand::ConvertToString(fPDGCharge), ""));
188 
189   values->push_back(G4AttValue("PDG", G4UIcommand::ConvertToString(fPDGEncoding), ""));
190 
191   values->push_back(G4AttValue("IMom", G4BestUnit(fInitialMomentum, "Energy"), ""));
192 
193   values->push_back(G4AttValue("IMag", G4BestUnit(fInitialMomentum.mag(), "Energy"), ""));
194 
195   values->push_back(G4AttValue("NTP", G4UIcommand::ConvertToString(GetPointEntries()), ""));
196 
197 #ifdef G4ATTDEBUG
198   G4cout << G4AttCheck(values, GetAttDefs());
199 #endif
200   return values;
201 }
202