source: trunk/source/tracking/src/G4RichTrajectory.cc @ 1228

Last change on this file since 1228 was 1228, checked in by garnier, 14 years ago

update geant4.9.3 tag

File size: 9.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: G4RichTrajectory.cc,v 1.8 2009/11/24 10:04:14 perl Exp $
28// GEANT4 tag $Name: geant4-09-03 $
29//
30// ---------------------------------------------------------------
31//
32// G4RichTrajectory.cc
33//
34// Contact:
35//   Questions and comments on G4Trajectory, on which this is based,
36//   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//   and on the extended code to:
41//     John Allison   (e-mail: John.Allison@manchester.ac.uk)
42//     Joseph Perl    (e-mail: perl@slac.stanford.edu)
43//
44// ---------------------------------------------------------------
45
46#include "G4RichTrajectory.hh"
47#include "G4RichTrajectoryPoint.hh"
48#include "G4AttDefStore.hh"
49#include "G4AttDef.hh"
50#include "G4AttValue.hh"
51#include "G4UnitsTable.hh"
52#include "G4VProcess.hh"
53
54//#define G4ATTDEBUG
55#ifdef G4ATTDEBUG
56#include "G4AttCheck.hh"
57#endif
58
59#include <sstream>
60
61G4Allocator<G4RichTrajectory> aRichTrajectoryAllocator;
62
63G4RichTrajectory::G4RichTrajectory():
64  fpRichPointsContainer(0),
65  fpCreatorProcess(0),
66  fpEndingProcess(0),
67  fFinalKineticEnergy(0.)
68{}
69
70G4RichTrajectory::G4RichTrajectory(const G4Track* aTrack):
71  G4Trajectory(aTrack)  // Note: this initialises the base class data
72                        // members and, unfortunately but never mind,
73                        // creates a G4TrajectoryPoint in
74                        // TrajectoryPointContainer that we cannot
75                        // access because it's private.  We store the
76                        // same information (plus more) in a
77                        // G4RichTrajectoryPoint in the
78                        // RichTrajectoryPointsContainer
79{
80  fpInitialVolume = aTrack->GetTouchableHandle();
81  fpInitialNextVolume = aTrack->GetNextTouchableHandle();
82  fpCreatorProcess = aTrack->GetCreatorProcess();
83  // On construction, set final values to initial values.
84  // Final values are updated at the addition of every step - see AppendStep.
85  fpFinalVolume = aTrack->GetTouchableHandle();
86  fpFinalNextVolume = aTrack->GetNextTouchableHandle();
87  fpEndingProcess = aTrack->GetCreatorProcess();
88  fFinalKineticEnergy = aTrack->GetKineticEnergy();
89  // Insert the first rich trajectory point (see note above)...
90  fpRichPointsContainer = new RichTrajectoryPointsContainer;
91  fpRichPointsContainer->push_back(new G4RichTrajectoryPoint(aTrack));
92}
93
94G4RichTrajectory::G4RichTrajectory(G4RichTrajectory & right):
95  G4Trajectory(right)
96{
97  fpInitialVolume = right.fpInitialVolume;
98  fpInitialNextVolume = right.fpInitialNextVolume;
99  fpCreatorProcess = right.fpCreatorProcess;
100  fpFinalVolume = right.fpFinalVolume;
101  fpFinalNextVolume = right.fpFinalNextVolume;
102  fpEndingProcess = right.fpEndingProcess;
103  fFinalKineticEnergy = right.fFinalKineticEnergy;
104  fpRichPointsContainer = new RichTrajectoryPointsContainer;
105  for(size_t i=0;i<right.fpRichPointsContainer->size();i++)
106  {
107    G4RichTrajectoryPoint* rightPoint =
108      (G4RichTrajectoryPoint*)((*(right.fpRichPointsContainer))[i]);
109    fpRichPointsContainer->push_back(new G4RichTrajectoryPoint(*rightPoint));
110  }
111}
112
113G4RichTrajectory::~G4RichTrajectory()
114{
115  if (fpRichPointsContainer) {
116    //  fpRichPointsContainer->clearAndDestroy();
117    size_t i;
118    for(i=0;i<fpRichPointsContainer->size();i++){
119      delete  (*fpRichPointsContainer)[i];
120    }
121    fpRichPointsContainer->clear();
122    delete fpRichPointsContainer;
123  }
124}
125
126void G4RichTrajectory::AppendStep(const G4Step* aStep)
127{
128  fpRichPointsContainer->push_back(new G4RichTrajectoryPoint(aStep));
129  // Except for first step, which is a sort of virtual step to start
130  // the track, compute the final values...
131  const G4Track* track = aStep->GetTrack();
132  const G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
133  if (track->GetCurrentStepNumber() > 0) {
134    fpFinalVolume = track->GetTouchableHandle();
135    fpFinalNextVolume = track->GetNextTouchableHandle();
136    fpEndingProcess = postStepPoint->GetProcessDefinedStep();
137    fFinalKineticEnergy =
138      aStep->GetPreStepPoint()->GetKineticEnergy() -
139      aStep->GetTotalEnergyDeposit();
140  }
141}
142 
143void G4RichTrajectory::MergeTrajectory(G4VTrajectory* secondTrajectory)
144{
145  if(!secondTrajectory) return;
146
147  G4Trajectory::MergeTrajectory(secondTrajectory);
148
149  G4RichTrajectory* seco = (G4RichTrajectory*)secondTrajectory;
150  G4int ent = seco->GetPointEntries();
151  for(G4int i=1;i<ent;i++) {
152    // initial point of the second trajectory should not be merged
153    fpRichPointsContainer->push_back((*(seco->fpRichPointsContainer))[i]);
154    //    fpRichPointsContainer->push_back(seco->fpRichPointsContainer->removeAt(1));
155  }
156  delete (*seco->fpRichPointsContainer)[0];
157  seco->fpRichPointsContainer->clear();
158}
159
160const std::map<G4String,G4AttDef>* G4RichTrajectory::GetAttDefs() const
161{
162  G4bool isNew;
163  std::map<G4String,G4AttDef>* store
164    = G4AttDefStore::GetInstance("G4RichTrajectory",isNew);
165  if (isNew) {
166
167    // Get att defs from base class...
168    *store = *(G4Trajectory::GetAttDefs());
169
170    G4String ID;
171
172    ID = "IVPath";
173    (*store)[ID] = G4AttDef(ID,"Initial Volume Path",
174                            "Physics","","G4String");
175
176    ID = "INVPath";
177    (*store)[ID] = G4AttDef(ID,"Initial Next Volume Path",
178                            "Physics","","G4String");
179
180    ID = "CPN";
181    (*store)[ID] = G4AttDef(ID,"Creator Process Name",
182                            "Physics","","G4String");
183
184    ID = "CPTN";
185    (*store)[ID] = G4AttDef(ID,"Creator Process Type Name",
186                            "Physics","","G4String");
187
188    ID = "FVPath";
189    (*store)[ID] = G4AttDef(ID,"Final Volume Path",
190                            "Physics","","G4String");
191
192    ID = "FNVPath";
193    (*store)[ID] = G4AttDef(ID,"Final Next Volume Path",
194                            "Physics","","G4String");
195
196    ID = "EPN";
197    (*store)[ID] = G4AttDef(ID,"Ending Process Name",
198                            "Physics","","G4String");
199
200    ID = "EPTN";
201    (*store)[ID] = G4AttDef(ID,"Ending Process Type Name",
202                            "Physics","","G4String");
203
204    ID = "FKE";
205    (*store)[ID] = G4AttDef(ID,"Final kinetic energy",
206                            "Physics","G4BestUnit","G4double");
207
208  }
209
210  return store;
211}
212
213static G4String Path(const G4TouchableHandle& th)
214{
215  std::ostringstream oss;
216  G4int depth = th->GetHistoryDepth();
217  for (G4int i = depth; i >= 0; --i) {
218    oss << th->GetVolume(i)->GetName()
219        << ':' << th->GetCopyNumber(i);
220    if (i != 0) oss << '/';
221  }
222  return oss.str();
223}
224
225std::vector<G4AttValue>* G4RichTrajectory::CreateAttValues() const
226{
227  // Create base class att values...
228  std::vector<G4AttValue>* values = G4Trajectory::CreateAttValues();
229
230  if (fpInitialVolume && fpInitialVolume->GetVolume()) {
231    values->push_back(G4AttValue("IVPath",Path(fpInitialVolume),""));
232  } else {
233    values->push_back(G4AttValue("IVPath","None",""));
234  }
235
236  if (fpInitialNextVolume && fpInitialNextVolume->GetVolume()) {
237    values->push_back(G4AttValue("INVPath",Path(fpInitialNextVolume),""));
238  } else {
239    values->push_back(G4AttValue("INVPath","None",""));
240  }
241
242  if (fpCreatorProcess) {
243    values->push_back(G4AttValue("CPN",fpCreatorProcess->GetProcessName(),""));
244    G4ProcessType type = fpCreatorProcess->GetProcessType();
245    values->push_back(G4AttValue("CPTN",G4VProcess::GetProcessTypeName(type),""));
246  } else {
247    values->push_back(G4AttValue("CPN","User Defined",""));
248    values->push_back(G4AttValue("CPTN","User",""));
249  }
250
251  if (fpFinalVolume && fpFinalVolume->GetVolume()) {
252    values->push_back(G4AttValue("FVPath",Path(fpFinalVolume),""));
253  } else {
254    values->push_back(G4AttValue("FVPath","None",""));
255  }
256
257  if (fpFinalNextVolume && fpFinalNextVolume->GetVolume()) {
258    values->push_back(G4AttValue("FNVPath",Path(fpFinalNextVolume),""));
259  } else {
260    values->push_back(G4AttValue("FNVPath","None",""));
261  }
262
263  if (fpEndingProcess) {
264    values->push_back(G4AttValue("EPN",fpEndingProcess->GetProcessName(),""));
265    G4ProcessType type = fpEndingProcess->GetProcessType();
266    values->push_back(G4AttValue("EPTN",G4VProcess::GetProcessTypeName(type),""));
267  } else {
268    values->push_back(G4AttValue("EPN","User Defined",""));
269    values->push_back(G4AttValue("EPTN","User",""));
270  }
271
272  values->push_back
273    (G4AttValue("FKE",G4BestUnit(fFinalKineticEnergy,"Energy"),""));
274
275#ifdef G4ATTDEBUG
276  G4cout << G4AttCheck(values,GetAttDefs());
277#endif
278
279  return values;
280}
Note: See TracBrowser for help on using the repository browser.