ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ParticleChangeForTransport.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ParticleChangeForTransport.cc
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 //
28 //
29 // --------------------------------------------------------------
30 // GEANT 4 class implementation file
31 //
32 //
33 //
34 // ------------------------------------------------------------
35 // Implemented for the new scheme 10 May. 1998 H.Kurahige
36 // Correct tratment of fpNextTouchable 12 May. 1998 H.Kurashige
37 // Change to the next volume only if energy>0 19 Jan. 2004 V.Ivanchenko
38 // --------------------------------------------------------------
39 
41 #include "G4TouchableHandle.hh"
42 #include "G4Track.hh"
43 #include "G4Step.hh"
44 #include "G4TrackFastVector.hh"
45 #include "G4DynamicParticle.hh"
46 
48  : G4ParticleChange(), isMomentumChanged(false), theMaterialChange(0),
49  theMaterialCutsCoupleChange(0), theSensitiveDetectorChange(0),
50  fpVectorOfAuxiliaryPointsPointer(0)
51 {
52  if (verboseLevel>2) {
53  G4cout << "G4ParticleChangeForTransport::G4ParticleChangeForTransport() "
54  << G4endl;
55  }
56 }
57 
59 {
60  if (verboseLevel>2) {
61  G4cout << "G4ParticleChangeForTransport::~G4ParticleChangeForTransport() "
62  << G4endl;
63  }
64 }
65 
68  : G4ParticleChange(r),
69  fpVectorOfAuxiliaryPointsPointer(0)
70 {
71  if (verboseLevel>0) {
72  G4cout << "G4ParticleChangeForTransport:: copy constructor is called "
73  << G4endl;
74  }
80 }
81 
82 // assignemnt operator
85 {
86  if (verboseLevel>1) {
87  G4cout << "G4ParticleChangeForTransport:: assignment operator is called "
88  << G4endl;
89  }
90  if (this != &r)
91  {
109  }
110  return *this;
111 }
112 
113 //----------------------------------------------------------------
114 // methods for updating G4Step
115 //
116 
118 {
119  // Nothing happens for AtRestDoIt
120  if (verboseLevel>0) {
121  G4cout << "G4ParticleChangeForTransport::UpdateStepForAtRest() is called"
122  << G4endl;
123  G4cout << " Nothing happens for this method " << G4endl;
124  }
125  // Update the G4Step specific attributes
126  return UpdateStepInfo(pStep);
127 }
128 
129 
131 {
132  // Smooth curved tajectory representation: let the Step know about
133  // the auxiliary trajectory points (jacek 30/10/2002)
135 
136  // copy of G4ParticleChange::UpdateStepForAlongStep
137  // i.e. no effect for touchable
138 
139  // A physics process always calculates the final state of the
140  // particle relative to the initial state at the beginning
141  // of the Step, i.e., based on information of G4Track (or
142  // equivalently the PreStepPoint).
143  // So, the differences (delta) between these two states have to be
144  // calculated and be accumulated in PostStepPoint.
145 
146  // Take note that the return type of GetMomentumChange is a
147  // pointer to G4ThreeVector. Also it is a normalized
148  // momentum vector.
149 
150  G4StepPoint* pPreStepPoint = pStep->GetPreStepPoint();
151  G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
152  G4Track* aTrack = pStep->GetTrack();
153  G4double mass = aTrack->GetDynamicParticle()->GetMass();
154 
155  // uodate kinetic energy
156  // now assume that no energy change in transportation
157  // However it is not true in electric fields
158  // Case for changing energy will be implemented in future
159 
160 
161  // update momentum direction and energy
162  if (isMomentumChanged) {
164  energy= pPostStepPoint->GetKineticEnergy()
165  + (theEnergyChange - pPreStepPoint->GetKineticEnergy());
166 
167  // calculate new momentum
168  G4ThreeVector pMomentum = pPostStepPoint->GetMomentum()
170  - pPreStepPoint->GetMomentum());
171  G4double tMomentum = pMomentum.mag();
172  G4ThreeVector direction(1.0,0.0,0.0);
173  if( tMomentum > 0. ){
174  G4double inv_Momentum= 1.0 / tMomentum;
175  direction= pMomentum * inv_Momentum;
176  }
177  pPostStepPoint->SetMomentumDirection(direction);
178  pPostStepPoint->SetKineticEnergy( energy );
179  }
180  if (isVelocityChanged) pPostStepPoint->SetVelocity(theVelocityChange);
181 
182  // stop case should not occur
183  //pPostStepPoint->SetMomentumDirection(G4ThreeVector(1., 0., 0.));
184 
185 
186  // update polarization
187  pPostStepPoint->AddPolarization( thePolarizationChange
188  - pPreStepPoint->GetPolarization());
189 
190  // update position and time
191  pPostStepPoint->AddPosition( thePositionChange
192  - pPreStepPoint->GetPosition() );
193  pPostStepPoint->AddGlobalTime( theTimeChange
194  - pPreStepPoint->GetLocalTime());
195  pPostStepPoint->AddLocalTime( theTimeChange
196  - pPreStepPoint->GetLocalTime());
197  pPostStepPoint->AddProperTime( theProperTimeChange
198  - pPreStepPoint->GetProperTime());
199 
200 #ifdef G4VERBOSE
201  if (debugFlag) CheckIt(*aTrack);
202 #endif
203 
204  // Update the G4Step specific attributes
205  //pStep->SetStepLength( theTrueStepLength );
206  // pStep->AddTotalEnergyDeposit( theLocalEnergyDeposit );
208  return pStep;
209  // return UpdateStepInfo(pStep);
210 }
211 
213 {
214  // A physics process always calculates the final state of the particle
215 
216  // Change volume only if some kinetic energy remains
217  G4StepPoint* pPostStepPoint = pStep->GetPostStepPoint();
218  if(pPostStepPoint->GetKineticEnergy() > 0.0) {
219 
220  // update next touchable
221  // (touchable can be changed only at PostStepDoIt)
222  pPostStepPoint->SetTouchableHandle( theTouchableHandle );
223 
224  pPostStepPoint->SetMaterial( theMaterialChange );
227  }
228  if( this->GetFirstStepInVolume() ){
229  pStep->SetFirstStepFlag();
230  }else{
231  pStep->ClearFirstStepFlag();
232  }
233  if( this->GetLastStepInVolume() ){
234  pStep->SetLastStepFlag();
235  }else{
236  pStep->ClearLastStepFlag();
237  }
238  // It used to call base class's method
239  // - but this would copy uninitialised data members
240  // return G4ParticleChange::UpdateStepForPostStep(pStep);
241 
242  // Copying what the base class does would instead
243  // - also not useful
244  // return G4VParticleChange::UpdateStepInfo(pStep);
245 
246  return pStep;
247 }
248 
249 
250 //----------------------------------------------------------------
251 // methods for printing messages
252 //
253 
255 {
256 // use base-class DumpInfo
258 
259  G4int oldprc = G4cout.precision(3);
260  G4cout << " Touchable (pointer) : "
261  << std::setw(20) << theTouchableHandle() << G4endl;
262  G4cout.precision(oldprc);
263 }
264