WCSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WCSimTrajectory.cc
Go to the documentation of this file.
1 #include "WCSimTrajectory.hh"
2 
3 #include "G4TrajectoryPoint.hh"
4 #include "G4ParticleTable.hh"
5 #include "G4AttDefStore.hh"
6 #include "G4AttDef.hh"
7 #include "G4AttValue.hh"
8 #include "G4UnitsTable.hh"
9 #include "G4VProcess.hh"
10 
11 #include "G4PhysicalConstants.hh"
12 #include "G4SystemOfUnits.hh"
13 
14 #include <sstream>
15 
16 //G4Allocator<WCSimTrajectory> aTrajectoryAllocator;
17 G4Allocator<WCSimTrajectory> myTrajectoryAllocator;
18 
20  : positionRecord(0), fTrackID(0), fParentID(0),
21  PDGEncoding( 0 ), PDGCharge(0.0), ParticleName(""),
22  initialMomentum( G4ThreeVector() ),SaveIt(false),creatorProcess(""),
23  globalTime(0.0)
24 {;}
25 
26 WCSimTrajectory::WCSimTrajectory(const G4Track* aTrack)
27 {
28  G4ParticleDefinition * fpParticleDefinition = aTrack->GetDefinition();
29  ParticleName = fpParticleDefinition->GetParticleName();
30  PDGCharge = fpParticleDefinition->GetPDGCharge();
31  PDGEncoding = fpParticleDefinition->GetPDGEncoding();
32  fTrackID = aTrack->GetTrackID();
33  fParentID = aTrack->GetParentID();
34  initialMomentum = aTrack->GetMomentum();
36  // Following is for the first trajectory point
37  positionRecord->push_back(new G4TrajectoryPoint(aTrack->GetPosition()));
38 
39  stoppingPoint = aTrack->GetPosition();
40  stoppingVolume = aTrack->GetVolume();
41  if ( aTrack->GetUserInformation() != 0 )
42  SaveIt = true;
43  else SaveIt = false;
44  globalTime = aTrack->GetGlobalTime();
45  if (aTrack->GetCreatorProcess() != 0 )
46  {
47  const G4VProcess* tempproc = aTrack->GetCreatorProcess();
48  creatorProcess = tempproc->GetProcessName();
49  }
50  else
51  creatorProcess = "";
52 }
53 
55 {
56  ParticleName = right.ParticleName;
57  PDGCharge = right.PDGCharge;
58  PDGEncoding = right.PDGEncoding;
59  fTrackID = right.fTrackID;
60  fParentID = right.fParentID;
63 
66  SaveIt = right.SaveIt;
68 
69  for(size_t i=0;i<right.positionRecord->size();i++)
70  {
71  G4TrajectoryPoint* rightPoint = (G4TrajectoryPoint*)((*(right.positionRecord))[i]);
72  positionRecord->push_back(new G4TrajectoryPoint(*rightPoint));
73  }
74  globalTime = right.globalTime;
75 }
76 
78 {
79  // positionRecord->clearAndDestroy();
80  size_t i;
81  for(i=0;i<positionRecord->size();i++){
82  delete (*positionRecord)[i];
83  }
84  positionRecord->clear();
85 
86  delete positionRecord;
87 }
88 
89 void WCSimTrajectory::ShowTrajectory(std::ostream& os) const
90 {
91  // Invoke the default implementation in G4VTrajectory...
92  G4VTrajectory::ShowTrajectory(os);
93  // ... or override with your own code here.
94 }
95 
96 void WCSimTrajectory::DrawTrajectory(G4int i_mode) const
97 {
98  // Invoke the default implementation in G4VTrajectory...
99  G4VTrajectory::DrawTrajectory();
100  // ... or override with your own code here.
101 }
102 
103 const std::map<G4String,G4AttDef>* WCSimTrajectory::GetAttDefs() const
104 {
105  G4bool isNew;
106  std::map<G4String,G4AttDef>* store
107  = G4AttDefStore::GetInstance("WCSimTrajectory",isNew);
108  if (isNew) {
109 
110  G4String ID("ID");
111  (*store)[ID] = G4AttDef(ID,"Track ID","Bookkeeping","","G4int");
112 
113  G4String PID("PID");
114  (*store)[PID] = G4AttDef(PID,"Parent ID","Bookkeeping","","G4int");
115 
116  G4String PN("PN");
117  (*store)[PN] = G4AttDef(PN,"Particle Name","Physics","","G4String");
118 
119  G4String Ch("Ch");
120  (*store)[Ch] = G4AttDef(Ch,"Charge","Physics","","G4double");
121 
122  G4String PDG("PDG");
123  (*store)[PDG] = G4AttDef(PDG,"PDG Encoding","Physics","","G4int");
124 
125  G4String IMom("IMom");
126  (*store)[IMom] = G4AttDef(IMom, "Momentum of track at start of trajectory",
127  "Physics","","G4ThreeVector");
128 
129  G4String NTP("NTP");
130  (*store)[NTP] = G4AttDef(NTP,"No. of points","Physics","","G4int");
131 
132  }
133  return store;
134 }
135 
136 std::vector<G4AttValue>* WCSimTrajectory::CreateAttValues() const
137 {
138  char c[100];
139  //std::ostrstream s(c,100);
140  std::ostringstream s(c);
141 
142  std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
143 
144  s.seekp(std::ios::beg);
145  s << fTrackID << std::ends;
146  values->push_back(G4AttValue("ID",c,""));
147 
148  s.seekp(std::ios::beg);
149  s << fParentID << std::ends;
150  values->push_back(G4AttValue("PID",c,""));
151 
152  values->push_back(G4AttValue("PN",ParticleName,""));
153 
154  s.seekp(std::ios::beg);
155  s << PDGCharge << std::ends;
156  values->push_back(G4AttValue("Ch",c,""));
157 
158  s.seekp(std::ios::beg);
159  s << PDGEncoding << std::ends;
160  values->push_back(G4AttValue("PDG",c,""));
161 
162  s.seekp(std::ios::beg);
163  s << G4BestUnit(initialMomentum,"Energy") << std::ends;
164  values->push_back(G4AttValue("IMom",c,""));
165 
166  s.seekp(std::ios::beg);
167  s << GetPointEntries() << std::ends;
168  values->push_back(G4AttValue("NTP",c,""));
169 
170  return values;
171 }
172 
173 void WCSimTrajectory::AppendStep(const G4Step* aStep)
174 {
175  positionRecord->push_back( new G4TrajectoryPoint(aStep->GetPostStepPoint()->
176  GetPosition() ));
177 }
178 
180 {
181  return (G4ParticleTable::GetParticleTable()->FindParticle(ParticleName));
182 }
183 
184 void WCSimTrajectory::MergeTrajectory(G4VTrajectory* secondTrajectory)
185 {
186  if(!secondTrajectory) return;
187 
188  WCSimTrajectory* seco = (WCSimTrajectory*)secondTrajectory;
189 
192 
193  G4int ent = seco->GetPointEntries();
194  for(G4int i=1;i<ent;i++) // initial point of the second trajectory should not be merged
195  {
196  positionRecord->push_back((*(seco->positionRecord))[i]);
197  // positionRecord->push_back(seco->positionRecord->removeAt(1));
198  }
199  delete (*seco->positionRecord)[0];
200  seco->positionRecord->clear();
201 }
202 
203 
G4VPhysicalVolume * stoppingVolume
virtual void AppendStep(const G4Step *aStep)
virtual int GetPointEntries() const
G4Allocator< WCSimTrajectory > myTrajectoryAllocator
virtual void MergeTrajectory(G4VTrajectory *secondTrajectory)
virtual void DrawTrajectory(G4int i_mode=0) const
virtual void ShowTrajectory(std::ostream &os=G4cout) const
TrajectoryPointContainer * positionRecord
G4ParticleDefinition * GetParticleDefinition()
virtual std::vector< G4AttValue > * CreateAttValues() const
G4ThreeVector stoppingPoint
virtual ~WCSimTrajectory()
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
std::vector< G4VTrajectoryPoint * > TrajectoryPointContainer
G4ThreeVector initialMomentum