source: trunk/source/track/src/G4ParticleChangeForTransport.cc @ 1340

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

update ti head

File size: 9.4 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: G4ParticleChangeForTransport.cc,v 1.20 2010/07/21 09:30:15 gcosmo Exp $
28// GEANT4 tag $Name: track-V09-03-09 $
29//
30//
31// --------------------------------------------------------------
32//      GEANT 4 class implementation file
33//
34//     
35//
36// ------------------------------------------------------------
37//   Implemented for the new scheme                 10 May. 1998  H.Kurahige
38//   Correct tratment of fpNextTouchable            12 May. 1998  H.Kurashige
39//   Change to the next volume only if energy>0     19 Jan. 2004  V.Ivanchenko
40// --------------------------------------------------------------
41
42#include "G4ParticleChangeForTransport.hh"
43#include "G4TouchableHandle.hh"
44#include "G4Track.hh"
45#include "G4Step.hh"
46#include "G4TrackFastVector.hh"
47#include "G4DynamicParticle.hh"
48
49G4ParticleChangeForTransport::G4ParticleChangeForTransport()
50  : G4ParticleChange(), isMomentumChanged(false), theMaterialChange(0),
51    theMaterialCutsCoupleChange(0), theSensitiveDetectorChange(0)
52{
53  if (verboseLevel>2) {
54    G4cout << "G4ParticleChangeForTransport::G4ParticleChangeForTransport() "
55           << G4endl;
56  }
57}
58
59G4ParticleChangeForTransport::~G4ParticleChangeForTransport() 
60{
61  if (verboseLevel>2) {
62    G4cout << "G4ParticleChangeForTransport::~G4ParticleChangeForTransport() "
63           << G4endl;
64  }
65}
66
67G4ParticleChangeForTransport::
68G4ParticleChangeForTransport(const G4ParticleChangeForTransport &r)
69  : G4ParticleChange(r)
70{
71  if (verboseLevel>0) {
72    G4cout << "G4ParticleChangeForTransport::  copy constructor is called "
73           << G4endl;
74  }
75  theTouchableHandle = r.theTouchableHandle;
76  isMomentumChanged = r.isMomentumChanged;
77  theMaterialChange = r.theMaterialChange;
78  theMaterialCutsCoupleChange = r.theMaterialCutsCoupleChange;
79  theSensitiveDetectorChange = r.theSensitiveDetectorChange;
80}
81
82// assignemnt operator
83G4ParticleChangeForTransport &
84G4ParticleChangeForTransport::operator=(const G4ParticleChangeForTransport &r)
85{
86   if (verboseLevel>1) {
87    G4cout << "G4ParticleChangeForTransport:: assignment operator is called "
88           << G4endl;
89   }
90   if (this != &r)
91   {
92      theListOfSecondaries = r.theListOfSecondaries;
93      theSizeOftheListOfSecondaries = r.theSizeOftheListOfSecondaries;
94      theNumberOfSecondaries = r.theNumberOfSecondaries;
95      theStatusChange = r.theStatusChange;
96      theTouchableHandle = r.theTouchableHandle;
97      theMaterialChange = r.theMaterialChange;
98      theMaterialCutsCoupleChange = r.theMaterialCutsCoupleChange;
99      theSensitiveDetectorChange = r.theSensitiveDetectorChange;
100      theMomentumDirectionChange = r.theMomentumDirectionChange;
101      thePolarizationChange = r.thePolarizationChange;
102      thePositionChange = r.thePositionChange;
103      theTimeChange = r.theTimeChange;
104      theEnergyChange = r.theEnergyChange;
105      theTrueStepLength = r.theTrueStepLength;
106      theLocalEnergyDeposit = r.theLocalEnergyDeposit;
107      theSteppingControlFlag = r.theSteppingControlFlag;
108   }
109   return *this;
110}
111
112//----------------------------------------------------------------
113// methods for updating G4Step
114//
115
116G4Step* G4ParticleChangeForTransport::UpdateStepForAtRest(G4Step* pStep)
117{
118  // Nothing happens for AtRestDoIt
119  if (verboseLevel>0) {
120    G4cout << "G4ParticleChangeForTransport::UpdateStepForAtRest() is called"
121           << G4endl;
122    G4cout << " Nothing happens for this method " << G4endl;
123  }
124  //  Update the G4Step specific attributes
125  return UpdateStepInfo(pStep);
126}
127
128
129G4Step* G4ParticleChangeForTransport::UpdateStepForAlongStep(G4Step* pStep)
130{
131  // Smooth curved tajectory representation: let the Step know about
132  // the auxiliary trajectory points (jacek 30/10/2002)
133  pStep->SetPointerToVectorOfAuxiliaryPoints(fpVectorOfAuxiliaryPointsPointer);
134
135  // copy of G4ParticleChange::UpdateStepForAlongStep
136  //  i.e. no effect for touchable
137
138  // A physics process always calculates the final state of the
139  // particle relative to the initial state at the beginning
140  // of the Step, i.e., based on information of G4Track (or
141  // equivalently the PreStepPoint).
142  // So, the differences (delta) between these two states have to be
143  // calculated and be accumulated in PostStepPoint.
144
145  // Take note that the return type of GetMomentumChange is a
146  // pointer to G4ThreeVector. Also it is a normalized
147  // momentum vector.
148
149  G4StepPoint* pPreStepPoint  = pStep->GetPreStepPoint();
150  G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
151  G4Track*     aTrack  = pStep->GetTrack();
152  G4double     mass = aTrack->GetDynamicParticle()->GetMass();
153
154  // uodate kinetic energy
155  //  now assume that no energy change in transportation
156  //  However it is not true in electric fields
157  //  Case for changing energy will be implemented in future
158
159
160  // update momentum direction and energy
161  if (isMomentumChanged) {
162    G4double energy;
163    energy= pPostStepPoint->GetKineticEnergy()
164                 + (theEnergyChange - pPreStepPoint->GetKineticEnergy());
165
166    // calculate new momentum
167    G4ThreeVector pMomentum =  pPostStepPoint->GetMomentum()
168                     + ( CalcMomentum(theEnergyChange, theMomentumDirectionChange, mass)
169                          - pPreStepPoint->GetMomentum());
170    G4double      tMomentum = pMomentum.mag();
171    G4ThreeVector direction(1.0,0.0,0.0);
172    if( tMomentum > 0. ){
173      G4double  inv_Momentum= 1.0 / tMomentum;
174      direction= pMomentum * inv_Momentum;
175    }
176    pPostStepPoint->SetMomentumDirection(direction);
177    pPostStepPoint->SetKineticEnergy( energy );
178  }
179
180  // stop case should not occur
181  //pPostStepPoint->SetMomentumDirection(G4ThreeVector(1., 0., 0.));
182
183
184  // update polarization
185  pPostStepPoint->AddPolarization( thePolarizationChange
186                                   - pPreStepPoint->GetPolarization());
187
188  // update position and time
189  pPostStepPoint->AddPosition( thePositionChange
190                               - pPreStepPoint->GetPosition() );
191  pPostStepPoint->AddGlobalTime( theTimeChange
192                                 - pPreStepPoint->GetGlobalTime());
193  pPostStepPoint->AddLocalTime( theTimeChange
194                                 - pPreStepPoint->GetGlobalTime());
195  pPostStepPoint->AddProperTime( theProperTimeChange
196                                 - pPreStepPoint->GetProperTime());
197
198#ifdef G4VERBOSE
199  if (debugFlag) CheckIt(*aTrack);
200#endif
201
202  //  Update the G4Step specific attributes
203  //pStep->SetStepLength( theTrueStepLength );
204  //  pStep->AddTotalEnergyDeposit( theLocalEnergyDeposit );
205  pStep->SetControlFlag( theSteppingControlFlag );
206  return pStep;
207  //  return UpdateStepInfo(pStep);
208}
209
210G4Step* G4ParticleChangeForTransport::UpdateStepForPostStep(G4Step* pStep)
211{
212  // A physics process always calculates the final state of the particle
213
214  // Change volume only if some kinetic energy remains
215  G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
216  if(pPostStepPoint->GetKineticEnergy() > 0.0) {
217
218    // update next touchable
219    // (touchable can be changed only at PostStepDoIt)
220    pPostStepPoint->SetTouchableHandle( theTouchableHandle );
221
222    pPostStepPoint->SetMaterial( theMaterialChange );
223    pPostStepPoint->SetMaterialCutsCouple( theMaterialCutsCoupleChange );
224    pPostStepPoint->SetSensitiveDetector( theSensitiveDetectorChange );
225  }
226  if( this->GetLastStepInVolume() ){
227    pStep->SetLastStepFlag();
228  }else{
229    pStep->ClearLastStepFlag(); 
230  }
231  // It used to call base class's method
232  //   - but this would copy uninitialised data members
233  // return G4ParticleChange::UpdateStepForPostStep(pStep);
234
235  // Copying what the base class does would instead
236  //   - also not useful
237  // return G4VParticleChange::UpdateStepInfo(pStep);
238
239  return pStep;
240}
241
242//----------------------------------------------------------------
243// methods for printing messages
244//
245
246void G4ParticleChangeForTransport::DumpInfo() const
247{
248// use base-class DumpInfo
249  G4ParticleChange::DumpInfo();
250
251  G4int oldprc = G4cout.precision(3);
252  G4cout << "        Touchable (pointer) : " 
253         << std::setw(20) << theTouchableHandle() << G4endl; 
254  G4cout.precision(oldprc);
255}
Note: See TracBrowser for help on using the repository browser.