source: trunk/source/tracking/src/G4SmoothTrajectory.cc @ 1187

Last change on this file since 1187 was 1011, checked in by garnier, 15 years ago

update

File size: 7.6 KB
Line 
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// $Id: G4SmoothTrajectory.cc,v 1.18 2006/10/16 13:37:17 allison Exp $
28// GEANT4 tag $Name: geant4-09-02-ref-02 $
29//
30//
31// ---------------------------------------------------------------
32//
33// G4SmoothTrajectory.cc
34//
35// Contact:
36//   Questions and comments to this code should be sent to
37//     Katsuya Amako  (e-mail: Katsuya.Amako@kek.jp)
38//     Makoto  Asai   (e-mail: asai@kekvax.kek.jp)
39//     Takashi Sasaki (e-mail: Takashi.Sasaki@kek.jp)
40//
41// ---------------------------------------------------------------
42
43#include "G4SmoothTrajectory.hh"
44#include "G4SmoothTrajectoryPoint.hh"
45#include "G4ParticleTable.hh"
46#include "G4AttDefStore.hh"
47#include "G4AttDef.hh"
48#include "G4AttValue.hh"
49#include "G4UIcommand.hh"
50#include "G4UnitsTable.hh"
51
52//#define G4ATTDEBUG
53#ifdef G4ATTDEBUG
54#include "G4AttCheck.hh"
55#endif
56
57G4Allocator<G4SmoothTrajectory> aSmoothTrajectoryAllocator;
58
59G4SmoothTrajectory::G4SmoothTrajectory()
60:  positionRecord(0), fTrackID(0), fParentID(0),
61   PDGEncoding( 0 ), PDGCharge(0.0), ParticleName(""),
62   initialMomentum( G4ThreeVector() )
63{;}
64
65G4SmoothTrajectory::G4SmoothTrajectory(const G4Track* aTrack)
66{
67   G4ParticleDefinition * fpParticleDefinition = aTrack->GetDefinition();
68   ParticleName = fpParticleDefinition->GetParticleName();
69   PDGCharge = fpParticleDefinition->GetPDGCharge();
70   PDGEncoding = fpParticleDefinition->GetPDGEncoding();
71   fTrackID = aTrack->GetTrackID();
72   fParentID = aTrack->GetParentID();
73   initialMomentum = aTrack->GetMomentum();
74   positionRecord = new TrajectoryPointContainer();
75   // Following is for the first trajectory point
76   positionRecord->push_back(new G4SmoothTrajectoryPoint(aTrack->GetPosition()));
77
78   // The first point has no auxiliary points, so set the auxiliary
79   // points vector to NULL (jacek 31/10/2002)
80   positionRecord->push_back(new G4SmoothTrajectoryPoint(aTrack->GetPosition(), NULL));
81}
82
83G4SmoothTrajectory::G4SmoothTrajectory(G4SmoothTrajectory & right):G4VTrajectory()
84{
85  ParticleName = right.ParticleName;
86  PDGCharge = right.PDGCharge;
87  PDGEncoding = right.PDGEncoding;
88  fTrackID = right.fTrackID;
89  fParentID = right.fParentID;
90  initialMomentum = right.initialMomentum;
91  positionRecord = new TrajectoryPointContainer();
92
93  for(size_t i=0;i<right.positionRecord->size();i++)
94  {
95    G4SmoothTrajectoryPoint* rightPoint = (G4SmoothTrajectoryPoint*)((*(right.positionRecord))[i]);
96    positionRecord->push_back(new G4SmoothTrajectoryPoint(*rightPoint));
97  }
98}
99
100G4SmoothTrajectory::~G4SmoothTrajectory()
101{
102  if (positionRecord) {
103    //  positionRecord->clearAndDestroy();
104    size_t i;
105    for(i=0;i<positionRecord->size();i++){
106      delete  (*positionRecord)[i];
107    }
108    positionRecord->clear();
109    delete positionRecord;
110  }
111}
112
113void G4SmoothTrajectory::ShowTrajectory(std::ostream& os) const
114{
115  // Invoke the default implementation in G4VTrajectory...
116  G4VTrajectory::ShowTrajectory(os);
117  // ... or override with your own code here.
118}
119
120void G4SmoothTrajectory::DrawTrajectory(G4int i_mode) const
121{
122  // Invoke the default implementation in G4VTrajectory...
123  G4VTrajectory::DrawTrajectory(i_mode);
124  // ... or override with your own code here.
125}
126
127const std::map<G4String,G4AttDef>* G4SmoothTrajectory::GetAttDefs() const
128{
129  G4bool isNew;
130  std::map<G4String,G4AttDef>* store
131    = G4AttDefStore::GetInstance("G4SmoothTrajectory",isNew);
132  if (isNew) {
133
134    G4String ID("ID");
135    (*store)[ID] = G4AttDef(ID,"Track ID","Physics","","G4int");
136
137    G4String PID("PID");
138    (*store)[PID] = G4AttDef(PID,"Parent ID","Physics","","G4int");
139
140    G4String PN("PN");
141    (*store)[PN] = G4AttDef(PN,"Particle Name","Physics","","G4String");
142
143    G4String Ch("Ch");
144    (*store)[Ch] = G4AttDef(Ch,"Charge","Physics","e+","G4double");
145
146    G4String PDG("PDG");
147    (*store)[PDG] = G4AttDef(PDG,"PDG Encoding","Physics","","G4int");
148
149    G4String IMom("IMom");
150    (*store)[IMom] = G4AttDef(IMom, "Momentum of track at start of trajectory",
151                              "Physics","G4BestUnit","G4ThreeVector");
152
153    G4String IMag("IMag");
154    (*store)[IMag] = G4AttDef
155      (IMag, "Magnitude of momentum of track at start of trajectory",
156       "Physics","G4BestUnit","G4double");
157
158    G4String NTP("NTP");
159    (*store)[NTP] = G4AttDef(NTP,"No. of points","Physics","","G4int");
160
161  }
162  return store;
163}
164
165
166std::vector<G4AttValue>* G4SmoothTrajectory::CreateAttValues() const
167{
168  std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
169
170  values->push_back
171    (G4AttValue("ID",G4UIcommand::ConvertToString(fTrackID),""));
172
173  values->push_back
174    (G4AttValue("PID",G4UIcommand::ConvertToString(fParentID),""));
175
176  values->push_back(G4AttValue("PN",ParticleName,""));
177
178  values->push_back
179    (G4AttValue("Ch",G4UIcommand::ConvertToString(PDGCharge),""));
180
181  values->push_back
182    (G4AttValue("PDG",G4UIcommand::ConvertToString(PDGEncoding),""));
183
184  values->push_back
185    (G4AttValue("IMom",G4BestUnit(initialMomentum,"Energy"),""));
186
187  values->push_back
188    (G4AttValue("IMag",G4BestUnit(initialMomentum.mag(),"Energy"),""));
189
190  values->push_back
191    (G4AttValue("NTP",G4UIcommand::ConvertToString(GetPointEntries()),""));
192
193#ifdef G4ATTDEBUG
194   G4cout << G4AttCheck(values,GetAttDefs());
195#endif
196
197  return values;
198}
199
200void G4SmoothTrajectory::AppendStep(const G4Step* aStep)
201{
202  // (jacek 30/10/2002)
203  positionRecord->push_back(
204      new G4SmoothTrajectoryPoint(aStep->GetPostStepPoint()->GetPosition(),
205                                  aStep->GetPointerToVectorOfAuxiliaryPoints()));
206}
207 
208G4ParticleDefinition* G4SmoothTrajectory::GetParticleDefinition()
209{
210   return (G4ParticleTable::GetParticleTable()->FindParticle(ParticleName));
211}
212
213void G4SmoothTrajectory::MergeTrajectory(G4VTrajectory* secondTrajectory)
214{
215  if(!secondTrajectory) return;
216
217  G4SmoothTrajectory* seco = (G4SmoothTrajectory*)secondTrajectory;
218  G4int ent = seco->GetPointEntries();
219  for(G4int i=1;i<ent;i++) // initial point of the second trajectory should not be merged
220  { 
221    positionRecord->push_back((*(seco->positionRecord))[i]);
222    //    positionRecord->push_back(seco->positionRecord->removeAt(1));
223  }
224  delete (*seco->positionRecord)[0];
225  seco->positionRecord->clear();
226}
227
228
Note: See TracBrowser for help on using the repository browser.